提交 02400c15 编写于 作者: S Shengliang Guan

test: add unitest for sdb

上级 a13cb870
...@@ -343,6 +343,8 @@ int32_t strDefault(SMnode *pMnode) { ...@@ -343,6 +343,8 @@ int32_t strDefault(SMnode *pMnode) {
pRaw = strEncode(&strObj); pRaw = strEncode(&strObj);
sdbSetRawStatus(pRaw, SDB_STATUS_READY); sdbSetRawStatus(pRaw, SDB_STATUS_READY);
if (sdbWriteWithoutFree(pMnode->pSdb, pRaw) != 0) return -1; if (sdbWriteWithoutFree(pMnode->pSdb, pRaw) != 0) return -1;
EXPECT_EQ(sdbGetRawTotalSize(pRaw), 79);
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
return 0; return 0;
...@@ -386,36 +388,36 @@ TEST_F(MndTestSdb, 01_Write_Str) { ...@@ -386,36 +388,36 @@ TEST_F(MndTestSdb, 01_Write_Str) {
opt.path = "/tmp/mnode_test_sdb"; opt.path = "/tmp/mnode_test_sdb";
taosRemoveDir(opt.path); taosRemoveDir(opt.path);
SSdbTable strTable1 = { SSdbTable strTable1;
.sdbType = SDB_USER, memset(&strTable1, 0, sizeof(SSdbTable));
.keyType = SDB_KEY_BINARY, strTable1.sdbType = SDB_USER;
.deployFp = (SdbDeployFp)strDefault, strTable1.keyType = SDB_KEY_BINARY;
.encodeFp = (SdbEncodeFp)strEncode, strTable1.deployFp = (SdbDeployFp)strDefault;
.decodeFp = (SdbDecodeFp)strDecode, strTable1.encodeFp = (SdbEncodeFp)strEncode;
.insertFp = (SdbInsertFp)strInsert, strTable1.decodeFp = (SdbDecodeFp)strDecode;
.updateFp = (SdbUpdateFp)strUpdate, strTable1.insertFp = (SdbInsertFp)strInsert;
.deleteFp = (SdbDeleteFp)strDelete, strTable1.updateFp = (SdbUpdateFp)strUpdate;
}; strTable1.deleteFp = (SdbDeleteFp)strDelete;
SSdbTable strTable2 = { SSdbTable strTable2;
.sdbType = SDB_VGROUP, memset(&strTable2, 0, sizeof(SSdbTable));
.keyType = SDB_KEY_INT32, strTable2.sdbType = SDB_VGROUP;
.encodeFp = (SdbEncodeFp)i32Encode, strTable2.keyType = SDB_KEY_INT32;
.decodeFp = (SdbDecodeFp)i32Decode, strTable2.encodeFp = (SdbEncodeFp)i32Encode;
.insertFp = (SdbInsertFp)i32Insert, strTable2.decodeFp = (SdbDecodeFp)i32Decode;
.updateFp = (SdbUpdateFp)i32Update, strTable2.insertFp = (SdbInsertFp)i32Insert;
.deleteFp = (SdbDeleteFp)i32Delete, strTable2.updateFp = (SdbUpdateFp)i32Update;
}; strTable2.deleteFp = (SdbDeleteFp)i32Delete;
SSdbTable strTable3 = { SSdbTable strTable3;
.sdbType = SDB_CONSUMER, memset(&strTable3, 0, sizeof(SSdbTable));
.keyType = SDB_KEY_INT64, strTable3.sdbType = SDB_CONSUMER;
.encodeFp = (SdbEncodeFp)i64Encode, strTable3.keyType = SDB_KEY_INT64;
.decodeFp = (SdbDecodeFp)i64Decode, strTable3.encodeFp = (SdbEncodeFp)i64Encode;
.insertFp = (SdbInsertFp)i64Insert, strTable3.decodeFp = (SdbDecodeFp)i64Decode;
.updateFp = (SdbUpdateFp)i64Update, strTable3.insertFp = (SdbInsertFp)i64Insert;
.deleteFp = (SdbDeleteFp)i64Delete, strTable3.updateFp = (SdbUpdateFp)i64Update;
}; strTable3.deleteFp = (SdbDeleteFp)i64Delete;
pSdb = sdbInit(&opt); pSdb = sdbInit(&opt);
mnode.pSdb = pSdb; mnode.pSdb = pSdb;
...@@ -730,36 +732,36 @@ TEST_F(MndTestSdb, 01_Read_Str) { ...@@ -730,36 +732,36 @@ TEST_F(MndTestSdb, 01_Read_Str) {
opt.pMnode = &mnode; opt.pMnode = &mnode;
opt.path = "/tmp/mnode_test_sdb"; opt.path = "/tmp/mnode_test_sdb";
SSdbTable strTable1 = { SSdbTable strTable1;
.sdbType = SDB_USER, memset(&strTable1, 0, sizeof(SSdbTable));
.keyType = SDB_KEY_BINARY, strTable1.sdbType = SDB_USER;
.deployFp = (SdbDeployFp)strDefault, strTable1.keyType = SDB_KEY_BINARY;
.encodeFp = (SdbEncodeFp)strEncode, strTable1.deployFp = (SdbDeployFp)strDefault;
.decodeFp = (SdbDecodeFp)strDecode, strTable1.encodeFp = (SdbEncodeFp)strEncode;
.insertFp = (SdbInsertFp)strInsert, strTable1.decodeFp = (SdbDecodeFp)strDecode;
.updateFp = (SdbUpdateFp)strUpdate, strTable1.insertFp = (SdbInsertFp)strInsert;
.deleteFp = (SdbDeleteFp)strDelete, strTable1.updateFp = (SdbUpdateFp)strUpdate;
}; strTable1.deleteFp = (SdbDeleteFp)strDelete;
SSdbTable strTable2 = { SSdbTable strTable2;
.sdbType = SDB_VGROUP, memset(&strTable2, 0, sizeof(SSdbTable));
.keyType = SDB_KEY_INT32, strTable2.sdbType = SDB_VGROUP;
.encodeFp = (SdbEncodeFp)i32Encode, strTable2.keyType = SDB_KEY_INT32;
.decodeFp = (SdbDecodeFp)i32Decode, strTable2.encodeFp = (SdbEncodeFp)i32Encode;
.insertFp = (SdbInsertFp)i32Insert, strTable2.decodeFp = (SdbDecodeFp)i32Decode;
.updateFp = (SdbUpdateFp)i32Update, strTable2.insertFp = (SdbInsertFp)i32Insert;
.deleteFp = (SdbDeleteFp)i32Delete, strTable2.updateFp = (SdbUpdateFp)i32Update;
}; strTable2.deleteFp = (SdbDeleteFp)i32Delete;
SSdbTable strTable3 = { SSdbTable strTable3;
.sdbType = SDB_CONSUMER, memset(&strTable3, 0, sizeof(SSdbTable));
.keyType = SDB_KEY_INT64, strTable3.sdbType = SDB_CONSUMER;
.encodeFp = (SdbEncodeFp)i64Encode, strTable3.keyType = SDB_KEY_INT64;
.decodeFp = (SdbDecodeFp)i64Decode, strTable3.encodeFp = (SdbEncodeFp)i64Encode;
.insertFp = (SdbInsertFp)i64Insert, strTable3.decodeFp = (SdbDecodeFp)i64Decode;
.updateFp = (SdbUpdateFp)i64Update, strTable3.insertFp = (SdbInsertFp)i64Insert;
.deleteFp = (SdbDeleteFp)i64Delete, strTable3.updateFp = (SdbUpdateFp)i64Update;
}; strTable3.deleteFp = (SdbDeleteFp)i64Delete;
pSdb = sdbInit(&opt); pSdb = sdbInit(&opt);
mnode.pSdb = pSdb; mnode.pSdb = pSdb;
......
...@@ -31,8 +31,6 @@ extern "C" { ...@@ -31,8 +31,6 @@ extern "C" {
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }} #define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }} #define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }}
#define SDB_MAX_SIZE (32 * 1024)
typedef struct SSdbRaw { typedef struct SSdbRaw {
int8_t type; int8_t type;
int8_t status; int8_t status;
......
...@@ -28,12 +28,12 @@ SSdb *sdbInit(SSdbOpt *pOption) { ...@@ -28,12 +28,12 @@ SSdb *sdbInit(SSdbOpt *pOption) {
return NULL; return NULL;
} }
char path[PATH_MAX + 100]; char path[PATH_MAX + 100] = {0};
snprintf(path, PATH_MAX + 100, "%s%sdata", pOption->path, TD_DIRSEP); snprintf(path, sizeof(path), "%s%sdata", pOption->path, TD_DIRSEP);
pSdb->currDir = strdup(path); pSdb->currDir = strdup(path);
snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP); snprintf(path, sizeof(path), "%s%ssync", pOption->path, TD_DIRSEP);
pSdb->syncDir = strdup(path); pSdb->syncDir = strdup(path);
snprintf(path, PATH_MAX + 100, "%s%stmp", pOption->path, TD_DIRSEP); snprintf(path, sizeof(path), "%s%stmp", pOption->path, TD_DIRSEP);
pSdb->tmpDir = strdup(path); pSdb->tmpDir = strdup(path);
if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) { if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) {
sdbCleanup(pSdb); sdbCleanup(pSdb);
......
...@@ -66,7 +66,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { ...@@ -66,7 +66,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
} }
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
int64_t ver = -1; int64_t ver = 0;
ret = taosReadFile(pFile, &ver, sizeof(int64_t)); ret = taosReadFile(pFile, &ver, sizeof(int64_t));
if (ret < 0) { if (ret < 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
...@@ -209,7 +209,7 @@ int32_t sdbReadFile(SSdb *pSdb) { ...@@ -209,7 +209,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
code = sdbWriteWithoutFree(pSdb, pRaw); code = sdbWriteWithoutFree(pSdb, pRaw);
if (code != 0) { if (code != 0) {
mError("failed to read file:%s since %s", file, terrstr()); mError("failed to read file:%s since %s", file, terrstr());
goto PARSE_SDB_DATA_ERROR; goto _OVER;
} }
} }
...@@ -218,7 +218,7 @@ int32_t sdbReadFile(SSdb *pSdb) { ...@@ -218,7 +218,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
memcpy(pSdb->tableVer, tableVer, sizeof(tableVer)); memcpy(pSdb->tableVer, tableVer, sizeof(tableVer));
mDebug("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); mDebug("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer);
PARSE_SDB_DATA_ERROR: _OVER:
taosCloseFile(&pFile); taosCloseFile(&pFile);
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册