[MediaWiki-commits] [Gerrit] operations...varnishkafka[master]: Improve resilience during varnish (re)starts
Elukey has submitted this change and it was merged. Change subject: Improve resilience during varnish (re)starts .. Improve resilience during varnish (re)starts This patch introduces a trick already used in Varnish's VUT library, namely forcing a reconnect to the shm log if it is detected as abandoned or not opened. This can happen if varnishkafka starts before varnish, or if varnish restarts/stops while varnishkafka is running. Varnishkafka is now going to retry every 100ms endlessly until a log is aquired. Background reading: - https://github.com/varnishcache/varnish-cache/blob/4.1/lib/libvarnishtools/vut.c#L366 - https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishlog/varnishlog.c To keep things consistent with the current behavior, the sequence number is restarted to its starting value when a log overrun/abandon is detected. Bug: T138747 Change-Id: I6969fcce80140bd9c24da4511ff7bbdde02a5ff8 --- M config.c M varnishkafka.c M varnishkafka.h 3 files changed, 78 insertions(+), 33 deletions(-) Approvals: Elukey: Verified; Looks good to me, approved diff --git a/config.c b/config.c index a9c48f4..33a8ed4 100644 --- a/config.c +++ b/config.c @@ -168,6 +168,7 @@ conf.sequence_number = (uint64_t)time(NULL)*100llu; else conf.sequence_number = strtoull(val, NULL, 0); + conf.sequence_number_start = conf.sequence_number; } else if (!strcmp(name, "output")) { if (!strcmp(val, "kafka")) outfunc = out_kafka; diff --git a/varnishkafka.c b/varnishkafka.c index c52594f..f37bdab 100644 --- a/varnishkafka.c +++ b/varnishkafka.c @@ -1866,6 +1866,40 @@ } +/** + * Open and configure VSM/VSL/VSLQ settings. The vslq_query parameter will be + * used to know if a VSLQ query/filter needs to be set or not. + * Returns 0 in case of success, -1 otherwise. + */ +static int varnish_api_open_handles(struct VSM_data **vsm, struct VSL_data **vsl, + struct VSL_cursor **vsl_cursor, + unsigned int vsl_cursor_options, + struct VSLQ **vslq, char* vslq_query) { + if (VSM_Open(*vsm) < 0) { + vk_log("VSM_OPEN", LOG_DEBUG, "Failed to open Varnish VSL: %s\n", VSM_Error(*vsm)); + return -1; + } + *vsl_cursor = VSL_CursorVSM(*vsl, *vsm, vsl_cursor_options); + if (*vsl_cursor == NULL) { + vk_log("VSL_CursorVSM", LOG_DEBUG, "Failed to obtain a cursor for the SHM log: %s\n", + VSL_Error(*vsl)); + return -1; + } + /* Setting VSLQ query */ + if (vslq_query) { + *vslq = VSLQ_New(*vsl, vsl_cursor, VSL_g_request, vslq_query); + } else { + *vslq = VSLQ_New(*vsl, vsl_cursor, VSL_g_request, NULL); + } + if (*vslq == NULL) { + vk_log("VSLQ_NEW", LOG_DEBUG, "Failed to instantiate the VSL query: %s\n", + VSL_Error(*vsl)); + return -1; + } + return 0; +} + + int main (int argc, char **argv) { char errstr[4096]; char hostname[1024]; @@ -2063,7 +2097,7 @@ * in the header file because used in both config.c and varnishkafka.c */ conf.vsl = VSL_New(); - struct VSL_cursor *vsl_cursor; + struct VSL_cursor *vsl_cursor = NULL; conf.vsm = VSM_New(); if (conf.T_flag) { @@ -2103,40 +2137,19 @@ } } - if (VSM_Open(conf.vsm) < 0) { - vk_log("VSM_OPEN", LOG_ERR, "Failed to open Varnish VSL: %s\n", VSM_Error(conf.vsm)); - varnish_api_cleaning(); - exit(1); - } - vsl_cursor = VSL_CursorVSM(conf.vsl, conf.vsm, VSL_COPT_TAIL | VSL_COPT_BATCH); - if (vsl_cursor == NULL) { - vk_log("VSL_CursorVSM", LOG_ERR, "Failed to obtain a cursor for the SHM log: %s\n", - VSL_Error(conf.vsl)); - varnish_api_cleaning(); - exit(1); - } - - /* Setting VSLQ query */ - if (conf.q_flag) { - conf.vslq = VSLQ_New(conf.vsl, &vsl_cursor, VSL_g_request, conf.q_flag_query); - } else { - conf.vslq = VSLQ_New(conf.vsl, &vsl_cursor, VSL_g_request, NULL); - } - if (conf.vslq == NULL) { - vk_log("VSLQ_NEW", LOG_ERR, "Failed to instantiate the VSL query: %s\n", - VSL_Error(conf.vsl)); - varnish_api_cleaning(); - exit(1); - } - /* Main dispatcher loop depending on outputter */ conf.run = 1; conf.pret = 0; /* time struct to sleep for 10ms */ - struct timespec wait_for; - wait_for.tv_sec = 0; - wait_for.tv_nsec = 1000L; + s
[MediaWiki-commits] [Gerrit] operations...varnishkafka[master]: Improve resilience during varnish (re)starts
Elukey has uploaded a new change for review. https://gerrit.wikimedia.org/r/311965 Change subject: Improve resilience during varnish (re)starts .. Improve resilience during varnish (re)starts This patch introduces a trick already used in Varnish's VUT library, namely forcing a reconnect to the shm log if it is detected as abandoned or not opened. This can happen if varnishkafka starts before varnish, or if varnish restarts/stops while varnishkafka is running. Varnishkafka is now going to retry every 100ms endlessly until a log is aquired. Background reading: - https://github.com/varnishcache/varnish-cache/blob/4.1/lib/libvarnishtools/vut.c#L366 - https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishlog/varnishlog.c To keep things consistent with the current behavior, the sequence number is restarted to its starting value when a log overrun/abandon is detected. Bug: T138747 Change-Id: I6969fcce80140bd9c24da4511ff7bbdde02a5ff8 --- M config.c M varnishkafka.c M varnishkafka.h 3 files changed, 78 insertions(+), 33 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/software/varnish/varnishkafka refs/changes/65/311965/1 diff --git a/config.c b/config.c index a9c48f4..33a8ed4 100644 --- a/config.c +++ b/config.c @@ -168,6 +168,7 @@ conf.sequence_number = (uint64_t)time(NULL)*100llu; else conf.sequence_number = strtoull(val, NULL, 0); + conf.sequence_number_start = conf.sequence_number; } else if (!strcmp(name, "output")) { if (!strcmp(val, "kafka")) outfunc = out_kafka; diff --git a/varnishkafka.c b/varnishkafka.c index c52594f..f37bdab 100644 --- a/varnishkafka.c +++ b/varnishkafka.c @@ -1866,6 +1866,40 @@ } +/** + * Open and configure VSM/VSL/VSLQ settings. The vslq_query parameter will be + * used to know if a VSLQ query/filter needs to be set or not. + * Returns 0 in case of success, -1 otherwise. + */ +static int varnish_api_open_handles(struct VSM_data **vsm, struct VSL_data **vsl, + struct VSL_cursor **vsl_cursor, + unsigned int vsl_cursor_options, + struct VSLQ **vslq, char* vslq_query) { + if (VSM_Open(*vsm) < 0) { + vk_log("VSM_OPEN", LOG_DEBUG, "Failed to open Varnish VSL: %s\n", VSM_Error(*vsm)); + return -1; + } + *vsl_cursor = VSL_CursorVSM(*vsl, *vsm, vsl_cursor_options); + if (*vsl_cursor == NULL) { + vk_log("VSL_CursorVSM", LOG_DEBUG, "Failed to obtain a cursor for the SHM log: %s\n", + VSL_Error(*vsl)); + return -1; + } + /* Setting VSLQ query */ + if (vslq_query) { + *vslq = VSLQ_New(*vsl, vsl_cursor, VSL_g_request, vslq_query); + } else { + *vslq = VSLQ_New(*vsl, vsl_cursor, VSL_g_request, NULL); + } + if (*vslq == NULL) { + vk_log("VSLQ_NEW", LOG_DEBUG, "Failed to instantiate the VSL query: %s\n", + VSL_Error(*vsl)); + return -1; + } + return 0; +} + + int main (int argc, char **argv) { char errstr[4096]; char hostname[1024]; @@ -2063,7 +2097,7 @@ * in the header file because used in both config.c and varnishkafka.c */ conf.vsl = VSL_New(); - struct VSL_cursor *vsl_cursor; + struct VSL_cursor *vsl_cursor = NULL; conf.vsm = VSM_New(); if (conf.T_flag) { @@ -2103,40 +2137,19 @@ } } - if (VSM_Open(conf.vsm) < 0) { - vk_log("VSM_OPEN", LOG_ERR, "Failed to open Varnish VSL: %s\n", VSM_Error(conf.vsm)); - varnish_api_cleaning(); - exit(1); - } - vsl_cursor = VSL_CursorVSM(conf.vsl, conf.vsm, VSL_COPT_TAIL | VSL_COPT_BATCH); - if (vsl_cursor == NULL) { - vk_log("VSL_CursorVSM", LOG_ERR, "Failed to obtain a cursor for the SHM log: %s\n", - VSL_Error(conf.vsl)); - varnish_api_cleaning(); - exit(1); - } - - /* Setting VSLQ query */ - if (conf.q_flag) { - conf.vslq = VSLQ_New(conf.vsl, &vsl_cursor, VSL_g_request, conf.q_flag_query); - } else { - conf.vslq = VSLQ_New(conf.vsl, &vsl_cursor, VSL_g_request, NULL); - } - if (conf.vslq == NULL) { - vk_log("VSLQ_NEW", LOG_ERR, "Failed to instantiate the VSL query: %s\n", - VSL_Error(conf.vsl)); - varnish_api_cleaning(); - exit(1); - } - /* Main dispatcher loop depending on outputter */ conf.run = 1; conf.pret = 0; /* time struct to sleep for 10ms */ - struct timespec
[MediaWiki-commits] [Gerrit] operations...varnishkafka[master]: Improve resilience during varnish (re)starts
Elukey has submitted this change and it was merged. Change subject: Improve resilience during varnish (re)starts .. Improve resilience during varnish (re)starts This patch introduces a trick already used in Varnish's VUT library, namely forcing a reconnect to the shm log if it is detected as abandoned or not opened. This can happen if varnishkafka starts before varnish, or if varnish restarts/stops while varnishkafka is running. Varnishkafka is now going to retry every 100ms endlessly until a log is aquired. Background reading: - https://github.com/varnishcache/varnish-cache/blob/4.1/lib/libvarnishtools/vut.c#L366 - https://github.com/varnishcache/varnish-cache/blob/master/bin/varnishlog/varnishlog.c To keep things consistent with the current behavior, the sequence number is restarted to its starting value when a log overrun/abandon is detected. Bug: T138747 Change-Id: I87048786b36de325aee663a873b12874588664fb --- M config.c M varnishkafka.c M varnishkafka.h 3 files changed, 78 insertions(+), 33 deletions(-) Approvals: Elukey: Verified; Looks good to me, approved diff --git a/config.c b/config.c index a9c48f4..33a8ed4 100644 --- a/config.c +++ b/config.c @@ -168,6 +168,7 @@ conf.sequence_number = (uint64_t)time(NULL)*100llu; else conf.sequence_number = strtoull(val, NULL, 0); + conf.sequence_number_start = conf.sequence_number; } else if (!strcmp(name, "output")) { if (!strcmp(val, "kafka")) outfunc = out_kafka; diff --git a/varnishkafka.c b/varnishkafka.c index c52594f..f37bdab 100644 --- a/varnishkafka.c +++ b/varnishkafka.c @@ -1866,6 +1866,40 @@ } +/** + * Open and configure VSM/VSL/VSLQ settings. The vslq_query parameter will be + * used to know if a VSLQ query/filter needs to be set or not. + * Returns 0 in case of success, -1 otherwise. + */ +static int varnish_api_open_handles(struct VSM_data **vsm, struct VSL_data **vsl, + struct VSL_cursor **vsl_cursor, + unsigned int vsl_cursor_options, + struct VSLQ **vslq, char* vslq_query) { + if (VSM_Open(*vsm) < 0) { + vk_log("VSM_OPEN", LOG_DEBUG, "Failed to open Varnish VSL: %s\n", VSM_Error(*vsm)); + return -1; + } + *vsl_cursor = VSL_CursorVSM(*vsl, *vsm, vsl_cursor_options); + if (*vsl_cursor == NULL) { + vk_log("VSL_CursorVSM", LOG_DEBUG, "Failed to obtain a cursor for the SHM log: %s\n", + VSL_Error(*vsl)); + return -1; + } + /* Setting VSLQ query */ + if (vslq_query) { + *vslq = VSLQ_New(*vsl, vsl_cursor, VSL_g_request, vslq_query); + } else { + *vslq = VSLQ_New(*vsl, vsl_cursor, VSL_g_request, NULL); + } + if (*vslq == NULL) { + vk_log("VSLQ_NEW", LOG_DEBUG, "Failed to instantiate the VSL query: %s\n", + VSL_Error(*vsl)); + return -1; + } + return 0; +} + + int main (int argc, char **argv) { char errstr[4096]; char hostname[1024]; @@ -2063,7 +2097,7 @@ * in the header file because used in both config.c and varnishkafka.c */ conf.vsl = VSL_New(); - struct VSL_cursor *vsl_cursor; + struct VSL_cursor *vsl_cursor = NULL; conf.vsm = VSM_New(); if (conf.T_flag) { @@ -2103,40 +2137,19 @@ } } - if (VSM_Open(conf.vsm) < 0) { - vk_log("VSM_OPEN", LOG_ERR, "Failed to open Varnish VSL: %s\n", VSM_Error(conf.vsm)); - varnish_api_cleaning(); - exit(1); - } - vsl_cursor = VSL_CursorVSM(conf.vsl, conf.vsm, VSL_COPT_TAIL | VSL_COPT_BATCH); - if (vsl_cursor == NULL) { - vk_log("VSL_CursorVSM", LOG_ERR, "Failed to obtain a cursor for the SHM log: %s\n", - VSL_Error(conf.vsl)); - varnish_api_cleaning(); - exit(1); - } - - /* Setting VSLQ query */ - if (conf.q_flag) { - conf.vslq = VSLQ_New(conf.vsl, &vsl_cursor, VSL_g_request, conf.q_flag_query); - } else { - conf.vslq = VSLQ_New(conf.vsl, &vsl_cursor, VSL_g_request, NULL); - } - if (conf.vslq == NULL) { - vk_log("VSLQ_NEW", LOG_ERR, "Failed to instantiate the VSL query: %s\n", - VSL_Error(conf.vsl)); - varnish_api_cleaning(); - exit(1); - } - /* Main dispatcher loop depending on outputter */ conf.run = 1; conf.pret = 0; /* time struct to sleep for 10ms */ - struct timespec wait_for; - wait_for.tv_sec = 0; - wait_for.tv_nsec = 1000L; + s