vnode snapshot read
This commit is contained in:
parent
93391f73e5
commit
7d30a6e27a
|
@ -347,6 +347,11 @@ typedef struct SStreamMeta {
|
||||||
void* streamBackend;
|
void* streamBackend;
|
||||||
int64_t streamBackendRid;
|
int64_t streamBackendRid;
|
||||||
int64_t checkpointTs;
|
int64_t checkpointTs;
|
||||||
|
|
||||||
|
SArray* checkpointSaved;
|
||||||
|
SArray* checkpointInUse;
|
||||||
|
int32_t checkpointCap;
|
||||||
|
SRWLatch checkpointDirLock;
|
||||||
} SStreamMeta;
|
} SStreamMeta;
|
||||||
|
|
||||||
int32_t tEncodeStreamEpInfo(SEncoder* pEncoder, const SStreamChildEpInfo* pInfo);
|
int32_t tEncodeStreamEpInfo(SEncoder* pEncoder, const SStreamChildEpInfo* pInfo);
|
||||||
|
|
|
@ -46,7 +46,7 @@ typedef struct {
|
||||||
|
|
||||||
void* streamBackendInit(const char* path);
|
void* streamBackendInit(const char* path);
|
||||||
void streamBackendCleanup(void* arg);
|
void streamBackendCleanup(void* arg);
|
||||||
int32_t streamBackendDoCheckpoint(int64_t rid, const char* cpPath);
|
int32_t streamBackendDoCheckpoint(void* pMeta, const char* path);
|
||||||
SListNode* streamBackendAddCompare(void* backend, void* arg);
|
SListNode* streamBackendAddCompare(void* backend, void* arg);
|
||||||
void streamBackendDelCompare(void* backend, void* arg);
|
void streamBackendDelCompare(void* backend, void* arg);
|
||||||
|
|
||||||
|
|
|
@ -195,16 +195,69 @@ void streamBackendCleanup(void* arg) {
|
||||||
qDebug("destroy stream backend backend:%p", pHandle);
|
qDebug("destroy stream backend backend:%p", pHandle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int32_t streamBackendDoCheckpoint(int64_t backendRid, const char* path) {
|
|
||||||
|
/*
|
||||||
|
* checkpointSave |--cp1--|--cp2--|--cp3--|--cp4--|--cp5--|
|
||||||
|
* checkpointInUse: |--cp2--|--cp4--|, checkpointDir in checkpointInUse do replicate trans, cannot del until
|
||||||
|
* replication is finished
|
||||||
|
*/
|
||||||
|
int32_t delObsoleteCheckpoint(void* arg, const char* path) {
|
||||||
|
SStreamMeta* pMeta = arg;
|
||||||
|
|
||||||
|
taosWLockLatch(&pMeta->checkpointDirLock);
|
||||||
|
int64_t checkpointId = pMeta->checkpointTs;
|
||||||
|
taosArrayPush(pMeta->checkpointSaved, &checkpointId);
|
||||||
|
|
||||||
|
SArray* checkpointDel = taosArrayInit(10, sizeof(int64_t));
|
||||||
|
SArray* checkpointDup = taosArrayInit(10, sizeof(int64_t));
|
||||||
|
|
||||||
|
int64_t minId = 0;
|
||||||
|
if (taosArrayGetSize(pMeta->checkpointInUse) >= 1) {
|
||||||
|
minId = *(int64_t*)taosArrayGet(pMeta->checkpointInUse, 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < taosArrayGetSize(pMeta->checkpointSaved); i++) {
|
||||||
|
int64_t id = *(int64_t*)taosArrayGet(pMeta->checkpointSaved, i);
|
||||||
|
if (id >= minId) {
|
||||||
|
taosArrayPush(checkpointDup, &id);
|
||||||
|
} else {
|
||||||
|
taosArrayPush(checkpointDel, &id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = taosArrayGetSize(pMeta->checkpointSaved); i >= 0; i--) {
|
||||||
|
int64_t id = *(int64_t*)taosArrayGet(pMeta->checkpointSaved, i);
|
||||||
|
if (taosArrayGetSize(checkpointDup) < pMeta->checkpointCap) {
|
||||||
|
taosArrayPush(checkpointDup, &id);
|
||||||
|
} else {
|
||||||
|
taosArrayPush(checkpointDel, &id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosArrayDestroy(pMeta->checkpointSaved);
|
||||||
|
pMeta->checkpointSaved = checkpointDup;
|
||||||
|
|
||||||
|
taosWUnLockLatch(&pMeta->checkpointDirLock);
|
||||||
|
|
||||||
|
for (int i = 0; i < taosArrayGetSize(checkpointDel); i++) {
|
||||||
|
int64_t id = *(int64_t*)taosArrayGet(checkpointDel, i);
|
||||||
|
char tbuf[256] = {0};
|
||||||
|
sprintf(tbuf, "%s/checkpoint_%" PRId64 "", path, id);
|
||||||
|
if (taosIsDir(tbuf)) {
|
||||||
|
taosRemoveDir(tbuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int32_t streamBackendDoCheckpoint(void* arg, const char* path) {
|
||||||
|
SStreamMeta* pMeta = arg;
|
||||||
|
int64_t backendRid = pMeta->streamBackendRid;
|
||||||
|
int64_t checkpointId = pMeta->checkpointTs;
|
||||||
int64_t st = taosGetTimestampMs();
|
int64_t st = taosGetTimestampMs();
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SBackendHandle* pHandle = taosAcquireRef(streamBackendId, backendRid);
|
SBackendHandle* pHandle = taosAcquireRef(streamBackendId, backendRid);
|
||||||
static int checkpointSuffix = 0;
|
|
||||||
|
|
||||||
char newDir[256] = {0};
|
char checkpointDir[256] = {0};
|
||||||
char oldDir[256] = {0};
|
sprintf(checkpointDir, "%s/checkpoint_%" PRId64 "", path, checkpointId);
|
||||||
sprintf(oldDir, "%s/checkpoint_%d", path, checkpointSuffix);
|
|
||||||
sprintf(newDir, "%s/checkpoint_%d", path, 1 - checkpointSuffix);
|
|
||||||
|
|
||||||
if (pHandle == NULL) {
|
if (pHandle == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -220,7 +273,7 @@ int32_t streamBackendDoCheckpoint(int64_t backendRid, const char* path) {
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
rocksdb_checkpoint_create(cp, newDir, 64 << 20, &err);
|
rocksdb_checkpoint_create(cp, checkpointDir, 64 << 20, &err);
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
qError("stream backend:%p failed to do checkpoint at:%s, reason:%s", pHandle, path, err);
|
qError("stream backend:%p failed to do checkpoint at:%s, reason:%s", pHandle, path, err);
|
||||||
taosMemoryFreeClear(err);
|
taosMemoryFreeClear(err);
|
||||||
|
@ -231,11 +284,7 @@ int32_t streamBackendDoCheckpoint(int64_t backendRid, const char* path) {
|
||||||
}
|
}
|
||||||
rocksdb_checkpoint_object_destroy(cp);
|
rocksdb_checkpoint_object_destroy(cp);
|
||||||
}
|
}
|
||||||
if (taosIsDir(oldDir)) {
|
delObsoleteCheckpoint(arg, path);
|
||||||
taosRemoveDir(oldDir);
|
|
||||||
}
|
|
||||||
taosRenameFile(newDir, oldDir);
|
|
||||||
|
|
||||||
_ERROR:
|
_ERROR:
|
||||||
taosReleaseRef(streamBackendId, backendRid);
|
taosReleaseRef(streamBackendId, backendRid);
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -93,6 +93,10 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
pMeta->streamBackendRid = taosAddRef(streamBackendId, pMeta->streamBackend);
|
pMeta->streamBackendRid = taosAddRef(streamBackendId, pMeta->streamBackend);
|
||||||
|
pMeta->checkpointSaved = taosArrayInit(4, sizeof(int64_t));
|
||||||
|
pMeta->checkpointInUse = taosArrayInit(4, sizeof(int64_t));
|
||||||
|
pMeta->checkpointCap = 4;
|
||||||
|
taosInitRWLatch(&pMeta->checkpointDirLock);
|
||||||
|
|
||||||
taosMemoryFree(streamPath);
|
taosMemoryFree(streamPath);
|
||||||
|
|
||||||
|
@ -108,6 +112,7 @@ _err:
|
||||||
if (pMeta->pCheckpointDb) tdbTbClose(pMeta->pCheckpointDb);
|
if (pMeta->pCheckpointDb) tdbTbClose(pMeta->pCheckpointDb);
|
||||||
if (pMeta->db) tdbClose(pMeta->db);
|
if (pMeta->db) tdbClose(pMeta->db);
|
||||||
taosMemoryFree(pMeta);
|
taosMemoryFree(pMeta);
|
||||||
|
|
||||||
qError("failed to open stream meta");
|
qError("failed to open stream meta");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -138,6 +143,9 @@ void streamMetaClose(SStreamMeta* pMeta) {
|
||||||
taosRemoveRef(streamBackendId, pMeta->streamBackendRid);
|
taosRemoveRef(streamBackendId, pMeta->streamBackendRid);
|
||||||
pMeta->pTaskList = taosArrayDestroy(pMeta->pTaskList);
|
pMeta->pTaskList = taosArrayDestroy(pMeta->pTaskList);
|
||||||
taosMemoryFree(pMeta->path);
|
taosMemoryFree(pMeta->path);
|
||||||
|
|
||||||
|
taosArrayDestroy(pMeta->checkpointSaved);
|
||||||
|
taosArrayDestroy(pMeta->checkpointInUse);
|
||||||
taosMemoryFree(pMeta);
|
taosMemoryFree(pMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,6 +427,6 @@ int32_t streamDoCheckpoint(SStreamMeta* pMeta) {
|
||||||
qError("failed to create chechpoint %s, reason:%s", buf, tstrerror(code));
|
qError("failed to create chechpoint %s, reason:%s", buf, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
code = streamBackendDoCheckpoint(pMeta->streamBackendRid, buf);
|
code = streamBackendDoCheckpoint((void*)pMeta, buf);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue