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

test: add unitest for sdb

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