提交 69a55916 编写于 作者: S slguan

add dnode offline timer

上级 d099ab73
......@@ -42,6 +42,8 @@ void * mgmtGetDnodeByIp(uint32_t ip);
void mgmtUpdateDnode(SDnodeObj *pDnode);
int32_t mgmtDropDnode(SDnodeObj *pDnode);
extern int32_t tsAccessSquence;
#ifdef __cplusplus
}
#endif
......
......@@ -38,6 +38,7 @@
void *tsDnodeSdb = NULL;
int32_t tsDnodeUpdateSize = 0;
int32_t tsAccessSquence = 0;
extern void * tsVgroupSdb;
static int32_t mgmtCreateDnode(uint32_t ip);
......@@ -323,6 +324,7 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
pDnode->alternativeRole = pStatus->alternativeRole;
pDnode->totalVnodes = pStatus->numOfTotalVnodes;
pDnode->moduleStatus = pStatus->moduleStatus;
pDnode->lastAccess = tsAccessSquence;
if (pStatus->dnodeId == 0) {
mTrace("dnode:%d, first access, privateIp:%s, name:%s", pDnode->dnodeId, taosIpStr(pDnode->privateIp), pDnode->dnodeName);
......
......@@ -149,12 +149,12 @@ void mgmtCleanUpSystem() {
mgmtCleanUpShell();
mgmtCleanupDClient();
mgmtCleanupDServer();
mgmtCleanUpAccts();
mgmtCleanUpTables();
mgmtCleanUpVgroups();
mgmtCleanUpDbs();
mgmtCleanupDnodes();
mgmtCleanUpUsers();
mgmtCleanUpAccts();
sdbCleanUp();
taosTmrCleanUp(tsMgmtTmr);
tsMgmtIsRunning = false;
......
......@@ -38,6 +38,8 @@ static void vnodeBuildVloadMsg(char *pNode, void * param);
static int vnodeWalCallback(void *arg);
static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg);
static int32_t vnodeReadCfg(SVnodeObj *pVnode);
static int32_t vnodeSaveVersion(SVnodeObj *pVnode);
static int32_t vnodeReadVersion(SVnodeObj *pVnode);
static int vnodeWalCallback(void *arg);
static uint32_t vnodeGetFileInfo(void *ahandle, char *name, uint32_t *index, int32_t *size);
static int vnodeGetWalInfo(void *ahandle, char *name, uint32_t *index);
......@@ -151,6 +153,8 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
return code;
}
vnodeReadVersion(pVnode);
pVnode->wqueue = dnodeAllocateWqueue(pVnode);
pVnode->rqueue = dnodeAllocateRqueue(pVnode);
......@@ -303,6 +307,7 @@ static void vnodeCleanUp(SVnodeObj *pVnode) {
//syncStop(pVnode->sync);
tsdbCloseRepo(pVnode->tsdb);
walClose(pVnode->wal);
vnodeSaveVersion(pVnode);
vnodeRelease(pVnode);
}
......@@ -562,3 +567,74 @@ PARSE_OVER:
fclose(fp);
return ret;
}
static int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
char versionFile[TSDB_FILENAME_LEN + 30] = {0};
sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
FILE *fp = fopen(versionFile, "w");
if (!fp) {
dError("pVnode:%p vgId:%d, failed to open vnode version file for write, error:%s", pVnode, pVnode->vgId);
return errno;
}
int32_t len = 0;
int32_t maxLen = 30;
char * content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"version\": %" PRId64 "\n", pVnode->version);
len += snprintf(content + len, maxLen - len, "}\n");
fwrite(content, 1, len, fp);
fclose(fp);
free(content);
dPrint("pVnode:%p vgId:%d, save vnode version successed", pVnode, pVnode->vgId);
return 0;
}
static int32_t vnodeReadVersion(SVnodeObj *pVnode) {
char versionFile[TSDB_FILENAME_LEN + 30] = {0};
sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
FILE *fp = fopen(versionFile, "w");
if (!fp) {
dError("pVnode:%p vgId:%d, failed to open vnode version file for write, error:%s", pVnode, pVnode->vgId);
return errno;
}
int ret = TSDB_CODE_OTHERS;
int maxLen = 100;
char *content = calloc(1, maxLen + 1);
int len = fread(content, 1, maxLen, fp);
if (len <= 0) {
free(content);
fclose(fp);
dError("pVnode:%p vgId:%d, failed to read vnode version, content is null", pVnode, pVnode->vgId);
return false;
}
cJSON *root = cJSON_Parse(content);
if (root == NULL) {
dError("pVnode:%p vgId:%d, failed to read vnode version, invalid json format", pVnode, pVnode->vgId);
goto PARSE_OVER;
}
cJSON *version = cJSON_GetObjectItem(root, "version");
if (!version || version->type != cJSON_Number) {
dError("pVnode:%p vgId:%d, failed to read vnode version, version not found", pVnode, pVnode->vgId);
goto PARSE_OVER;
}
pVnode->version = version->valueint;
ret = 0;
dPrint("pVnode:%p vgId:%d, read vnode version successed, version:%%" PRId64, pVnode, pVnode->vgId, pVnode->version);
PARSE_OVER:
free(content);
cJSON_Delete(root);
fclose(fp);
return ret;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册