Kubernetes update compatibility fix, issue #153
authorJeroen van der Heijden <jeroen@transceptor.technology>
Wed, 11 Nov 2020 15:58:06 +0000 (16:58 +0100)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Wed, 11 Nov 2020 15:58:06 +0000 (16:58 +0100)
include/siri/args/args.h
include/siri/db/server.h
include/siri/version.h
src/siri/args/args.c
src/siri/db/replicate.c
src/siri/db/server.c
src/siri/health.c

index d756df7b8501d548ff9c1cb8bdf63f4377830c78..70373ceeb7ed358660535084aaaada0b2b09397e 100644 (file)
@@ -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];
index 77b1ff8d95972c4fad2257fdab860edb02986d45..2b74cd12e145b7102a5999a09e63637e564680da 100644 (file)
@@ -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;
index d2f3a2aa93892a2b769d84e01f60a636cb6949db..006a6623ac33762a9bdc3bef10b5d389f72cb111 100644 (file)
@@ -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"
index e510839adfed30ab9dfc4ba0364bb119377bf828..99f4726451140ae9faf430fb264f474efb43ac92 100644 (file)
@@ -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);
index 714cc6fe6b6bae1a6eefc19108408f0676215b3a..91a4bde5378b21d888dbde4c3e35265b687e6c86 100644 (file)
@@ -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
index 54af4956a5aa8c29f3c57011f5794f362fd58200..9fb96015695a16569c248eefc0b113662ac3ef1c 100644 (file)
@@ -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,
index 2a9c4eeed092cdab19ed68776b127adab66dae43..a7e0916ebeb83f5596516cc106e4e83d0fac0454 100644 (file)
@@ -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)