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.
This commit is contained in:
@ -20,11 +20,14 @@
|
|||||||
#include "maxinfo_func.h"
|
#include "maxinfo_func.h"
|
||||||
#include "sql_t1.h"
|
#include "sql_t1.h"
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
char reg_str[] = "REGISTER UUID=XXX-YYY_YYY, TYPE=JSON";
|
char reg_str[] = "REGISTER UUID=XXX-YYY_YYY, TYPE=JSON";
|
||||||
char req_str[] = "REQUEST-DATA test.t1";
|
char req_str[] = "REQUEST-DATA test.t1";
|
||||||
int insert_val = 0;
|
std::atomic<int> insert_val {0};
|
||||||
bool exit_flag = false;
|
bool exit_flag = false;
|
||||||
|
|
||||||
void* query_thread(void* ptr);
|
void* query_thread(void* ptr);
|
||||||
@ -225,10 +228,14 @@ void* query_thread(void* ptr)
|
|||||||
if (insert_val != 0)
|
if (insert_val != 0)
|
||||||
{
|
{
|
||||||
char str[256];
|
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;
|
insert_val = 0;
|
||||||
execute_query(Test->repl->nodes[0], "%s", str);
|
execute_query(Test->repl->nodes[0], "%s", str);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Test->repl->close_connections();
|
Test->repl->close_connections();
|
||||||
|
|||||||
Reference in New Issue
Block a user