other: merge main.
This commit is contained in:
commit
78f49db0ad
|
@ -2,7 +2,7 @@
|
||||||
# taosadapter
|
# taosadapter
|
||||||
ExternalProject_Add(taosadapter
|
ExternalProject_Add(taosadapter
|
||||||
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
||||||
GIT_TAG a2e9920
|
GIT_TAG 69eee2e
|
||||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
||||||
BINARY_DIR ""
|
BINARY_DIR ""
|
||||||
#BUILD_IN_SOURCE TRUE
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# taos-tools
|
# taos-tools
|
||||||
ExternalProject_Add(taos-tools
|
ExternalProject_Add(taos-tools
|
||||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||||
GIT_TAG 4efbc10
|
GIT_TAG 5aa25e9
|
||||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||||
BINARY_DIR ""
|
BINARY_DIR ""
|
||||||
#BUILD_IN_SOURCE TRUE
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
|
|
@ -69,6 +69,9 @@ extern int32_t tsElectInterval;
|
||||||
extern int32_t tsHeartbeatInterval;
|
extern int32_t tsHeartbeatInterval;
|
||||||
extern int32_t tsHeartbeatTimeout;
|
extern int32_t tsHeartbeatTimeout;
|
||||||
|
|
||||||
|
// vnode
|
||||||
|
extern int64_t tsVndCommitMaxIntervalMs;
|
||||||
|
|
||||||
// monitor
|
// monitor
|
||||||
extern bool tsEnableMonitor;
|
extern bool tsEnableMonitor;
|
||||||
extern int32_t tsMonitorInterval;
|
extern int32_t tsMonitorInterval;
|
||||||
|
@ -82,6 +85,10 @@ extern bool tsEnableTelem;
|
||||||
extern int32_t tsTelemInterval;
|
extern int32_t tsTelemInterval;
|
||||||
extern char tsTelemServer[];
|
extern char tsTelemServer[];
|
||||||
extern uint16_t tsTelemPort;
|
extern uint16_t tsTelemPort;
|
||||||
|
extern bool tsEnableCrashReport;
|
||||||
|
extern char* tsTelemUri;
|
||||||
|
extern char* tsClientCrashReportUri;
|
||||||
|
extern char* tsSvrCrashReportUri;
|
||||||
|
|
||||||
// query buffer management
|
// query buffer management
|
||||||
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
|
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
|
||||||
|
|
|
@ -78,7 +78,7 @@ typedef struct {
|
||||||
|
|
||||||
// output
|
// output
|
||||||
char* ctbShortName; // must have size of TSDB_TABLE_NAME_LEN;
|
char* ctbShortName; // must have size of TSDB_TABLE_NAME_LEN;
|
||||||
uint64_t uid; // child table uid, may be useful
|
// uint64_t uid; // child table uid, may be useful
|
||||||
} RandTableName;
|
} RandTableName;
|
||||||
|
|
||||||
void buildChildTableName(RandTableName* rName);
|
void buildChildTableName(RandTableName* rName);
|
||||||
|
|
|
@ -49,10 +49,12 @@ extern "C" {
|
||||||
#define SYNC_HEARTBEAT_REPLY_SLOW_MS 1500
|
#define SYNC_HEARTBEAT_REPLY_SLOW_MS 1500
|
||||||
#define SYNC_SNAP_RESEND_MS 1000 * 60
|
#define SYNC_SNAP_RESEND_MS 1000 * 60
|
||||||
|
|
||||||
|
#define SYNC_VND_COMMIT_MIN_MS 1000
|
||||||
|
|
||||||
#define SYNC_MAX_BATCH_SIZE 1
|
#define SYNC_MAX_BATCH_SIZE 1
|
||||||
#define SYNC_INDEX_BEGIN 0
|
#define SYNC_INDEX_BEGIN 0
|
||||||
#define SYNC_INDEX_INVALID -1
|
#define SYNC_INDEX_INVALID -1
|
||||||
#define SYNC_TERM_INVALID -1 // 0xFFFFFFFFFFFFFFFF
|
#define SYNC_TERM_INVALID -1
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SYNC_STRATEGY_NO_SNAPSHOT = 0,
|
SYNC_STRATEGY_NO_SNAPSHOT = 0,
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef enum { HTTP_GZIP, HTTP_FLAT } EHttpCompFlag;
|
typedef enum { HTTP_GZIP, HTTP_FLAT } EHttpCompFlag;
|
||||||
|
|
||||||
int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag);
|
int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,27 +46,73 @@ void taosSetTerminalMode();
|
||||||
int32_t taosGetOldTerminalMode();
|
int32_t taosGetOldTerminalMode();
|
||||||
void taosResetTerminalMode();
|
void taosResetTerminalMode();
|
||||||
|
|
||||||
|
#define STACKSIZE 100
|
||||||
|
|
||||||
#if !defined(WINDOWS)
|
#if !defined(WINDOWS)
|
||||||
#define taosPrintTrace(flags, level, dflag) \
|
#define taosLogTraceToBuf(buf, bufSize, ignoreNum) { \
|
||||||
|
void* array[STACKSIZE]; \
|
||||||
|
int32_t size = backtrace(array, STACKSIZE); \
|
||||||
|
char** strings = backtrace_symbols(array, size); \
|
||||||
|
int32_t offset = 0; \
|
||||||
|
if (strings != NULL) { \
|
||||||
|
offset = snprintf(buf, bufSize - 1, "obtained %d stack frames\n", (ignoreNum > 0) ? size - ignoreNum : size); \
|
||||||
|
for (int32_t i = (ignoreNum > 0) ? ignoreNum : 0; i < size; i++) { \
|
||||||
|
offset += snprintf(buf + offset, bufSize - 1 - offset, "frame:%d, %s\n", (ignoreNum > 0) ? i - ignoreNum : i, strings[i]); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
taosMemoryFree(strings); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define taosPrintTrace(flags, level, dflag, ignoreNum) \
|
||||||
{ \
|
{ \
|
||||||
void* array[100]; \
|
void* array[STACKSIZE]; \
|
||||||
int32_t size = backtrace(array, 100); \
|
int32_t size = backtrace(array, STACKSIZE); \
|
||||||
char** strings = backtrace_symbols(array, size); \
|
char** strings = backtrace_symbols(array, size); \
|
||||||
if (strings != NULL) { \
|
if (strings != NULL) { \
|
||||||
taosPrintLog(flags, level, dflag, "obtained %d stack frames", size); \
|
taosPrintLog(flags, level, dflag, "obtained %d stack frames", (ignoreNum > 0) ? size - ignoreNum : size); \
|
||||||
for (int32_t i = 0; i < size; i++) { \
|
for (int32_t i = (ignoreNum > 0) ? ignoreNum : 0; i < size; i++) { \
|
||||||
taosPrintLog(flags, level, dflag, "frame:%d, %s", i, strings[i]); \
|
taosPrintLog(flags, level, dflag, "frame:%d, %s", (ignoreNum > 0) ? i - ignoreNum : i, strings[i]); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
taosMemoryFree(strings); \
|
taosMemoryFree(strings); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <dbghelp.h>
|
#include <dbghelp.h>
|
||||||
|
|
||||||
#define STACKSIZE 64
|
#define taosLogTraceToBuf(buf, bufSize, ignoreNum) { \
|
||||||
#define taosPrintTrace(flags, level, dflag) \
|
unsigned int i; \
|
||||||
|
void* stack[STACKSIZE]; \
|
||||||
|
unsigned short frames; \
|
||||||
|
SYMBOL_INFO* symbol; \
|
||||||
|
HANDLE process; \
|
||||||
|
int32_t offset = 0; \
|
||||||
|
\
|
||||||
|
process = GetCurrentProcess(); \
|
||||||
|
\
|
||||||
|
SymInitialize(process, NULL, TRUE); \
|
||||||
|
\
|
||||||
|
frames = CaptureStackBackTrace(0, STACKSIZE, stack, NULL); \
|
||||||
|
symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1); \
|
||||||
|
if (symbol != NULL) { \
|
||||||
|
symbol->MaxNameLen = 255; \
|
||||||
|
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \
|
||||||
|
\
|
||||||
|
if (frames > 0) { \
|
||||||
|
offset = snprintf(buf, bufSize - 1, "obtained %d stack frames\n", (ignoreNum > 0) ? frames - ignoreNum : frames); \
|
||||||
|
for (i = (ignoreNum > 0) ? ignoreNum : 0; i < frames; i++) { \
|
||||||
|
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); \
|
||||||
|
offset += snprintf(buf + offset, bufSize - 1 - offset, "frame:%i, %s - 0x%0X\n", (ignoreNum > 0) ? i - ignoreNum : i, symbol->Name, symbol->Address); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
free(symbol); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define taosPrintTrace(flags, level, dflag, ignoreNum) \
|
||||||
{ \
|
{ \
|
||||||
unsigned int i; \
|
unsigned int i; \
|
||||||
void* stack[STACKSIZE]; \
|
void* stack[STACKSIZE]; \
|
||||||
|
@ -85,10 +131,10 @@ void taosResetTerminalMode();
|
||||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \
|
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \
|
||||||
\
|
\
|
||||||
if (frames > 0) { \
|
if (frames > 0) { \
|
||||||
taosPrintLog(flags, level, dflag, "obtained %d stack frames", frames); \
|
taosPrintLog(flags, level, dflag, "obtained %d stack frames\n", (ignoreNum > 0) ? frames - ignoreNum : frames); \
|
||||||
for (i = 0; i < frames; i++) { \
|
for (i = (ignoreNum > 0) ? ignoreNum : 0; i < frames; i++) { \
|
||||||
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); \
|
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); \
|
||||||
taosPrintLog(flags, level, dflag, "frame:%i: %s - 0x%0X", frames - i - 1, symbol->Name, symbol->Address); \
|
taosPrintLog(flags, level, dflag, "frame:%i, %s - 0x%0X\n", (ignoreNum > 0) ? i - ignoreNum : i, symbol->Name, symbol->Address); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
free(symbol); \
|
free(symbol); \
|
||||||
|
|
|
@ -99,6 +99,11 @@ bool taosAssertRelease(bool condition);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void taosLogCrashInfo(char* nodeType, char* pMsg, int64_t msgLen, int signum, void *sigInfo);
|
||||||
|
void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr* pFd);
|
||||||
|
void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile);
|
||||||
|
int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime);
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
|
@ -43,6 +43,9 @@
|
||||||
# Switch for allowing TDengine to collect and report service usage information
|
# Switch for allowing TDengine to collect and report service usage information
|
||||||
# telemetryReporting 1
|
# telemetryReporting 1
|
||||||
|
|
||||||
|
# Switch for allowing TDengine to collect and report crash information
|
||||||
|
# crashReporting 1
|
||||||
|
|
||||||
# The maximum number of vnodes supported by this dnode
|
# The maximum number of vnodes supported by this dnode
|
||||||
# supportVnodes 0
|
# supportVnodes 0
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,7 @@ if [ "$osType" != "Darwin" ]; then
|
||||||
[ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0"
|
[ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0"
|
||||||
|
|
||||||
${csudo}./make-taos-tools-deb.sh ${top_dir} \
|
${csudo}./make-taos-tools-deb.sh ${top_dir} \
|
||||||
${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType}
|
${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} ${verNumberComp}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -298,7 +298,7 @@ if [ "$osType" != "Darwin" ]; then
|
||||||
[ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0"
|
[ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0"
|
||||||
|
|
||||||
${csudo}./make-taos-tools-rpm.sh ${top_dir} \
|
${csudo}./make-taos-tools-rpm.sh ${top_dir} \
|
||||||
${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType}
|
${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} ${verNumberComp}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
|
@ -481,10 +481,10 @@ function install_adapter_config() {
|
||||||
${csudo}mkdir -p ${cfg_install_dir}
|
${csudo}mkdir -p ${cfg_install_dir}
|
||||||
[ -f ${script_dir}/cfg/${adapterName}.toml ] && ${csudo}cp ${script_dir}/cfg/${adapterName}.toml ${cfg_install_dir}
|
[ -f ${script_dir}/cfg/${adapterName}.toml ] && ${csudo}cp ${script_dir}/cfg/${adapterName}.toml ${cfg_install_dir}
|
||||||
[ -f ${cfg_install_dir}/${adapterName}.toml ] && ${csudo}chmod 644 ${cfg_install_dir}/${adapterName}.toml
|
[ -f ${cfg_install_dir}/${adapterName}.toml ] && ${csudo}chmod 644 ${cfg_install_dir}/${adapterName}.toml
|
||||||
fi
|
else
|
||||||
|
|
||||||
[ -f ${script_dir}/cfg/${adapterName}.toml ] &&
|
[ -f ${script_dir}/cfg/${adapterName}.toml ] &&
|
||||||
${csudo}cp -f ${script_dir}/cfg/${adapterName}.toml ${cfg_install_dir}/${adapterName}.toml.new
|
${csudo}cp -f ${script_dir}/cfg/${adapterName}.toml ${cfg_install_dir}/${adapterName}.toml.new
|
||||||
|
fi
|
||||||
|
|
||||||
[ -f ${cfg_install_dir}/${adapterName}.toml ] &&
|
[ -f ${cfg_install_dir}/${adapterName}.toml ] &&
|
||||||
${csudo}ln -s ${cfg_install_dir}/${adapterName}.toml ${install_main_dir}/cfg/${adapterName}.toml
|
${csudo}ln -s ${cfg_install_dir}/${adapterName}.toml ${install_main_dir}/cfg/${adapterName}.toml
|
||||||
|
@ -499,9 +499,10 @@ function install_config() {
|
||||||
${csudo}mkdir -p ${cfg_install_dir}
|
${csudo}mkdir -p ${cfg_install_dir}
|
||||||
[ -f ${script_dir}/cfg/${configFile} ] && ${csudo}cp ${script_dir}/cfg/${configFile} ${cfg_install_dir}
|
[ -f ${script_dir}/cfg/${configFile} ] && ${csudo}cp ${script_dir}/cfg/${configFile} ${cfg_install_dir}
|
||||||
${csudo}chmod 644 ${cfg_install_dir}/*
|
${csudo}chmod 644 ${cfg_install_dir}/*
|
||||||
|
else
|
||||||
|
${csudo}cp -f ${script_dir}/cfg/${configFile} ${cfg_install_dir}/${configFile}.new
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${csudo}cp -f ${script_dir}/cfg/${configFile} ${cfg_install_dir}/${configFile}.new
|
|
||||||
${csudo}ln -s ${cfg_install_dir}/${configFile} ${install_main_dir}/cfg
|
${csudo}ln -s ${cfg_install_dir}/${configFile} ${install_main_dir}/cfg
|
||||||
|
|
||||||
[ ! -z $1 ] && return 0 || : # only install client
|
[ ! -z $1 ] && return 0 || : # only install client
|
||||||
|
|
|
@ -313,6 +313,8 @@ extern SAppInfo appInfo;
|
||||||
extern int32_t clientReqRefPool;
|
extern int32_t clientReqRefPool;
|
||||||
extern int32_t clientConnRefPool;
|
extern int32_t clientConnRefPool;
|
||||||
extern int32_t timestampDeltaLimit;
|
extern int32_t timestampDeltaLimit;
|
||||||
|
extern int64_t lastClusterId;
|
||||||
|
|
||||||
|
|
||||||
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
||||||
|
|
||||||
|
@ -340,6 +342,7 @@ void resetConnectDB(STscObj* pTscObj);
|
||||||
int taos_options_imp(TSDB_OPTION option, const char* str);
|
int taos_options_imp(TSDB_OPTION option, const char* str);
|
||||||
|
|
||||||
void* openTransporter(const char* user, const char* auth, int32_t numOfThreads);
|
void* openTransporter(const char* user, const char* auth, int32_t numOfThreads);
|
||||||
|
void tscStopCrashReport();
|
||||||
|
|
||||||
typedef struct AsyncArg {
|
typedef struct AsyncArg {
|
||||||
SRpcMsg msg;
|
SRpcMsg msg;
|
||||||
|
|
|
@ -28,13 +28,16 @@
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tsched.h"
|
#include "tsched.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
#include "thttp.h"
|
||||||
|
|
||||||
#define TSC_VAR_NOT_RELEASE 1
|
#define TSC_VAR_NOT_RELEASE 1
|
||||||
#define TSC_VAR_RELEASED 0
|
#define TSC_VAR_RELEASED 0
|
||||||
|
|
||||||
SAppInfo appInfo;
|
SAppInfo appInfo;
|
||||||
|
int64_t lastClusterId = 0;
|
||||||
int32_t clientReqRefPool = -1;
|
int32_t clientReqRefPool = -1;
|
||||||
int32_t clientConnRefPool = -1;
|
int32_t clientConnRefPool = -1;
|
||||||
|
int32_t clientStop = 0;
|
||||||
|
|
||||||
int32_t timestampDeltaLimit = 900; // s
|
int32_t timestampDeltaLimit = 900; // s
|
||||||
|
|
||||||
|
@ -385,6 +388,150 @@ void destroyRequest(SRequestObj *pRequest) {
|
||||||
removeRequest(pRequest->self);
|
removeRequest(pRequest->self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosClientCrash(int signum, void *sigInfo, void *context) {
|
||||||
|
taosIgnSignal(SIGTERM);
|
||||||
|
taosIgnSignal(SIGHUP);
|
||||||
|
taosIgnSignal(SIGINT);
|
||||||
|
taosIgnSignal(SIGBREAK);
|
||||||
|
|
||||||
|
#if !defined(WINDOWS)
|
||||||
|
taosIgnSignal(SIGBUS);
|
||||||
|
#endif
|
||||||
|
taosIgnSignal(SIGABRT);
|
||||||
|
taosIgnSignal(SIGFPE);
|
||||||
|
taosIgnSignal(SIGSEGV);
|
||||||
|
|
||||||
|
char *pMsg = NULL;
|
||||||
|
const char *flags = "UTL FATAL ";
|
||||||
|
ELogLevel level = DEBUG_FATAL;
|
||||||
|
int32_t dflag = 255;
|
||||||
|
int64_t msgLen= -1;
|
||||||
|
|
||||||
|
if (tsEnableCrashReport) {
|
||||||
|
if (taosGenCrashJsonMsg(signum, &pMsg, lastClusterId, appInfo.startTime)) {
|
||||||
|
taosPrintLog(flags, level, dflag, "failed to generate crash json msg");
|
||||||
|
goto _return;
|
||||||
|
} else {
|
||||||
|
msgLen = strlen(pMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
taosLogCrashInfo("taos", pMsg, msgLen, signum, sigInfo);
|
||||||
|
|
||||||
|
#ifdef _TD_DARWIN_64
|
||||||
|
exit(signum);
|
||||||
|
#elif defined(WINDOWS)
|
||||||
|
exit(signum);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void crashReportThreadFuncUnexpectedStopped(void) { atomic_store_32(&clientStop, -1); }
|
||||||
|
|
||||||
|
static void *tscCrashReportThreadFp(void *param) {
|
||||||
|
setThreadName("client-crashReport");
|
||||||
|
char filepath[PATH_MAX] = {0};
|
||||||
|
snprintf(filepath, sizeof(filepath), "%s%s.taosCrashLog", tsLogDir, TD_DIRSEP);
|
||||||
|
char *pMsg = NULL;
|
||||||
|
int64_t msgLen = 0;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
bool truncateFile = false;
|
||||||
|
int32_t sleepTime = 200;
|
||||||
|
int32_t reportPeriodNum = 3600 * 1000 / sleepTime;
|
||||||
|
int32_t loopTimes = reportPeriodNum;
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
if (taosCheckCurrentInDll()) {
|
||||||
|
atexit(crashReportThreadFuncUnexpectedStopped);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (clientStop) break;
|
||||||
|
if (loopTimes++ < reportPeriodNum) {
|
||||||
|
taosMsleep(sleepTime);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosReadCrashInfo(filepath, &pMsg, &msgLen, &pFile);
|
||||||
|
if (pMsg && msgLen > 0) {
|
||||||
|
if (taosSendHttpReport(tsTelemServer, tsClientCrashReportUri, tsTelemPort, pMsg, msgLen, HTTP_FLAT) != 0) {
|
||||||
|
tscError("failed to send crash report");
|
||||||
|
if (pFile) {
|
||||||
|
taosReleaseCrashLogFile(pFile, false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tscInfo("succeed to send crash report");
|
||||||
|
truncateFile = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tscDebug("no crash info");
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
|
|
||||||
|
if (pMsg && msgLen > 0) {
|
||||||
|
pMsg = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pFile) {
|
||||||
|
taosReleaseCrashLogFile(pFile, truncateFile);
|
||||||
|
truncateFile = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMsleep(sleepTime);
|
||||||
|
loopTimes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
clientStop = -1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tscCrashReportInit() {
|
||||||
|
if (!tsEnableCrashReport) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TdThreadAttr thAttr;
|
||||||
|
taosThreadAttrInit(&thAttr);
|
||||||
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
TdThread crashReportThread;
|
||||||
|
if (taosThreadCreate(&crashReportThread, &thAttr, tscCrashReportThreadFp, NULL) != 0) {
|
||||||
|
tscError("failed to create crashReport thread since %s", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tscStopCrashReport() {
|
||||||
|
if (!tsEnableCrashReport) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (atomic_val_compare_exchange_32(&clientStop, 0, 1)) {
|
||||||
|
tscDebug("hb thread already stopped");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (atomic_load_32(&clientStop) > 0) {
|
||||||
|
taosMsleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tscSetSignalHandle() {
|
||||||
|
#if !defined(WINDOWS)
|
||||||
|
taosSetSignal(SIGBUS, taosClientCrash);
|
||||||
|
#endif
|
||||||
|
taosSetSignal(SIGABRT, taosClientCrash);
|
||||||
|
taosSetSignal(SIGFPE, taosClientCrash);
|
||||||
|
taosSetSignal(SIGSEGV, taosClientCrash);
|
||||||
|
}
|
||||||
|
|
||||||
void taos_init_imp(void) {
|
void taos_init_imp(void) {
|
||||||
// In the APIs of other program language, taos_cleanup is not available yet.
|
// In the APIs of other program language, taos_cleanup is not available yet.
|
||||||
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
||||||
|
@ -392,6 +539,10 @@ void taos_init_imp(void) {
|
||||||
errno = TSDB_CODE_SUCCESS;
|
errno = TSDB_CODE_SUCCESS;
|
||||||
taosSeedRand(taosGetTimestampSec());
|
taosSeedRand(taosGetTimestampSec());
|
||||||
|
|
||||||
|
appInfo.pid = taosGetPId();
|
||||||
|
appInfo.startTime = taosGetTimestampMs();
|
||||||
|
appInfo.pInstMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
deltaToUtcInitOnce();
|
deltaToUtcInitOnce();
|
||||||
|
|
||||||
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||||
|
@ -404,6 +555,8 @@ void taos_init_imp(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tscSetSignalHandle();
|
||||||
|
|
||||||
initQueryModuleMsgHandle();
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
if (taosConvInit() != 0) {
|
if (taosConvInit() != 0) {
|
||||||
|
@ -433,9 +586,8 @@ void taos_init_imp(void) {
|
||||||
taosGetAppName(appInfo.appName, NULL);
|
taosGetAppName(appInfo.appName, NULL);
|
||||||
taosThreadMutexInit(&appInfo.mutex, NULL);
|
taosThreadMutexInit(&appInfo.mutex, NULL);
|
||||||
|
|
||||||
appInfo.pid = taosGetPId();
|
tscCrashReportInit();
|
||||||
appInfo.startTime = taosGetTimestampMs();
|
|
||||||
appInfo.pInstMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
|
||||||
tscDebug("client is initialized successfully");
|
tscDebug("client is initialized successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,8 @@ void taos_cleanup(void) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tscStopCrashReport();
|
||||||
|
|
||||||
int32_t id = clientReqRefPool;
|
int32_t id = clientReqRefPool;
|
||||||
clientReqRefPool = -1;
|
clientReqRefPool = -1;
|
||||||
taosCloseRef(id);
|
taosCloseRef(id);
|
||||||
|
|
|
@ -119,6 +119,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
|
|
||||||
// update the appInstInfo
|
// update the appInstInfo
|
||||||
pTscObj->pAppInfo->clusterId = connectRsp.clusterId;
|
pTscObj->pAppInfo->clusterId = connectRsp.clusterId;
|
||||||
|
lastClusterId = connectRsp.clusterId;
|
||||||
|
|
||||||
pTscObj->connType = connectRsp.connType;
|
pTscObj->connType = connectRsp.connType;
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,7 @@ typedef struct {
|
||||||
SSmlMsgBuf msgBuf;
|
SSmlMsgBuf msgBuf;
|
||||||
SHashObj *dumplicateKey; // for dumplicate key
|
SHashObj *dumplicateKey; // for dumplicate key
|
||||||
SArray *colsContainer; // for cols parse, if dataFormat == false
|
SArray *colsContainer; // for cols parse, if dataFormat == false
|
||||||
|
int32_t uid; // used for automatic create child table
|
||||||
|
|
||||||
cJSON *root; // for parse json
|
cJSON *root; // for parse json
|
||||||
} SSmlHandle;
|
} SSmlHandle;
|
||||||
|
@ -2155,13 +2156,11 @@ static int32_t smlParseInfluxLine(SSmlHandle *info, const char *sql, const int l
|
||||||
(*oneTable)->sTableNameLen = elements.measureLen;
|
(*oneTable)->sTableNameLen = elements.measureLen;
|
||||||
if (strlen((*oneTable)->childTableName) == 0) {
|
if (strlen((*oneTable)->childTableName) == 0) {
|
||||||
RandTableName rName = {(*oneTable)->tags, (*oneTable)->sTableName, (uint8_t)(*oneTable)->sTableNameLen,
|
RandTableName rName = {(*oneTable)->tags, (*oneTable)->sTableName, (uint8_t)(*oneTable)->sTableNameLen,
|
||||||
(*oneTable)->childTableName, 0};
|
(*oneTable)->childTableName};
|
||||||
|
|
||||||
buildChildTableName(&rName);
|
buildChildTableName(&rName);
|
||||||
(*oneTable)->uid = rName.uid;
|
|
||||||
} else {
|
|
||||||
(*oneTable)->uid = *(uint64_t *)((*oneTable)->childTableName);
|
|
||||||
}
|
}
|
||||||
|
(*oneTable)->uid = info->uid++;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSmlSTableMeta **tableMeta = (SSmlSTableMeta **)taosHashGet(info->superTables, elements.measure, elements.measureLen);
|
SSmlSTableMeta **tableMeta = (SSmlSTableMeta **)taosHashGet(info->superTables, elements.measure, elements.measureLen);
|
||||||
|
@ -2226,11 +2225,8 @@ static int32_t smlParseTelnetLine(SSmlHandle *info, void *data, const int len) {
|
||||||
taosHashClear(info->dumplicateKey);
|
taosHashClear(info->dumplicateKey);
|
||||||
|
|
||||||
if (strlen(tinfo->childTableName) == 0) {
|
if (strlen(tinfo->childTableName) == 0) {
|
||||||
RandTableName rName = {tinfo->tags, tinfo->sTableName, (uint8_t)tinfo->sTableNameLen, tinfo->childTableName, 0};
|
RandTableName rName = {tinfo->tags, tinfo->sTableName, (uint8_t)tinfo->sTableNameLen, tinfo->childTableName};
|
||||||
buildChildTableName(&rName);
|
buildChildTableName(&rName);
|
||||||
tinfo->uid = rName.uid;
|
|
||||||
} else {
|
|
||||||
tinfo->uid = *(uint64_t *)(tinfo->childTableName); // generate uid by name simple
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasTable = true;
|
bool hasTable = true;
|
||||||
|
@ -2239,6 +2235,7 @@ static int32_t smlParseTelnetLine(SSmlHandle *info, void *data, const int len) {
|
||||||
if (!oneTable) {
|
if (!oneTable) {
|
||||||
taosHashPut(info->childTables, tinfo->childTableName, strlen(tinfo->childTableName), &tinfo, POINTER_BYTES);
|
taosHashPut(info->childTables, tinfo->childTableName, strlen(tinfo->childTableName), &tinfo, POINTER_BYTES);
|
||||||
oneTable = &tinfo;
|
oneTable = &tinfo;
|
||||||
|
tinfo->uid = info->uid++;
|
||||||
hasTable = false;
|
hasTable = false;
|
||||||
} else {
|
} else {
|
||||||
smlDestroyTableInfo(info, tinfo);
|
smlDestroyTableInfo(info, tinfo);
|
||||||
|
|
|
@ -67,6 +67,8 @@ static const SSysDbTableSchema clusterSchema[] = {
|
||||||
{.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
{.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||||
{.name = "uptime", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
{.name = "uptime", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true},
|
||||||
|
{.name = "version", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||||
|
{.name = "expire_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SSysDbTableSchema userDBSchema[] = {
|
static const SSysDbTableSchema userDBSchema[] = {
|
||||||
|
|
|
@ -60,6 +60,9 @@ int32_t tsElectInterval = 25 * 1000;
|
||||||
int32_t tsHeartbeatInterval = 1000;
|
int32_t tsHeartbeatInterval = 1000;
|
||||||
int32_t tsHeartbeatTimeout = 20 * 1000;
|
int32_t tsHeartbeatTimeout = 20 * 1000;
|
||||||
|
|
||||||
|
// vnode
|
||||||
|
int64_t tsVndCommitMaxIntervalMs = 60 * 1000;
|
||||||
|
|
||||||
// monitor
|
// monitor
|
||||||
bool tsEnableMonitor = true;
|
bool tsEnableMonitor = true;
|
||||||
int32_t tsMonitorInterval = 30;
|
int32_t tsMonitorInterval = 30;
|
||||||
|
@ -73,6 +76,11 @@ bool tsEnableTelem = true;
|
||||||
int32_t tsTelemInterval = 43200;
|
int32_t tsTelemInterval = 43200;
|
||||||
char tsTelemServer[TSDB_FQDN_LEN] = "telemetry.taosdata.com";
|
char tsTelemServer[TSDB_FQDN_LEN] = "telemetry.taosdata.com";
|
||||||
uint16_t tsTelemPort = 80;
|
uint16_t tsTelemPort = 80;
|
||||||
|
char* tsTelemUri = "/report";
|
||||||
|
|
||||||
|
bool tsEnableCrashReport = true;
|
||||||
|
char* tsClientCrashReportUri = "/ccrashreport";
|
||||||
|
char* tsSvrCrashReportUri = "/dcrashreport";
|
||||||
|
|
||||||
// schemaless
|
// schemaless
|
||||||
char tsSmlTagName[TSDB_COL_NAME_LEN] = "_tag_null";
|
char tsSmlTagName[TSDB_COL_NAME_LEN] = "_tag_null";
|
||||||
|
@ -202,7 +210,9 @@ int32_t taosSetTfsCfg(SConfig *pCfg) {
|
||||||
int32_t taosSetTfsCfg(SConfig *pCfg);
|
int32_t taosSetTfsCfg(SConfig *pCfg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct SConfig *taosGetCfg() { return tsCfg; }
|
struct SConfig *taosGetCfg() {
|
||||||
|
return tsCfg;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile,
|
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile,
|
||||||
char *apolloUrl) {
|
char *apolloUrl) {
|
||||||
|
@ -314,6 +324,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
||||||
if (cfgAddInt32(pCfg, "maxMemUsedByInsert", tsMaxMemUsedByInsert, 1, INT32_MAX, true) != 0) return -1;
|
if (cfgAddInt32(pCfg, "maxMemUsedByInsert", tsMaxMemUsedByInsert, 1, INT32_MAX, true) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "maxRetryWaitTime", tsMaxRetryWaitTime, 0, 86400000, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "maxRetryWaitTime", tsMaxRetryWaitTime, 0, 86400000, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "useAdapter", tsUseAdapter, true) != 0) return -1;
|
if (cfgAddBool(pCfg, "useAdapter", tsUseAdapter, true) != 0) return -1;
|
||||||
|
if (cfgAddBool(pCfg, "crashReporting", tsEnableCrashReport, true) != 0) return -1;
|
||||||
|
|
||||||
tsNumOfTaskQueueThreads = tsNumOfCores / 2;
|
tsNumOfTaskQueueThreads = tsNumOfCores / 2;
|
||||||
tsNumOfTaskQueueThreads = TMAX(tsNumOfTaskQueueThreads, 4);
|
tsNumOfTaskQueueThreads = TMAX(tsNumOfTaskQueueThreads, 4);
|
||||||
|
@ -377,7 +388,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
||||||
if (cfgAddInt32(pCfg, "queryRspPolicy", tsQueryRspPolicy, 0, 1, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "queryRspPolicy", tsQueryRspPolicy, 0, 1, 0) != 0) return -1;
|
||||||
|
|
||||||
tsNumOfRpcThreads = tsNumOfCores / 2;
|
tsNumOfRpcThreads = tsNumOfCores / 2;
|
||||||
tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, 4);
|
tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 1, TSDB_MAX_RPC_THREADS);
|
||||||
if (cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "numOfRpcThreads", tsNumOfRpcThreads, 1, 1024, 0) != 0) return -1;
|
||||||
|
|
||||||
tsNumOfCommitThreads = tsNumOfCores / 2;
|
tsNumOfCommitThreads = tsNumOfCores / 2;
|
||||||
|
@ -427,6 +438,8 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
||||||
if (cfgAddInt32(pCfg, "syncHeartbeatInterval", tsHeartbeatInterval, 10, 1000 * 60 * 24 * 2, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "syncHeartbeatInterval", tsHeartbeatInterval, 10, 1000 * 60 * 24 * 2, 0) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "syncHeartbeatTimeout", tsHeartbeatTimeout, 10, 1000 * 60 * 24 * 2, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "syncHeartbeatTimeout", tsHeartbeatTimeout, 10, 1000 * 60 * 24 * 2, 0) != 0) return -1;
|
||||||
|
|
||||||
|
if (cfgAddInt64(pCfg, "vndCommitMaxInterval", tsVndCommitMaxIntervalMs, 1000, 1000 * 60 * 60, 0) != 0) return -1;
|
||||||
|
|
||||||
if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 200000, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 200000, 0) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "monitorFqdn", tsMonitorFqdn, 0) != 0) return -1;
|
if (cfgAddString(pCfg, "monitorFqdn", tsMonitorFqdn, 0) != 0) return -1;
|
||||||
|
@ -434,6 +447,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
||||||
if (cfgAddInt32(pCfg, "monitorMaxLogs", tsMonitorMaxLogs, 1, 1000000, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "monitorMaxLogs", tsMonitorMaxLogs, 1, 1000000, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "monitorComp", tsMonitorComp, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "monitorComp", tsMonitorComp, 0) != 0) return -1;
|
||||||
|
|
||||||
|
if (cfgAddBool(pCfg, "crashReporting", tsEnableCrashReport, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "telemetryReporting", tsEnableTelem, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "telemetryReporting", tsEnableTelem, 0) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "telemetryInterval", tsTelemInterval, 1, 200000, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "telemetryInterval", tsTelemInterval, 1, 200000, 0) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "telemetryServer", tsTelemServer, 0) != 0) return -1;
|
if (cfgAddString(pCfg, "telemetryServer", tsTelemServer, 0) != 0) return -1;
|
||||||
|
@ -665,6 +679,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
||||||
tsQueryUseNodeAllocator = cfgGetItem(pCfg, "queryUseNodeAllocator")->bval;
|
tsQueryUseNodeAllocator = cfgGetItem(pCfg, "queryUseNodeAllocator")->bval;
|
||||||
tsKeepColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
tsKeepColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
||||||
tsUseAdapter = cfgGetItem(pCfg, "useAdapter")->bval;
|
tsUseAdapter = cfgGetItem(pCfg, "useAdapter")->bval;
|
||||||
|
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
||||||
|
|
||||||
tsMaxRetryWaitTime = cfgGetItem(pCfg, "maxRetryWaitTime")->i32;
|
tsMaxRetryWaitTime = cfgGetItem(pCfg, "maxRetryWaitTime")->i32;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -715,7 +730,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
tsNumOfSnodeWriteThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32;
|
tsNumOfSnodeWriteThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32;
|
||||||
tsRpcQueueMemoryAllowed = cfgGetItem(pCfg, "rpcQueueMemoryAllowed")->i64;
|
tsRpcQueueMemoryAllowed = cfgGetItem(pCfg, "rpcQueueMemoryAllowed")->i64;
|
||||||
|
|
||||||
tsSIMDBuiltins = (bool) cfgGetItem(pCfg, "SIMD-builtins")->bval;
|
tsSIMDBuiltins = (bool)cfgGetItem(pCfg, "SIMD-builtins")->bval;
|
||||||
|
|
||||||
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
|
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
|
||||||
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
|
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
|
||||||
|
@ -726,6 +741,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
tsQueryRspPolicy = cfgGetItem(pCfg, "queryRspPolicy")->i32;
|
tsQueryRspPolicy = cfgGetItem(pCfg, "queryRspPolicy")->i32;
|
||||||
|
|
||||||
tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval;
|
tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval;
|
||||||
|
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
||||||
tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32;
|
tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32;
|
||||||
tstrncpy(tsTelemServer, cfgGetItem(pCfg, "telemetryServer")->str, TSDB_FQDN_LEN);
|
tstrncpy(tsTelemServer, cfgGetItem(pCfg, "telemetryServer")->str, TSDB_FQDN_LEN);
|
||||||
tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32;
|
tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32;
|
||||||
|
@ -743,6 +759,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
tsHeartbeatInterval = cfgGetItem(pCfg, "syncHeartbeatInterval")->i32;
|
tsHeartbeatInterval = cfgGetItem(pCfg, "syncHeartbeatInterval")->i32;
|
||||||
tsHeartbeatTimeout = cfgGetItem(pCfg, "syncHeartbeatTimeout")->i32;
|
tsHeartbeatTimeout = cfgGetItem(pCfg, "syncHeartbeatTimeout")->i32;
|
||||||
|
|
||||||
|
tsVndCommitMaxIntervalMs = cfgGetItem(pCfg, "vndCommitMaxInterval")->i64;
|
||||||
|
|
||||||
tsStartUdfd = cfgGetItem(pCfg, "udf")->bval;
|
tsStartUdfd = cfgGetItem(pCfg, "udf")->bval;
|
||||||
tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs));
|
tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs));
|
||||||
tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath));
|
tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath));
|
||||||
|
@ -795,6 +813,8 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) {
|
||||||
tsCountAlwaysReturnValue = cfgGetItem(pCfg, "countAlwaysReturnValue")->i32;
|
tsCountAlwaysReturnValue = cfgGetItem(pCfg, "countAlwaysReturnValue")->i32;
|
||||||
} else if (strcasecmp("cDebugFlag", name) == 0) {
|
} else if (strcasecmp("cDebugFlag", name) == 0) {
|
||||||
cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32;
|
cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32;
|
||||||
|
} else if (strcasecmp("crashReporting", name) == 0) {
|
||||||
|
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -330,5 +330,4 @@ void buildChildTableName(RandTableName* rName) {
|
||||||
strcat(rName->ctbShortName, temp);
|
strcat(rName->ctbShortName, temp);
|
||||||
}
|
}
|
||||||
taosStringBuilderDestroy(&sb);
|
taosStringBuilderDestroy(&sb);
|
||||||
rName->uid = *(uint64_t*)(context.digest);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ static struct {
|
||||||
char apolloUrl[PATH_MAX];
|
char apolloUrl[PATH_MAX];
|
||||||
const char **envCmd;
|
const char **envCmd;
|
||||||
SArray *pArgs; // SConfigPair
|
SArray *pArgs; // SConfigPair
|
||||||
|
int64_t startTime;
|
||||||
} global = {0};
|
} global = {0};
|
||||||
|
|
||||||
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { taosSetAllDebugFlag(143, true); }
|
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { taosSetAllDebugFlag(143, true); }
|
||||||
|
@ -67,23 +68,71 @@ static void dmStopDnode(int signum, void *sigInfo, void *context) {
|
||||||
dmStop();
|
dmStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dmLogCrash(int signum, void *sigInfo, void *context) {
|
||||||
|
taosIgnSignal(SIGTERM);
|
||||||
|
taosIgnSignal(SIGHUP);
|
||||||
|
taosIgnSignal(SIGINT);
|
||||||
|
taosIgnSignal(SIGBREAK);
|
||||||
|
|
||||||
|
#ifndef WINDOWS
|
||||||
|
taosIgnSignal(SIGBUS);
|
||||||
|
#endif
|
||||||
|
taosIgnSignal(SIGABRT);
|
||||||
|
taosIgnSignal(SIGFPE);
|
||||||
|
taosIgnSignal(SIGSEGV);
|
||||||
|
|
||||||
|
char *pMsg = NULL;
|
||||||
|
const char *flags = "UTL FATAL ";
|
||||||
|
ELogLevel level = DEBUG_FATAL;
|
||||||
|
int32_t dflag = 255;
|
||||||
|
int64_t msgLen= -1;
|
||||||
|
|
||||||
|
if (tsEnableCrashReport) {
|
||||||
|
if (taosGenCrashJsonMsg(signum, &pMsg, dmGetClusterId(), global.startTime)) {
|
||||||
|
taosPrintLog(flags, level, dflag, "failed to generate crash json msg");
|
||||||
|
goto _return;
|
||||||
|
} else {
|
||||||
|
msgLen = strlen(pMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
taosLogCrashInfo("taosd", pMsg, msgLen, signum, sigInfo);
|
||||||
|
|
||||||
|
#ifdef _TD_DARWIN_64
|
||||||
|
exit(signum);
|
||||||
|
#elif defined(WINDOWS)
|
||||||
|
exit(signum);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void dmSetSignalHandle() {
|
static void dmSetSignalHandle() {
|
||||||
taosSetSignal(SIGUSR1, dmSetDebugFlag);
|
taosSetSignal(SIGUSR1, dmSetDebugFlag);
|
||||||
taosSetSignal(SIGUSR2, dmSetAssert);
|
taosSetSignal(SIGUSR2, dmSetAssert);
|
||||||
taosSetSignal(SIGTERM, dmStopDnode);
|
taosSetSignal(SIGTERM, dmStopDnode);
|
||||||
taosSetSignal(SIGHUP, dmStopDnode);
|
taosSetSignal(SIGHUP, dmStopDnode);
|
||||||
taosSetSignal(SIGINT, dmStopDnode);
|
taosSetSignal(SIGINT, dmStopDnode);
|
||||||
taosSetSignal(SIGABRT, dmStopDnode);
|
|
||||||
taosSetSignal(SIGBREAK, dmStopDnode);
|
taosSetSignal(SIGBREAK, dmStopDnode);
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
taosSetSignal(SIGTSTP, dmStopDnode);
|
taosSetSignal(SIGTSTP, dmStopDnode);
|
||||||
taosSetSignal(SIGQUIT, dmStopDnode);
|
taosSetSignal(SIGQUIT, dmStopDnode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WINDOWS
|
||||||
|
taosSetSignal(SIGBUS, dmLogCrash);
|
||||||
|
#endif
|
||||||
|
taosSetSignal(SIGABRT, dmLogCrash);
|
||||||
|
taosSetSignal(SIGFPE, dmLogCrash);
|
||||||
|
taosSetSignal(SIGSEGV, dmLogCrash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
|
global.startTime = taosGetTimestampMs();
|
||||||
|
|
||||||
int32_t cmdEnvIndex = 0;
|
int32_t cmdEnvIndex = 0;
|
||||||
if (argc < 2) return 0;
|
if (argc < 2) return 0;
|
||||||
|
|
||||||
global.envCmd = taosMemoryMalloc((argc - 1) * sizeof(char *));
|
global.envCmd = taosMemoryMalloc((argc - 1) * sizeof(char *));
|
||||||
memset(global.envCmd, 0, (argc - 1) * sizeof(char *));
|
memset(global.envCmd, 0, (argc - 1) * sizeof(char *));
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ typedef struct SDnodeMgmt {
|
||||||
const char *name;
|
const char *name;
|
||||||
TdThread statusThread;
|
TdThread statusThread;
|
||||||
TdThread monitorThread;
|
TdThread monitorThread;
|
||||||
|
TdThread crashReportThread;
|
||||||
SSingleWorker mgmtWorker;
|
SSingleWorker mgmtWorker;
|
||||||
ProcessCreateNodeFp processCreateNodeFp;
|
ProcessCreateNodeFp processCreateNodeFp;
|
||||||
ProcessDropNodeFp processDropNodeFp;
|
ProcessDropNodeFp processDropNodeFp;
|
||||||
|
@ -55,6 +56,8 @@ int32_t dmStartStatusThread(SDnodeMgmt *pMgmt);
|
||||||
void dmStopStatusThread(SDnodeMgmt *pMgmt);
|
void dmStopStatusThread(SDnodeMgmt *pMgmt);
|
||||||
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt);
|
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt);
|
||||||
void dmStopMonitorThread(SDnodeMgmt *pMgmt);
|
void dmStopMonitorThread(SDnodeMgmt *pMgmt);
|
||||||
|
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt);
|
||||||
|
void dmStopCrashReportThread(SDnodeMgmt *pMgmt);
|
||||||
int32_t dmStartWorker(SDnodeMgmt *pMgmt);
|
int32_t dmStartWorker(SDnodeMgmt *pMgmt);
|
||||||
void dmStopWorker(SDnodeMgmt *pMgmt);
|
void dmStopWorker(SDnodeMgmt *pMgmt);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
|
||||||
if (dmStartMonitorThread(pMgmt) != 0) {
|
if (dmStartMonitorThread(pMgmt) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (dmStartCrashReportThread(pMgmt) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +33,7 @@ static void dmStopMgmt(SDnodeMgmt *pMgmt) {
|
||||||
pMgmt->pData->stopped = true;
|
pMgmt->pData->stopped = true;
|
||||||
dmStopMonitorThread(pMgmt);
|
dmStopMonitorThread(pMgmt);
|
||||||
dmStopStatusThread(pMgmt);
|
dmStopStatusThread(pMgmt);
|
||||||
|
dmStopCrashReportThread(pMgmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dmInt.h"
|
#include "dmInt.h"
|
||||||
|
#include "thttp.h"
|
||||||
|
|
||||||
static void *dmStatusThreadFp(void *param) {
|
static void *dmStatusThreadFp(void *param) {
|
||||||
SDnodeMgmt *pMgmt = param;
|
SDnodeMgmt *pMgmt = param;
|
||||||
|
@ -63,6 +64,63 @@ static void *dmMonitorThreadFp(void *param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *dmCrashReportThreadFp(void *param) {
|
||||||
|
SDnodeMgmt *pMgmt = param;
|
||||||
|
int64_t lastTime = taosGetTimestampMs();
|
||||||
|
setThreadName("dnode-crashReport");
|
||||||
|
char filepath[PATH_MAX] = {0};
|
||||||
|
snprintf(filepath, sizeof(filepath), "%s%s.taosdCrashLog", tsLogDir, TD_DIRSEP);
|
||||||
|
char *pMsg = NULL;
|
||||||
|
int64_t msgLen = 0;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
bool truncateFile = false;
|
||||||
|
int32_t sleepTime = 200;
|
||||||
|
int32_t reportPeriodNum = 3600 * 1000 / sleepTime;;
|
||||||
|
int32_t loopTimes = reportPeriodNum;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (pMgmt->pData->dropped || pMgmt->pData->stopped) break;
|
||||||
|
if (loopTimes++ < reportPeriodNum) {
|
||||||
|
taosMsleep(sleepTime);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosReadCrashInfo(filepath, &pMsg, &msgLen, &pFile);
|
||||||
|
if (pMsg && msgLen > 0) {
|
||||||
|
if (taosSendHttpReport(tsTelemServer, tsSvrCrashReportUri, tsTelemPort, pMsg, msgLen, HTTP_FLAT) != 0) {
|
||||||
|
dError("failed to send crash report");
|
||||||
|
if (pFile) {
|
||||||
|
taosReleaseCrashLogFile(pFile, false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dInfo("succeed to send crash report");
|
||||||
|
truncateFile = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dDebug("no crash info");
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
|
|
||||||
|
if (pMsg && msgLen > 0) {
|
||||||
|
pMsg = NULL;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pFile) {
|
||||||
|
taosReleaseCrashLogFile(pFile, truncateFile);
|
||||||
|
truncateFile = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMsleep(sleepTime);
|
||||||
|
loopTimes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
|
@ -105,6 +163,36 @@ void dmStopMonitorThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||||
|
if (!tsEnableCrashReport) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TdThreadAttr thAttr;
|
||||||
|
taosThreadAttrInit(&thAttr);
|
||||||
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
|
||||||
|
dError("failed to create crashReport thread since %s", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
tmsgReportStartup("dnode-crashReport", "initialized");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dmStopCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||||
|
if (!tsEnableCrashReport) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosCheckPthreadValid(pMgmt->crashReportThread)) {
|
||||||
|
taosThreadJoin(pMgmt->crashReportThread, NULL);
|
||||||
|
taosThreadClear(&pMgmt->crashReportThread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
SDnodeMgmt *pMgmt = pInfo->ahandle;
|
SDnodeMgmt *pMgmt = pInfo->ahandle;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
|
@ -15,171 +15,166 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mmInt.h"
|
#include "mmInt.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
|
static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
tjsonGetInt32ValueFromDouble(pJson, "deployed", pOption->deploy, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetInt32ValueFromDouble(pJson, "selfIndex", pOption->selfIndex, code);
|
||||||
|
if (code < 0) return 0;
|
||||||
|
|
||||||
|
SJson *replicas = tjsonGetObjectItem(pJson, "replicas");
|
||||||
|
if (replicas == NULL) return 0;
|
||||||
|
pOption->numOfReplicas = tjsonGetArraySize(replicas);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pOption->numOfReplicas; ++i) {
|
||||||
|
SJson *replica = tjsonGetArrayItem(replicas, i);
|
||||||
|
if (replica == NULL) return -1;
|
||||||
|
|
||||||
|
SReplica *pReplica = pOption->replicas + i;
|
||||||
|
tjsonGetInt32ValueFromDouble(replica, "id", pReplica->id, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
code = tjsonGetStringValue(replica, "fqdn", pReplica->fqdn);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetUInt16ValueFromDouble(replica, "port", pReplica->port, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
int32_t code = TSDB_CODE_INVALID_JSON_FORMAT;
|
int32_t code = -1;
|
||||||
int32_t len = 0;
|
|
||||||
int32_t maxLen = 4096;
|
|
||||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
|
||||||
cJSON *root = NULL;
|
|
||||||
char file[PATH_MAX] = {0};
|
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
|
char *pData = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||||
|
|
||||||
|
if (taosStatFile(file, NULL, NULL) < 0) {
|
||||||
|
dInfo("mnode file:%s not exist", file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = 0;
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to open mnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = (int32_t)taosReadFile(pFile, content, maxLen);
|
int64_t size = 0;
|
||||||
if (len <= 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
dError("failed to read %s since content is null", file);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content[len] = 0;
|
pData = taosMemoryMalloc(size + 1);
|
||||||
root = cJSON_Parse(content);
|
if (pData == NULL) {
|
||||||
if (root == NULL) {
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
dError("failed to read %s since invalid json format", file);
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
if (!deployed || deployed->type != cJSON_Number) {
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read %s since deployed not found", file);
|
dError("failed to read mnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
pOption->deploy = deployed->valueint;
|
|
||||||
|
|
||||||
cJSON *selfIndex = cJSON_GetObjectItem(root, "selfIndex");
|
|
||||||
if (selfIndex) {
|
|
||||||
if (selfIndex->type != cJSON_Number) {
|
|
||||||
dError("failed to read %s since selfIndex not found", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
pOption->selfIndex = selfIndex->valueint;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *replicas = cJSON_GetObjectItem(root, "replicas");
|
|
||||||
if (replicas) {
|
|
||||||
if (replicas->type != cJSON_Array) {
|
|
||||||
dError("failed to read %s since replicas not found", file);
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numOfReplicas = cJSON_GetArraySize(replicas);
|
pData[size] = '\0';
|
||||||
if (numOfReplicas <= 0) {
|
|
||||||
dError("failed to read %s since numOfReplicas:%d invalid", file, numOfReplicas);
|
pJson = tjsonParse(pData);
|
||||||
|
if (pJson == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
pOption->numOfReplicas = numOfReplicas;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfReplicas; ++i) {
|
if (mmDecodeOption(pJson, pOption) < 0) {
|
||||||
SReplica *pReplica = pOption->replicas + i;
|
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
|
||||||
cJSON *replica = cJSON_GetArrayItem(replicas, i);
|
|
||||||
if (replica == NULL) break;
|
|
||||||
|
|
||||||
cJSON *id = cJSON_GetObjectItem(replica, "id");
|
|
||||||
if (id) {
|
|
||||||
if (id->type != cJSON_Number) {
|
|
||||||
dError("failed to read %s since id not found", file);
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (pReplica) {
|
|
||||||
pReplica->id = id->valueint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *fqdn = cJSON_GetObjectItem(replica, "fqdn");
|
|
||||||
if (fqdn) {
|
|
||||||
if (fqdn->type != cJSON_String || fqdn->valuestring == NULL) {
|
|
||||||
dError("failed to read %s since fqdn not found", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
if (pReplica) {
|
|
||||||
tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *port = cJSON_GetObjectItem(replica, "port");
|
|
||||||
if (port) {
|
|
||||||
if (port->type != cJSON_Number) {
|
|
||||||
dError("failed to read %s since port not found", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
if (pReplica) {
|
|
||||||
pReplica->port = (uint16_t)port->valueint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
dInfo("succceed to read mnode file %s", file);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (content != NULL) taosMemoryFree(content);
|
if (pData != NULL) taosMemoryFree(pData);
|
||||||
if (root != NULL) cJSON_Delete(root);
|
if (pJson != NULL) cJSON_Delete(pJson);
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
if (code == 0) {
|
|
||||||
dDebug("succcessed to read file %s, deployed:%d", file, pOption->deploy);
|
|
||||||
}
|
|
||||||
|
|
||||||
terrno = code;
|
if (code != 0) {
|
||||||
|
dError("failed to read mnode file:%s since %s", file, terrstr());
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mmEncodeOption(SJson *pJson, const SMnodeOpt *pOption) {
|
||||||
|
if (pOption->deploy && pOption->numOfReplicas > 0) {
|
||||||
|
if (tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex) < 0) return -1;
|
||||||
|
|
||||||
|
SJson *replicas = tjsonCreateArray();
|
||||||
|
if (replicas == NULL) return -1;
|
||||||
|
if (tjsonAddItemToObject(pJson, "replicas", replicas) < 0) return -1;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pOption->numOfReplicas; ++i) {
|
||||||
|
SJson *replica = tjsonCreateObject();
|
||||||
|
if (replica == NULL) return -1;
|
||||||
|
|
||||||
|
const SReplica *pReplica = pOption->replicas + i;
|
||||||
|
if (tjsonAddDoubleToObject(replica, "id", pReplica->id) < 0) return -1;
|
||||||
|
if (tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn) < 0) return -1;
|
||||||
|
if (tjsonAddDoubleToObject(replica, "port", pReplica->port) < 0) return -1;
|
||||||
|
if (tjsonAddItemToArray(replicas, replica) < 0) return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy) < 0) return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
|
int32_t code = -1;
|
||||||
|
char *buffer = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
||||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
if (pFile == NULL) {
|
pJson = tjsonCreateObject();
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
if (pJson == NULL) goto _OVER;
|
||||||
dError("failed to write %s since %s", file, terrstr());
|
if (mmEncodeOption(pJson, pOption) != 0) goto _OVER;
|
||||||
return -1;
|
buffer = tjsonToString(pJson);
|
||||||
}
|
if (buffer == NULL) goto _OVER;
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
int32_t len = 0;
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
int32_t maxLen = 4096;
|
if (pFile == NULL) goto _OVER;
|
||||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
int32_t len = strlen(buffer);
|
||||||
if (pOption->deploy && pOption->numOfReplicas > 0) {
|
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||||
len += snprintf(content + len, maxLen - len, " \"selfIndex\": %d,\n", pOption->selfIndex);
|
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||||
len += snprintf(content + len, maxLen - len, " \"replicas\": [{\n");
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pOption->numOfReplicas; ++i) {
|
|
||||||
const SReplica *pReplica = pOption->replicas + i;
|
|
||||||
if (pReplica != NULL && pReplica->id > 0) {
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port);
|
|
||||||
}
|
|
||||||
if (i < pOption->numOfReplicas - 1) {
|
|
||||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
|
||||||
} else {
|
|
||||||
len += snprintf(content + len, maxLen - len, " }],\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", pOption->deploy);
|
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
|
||||||
|
|
||||||
taosWriteFile(pFile, content, len);
|
|
||||||
taosFsyncFile(pFile);
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
taosMemoryFree(content);
|
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
code = 0;
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
||||||
dError("failed to rename %s since %s", file, terrstr());
|
|
||||||
return -1;
|
_OVER:
|
||||||
|
if (pJson != NULL) tjsonDelete(pJson);
|
||||||
|
if (buffer != NULL) taosMemoryFree(buffer);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, terrstr(), pOption->deploy);
|
||||||
}
|
}
|
||||||
|
return code;
|
||||||
dDebug("succeed to write %s, deployed:%d", realfile, pOption->deploy);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "vmInt.h"
|
#include "vmInt.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
||||||
|
|
||||||
|
@ -144,65 +145,66 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t numOfVnodes) {
|
||||||
int32_t code = 0;
|
SJson *vnodes = tjsonCreateArray();
|
||||||
char file[PATH_MAX] = {0};
|
if (vnodes == NULL) return -1;
|
||||||
char realfile[PATH_MAX] = {0};
|
if (tjsonAddItemToObject(pJson, "vnodes", vnodes) < 0) return -1;
|
||||||
snprintf(file, sizeof(file), "%s%svnodes.json.bak", pMgmt->path, TD_DIRSEP);
|
|
||||||
snprintf(realfile, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to write %s since %s", file, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t numOfVnodes = 0;
|
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
|
||||||
if (ppVnodes == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
code = -1;
|
|
||||||
dError("failed to write %s while get vnodelist", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
int32_t maxLen = MAX_CONTENT_LEN;
|
|
||||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
|
||||||
if (content == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
code = -1;
|
|
||||||
dError("failed to write %s while malloc content", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"vnodes\": [\n");
|
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
SVnodeObj *pVnode = ppVnodes[i];
|
SVnodeObj *pVnode = ppVnodes[i];
|
||||||
if (pVnode == NULL) continue;
|
if (pVnode == NULL) continue;
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, " {\n");
|
SJson *vnode = tjsonCreateObject();
|
||||||
len += snprintf(content + len, maxLen - len, " \"vgId\": %d,\n", pVnode->vgId);
|
if (vnode == NULL) return -1;
|
||||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pVnode->dropped);
|
if (tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId) < 0) return -1;
|
||||||
len += snprintf(content + len, maxLen - len, " \"vgVersion\": %d\n", pVnode->vgVersion);
|
if (tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped) < 0) return -1;
|
||||||
if (i < numOfVnodes - 1) {
|
if (tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion) < 0) return -1;
|
||||||
len += snprintf(content + len, maxLen - len, " },\n");
|
if (tjsonAddItemToArray(vnodes, vnode) < 0) return -1;
|
||||||
} else {
|
|
||||||
len += snprintf(content + len, maxLen - len, " }\n");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
len += snprintf(content + len, maxLen - len, " ]\n");
|
return 0;
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
}
|
||||||
|
|
||||||
|
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = -1;
|
||||||
|
char *buffer = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
char file[PATH_MAX] = {0};
|
||||||
|
char realfile[PATH_MAX] = {0};
|
||||||
|
snprintf(file, sizeof(file), "%s%svnodes.json.bak", pMgmt->path, TD_DIRSEP);
|
||||||
|
snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
|
||||||
|
int32_t numOfVnodes = 0;
|
||||||
|
ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||||
|
if (ppVnodes == NULL) goto _OVER;
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
pJson = tjsonCreateObject();
|
||||||
|
if (pJson == NULL) goto _OVER;
|
||||||
|
if (vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes) != 0) goto _OVER;
|
||||||
|
buffer = tjsonToString(pJson);
|
||||||
|
if (buffer == NULL) goto _OVER;
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
|
||||||
_OVER:
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
taosWriteFile(pFile, content, len);
|
if (pFile == NULL) goto _OVER;
|
||||||
taosFsyncFile(pFile);
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
taosMemoryFree(content);
|
|
||||||
|
|
||||||
|
int32_t len = strlen(buffer);
|
||||||
|
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||||
|
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||||
|
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (pJson != NULL) tjsonDelete(pJson);
|
||||||
|
if (buffer != NULL) taosMemoryFree(buffer);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
if (ppVnodes != NULL) {
|
if (ppVnodes != NULL) {
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
SVnodeObj *pVnode = ppVnodes[i];
|
SVnodeObj *pVnode = ppVnodes[i];
|
||||||
|
@ -213,14 +215,9 @@ _OVER:
|
||||||
taosMemoryFree(ppVnodes);
|
taosMemoryFree(ppVnodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code != 0) return -1;
|
|
||||||
|
|
||||||
dInfo("succeed to write %s, numOfVnodes:%d", realfile, numOfVnodes);
|
|
||||||
code = taosRenameFile(file, realfile);
|
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to rename %s to %s", file, realfile);
|
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, terrstr(), numOfVnodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
|
@ -79,6 +79,8 @@ int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) {
|
||||||
void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
char path[TSDB_FILENAME_LEN] = {0};
|
char path[TSDB_FILENAME_LEN] = {0};
|
||||||
|
|
||||||
|
vnodeProposeCommitOnNeed(pVnode->pImpl);
|
||||||
|
|
||||||
taosThreadRwlockWrlock(&pMgmt->lock);
|
taosThreadRwlockWrlock(&pMgmt->lock);
|
||||||
taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t));
|
taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t));
|
||||||
taosThreadRwlockUnlock(&pMgmt->lock);
|
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||||
|
|
|
@ -85,6 +85,7 @@ typedef struct SDnode {
|
||||||
// dmEnv.c
|
// dmEnv.c
|
||||||
SDnode *dmInstance();
|
SDnode *dmInstance();
|
||||||
void dmReportStartup(const char *pName, const char *pDesc);
|
void dmReportStartup(const char *pName, const char *pDesc);
|
||||||
|
int64_t dmGetClusterId();
|
||||||
|
|
||||||
// dmMgmt.c
|
// dmMgmt.c
|
||||||
int32_t dmInitDnode(SDnode *pDnode);
|
int32_t dmInitDnode(SDnode *pDnode);
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dmMgmt.h"
|
#include "dmMgmt.h"
|
||||||
|
|
||||||
static SDnode global = {0};
|
static SDnode globalDnode = {0};
|
||||||
|
|
||||||
SDnode *dmInstance() { return &global; }
|
SDnode *dmInstance() { return &globalDnode; }
|
||||||
|
|
||||||
static int32_t dmCheckRepeatInit(SDnode *pDnode) {
|
static int32_t dmCheckRepeatInit(SDnode *pDnode) {
|
||||||
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||||
|
@ -268,3 +268,8 @@ void dmReportStartup(const char *pName, const char *pDesc) {
|
||||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||||
dDebug("step:%s, %s", pStartup->name, pStartup->desc);
|
dDebug("step:%s, %s", pStartup->name, pStartup->desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t dmGetClusterId() {
|
||||||
|
return globalDnode.data.clusterId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ static int32_t dmStartNodes(SDnode *pDnode) {
|
||||||
|
|
||||||
dInfo("TDengine initialized successfully");
|
dInfo("TDengine initialized successfully");
|
||||||
dmReportStartup("TDengine", "initialized successfully");
|
dmReportStartup("TDengine", "initialized successfully");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dmUtil.h"
|
#include "dmUtil.h"
|
||||||
|
#include "tjson.h"
|
||||||
#include "tmisce.h"
|
#include "tmisce.h"
|
||||||
|
|
||||||
static void dmPrintEps(SDnodeData *pData);
|
static void dmPrintEps(SDnodeData *pData);
|
||||||
|
@ -181,81 +182,73 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t dmEncodeEps(SJson *pJson, SDnodeData *pData) {
|
||||||
|
if (tjsonAddDoubleToObject(pJson, "dnodeId", pData->dnodeId) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "dnodeVer", pData->dnodeVer) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "clusterId", pData->clusterId) < 0) return -1;
|
||||||
|
if (tjsonAddDoubleToObject(pJson, "dropped", pData->dropped) < 0) return -1;
|
||||||
|
|
||||||
|
SJson *dnodes = tjsonCreateArray();
|
||||||
|
if (dnodes == NULL) return -1;
|
||||||
|
if (tjsonAddItemToObject(pJson, "dnodes", dnodes) < 0) return -1;
|
||||||
|
|
||||||
|
int32_t numOfEps = (int32_t)taosArrayGetSize(pData->dnodeEps);
|
||||||
|
for (int32_t i = 0; i < numOfEps; ++i) {
|
||||||
|
SDnodeEp *pDnodeEp = taosArrayGet(pData->dnodeEps, i);
|
||||||
|
SJson *dnode = tjsonCreateObject();
|
||||||
|
if (dnode == NULL) return -1;
|
||||||
|
|
||||||
|
if (tjsonAddDoubleToObject(dnode, "id", pDnodeEp->id) < 0) return -1;
|
||||||
|
if (tjsonAddStringToObject(dnode, "fqdn", pDnodeEp->ep.fqdn) < 0) return -1;
|
||||||
|
if (tjsonAddDoubleToObject(dnode, "port", pDnodeEp->ep.port) < 0) return -1;
|
||||||
|
if (tjsonAddDoubleToObject(dnode, "isMnode", pDnodeEp->isMnode) < 0) return -1;
|
||||||
|
if (tjsonAddItemToArray(dnodes, dnode) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t dmWriteEps(SDnodeData *pData) {
|
int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
char *content = NULL;
|
char *buffer = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
|
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
pJson = tjsonCreateObject();
|
||||||
|
if (pJson == NULL) goto _OVER;
|
||||||
|
if (dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
||||||
|
buffer = tjsonToString(pJson);
|
||||||
|
if (buffer == NULL) goto _OVER;
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) goto _OVER;
|
||||||
dError("failed to open %s since %s", file, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t len = 0;
|
int32_t len = strlen(buffer);
|
||||||
int32_t maxLen = 256 * 1024;
|
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||||
content = taosMemoryCalloc(1, maxLen + 1);
|
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pData->dnodeId);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"dnodeVer\": \"%" PRId64 "\",\n", pData->dnodeVer);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pData->clusterId);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pData->dropped);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n");
|
|
||||||
|
|
||||||
int32_t numOfEps = (int32_t)taosArrayGetSize(pData->dnodeEps);
|
|
||||||
for (int32_t i = 0; i < numOfEps; ++i) {
|
|
||||||
SDnodeEp *pDnodeEp = taosArrayGet(pData->dnodeEps, i);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pDnodeEp->id);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pDnodeEp->ep.fqdn);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->ep.port);
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"isMnode\": %d\n", pDnodeEp->isMnode);
|
|
||||||
if (i < numOfEps - 1) {
|
|
||||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
|
||||||
} else {
|
|
||||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
|
||||||
|
|
||||||
if (taosWriteFile(pFile, content, len) != len) {
|
|
||||||
dError("failed to write %s since %s", file, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
|
||||||
dError("failed to fsync %s since %s", file, strerror(errno));
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
taosMemoryFreeClear(content);
|
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to rename %s since %s", file, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
pData->updateTime = taosGetTimestampMs();
|
pData->updateTime = taosGetTimestampMs();
|
||||||
dInfo("succeed to write %s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
dInfo("succeed to write dnode file:%s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (content != NULL) taosMemoryFreeClear(content);
|
if (pJson != NULL) tjsonDelete(pJson);
|
||||||
|
if (buffer != NULL) taosMemoryFree(buffer);
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
if (code != 0) {
|
|
||||||
dError("failed to write file %s since %s", realfile, terrstr());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dInfo("succeed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, terrstr(), pData->dnodeVer);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dmUtil.h"
|
#include "dmUtil.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
#define MAXLEN 1024
|
#define MAXLEN 1024
|
||||||
|
|
||||||
|
@ -63,56 +64,51 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t dmEncodeFile(SJson *pJson, bool deployed) {
|
||||||
|
if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
int32_t len = 0;
|
char *buffer = NULL;
|
||||||
char content[MAXLEN + 1] = {0};
|
SJson *pJson = NULL;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
TdFilePtr pFile = NULL;
|
|
||||||
|
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
pJson = tjsonCreateObject();
|
||||||
|
if (pJson == NULL) goto _OVER;
|
||||||
|
if (dmEncodeFile(pJson, deployed) != 0) goto _OVER;
|
||||||
|
buffer = tjsonToString(pJson);
|
||||||
|
if (buffer == NULL) goto _OVER;
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) goto _OVER;
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to write %s since %s", file, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
len += snprintf(content + len, MAXLEN - len, "{\n");
|
int32_t len = strlen(buffer);
|
||||||
len += snprintf(content + len, MAXLEN - len, " \"deployed\": %d\n", deployed);
|
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||||
len += snprintf(content + len, MAXLEN - len, "}\n");
|
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||||
|
|
||||||
if (taosWriteFile(pFile, content, len) != len) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to write file:%s since %s", file, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosFsyncFile(pFile) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to fsync file:%s since %s", file, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
|
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to rename %s since %s", file, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dInfo("succeed to write %s, deployed:%d", realfile, deployed);
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (pFile != NULL) {
|
if (pJson != NULL) tjsonDelete(pJson);
|
||||||
taosCloseFile(&pFile);
|
if (buffer != NULL) taosMemoryFree(buffer);
|
||||||
}
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to write file:%s since %s, deloyed:%d", realfile, terrstr(), deployed);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ SHashObj *mndDupDbHash(SHashObj *pOld);
|
||||||
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
||||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||||
int32_t *pRspLen);
|
int32_t *pRspLen);
|
||||||
|
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
||||||
|
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#define CLUSTER_VER_NUMBE 1
|
#define CLUSTER_VER_NUMBE 1
|
||||||
#define CLUSTER_RESERVE_SIZE 60
|
#define CLUSTER_RESERVE_SIZE 60
|
||||||
|
char tsVersionName[16] = "community";
|
||||||
|
int64_t tsExpireTime = 0;
|
||||||
|
|
||||||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
|
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
|
||||||
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw);
|
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw);
|
||||||
|
@ -291,6 +293,18 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataAppend(pColInfo, numOfRows, (const char *)&pCluster->createdTime, false);
|
colDataAppend(pColInfo, numOfRows, (const char *)&pCluster->createdTime, false);
|
||||||
|
|
||||||
|
char ver[12] = {0};
|
||||||
|
STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes);
|
||||||
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
colDataAppend(pColInfo, numOfRows, (const char *)ver, false);
|
||||||
|
|
||||||
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
if (tsExpireTime <= 0) {
|
||||||
|
colDataAppendNULL(pColInfo, numOfRows);
|
||||||
|
} else {
|
||||||
|
colDataAppend(pColInfo, numOfRows, (const char *)&tsExpireTime, false);
|
||||||
|
}
|
||||||
|
|
||||||
sdbRelease(pSdb, pCluster);
|
sdbRelease(pSdb, pCluster);
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1051,17 +1051,7 @@ static int32_t mndDropDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb) {
|
||||||
if (mndDropStreamByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndDropStreamByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
if (mndDropSmasByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndDropSmasByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
|
if (mndUserRemoveDb(pMnode, pTrans, pDb->name) != 0) goto _OVER;
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pDb->createUser);
|
|
||||||
if (pUser != NULL) {
|
|
||||||
pUser->authVersion++;
|
|
||||||
SSdbRaw *pCommitRaw = mndUserActionEncode(pUser);
|
|
||||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
|
||||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t rspLen = 0;
|
int32_t rspLen = 0;
|
||||||
void *pRsp = NULL;
|
void *pRsp = NULL;
|
||||||
|
|
|
@ -308,7 +308,8 @@ void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeEps) {
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
SDnodeObj *pDnode = NULL;
|
SDnodeObj *pDnode = NULL;
|
||||||
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
|
ESdbStatus objStatus = 0;
|
||||||
|
pIter = sdbFetchAll(pSdb, SDB_DNODE, pIter, (void **)&pDnode, &objStatus, true);
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
SDnodeEp dnodeEp = {0};
|
SDnodeEp dnodeEp = {0};
|
||||||
|
|
|
@ -785,9 +785,9 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
||||||
|
|
||||||
int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("vgId:1, failed to reconfig mnode sync since %s", terrstr());
|
mError("vgId:1, mnode sync reconfig failed since %s", terrstr());
|
||||||
} else {
|
} else {
|
||||||
mInfo("vgId:1, reconfig mnode sync success");
|
mInfo("vgId:1, mnode sync reconfig success");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ static int32_t mndProcessTelemTimer(SRpcMsg* pReq) {
|
||||||
taosThreadMutexUnlock(&pMgmt->lock);
|
taosThreadMutexUnlock(&pMgmt->lock);
|
||||||
|
|
||||||
if (pCont != NULL) {
|
if (pCont != NULL) {
|
||||||
if (taosSendHttpReport(tsTelemServer, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT) != 0) {
|
if (taosSendHttpReport(tsTelemServer, tsTelemUri, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT) != 0) {
|
||||||
mError("failed to send telemetry report");
|
mError("failed to send telemetry report");
|
||||||
} else {
|
} else {
|
||||||
mInfo("succeed to send telemetry report");
|
mInfo("succeed to send telemetry report");
|
||||||
|
|
|
@ -604,22 +604,19 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndDropTopic(SMnode *pMnode, STrans *pTrans, SRpcMsg *pReq, SMqTopicObj *pTopic) {
|
static int32_t mndDropTopic(SMnode *pMnode, STrans *pTrans, SRpcMsg *pReq, SMqTopicObj *pTopic) {
|
||||||
|
int32_t code = -1;
|
||||||
|
if (mndUserRemoveTopic(pMnode, pTrans, pTopic->name) != 0) goto _OVER;
|
||||||
|
|
||||||
SSdbRaw *pCommitRaw = mndTopicActionEncode(pTopic);
|
SSdbRaw *pCommitRaw = mndTopicActionEncode(pTopic);
|
||||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto _OVER;
|
||||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
|
||||||
mndTransDrop(pTrans);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
code = 0;
|
||||||
mndTransDrop(pTrans);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
_OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
|
@ -890,6 +887,7 @@ int32_t mndCheckTopicExist(SMnode *pMnode, SDbObj *pDb) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
@ -917,3 +915,4 @@ int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -285,14 +285,35 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
||||||
mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser);
|
memcpy(pNew, pUser, sizeof(SUserObj));
|
||||||
|
pNew->authVersion++;
|
||||||
|
pNew->updateTime = taosGetTimestampMs();
|
||||||
|
|
||||||
|
taosRLockLatch(&pUser->lock);
|
||||||
|
pNew->readDbs = mndDupDbHash(pUser->readDbs);
|
||||||
|
pNew->writeDbs = mndDupDbHash(pUser->writeDbs);
|
||||||
|
pNew->topics = mndDupTopicHash(pUser->topics);
|
||||||
|
taosRUnLockLatch(&pUser->lock);
|
||||||
|
|
||||||
|
if (pNew->readDbs == NULL || pNew->writeDbs == NULL || pNew->topics == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndUserFreeObj(SUserObj *pUser) {
|
||||||
taosHashCleanup(pUser->readDbs);
|
taosHashCleanup(pUser->readDbs);
|
||||||
taosHashCleanup(pUser->writeDbs);
|
taosHashCleanup(pUser->writeDbs);
|
||||||
taosHashCleanup(pUser->topics);
|
taosHashCleanup(pUser->topics);
|
||||||
pUser->readDbs = NULL;
|
pUser->readDbs = NULL;
|
||||||
pUser->writeDbs = NULL;
|
pUser->writeDbs = NULL;
|
||||||
pUser->topics = NULL;
|
pUser->topics = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
||||||
|
mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser);
|
||||||
|
mndUserFreeObj(pUser);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,19 +537,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&newUser, pUser, sizeof(SUserObj));
|
if (mndUserDupObj(pUser, &newUser) != 0) goto _OVER;
|
||||||
newUser.authVersion++;
|
|
||||||
newUser.updateTime = taosGetTimestampMs();
|
|
||||||
|
|
||||||
taosRLockLatch(&pUser->lock);
|
|
||||||
newUser.readDbs = mndDupDbHash(pUser->readDbs);
|
|
||||||
newUser.writeDbs = mndDupDbHash(pUser->writeDbs);
|
|
||||||
newUser.topics = mndDupTopicHash(pUser->topics);
|
|
||||||
taosRUnLockLatch(&pUser->lock);
|
|
||||||
|
|
||||||
if (newUser.readDbs == NULL || newUser.writeDbs == NULL || newUser.topics == NULL) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
|
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
|
||||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||||
|
@ -654,9 +663,7 @@ _OVER:
|
||||||
|
|
||||||
mndReleaseUser(pMnode, pOperUser);
|
mndReleaseUser(pMnode, pOperUser);
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
taosHashCleanup(newUser.writeDbs);
|
mndUserFreeObj(&newUser);
|
||||||
taosHashCleanup(newUser.readDbs);
|
|
||||||
taosHashCleanup(newUser.topics);
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1007,3 +1014,74 @@ _OVER:
|
||||||
tFreeSUserAuthBatchRsp(&batchRsp);
|
tFreeSUserAuthBatchRsp(&batchRsp);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t len = strlen(db) + 1;
|
||||||
|
void *pIter = NULL;
|
||||||
|
SUserObj *pUser = NULL;
|
||||||
|
SUserObj newUser = {0};
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
code = -1;
|
||||||
|
if (mndUserDupObj(pUser, &newUser) != 0) break;
|
||||||
|
|
||||||
|
bool inRead = (taosHashGet(newUser.readDbs, db, len) != NULL);
|
||||||
|
bool inWrite = (taosHashGet(newUser.writeDbs, db, len) != NULL);
|
||||||
|
if (inRead || inWrite) {
|
||||||
|
(void)taosHashRemove(newUser.readDbs, db, len);
|
||||||
|
(void)taosHashRemove(newUser.writeDbs, db, len);
|
||||||
|
|
||||||
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
|
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) break;
|
||||||
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pUser != NULL) sdbRelease(pSdb, pUser);
|
||||||
|
if (pIter != NULL) sdbCancelFetch(pSdb, pIter);
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t len = strlen(topic) + 1;
|
||||||
|
void *pIter = NULL;
|
||||||
|
SUserObj *pUser = NULL;
|
||||||
|
SUserObj newUser = {0};
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
code = -1;
|
||||||
|
if (mndUserDupObj(pUser, &newUser) != 0) break;
|
||||||
|
|
||||||
|
bool inTopic = (taosHashGet(newUser.topics, topic, len) != NULL);
|
||||||
|
if (inTopic) {
|
||||||
|
(void)taosHashRemove(newUser.topics, topic, len);
|
||||||
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
|
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) break;
|
||||||
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pUser != NULL) sdbRelease(pSdb, pUser);
|
||||||
|
if (pIter != NULL) sdbCancelFetch(pSdb, pIter);
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
|
@ -243,7 +243,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
taosMemoryFree(pRaw);
|
taosMemoryFree(pRaw);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
mDebug("failed to read sdb file:%s since %s", file, terrstr());
|
mInfo("read sdb file:%s finished since %s", file, terrstr());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,15 +636,20 @@ int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, int64_t term, int64_t config) {
|
int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, int64_t term, int64_t config) {
|
||||||
int32_t code = 0;
|
int32_t code = -1;
|
||||||
|
|
||||||
if (!isApply) {
|
if (!isApply) {
|
||||||
mInfo("sdbiter:%p, not apply to sdb", pIter);
|
mInfo("sdbiter:%p, not apply to sdb", pIter);
|
||||||
sdbCloseIter(pIter);
|
code = 0;
|
||||||
return 0;
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosFsyncFile(pIter->file) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, terrstr());
|
||||||
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosFsyncFile(pIter->file);
|
|
||||||
taosCloseFile(&pIter->file);
|
taosCloseFile(&pIter->file);
|
||||||
pIter->file = NULL;
|
pIter->file = NULL;
|
||||||
|
|
||||||
|
@ -653,14 +658,12 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
||||||
if (taosRenameFile(pIter->name, datafile) != 0) {
|
if (taosRenameFile(pIter->name, datafile) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, terrstr());
|
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, terrstr());
|
||||||
sdbCloseIter(pIter);
|
goto _OVER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbReadFile(pSdb) != 0) {
|
if (sdbReadFile(pSdb) != 0) {
|
||||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, terrstr());
|
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, terrstr());
|
||||||
sdbCloseIter(pIter);
|
goto _OVER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config > 0) {
|
if (config > 0) {
|
||||||
|
@ -674,8 +677,11 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("sdbiter:%p, success applyed to sdb", pIter);
|
mInfo("sdbiter:%p, success applyed to sdb", pIter);
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
sdbCloseIter(pIter);
|
sdbCloseIter(pIter);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
||||||
|
|
|
@ -124,6 +124,7 @@ FAIL:
|
||||||
}
|
}
|
||||||
|
|
||||||
void sndClose(SSnode *pSnode) {
|
void sndClose(SSnode *pSnode) {
|
||||||
|
streamMetaCommit(pSnode->pMeta);
|
||||||
streamMetaClose(pSnode->pMeta);
|
streamMetaClose(pSnode->pMeta);
|
||||||
taosMemoryFree(pSnode->path);
|
taosMemoryFree(pSnode->path);
|
||||||
taosMemoryFree(pSnode);
|
taosMemoryFree(pSnode);
|
||||||
|
|
|
@ -89,6 +89,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||||
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
||||||
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
|
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
|
||||||
void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
|
void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
|
||||||
|
void vnodeProposeCommitOnNeed(SVnode *pVnode);
|
||||||
|
|
||||||
// meta
|
// meta
|
||||||
typedef struct SMeta SMeta; // todo: remove
|
typedef struct SMeta SMeta; // todo: remove
|
||||||
|
|
|
@ -86,6 +86,7 @@ int32_t vnodeGetBatchMeta(SVnode* pVnode, SRpcMsg* pMsg);
|
||||||
// vnodeCommit.c
|
// vnodeCommit.c
|
||||||
int32_t vnodeBegin(SVnode* pVnode);
|
int32_t vnodeBegin(SVnode* pVnode);
|
||||||
int32_t vnodeShouldCommit(SVnode* pVnode);
|
int32_t vnodeShouldCommit(SVnode* pVnode);
|
||||||
|
void vnodeUpdCommitSched(SVnode* pVnode);
|
||||||
void vnodeRollback(SVnode* pVnode);
|
void vnodeRollback(SVnode* pVnode);
|
||||||
int32_t vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
|
int32_t vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
|
||||||
int32_t vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
|
int32_t vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
|
||||||
|
@ -103,6 +104,7 @@ void vnodeSyncClose(SVnode* pVnode);
|
||||||
void vnodeRedirectRpcMsg(SVnode* pVnode, SRpcMsg* pMsg, int32_t code);
|
void vnodeRedirectRpcMsg(SVnode* pVnode, SRpcMsg* pMsg, int32_t code);
|
||||||
bool vnodeIsLeader(SVnode* pVnode);
|
bool vnodeIsLeader(SVnode* pVnode);
|
||||||
bool vnodeIsRoleLeader(SVnode* pVnode);
|
bool vnodeIsRoleLeader(SVnode* pVnode);
|
||||||
|
int vnodeShouldCommit(SVnode* pVnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,6 +332,11 @@ struct STsdbKeepCfg {
|
||||||
int32_t keep2;
|
int32_t keep2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct SVCommitSched {
|
||||||
|
int64_t commitMs;
|
||||||
|
int64_t maxWaitMs;
|
||||||
|
} SVCommitSched;
|
||||||
|
|
||||||
struct SVnode {
|
struct SVnode {
|
||||||
char* path;
|
char* path;
|
||||||
SVnodeCfg config;
|
SVnodeCfg config;
|
||||||
|
@ -350,6 +355,7 @@ struct SVnode {
|
||||||
STQ* pTq;
|
STQ* pTq;
|
||||||
SSink* pSink;
|
SSink* pSink;
|
||||||
tsem_t canCommit;
|
tsem_t canCommit;
|
||||||
|
SVCommitSched commitSched;
|
||||||
int64_t sync;
|
int64_t sync;
|
||||||
TdThreadMutex lock;
|
TdThreadMutex lock;
|
||||||
bool blocked;
|
bool blocked;
|
||||||
|
|
|
@ -203,6 +203,7 @@ _err:
|
||||||
|
|
||||||
int metaClose(SMeta *pMeta) {
|
int metaClose(SMeta *pMeta) {
|
||||||
if (pMeta) {
|
if (pMeta) {
|
||||||
|
if (pMeta->pEnv) tdbAbort(pMeta->pEnv, pMeta->txn);
|
||||||
if (pMeta->pCache) metaCacheClose(pMeta);
|
if (pMeta->pCache) metaCacheClose(pMeta);
|
||||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||||
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
||||||
|
|
|
@ -395,6 +395,10 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
|
||||||
static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma, SCommitInfo *pInfo) {
|
static int32_t tdProcessRSmaAsyncCommitImpl(SSma *pSma, SCommitInfo *pInfo) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SVnode *pVnode = pSma->pVnode;
|
SVnode *pVnode = pSma->pVnode;
|
||||||
|
SSmaEnv *pSmaEnv = SMA_RSMA_ENV(pSma);
|
||||||
|
if (!pSmaEnv) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
#if 0
|
#if 0
|
||||||
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pSmaEnv);
|
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pSmaEnv);
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,11 @@
|
||||||
|
|
||||||
#include "tq.h"
|
#include "tq.h"
|
||||||
|
|
||||||
int tqCommit(STQ* pTq) { return tqOffsetCommitFile(pTq->pOffsetStore); }
|
int tqCommit(STQ* pTq) {
|
||||||
|
if (streamMetaCommit(pTq->pStreamMeta) < 0) {
|
||||||
|
tqError("vgId:%d, failed to commit stream meta since %s", TD_VID(pTq->pVnode), terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tqOffsetCommitFile(pTq->pOffsetStore);
|
||||||
|
}
|
||||||
|
|
|
@ -1080,6 +1080,8 @@ static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow) {
|
||||||
|
|
||||||
iMax[nMax] = i;
|
iMax[nMax] = i;
|
||||||
max[nMax++] = pIter->input[i].pRow;
|
max[nMax++] = pIter->input[i].pRow;
|
||||||
|
} else {
|
||||||
|
pIter->input[i].next = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,7 @@ static int32_t tsdbSnapNextRow(STsdbSnapReader* pReader) {
|
||||||
int64_t rowVer = pIter->bData.aVersion[pIter->iRow];
|
int64_t rowVer = pIter->bData.aVersion[pIter->iRow];
|
||||||
|
|
||||||
if (rowVer >= pReader->sver && rowVer <= pReader->ever) {
|
if (rowVer >= pReader->sver && rowVer <= pReader->ever) {
|
||||||
|
pIter->rInfo.suid = pIter->bData.suid;
|
||||||
pIter->rInfo.uid = pIter->bData.uid ? pIter->bData.uid : pIter->bData.aUid[pIter->iRow];
|
pIter->rInfo.uid = pIter->bData.uid ? pIter->bData.uid : pIter->bData.aUid[pIter->iRow];
|
||||||
pIter->rInfo.row = tsdbRowFromBlockData(&pIter->bData, pIter->iRow);
|
pIter->rInfo.row = tsdbRowFromBlockData(&pIter->bData, pIter->iRow);
|
||||||
goto _out;
|
goto _out;
|
||||||
|
|
|
@ -682,6 +682,18 @@ int32_t tRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRo
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
|
tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
|
||||||
|
if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||||
|
uint8_t *pVal = pColVal->value.pData;
|
||||||
|
|
||||||
|
pColVal->value.pData = NULL;
|
||||||
|
code = tRealloc(&pColVal->value.pData, pColVal->value.nData);
|
||||||
|
if (code) goto _exit;
|
||||||
|
|
||||||
|
if (pColVal->value.nData) {
|
||||||
|
memcpy(pColVal->value.pData, pVal, pColVal->value.nData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
@ -720,13 +732,36 @@ int32_t tRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||||
|
|
||||||
if (key.version > pMerger->version) {
|
if (key.version > pMerger->version) {
|
||||||
if (!COL_VAL_IS_NONE(pColVal)) {
|
if (!COL_VAL_IS_NONE(pColVal)) {
|
||||||
|
if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||||
|
SColVal *tColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
|
code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
tColVal->value.nData = pColVal->value.nData;
|
||||||
|
if (pColVal->value.nData) {
|
||||||
|
memcpy(tColVal->value.pData, pColVal->value.pData, pColVal->value.nData);
|
||||||
|
}
|
||||||
|
tColVal->flag = 0;
|
||||||
|
} else {
|
||||||
taosArraySet(pMerger->pArray, iCol, pColVal);
|
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (key.version < pMerger->version) {
|
} else if (key.version < pMerger->version) {
|
||||||
SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
|
SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
|
||||||
if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
|
if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
|
||||||
|
if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||||
|
code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
tColVal->value.nData = pColVal->value.nData;
|
||||||
|
if (pColVal->value.nData) {
|
||||||
|
memcpy(tColVal->value.pData, pColVal->value.pData, pColVal->value.nData);
|
||||||
|
}
|
||||||
|
tColVal->flag = 0;
|
||||||
|
} else {
|
||||||
taosArraySet(pMerger->pArray, iCol, pColVal);
|
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0 && "dup versions not allowed");
|
ASSERT(0 && "dup versions not allowed");
|
||||||
}
|
}
|
||||||
|
@ -765,6 +800,18 @@ int32_t tRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||||
// other
|
// other
|
||||||
for (int16_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) {
|
for (int16_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) {
|
||||||
tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal);
|
tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal);
|
||||||
|
if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||||
|
uint8_t *pVal = pColVal->value.pData;
|
||||||
|
|
||||||
|
pColVal->value.pData = NULL;
|
||||||
|
code = tRealloc(&pColVal->value.pData, pColVal->value.nData);
|
||||||
|
if (code) goto _exit;
|
||||||
|
|
||||||
|
if (pColVal->value.nData) {
|
||||||
|
memcpy(pColVal->value.pData, pVal, pColVal->value.nData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
@ -775,7 +822,16 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tRowMergerClear(SRowMerger *pMerger) { taosArrayDestroy(pMerger->pArray); }
|
void tRowMergerClear(SRowMerger *pMerger) {
|
||||||
|
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
||||||
|
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
|
if (IS_VAR_DATA_TYPE(pTColVal->type)) {
|
||||||
|
tFree(pTColVal->value.pData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(pMerger->pArray);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -789,13 +845,48 @@ int32_t tRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
||||||
|
|
||||||
if (key.version > pMerger->version) {
|
if (key.version > pMerger->version) {
|
||||||
if (!COL_VAL_IS_NONE(pColVal)) {
|
if (!COL_VAL_IS_NONE(pColVal)) {
|
||||||
|
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||||
|
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
|
if (!COL_VAL_IS_NULL(pColVal)) {
|
||||||
|
code = tRealloc(&pTColVal->value.pData, pColVal->value.nData);
|
||||||
|
if (code) goto _exit;
|
||||||
|
|
||||||
|
pTColVal->value.nData = pColVal->value.nData;
|
||||||
|
if (pTColVal->value.nData) {
|
||||||
|
memcpy(pTColVal->value.pData, pColVal->value.pData, pTColVal->value.nData);
|
||||||
|
}
|
||||||
|
pTColVal->flag = 0;
|
||||||
|
} else {
|
||||||
|
tFree(pTColVal->value.pData);
|
||||||
|
pTColVal->value.pData = NULL;
|
||||||
taosArraySet(pMerger->pArray, iCol, pColVal);
|
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (key.version < pMerger->version) {
|
} else if (key.version < pMerger->version) {
|
||||||
SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
|
SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
|
||||||
if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
|
if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
|
||||||
|
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||||
|
if (!COL_VAL_IS_NULL(pColVal)) {
|
||||||
|
code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
|
||||||
|
if (code) goto _exit;
|
||||||
|
|
||||||
|
tColVal->value.nData = pColVal->value.nData;
|
||||||
|
if (tColVal->value.nData) {
|
||||||
|
memcpy(tColVal->value.pData, pColVal->value.pData, tColVal->value.nData);
|
||||||
|
}
|
||||||
|
tColVal->flag = 0;
|
||||||
|
} else {
|
||||||
|
tFree(tColVal->value.pData);
|
||||||
|
tColVal->value.pData = NULL;
|
||||||
taosArraySet(pMerger->pArray, iCol, pColVal);
|
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,25 @@ int vnodeBegin(SVnode *pVnode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vnodeUpdCommitSched(SVnode *pVnode) {
|
||||||
|
int64_t randNum = taosRand();
|
||||||
|
pVnode->commitSched.commitMs = taosGetMonoTimestampMs();
|
||||||
|
pVnode->commitSched.maxWaitMs = tsVndCommitMaxIntervalMs + (randNum % tsVndCommitMaxIntervalMs);
|
||||||
|
}
|
||||||
|
|
||||||
int vnodeShouldCommit(SVnode *pVnode) {
|
int vnodeShouldCommit(SVnode *pVnode) {
|
||||||
|
if (!pVnode->inUse || !osDataSpaceAvailable()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SVCommitSched *pSched = &pVnode->commitSched;
|
||||||
|
int64_t nowMs = taosGetMonoTimestampMs();
|
||||||
|
|
||||||
|
return (((pVnode->inUse->size > pVnode->inUse->node.size) && (pSched->commitMs + SYNC_VND_COMMIT_MIN_MS < nowMs)) ||
|
||||||
|
(pVnode->inUse->size > 0 && pSched->commitMs + pSched->maxWaitMs < nowMs));
|
||||||
|
}
|
||||||
|
|
||||||
|
int vnodeShouldCommitOld(SVnode *pVnode) {
|
||||||
if (pVnode->inUse) {
|
if (pVnode->inUse) {
|
||||||
return osDataSpaceAvailable() && (pVnode->inUse->size > pVnode->inUse->node.size);
|
return osDataSpaceAvailable() && (pVnode->inUse->size > pVnode->inUse->node.size);
|
||||||
}
|
}
|
||||||
|
@ -247,6 +265,7 @@ _exit:
|
||||||
taosMemoryFree(pInfo);
|
taosMemoryFree(pInfo);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vnodeAsyncCommit(SVnode *pVnode) {
|
int vnodeAsyncCommit(SVnode *pVnode) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
@ -294,7 +313,9 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
||||||
SVnode *pVnode = pInfo->pVnode;
|
SVnode *pVnode = pInfo->pVnode;
|
||||||
|
|
||||||
vInfo("vgId:%d, start to commit, commitId:%" PRId64 " version:%" PRId64 " term: %" PRId64, TD_VID(pVnode),
|
vInfo("vgId:%d, start to commit, commitId:%" PRId64 " version:%" PRId64 " term: %" PRId64, TD_VID(pVnode),
|
||||||
pVnode->state.commitID, pVnode->state.applied, pVnode->state.applyTerm);
|
pInfo->info.state.commitID, pInfo->info.state.committed, pInfo->info.state.commitTerm);
|
||||||
|
|
||||||
|
vnodeUpdCommitSched(pVnode);
|
||||||
|
|
||||||
// persist wal before starting
|
// persist wal before starting
|
||||||
if (walPersist(pVnode->pWal) < 0) {
|
if (walPersist(pVnode->pWal) < 0) {
|
||||||
|
@ -308,8 +329,7 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
||||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// walBeginSnapshot(pVnode->pWal, pVnode->state.applied);
|
syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed);
|
||||||
syncBeginSnapshot(pVnode->sync, pVnode->state.applied);
|
|
||||||
|
|
||||||
// commit each sub-system
|
// commit each sub-system
|
||||||
code = tsdbCommit(pVnode->pTsdb, pInfo);
|
code = tsdbCommit(pVnode->pTsdb, pInfo);
|
||||||
|
@ -351,7 +371,6 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// walEndSnapshot(pVnode->pWal);
|
|
||||||
syncEndSnapshot(pVnode->sync);
|
syncEndSnapshot(pVnode->sync);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
|
|
@ -160,6 +160,8 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
|
||||||
taosThreadMutexInit(&pVnode->mutex, NULL);
|
taosThreadMutexInit(&pVnode->mutex, NULL);
|
||||||
taosThreadCondInit(&pVnode->poolNotEmpty, NULL);
|
taosThreadCondInit(&pVnode->poolNotEmpty, NULL);
|
||||||
|
|
||||||
|
vnodeUpdCommitSched(pVnode);
|
||||||
|
|
||||||
int8_t rollback = vnodeShouldRollback(pVnode);
|
int8_t rollback = vnodeShouldRollback(pVnode);
|
||||||
|
|
||||||
// open buffer pool
|
// open buffer pool
|
||||||
|
@ -254,7 +256,7 @@ void vnodePostClose(SVnode *pVnode) { vnodeSyncPostClose(pVnode); }
|
||||||
|
|
||||||
void vnodeClose(SVnode *pVnode) {
|
void vnodeClose(SVnode *pVnode) {
|
||||||
if (pVnode) {
|
if (pVnode) {
|
||||||
vnodeSyncCommit(pVnode);
|
tsem_wait(&pVnode->canCommit);
|
||||||
vnodeSyncClose(pVnode);
|
vnodeSyncClose(pVnode);
|
||||||
vnodeQueryClose(pVnode);
|
vnodeQueryClose(pVnode);
|
||||||
walClose(pVnode->pWal);
|
walClose(pVnode->pWal);
|
||||||
|
@ -263,6 +265,8 @@ void vnodeClose(SVnode *pVnode) {
|
||||||
smaClose(pVnode->pSma);
|
smaClose(pVnode->pSma);
|
||||||
metaClose(pVnode->pMeta);
|
metaClose(pVnode->pMeta);
|
||||||
vnodeCloseBufPool(pVnode);
|
vnodeCloseBufPool(pVnode);
|
||||||
|
tsem_post(&pVnode->canCommit);
|
||||||
|
|
||||||
// destroy handle
|
// destroy handle
|
||||||
tsem_destroy(&(pVnode->canCommit));
|
tsem_destroy(&(pVnode->canCommit));
|
||||||
tsem_destroy(&pVnode->syncSem);
|
tsem_destroy(&pVnode->syncSem);
|
||||||
|
|
|
@ -406,8 +406,10 @@ static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_
|
||||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path);
|
snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SVnodeStats vndStats = pWriter->info.config.vndStats;
|
||||||
SVnode *pVnode = pWriter->pVnode;
|
SVnode *pVnode = pWriter->pVnode;
|
||||||
pWriter->info.config = pVnode->config;
|
pWriter->info.config = pVnode->config;
|
||||||
|
pWriter->info.config.vndStats = vndStats;
|
||||||
vDebug("vgId:%d, save config while write snapshot", pWriter->pVnode->config.vgId);
|
vDebug("vgId:%d, save config while write snapshot", pWriter->pVnode->config.vgId);
|
||||||
if (vnodeSaveInfo(dir, &pWriter->info) < 0) {
|
if (vnodeSaveInfo(dir, &pWriter->info) < 0) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
|
|
|
@ -203,6 +203,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
// skip header
|
// skip header
|
||||||
pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||||
len = pMsg->contLen - sizeof(SMsgHead);
|
len = pMsg->contLen - sizeof(SMsgHead);
|
||||||
|
bool needCommit = false;
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
/* META */
|
/* META */
|
||||||
|
@ -299,9 +300,8 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
vnodeProcessAlterConfigReq(pVnode, version, pReq, len, pRsp);
|
vnodeProcessAlterConfigReq(pVnode, version, pReq, len, pRsp);
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_COMMIT:
|
case TDMT_VND_COMMIT:
|
||||||
vnodeSyncCommit(pVnode);
|
needCommit = true;
|
||||||
vnodeBegin(pVnode);
|
break;
|
||||||
goto _exit;
|
|
||||||
default:
|
default:
|
||||||
vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
|
vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -318,7 +318,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit if need
|
// commit if need
|
||||||
if (vnodeShouldCommit(pVnode)) {
|
if (needCommit) {
|
||||||
vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), version);
|
vInfo("vgId:%d, commit at version %" PRId64, TD_VID(pVnode), version);
|
||||||
vnodeAsyncCommit(pVnode);
|
vnodeAsyncCommit(pVnode);
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,64 @@ static void vnodeHandleProposeError(SVnode *pVnode, SRpcMsg *pMsg, int32_t code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t inline vnodeProposeMsg(SVnode *pVnode, SRpcMsg *pMsg, bool isWeak) {
|
||||||
|
int64_t seq = 0;
|
||||||
|
|
||||||
|
taosThreadMutexLock(&pVnode->lock);
|
||||||
|
int32_t code = syncPropose(pVnode->sync, pMsg, isWeak, &seq);
|
||||||
|
bool wait = (code == 0 && vnodeIsMsgBlock(pMsg->msgType));
|
||||||
|
if (wait) {
|
||||||
|
ASSERT(!pVnode->blocked);
|
||||||
|
pVnode->blocked = true;
|
||||||
|
pVnode->blockSec = taosGetTimestampSec();
|
||||||
|
pVnode->blockSeq = seq;
|
||||||
|
#if 0
|
||||||
|
pVnode->blockInfo = pMsg->info;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
taosThreadMutexUnlock(&pVnode->lock);
|
||||||
|
|
||||||
|
if (code > 0) {
|
||||||
|
vnodeHandleWriteMsg(pVnode, pMsg);
|
||||||
|
} else if (code < 0) {
|
||||||
|
if (terrno != 0) code = terrno;
|
||||||
|
vnodeHandleProposeError(pVnode, pMsg, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wait) vnodeWaitBlockMsg(pVnode, pMsg);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vnodeProposeCommitOnNeed(SVnode *pVnode) {
|
||||||
|
if (!vnodeShouldCommit(pVnode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t contLen = sizeof(SMsgHead);
|
||||||
|
SMsgHead *pHead = rpcMallocCont(contLen);
|
||||||
|
pHead->contLen = contLen;
|
||||||
|
pHead->vgId = pVnode->config.vgId;
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg = {0};
|
||||||
|
rpcMsg.msgType = TDMT_VND_COMMIT;
|
||||||
|
rpcMsg.contLen = contLen;
|
||||||
|
rpcMsg.pCont = pHead;
|
||||||
|
rpcMsg.info.noResp = 1;
|
||||||
|
|
||||||
|
bool isWeak = false;
|
||||||
|
if (vnodeProposeMsg(pVnode, &rpcMsg, isWeak) < 0) {
|
||||||
|
vTrace("vgId:%d, failed to propose vnode commit since %s", pVnode->config.vgId, terrstr());
|
||||||
|
goto _out;
|
||||||
|
}
|
||||||
|
|
||||||
|
vInfo("vgId:%d, proposed vnode commit", pVnode->config.vgId);
|
||||||
|
|
||||||
|
_out:
|
||||||
|
vnodeUpdCommitSched(pVnode);
|
||||||
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
rpcMsg.pCont = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#if BATCH_ENABLE
|
#if BATCH_ENABLE
|
||||||
|
|
||||||
static void inline vnodeProposeBatchMsg(SVnode *pVnode, SRpcMsg **pMsgArr, bool *pIsWeakArr, int32_t *arrSize) {
|
static void inline vnodeProposeBatchMsg(SVnode *pVnode, SRpcMsg **pMsgArr, bool *pIsWeakArr, int32_t *arrSize) {
|
||||||
|
@ -178,6 +236,8 @@ void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vnodeProposeCommitOnNeed(pVnode);
|
||||||
|
|
||||||
code = vnodePreProcessWriteMsg(pVnode, pMsg);
|
code = vnodePreProcessWriteMsg(pVnode, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
vGError("vgId:%d, msg:%p failed to pre-process since %s", vgId, pMsg, terrstr());
|
vGError("vgId:%d, msg:%p failed to pre-process since %s", vgId, pMsg, terrstr());
|
||||||
|
@ -205,34 +265,6 @@ void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static int32_t inline vnodeProposeMsg(SVnode *pVnode, SRpcMsg *pMsg, bool isWeak) {
|
|
||||||
int64_t seq = 0;
|
|
||||||
|
|
||||||
taosThreadMutexLock(&pVnode->lock);
|
|
||||||
int32_t code = syncPropose(pVnode->sync, pMsg, isWeak, &seq);
|
|
||||||
bool wait = (code == 0 && vnodeIsMsgBlock(pMsg->msgType));
|
|
||||||
if (wait) {
|
|
||||||
ASSERT(!pVnode->blocked);
|
|
||||||
pVnode->blocked = true;
|
|
||||||
pVnode->blockSec = taosGetTimestampSec();
|
|
||||||
pVnode->blockSeq = seq;
|
|
||||||
#if 0
|
|
||||||
pVnode->blockInfo = pMsg->info;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
taosThreadMutexUnlock(&pVnode->lock);
|
|
||||||
|
|
||||||
if (code > 0) {
|
|
||||||
vnodeHandleWriteMsg(pVnode, pMsg);
|
|
||||||
} else if (code < 0) {
|
|
||||||
if (terrno != 0) code = terrno;
|
|
||||||
vnodeHandleProposeError(pVnode, pMsg, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wait) vnodeWaitBlockMsg(pVnode, pMsg);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||||
SVnode *pVnode = pInfo->ahandle;
|
SVnode *pVnode = pInfo->ahandle;
|
||||||
int32_t vgId = pVnode->config.vgId;
|
int32_t vgId = pVnode->config.vgId;
|
||||||
|
@ -256,6 +288,8 @@ void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vnodeProposeCommitOnNeed(pVnode);
|
||||||
|
|
||||||
code = vnodePreProcessWriteMsg(pVnode, pMsg);
|
code = vnodePreProcessWriteMsg(pVnode, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
vGError("vgId:%d, msg:%p failed to pre-process since %s", vgId, pMsg, terrstr());
|
vGError("vgId:%d, msg:%p failed to pre-process since %s", vgId, pMsg, terrstr());
|
||||||
|
|
|
@ -905,6 +905,14 @@ int32_t ctgCallUserCb(void* param) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ctgUpdateJobErrCode(SCtgJob* pJob, int32_t errCode) {
|
||||||
|
if (!NEED_CLIENT_REFRESH_VG_ERROR(errCode) || errCode == TSDB_CODE_SUCCESS) return;
|
||||||
|
|
||||||
|
atomic_store_32(&pJob->jobResCode, errCode);
|
||||||
|
qDebug("QID:0x%" PRIx64 " ctg job errCode updated to %s", pJob->queryId, tstrerror(errCode));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) {
|
int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) {
|
||||||
SCtgJob* pJob = pTask->pJob;
|
SCtgJob* pJob = pTask->pJob;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -924,6 +932,8 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) {
|
||||||
if (taskDone < taosArrayGetSize(pJob->pTasks)) {
|
if (taskDone < taosArrayGetSize(pJob->pTasks)) {
|
||||||
qDebug("QID:0x%" PRIx64 " task done: %d, total: %d", pJob->queryId, taskDone,
|
qDebug("QID:0x%" PRIx64 " task done: %d, total: %d", pJob->queryId, taskDone,
|
||||||
(int32_t)taosArrayGetSize(pJob->pTasks));
|
(int32_t)taosArrayGetSize(pJob->pTasks));
|
||||||
|
|
||||||
|
ctgUpdateJobErrCode(pJob, rspCode);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,7 +941,8 @@ int32_t ctgHandleTaskEnd(SCtgTask* pTask, int32_t rspCode) {
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
pJob->jobResCode = code;
|
ctgUpdateJobErrCode(pJob, rspCode);
|
||||||
|
// pJob->jobResCode = code;
|
||||||
|
|
||||||
// taosSsleep(2);
|
// taosSsleep(2);
|
||||||
// qDebug("QID:0x%" PRIx64 " ctg after sleep", pJob->queryId);
|
// qDebug("QID:0x%" PRIx64 " ctg after sleep", pJob->queryId);
|
||||||
|
@ -1098,7 +1109,8 @@ _return:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
ctgTaskError("Get table %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname, tstrerror(code));
|
ctgTaskError("Get table %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname,
|
||||||
|
tstrerror(code));
|
||||||
}
|
}
|
||||||
if (pTask->res || code) {
|
if (pTask->res || code) {
|
||||||
ctgHandleTaskEnd(pTask, code);
|
ctgHandleTaskEnd(pTask, code);
|
||||||
|
@ -1286,7 +1298,8 @@ _return:
|
||||||
TSWAP(pTask->res, ctx->pResList);
|
TSWAP(pTask->res, ctx->pResList);
|
||||||
taskDone = true;
|
taskDone = true;
|
||||||
}
|
}
|
||||||
ctgTaskError("Get table %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname, tstrerror(code));
|
ctgTaskError("Get table %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname,
|
||||||
|
tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTask->res && taskDone) {
|
if (pTask->res && taskDone) {
|
||||||
|
|
|
@ -1729,6 +1729,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||||
/*resetTableScanInfo(pTSInfo, pWin);*/
|
/*resetTableScanInfo(pTSInfo, pWin);*/
|
||||||
tsdbReaderClose(pTSInfo->base.dataReader);
|
tsdbReaderClose(pTSInfo->base.dataReader);
|
||||||
pTSInfo->base.dataReader = NULL;
|
pTSInfo->base.dataReader = NULL;
|
||||||
|
pInfo->pTableScanOp->status = OP_OPENED;
|
||||||
|
|
||||||
pTSInfo->scanTimes = 0;
|
pTSInfo->scanTimes = 0;
|
||||||
pTSInfo->currentGroupId = -1;
|
pTSInfo->currentGroupId = -1;
|
||||||
|
|
|
@ -108,7 +108,7 @@ static int32_t sortComparCleanup(SMsortComparParam* cmpParam) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsortClearOrderdSource(SArray *pOrderedSource) {
|
void tsortClearOrderdSource(SArray* pOrderedSource) {
|
||||||
for (size_t i = 0; i < taosArrayGetSize(pOrderedSource); i++) {
|
for (size_t i = 0; i < taosArrayGetSize(pOrderedSource); i++) {
|
||||||
SSortSource** pSource = taosArrayGet(pOrderedSource, i);
|
SSortSource** pSource = taosArrayGet(pOrderedSource, i);
|
||||||
if (NULL == *pSource) {
|
if (NULL == *pSource) {
|
||||||
|
@ -121,6 +121,12 @@ void tsortClearOrderdSource(SArray *pOrderedSource) {
|
||||||
if ((*pSource)->param && !(*pSource)->onlyRef) {
|
if ((*pSource)->param && !(*pSource)->onlyRef) {
|
||||||
taosMemoryFree((*pSource)->param);
|
taosMemoryFree((*pSource)->param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(*pSource)->onlyRef && (*pSource)->src.pBlock) {
|
||||||
|
blockDataDestroy((*pSource)->src.pBlock);
|
||||||
|
(*pSource)->src.pBlock = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
taosMemoryFreeClear(*pSource);
|
taosMemoryFreeClear(*pSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +251,8 @@ static int32_t sortComparInit(SMsortComparParam* pParam, SArray* pSources, int32
|
||||||
if (pHandle->pBuf == NULL) {
|
if (pHandle->pBuf == NULL) {
|
||||||
if (!osTempSpaceAvailable()) {
|
if (!osTempSpaceAvailable()) {
|
||||||
code = TSDB_CODE_NO_AVAIL_DISK;
|
code = TSDB_CODE_NO_AVAIL_DISK;
|
||||||
qError("Sort compare init failed since %s, %s", terrstr(code), pHandle->idStr);
|
terrno = code;
|
||||||
|
qError("Sort compare init failed since %s, %s", tstrerror(code), pHandle->idStr);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +260,7 @@ static int32_t sortComparInit(SMsortComparParam* pParam, SArray* pSources, int32
|
||||||
"sortComparInit", tsTempDir);
|
"sortComparInit", tsTempDir);
|
||||||
dBufSetPrintInfo(pHandle->pBuf);
|
dBufSetPrintInfo(pHandle->pBuf);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = code;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +284,7 @@ static int32_t sortComparInit(SMsortComparParam* pParam, SArray* pSources, int32
|
||||||
|
|
||||||
code = blockDataFromBuf(pSource->src.pBlock, pPage);
|
code = blockDataFromBuf(pSource->src.pBlock, pPage);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = code;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,6 +668,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
|
||||||
if (source->param && !source->onlyRef) {
|
if (source->param && !source->onlyRef) {
|
||||||
taosMemoryFree(source->param);
|
taosMemoryFree(source->param);
|
||||||
}
|
}
|
||||||
|
if (!source->onlyRef && source->src.pBlock) {
|
||||||
|
blockDataDestroy(source->src.pBlock);
|
||||||
|
source->src.pBlock = NULL;
|
||||||
|
}
|
||||||
taosMemoryFree(source);
|
taosMemoryFree(source);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -672,6 +685,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
|
||||||
if (source->param && !source->onlyRef) {
|
if (source->param && !source->onlyRef) {
|
||||||
taosMemoryFree(source->param);
|
taosMemoryFree(source->param);
|
||||||
}
|
}
|
||||||
|
if (!source->onlyRef && source->src.pBlock) {
|
||||||
|
blockDataDestroy(source->src.pBlock);
|
||||||
|
source->src.pBlock = NULL;
|
||||||
|
}
|
||||||
taosMemoryFree(source);
|
taosMemoryFree(source);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ void tMemBucketDestroy(tMemBucket *pBucket);
|
||||||
|
|
||||||
int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size);
|
int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size);
|
||||||
|
|
||||||
double getPercentile(tMemBucket *pMemBucket, double percent);
|
int32_t getPercentile(tMemBucket *pMemBucket, double percent, double *result);
|
||||||
|
|
||||||
#endif // TDENGINE_TPERCENTILE_H
|
#endif // TDENGINE_TPERCENTILE_H
|
||||||
|
|
||||||
|
|
|
@ -1662,9 +1662,9 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) {
|
||||||
|
|
||||||
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SVariant* pVal = &pCtx->param[1].param;
|
SVariant* pVal = &pCtx->param[1].param;
|
||||||
terrno = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
double v = 0;
|
double v = 0;
|
||||||
|
|
||||||
GET_TYPED_DATA(v, double, pVal->nType, &pVal->i);
|
GET_TYPED_DATA(v, double, pVal->nType, &pVal->i);
|
||||||
|
|
||||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
@ -1672,13 +1672,12 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
|
|
||||||
tMemBucket* pMemBucket = ppInfo->pMemBucket;
|
tMemBucket* pMemBucket = ppInfo->pMemBucket;
|
||||||
if (pMemBucket != NULL && pMemBucket->total > 0) { // check for null
|
if (pMemBucket != NULL && pMemBucket->total > 0) { // check for null
|
||||||
SET_DOUBLE_VAL(&ppInfo->result, getPercentile(pMemBucket, v));
|
code = getPercentile(pMemBucket, v, &ppInfo->result);
|
||||||
}
|
}
|
||||||
|
|
||||||
tMemBucketDestroy(pMemBucket);
|
tMemBucketDestroy(pMemBucket);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (terrno != TSDB_CODE_SUCCESS) {
|
return code;
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionFinalize(pCtx, pBlock);
|
return functionFinalize(pCtx, pBlock);
|
||||||
|
|
|
@ -90,7 +90,7 @@ static void resetPosInfo(SSlotInfo *pInfo) {
|
||||||
pInfo->data = NULL;
|
pInfo->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
double findOnlyResult(tMemBucket *pMemBucket) {
|
int32_t findOnlyResult(tMemBucket *pMemBucket, double *result) {
|
||||||
ASSERT(pMemBucket->total == 1);
|
ASSERT(pMemBucket->total == 1);
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
|
||||||
|
@ -109,19 +109,17 @@ double findOnlyResult(tMemBucket *pMemBucket) {
|
||||||
int32_t *pageId = taosArrayGet(list, 0);
|
int32_t *pageId = taosArrayGet(list, 0);
|
||||||
SFilePage *pPage = getBufPage(pMemBucket->pBuffer, *pageId);
|
SFilePage *pPage = getBufPage(pMemBucket->pBuffer, *pageId);
|
||||||
if (pPage == NULL) {
|
if (pPage == NULL) {
|
||||||
terrno = TSDB_CODE_NO_AVAIL_DISK;
|
return TSDB_CODE_NO_AVAIL_DISK;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pPage->num == 1);
|
ASSERT(pPage->num == 1);
|
||||||
|
|
||||||
double v = 0;
|
GET_TYPED_DATA(*result, double, pMemBucket->type, pPage->data);
|
||||||
GET_TYPED_DATA(v, double, pMemBucket->type, pPage->data);
|
return TSDB_CODE_SUCCESS;
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
*result = 0.0;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) {
|
int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) {
|
||||||
|
@ -443,7 +441,7 @@ static double getIdenticalDataVal(tMemBucket *pMemBucket, int32_t slotIndex) {
|
||||||
return finalResult;
|
return finalResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) {
|
int32_t getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction, double *result) {
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pMemBucket->numOfSlots; ++i) {
|
for (int32_t i = 0; i < pMemBucket->numOfSlots; ++i) {
|
||||||
|
@ -476,15 +474,15 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction)
|
||||||
|
|
||||||
ASSERT(minOfNextSlot > maxOfThisSlot);
|
ASSERT(minOfNextSlot > maxOfThisSlot);
|
||||||
|
|
||||||
double val = (1 - fraction) * maxOfThisSlot + fraction * minOfNextSlot;
|
*result = (1 - fraction) * maxOfThisSlot + fraction * minOfNextSlot;
|
||||||
return val;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSlot->info.size <= pMemBucket->maxCapacity) {
|
if (pSlot->info.size <= pMemBucket->maxCapacity) {
|
||||||
// data in buffer and file are merged together to be processed.
|
// data in buffer and file are merged together to be processed.
|
||||||
SFilePage *buffer = loadDataFromFilePage(pMemBucket, i);
|
SFilePage *buffer = loadDataFromFilePage(pMemBucket, i);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
return -1;
|
return TSDB_CODE_NO_AVAIL_DISK;
|
||||||
}
|
}
|
||||||
int32_t currentIdx = count - num;
|
int32_t currentIdx = count - num;
|
||||||
|
|
||||||
|
@ -495,13 +493,14 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction)
|
||||||
GET_TYPED_DATA(td, double, pMemBucket->type, thisVal);
|
GET_TYPED_DATA(td, double, pMemBucket->type, thisVal);
|
||||||
GET_TYPED_DATA(nd, double, pMemBucket->type, nextVal);
|
GET_TYPED_DATA(nd, double, pMemBucket->type, nextVal);
|
||||||
|
|
||||||
double val = (1 - fraction) * td + fraction * nd;
|
*result = (1 - fraction) * td + fraction * nd;
|
||||||
taosMemoryFreeClear(buffer);
|
taosMemoryFreeClear(buffer);
|
||||||
|
|
||||||
return val;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else { // incur a second round bucket split
|
} else { // incur a second round bucket split
|
||||||
if (isIdenticalData(pMemBucket, i)) {
|
if (isIdenticalData(pMemBucket, i)) {
|
||||||
return getIdenticalDataVal(pMemBucket, i);
|
*result = getIdenticalDataVal(pMemBucket, i);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try next round
|
// try next round
|
||||||
|
@ -521,35 +520,37 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction)
|
||||||
int32_t *pageId = taosArrayGet(list, f);
|
int32_t *pageId = taosArrayGet(list, f);
|
||||||
SFilePage *pg = getBufPage(pMemBucket->pBuffer, *pageId);
|
SFilePage *pg = getBufPage(pMemBucket->pBuffer, *pageId);
|
||||||
if (pg == NULL) {
|
if (pg == NULL) {
|
||||||
return -1;
|
return TSDB_CODE_NO_AVAIL_DISK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = tMemBucketPut(pMemBucket, pg->data, (int32_t)pg->num);
|
int32_t code = tMemBucketPut(pMemBucket, pg->data, (int32_t)pg->num);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
setBufPageDirty(pg, true);
|
setBufPageDirty(pg, true);
|
||||||
releaseBufPage(pMemBucket->pBuffer, pg);
|
releaseBufPage(pMemBucket->pBuffer, pg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getPercentileImpl(pMemBucket, count - num, fraction);
|
return getPercentileImpl(pMemBucket, count - num, fraction, result);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
num += pSlot->info.size;
|
num += pSlot->info.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
*result = 0;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getPercentile(tMemBucket *pMemBucket, double percent) {
|
int32_t getPercentile(tMemBucket *pMemBucket, double percent, double *result) {
|
||||||
if (pMemBucket->total == 0) {
|
if (pMemBucket->total == 0) {
|
||||||
return 0.0;
|
*result = 0.0;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if only one elements exists, return it
|
// if only one elements exists, return it
|
||||||
if (pMemBucket->total == 1) {
|
if (pMemBucket->total == 1) {
|
||||||
return findOnlyResult(pMemBucket);
|
return findOnlyResult(pMemBucket, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
percent = fabs(percent);
|
percent = fabs(percent);
|
||||||
|
@ -559,21 +560,21 @@ double getPercentile(tMemBucket *pMemBucket, double percent) {
|
||||||
MinMaxEntry *pRange = &pMemBucket->range;
|
MinMaxEntry *pRange = &pMemBucket->range;
|
||||||
|
|
||||||
if (IS_SIGNED_NUMERIC_TYPE(pMemBucket->type)) {
|
if (IS_SIGNED_NUMERIC_TYPE(pMemBucket->type)) {
|
||||||
double v = (double)(fabs(percent - 100) < DBL_EPSILON ? pRange->i64MaxVal : pRange->i64MinVal);
|
*result = (double)(fabs(percent - 100) < DBL_EPSILON ? pRange->i64MaxVal : pRange->i64MinVal);
|
||||||
return v;
|
|
||||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(pMemBucket->type)) {
|
} else if (IS_UNSIGNED_NUMERIC_TYPE(pMemBucket->type)) {
|
||||||
double v = (double)(fabs(percent - 100) < DBL_EPSILON ? pRange->u64MaxVal : pRange->u64MinVal);
|
*result = (double)(fabs(percent - 100) < DBL_EPSILON ? pRange->u64MaxVal : pRange->u64MinVal);
|
||||||
return v;
|
|
||||||
} else {
|
} else {
|
||||||
return fabs(percent - 100) < DBL_EPSILON ? pRange->dMaxVal : pRange->dMinVal;
|
*result = fabs(percent - 100) < DBL_EPSILON ? pRange->dMaxVal : pRange->dMinVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
double percentVal = (percent * (pMemBucket->total - 1)) / ((double)100.0);
|
double percentVal = (percent * (pMemBucket->total - 1)) / ((double)100.0);
|
||||||
|
|
||||||
// do put data by using buckets
|
// do put data by using buckets
|
||||||
int32_t orderIdx = (int32_t)percentVal;
|
int32_t orderIdx = (int32_t)percentVal;
|
||||||
return getPercentileImpl(pMemBucket, orderIdx, percentVal - orderIdx);
|
return getPercentileImpl(pMemBucket, orderIdx, percentVal - orderIdx, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
static SMonitor tsMonitor = {0};
|
static SMonitor tsMonitor = {0};
|
||||||
|
static char* tsMonUri = "/report";
|
||||||
|
|
||||||
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
void monRecordLog(int64_t ts, ELogLevel level, const char *content) {
|
||||||
taosThreadMutexLock(&tsMonitor.lock);
|
taosThreadMutexLock(&tsMonitor.lock);
|
||||||
|
@ -550,7 +551,7 @@ void monSendReport() {
|
||||||
// uDebugL("report cont:%s\n", pCont);
|
// uDebugL("report cont:%s\n", pCont);
|
||||||
if (pCont != NULL) {
|
if (pCont != NULL) {
|
||||||
EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT;
|
EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT;
|
||||||
if (taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) {
|
if (taosSendHttpReport(tsMonitor.cfg.server, tsMonUri, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) {
|
||||||
uError("failed to send monitor msg");
|
uError("failed to send monitor msg");
|
||||||
}
|
}
|
||||||
taosMemoryFree(pCont);
|
taosMemoryFree(pCont);
|
||||||
|
|
|
@ -1334,6 +1334,7 @@ static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetO
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pSetOp->precision = pSetOperator->precision;
|
||||||
*pLogicNode = (SLogicNode*)pSetOp;
|
*pLogicNode = (SLogicNode*)pSetOp;
|
||||||
} else {
|
} else {
|
||||||
nodesDestroyNode((SNode*)pSetOp);
|
nodesDestroyNode((SNode*)pSetOp);
|
||||||
|
|
|
@ -69,8 +69,7 @@ _err:
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamMetaClose(SStreamMeta* pMeta) {
|
void streamMetaClose(SStreamMeta* pMeta) {
|
||||||
tdbCommit(pMeta->db, pMeta->txn);
|
tdbAbort(pMeta->db, pMeta->txn);
|
||||||
tdbPostCommit(pMeta->db, pMeta->txn);
|
|
||||||
tdbTbClose(pMeta->pTaskDb);
|
tdbTbClose(pMeta->pTaskDb);
|
||||||
tdbTbClose(pMeta->pCheckpointDb);
|
tdbTbClose(pMeta->pCheckpointDb);
|
||||||
tdbClose(pMeta->db);
|
tdbClose(pMeta->db);
|
||||||
|
@ -88,6 +87,7 @@ void streamMetaClose(SStreamMeta* pMeta) {
|
||||||
/*streamMetaReleaseTask(pMeta, pTask);*/
|
/*streamMetaReleaseTask(pMeta, pTask);*/
|
||||||
}
|
}
|
||||||
taosHashCleanup(pMeta->pTasks);
|
taosHashCleanup(pMeta->pTasks);
|
||||||
|
taosHashCleanup(pMeta->pRecoverStatus);
|
||||||
taosMemoryFree(pMeta->path);
|
taosMemoryFree(pMeta->path);
|
||||||
taosMemoryFree(pMeta);
|
taosMemoryFree(pMeta);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,9 @@ typedef struct SyncRequestVoteReply SyncRequestVoteReply;
|
||||||
typedef struct SyncAppendEntries SyncAppendEntries;
|
typedef struct SyncAppendEntries SyncAppendEntries;
|
||||||
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
|
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
|
||||||
typedef struct SSyncEnv SSyncEnv;
|
typedef struct SSyncEnv SSyncEnv;
|
||||||
typedef struct SRaftStore SRaftStore;
|
|
||||||
typedef struct SVotesGranted SVotesGranted;
|
typedef struct SVotesGranted SVotesGranted;
|
||||||
typedef struct SVotesRespond SVotesRespond;
|
typedef struct SVotesRespond SVotesRespond;
|
||||||
typedef struct SSyncIndexMgr SSyncIndexMgr;
|
typedef struct SSyncIndexMgr SSyncIndexMgr;
|
||||||
typedef struct SRaftCfg SRaftCfg;
|
|
||||||
typedef struct SSyncRespMgr SSyncRespMgr;
|
typedef struct SSyncRespMgr SSyncRespMgr;
|
||||||
typedef struct SSyncSnapshotSender SSyncSnapshotSender;
|
typedef struct SSyncSnapshotSender SSyncSnapshotSender;
|
||||||
typedef struct SSyncSnapshotReceiver SSyncSnapshotReceiver;
|
typedef struct SSyncSnapshotReceiver SSyncSnapshotReceiver;
|
||||||
|
@ -70,6 +68,11 @@ typedef struct SRaftId {
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
} SRaftId;
|
} SRaftId;
|
||||||
|
|
||||||
|
typedef struct SRaftStore {
|
||||||
|
SyncTerm currentTerm;
|
||||||
|
SRaftId voteFor;
|
||||||
|
} SRaftStore;
|
||||||
|
|
||||||
typedef struct SSyncHbTimerData {
|
typedef struct SSyncHbTimerData {
|
||||||
int64_t syncNodeRid;
|
int64_t syncNodeRid;
|
||||||
SSyncTimer* pTimer;
|
SSyncTimer* pTimer;
|
||||||
|
@ -140,7 +143,7 @@ typedef struct SSyncNode {
|
||||||
|
|
||||||
// tla+ server vars
|
// tla+ server vars
|
||||||
ESyncState state;
|
ESyncState state;
|
||||||
SRaftStore* pRaftStore;
|
SRaftStore raftStore;
|
||||||
|
|
||||||
// tla+ candidate vars
|
// tla+ candidate vars
|
||||||
SVotesGranted* pVotesGranted;
|
SVotesGranted* pVotesGranted;
|
||||||
|
@ -229,7 +232,7 @@ int32_t syncNodeStartStandBy(SSyncNode* pSyncNode);
|
||||||
void syncNodeClose(SSyncNode* pSyncNode);
|
void syncNodeClose(SSyncNode* pSyncNode);
|
||||||
void syncNodePreClose(SSyncNode* pSyncNode);
|
void syncNodePreClose(SSyncNode* pSyncNode);
|
||||||
void syncNodePostClose(SSyncNode* pSyncNode);
|
void syncNodePostClose(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_t *seq);
|
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_t* seq);
|
||||||
int32_t syncNodeRestore(SSyncNode* pSyncNode);
|
int32_t syncNodeRestore(SSyncNode* pSyncNode);
|
||||||
void syncHbTimerDataFree(SSyncHbTimerData* pData);
|
void syncHbTimerDataFree(SSyncHbTimerData* pData);
|
||||||
|
|
||||||
|
|
|
@ -247,8 +247,8 @@ typedef struct SyncLocalCmd {
|
||||||
SRaftId destId;
|
SRaftId destId;
|
||||||
|
|
||||||
int32_t cmd;
|
int32_t cmd;
|
||||||
SyncTerm sdNewTerm; // step down new term
|
SyncTerm currentTerm; // step down new term
|
||||||
SyncIndex fcIndex; // follower commit index
|
SyncIndex commitIndex; // follower commit index
|
||||||
} SyncLocalCmd;
|
} SyncLocalCmd;
|
||||||
|
|
||||||
int32_t syncBuildTimeout(SRpcMsg* pMsg, ESyncTimeoutType ttype, uint64_t logicClock, int32_t ms, SSyncNode* pNode);
|
int32_t syncBuildTimeout(SRpcMsg* pMsg, ESyncTimeoutType ttype, uint64_t logicClock, int32_t ms, SSyncNode* pNode);
|
||||||
|
@ -258,7 +258,7 @@ int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId);
|
||||||
int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId);
|
int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId);
|
||||||
int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId);
|
int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId);
|
||||||
int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId);
|
int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId);
|
||||||
int32_t syncBuildAppendEntriesFromRaftLog(SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevLogTerm,
|
int32_t syncBuildAppendEntriesFromRaftEntry(SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevLogTerm,
|
||||||
SRpcMsg* pRpcMsg);
|
SRpcMsg* pRpcMsg);
|
||||||
int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId);
|
int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId);
|
||||||
int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId);
|
int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId);
|
||||||
|
|
|
@ -78,14 +78,14 @@ static FORCE_INLINE int32_t syncLogGetNextRetryBackoff(SSyncLogReplMgr* pMgr) {
|
||||||
SyncTerm syncLogReplMgrGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
SyncTerm syncLogReplMgrGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
int32_t syncLogReplMgrReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
||||||
int32_t syncLogBufferReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
int32_t syncLogReplMgrReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
||||||
SRaftId* pDestId, bool* pBarrier);
|
SRaftId* pDestId, bool* pBarrier);
|
||||||
int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
||||||
int32_t syncLogReplMgrReplicateProbeOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
||||||
int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
||||||
int32_t syncLogReplMgrProcessReplyInNormalMode(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
int32_t syncLogReplMgrProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg);
|
int32_t syncLogReplMgrProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg);
|
||||||
int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
||||||
|
@ -98,6 +98,7 @@ int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode);
|
||||||
|
|
||||||
// access
|
// access
|
||||||
int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf);
|
int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf);
|
||||||
|
SyncTerm syncLogBufferGetLastMatchTerm(SSyncLogBuffer* pBuf);
|
||||||
int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry);
|
int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry);
|
||||||
int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm);
|
int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm);
|
||||||
int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm);
|
int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm);
|
||||||
|
|
|
@ -24,27 +24,16 @@ extern "C" {
|
||||||
|
|
||||||
#define RAFT_STORE_BLOCK_SIZE 512
|
#define RAFT_STORE_BLOCK_SIZE 512
|
||||||
#define RAFT_STORE_PATH_LEN (TSDB_FILENAME_LEN * 2)
|
#define RAFT_STORE_PATH_LEN (TSDB_FILENAME_LEN * 2)
|
||||||
|
|
||||||
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
||||||
|
|
||||||
typedef struct SRaftStore {
|
int32_t raftStoreReadFile(SSyncNode *pNode);
|
||||||
SyncTerm currentTerm;
|
int32_t raftStoreWriteFile(SSyncNode *pNode);
|
||||||
SRaftId voteFor;
|
|
||||||
TdFilePtr pFile;
|
|
||||||
char path[RAFT_STORE_PATH_LEN];
|
|
||||||
} SRaftStore;
|
|
||||||
|
|
||||||
SRaftStore *raftStoreOpen(const char *path);
|
bool raftStoreHasVoted(SSyncNode *pNode);
|
||||||
int32_t raftStoreClose(SRaftStore *pRaftStore);
|
void raftStoreVote(SSyncNode *pNode, SRaftId *pRaftId);
|
||||||
int32_t raftStorePersist(SRaftStore *pRaftStore);
|
void raftStoreClearVote(SSyncNode *pNode);
|
||||||
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
void raftStoreNextTerm(SSyncNode *pNode);
|
||||||
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
void raftStoreSetTerm(SSyncNode *pNode, SyncTerm term);
|
||||||
|
|
||||||
bool raftStoreHasVoted(SRaftStore *pRaftStore);
|
|
||||||
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId);
|
|
||||||
void raftStoreClearVote(SRaftStore *pRaftStore);
|
|
||||||
void raftStoreNextTerm(SRaftStore *pRaftStore);
|
|
||||||
void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
||||||
|
ASSERT(false && "deprecated");
|
||||||
if (ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
if (ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
sNTrace(ths, "can not do follower commit");
|
sNTrace(ths, "can not do follower commit");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -127,7 +128,7 @@ int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry* syncLogAppendEntriesToRaftEntry(const SyncAppendEntries* pMsg) {
|
SSyncRaftEntry* syncBuildRaftEntryFromAppendEntries(const SyncAppendEntries* pMsg) {
|
||||||
SSyncRaftEntry* pEntry = taosMemoryMalloc(pMsg->dataLen);
|
SSyncRaftEntry* pEntry = taosMemoryMalloc(pMsg->dataLen);
|
||||||
if (pEntry == NULL) {
|
if (pEntry == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -158,17 +159,17 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
// prepare response msg
|
// prepare response msg
|
||||||
pReply->srcId = ths->myRaftId;
|
pReply->srcId = ths->myRaftId;
|
||||||
pReply->destId = pMsg->srcId;
|
pReply->destId = pMsg->srcId;
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
pReply->term = ths->raftStore.currentTerm;
|
||||||
pReply->success = false;
|
pReply->success = false;
|
||||||
pReply->matchIndex = SYNC_INDEX_INVALID;
|
pReply->matchIndex = SYNC_INDEX_INVALID;
|
||||||
pReply->lastSendIndex = pMsg->prevLogIndex + 1;
|
pReply->lastSendIndex = pMsg->prevLogIndex + 1;
|
||||||
pReply->startTime = ths->startTime;
|
pReply->startTime = ths->startTime;
|
||||||
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->raftStore.currentTerm) {
|
||||||
goto _SEND_RESPONSE;
|
goto _SEND_RESPONSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->raftStore.currentTerm) {
|
||||||
pReply->term = pMsg->term;
|
pReply->term = pMsg->term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
goto _IGNORE;
|
goto _IGNORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = syncLogAppendEntriesToRaftEntry(pMsg);
|
SSyncRaftEntry* pEntry = syncBuildRaftEntryFromAppendEntries(pMsg);
|
||||||
|
|
||||||
if (pEntry == NULL) {
|
if (pEntry == NULL) {
|
||||||
sError("vgId:%d, failed to get raft entry from append entries since %s", ths->vgId, terrstr());
|
sError("vgId:%d, failed to get raft entry from append entries since %s", ths->vgId, terrstr());
|
||||||
|
@ -206,12 +207,13 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
accepted = true;
|
accepted = true;
|
||||||
|
|
||||||
_SEND_RESPONSE:
|
_SEND_RESPONSE:
|
||||||
|
pEntry = NULL;
|
||||||
pReply->matchIndex = syncLogBufferProceed(ths->pLogBuf, ths, &pReply->lastMatchTerm);
|
pReply->matchIndex = syncLogBufferProceed(ths->pLogBuf, ths, &pReply->lastMatchTerm);
|
||||||
bool matched = (pReply->matchIndex >= pReply->lastSendIndex);
|
bool matched = (pReply->matchIndex >= pReply->lastSendIndex);
|
||||||
if (accepted && matched) {
|
if (accepted && matched) {
|
||||||
pReply->success = true;
|
pReply->success = true;
|
||||||
// update commit index only after matching
|
// update commit index only after matching
|
||||||
(void)syncNodeUpdateCommitIndex(ths, pMsg->commitIndex);
|
(void)syncNodeUpdateCommitIndex(ths, TMIN(pMsg->commitIndex, pReply->lastSendIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ack, i.e. send response
|
// ack, i.e. send response
|
||||||
|
@ -251,19 +253,19 @@ int32_t syncNodeOnAppendEntriesOld(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
SyncAppendEntriesReply* pReply = rpcRsp.pCont;
|
SyncAppendEntriesReply* pReply = rpcRsp.pCont;
|
||||||
pReply->srcId = ths->myRaftId;
|
pReply->srcId = ths->myRaftId;
|
||||||
pReply->destId = pMsg->srcId;
|
pReply->destId = pMsg->srcId;
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
pReply->term = ths->raftStore.currentTerm;
|
||||||
pReply->success = false;
|
pReply->success = false;
|
||||||
// pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
// pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
||||||
pReply->matchIndex = SYNC_INDEX_INVALID;
|
pReply->matchIndex = SYNC_INDEX_INVALID;
|
||||||
pReply->lastSendIndex = pMsg->prevLogIndex + 1;
|
pReply->lastSendIndex = pMsg->prevLogIndex + 1;
|
||||||
pReply->startTime = ths->startTime;
|
pReply->startTime = ths->startTime;
|
||||||
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->raftStore.currentTerm) {
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "reject, small term");
|
syncLogRecvAppendEntries(ths, pMsg, "reject, small term");
|
||||||
goto _SEND_RESPONSE;
|
goto _SEND_RESPONSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->raftStore.currentTerm) {
|
||||||
pReply->term = pMsg->term;
|
pReply->term = pMsg->term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,19 +50,19 @@ int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop stale response
|
// drop stale response
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->raftStore.currentTerm) {
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response");
|
syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->raftStore.currentTerm) {
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
||||||
syncNodeStepDown(ths, pMsg->term);
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
ASSERT(pMsg->term == ths->raftStore.currentTerm);
|
||||||
|
|
||||||
sTrace("vgId:%d, received append entries reply. srcId:0x%016" PRIx64 ", term:%" PRId64 ", matchIndex:%" PRId64 "",
|
sTrace("vgId:%d, received append entries reply. srcId:0x%016" PRIx64 ", term:%" PRId64 ", matchIndex:%" PRId64 "",
|
||||||
pMsg->vgId, pMsg->srcId.addr, pMsg->term, pMsg->matchIndex);
|
pMsg->vgId, pMsg->srcId.addr, pMsg->term, pMsg->matchIndex);
|
||||||
|
@ -100,19 +100,19 @@ int32_t syncNodeOnAppendEntriesReplyOld(SSyncNode* ths, SyncAppendEntriesReply*
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop stale response
|
// drop stale response
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->raftStore.currentTerm) {
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response");
|
syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->raftStore.currentTerm) {
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
||||||
syncNodeStepDown(ths, pMsg->term);
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
ASSERT(pMsg->term == ths->raftStore.currentTerm);
|
||||||
|
|
||||||
if (pMsg->success) {
|
if (pMsg->success) {
|
||||||
SyncIndex oldMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
SyncIndex oldMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
||||||
//
|
//
|
||||||
void syncOneReplicaAdvance(SSyncNode* pSyncNode) {
|
void syncOneReplicaAdvance(SSyncNode* pSyncNode) {
|
||||||
|
ASSERT(false && "deprecated");
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) {
|
||||||
sError("pSyncNode is NULL");
|
sError("pSyncNode is NULL");
|
||||||
return;
|
return;
|
||||||
|
@ -132,7 +133,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cannot commit, even if quorum agree. need check term!
|
// cannot commit, even if quorum agree. need check term!
|
||||||
if (pEntry->term <= pSyncNode->pRaftStore->currentTerm) {
|
if (pEntry->term <= pSyncNode->raftStore.currentTerm) {
|
||||||
// update commit index
|
// update commit index
|
||||||
newCommitIndex = index;
|
newCommitIndex = index;
|
||||||
|
|
||||||
|
@ -328,7 +329,7 @@ int64_t syncNodeCheckCommitIndex(SSyncNode* ths, SyncIndex indexLikely) {
|
||||||
SyncIndex commitIndex = indexLikely;
|
SyncIndex commitIndex = indexLikely;
|
||||||
syncNodeUpdateCommitIndex(ths, commitIndex);
|
syncNodeUpdateCommitIndex(ths, commitIndex);
|
||||||
sTrace("vgId:%d, agreed upon. role:%d, term:%" PRId64 ", index: %" PRId64 "", ths->vgId, ths->state,
|
sTrace("vgId:%d, agreed upon. role:%d, term:%" PRId64 ", index: %" PRId64 "", ths->vgId, ths->state,
|
||||||
ths->pRaftStore->currentTerm, commitIndex);
|
ths->raftStore.currentTerm, commitIndex);
|
||||||
}
|
}
|
||||||
return ths->commitIndex;
|
return ths->commitIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ static int32_t syncNodeRequestVotePeers(SSyncNode* pNode) {
|
||||||
SyncRequestVote* pMsg = rpcMsg.pCont;
|
SyncRequestVote* pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pNode->myRaftId;
|
pMsg->srcId = pNode->myRaftId;
|
||||||
pMsg->destId = pNode->peersId[i];
|
pMsg->destId = pNode->peersId[i];
|
||||||
pMsg->term = pNode->pRaftStore->currentTerm;
|
pMsg->term = pNode->raftStore.currentTerm;
|
||||||
|
|
||||||
ret = syncNodeGetLastIndexTerm(pNode, &pMsg->lastLogIndex, &pMsg->lastLogTerm);
|
ret = syncNodeGetLastIndexTerm(pNode, &pMsg->lastLogIndex, &pMsg->lastLogTerm);
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
@ -75,10 +75,10 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// start election
|
// start election
|
||||||
raftStoreNextTerm(pSyncNode->pRaftStore);
|
raftStoreNextTerm(pSyncNode);
|
||||||
raftStoreClearVote(pSyncNode->pRaftStore);
|
raftStoreClearVote(pSyncNode);
|
||||||
voteGrantedReset(pSyncNode->pVotesGranted, pSyncNode->pRaftStore->currentTerm);
|
voteGrantedReset(pSyncNode->pVotesGranted, pSyncNode->raftStore.currentTerm);
|
||||||
votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->pRaftStore->currentTerm);
|
votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->raftStore.currentTerm);
|
||||||
|
|
||||||
syncNodeVoteForSelf(pSyncNode);
|
syncNodeVoteForSelf(pSyncNode);
|
||||||
if (voteGrantedMajority(pSyncNode->pVotesGranted)) {
|
if (voteGrantedMajority(pSyncNode->pVotesGranted)) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ void syncHbTimerDataRemove(int64_t rid) { taosRemoveRef(gHbDataRefId, rid); }
|
||||||
|
|
||||||
SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) {
|
SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) {
|
||||||
SSyncHbTimerData *pData = taosAcquireRef(gHbDataRefId, rid);
|
SSyncHbTimerData *pData = taosAcquireRef(gHbDataRefId, rid);
|
||||||
if (pData == NULL) {
|
if (pData == NULL && rid > 0) {
|
||||||
sInfo("failed to acquire hb-timer-data from refId:%" PRId64, rid);
|
sInfo("failed to acquire hb-timer-data from refId:%" PRId64, rid);
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,7 +468,7 @@ bool syncNodeIsReadyForRead(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code == 0 && pEntry != NULL) {
|
if (code == 0 && pEntry != NULL) {
|
||||||
if (pEntry->originalRpcType == TDMT_SYNC_NOOP && pEntry->term == pSyncNode->pRaftStore->currentTerm) {
|
if (pEntry->originalRpcType == TDMT_SYNC_NOOP && pEntry->term == pSyncNode->raftStore.currentTerm) {
|
||||||
ready = true;
|
ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +736,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_
|
||||||
int32_t code = syncNodeOnClientRequest(pSyncNode, pMsg, &retIndex);
|
int32_t code = syncNodeOnClientRequest(pSyncNode, pMsg, &retIndex);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
pMsg->info.conn.applyIndex = retIndex;
|
pMsg->info.conn.applyIndex = retIndex;
|
||||||
pMsg->info.conn.applyTerm = pSyncNode->pRaftStore->currentTerm;
|
pMsg->info.conn.applyTerm = pSyncNode->raftStore.currentTerm;
|
||||||
sTrace("vgId:%d, propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex,
|
sTrace("vgId:%d, propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex,
|
||||||
TMSG_INFO(pMsg->msgType));
|
TMSG_INFO(pMsg->msgType));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -983,8 +983,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
|
|
||||||
// init TLA+ server vars
|
// init TLA+ server vars
|
||||||
pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER;
|
pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER;
|
||||||
pSyncNode->pRaftStore = raftStoreOpen(pSyncNode->raftStorePath);
|
if (raftStoreReadFile(pSyncNode) != 0) {
|
||||||
if (pSyncNode->pRaftStore == NULL) {
|
|
||||||
sError("vgId:%d, failed to open raft store at path %s", pSyncNode->vgId, pSyncNode->raftStorePath);
|
sError("vgId:%d, failed to open raft store at path %s", pSyncNode->vgId, pSyncNode->raftStorePath);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
@ -1030,6 +1029,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSyncNode->commitIndex = commitIndex;
|
pSyncNode->commitIndex = commitIndex;
|
||||||
|
sInfo("vgId:%d, sync node commitIndex initialized as %" PRId64, pSyncNode->vgId, pSyncNode->commitIndex);
|
||||||
|
|
||||||
if (syncNodeLogStoreRestoreOnNeed(pSyncNode) < 0) {
|
if (syncNodeLogStoreRestoreOnNeed(pSyncNode) < 0) {
|
||||||
goto _error;
|
goto _error;
|
||||||
|
@ -1170,9 +1170,10 @@ int32_t syncNodeRestore(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(endIndex == lastVer + 1);
|
ASSERT(endIndex == lastVer + 1);
|
||||||
commitIndex = TMAX(pSyncNode->commitIndex, commitIndex);
|
pSyncNode->commitIndex = TMAX(pSyncNode->commitIndex, commitIndex);
|
||||||
|
sInfo("vgId:%d, restore sync until commitIndex:%" PRId64, pSyncNode->vgId, pSyncNode->commitIndex);
|
||||||
|
|
||||||
if (syncLogBufferCommit(pSyncNode->pLogBuf, pSyncNode, commitIndex) < 0) {
|
if (syncLogBufferCommit(pSyncNode->pLogBuf, pSyncNode, pSyncNode->commitIndex) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1182,7 +1183,7 @@ int32_t syncNodeRestore(SSyncNode* pSyncNode) {
|
||||||
int32_t syncNodeStart(SSyncNode* pSyncNode) {
|
int32_t syncNodeStart(SSyncNode* pSyncNode) {
|
||||||
// start raft
|
// start raft
|
||||||
if (pSyncNode->replicaNum == 1) {
|
if (pSyncNode->replicaNum == 1) {
|
||||||
raftStoreNextTerm(pSyncNode->pRaftStore);
|
raftStoreNextTerm(pSyncNode);
|
||||||
syncNodeBecomeLeader(pSyncNode, "one replica start");
|
syncNodeBecomeLeader(pSyncNode, "one replica start");
|
||||||
|
|
||||||
// Raft 3.6.2 Committing entries from previous terms
|
// Raft 3.6.2 Committing entries from previous terms
|
||||||
|
@ -1200,7 +1201,7 @@ int32_t syncNodeStart(SSyncNode* pSyncNode) {
|
||||||
void syncNodeStartOld(SSyncNode* pSyncNode) {
|
void syncNodeStartOld(SSyncNode* pSyncNode) {
|
||||||
// start raft
|
// start raft
|
||||||
if (pSyncNode->replicaNum == 1) {
|
if (pSyncNode->replicaNum == 1) {
|
||||||
raftStoreNextTerm(pSyncNode->pRaftStore);
|
raftStoreNextTerm(pSyncNode);
|
||||||
syncNodeBecomeLeader(pSyncNode, "one replica start");
|
syncNodeBecomeLeader(pSyncNode, "one replica start");
|
||||||
|
|
||||||
// Raft 3.6.2 Committing entries from previous terms
|
// Raft 3.6.2 Committing entries from previous terms
|
||||||
|
@ -1286,10 +1287,6 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
if (pSyncNode == NULL) return;
|
if (pSyncNode == NULL) return;
|
||||||
sNInfo(pSyncNode, "sync close, node:%p", pSyncNode);
|
sNInfo(pSyncNode, "sync close, node:%p", pSyncNode);
|
||||||
|
|
||||||
int32_t ret = raftStoreClose(pSyncNode->pRaftStore);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
pSyncNode->pRaftStore = NULL;
|
|
||||||
|
|
||||||
syncNodeLogReplMgrDestroy(pSyncNode);
|
syncNodeLogReplMgrDestroy(pSyncNode);
|
||||||
syncRespMgrDestroy(pSyncNode->pSyncRespMgr);
|
syncRespMgrDestroy(pSyncNode->pSyncRespMgr);
|
||||||
pSyncNode->pSyncRespMgr = NULL;
|
pSyncNode->pSyncRespMgr = NULL;
|
||||||
|
@ -1480,16 +1477,21 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pNode, SRpcMsg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t code = -1;
|
||||||
if (pNode->syncSendMSg != NULL && epSet != NULL) {
|
if (pNode->syncSendMSg != NULL && epSet != NULL) {
|
||||||
syncUtilMsgHtoN(pMsg->pCont);
|
syncUtilMsgHtoN(pMsg->pCont);
|
||||||
pMsg->info.noResp = 1;
|
pMsg->info.noResp = 1;
|
||||||
return pNode->syncSendMSg(epSet, pMsg);
|
code = pNode->syncSendMSg(epSet, pMsg);
|
||||||
} else {
|
}
|
||||||
sError("vgId:%d, sync send msg by id error, fp:%p epset:%p", pNode->vgId, pNode->syncSendMSg, epSet);
|
|
||||||
|
if (code < 0) {
|
||||||
|
sError("vgId:%d, sync send msg by id error, epset:%p dnode:%d addr:%" PRId64 " err:0x%x", pNode->vgId, epSet,
|
||||||
|
DID(destRaftId), destRaftId->addr, terrno);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool syncNodeInConfig(SSyncNode* pNode, const SSyncCfg* pCfg) {
|
inline bool syncNodeInConfig(SSyncNode* pNode, const SSyncCfg* pCfg) {
|
||||||
|
@ -1707,39 +1709,39 @@ _END:
|
||||||
|
|
||||||
// raft state change --------------
|
// raft state change --------------
|
||||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
|
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
|
||||||
if (term > pSyncNode->pRaftStore->currentTerm) {
|
if (term > pSyncNode->raftStore.currentTerm) {
|
||||||
raftStoreSetTerm(pSyncNode->pRaftStore, term);
|
raftStoreSetTerm(pSyncNode, term);
|
||||||
char tmpBuf[64];
|
char tmpBuf[64];
|
||||||
snprintf(tmpBuf, sizeof(tmpBuf), "update term to %" PRId64, term);
|
snprintf(tmpBuf, sizeof(tmpBuf), "update term to %" PRId64, term);
|
||||||
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
||||||
raftStoreClearVote(pSyncNode->pRaftStore);
|
raftStoreClearVote(pSyncNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) {
|
void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) {
|
||||||
if (term > pSyncNode->pRaftStore->currentTerm) {
|
if (term > pSyncNode->raftStore.currentTerm) {
|
||||||
raftStoreSetTerm(pSyncNode->pRaftStore, term);
|
raftStoreSetTerm(pSyncNode, term);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) {
|
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) {
|
||||||
if (pSyncNode->pRaftStore->currentTerm > newTerm) {
|
if (pSyncNode->raftStore.currentTerm > newTerm) {
|
||||||
sNTrace(pSyncNode, "step down, ignore, new-term:%" PRId64 ", current-term:%" PRId64, newTerm,
|
sNTrace(pSyncNode, "step down, ignore, new-term:%" PRId64 ", current-term:%" PRId64, newTerm,
|
||||||
pSyncNode->pRaftStore->currentTerm);
|
pSyncNode->raftStore.currentTerm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sNTrace(pSyncNode, "step down, new-term:%" PRId64 ", current-term:%" PRId64, newTerm,
|
sNTrace(pSyncNode, "step down, new-term:%" PRId64 ", current-term:%" PRId64, newTerm,
|
||||||
pSyncNode->pRaftStore->currentTerm);
|
pSyncNode->raftStore.currentTerm);
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (pSyncNode->pRaftStore->currentTerm < newTerm) {
|
if (pSyncNode->raftStore.currentTerm < newTerm) {
|
||||||
raftStoreSetTerm(pSyncNode->pRaftStore, newTerm);
|
raftStoreSetTerm(pSyncNode, newTerm);
|
||||||
char tmpBuf[64];
|
char tmpBuf[64];
|
||||||
snprintf(tmpBuf, sizeof(tmpBuf), "step down, update term to %" PRId64, newTerm);
|
snprintf(tmpBuf, sizeof(tmpBuf), "step down, update term to %" PRId64, newTerm);
|
||||||
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
||||||
raftStoreClearVote(pSyncNode->pRaftStore);
|
raftStoreClearVote(pSyncNode);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_FOLLOWER) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
|
@ -1897,7 +1899,7 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
|
||||||
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
||||||
ASSERT(lastIndex >= 0);
|
ASSERT(lastIndex >= 0);
|
||||||
sInfo("vgId:%d, become leader. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64 "",
|
sInfo("vgId:%d, become leader. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64 "",
|
||||||
pSyncNode->vgId, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, lastIndex);
|
pSyncNode->vgId, pSyncNode->raftStore.currentTerm, pSyncNode->commitIndex, lastIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeCandidate2LeaderOld(SSyncNode* pSyncNode) {
|
void syncNodeCandidate2LeaderOld(SSyncNode* pSyncNode) {
|
||||||
|
@ -1930,7 +1932,7 @@ void syncNodeFollower2Candidate(SSyncNode* pSyncNode) {
|
||||||
pSyncNode->state = TAOS_SYNC_STATE_CANDIDATE;
|
pSyncNode->state = TAOS_SYNC_STATE_CANDIDATE;
|
||||||
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
||||||
sInfo("vgId:%d, become candidate from follower. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64,
|
sInfo("vgId:%d, become candidate from follower. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64,
|
||||||
pSyncNode->vgId, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, lastIndex);
|
pSyncNode->vgId, pSyncNode->raftStore.currentTerm, pSyncNode->commitIndex, lastIndex);
|
||||||
|
|
||||||
sNTrace(pSyncNode, "follower to candidate");
|
sNTrace(pSyncNode, "follower to candidate");
|
||||||
}
|
}
|
||||||
|
@ -1940,7 +1942,7 @@ void syncNodeLeader2Follower(SSyncNode* pSyncNode) {
|
||||||
syncNodeBecomeFollower(pSyncNode, "leader to follower");
|
syncNodeBecomeFollower(pSyncNode, "leader to follower");
|
||||||
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
||||||
sInfo("vgId:%d, become follower from leader. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64,
|
sInfo("vgId:%d, become follower from leader. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64,
|
||||||
pSyncNode->vgId, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, lastIndex);
|
pSyncNode->vgId, pSyncNode->raftStore.currentTerm, pSyncNode->commitIndex, lastIndex);
|
||||||
|
|
||||||
sNTrace(pSyncNode, "leader to follower");
|
sNTrace(pSyncNode, "leader to follower");
|
||||||
}
|
}
|
||||||
|
@ -1950,7 +1952,7 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
|
||||||
syncNodeBecomeFollower(pSyncNode, "candidate to follower");
|
syncNodeBecomeFollower(pSyncNode, "candidate to follower");
|
||||||
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
||||||
sInfo("vgId:%d, become follower from candidate. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64,
|
sInfo("vgId:%d, become follower from candidate. term: %" PRId64 ", commit index: %" PRId64 ", last index: %" PRId64,
|
||||||
pSyncNode->vgId, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, lastIndex);
|
pSyncNode->vgId, pSyncNode->raftStore.currentTerm, pSyncNode->commitIndex, lastIndex);
|
||||||
|
|
||||||
sNTrace(pSyncNode, "candidate to follower");
|
sNTrace(pSyncNode, "candidate to follower");
|
||||||
}
|
}
|
||||||
|
@ -1958,15 +1960,15 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
|
||||||
// just called by syncNodeVoteForSelf
|
// just called by syncNodeVoteForSelf
|
||||||
// need assert
|
// need assert
|
||||||
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) {
|
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) {
|
||||||
ASSERT(term == pSyncNode->pRaftStore->currentTerm);
|
ASSERT(term == pSyncNode->raftStore.currentTerm);
|
||||||
ASSERT(!raftStoreHasVoted(pSyncNode->pRaftStore));
|
ASSERT(!raftStoreHasVoted(pSyncNode));
|
||||||
|
|
||||||
raftStoreVote(pSyncNode->pRaftStore, pRaftId);
|
raftStoreVote(pSyncNode, pRaftId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// simulate get vote from outside
|
// simulate get vote from outside
|
||||||
void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
||||||
syncNodeVoteForTerm(pSyncNode, pSyncNode->pRaftStore->currentTerm, &pSyncNode->myRaftId);
|
syncNodeVoteForTerm(pSyncNode, pSyncNode->raftStore.currentTerm, &pSyncNode->myRaftId);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
int32_t ret = syncBuildRequestVoteReply(&rpcMsg, pSyncNode->vgId);
|
int32_t ret = syncBuildRequestVoteReply(&rpcMsg, pSyncNode->vgId);
|
||||||
|
@ -1975,7 +1977,7 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
||||||
SyncRequestVoteReply* pMsg = rpcMsg.pCont;
|
SyncRequestVoteReply* pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
pMsg->srcId = pSyncNode->myRaftId;
|
||||||
pMsg->destId = pSyncNode->myRaftId;
|
pMsg->destId = pSyncNode->myRaftId;
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pMsg->voteGranted = true;
|
pMsg->voteGranted = true;
|
||||||
|
|
||||||
voteGrantedVote(pSyncNode->pVotesGranted, pMsg);
|
voteGrantedVote(pSyncNode->pVotesGranted, pMsg);
|
||||||
|
@ -2265,13 +2267,6 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSyncNode->pRaftStore == NULL) {
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
syncHbTimerDataRelease(pData);
|
|
||||||
sError("vgId:%d, hb timer raft store already stop", pSyncNode->vgId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sTrace("vgId:%d, eq peer hb timer", pSyncNode->vgId);
|
// sTrace("vgId:%d, eq peer hb timer", pSyncNode->vgId);
|
||||||
|
|
||||||
if (pSyncNode->replicaNum > 1) {
|
if (pSyncNode->replicaNum > 1) {
|
||||||
|
@ -2295,7 +2290,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
||||||
SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
|
SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
|
||||||
pSyncMsg->srcId = pSyncNode->myRaftId;
|
pSyncMsg->srcId = pSyncNode->myRaftId;
|
||||||
pSyncMsg->destId = pData->destId;
|
pSyncMsg->destId = pData->destId;
|
||||||
pSyncMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pSyncMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pSyncMsg->commitIndex = pSyncNode->commitIndex;
|
pSyncMsg->commitIndex = pSyncNode->commitIndex;
|
||||||
pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
||||||
pSyncMsg->privateTerm = 0;
|
pSyncMsg->privateTerm = 0;
|
||||||
|
@ -2341,7 +2336,7 @@ static int32_t syncNodeEqNoop(SSyncNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex index = pNode->pLogStore->syncLogWriteIndex(pNode->pLogStore);
|
SyncIndex index = pNode->pLogStore->syncLogWriteIndex(pNode->pLogStore);
|
||||||
SyncTerm term = pNode->pRaftStore->currentTerm;
|
SyncTerm term = pNode->raftStore.currentTerm;
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, pNode->vgId);
|
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, pNode->vgId);
|
||||||
if (pEntry == NULL) return -1;
|
if (pEntry == NULL) return -1;
|
||||||
|
|
||||||
|
@ -2387,8 +2382,7 @@ int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
|
||||||
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
|
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
|
||||||
sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index);
|
sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index);
|
||||||
terrno = TSDB_CODE_SYN_BUFFER_FULL;
|
terrno = TSDB_CODE_SYN_BUFFER_FULL;
|
||||||
(void)syncLogFsmExecute(ths, ths->pFsm, ths->state, ths->pRaftStore->currentTerm, pEntry,
|
(void)syncLogFsmExecute(ths, ths->pFsm, ths->state, ths->raftStore.currentTerm, pEntry, TSDB_CODE_SYN_BUFFER_FULL);
|
||||||
TSDB_CODE_SYN_BUFFER_FULL);
|
|
||||||
syncEntryDestroy(pEntry);
|
syncEntryDestroy(pEntry);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -2461,7 +2455,7 @@ bool syncNodeSnapshotRecving(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
static int32_t syncNodeAppendNoop(SSyncNode* ths) {
|
static int32_t syncNodeAppendNoop(SSyncNode* ths) {
|
||||||
SyncIndex index = syncLogBufferGetEndIndex(ths->pLogBuf);
|
SyncIndex index = syncLogBufferGetEndIndex(ths->pLogBuf);
|
||||||
SyncTerm term = ths->pRaftStore->currentTerm;
|
SyncTerm term = ths->raftStore.currentTerm;
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId);
|
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId);
|
||||||
if (pEntry == NULL) {
|
if (pEntry == NULL) {
|
||||||
|
@ -2477,7 +2471,7 @@ static int32_t syncNodeAppendNoopOld(SSyncNode* ths) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
||||||
SyncTerm term = ths->pRaftStore->currentTerm;
|
SyncTerm term = ths->raftStore.currentTerm;
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId);
|
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId);
|
||||||
ASSERT(pEntry != NULL);
|
ASSERT(pEntry != NULL);
|
||||||
|
|
||||||
|
@ -2519,12 +2513,12 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
SyncHeartbeatReply* pMsgReply = rpcMsg.pCont;
|
SyncHeartbeatReply* pMsgReply = rpcMsg.pCont;
|
||||||
pMsgReply->destId = pMsg->srcId;
|
pMsgReply->destId = pMsg->srcId;
|
||||||
pMsgReply->srcId = ths->myRaftId;
|
pMsgReply->srcId = ths->myRaftId;
|
||||||
pMsgReply->term = ths->pRaftStore->currentTerm;
|
pMsgReply->term = ths->raftStore.currentTerm;
|
||||||
pMsgReply->privateTerm = 8864; // magic number
|
pMsgReply->privateTerm = 8864; // magic number
|
||||||
pMsgReply->startTime = ths->startTime;
|
pMsgReply->startTime = ths->startTime;
|
||||||
pMsgReply->timeStamp = tsMs;
|
pMsgReply->timeStamp = tsMs;
|
||||||
|
|
||||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_LEADER) {
|
if (pMsg->term == ths->raftStore.currentTerm && ths->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), tsMs);
|
syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), tsMs);
|
||||||
|
|
||||||
syncNodeResetElectTimer(ths);
|
syncNodeResetElectTimer(ths);
|
||||||
|
@ -2537,8 +2531,9 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
|
|
||||||
SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont;
|
SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont;
|
||||||
pSyncMsg->cmd = SYNC_LOCAL_CMD_FOLLOWER_CMT;
|
pSyncMsg->cmd = SYNC_LOCAL_CMD_FOLLOWER_CMT;
|
||||||
pSyncMsg->fcIndex = pMsg->commitIndex;
|
pSyncMsg->commitIndex = pMsg->commitIndex;
|
||||||
SyncIndex fcIndex = pSyncMsg->fcIndex;
|
pSyncMsg->currentTerm = pMsg->term;
|
||||||
|
SyncIndex fcIndex = pSyncMsg->commitIndex;
|
||||||
|
|
||||||
if (ths->syncEqMsg != NULL && ths->msgcb != NULL) {
|
if (ths->syncEqMsg != NULL && ths->msgcb != NULL) {
|
||||||
int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
||||||
|
@ -2552,14 +2547,15 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
if (pMsg->term >= ths->raftStore.currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
// syncNodeStepDown(ths, pMsg->term);
|
// syncNodeStepDown(ths, pMsg->term);
|
||||||
SRpcMsg rpcMsgLocalCmd = {0};
|
SRpcMsg rpcMsgLocalCmd = {0};
|
||||||
(void)syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId);
|
(void)syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId);
|
||||||
|
|
||||||
SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont;
|
SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont;
|
||||||
pSyncMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
pSyncMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
||||||
pSyncMsg->sdNewTerm = pMsg->term;
|
pSyncMsg->currentTerm = pMsg->term;
|
||||||
|
pSyncMsg->commitIndex = pMsg->commitIndex;
|
||||||
|
|
||||||
if (ths->syncEqMsg != NULL && ths->msgcb != NULL) {
|
if (ths->syncEqMsg != NULL && ths->msgcb != NULL) {
|
||||||
int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
||||||
|
@ -2567,7 +2563,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code);
|
sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code);
|
||||||
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
||||||
} else {
|
} else {
|
||||||
sTrace("vgId:%d, sync enqueue step-down msg, new-term: %" PRId64, ths->vgId, pSyncMsg->sdNewTerm);
|
sTrace("vgId:%d, sync enqueue step-down msg, new-term: %" PRId64, ths->vgId, pSyncMsg->currentTerm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2625,10 +2621,13 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
syncLogRecvLocalCmd(ths, pMsg, "");
|
syncLogRecvLocalCmd(ths, pMsg, "");
|
||||||
|
|
||||||
if (pMsg->cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
|
if (pMsg->cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
|
||||||
syncNodeStepDown(ths, pMsg->sdNewTerm);
|
syncNodeStepDown(ths, pMsg->currentTerm);
|
||||||
|
|
||||||
} else if (pMsg->cmd == SYNC_LOCAL_CMD_FOLLOWER_CMT) {
|
} else if (pMsg->cmd == SYNC_LOCAL_CMD_FOLLOWER_CMT) {
|
||||||
(void)syncNodeUpdateCommitIndex(ths, pMsg->fcIndex);
|
SyncTerm matchTerm = syncLogBufferGetLastMatchTerm(ths->pLogBuf);
|
||||||
|
if (pMsg->currentTerm == matchTerm) {
|
||||||
|
(void)syncNodeUpdateCommitIndex(ths, pMsg->commitIndex);
|
||||||
|
}
|
||||||
if (syncLogBufferCommit(ths->pLogBuf, ths, ths->commitIndex) < 0) {
|
if (syncLogBufferCommit(ths->pLogBuf, ths, ths->commitIndex) < 0) {
|
||||||
sError("vgId:%d, failed to commit raft log since %s. commit index: %" PRId64 "", ths->vgId, terrstr(),
|
sError("vgId:%d, failed to commit raft log since %s. commit index: %" PRId64 "", ths->vgId, terrstr(),
|
||||||
ths->commitIndex);
|
ths->commitIndex);
|
||||||
|
@ -2641,14 +2640,15 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnLocalCmdOld(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
int32_t syncNodeOnLocalCmdOld(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
|
ASSERT(false && "deprecated");
|
||||||
SyncLocalCmd* pMsg = pRpcMsg->pCont;
|
SyncLocalCmd* pMsg = pRpcMsg->pCont;
|
||||||
syncLogRecvLocalCmd(ths, pMsg, "");
|
syncLogRecvLocalCmd(ths, pMsg, "");
|
||||||
|
|
||||||
if (pMsg->cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
|
if (pMsg->cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
|
||||||
syncNodeStepDown(ths, pMsg->sdNewTerm);
|
syncNodeStepDown(ths, pMsg->currentTerm);
|
||||||
|
|
||||||
} else if (pMsg->cmd == SYNC_LOCAL_CMD_FOLLOWER_CMT) {
|
} else if (pMsg->cmd == SYNC_LOCAL_CMD_FOLLOWER_CMT) {
|
||||||
syncNodeFollowerCommit(ths, pMsg->fcIndex);
|
syncNodeFollowerCommit(ths, pMsg->commitIndex);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sError("error local cmd");
|
sError("error local cmd");
|
||||||
|
@ -2674,7 +2674,7 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIn
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
SyncIndex index = syncLogBufferGetEndIndex(ths->pLogBuf);
|
SyncIndex index = syncLogBufferGetEndIndex(ths->pLogBuf);
|
||||||
SyncTerm term = ths->pRaftStore->currentTerm;
|
SyncTerm term = ths->raftStore.currentTerm;
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
pEntry = syncEntryBuildFromClientRequest(pMsg->pCont, term, index);
|
pEntry = syncEntryBuildFromClientRequest(pMsg->pCont, term, index);
|
||||||
|
@ -2708,7 +2708,7 @@ int32_t syncNodeOnClientRequestOld(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRe
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
||||||
SyncTerm term = ths->pRaftStore->currentTerm;
|
SyncTerm term = ths->raftStore.currentTerm;
|
||||||
SSyncRaftEntry* pEntry;
|
SSyncRaftEntry* pEntry;
|
||||||
|
|
||||||
if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
|
@ -2742,7 +2742,7 @@ int32_t syncNodeOnClientRequestOld(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRe
|
||||||
.state = ths->state,
|
.state = ths->state,
|
||||||
.seqNum = pEntry->seqNum,
|
.seqNum = pEntry->seqNum,
|
||||||
.term = pEntry->term,
|
.term = pEntry->term,
|
||||||
.currentTerm = ths->pRaftStore->currentTerm,
|
.currentTerm = ths->raftStore.currentTerm,
|
||||||
.flag = 0,
|
.flag = 0,
|
||||||
};
|
};
|
||||||
ths->pFsm->FpCommitCb(ths->pFsm, pMsg, &cbMeta);
|
ths->pFsm->FpCommitCb(ths->pFsm, pMsg, &cbMeta);
|
||||||
|
@ -2820,7 +2820,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pEntry->term < ths->pRaftStore->currentTerm) {
|
if (pEntry->term < ths->raftStore.currentTerm) {
|
||||||
sNTrace(ths, "little term:%" PRId64 ", can not do leader transfer", pEntry->term);
|
sNTrace(ths, "little term:%" PRId64 ", can not do leader transfer", pEntry->term);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2858,7 +2858,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
||||||
if (ths->pFsm->FpLeaderTransferCb != NULL) {
|
if (ths->pFsm->FpLeaderTransferCb != NULL) {
|
||||||
SFsmCbMeta cbMeta = {
|
SFsmCbMeta cbMeta = {
|
||||||
.code = 0,
|
.code = 0,
|
||||||
.currentTerm = ths->pRaftStore->currentTerm,
|
.currentTerm = ths->raftStore.currentTerm,
|
||||||
.flag = 0,
|
.flag = 0,
|
||||||
.index = pEntry->index,
|
.index = pEntry->index,
|
||||||
.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index),
|
.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index),
|
||||||
|
@ -2974,7 +2974,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
||||||
.state = ths->state,
|
.state = ths->state,
|
||||||
.seqNum = pEntry->seqNum,
|
.seqNum = pEntry->seqNum,
|
||||||
.term = pEntry->term,
|
.term = pEntry->term,
|
||||||
.currentTerm = ths->pRaftStore->currentTerm,
|
.currentTerm = ths->raftStore.currentTerm,
|
||||||
.flag = flag,
|
.flag = flag,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncBuildAppendEntriesFromRaftLog(SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevLogTerm,
|
int32_t syncBuildAppendEntriesFromRaftEntry(SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevLogTerm,
|
||||||
SRpcMsg* pRpcMsg) {
|
SRpcMsg* pRpcMsg) {
|
||||||
uint32_t dataLen = pEntry->bytes;
|
uint32_t dataLen = pEntry->bytes;
|
||||||
uint32_t bytes = sizeof(SyncAppendEntries) + dataLen;
|
uint32_t bytes = sizeof(SyncAppendEntries) + dataLen;
|
||||||
|
@ -176,7 +176,7 @@ int32_t syncBuildAppendEntriesFromRaftLog(SSyncNode* pNode, SSyncRaftEntry* pEnt
|
||||||
pMsg->prevLogTerm = prevLogTerm;
|
pMsg->prevLogTerm = prevLogTerm;
|
||||||
pMsg->vgId = pNode->vgId;
|
pMsg->vgId = pNode->vgId;
|
||||||
pMsg->srcId = pNode->myRaftId;
|
pMsg->srcId = pNode->myRaftId;
|
||||||
pMsg->term = pNode->pRaftStore->currentTerm;
|
pMsg->term = pNode->raftStore.currentTerm;
|
||||||
pMsg->commitIndex = pNode->commitIndex;
|
pMsg->commitIndex = pNode->commitIndex;
|
||||||
pMsg->privateTerm = 0;
|
pMsg->privateTerm = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -31,6 +31,10 @@ static bool syncIsMsgBlock(tmsg_t type) {
|
||||||
(type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM);
|
(type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE static int64_t syncGetRetryMaxWaitMs() {
|
||||||
|
return SYNC_LOG_REPL_RETRY_WAIT_MS * (1 << SYNC_MAX_RETRY_BACKOFF);
|
||||||
|
}
|
||||||
|
|
||||||
int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf) {
|
int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf) {
|
||||||
taosThreadMutexLock(&pBuf->mutex);
|
taosThreadMutexLock(&pBuf->mutex);
|
||||||
int64_t index = pBuf->endIndex;
|
int64_t index = pBuf->endIndex;
|
||||||
|
@ -264,20 +268,27 @@ int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE SyncTerm syncLogBufferGetLastMatchTerm(SSyncLogBuffer* pBuf) {
|
FORCE_INLINE SyncTerm syncLogBufferGetLastMatchTermWithoutLock(SSyncLogBuffer* pBuf) {
|
||||||
SyncIndex index = pBuf->matchIndex;
|
SyncIndex index = pBuf->matchIndex;
|
||||||
SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem;
|
SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem;
|
||||||
ASSERT(pEntry != NULL);
|
ASSERT(pEntry != NULL);
|
||||||
return pEntry->term;
|
return pEntry->term;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SyncTerm syncLogBufferGetLastMatchTerm(SSyncLogBuffer* pBuf) {
|
||||||
|
taosThreadMutexLock(&pBuf->mutex);
|
||||||
|
SyncTerm term = syncLogBufferGetLastMatchTermWithoutLock(pBuf);
|
||||||
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
|
return term;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm) {
|
int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm) {
|
||||||
taosThreadMutexLock(&pBuf->mutex);
|
taosThreadMutexLock(&pBuf->mutex);
|
||||||
syncLogBufferValidate(pBuf);
|
syncLogBufferValidate(pBuf);
|
||||||
int32_t ret = -1;
|
int32_t ret = -1;
|
||||||
SyncIndex index = pEntry->index;
|
SyncIndex index = pEntry->index;
|
||||||
SyncIndex prevIndex = pEntry->index - 1;
|
SyncIndex prevIndex = pEntry->index - 1;
|
||||||
SyncTerm lastMatchTerm = syncLogBufferGetLastMatchTerm(pBuf);
|
SyncTerm lastMatchTerm = syncLogBufferGetLastMatchTermWithoutLock(pBuf);
|
||||||
SSyncRaftEntry* pExist = NULL;
|
SSyncRaftEntry* pExist = NULL;
|
||||||
bool inBuf = true;
|
bool inBuf = true;
|
||||||
|
|
||||||
|
@ -329,6 +340,8 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
|
||||||
}
|
}
|
||||||
|
|
||||||
// update
|
// update
|
||||||
|
ASSERT(pBuf->startIndex < index);
|
||||||
|
ASSERT(index - pBuf->startIndex < pBuf->size);
|
||||||
ASSERT(pBuf->entries[index % pBuf->size].pItem == NULL);
|
ASSERT(pBuf->entries[index % pBuf->size].pItem == NULL);
|
||||||
SSyncLogBufEntry tmp = {.pItem = pEntry, .prevLogIndex = prevIndex, .prevLogTerm = prevTerm};
|
SSyncLogBufEntry tmp = {.pItem = pEntry, .prevLogIndex = prevIndex, .prevLogTerm = prevTerm};
|
||||||
pEntry = NULL;
|
pEntry = NULL;
|
||||||
|
@ -456,6 +469,11 @@ int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, Syn
|
||||||
pNode->vgId, pEntry->index, pEntry->term, TMSG_INFO(pEntry->originalRpcType), applyCode);
|
pNode->vgId, pEntry->index, pEntry->term, TMSG_INFO(pEntry->originalRpcType), applyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pEntry->originalRpcType == TDMT_VND_COMMIT) {
|
||||||
|
sInfo("vgId:%d, fsm execute vnode commit. index: %" PRId64 ", term: %" PRId64 "", pNode->vgId, pEntry->index,
|
||||||
|
pEntry->term);
|
||||||
|
}
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {.code = applyCode};
|
SRpcMsg rpcMsg = {.code = applyCode};
|
||||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||||
|
|
||||||
|
@ -491,7 +509,7 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
|
||||||
SSyncLogStore* pLogStore = pNode->pLogStore;
|
SSyncLogStore* pLogStore = pNode->pLogStore;
|
||||||
SSyncFSM* pFsm = pNode->pFsm;
|
SSyncFSM* pFsm = pNode->pFsm;
|
||||||
ESyncState role = pNode->state;
|
ESyncState role = pNode->state;
|
||||||
SyncTerm term = pNode->pRaftStore->currentTerm;
|
SyncTerm term = pNode->raftStore.currentTerm;
|
||||||
SyncGroupId vgId = pNode->vgId;
|
SyncGroupId vgId = pNode->vgId;
|
||||||
int32_t ret = -1;
|
int32_t ret = -1;
|
||||||
int64_t upperIndex = TMIN(commitIndex, pBuf->matchIndex);
|
int64_t upperIndex = TMIN(commitIndex, pBuf->matchIndex);
|
||||||
|
@ -552,7 +570,8 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
|
||||||
ret = 0;
|
ret = 0;
|
||||||
_out:
|
_out:
|
||||||
// mark as restored if needed
|
// mark as restored if needed
|
||||||
if (!pNode->restoreFinish && pBuf->commitIndex >= pNode->commitIndex) {
|
if (!pNode->restoreFinish && pBuf->commitIndex >= pNode->commitIndex && pEntry != NULL &&
|
||||||
|
pNode->raftStore.currentTerm <= pEntry->term) {
|
||||||
pNode->pFsm->FpRestoreFinishCb(pNode->pFsm);
|
pNode->pFsm->FpRestoreFinishCb(pNode->pFsm);
|
||||||
pNode->restoreFinish = true;
|
pNode->restoreFinish = true;
|
||||||
sInfo("vgId:%d, restore finished. log buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pNode->vgId,
|
sInfo("vgId:%d, restore finished. log buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pNode->vgId,
|
||||||
|
@ -613,11 +632,17 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMgr->states[pos].acked) {
|
if (pMgr->states[pos].acked) {
|
||||||
|
if (pMgr->matchIndex < index && pMgr->states[pos].timeMs + (syncGetRetryMaxWaitMs() << 3) < nowMs) {
|
||||||
|
syncLogReplMgrReset(pMgr);
|
||||||
|
sWarn("vgId:%d, reset sync log repl mgr since stagnation. index: %" PRId64 ", peer: %" PRIx64, pNode->vgId,
|
||||||
|
index, pDestId->addr);
|
||||||
|
goto _out;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool barrier = false;
|
bool barrier = false;
|
||||||
if (syncLogBufferReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
if (syncLogReplMgrReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
||||||
sError("vgId:%d, failed to replicate sync log entry since %s. index: %" PRId64 ", dest: %" PRIx64 "", pNode->vgId,
|
sError("vgId:%d, failed to replicate sync log entry since %s. index: %" PRId64 ", dest: %" PRIx64 "", pNode->vgId,
|
||||||
terrstr(), index, pDestId->addr);
|
terrstr(), index, pDestId->addr);
|
||||||
goto _out;
|
goto _out;
|
||||||
|
@ -639,16 +664,17 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
_out:
|
_out:
|
||||||
if (retried) {
|
if (retried) {
|
||||||
pMgr->retryBackoff = syncLogGetNextRetryBackoff(pMgr);
|
pMgr->retryBackoff = syncLogGetNextRetryBackoff(pMgr);
|
||||||
sInfo("vgId:%d, resent %d sync log entries. dest: %" PRIx64 ", indexes: %" PRId64 " ..., terms: ... %" PRId64
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
", retryWaitMs: %" PRId64 ", repl mgr: [%" PRId64 " %" PRId64 ", %" PRId64 ")",
|
sInfo("vgId:%d, resend %d sync log entries. dest: %" PRIx64 ", indexes: %" PRId64 " ..., terms: ... %" PRId64
|
||||||
|
", retryWaitMs: %" PRId64 ", mgr: [%" PRId64 " %" PRId64 ", %" PRId64 "), buffer: [%" PRId64 " %" PRId64
|
||||||
|
" %" PRId64 ", %" PRId64 ")",
|
||||||
pNode->vgId, count, pDestId->addr, firstIndex, term, retryWaitMs, pMgr->startIndex, pMgr->matchIndex,
|
pNode->vgId, count, pDestId->addr, firstIndex, term, retryWaitMs, pMgr->startIndex, pMgr->matchIndex,
|
||||||
pMgr->endIndex);
|
pMgr->endIndex, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNode* pNode,
|
int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
||||||
SyncAppendEntriesReply* pMsg) {
|
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
SRaftId destId = pMsg->srcId;
|
SRaftId destId = pMsg->srcId;
|
||||||
ASSERT(pMgr->restored == false);
|
ASSERT(pMgr->restored == false);
|
||||||
|
@ -723,7 +749,7 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
|
||||||
|
|
||||||
// attempt to replicate the raft log at index
|
// attempt to replicate the raft log at index
|
||||||
(void)syncLogReplMgrReset(pMgr);
|
(void)syncLogReplMgrReset(pMgr);
|
||||||
return syncLogReplMgrReplicateProbeOnce(pMgr, pNode, index);
|
return syncLogReplMgrReplicateProbe(pMgr, pNode, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg) {
|
int32_t syncLogReplMgrProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg) {
|
||||||
|
@ -751,9 +777,9 @@ int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sync
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMgr->restored) {
|
if (pMgr->restored) {
|
||||||
(void)syncLogReplMgrProcessReplyInNormalMode(pMgr, pNode, pMsg);
|
(void)syncLogReplMgrProcessReplyAsNormal(pMgr, pNode, pMsg);
|
||||||
} else {
|
} else {
|
||||||
(void)syncLogReplMgrProcessReplyInRecoveryMode(pMgr, pNode, pMsg);
|
(void)syncLogReplMgrProcessReplyAsRecovery(pMgr, pNode, pMsg);
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -761,17 +787,17 @@ int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sync
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
int32_t syncLogReplMgrReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
if (pMgr->restored) {
|
if (pMgr->restored) {
|
||||||
(void)syncLogReplMgrReplicateAttemptedOnce(pMgr, pNode);
|
(void)syncLogReplMgrReplicateAttempt(pMgr, pNode);
|
||||||
} else {
|
} else {
|
||||||
(void)syncLogReplMgrReplicateProbeOnce(pMgr, pNode, pNode->pLogBuf->matchIndex);
|
(void)syncLogReplMgrReplicateProbe(pMgr, pNode, pNode->pLogBuf->matchIndex);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateProbeOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index) {
|
int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index) {
|
||||||
ASSERT(!pMgr->restored);
|
ASSERT(!pMgr->restored);
|
||||||
ASSERT(pMgr->startIndex >= 0);
|
ASSERT(pMgr->startIndex >= 0);
|
||||||
int64_t retryMaxWaitMs = SYNC_LOG_REPL_RETRY_WAIT_MS * (1 << SYNC_MAX_RETRY_BACKOFF);
|
int64_t retryMaxWaitMs = syncGetRetryMaxWaitMs();
|
||||||
int64_t nowMs = taosGetMonoTimestampMs();
|
int64_t nowMs = taosGetMonoTimestampMs();
|
||||||
|
|
||||||
if (pMgr->endIndex > pMgr->startIndex &&
|
if (pMgr->endIndex > pMgr->startIndex &&
|
||||||
|
@ -783,7 +809,7 @@ int32_t syncLogReplMgrReplicateProbeOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode
|
||||||
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
||||||
bool barrier = false;
|
bool barrier = false;
|
||||||
SyncTerm term = -1;
|
SyncTerm term = -1;
|
||||||
if (syncLogBufferReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
if (syncLogReplMgrReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
||||||
sError("vgId:%d, failed to replicate log entry since %s. index: %" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
sError("vgId:%d, failed to replicate log entry since %s. index: %" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
||||||
terrstr(), index, pDestId->addr);
|
terrstr(), index, pDestId->addr);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -799,15 +825,14 @@ int32_t syncLogReplMgrReplicateProbeOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode
|
||||||
pMgr->endIndex = index + 1;
|
pMgr->endIndex = index + 1;
|
||||||
|
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
sTrace("vgId:%d, attempted to probe the %d'th peer with msg of index:%" PRId64 " term: %" PRId64
|
sInfo("vgId:%d, probe peer:%" PRIx64 " with msg of index:%" PRId64 " term: %" PRId64 ". mgr (rs:%d): [%" PRId64
|
||||||
". pMgr(rs:%d): [%" PRId64 " %" PRId64 ", %" PRId64 "), pBuf: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64
|
" %" PRId64 ", %" PRId64 "), buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
||||||
")",
|
pNode->vgId, pDestId->addr, index, term, pMgr->restored, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex,
|
||||||
pNode->vgId, pMgr->peerId, index, term, pMgr->restored, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex,
|
|
||||||
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
ASSERT(pMgr->restored);
|
ASSERT(pMgr->restored);
|
||||||
|
|
||||||
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
||||||
|
@ -815,9 +840,11 @@ int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* p
|
||||||
int32_t count = 0;
|
int32_t count = 0;
|
||||||
int64_t nowMs = taosGetMonoTimestampMs();
|
int64_t nowMs = taosGetMonoTimestampMs();
|
||||||
int64_t limit = pMgr->size >> 1;
|
int64_t limit = pMgr->size >> 1;
|
||||||
|
SyncTerm term = -1;
|
||||||
|
SyncIndex firstIndex = -1;
|
||||||
|
|
||||||
for (SyncIndex index = pMgr->endIndex; index <= pNode->pLogBuf->matchIndex; index++) {
|
for (SyncIndex index = pMgr->endIndex; index <= pNode->pLogBuf->matchIndex; index++) {
|
||||||
if (batchSize < count++ || limit <= index - pMgr->startIndex) {
|
if (batchSize < count || limit <= index - pMgr->startIndex) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pMgr->startIndex + 1 < index && pMgr->states[(index - 1) % pMgr->size].barrier) {
|
if (pMgr->startIndex + 1 < index && pMgr->states[(index - 1) % pMgr->size].barrier) {
|
||||||
|
@ -827,7 +854,7 @@ int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* p
|
||||||
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
||||||
bool barrier = false;
|
bool barrier = false;
|
||||||
SyncTerm term = -1;
|
SyncTerm term = -1;
|
||||||
if (syncLogBufferReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
if (syncLogReplMgrReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
||||||
sError("vgId:%d, failed to replicate log entry since %s. index: %" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
sError("vgId:%d, failed to replicate log entry since %s. index: %" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
||||||
terrstr(), index, pDestId->addr);
|
terrstr(), index, pDestId->addr);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -837,6 +864,9 @@ int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* p
|
||||||
pMgr->states[pos].term = term;
|
pMgr->states[pos].term = term;
|
||||||
pMgr->states[pos].acked = false;
|
pMgr->states[pos].acked = false;
|
||||||
|
|
||||||
|
if (firstIndex == -1) firstIndex = index;
|
||||||
|
count++;
|
||||||
|
|
||||||
pMgr->endIndex = index + 1;
|
pMgr->endIndex = index + 1;
|
||||||
if (barrier) {
|
if (barrier) {
|
||||||
sInfo("vgId:%d, replicated sync barrier to dest: %" PRIx64 ". index: %" PRId64 ", term: %" PRId64
|
sInfo("vgId:%d, replicated sync barrier to dest: %" PRIx64 ". index: %" PRId64 ", term: %" PRId64
|
||||||
|
@ -850,14 +880,15 @@ int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* p
|
||||||
syncLogReplMgrRetryOnNeed(pMgr, pNode);
|
syncLogReplMgrRetryOnNeed(pMgr, pNode);
|
||||||
|
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
sTrace("vgId:%d, attempted to replicate %d msgs to the %d'th peer. pMgr(rs:%d): [%" PRId64 " %" PRId64 ", %" PRId64
|
sTrace("vgId:%d, replicated %d msgs to peer: %" PRIx64 ". indexes: %" PRId64 "..., terms: ...%" PRId64
|
||||||
"), pBuf: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
", mgr: (rs:%d) [%" PRId64 " %" PRId64 ", %" PRId64 "), buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64
|
||||||
pNode->vgId, count, pMgr->peerId, pMgr->restored, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex,
|
")",
|
||||||
pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
pNode->vgId, count, pDestId->addr, firstIndex, term, pMgr->restored, pMgr->startIndex, pMgr->matchIndex,
|
||||||
|
pMgr->endIndex, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessReplyInNormalMode(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
int32_t syncLogReplMgrProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
||||||
ASSERT(pMgr->restored == true);
|
ASSERT(pMgr->restored == true);
|
||||||
if (pMgr->startIndex <= pMsg->lastSendIndex && pMsg->lastSendIndex < pMgr->endIndex) {
|
if (pMgr->startIndex <= pMsg->lastSendIndex && pMsg->lastSendIndex < pMgr->endIndex) {
|
||||||
if (pMgr->startIndex < pMgr->matchIndex && pMgr->retryBackoff > 0) {
|
if (pMgr->startIndex < pMgr->matchIndex && pMgr->retryBackoff > 0) {
|
||||||
|
@ -876,7 +907,7 @@ int32_t syncLogReplMgrProcessReplyInNormalMode(SSyncLogReplMgr* pMgr, SSyncNode*
|
||||||
pMgr->startIndex = pMgr->matchIndex;
|
pMgr->startIndex = pMgr->matchIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return syncLogReplMgrReplicateAttemptedOnce(pMgr, pNode);
|
return syncLogReplMgrReplicateAttempt(pMgr, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncLogReplMgr* syncLogReplMgrCreate() {
|
SSyncLogReplMgr* syncLogReplMgrCreate() {
|
||||||
|
@ -985,6 +1016,10 @@ void syncLogBufferDestroy(SSyncLogBuffer* pBuf) {
|
||||||
int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex toIndex) {
|
int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex toIndex) {
|
||||||
ASSERT(pBuf->commitIndex < toIndex && toIndex <= pBuf->endIndex);
|
ASSERT(pBuf->commitIndex < toIndex && toIndex <= pBuf->endIndex);
|
||||||
|
|
||||||
|
if (toIndex == pBuf->endIndex) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
sInfo("vgId:%d, rollback sync log buffer. toindex: %" PRId64 ", buffer: [%" PRId64 " %" PRId64 " %" PRId64
|
sInfo("vgId:%d, rollback sync log buffer. toindex: %" PRId64 ", buffer: [%" PRId64 " %" PRId64 " %" PRId64
|
||||||
", %" PRId64 ")",
|
", %" PRId64 ")",
|
||||||
pNode->vgId, toIndex, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
pNode->vgId, toIndex, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
|
@ -1066,12 +1101,11 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogBufferReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
int32_t syncLogReplMgrReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
||||||
SRaftId* pDestId, bool* pBarrier) {
|
SRaftId* pDestId, bool* pBarrier) {
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
SRpcMsg msgOut = {0};
|
SRpcMsg msgOut = {0};
|
||||||
bool inBuf = false;
|
bool inBuf = false;
|
||||||
int32_t ret = -1;
|
|
||||||
SyncTerm prevLogTerm = -1;
|
SyncTerm prevLogTerm = -1;
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
|
|
||||||
|
@ -1097,14 +1131,13 @@ int32_t syncLogBufferReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Syn
|
||||||
}
|
}
|
||||||
if (pTerm) *pTerm = pEntry->term;
|
if (pTerm) *pTerm = pEntry->term;
|
||||||
|
|
||||||
int32_t code = syncBuildAppendEntriesFromRaftLog(pNode, pEntry, prevLogTerm, &msgOut);
|
int32_t code = syncBuildAppendEntriesFromRaftEntry(pNode, pEntry, prevLogTerm, &msgOut);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
sError("vgId:%d, failed to get append entries for index:%" PRId64 "", pNode->vgId, index);
|
sError("vgId:%d, failed to get append entries for index:%" PRId64 "", pNode->vgId, index);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)syncNodeSendAppendEntries(pNode, pDestId, &msgOut);
|
(void)syncNodeSendAppendEntries(pNode, pDestId, &msgOut);
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
sTrace("vgId:%d, replicate one msg index: %" PRId64 " term: %" PRId64 " prevterm: %" PRId64 " to dest: 0x%016" PRIx64,
|
sTrace("vgId:%d, replicate one msg index: %" PRId64 " term: %" PRId64 " prevterm: %" PRId64 " to dest: 0x%016" PRIx64,
|
||||||
pNode->vgId, pEntry->index, pEntry->term, prevLogTerm, pDestId->addr);
|
pNode->vgId, pEntry->index, pEntry->term, prevLogTerm, pDestId->addr);
|
||||||
|
|
|
@ -71,31 +71,23 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) {
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s.bak", realfile);
|
snprintf(file, sizeof(file), "%s.bak", realfile);
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
sError("vgId:%d, failed to open sync cfg file:%s since %s", pNode->vgId, realfile, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) goto _OVER;
|
||||||
if (tjsonAddObject(pJson, "RaftCfg", syncEncodeRaftCfg, pCfg) < 0) goto _OVER;
|
if (tjsonAddObject(pJson, "RaftCfg", syncEncodeRaftCfg, pCfg) < 0) goto _OVER;
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) goto _OVER;
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
|
if (pFile == NULL) goto _OVER;
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||||
taosCloseFile(&pFile);
|
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
taosCloseFile(&pFile);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||||
sError("vgId:%d, failed to rename sync cfg file:%s to %s since %s", pNode->vgId, file, realfile, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d", pNode->vgId, realfile, len);
|
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d", pNode->vgId, realfile, len);
|
||||||
|
@ -106,6 +98,7 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
sError("vgId:%d, failed to write sync cfg file:%s since %s", pNode->vgId, realfile, terrstr());
|
sError("vgId:%d, failed to write sync cfg file:%s since %s", pNode->vgId, realfile, terrstr());
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -219,6 +219,10 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
||||||
|
|
||||||
ASSERT(pEntry->index == index);
|
ASSERT(pEntry->index == index);
|
||||||
|
|
||||||
|
if (pEntry->originalRpcType == TDMT_VND_COMMIT) {
|
||||||
|
walFsync(pWal, true);
|
||||||
|
}
|
||||||
|
|
||||||
sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s, elapsed:%" PRId64, pEntry->index,
|
sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s, elapsed:%" PRId64, pEntry->index,
|
||||||
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType), tsElapsed);
|
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType), tsElapsed);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -312,29 +316,6 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
|
|
||||||
// need not truncate
|
|
||||||
SyncIndex wallastVer = walGetLastVer(pWal);
|
|
||||||
if (fromIndex > wallastVer) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// need not truncate
|
|
||||||
SyncIndex walCommitVer = walGetCommittedVer(pWal);
|
|
||||||
if (fromIndex <= walCommitVer) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete from cache
|
|
||||||
for (SyncIndex index = fromIndex; index <= wallastVer; ++index) {
|
|
||||||
SLRUCache* pCache = pData->pSyncNode->pLogStore->pCache;
|
|
||||||
LRUHandle* h = taosLRUCacheLookup(pCache, &index, sizeof(index));
|
|
||||||
if (h) {
|
|
||||||
sNTrace(pData->pSyncNode, "cache delete index:%" PRId64, index);
|
|
||||||
|
|
||||||
taosLRUCacheRelease(pData->pSyncNode->pLogStore->pCache, h, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t code = walRollback(pWal, fromIndex);
|
int32_t code = walRollback(pWal, fromIndex);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
int32_t err = terrno;
|
int32_t err = terrno;
|
||||||
|
|
|
@ -16,156 +16,161 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
// private function
|
static int32_t raftStoreDecode(const SJson *pJson, SRaftStore *pStore) {
|
||||||
static int32_t raftStoreInit(SRaftStore *pRaftStore);
|
int32_t code = 0;
|
||||||
static bool raftStoreFileExist(char *path);
|
|
||||||
|
|
||||||
// public function
|
tjsonGetNumberValue(pJson, "current_term", pStore->currentTerm, code);
|
||||||
SRaftStore *raftStoreOpen(const char *path) {
|
if (code < 0) return -1;
|
||||||
int32_t ret;
|
tjsonGetNumberValue(pJson, "vote_for_addr", pStore->voteFor.addr, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
tjsonGetInt32ValueFromDouble(pJson, "vote_for_vgid", pStore->voteFor.vgId, code);
|
||||||
|
if (code < 0) return -1;
|
||||||
|
|
||||||
SRaftStore *pRaftStore = taosMemoryCalloc(1, sizeof(SRaftStore));
|
return 0;
|
||||||
if (pRaftStore == NULL) {
|
}
|
||||||
|
|
||||||
|
int32_t raftStoreReadFile(SSyncNode *pNode) {
|
||||||
|
int32_t code = -1;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
char *pData = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
|
const char *file = pNode->raftStorePath;
|
||||||
|
SRaftStore *pStore = &pNode->raftStore;
|
||||||
|
|
||||||
|
if (taosStatFile(file, NULL, NULL) < 0) {
|
||||||
|
sInfo("vgId:%d, raft store file:%s not exist, use default value", pNode->vgId, file);
|
||||||
|
pStore->currentTerm = 0;
|
||||||
|
pStore->voteFor.addr = 0;
|
||||||
|
pStore->voteFor.vgId = 0;
|
||||||
|
return raftStoreWriteFile(pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("vgId:%d, failed to open raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t size = 0;
|
||||||
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("vgId:%d, failed to fstat raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
pData = taosMemoryMalloc(size + 1);
|
||||||
|
if (pData == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(pRaftStore->path, sizeof(pRaftStore->path), "%s", path);
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
if (!raftStoreFileExist(pRaftStore->path)) {
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
ret = raftStoreInit(pRaftStore);
|
sError("vgId:%d, failed to read raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
ASSERT(ret == 0);
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
char storeBuf[RAFT_STORE_BLOCK_SIZE] = {0};
|
pData[size] = '\0';
|
||||||
pRaftStore->pFile = taosOpenFile(path, TD_FILE_READ | TD_FILE_WRITE);
|
|
||||||
ASSERT(pRaftStore->pFile != NULL);
|
|
||||||
|
|
||||||
int len = taosReadFile(pRaftStore->pFile, storeBuf, RAFT_STORE_BLOCK_SIZE);
|
pJson = tjsonParse(pData);
|
||||||
ASSERT(len > 0);
|
if (pJson == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
ret = raftStoreDeserialize(pRaftStore, storeBuf, len);
|
if (raftStoreDecode(pJson, pStore) < 0) {
|
||||||
ASSERT(ret == 0);
|
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
return pRaftStore;
|
code = 0;
|
||||||
|
sInfo("vgId:%d, succceed to read raft store file %s", pNode->vgId, file);
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (pData != NULL) taosMemoryFree(pData);
|
||||||
|
if (pJson != NULL) cJSON_Delete(pJson);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
sError("vgId:%d, failed to read raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t raftStoreInit(SRaftStore *pRaftStore) {
|
static int32_t raftStoreEncode(SJson *pJson, SRaftStore *pStore) {
|
||||||
ASSERT(pRaftStore != NULL);
|
if (tjsonAddIntegerToObject(pJson, "current_term", pStore->currentTerm) < 0) return -1;
|
||||||
|
if (tjsonAddIntegerToObject(pJson, "vote_for_addr", pStore->voteFor.addr) < 0) return -1;
|
||||||
pRaftStore->pFile = taosOpenFile(pRaftStore->path, TD_FILE_CREATE | TD_FILE_WRITE);
|
if (tjsonAddDoubleToObject(pJson, "vote_for_vgid", pStore->voteFor.vgId) < 0) return -1;
|
||||||
ASSERT(pRaftStore->pFile != NULL);
|
|
||||||
|
|
||||||
pRaftStore->currentTerm = 0;
|
|
||||||
pRaftStore->voteFor.addr = 0;
|
|
||||||
pRaftStore->voteFor.vgId = 0;
|
|
||||||
|
|
||||||
int32_t ret = raftStorePersist(pRaftStore);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
|
|
||||||
taosCloseFile(&pRaftStore->pFile);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftStoreClose(SRaftStore *pRaftStore) {
|
int32_t raftStoreWriteFile(SSyncNode *pNode) {
|
||||||
if (pRaftStore == NULL) return 0;
|
int32_t code = -1;
|
||||||
|
char *buffer = NULL;
|
||||||
|
SJson *pJson = NULL;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
const char *realfile = pNode->raftStorePath;
|
||||||
|
SRaftStore *pStore = &pNode->raftStore;
|
||||||
|
char file[PATH_MAX] = {0};
|
||||||
|
snprintf(file, sizeof(file), "%s.bak", realfile);
|
||||||
|
|
||||||
taosCloseFile(&pRaftStore->pFile);
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
taosMemoryFree(pRaftStore);
|
pJson = tjsonCreateObject();
|
||||||
pRaftStore = NULL;
|
if (pJson == NULL) goto _OVER;
|
||||||
return 0;
|
if (raftStoreEncode(pJson, pStore) != 0) goto _OVER;
|
||||||
|
buffer = tjsonToString(pJson);
|
||||||
|
if (buffer == NULL) goto _OVER;
|
||||||
|
terrno = 0;
|
||||||
|
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
|
if (pFile == NULL) goto _OVER;
|
||||||
|
|
||||||
|
int32_t len = strlen(buffer);
|
||||||
|
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||||
|
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||||
|
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
sInfo("vgId:%d, succeed to write raft store file:%s, len:%d", pNode->vgId, realfile, len);
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (pJson != NULL) tjsonDelete(pJson);
|
||||||
|
if (buffer != NULL) taosMemoryFree(buffer);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("vgId:%d, failed to write raft store file:%s since %s", pNode->vgId, realfile, terrstr());
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftStorePersist(SRaftStore *pRaftStore) {
|
bool raftStoreHasVoted(SSyncNode *pNode) {
|
||||||
ASSERT(pRaftStore != NULL);
|
bool b = syncUtilEmptyId(&pNode->raftStore.voteFor);
|
||||||
|
|
||||||
int32_t ret;
|
|
||||||
char storeBuf[RAFT_STORE_BLOCK_SIZE] = {0};
|
|
||||||
ret = raftStoreSerialize(pRaftStore, storeBuf, sizeof(storeBuf));
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
|
|
||||||
taosLSeekFile(pRaftStore->pFile, 0, SEEK_SET);
|
|
||||||
|
|
||||||
ret = taosWriteFile(pRaftStore->pFile, storeBuf, sizeof(storeBuf));
|
|
||||||
ASSERT(ret == RAFT_STORE_BLOCK_SIZE);
|
|
||||||
|
|
||||||
taosFsyncFile(pRaftStore->pFile);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool raftStoreFileExist(char *path) {
|
|
||||||
bool b = taosStatFile(path, NULL, NULL) >= 0;
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
|
||||||
ASSERT(pRaftStore != NULL);
|
|
||||||
|
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
char u64Buf[128] = {0};
|
|
||||||
snprintf(u64Buf, sizeof(u64Buf), "%" PRIu64 "", pRaftStore->currentTerm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "current_term", u64Buf);
|
|
||||||
|
|
||||||
snprintf(u64Buf, sizeof(u64Buf), "%" PRIu64 "", pRaftStore->voteFor.addr);
|
|
||||||
cJSON_AddStringToObject(pRoot, "vote_for_addr", u64Buf);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId);
|
|
||||||
|
|
||||||
char *serialized = cJSON_Print(pRoot);
|
|
||||||
int len2 = strlen(serialized);
|
|
||||||
ASSERT(len2 < len);
|
|
||||||
memset(buf, 0, len);
|
|
||||||
snprintf(buf, len, "%s", serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
|
|
||||||
cJSON_Delete(pRoot);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
|
||||||
ASSERT(pRaftStore != NULL);
|
|
||||||
|
|
||||||
ASSERT(len > 0 && len <= RAFT_STORE_BLOCK_SIZE);
|
|
||||||
cJSON *pRoot = cJSON_Parse(buf);
|
|
||||||
|
|
||||||
cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term");
|
|
||||||
ASSERT(cJSON_IsString(pCurrentTerm));
|
|
||||||
sscanf(pCurrentTerm->valuestring, "%" PRIu64 "", &(pRaftStore->currentTerm));
|
|
||||||
|
|
||||||
cJSON *pVoteForAddr = cJSON_GetObjectItem(pRoot, "vote_for_addr");
|
|
||||||
ASSERT(cJSON_IsString(pVoteForAddr));
|
|
||||||
sscanf(pVoteForAddr->valuestring, "%" PRIu64 "", &(pRaftStore->voteFor.addr));
|
|
||||||
|
|
||||||
cJSON *pVoteForVgid = cJSON_GetObjectItem(pRoot, "vote_for_vgid");
|
|
||||||
pRaftStore->voteFor.vgId = pVoteForVgid->valueint;
|
|
||||||
|
|
||||||
cJSON_Delete(pRoot);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool raftStoreHasVoted(SRaftStore *pRaftStore) {
|
|
||||||
bool b = syncUtilEmptyId(&(pRaftStore->voteFor));
|
|
||||||
return (!b);
|
return (!b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId) {
|
void raftStoreVote(SSyncNode *pNode, SRaftId *pRaftId) {
|
||||||
ASSERT(!syncUtilEmptyId(pRaftId));
|
pNode->raftStore.voteFor = *pRaftId;
|
||||||
pRaftStore->voteFor = *pRaftId;
|
(void)raftStoreWriteFile(pNode);
|
||||||
raftStorePersist(pRaftStore);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStoreClearVote(SRaftStore *pRaftStore) {
|
void raftStoreClearVote(SSyncNode *pNode) {
|
||||||
pRaftStore->voteFor = EMPTY_RAFT_ID;
|
pNode->raftStore.voteFor = EMPTY_RAFT_ID;
|
||||||
raftStorePersist(pRaftStore);
|
(void)raftStoreWriteFile(pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStoreNextTerm(SRaftStore *pRaftStore) {
|
void raftStoreNextTerm(SSyncNode *pNode) {
|
||||||
++(pRaftStore->currentTerm);
|
pNode->raftStore.currentTerm++;
|
||||||
raftStorePersist(pRaftStore);
|
(void)raftStoreWriteFile(pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term) {
|
void raftStoreSetTerm(SSyncNode *pNode, SyncTerm term) {
|
||||||
pRaftStore->currentTerm = term;
|
pNode->raftStore.currentTerm = term;
|
||||||
raftStorePersist(pRaftStore);
|
(void)raftStoreWriteFile(pNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapsh
|
||||||
ASSERT(pMsg != NULL);
|
ASSERT(pMsg != NULL);
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
pMsg->srcId = pSyncNode->myRaftId;
|
||||||
pMsg->destId = *pDestId;
|
pMsg->destId = *pDestId;
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pMsg->prevLogIndex = preLogIndex;
|
pMsg->prevLogIndex = preLogIndex;
|
||||||
pMsg->prevLogTerm = preLogTerm;
|
pMsg->prevLogTerm = preLogTerm;
|
||||||
pMsg->commitIndex = pSyncNode->commitIndex;
|
pMsg->commitIndex = pSyncNode->commitIndex;
|
||||||
|
@ -245,7 +245,7 @@ int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
|
||||||
SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
|
SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
|
||||||
pSyncMsg->srcId = pSyncNode->myRaftId;
|
pSyncMsg->srcId = pSyncNode->myRaftId;
|
||||||
pSyncMsg->destId = pSyncNode->peersId[i];
|
pSyncMsg->destId = pSyncNode->peersId[i];
|
||||||
pSyncMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pSyncMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pSyncMsg->commitIndex = pSyncNode->commitIndex;
|
pSyncMsg->commitIndex = pSyncNode->commitIndex;
|
||||||
pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
||||||
pSyncMsg->privateTerm = 0;
|
pSyncMsg->privateTerm = 0;
|
||||||
|
|
|
@ -44,21 +44,12 @@
|
||||||
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
|
||||||
//
|
//
|
||||||
|
|
||||||
static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pMsg) {
|
static bool syncNodeOnRequestVoteLogOK(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode);
|
SyncTerm myLastTerm = syncNodeGetLastTerm(ths);
|
||||||
SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode);
|
SyncIndex myLastIndex = syncNodeGetLastIndex(ths);
|
||||||
|
|
||||||
if (pMsg->lastLogIndex < pSyncNode->commitIndex) {
|
|
||||||
sNTrace(pSyncNode,
|
|
||||||
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
|
||||||
", recv-term:%" PRIu64 "}",
|
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myLastTerm == SYNC_TERM_INVALID) {
|
if (myLastTerm == SYNC_TERM_INVALID) {
|
||||||
sNTrace(pSyncNode,
|
sNTrace(ths,
|
||||||
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
|
@ -66,22 +57,29 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->lastLogTerm > myLastTerm) {
|
if (pMsg->lastLogTerm > myLastTerm) {
|
||||||
sNTrace(pSyncNode,
|
sNTrace(ths,
|
||||||
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
|
|
||||||
|
if (pMsg->lastLogIndex < ths->commitIndex) {
|
||||||
|
sNWarn(ths,
|
||||||
|
"logok:1, commit rollback required. {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64
|
||||||
|
", recv-lindex:%" PRId64 ", recv-term:%" PRIu64 "}",
|
||||||
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->lastLogTerm == myLastTerm && pMsg->lastLogIndex >= myLastIndex) {
|
if (pMsg->lastLogTerm == myLastTerm && pMsg->lastLogIndex >= myLastIndex) {
|
||||||
sNTrace(pSyncNode,
|
sNTrace(ths,
|
||||||
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(ths,
|
||||||
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
"logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64
|
||||||
", recv-term:%" PRIu64 "}",
|
", recv-term:%" PRIu64 "}",
|
||||||
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term);
|
||||||
|
@ -93,7 +91,7 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
SyncRequestVote* pMsg = pRpcMsg->pCont;
|
SyncRequestVote* pMsg = pRpcMsg->pCont;
|
||||||
|
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
if (!syncNodeInRaftGroup(ths, &pMsg->srcId)) {
|
||||||
syncLogRecvRequestVote(ths, pMsg, -1, "not in my config");
|
syncLogRecvRequestVote(ths, pMsg, -1, "not in my config");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -101,21 +99,21 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
bool logOK = syncNodeOnRequestVoteLogOK(ths, pMsg);
|
bool logOK = syncNodeOnRequestVoteLogOK(ths, pMsg);
|
||||||
|
|
||||||
// maybe update term
|
// maybe update term
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->raftStore.currentTerm) {
|
||||||
syncNodeStepDown(ths, pMsg->term);
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
// syncNodeUpdateTerm(ths, pMsg->term);
|
// syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
}
|
}
|
||||||
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
ASSERT(pMsg->term <= ths->raftStore.currentTerm);
|
||||||
|
|
||||||
bool grant = (pMsg->term == ths->pRaftStore->currentTerm) && logOK &&
|
bool grant = (pMsg->term == ths->raftStore.currentTerm) && logOK &&
|
||||||
((!raftStoreHasVoted(ths->pRaftStore)) || (syncUtilSameId(&(ths->pRaftStore->voteFor), &(pMsg->srcId))));
|
((!raftStoreHasVoted(ths)) || (syncUtilSameId(&ths->raftStore.voteFor, &pMsg->srcId)));
|
||||||
if (grant) {
|
if (grant) {
|
||||||
// maybe has already voted for pMsg->srcId
|
// maybe has already voted for pMsg->srcId
|
||||||
// vote again, no harm
|
// vote again, no harm
|
||||||
raftStoreVote(ths->pRaftStore, &(pMsg->srcId));
|
raftStoreVote(ths, &(pMsg->srcId));
|
||||||
|
|
||||||
// candidate ?
|
// candidate ?
|
||||||
syncNodeStepDown(ths, ths->pRaftStore->currentTerm);
|
syncNodeStepDown(ths, ths->raftStore.currentTerm);
|
||||||
|
|
||||||
// forbid elect for this round
|
// forbid elect for this round
|
||||||
syncNodeResetElectTimer(ths);
|
syncNodeResetElectTimer(ths);
|
||||||
|
@ -129,7 +127,7 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
SyncRequestVoteReply* pReply = rpcMsg.pCont;
|
SyncRequestVoteReply* pReply = rpcMsg.pCont;
|
||||||
pReply->srcId = ths->myRaftId;
|
pReply->srcId = ths->myRaftId;
|
||||||
pReply->destId = pMsg->srcId;
|
pReply->destId = pMsg->srcId;
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
pReply->term = ths->raftStore.currentTerm;
|
||||||
pReply->voteGranted = grant;
|
pReply->voteGranted = grant;
|
||||||
|
|
||||||
// trace log
|
// trace log
|
||||||
|
|
|
@ -49,25 +49,25 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop stale response
|
// drop stale response
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->raftStore.currentTerm) {
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response");
|
syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ASSERT(!(pMsg->term > ths->pRaftStore->currentTerm));
|
// ASSERT(!(pMsg->term > ths->raftStore.currentTerm));
|
||||||
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
||||||
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
// if (pMsg->term > ths->raftStore.currentTerm) {
|
||||||
// syncNodeUpdateTerm(ths, pMsg->term);
|
// syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->raftStore.currentTerm) {
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "error term");
|
syncLogRecvRequestVoteReply(ths, pMsg, "error term");
|
||||||
syncNodeStepDown(ths, pMsg->term);
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "");
|
syncLogRecvRequestVoteReply(ths, pMsg, "");
|
||||||
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
ASSERT(pMsg->term == ths->raftStore.currentTerm);
|
||||||
|
|
||||||
// This tallies votes even when the current state is not Candidate,
|
// This tallies votes even when the current state is not Candidate,
|
||||||
// but they won't be looked at, so it doesn't matter.
|
// but they won't be looked at, so it doesn't matter.
|
||||||
|
|
|
@ -143,7 +143,7 @@ static void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
|
||||||
.state = pNode->state,
|
.state = pNode->state,
|
||||||
.seqNum = *pSeqNum,
|
.seqNum = *pSeqNum,
|
||||||
.term = SYNC_TERM_INVALID,
|
.term = SYNC_TERM_INVALID,
|
||||||
.currentTerm = pNode->pRaftStore->currentTerm,
|
.currentTerm = pNode->raftStore.currentTerm,
|
||||||
.flag = 0,
|
.flag = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
|
||||||
pSender->sendingMS = SYNC_SNAPSHOT_RETRY_MS;
|
pSender->sendingMS = SYNC_SNAPSHOT_RETRY_MS;
|
||||||
pSender->pSyncNode = pSyncNode;
|
pSender->pSyncNode = pSyncNode;
|
||||||
pSender->replicaIndex = replicaIndex;
|
pSender->replicaIndex = replicaIndex;
|
||||||
pSender->term = pSyncNode->pRaftStore->currentTerm;
|
pSender->term = pSyncNode->raftStore.currentTerm;
|
||||||
pSender->startTime = 0;
|
pSender->startTime = 0;
|
||||||
pSender->endTime = 0;
|
pSender->endTime = 0;
|
||||||
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &pSender->snapshot);
|
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &pSender->snapshot);
|
||||||
|
@ -90,7 +90,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
|
|
||||||
memset(&pSender->lastConfig, 0, sizeof(pSender->lastConfig));
|
memset(&pSender->lastConfig, 0, sizeof(pSender->lastConfig));
|
||||||
pSender->sendingMS = 0;
|
pSender->sendingMS = 0;
|
||||||
pSender->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pSender->term = pSender->pSyncNode->raftStore.currentTerm;
|
||||||
pSender->startTime = taosGetTimestampMs();
|
pSender->startTime = taosGetTimestampMs();
|
||||||
pSender->lastSendTime = pSender->startTime;
|
pSender->lastSendTime = pSender->startTime;
|
||||||
pSender->finish = false;
|
pSender->finish = false;
|
||||||
|
@ -105,7 +105,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSender->pSyncNode->raftStore.currentTerm;
|
||||||
pMsg->beginIndex = pSender->snapshotParam.start;
|
pMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
||||||
|
@ -185,7 +185,7 @@ static int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSender->pSyncNode->raftStore.currentTerm;
|
||||||
pMsg->beginIndex = pSender->snapshotParam.start;
|
pMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
||||||
|
@ -226,7 +226,7 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
||||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSender->pSyncNode->raftStore.currentTerm;
|
||||||
pMsg->beginIndex = pSender->snapshotParam.start;
|
pMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
||||||
|
@ -314,7 +314,7 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId from
|
||||||
pReceiver->pWriter = NULL;
|
pReceiver->pWriter = NULL;
|
||||||
pReceiver->pSyncNode = pSyncNode;
|
pReceiver->pSyncNode = pSyncNode;
|
||||||
pReceiver->fromId = fromId;
|
pReceiver->fromId = fromId;
|
||||||
pReceiver->term = pSyncNode->pRaftStore->currentTerm;
|
pReceiver->term = pSyncNode->raftStore.currentTerm;
|
||||||
pReceiver->snapshot.data = NULL;
|
pReceiver->snapshot.data = NULL;
|
||||||
pReceiver->snapshot.lastApplyIndex = SYNC_INDEX_INVALID;
|
pReceiver->snapshot.lastApplyIndex = SYNC_INDEX_INVALID;
|
||||||
pReceiver->snapshot.lastApplyTerm = 0;
|
pReceiver->snapshot.lastApplyTerm = 0;
|
||||||
|
@ -380,7 +380,7 @@ void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *p
|
||||||
|
|
||||||
pReceiver->start = true;
|
pReceiver->start = true;
|
||||||
pReceiver->ack = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT;
|
pReceiver->ack = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT;
|
||||||
pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm;
|
pReceiver->term = pReceiver->pSyncNode->raftStore.currentTerm;
|
||||||
pReceiver->fromId = pPreMsg->srcId;
|
pReceiver->fromId = pPreMsg->srcId;
|
||||||
pReceiver->startTime = pPreMsg->startTime;
|
pReceiver->startTime = pPreMsg->startTime;
|
||||||
|
|
||||||
|
@ -437,9 +437,9 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe update term
|
// maybe update term
|
||||||
if (pReceiver->snapshot.lastApplyTerm > pReceiver->pSyncNode->pRaftStore->currentTerm) {
|
if (pReceiver->snapshot.lastApplyTerm > pReceiver->pSyncNode->raftStore.currentTerm) {
|
||||||
pReceiver->pSyncNode->pRaftStore->currentTerm = pReceiver->snapshot.lastApplyTerm;
|
pReceiver->pSyncNode->raftStore.currentTerm = pReceiver->snapshot.lastApplyTerm;
|
||||||
raftStorePersist(pReceiver->pSyncNode->pRaftStore);
|
(void)raftStoreWriteFile(pReceiver->pSyncNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop writer, apply data
|
// stop writer, apply data
|
||||||
|
@ -592,7 +592,7 @@ _SEND_REPLY:
|
||||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||||
pRspMsg->destId = pMsg->srcId;
|
pRspMsg->destId = pMsg->srcId;
|
||||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pRspMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pRspMsg->lastIndex = pMsg->lastIndex;
|
pRspMsg->lastIndex = pMsg->lastIndex;
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
|
@ -648,7 +648,7 @@ _SEND_REPLY:
|
||||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||||
pRspMsg->destId = pMsg->srcId;
|
pRspMsg->destId = pMsg->srcId;
|
||||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pRspMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pRspMsg->lastIndex = pMsg->lastIndex;
|
pRspMsg->lastIndex = pMsg->lastIndex;
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
|
@ -698,7 +698,7 @@ static int32_t syncNodeOnSnapshotReceive(SSyncNode *pSyncNode, SyncSnapshotSend
|
||||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||||
pRspMsg->destId = pMsg->srcId;
|
pRspMsg->destId = pMsg->srcId;
|
||||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pRspMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pRspMsg->lastIndex = pMsg->lastIndex;
|
pRspMsg->lastIndex = pMsg->lastIndex;
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
|
@ -745,7 +745,7 @@ static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
||||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||||
pRspMsg->destId = pMsg->srcId;
|
pRspMsg->destId = pMsg->srcId;
|
||||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pRspMsg->term = pSyncNode->raftStore.currentTerm;
|
||||||
pRspMsg->lastIndex = pMsg->lastIndex;
|
pRspMsg->lastIndex = pMsg->lastIndex;
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
|
@ -794,13 +794,13 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term < pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term < pSyncNode->raftStore.currentTerm) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "reject since small term");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "reject since small term");
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term > pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term > pSyncNode->raftStore.currentTerm) {
|
||||||
syncNodeStepDown(pSyncNode, pMsg->term);
|
syncNodeStepDown(pSyncNode, pMsg->term);
|
||||||
}
|
}
|
||||||
syncNodeResetElectTimer(pSyncNode);
|
syncNodeResetElectTimer(pSyncNode);
|
||||||
|
@ -808,7 +808,7 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||||
// state, term, seq/ack
|
// state, term, seq/ack
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term == pSyncNode->raftStore.currentTerm) {
|
||||||
if (pMsg->seq == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
if (pMsg->seq == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq pre-snapshot");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq pre-snapshot");
|
||||||
code = syncNodeOnSnapshotPre(pSyncNode, pMsg);
|
code = syncNodeOnSnapshotPre(pSyncNode, pMsg);
|
||||||
|
@ -892,7 +892,7 @@ static int32_t syncNodeOnSnapshotPreRsp(SSyncNode *pSyncNode, SSyncSnapshotSende
|
||||||
SyncSnapshotSend *pSendMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pSendMsg = rpcMsg.pCont;
|
||||||
pSendMsg->srcId = pSender->pSyncNode->myRaftId;
|
pSendMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pSendMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
pSendMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pSendMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pSendMsg->term = pSender->pSyncNode->raftStore.currentTerm;
|
||||||
pSendMsg->beginIndex = pSender->snapshotParam.start;
|
pSendMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pSendMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pSendMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
pSendMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
pSendMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
||||||
|
@ -951,10 +951,10 @@ int32_t syncNodeOnSnapshotRsp(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term != pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term != pSyncNode->raftStore.currentTerm) {
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "snapshot sender and receiver term not match");
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "snapshot sender and receiver term not match");
|
||||||
sSError(pSender, "snapshot sender term not equal, msg term:%" PRId64 " currentTerm:%" PRId64, pMsg->term,
|
sSError(pSender, "snapshot sender term not equal, msg term:%" PRId64 " currentTerm:%" PRId64, pMsg->term,
|
||||||
pSyncNode->pRaftStore->currentTerm);
|
pSyncNode->raftStore.currentTerm);
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,20 +17,20 @@
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "syncIndexMgr.h"
|
#include "syncIndexMgr.h"
|
||||||
#include "syncMessage.h"
|
#include "syncMessage.h"
|
||||||
|
#include "syncPipeline.h"
|
||||||
#include "syncRaftCfg.h"
|
#include "syncRaftCfg.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
#include "syncSnapshot.h"
|
#include "syncSnapshot.h"
|
||||||
|
|
||||||
void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
|
void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
|
||||||
int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex);
|
int32_t len = snprintf(buf, bufLen, "{num:%d, as:%d, [", pCfg->replicaNum, pCfg->myIndex);
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s:%d", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
||||||
if (i < pCfg->replicaNum - 1) {
|
if (i < pCfg->replicaNum - 1) {
|
||||||
len += snprintf(buf + len, bufLen - len, "%s:%d, ", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
len += snprintf(buf + len, bufLen - len, "%s", ", ");
|
||||||
} else {
|
|
||||||
len += snprintf(buf + len, bufLen - len, "%s:%d}", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", "]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
|
void syncUtilNodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) {
|
||||||
|
@ -89,32 +89,55 @@ bool syncUtilUserRollback(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP &&
|
||||||
|
|
||||||
// for leader
|
// for leader
|
||||||
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
int32_t len = 5;
|
int32_t len = 0;
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", "{");
|
||||||
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||||
int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
|
int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->replicasId[i]));
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%d:%" PRId64, i, tsMs);
|
||||||
if (i < pSyncNode->replicaNum - 1) {
|
if (i < pSyncNode->replicaNum - 1) {
|
||||||
len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 ",", i, tsMs);
|
len += snprintf(buf + len, bufLen - len, "%s", ",");
|
||||||
} else {
|
|
||||||
len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 "}", i, tsMs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// for follower
|
// for follower
|
||||||
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
static void syncHearbeatTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
int32_t len = 4;
|
int32_t len = 0;
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", "{");
|
||||||
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||||
int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
|
int64_t tsMs = syncIndexMgrGetRecvTime(pSyncNode->pNextIndex, &(pSyncNode->replicasId[i]));
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%d:%" PRId64, i, tsMs);
|
||||||
if (i < pSyncNode->replicaNum - 1) {
|
if (i < pSyncNode->replicaNum - 1) {
|
||||||
len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 ",", i, tsMs);
|
len += snprintf(buf + len, bufLen - len, "%s", ",");
|
||||||
} else {
|
|
||||||
len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 "}", i, tsMs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", "}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void syncLogBufferStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
|
SSyncLogBuffer* pBuf = pSyncNode->pLogBuf;
|
||||||
|
if (pBuf == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int len = 0;
|
||||||
|
len += snprintf(buf + len, bufLen - len, "[%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pBuf->startIndex,
|
||||||
|
pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void syncLogReplMgrStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
|
int len = 0;
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", "{");
|
||||||
|
for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
|
||||||
|
SSyncLogReplMgr* pMgr = pSyncNode->logReplMgrs[i];
|
||||||
|
if (pMgr == NULL) break;
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%d:%d [%" PRId64 " %" PRId64 ", %" PRId64 ")", i, pMgr->restored,
|
||||||
|
pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex);
|
||||||
|
if (i + 1 < pSyncNode->replicaNum) {
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", ", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len += snprintf(buf + len, bufLen - len, "%s", "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
|
@ -135,8 +158,8 @@ static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
|
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
|
||||||
if (pNode == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
if (pNode == NULL || pNode->pLogStore == NULL) return;
|
||||||
int64_t currentTerm = pNode->pRaftStore->currentTerm;
|
int64_t currentTerm = pNode->raftStore.currentTerm;
|
||||||
|
|
||||||
// save error code, otherwise it will be overwritten
|
// save error code, otherwise it will be overwritten
|
||||||
int32_t errCode = terrno;
|
int32_t errCode = terrno;
|
||||||
|
@ -156,16 +179,19 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
int32_t cacheHit = pNode->pLogStore->cacheHit;
|
int32_t cacheHit = pNode->pLogStore->cacheHit;
|
||||||
int32_t cacheMiss = pNode->pLogStore->cacheMiss;
|
int32_t cacheMiss = pNode->pLogStore->cacheMiss;
|
||||||
|
|
||||||
char cfgStr[1024];
|
char cfgStr[1024] = "";
|
||||||
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
char peerStr[1024] = "{";
|
char replMgrStatesStr[1024] = "";
|
||||||
syncPeerState2Str(pNode, peerStr, sizeof(peerStr));
|
syncLogReplMgrStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
|
||||||
|
|
||||||
char hbrTimeStr[256] = "hbr:{";
|
char bufferStatesStr[256] = "";
|
||||||
|
syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
|
||||||
|
|
||||||
|
char hbrTimeStr[256] = "";
|
||||||
syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr));
|
syncHearbeatReplyTime2Str(pNode, hbrTimeStr, sizeof(hbrTimeStr));
|
||||||
|
|
||||||
char hbTimeStr[256] = "hb:{";
|
char hbTimeStr[256] = "";
|
||||||
syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr));
|
syncHearbeatTime2Str(pNode, hbTimeStr, sizeof(hbTimeStr));
|
||||||
|
|
||||||
char eventLog[512]; // {0};
|
char eventLog[512]; // {0};
|
||||||
|
@ -186,23 +212,23 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
taosPrintLog(flags, level, dflag,
|
taosPrintLog(flags, level, dflag,
|
||||||
"vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", first-ver:%" PRId64
|
"vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", first-ver:%" PRId64
|
||||||
", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 ", snap-term:%" PRIu64
|
", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 ", snap-term:%" PRIu64
|
||||||
", elect-times:%d, as-leader-times:%d, cfg-ch-times:%d, hit:%d, mis:%d, hb-slow:%d, hbr-slow:%d, "
|
", elect-times:%d, as-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
|
||||||
"aq-items:%d, snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
|
"aq-items:%d, snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
|
||||||
", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64 ", %s, %s, %s, %s",
|
", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64
|
||||||
|
", buffer:%s, repl-mgrs:%s, members:%s, hb:%s, hb-reply:%s",
|
||||||
pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, logBeginIndex,
|
pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, logBeginIndex,
|
||||||
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->electNum,
|
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->electNum,
|
||||||
pNode->becomeLeaderNum, pNode->configChangeNum, cacheHit, cacheMiss, pNode->hbSlowNum,
|
pNode->becomeLeaderNum, pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum, aqItems,
|
||||||
pNode->hbrSlowNum, aqItems, pNode->snapshottingIndex, pNode->replicaNum,
|
pNode->snapshottingIndex, pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing,
|
||||||
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
pNode->restoreFinish, syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser,
|
||||||
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr, hbTimeStr,
|
bufferStatesStr, replMgrStatesStr, cfgStr, hbTimeStr, hbrTimeStr);
|
||||||
hbrTimeStr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
||||||
const char* format, ...) {
|
const char* format, ...) {
|
||||||
SSyncNode* pNode = pSender->pSyncNode;
|
SSyncNode* pNode = pSender->pSyncNode;
|
||||||
if (pNode == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
if (pNode == NULL || pNode->pLogStore == NULL) return;
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
|
@ -216,7 +242,7 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla
|
||||||
logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
|
logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
char cfgStr[1024];
|
char cfgStr[1024] = "";
|
||||||
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
char peerStr[1024] = "{";
|
char peerStr[1024] = "{";
|
||||||
|
@ -238,7 +264,7 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla
|
||||||
pNode->vgId, eventLog, syncStr(pNode->state), pSender, pSender->snapshotParam.start,
|
pNode->vgId, eventLog, syncStr(pNode->state), pSender, pSender->snapshotParam.start,
|
||||||
pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm,
|
pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm,
|
||||||
pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, pSender->finish, pSender->replicaIndex,
|
pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, pSender->finish, pSender->replicaIndex,
|
||||||
DID(&pNode->replicasId[pSender->replicaIndex]), pNode->pRaftStore->currentTerm, pNode->commitIndex,
|
DID(&pNode->replicasId[pSender->replicaIndex]), pNode->raftStore.currentTerm, pNode->commitIndex,
|
||||||
logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||||
pNode->raftCfg.isStandBy, pNode->raftCfg.snapshotStrategy, pNode->raftCfg.batchSize, pNode->replicaNum,
|
pNode->raftCfg.isStandBy, pNode->raftCfg.snapshotStrategy, pNode->raftCfg.batchSize, pNode->replicaNum,
|
||||||
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
||||||
|
@ -248,7 +274,7 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla
|
||||||
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
||||||
const char* format, ...) {
|
const char* format, ...) {
|
||||||
SSyncNode* pNode = pReceiver->pSyncNode;
|
SSyncNode* pNode = pReceiver->pSyncNode;
|
||||||
if (pNode == NULL || pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
if (pNode == NULL || pNode->pLogStore == NULL) return;
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
|
@ -262,7 +288,7 @@ void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t df
|
||||||
logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
|
logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
char cfgStr[1024];
|
char cfgStr[1024] = "";
|
||||||
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
char peerStr[1024] = "{";
|
char peerStr[1024] = "{";
|
||||||
|
@ -285,7 +311,7 @@ void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t df
|
||||||
pNode->vgId, eventLog, syncStr(pNode->state), pReceiver, pReceiver->start, pReceiver->ack,
|
pNode->vgId, eventLog, syncStr(pNode->state), pReceiver, pReceiver->start, pReceiver->ack,
|
||||||
pReceiver->term, pReceiver->startTime, DID(&pReceiver->fromId), pReceiver->snapshotParam.start,
|
pReceiver->term, pReceiver->startTime, DID(&pReceiver->fromId), pReceiver->snapshotParam.start,
|
||||||
pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm,
|
pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm,
|
||||||
pReceiver->snapshot.lastConfigIndex, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex,
|
pReceiver->snapshot.lastConfigIndex, pNode->raftStore.currentTerm, pNode->commitIndex, logBeginIndex,
|
||||||
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||||
pNode->raftCfg.isStandBy, pNode->raftCfg.snapshotStrategy, pNode->raftCfg.batchSize, pNode->replicaNum,
|
pNode->raftCfg.isStandBy, pNode->raftCfg.snapshotStrategy, pNode->raftCfg.batchSize, pNode->replicaNum,
|
||||||
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish, syncNodeDynamicQuorum(pNode),
|
||||||
|
@ -304,7 +330,7 @@ void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char*
|
||||||
|
|
||||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
||||||
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
|
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
|
||||||
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, pMsg->fcIndex, s);
|
syncLocalCmdGetStr(pMsg->cmd), pMsg->currentTerm, pMsg->commitIndex, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
||||||
|
|
|
@ -16,8 +16,8 @@ SyncLocalCmd *createMsg() {
|
||||||
pMsg->srcId.vgId = 100;
|
pMsg->srcId.vgId = 100;
|
||||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||||
pMsg->destId.vgId = 100;
|
pMsg->destId.vgId = 100;
|
||||||
pMsg->sdNewTerm = 123;
|
// pMsg->sdNewTerm = 123;
|
||||||
pMsg->fcIndex = 456;
|
// pMsg->fcIndex = 456;
|
||||||
pMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
pMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
||||||
|
|
||||||
return pMsg;
|
return pMsg;
|
||||||
|
|
|
@ -33,35 +33,35 @@ int main() {
|
||||||
|
|
||||||
initRaftId();
|
initRaftId();
|
||||||
|
|
||||||
SRaftStore* pRaftStore = raftStoreOpen("./test_raft_store.json");
|
// SRaftStore* pRaftStore = raftStoreOpen("./test_raft_store.json");
|
||||||
assert(pRaftStore != NULL);
|
// assert(pRaftStore != NULL);
|
||||||
raftStoreLog2((char*)"==raftStoreOpen==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreOpen==", pRaftStore);
|
||||||
|
|
||||||
raftStoreSetTerm(pRaftStore, 100);
|
// raftStoreSetTerm(pRaftStore, 100);
|
||||||
raftStoreLog2((char*)"==raftStoreSetTerm==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreSetTerm==", pRaftStore);
|
||||||
|
|
||||||
raftStoreVote(pRaftStore, &ids[0]);
|
// raftStoreVote(pRaftStore, &ids[0]);
|
||||||
raftStoreLog2((char*)"==raftStoreVote==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreVote==", pRaftStore);
|
||||||
|
|
||||||
raftStoreClearVote(pRaftStore);
|
// raftStoreClearVote(pRaftStore);
|
||||||
raftStoreLog2((char*)"==raftStoreClearVote==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreClearVote==", pRaftStore);
|
||||||
|
|
||||||
raftStoreVote(pRaftStore, &ids[1]);
|
// raftStoreVote(pRaftStore, &ids[1]);
|
||||||
raftStoreLog2((char*)"==raftStoreVote==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreVote==", pRaftStore);
|
||||||
|
|
||||||
raftStoreNextTerm(pRaftStore);
|
// raftStoreNextTerm(pRaftStore);
|
||||||
raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
||||||
|
|
||||||
raftStoreNextTerm(pRaftStore);
|
// raftStoreNextTerm(pRaftStore);
|
||||||
raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
||||||
|
|
||||||
raftStoreNextTerm(pRaftStore);
|
// raftStoreNextTerm(pRaftStore);
|
||||||
raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
||||||
|
|
||||||
raftStoreNextTerm(pRaftStore);
|
// raftStoreNextTerm(pRaftStore);
|
||||||
raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
// raftStoreLog2((char*)"==raftStoreNextTerm==", pRaftStore);
|
||||||
|
|
||||||
raftStoreClose(pRaftStore);
|
// raftStoreClose(pRaftStore);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
|
||||||
|
|
||||||
SSyncSnapshotReceiver* createReceiver() {
|
SSyncSnapshotReceiver* createReceiver() {
|
||||||
SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(*pSyncNode));
|
SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(*pSyncNode));
|
||||||
pSyncNode->pRaftStore = (SRaftStore*)taosMemoryMalloc(sizeof(*(pSyncNode->pRaftStore)));
|
// pSyncNode->pRaftStore = (SRaftStore*)taosMemoryMalloc(sizeof(*(pSyncNode->pRaftStore)));
|
||||||
pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(*(pSyncNode->pFsm)));
|
pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(*(pSyncNode->pFsm)));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -29,7 +29,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
|
||||||
|
|
||||||
SSyncSnapshotSender* createSender() {
|
SSyncSnapshotSender* createSender() {
|
||||||
SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(*pSyncNode));
|
SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(*pSyncNode));
|
||||||
pSyncNode->pRaftStore = (SRaftStore*)taosMemoryMalloc(sizeof(*(pSyncNode->pRaftStore)));
|
// pSyncNode->pRaftStore = (SRaftStore*)taosMemoryMalloc(sizeof(*(pSyncNode->pRaftStore)));
|
||||||
pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(*(pSyncNode->pFsm)));
|
pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(*(pSyncNode->pFsm)));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -80,7 +80,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
||||||
// tla+ server vars
|
// tla+ server vars
|
||||||
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
||||||
cJSON_AddStringToObject(pRoot, "state_str", syncStr(pSyncNode->state));
|
cJSON_AddStringToObject(pRoot, "state_str", syncStr(pSyncNode->state));
|
||||||
cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(pSyncNode->pRaftStore));
|
// cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(&pSyncNode.raftStore));
|
||||||
|
|
||||||
// tla+ candidate vars
|
// tla+ candidate vars
|
||||||
cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted));
|
cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted));
|
||||||
|
@ -199,7 +199,7 @@ inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
|
||||||
", sby:%d, "
|
", sby:%d, "
|
||||||
"r-num:%d, "
|
"r-num:%d, "
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
||||||
pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex,
|
pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->raftStore.currentTerm, pSyncNode->commitIndex,
|
||||||
logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->raftCfg.isStandBy, pSyncNode->replicaNum,
|
logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->raftCfg.isStandBy, pSyncNode->replicaNum,
|
||||||
pSyncNode->raftCfg.lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
pSyncNode->raftCfg.lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
||||||
|
|
||||||
|
|
|
@ -2858,11 +2858,11 @@ cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "cmd", pMsg->cmd);
|
cJSON_AddNumberToObject(pRoot, "cmd", pMsg->cmd);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->sdNewTerm);
|
// snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->sdNewTerm);
|
||||||
cJSON_AddStringToObject(pRoot, "sd-new-term", u64buf);
|
// cJSON_AddStringToObject(pRoot, "sd-new-term", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fcIndex);
|
// snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fcIndex);
|
||||||
cJSON_AddStringToObject(pRoot, "fc-index", u64buf);
|
// cJSON_AddStringToObject(pRoot, "fc-index", u64buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
|
|
@ -41,8 +41,8 @@ cJSON *raftStore2Json(SRaftStore *pRaftStore) {
|
||||||
cJSON_AddNumberToObject(pVoteFor, "vgId", pRaftStore->voteFor.vgId);
|
cJSON_AddNumberToObject(pVoteFor, "vgId", pRaftStore->voteFor.vgId);
|
||||||
cJSON_AddItemToObject(pRoot, "voteFor", pVoteFor);
|
cJSON_AddItemToObject(pRoot, "voteFor", pVoteFor);
|
||||||
|
|
||||||
int hasVoted = raftStoreHasVoted(pRaftStore);
|
// int hasVoted = raftStoreHasVoted(pRaftStore);
|
||||||
cJSON_AddNumberToObject(pRoot, "hasVoted", hasVoted);
|
// cJSON_AddNumberToObject(pRoot, "hasVoted", hasVoted);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *pJson = cJSON_CreateObject();
|
cJSON *pJson = cJSON_CreateObject();
|
||||||
|
|
|
@ -137,7 +137,7 @@ int32_t syncNodeOnPreSnapshot(SSyncNode *ths, SyncPreSnapshot *pMsg) {
|
||||||
SyncPreSnapshotReply *pMsgReply = syncPreSnapshotReplyBuild(ths->vgId);
|
SyncPreSnapshotReply *pMsgReply = syncPreSnapshotReplyBuild(ths->vgId);
|
||||||
pMsgReply->srcId = ths->myRaftId;
|
pMsgReply->srcId = ths->myRaftId;
|
||||||
pMsgReply->destId = pMsg->srcId;
|
pMsgReply->destId = pMsg->srcId;
|
||||||
pMsgReply->term = ths->pRaftStore->currentTerm;
|
pMsgReply->term = ths->raftStore.currentTerm;
|
||||||
|
|
||||||
SSyncLogStoreData *pData = ths->pLogStore->data;
|
SSyncLogStoreData *pData = ths->pLogStore->data;
|
||||||
SWal *pWal = pData->pWal;
|
SWal *pWal = pData->pWal;
|
||||||
|
|
|
@ -74,7 +74,12 @@ int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, i
|
||||||
|
|
||||||
int32_t tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *),
|
int32_t tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *),
|
||||||
void *xArg, int flags);
|
void *xArg, int flags);
|
||||||
int32_t tdbTxnClose(TXN *pTxn);
|
int32_t tdbTxnCloseImpl(TXN *pTxn);
|
||||||
|
#define tdbTxnClose(pTxn) \
|
||||||
|
do { \
|
||||||
|
tdbTxnCloseImpl(pTxn); \
|
||||||
|
(pTxn) = NULL; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
// other
|
// other
|
||||||
void tdbFree(void *);
|
void tdbFree(void *);
|
||||||
|
|
|
@ -28,13 +28,18 @@ int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbTxnClose(TXN *pTxn) {
|
int tdbTxnCloseImpl(TXN *pTxn) {
|
||||||
if (pTxn) {
|
if (pTxn) {
|
||||||
if (pTxn->jPageSet) {
|
if (pTxn->jPageSet) {
|
||||||
hashset_destroy(pTxn->jPageSet);
|
hashset_destroy(pTxn->jPageSet);
|
||||||
pTxn->jPageSet = NULL;
|
pTxn->jPageSet = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pTxn->jfd) {
|
||||||
|
tdbOsClose(pTxn->jfd);
|
||||||
|
ASSERT(pTxn->jfd == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
tdbOsFree(pTxn);
|
tdbOsFree(pTxn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,13 +101,6 @@ typedef void* queue[2];
|
||||||
#define TRANS_PACKET_LIMIT 1024 * 1024 * 512
|
#define TRANS_PACKET_LIMIT 1024 * 1024 * 512
|
||||||
|
|
||||||
#define TRANS_MAGIC_NUM 0x5f375a86
|
#define TRANS_MAGIC_NUM 0x5f375a86
|
||||||
|
|
||||||
#define TRANS_NOVALID_PACKET(src) ((src) != TRANS_MAGIC_NUM ? 1 : 0)
|
|
||||||
|
|
||||||
#define TRANS_PACKET_LIMIT 1024 * 1024 * 512
|
|
||||||
|
|
||||||
#define TRANS_MAGIC_NUM 0x5f375a86
|
|
||||||
|
|
||||||
#define TRANS_NOVALID_PACKET(src) ((src) != TRANS_MAGIC_NUM ? 1 : 0)
|
#define TRANS_NOVALID_PACKET(src) ((src) != TRANS_MAGIC_NUM ? 1 : 0)
|
||||||
|
|
||||||
typedef SRpcMsg STransMsg;
|
typedef SRpcMsg STransMsg;
|
||||||
|
|
|
@ -35,6 +35,7 @@ typedef struct SHttpModule {
|
||||||
typedef struct SHttpMsg {
|
typedef struct SHttpMsg {
|
||||||
queue q;
|
queue q;
|
||||||
char* server;
|
char* server;
|
||||||
|
char* uri;
|
||||||
int32_t port;
|
int32_t port;
|
||||||
char* cont;
|
char* cont;
|
||||||
int32_t len;
|
int32_t len;
|
||||||
|
@ -63,26 +64,26 @@ static void httpHandleReq(SHttpMsg* msg);
|
||||||
static void httpHandleQuit(SHttpMsg* msg);
|
static void httpHandleQuit(SHttpMsg* msg);
|
||||||
static int32_t httpSendQuit();
|
static int32_t httpSendQuit();
|
||||||
|
|
||||||
static int32_t taosSendHttpReportImpl(const char* server, uint16_t port, char* pCont, int32_t contLen,
|
static int32_t taosSendHttpReportImpl(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||||
EHttpCompFlag flag);
|
EHttpCompFlag flag);
|
||||||
|
|
||||||
static int32_t taosBuildHttpHeader(const char* server, int32_t contLen, char* pHead, int32_t headLen,
|
static int32_t taosBuildHttpHeader(const char* server, const char* uri, int32_t contLen, char* pHead, int32_t headLen,
|
||||||
EHttpCompFlag flag) {
|
EHttpCompFlag flag) {
|
||||||
if (flag == HTTP_FLAT) {
|
if (flag == HTTP_FLAT) {
|
||||||
return snprintf(pHead, headLen,
|
return snprintf(pHead, headLen,
|
||||||
"POST /report HTTP/1.1\n"
|
"POST %s HTTP/1.1\n"
|
||||||
"Host: %s\n"
|
"Host: %s\n"
|
||||||
"Content-Type: application/json\n"
|
"Content-Type: application/json\n"
|
||||||
"Content-Length: %d\n\n",
|
"Content-Length: %d\n\n",
|
||||||
server, contLen);
|
uri, server, contLen);
|
||||||
} else if (flag == HTTP_GZIP) {
|
} else if (flag == HTTP_GZIP) {
|
||||||
return snprintf(pHead, headLen,
|
return snprintf(pHead, headLen,
|
||||||
"POST /report HTTP/1.1\n"
|
"POST %s HTTP/1.1\n"
|
||||||
"Host: %s\n"
|
"Host: %s\n"
|
||||||
"Content-Type: application/json\n"
|
"Content-Type: application/json\n"
|
||||||
"Content-Encoding: gzip\n"
|
"Content-Encoding: gzip\n"
|
||||||
"Content-Length: %d\n\n",
|
"Content-Length: %d\n\n",
|
||||||
server, contLen);
|
uri, server, contLen);
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_INVALID_CFG;
|
terrno = TSDB_CODE_INVALID_CFG;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -181,6 +182,7 @@ static void httpDestroyMsg(SHttpMsg* msg) {
|
||||||
if (msg == NULL) return;
|
if (msg == NULL) return;
|
||||||
|
|
||||||
taosMemoryFree(msg->server);
|
taosMemoryFree(msg->server);
|
||||||
|
taosMemoryFree(msg->uri);
|
||||||
taosMemoryFree(msg->cont);
|
taosMemoryFree(msg->cont);
|
||||||
taosMemoryFree(msg);
|
taosMemoryFree(msg);
|
||||||
}
|
}
|
||||||
|
@ -293,10 +295,11 @@ int32_t httpSendQuit() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosSendHttpReportImpl(const char* server, uint16_t port, char* pCont, int32_t contLen,
|
static int32_t taosSendHttpReportImpl(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen,
|
||||||
EHttpCompFlag flag) {
|
EHttpCompFlag flag) {
|
||||||
SHttpMsg* msg = taosMemoryMalloc(sizeof(SHttpMsg));
|
SHttpMsg* msg = taosMemoryMalloc(sizeof(SHttpMsg));
|
||||||
msg->server = strdup(server);
|
msg->server = strdup(server);
|
||||||
|
msg->uri = strdup(uri);
|
||||||
msg->port = port;
|
msg->port = port;
|
||||||
msg->cont = taosMemoryMalloc(contLen);
|
msg->cont = taosMemoryMalloc(contLen);
|
||||||
memcpy(msg->cont, pCont, contLen);
|
memcpy(msg->cont, pCont, contLen);
|
||||||
|
@ -309,12 +312,10 @@ static int32_t taosSendHttpReportImpl(const char* server, uint16_t port, char* p
|
||||||
httpDestroyMsg(msg);
|
httpDestroyMsg(msg);
|
||||||
tError("http-report already released");
|
tError("http-report already released");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
msg->http = load;
|
|
||||||
transAsyncSend(load->asyncPool, &(msg->q));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
msg->http = load;
|
||||||
|
return transAsyncSend(load->asyncPool, &(msg->q));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void httpDestroyClientCb(uv_handle_t* handle) {
|
static void httpDestroyClientCb(uv_handle_t* handle) {
|
||||||
|
@ -360,7 +361,7 @@ static void httpHandleReq(SHttpMsg* msg) {
|
||||||
|
|
||||||
int32_t len = 2048;
|
int32_t len = 2048;
|
||||||
char* header = taosMemoryCalloc(1, len);
|
char* header = taosMemoryCalloc(1, len);
|
||||||
int32_t headLen = taosBuildHttpHeader(msg->server, msg->len, header, len, msg->flag);
|
int32_t headLen = taosBuildHttpHeader(msg->server, msg->uri, msg->len, header, len, msg->flag);
|
||||||
if (headLen < 0) {
|
if (headLen < 0) {
|
||||||
taosMemoryFree(header);
|
taosMemoryFree(header);
|
||||||
goto END;
|
goto END;
|
||||||
|
@ -380,6 +381,7 @@ static void httpHandleReq(SHttpMsg* msg) {
|
||||||
cli->port = msg->port;
|
cli->port = msg->port;
|
||||||
cli->dest = dest;
|
cli->dest = dest;
|
||||||
|
|
||||||
|
taosMemoryFree(msg->uri);
|
||||||
taosMemoryFree(msg);
|
taosMemoryFree(msg);
|
||||||
|
|
||||||
uv_tcp_init(http->loop, &cli->tcp);
|
uv_tcp_init(http->loop, &cli->tcp);
|
||||||
|
@ -406,9 +408,9 @@ END:
|
||||||
httpDestroyMsg(msg);
|
httpDestroyMsg(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) {
|
int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) {
|
||||||
taosThreadOnce(&transHttpInit, transHttpEnvInit);
|
taosThreadOnce(&transHttpInit, transHttpEnvInit);
|
||||||
return taosSendHttpReportImpl(server, port, pCont, contLen, flag);
|
return taosSendHttpReportImpl(server, uri, port, pCont, contLen, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transHttpEnvInit() {
|
static void transHttpEnvInit() {
|
||||||
|
|
|
@ -1126,7 +1126,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
|
||||||
|
|
||||||
int ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb);
|
int ret = uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
tGTrace("%s conn %p failed to connect to %s:%d, reason:%s", pTransInst->label, conn, conn->ip, conn->port,
|
tGError("%s conn %p failed to connect to %s:%d, reason:%s", pTransInst->label, conn, conn->ip, conn->port,
|
||||||
uv_err_name(ret));
|
uv_err_name(ret));
|
||||||
|
|
||||||
uv_timer_stop(conn->timer);
|
uv_timer_stop(conn->timer);
|
||||||
|
|
|
@ -292,19 +292,10 @@ void walAlignVersions(SWal* pWal) {
|
||||||
}
|
}
|
||||||
pWal->vers.lastVer = pWal->vers.snapshotVer;
|
pWal->vers.lastVer = pWal->vers.snapshotVer;
|
||||||
}
|
}
|
||||||
if (pWal->vers.commitVer < pWal->vers.snapshotVer) {
|
// reset commitVer and appliedVer
|
||||||
wWarn("vgId:%d, commitVer:%" PRId64 " is less than snapshotVer:%" PRId64 ". align with it.", pWal->cfg.vgId,
|
|
||||||
pWal->vers.commitVer, pWal->vers.snapshotVer);
|
|
||||||
pWal->vers.commitVer = pWal->vers.snapshotVer;
|
pWal->vers.commitVer = pWal->vers.snapshotVer;
|
||||||
}
|
|
||||||
if (pWal->vers.appliedVer < pWal->vers.snapshotVer) {
|
|
||||||
wWarn("vgId:%d, appliedVer:%" PRId64 " is less than snapshotVer:%" PRId64 ". align with it.", pWal->cfg.vgId,
|
|
||||||
pWal->vers.appliedVer, pWal->vers.snapshotVer);
|
|
||||||
pWal->vers.appliedVer = pWal->vers.snapshotVer;
|
pWal->vers.appliedVer = pWal->vers.snapshotVer;
|
||||||
}
|
wInfo("vgId:%d, reset commitVer to %" PRId64, pWal->cfg.vgId, pWal->vers.commitVer);
|
||||||
|
|
||||||
pWal->vers.commitVer = TMIN(pWal->vers.lastVer, pWal->vers.commitVer);
|
|
||||||
pWal->vers.appliedVer = TMIN(pWal->vers.commitVer, pWal->vers.appliedVer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool walLogEntriesComplete(const SWal* pWal) {
|
bool walLogEntriesComplete(const SWal* pWal) {
|
||||||
|
|
|
@ -105,7 +105,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
wInfo("vgId:%d, wal rollback for version %" PRId64, pWal->cfg.vgId, ver);
|
wInfo("vgId:%d, wal rollback for version %" PRId64, pWal->cfg.vgId, ver);
|
||||||
int64_t code;
|
int64_t code;
|
||||||
char fnameStr[WAL_FILE_LEN];
|
char fnameStr[WAL_FILE_LEN];
|
||||||
if (ver > pWal->vers.lastVer || ver < pWal->vers.commitVer || ver <= pWal->vers.snapshotVer) {
|
if (ver > pWal->vers.lastVer || ver <= pWal->vers.commitVer || ver <= pWal->vers.snapshotVer) {
|
||||||
terrno = TSDB_CODE_WAL_INVALID_VER;
|
terrno = TSDB_CODE_WAL_INVALID_VER;
|
||||||
taosThreadMutexUnlock(&pWal->mutex);
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -635,6 +635,7 @@ int32_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
|
||||||
}
|
}
|
||||||
|
|
||||||
void walFsync(SWal *pWal, bool forceFsync) {
|
void walFsync(SWal *pWal, bool forceFsync) {
|
||||||
|
taosThreadMutexLock(&pWal->mutex);
|
||||||
if (forceFsync || (pWal->cfg.level == TAOS_WAL_FSYNC && pWal->cfg.fsyncPeriod == 0)) {
|
if (forceFsync || (pWal->cfg.level == TAOS_WAL_FSYNC && pWal->cfg.fsyncPeriod == 0)) {
|
||||||
wTrace("vgId:%d, fileId:%" PRId64 ".idx, do fsync", pWal->cfg.vgId, walGetCurFileFirstVer(pWal));
|
wTrace("vgId:%d, fileId:%" PRId64 ".idx, do fsync", pWal->cfg.vgId, walGetCurFileFirstVer(pWal));
|
||||||
if (taosFsyncFile(pWal->pIdxFile) < 0) {
|
if (taosFsyncFile(pWal->pIdxFile) < 0) {
|
||||||
|
@ -647,4 +648,5 @@ void walFsync(SWal *pWal, bool forceFsync) {
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue