/* true/false props */
int32_t version;
int32_t log_colorized;
+ int32_t managed;
/* string props */
char config[ARGPARSE_MAX_LEN_ARG];
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;
#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.
* 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"
.config="",
.log_level="",
.log_colorized=0,
+ .managed=0,
};
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 */
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);
}
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
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;
/* 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)
"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,
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)