From: Jeroen van der Heijden Date: Wed, 11 Nov 2020 15:58:06 +0000 (+0100) Subject: Kubernetes update compatibility fix, issue #153 X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~3^2~1^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=21ad591ba9836433984b01207ecd666e1ab4af86;p=siridb-server.git Kubernetes update compatibility fix, issue #153 --- diff --git a/include/siri/args/args.h b/include/siri/args/args.h index d756df7b..70373cee 100644 --- a/include/siri/args/args.h +++ b/include/siri/args/args.h @@ -18,6 +18,7 @@ struct siri_args_s /* true/false props */ int32_t version; int32_t log_colorized; + int32_t managed; /* string props */ char config[ARGPARSE_MAX_LEN_ARG]; diff --git a/include/siri/db/server.h b/include/siri/db/server.h index 77b1ff8d..2b74cd12 100644 --- a/include/siri/db/server.h +++ b/include/siri/db/server.h @@ -154,7 +154,7 @@ struct siridb_server_s uint16_t pid; /* fixed server properties */ uint8_t ip_support; - uint8_t pad0; + uint8_t retry_attempts; uint32_t startup_time; char * libuv; char * version; diff --git a/include/siri/version.h b/include/siri/version.h index d2f3a2aa..006a6623 100644 --- a/include/siri/version.h +++ b/include/siri/version.h @@ -6,7 +6,7 @@ #define SIRIDB_VERSION_MAJOR 2 #define SIRIDB_VERSION_MINOR 0 -#define SIRIDB_VERSION_PATCH 41 +#define SIRIDB_VERSION_PATCH 42 /* * Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions. @@ -15,7 +15,7 @@ * Note that debian alpha packages should use versions like this: * 2.0.34-0alpha0 */ -#define SIRIDB_VERSION_PRE_RELEASE "-alpha-1" +#define SIRIDB_VERSION_PRE_RELEASE "-alpha-0" #ifndef NDEBUG #define SIRIDB_VERSION_BUILD_RELEASE "+debug" diff --git a/src/siri/args/args.c b/src/siri/args/args.c index e510839a..99f47264 100644 --- a/src/siri/args/args.c +++ b/src/siri/args/args.c @@ -22,6 +22,7 @@ static siri_args_t siri_args = { .config="", .log_level="", .log_colorized=0, + .managed=0, }; void siri_args_parse(siri_t * siri, int argc, char *argv[]) @@ -56,6 +57,18 @@ void siri_args_parse(siri_t * siri, int argc, char *argv[]) NULL /* choices */ }; + argparse_argument_t managed = { + "managed", + 0, + "use this flag when deployed using a managed environment", + ARGPARSE_STORE_TRUE, + 0, + &siri_args.managed, + NULL, + NULL, + NULL, + }; + argparse_argument_t log_level = { "log-level", /* name */ 'l', /* shortcut */ @@ -84,6 +97,7 @@ void siri_args_parse(siri_t * siri, int argc, char *argv[]) argparse_add_argument(&parser, &version); argparse_add_argument(&parser, &log_level); argparse_add_argument(&parser, &log_colorized); + argparse_add_argument(&parser, &managed); /* this will parse and free the parser from memory */ argparse_parse(&parser, argc, argv); diff --git a/src/siri/db/replicate.c b/src/siri/db/replicate.c index 714cc6fe..91a4bde5 100644 --- a/src/siri/db/replicate.c +++ b/src/siri/db/replicate.c @@ -377,7 +377,7 @@ static void REPLICATE_on_repl_finished_response( } else if (pkg->tp == BPROTO_ACK_REPL_FINISHED) { - log_debug("Replication finished ACK received from '%s'", + log_info("Replication finished ACK received from '%s'", promise->server->name); } else diff --git a/src/siri/db/server.c b/src/siri/db/server.c index 54af4956..9fb96015 100644 --- a/src/siri/db/server.c +++ b/src/siri/db/server.c @@ -87,6 +87,7 @@ siridb_server_t * siridb_server_new( server->pid = 0; server->version = NULL; server->ip_support = 255; /* unknown */ + server->retry_attempts = 0; server->libuv = NULL; server->dbpath = NULL; server->buffer_path = NULL; @@ -390,6 +391,7 @@ void siridb_server_connect(siridb_t * siridb, siridb_server_t * server) /* server->socket must be NULL at this point */ assert (server->client == NULL); + ++server->retry_attempts; server->client = sirinet_stream_new(STREAM_TCP_SERVER, &SERVER_on_data); if (server->client != NULL) @@ -670,6 +672,8 @@ static void SERVER_on_connect(uv_connect_t * req, int status) "Connection created to back-end server: '%s', " "sending authentication request", server->name); + server->retry_attempts = 0; /* reset connection attempts */ + uv_read_start( req->handle, sirinet_stream_alloc_buffer, diff --git a/src/siri/health.c b/src/siri/health.c index 2a9c4eee..a7e0916e 100644 --- a/src/siri/health.c +++ b/src/siri/health.c @@ -157,21 +157,55 @@ static uv_buf_t * health__get_status_response(void) static uv_buf_t * health__get_ready_response(void) { + int status = 1; siridb_t * siridb; - uint8_t flags = SERVER_FLAG_RUNNING; llist_node_t * siridb_node; siridb_node = siri.siridb_list->first; while (siridb_node != NULL) { siridb = (siridb_t *) siridb_node->data; - flags |= siridb->server->flags; + if (siridb->server->flags != SERVER_FLAG_RUNNING) + { + status = 0; + break; + } siridb_node = siridb_node->next; } - return flags == SERVER_FLAG_RUNNING - ? &health__uv_ok_buf - : &health__uv_nok_buf; + if (status) + { + return &health__uv_ok_buf; + } + + if (siri.args->managed) + { + /* + * If managed, return NOK only if the server is not RUNNING and the + * server is not SERVER_FLAG_REINDEXING and the server has either no + * replica, or the replica is (maybe) online + * + * In case the the replica is off-line we want to respond using `OK` + * since the an environment like Kubernetes can continue to start + * the next pod. + */ + siridb_node = siri.siridb_list->first; + while (siridb_node != NULL) + { + siridb = (siridb_t *) siridb_node->data; + if (siridb->server->flags != SERVER_FLAG_RUNNING && + (~siridb->server->flags & SERVER_FLAG_REINDEXING) && ( + siridb->replica == NULL || + siridb->replica->retry_attempts < 3)) + { + return &health__uv_nok_buf; + } + siridb_node = siridb_node->next; + } + return &health__uv_ok_buf; + } + + return &health__uv_nok_buf; } static int health__url_cb(http_parser * parser, const char * at, size_t length)