This commit is contained in:
Hongze Cheng 2020-06-18 15:49:24 +00:00
parent fe34e6a274
commit eb8f74e952
3 changed files with 16 additions and 4 deletions

View File

@ -80,6 +80,7 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
char *tDataDir = NULL; char *tDataDir = NULL;
DIR * dir = NULL; DIR * dir = NULL;
int fid = 0; int fid = 0;
int vid = 0;
SFileGroup fileGroup = {0}; SFileGroup fileGroup = {0};
STsdbFileH *pFileH = pRepo->tsdbFileH; STsdbFileH *pFileH = pRepo->tsdbFileH;
@ -100,7 +101,7 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
struct dirent *dp = NULL; struct dirent *dp = NULL;
while ((dp = readdir(dir)) != NULL) { while ((dp = readdir(dir)) != NULL) {
if (strncmp(dp->d_name, ".", 1) == 0 || strncmp(dp->d_name, "..", 2) == 0) continue; if (strncmp(dp->d_name, ".", 1) == 0 || strncmp(dp->d_name, "..", 2) == 0) continue;
sscanf(dp->d_name, "f%d", &fid); sscanf(dp->d_name, "v%df%d", &vid, &fid);
if (tsdbSearchFGroup(pRepo->tsdbFileH, fid, TD_EQ) != NULL) return 0; if (tsdbSearchFGroup(pRepo->tsdbFileH, fid, TD_EQ) != NULL) return 0;

View File

@ -134,7 +134,6 @@ TSDB_REPO_T *tsdbOpenRepo(char *rootDir, STsdbAppH *pAppH) {
_err: _err:
tsdbCloseRepo(pRepo, false); tsdbCloseRepo(pRepo, false);
tsdbFreeRepo(pRepo);
return NULL; return NULL;
} }

View File

@ -223,6 +223,8 @@ _err:
int tdUpdateKVStoreRecord(SKVStore *pStore, uint64_t uid, void *cont, int contLen) { int tdUpdateKVStoreRecord(SKVStore *pStore, uint64_t uid, void *cont, int contLen) {
SKVRecord rInfo = {0}; SKVRecord rInfo = {0};
char buf[64] = "\0";
char * pBuf = buf;
rInfo.offset = lseek(pStore->fd, 0, SEEK_CUR); rInfo.offset = lseek(pStore->fd, 0, SEEK_CUR);
if (rInfo.offset < 0) { if (rInfo.offset < 0) {
@ -233,6 +235,16 @@ int tdUpdateKVStoreRecord(SKVStore *pStore, uint64_t uid, void *cont, int contLe
rInfo.uid = uid; rInfo.uid = uid;
rInfo.size = contLen; rInfo.size = contLen;
int tlen = tdEncodeKVRecord((void *)(&pBuf), &rInfo);
ASSERT(tlen == POINTER_DISTANCE(pBuf, buf));
ASSERT(tlen == sizeof(SKVRecord));
if (twrite(pStore->fd, buf, tlen) < tlen) {
uError("failed to write %d bytes to file %s since %s", tlen, pStore->fname, strerror(errno));
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
if (twrite(pStore->fd, cont, contLen) < contLen) { if (twrite(pStore->fd, cont, contLen) < contLen) {
uError("failed to write %d bytes to file %s since %s", contLen, pStore->fname, strerror(errno)); uError("failed to write %d bytes to file %s since %s", contLen, pStore->fname, strerror(errno));
return -1; return -1;
@ -534,7 +546,7 @@ static int tdRestoreKVStore(SKVStore *pStore) {
while (taosHashIterNext(pIter)) { while (taosHashIterNext(pIter)) {
SKVRecord *pRecord = taosHashIterGet(pIter); SKVRecord *pRecord = taosHashIterGet(pIter);
if (lseek(pStore->fd, pRecord->offset, SEEK_SET) < 0) { if (lseek(pStore->fd, pRecord->offset + sizeof(SKVRecord), SEEK_SET) < 0) {
uError("failed to lseek file %s since %s, offset %" PRId64, pStore->fname, strerror(errno), pRecord->offset); uError("failed to lseek file %s since %s, offset %" PRId64, pStore->fname, strerror(errno), pRecord->offset);
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
goto _err; goto _err;
@ -551,7 +563,7 @@ static int tdRestoreKVStore(SKVStore *pStore) {
if ((*pStore->iFunc)(pStore->appH, buf, pRecord->size) < 0) { if ((*pStore->iFunc)(pStore->appH, buf, pRecord->size) < 0) {
uError("failed to restore record uid %" PRIu64 " in kv store %s at offset %" PRId64 " size %" PRId64 uError("failed to restore record uid %" PRIu64 " in kv store %s at offset %" PRId64 " size %" PRId64
" since %s", " since %s",
pStore->fname, pRecord->uid, pRecord->offset, pRecord->size, tstrerror(terrno)); pRecord->uid, pStore->fname, pRecord->offset, pRecord->size, tstrerror(terrno));
goto _err; goto _err;
} }
} }