From b6dc67f1b951f5fd91974eb6af02ce8f093fdc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 16 Jan 2020 15:51:17 +0200 Subject: [PATCH] Improve cdc_client stability It was possible that the query thread got stuck and never saw the updated insert_val. Making the variable atomic as well as sleeping in between queries should prevent it. --- maxscale-system-test/cdc_client.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/maxscale-system-test/cdc_client.cpp b/maxscale-system-test/cdc_client.cpp index fea1023bc..e97929697 100644 --- a/maxscale-system-test/cdc_client.cpp +++ b/maxscale-system-test/cdc_client.cpp @@ -20,11 +20,14 @@ #include "maxinfo_func.h" #include "sql_t1.h" #include +#include +#include +#include using namespace std; char reg_str[] = "REGISTER UUID=XXX-YYY_YYY, TYPE=JSON"; char req_str[] = "REQUEST-DATA test.t1"; -int insert_val = 0; +std::atomic insert_val {0}; bool exit_flag = false; void* query_thread(void* ptr); @@ -225,10 +228,14 @@ void* query_thread(void* ptr) if (insert_val != 0) { char str[256]; - sprintf(str, "INSERT INTO t1 VALUES (%d, %d)", insert_val, insert_val + 100); + sprintf(str, "INSERT INTO t1 VALUES (%d, %d)", insert_val.load(), insert_val.load() + 100); insert_val = 0; execute_query(Test->repl->nodes[0], "%s", str); } + else + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } } Test->repl->close_connections();