提交 c4f40874 编写于 作者: M Minglei Jin

tdb/pager: debug logs for pager restore

上级 336ee146
...@@ -880,6 +880,8 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) { ...@@ -880,6 +880,8 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) {
return -1; return -1;
} }
tdbDebug("pager/restore: %p, %d/%d, txnId:%s", pPager, pPager->dbOrigSize, pPager->dbFileSize, jFileName);
for (int pgIndex = 0; pgIndex < journalSize; ++pgIndex) { for (int pgIndex = 0; pgIndex < journalSize; ++pgIndex) {
// read pgno & the page from journal // read pgno & the page from journal
SPgno pgno; SPgno pgno;
...@@ -890,6 +892,8 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) { ...@@ -890,6 +892,8 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) {
return -1; return -1;
} }
tdbTrace("pager/restore: restore pgno:%d,", pgno);
ret = tdbOsRead(jfd, pageBuf, pPager->pageSize); ret = tdbOsRead(jfd, pageBuf, pPager->pageSize);
if (ret < 0) { if (ret < 0) {
tdbOsFree(pageBuf); tdbOsFree(pageBuf);
...@@ -929,7 +933,7 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) { ...@@ -929,7 +933,7 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) {
return -1; return -1;
} }
if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) { if (tdbOsRemove(jFileName) < 0 && errno != ENOENT) {
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName); tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return -1;
...@@ -949,7 +953,12 @@ int tdbPagerRestoreJournals(SPager *pPager) { ...@@ -949,7 +953,12 @@ int tdbPagerRestoreJournals(SPager *pPager) {
while ((pDirEntry = tdbReadDir(pDir)) != NULL) { while ((pDirEntry = tdbReadDir(pDir)) != NULL) {
char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry)); char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry));
if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) { if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) {
if (tdbPagerRestore(pPager, name) < 0) { char jname[TD_PATH_MAX] = {0};
int dirLen = strlen(pPager->pEnv->dbName);
memcpy(jname, pPager->pEnv->dbName, dirLen);
jname[dirLen] = '/';
memcpy(jname + dirLen + 1, name, strlen(name));
if (tdbPagerRestore(pPager, jname) < 0) {
tdbCloseDir(&pDir); tdbCloseDir(&pDir);
tdbError("failed to restore file due to %s. jFileName:%s", strerror(errno), name); tdbError("failed to restore file due to %s. jFileName:%s", strerror(errno), name);
...@@ -975,7 +984,12 @@ int tdbPagerRollback(SPager *pPager) { ...@@ -975,7 +984,12 @@ int tdbPagerRollback(SPager *pPager) {
char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry)); char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry));
if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) { if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) {
if (tdbOsRemove(name) < 0 && errno != ENOENT) { char jname[TD_PATH_MAX] = {0};
int dirLen = strlen(pPager->pEnv->dbName);
memcpy(jname, pPager->pEnv->dbName, dirLen);
jname[dirLen] = '/';
memcpy(jname + dirLen + 1, name, strlen(name));
if (tdbOsRemove(jname) < 0 && errno != ENOENT) {
tdbCloseDir(&pDir); tdbCloseDir(&pDir);
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), name); tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), name);
......
...@@ -108,13 +108,13 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF ...@@ -108,13 +108,13 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
ASSERT(pPager != NULL); ASSERT(pPager != NULL);
if (rollback) { if (rollback) {
tdbPagerRollback(pPager);
} else {
ret = tdbPagerRestoreJournals(pPager); ret = tdbPagerRestoreJournals(pPager);
if (ret < 0) { if (ret < 0) {
tdbOsFree(pTb); tdbOsFree(pTb);
return -1; return -1;
} }
} else {
tdbPagerRollback(pPager);
} }
// pTb->pBt // pTb->pBt
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册