From 144e334d04604ec70fc41cdc1ddc8e4a37208a2e Mon Sep 17 00:00:00 2001 From: jtao1735 Date: Thu, 7 May 2020 23:39:23 +0000 Subject: [PATCH] notify vnode when data file is synced, so vnode can restart TSDB --- src/inc/tsync.h | 9 ++++++--- src/vnode/src/vnodeMain.c | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/inc/tsync.h b/src/inc/tsync.h index 797de063b9..0d6004bba5 100644 --- a/src/inc/tsync.h +++ b/src/inc/tsync.h @@ -54,8 +54,8 @@ typedef struct { int role[TAOS_SYNC_MAX_REPLICA]; } SNodesRole; -// if name is null, get the file from index or after, used by master -// if name is provided, get the named file at the specified index, used by unsynced node +// if name is empty(name[0] is zero), get the file from index or after, used by master +// if name is provided(name[0] is not zero), get the named file at the specified index, used by unsynced node // it returns the file magic number and size, if file not there, magic shall be 0. typedef uint32_t (*FGetFileInfo)(void *ahandle, char *name, uint32_t *index, int32_t *size); @@ -72,6 +72,9 @@ typedef void (*FConfirmForward)(void *ahandle, void *mhandle, int32_t code); // when role is changed, call this to notify app typedef void (*FNotifyRole)(void *ahandle, int8_t role); +// when data file is synced successfully, notity app +typedef void (*FNotifyFileSynced)(void *ahandle); + typedef struct { int32_t vgId; // vgroup ID uint64_t version; // initial version @@ -84,7 +87,7 @@ typedef struct { FWriteToCache writeToCache; FConfirmForward confirmForward; FNotifyRole notifyRole; - + FNotifyFileSynced notifyFileSynced; } SSyncInfo; typedef void* tsync_h; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index f5d7bd45a7..d3d79efab9 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -46,6 +46,7 @@ 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); static void vnodeNotifyRole(void *ahandle, int8_t role); +static void vnodeNotifyFileSynced(void *ahandle); static pthread_once_t vnodeModuleInit = PTHREAD_ONCE_INIT; @@ -234,6 +235,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { syncInfo.writeToCache = vnodeWriteToQueue; syncInfo.confirmForward = dnodeSendRpcWriteRsp; syncInfo.notifyRole = vnodeNotifyRole; + syncInfo.notifyFileSynced = vnodeNotifyFileSynced; pVnode->sync = syncStart(&syncInfo); // start continuous query @@ -405,6 +407,13 @@ static void vnodeNotifyRole(void *ahandle, int8_t role) { cqStop(pVnode->cq); } +static void vnodeNotifyFileSynced(void *ahandle) { + SVnodeObj *pVnode = ahandle; + dTrace("pVnode:%p vgId:%d, data file is synced", pVnode, pVnode->vgId); + + // clsoe tsdb, then open tsdb +} + static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg) { char cfgFile[TSDB_FILENAME_LEN + 30] = {0}; sprintf(cfgFile, "%s/vnode%d/config.json", tsVnodeDir, pVnodeCfg->cfg.vgId); -- GitLab