From 69c09c7c65a0ed974a0971592c7416e7eab57269 Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Fri, 8 Jul 2022 14:52:17 +0200 Subject: [PATCH] Upper-case client connection log, grow chuck size for older shards --- include/siri/version.h | 2 +- src/siri/db/series.c | 1 - src/siri/db/shard.c | 31 +++++++++++++++++++++++++++---- src/siri/net/stream.c | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/siri/version.h b/include/siri/version.h index 90762616..8acce47d 100644 --- a/include/siri/version.h +++ b/include/siri/version.h @@ -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 diff --git a/src/siri/db/series.c b/src/siri/db/series.c index 26c1e12c..ff83275e 100644 --- a/src/siri/db/series.c +++ b/src/siri/db/series.c @@ -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. */ diff --git a/src/siri/db/shard.c b/src/siri/db/shard.c index d2e7b937..01f5a0e2 100644 --- a/src/siri/db/shard.c +++ b/src/siri/db/shard.c @@ -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) { diff --git a/src/siri/net/stream.c b/src/siri/net/stream.c index 7af4c6a7..e46037d0 100644 --- a/src/siri/net/stream.c +++ b/src/siri/net/stream.c @@ -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; -- 2.30.2