Upper-case client connection log, grow chuck size for older shards
authorJeroen van der Heijden <jeroen@cesbit.com>
Fri, 8 Jul 2022 12:52:17 +0000 (14:52 +0200)
committerJeroen van der Heijden <jeroen@cesbit.com>
Fri, 8 Jul 2022 12:52:17 +0000 (14:52 +0200)
include/siri/version.h
src/siri/db/series.c
src/siri/db/shard.c
src/siri/net/stream.c

index 9076261622975d63287f2451aeaf4818a23debf9..8acce47d31d998aff757c91c8acf6f81631e6aa8 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef NDEBUG
 #define SIRIDB_VERSION_BUILD_RELEASE "+debug"
 #else
-#define SIRIDB_VERSION_BUILD_RELEASE "-alpha-0"
+#define SIRIDB_VERSION_BUILD_RELEASE "-alpha-1"
 #endif
 
 #define SIRIDB_STRINGIFY(num) #num
index 26c1e12cf0e719ae1aaf8bf0f5d71e8193cf1924..ff83275eb3df871749359ff1ff9f650eb714baa4 100644 (file)
@@ -900,7 +900,6 @@ siridb_points_t * siridb_series_get_points_head(
     return points;
 }
 
-
 /*
  * Returns NULL and raises a SIGNAL in case an error has occurred.
  */
index d2e7b937ea605bd4b883f42e386ae6c895444885..01f5a0e2759f9e7cb0aba457149fd00f40eb4f00 100644 (file)
@@ -457,10 +457,33 @@ siridb_shard_t *  siridb_shard_create(
     shard->replacing = replacing;
     shard->len = shard->size = HEADER_SIZE;
     shard->duration = duration;
-    shard->max_chunk_sz = (replacing == NULL) ?
-            (tp == SIRIDB_SHARD_TP_NUMBER ?
-                    DEFAULT_MAX_CHUNK_SZ_NUM : DEFAULT_MAX_CHUNK_SZ_LOG) :
-                    replacing->max_chunk_sz;
+    if (replacing == NULL)
+    {
+        shard->max_chunk_sz = (tp == SIRIDB_SHARD_TP_NUMBER)
+                ? DEFAULT_MAX_CHUNK_SZ_NUM
+                : DEFAULT_MAX_CHUNK_SZ_LOG;
+    }
+    else
+    {
+        shard->max_chunk_sz = replacing->max_chunk_sz;
+        if (tp == SIRIDB_SHARD_TP_NUMBER && shard->max_chunk_sz < 4000)
+        {
+            uint64_t now_ts;
+            struct timespec now;
+            clock_gettime(CLOCK_REALTIME, &now);
+            now_ts = siridb_time_now(siridb, now);
+
+            if (now_ts > id && (now_ts - id) > (duration * 3))
+            {
+                /* for numbers, we grow the max_chunk_size on each optimize;
+                 * as soon as the shard is older than 3 times the duration */
+                shard->max_chunk_sz *= 2;
+                log_debug(
+                        "Grow chunk size for shard id %" PRIu64 " to %u",
+                        id, shard->max_chunk_sz);
+            }
+        }
+    }
 
     if (SHARD_init_fn(siridb, shard) < 0)
     {
index 7af4c6a7b7b049203d66d1d09f0c62703dfe0649..e46037d0c0096fb63445842100dc3cd2f5382adc 100644 (file)
@@ -252,7 +252,7 @@ void sirinet__stream_free(uv_stream_t * uvclient)
     case STREAM_API_CLIENT:
     case STREAM_PIPE_CLIENT:
     case STREAM_TCP_CLIENT:  /* listens to client connections  */
-        log_debug("client connection lost");
+        log_debug("Client connection lost");
         if (client->origin != NULL)
         {
             siridb_user_t * user = client->origin;