TD-1696
This commit is contained in:
parent
bd934402e7
commit
3f52d74a8e
|
@ -193,6 +193,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, 0, 0x0506, "No write p
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "Missing data file")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "Missing data file")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "Out of memory")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "Out of memory")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "Unexpected generic error in vnode")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "Unexpected generic error in vnode")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VRESION_FILE, 0, 0x050A, "Invalid version file")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_SYNCED, 0, 0x0511, "Database suspended")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_SYNCED, 0, 0x0511, "Database suspended")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0512, "Write operation denied")
|
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0512, "Write operation denied")
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ int walWrite(twalh, SWalHead *);
|
||||||
void walFsync(twalh);
|
void walFsync(twalh);
|
||||||
int walRestore(twalh, void *pVnode, FWalWrite writeFp);
|
int walRestore(twalh, void *pVnode, FWalWrite writeFp);
|
||||||
int walGetWalFile(twalh, char *name, uint32_t *index);
|
int walGetWalFile(twalh, char *name, uint32_t *index);
|
||||||
|
int64_t walGetVersion(twalh);
|
||||||
|
|
||||||
extern int wDebugFlag;
|
extern int wDebugFlag;
|
||||||
|
|
||||||
|
|
|
@ -239,8 +239,10 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
||||||
|
|
||||||
code = vnodeReadVersion(pVnode);
|
code = vnodeReadVersion(pVnode);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
vnodeCleanUp(pVnode);
|
vError("vgId:%d, failed to read version, generate it from data file", pVnode->vgId);
|
||||||
return code;
|
// Allow vnode start even when read version fails, set version as walVersion or zero
|
||||||
|
// vnodeCleanUp(pVnode);
|
||||||
|
// return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pVnode->fversion = pVnode->version;
|
pVnode->fversion = pVnode->version;
|
||||||
|
@ -292,6 +294,9 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
walRestore(pVnode->wal, pVnode, vnodeWriteToQueue);
|
walRestore(pVnode->wal, pVnode, vnodeWriteToQueue);
|
||||||
|
if (pVnode->version == 0) {
|
||||||
|
pVnode->version = walGetVersion(pVnode->wal);
|
||||||
|
}
|
||||||
|
|
||||||
SSyncInfo syncInfo;
|
SSyncInfo syncInfo;
|
||||||
syncInfo.vgId = pVnode->vgId;
|
syncInfo.vgId = pVnode->vgId;
|
||||||
|
@ -947,6 +952,7 @@ static int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
len += snprintf(content + len, maxLen - len, "}\n");
|
||||||
|
|
||||||
fwrite(content, 1, len, fp);
|
fwrite(content, 1, len, fp);
|
||||||
|
fflush(fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
vInfo("vgId:%d, save vnode version:%" PRId64 " succeed", pVnode->vgId, pVnode->fversion);
|
vInfo("vgId:%d, save vnode version:%" PRId64 " succeed", pVnode->vgId, pVnode->fversion);
|
||||||
|
@ -960,7 +966,7 @@ static int32_t vnodeReadVersion(SVnodeObj *pVnode) {
|
||||||
cJSON *root = NULL;
|
cJSON *root = NULL;
|
||||||
int maxLen = 100;
|
int maxLen = 100;
|
||||||
|
|
||||||
terrno = TSDB_CODE_VND_APP_ERROR;
|
terrno = TSDB_CODE_VND_INVALID_VRESION_FILE;
|
||||||
sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
|
sprintf(versionFile, "%s/vnode%d/version.json", tsVnodeDir, pVnode->vgId);
|
||||||
FILE *fp = fopen(versionFile, "r");
|
FILE *fp = fopen(versionFile, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
|
@ -974,7 +980,7 @@ static int32_t vnodeReadVersion(SVnodeObj *pVnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
content = calloc(1, maxLen + 1);
|
content = calloc(1, maxLen + 1);
|
||||||
int len = fread(content, 1, maxLen, fp);
|
int len = fread(content, 1, maxLen, fp);
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
vError("vgId:%d, failed to read vnode version, content is null", pVnode->vgId);
|
vError("vgId:%d, failed to read vnode version, content is null", pVnode->vgId);
|
||||||
goto PARSE_OVER;
|
goto PARSE_OVER;
|
||||||
|
@ -999,6 +1005,6 @@ static int32_t vnodeReadVersion(SVnodeObj *pVnode) {
|
||||||
PARSE_OVER:
|
PARSE_OVER:
|
||||||
taosTFree(content);
|
taosTFree(content);
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
if(fp) fclose(fp);
|
if (fp) fclose(fp);
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,10 +240,7 @@ int walWrite(void *handle, SWalHead *pHead) {
|
||||||
|
|
||||||
// no wal
|
// no wal
|
||||||
if (pWal->level == TAOS_WAL_NOLOG) return 0;
|
if (pWal->level == TAOS_WAL_NOLOG) return 0;
|
||||||
if (pHead->version <= pWal->version) {
|
if (pHead->version <= pWal->version) return 0;
|
||||||
wError("wal:%s, failed to write ver:%" PRIu64 ", last ver:%" PRIu64, pWal->name, pHead->version, pWal->version);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pHead->signature = walSignature;
|
pHead->signature = walSignature;
|
||||||
taosCalcChecksumAppend(0, (uint8_t *)pHead, sizeof(SWalHead));
|
taosCalcChecksumAppend(0, (uint8_t *)pHead, sizeof(SWalHead));
|
||||||
|
@ -560,3 +557,10 @@ static void walProcessFsyncTimer(void *param, void *tmrId) {
|
||||||
pWal->timer = NULL;
|
pWal->timer = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t walGetVersion(twalh param) {
|
||||||
|
SWal *pWal = param;
|
||||||
|
if (pWal == 0) return 0;
|
||||||
|
|
||||||
|
return pWal->version;
|
||||||
|
}
|
Loading…
Reference in New Issue