Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/ctrip_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,8 @@ void initServerConfig4Test(void) {
}

int clearTestRedisDb() {
// Simply clear the database without logging
// The key is that emptyDbStructure should work correctly with RocksDB
emptyDbStructure(server.db, -1, 0, NULL);
return 1;
}
Expand Down Expand Up @@ -693,7 +695,7 @@ int initTestRedisDb() {
server.db[j].cold_keys = 0;
server.db[j].randomkey_nextseek = NULL;
server.db[j].scan_expire = scanExpireCreate();
// server.db[j].cold_filter = coldFilterCreate();
server.db[j].cold_filter = coldFilterCreate();
server.db[j].expires_cursor = 0;
server.db[j].id = j;
server.db[j].avg_ttl = 0;
Expand All @@ -706,18 +708,26 @@ int initTestRedisDb() {

void createSharedObjects(void);
void createSwapSharedObjects(void);
void swapInit(void);

int initTestRedisServer() {
static int inited;
if (inited) {
clearTestRedisDb();
return;
// Don't clean database - let each test manage its own data
return 1;
}

// Initialize server config first (includes module and ACL init)
initServerConfig4Test();

server.maxmemory_policy = MAXMEMORY_FLAG_LFU;
// if (!server.logfile) server.logfile = zstrdup(CONFIG_DEFAULT_LOGFILE);
swapInitVersion();
createSharedObjects();
initTestRedisDb();

// Call complete swapInit to initialize all swap subsystems
swapInit();

inited = 1;
return 1;
}
Expand All @@ -738,24 +748,24 @@ int swapTest(int argc, char **argv, int accurate) {
result += swapRdbTest(argc, argv, accurate);
result += swapIterTest(argc, argv, accurate);
result += swapDataHashTest(argc, argv, accurate);
// // result += swapDataSetTest(argc, argv, accurate);
result += swapDataSetTest(argc, argv, accurate);
result += swapDataZsetTest(argc, argv, accurate);
result += metaScanTest(argc, argv, accurate);
result += swapExpireTest(argc, argv, accurate);
result += swapUtilTest(argc, argv, accurate);
result += swapPersistTest(argc, argv, accurate);
result += swapFilterTest(argc, argv, accurate);
// // result += swapListMetaTest(argc, argv, accurate);
// // result += swapListDataTest(argc, argv, accurate);
// // result += swapListUtilsTest(argc, argv, accurate);
result += swapListMetaTest(argc, argv, accurate);
result += swapListDataTest(argc, argv, accurate);
result += swapListUtilsTest(argc, argv, accurate);
result += lruCacheTest(argc, argv, accurate);
result += swapAbsentTest(argc, argv, accurate);
result += swapRIOTest(argc, argv, accurate);
result += swapBatchTest(argc, argv, accurate);
result += cuckooFilterTest(argc, argv, accurate);
// // result += roaringBitmapTest(argc, argv, accurate);
result += roaringBitmapTest(argc, argv, accurate);
result += swapRordbTest(argc, argv, accurate);
// // result += swapDataBitmapTest(argc, argv, accurate);
result += swapDataBitmapTest(argc, argv, accurate);
result += wtdigestTest(argc, argv, accurate);
result += swapReplTest(argc, argv, accurate);
return result;
Expand Down
1 change: 0 additions & 1 deletion src/ctrip_swap_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,6 @@ int swapDataHashTest(int argc, char **argv, int accurate) {
swapDataFree(hash1_data, hash1_ctx);
swapDataFree(cold1_data, cold1_ctx);
decrRefCount(key1);
printf("????????????????????????????????? %d\n", key1->refcount);
decrRefCount(cold1);
}

Expand Down
4 changes: 4 additions & 0 deletions src/ctrip_swap_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,10 @@ int swapDataSetTest(int argc, char **argv, int accurate) {
setTypeAdd(set1, f2);
setTypeAdd(set1, f3);
setTypeAdd(set1, f4);
// Balance refcount before dbAdd - createSwapData from previous tests accumulated refcount
while (set1->refcount > 1) {
decrRefCount(set1);
}
dbAdd(db, key1, &set1);

// swap del
Expand Down
24 changes: 22 additions & 2 deletions src/ctrip_swap_zset.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ swapDataType zsetSwapDataType = {
int swapDataSetupZSet(swapData *d, void **pdatactx) {
d->type = &zsetSwapDataType;
d->omtype = &zsetObjectMetaType;
zsetDataCtx *datactx = zmalloc(sizeof(zsetDataCtx));
zsetDataCtx *datactx = zcalloc(sizeof(zsetDataCtx));
datactx->bdc.type = BASE_SWAP_CTX_TYPE_SUBKEY;
datactx->bdc.sub.num = 0;
datactx->bdc.ctx_flag = BIG_DATA_CTX_FLAG_NONE;
Expand Down Expand Up @@ -1564,13 +1564,19 @@ int swapDataZsetTest(int argc, char **argv, int accurate) {
zset1_data = createSwapData(db, key1,zset1,NULL);
swapDataSetupZSet(zset1_data, (void**)&zset1_ctx);

// Initialize keyRequest structures to zero
memset(kr1, 0, sizeof(keyRequest));
memset(cold_kr1, 0, sizeof(keyRequest));

kr1->key = key1;
kr1->level = REQUEST_LEVEL_KEY;
kr1->type = KEYREQUEST_TYPE_KEY;
kr1->b.num_subkeys = 0;
kr1->b.subkeys = NULL;
kr1->dbid = db->id;
cold_kr1->key = key1;
cold_kr1->level = REQUEST_LEVEL_KEY;
cold_kr1->type = KEYREQUEST_TYPE_KEY;
cold_kr1->b.num_subkeys = 0;
cold_kr1->b.subkeys = NULL;
cold_kr1->dbid = db->id;
Expand Down Expand Up @@ -1664,10 +1670,13 @@ int swapDataZsetTest(int argc, char **argv, int accurate) {
zfree(kr1->b.subkeys);
zfree(zset1_ctx->bdc.sub.subkeys);
kr1->b.subkeys = NULL;
kr1->b.num_subkeys = 0;

// swap in with subkeys - subkeys not in mem
kr1->cmd_intention = SWAP_IN;
kr1->cmd_intention_flags = 0;
clearReqSubkeys(kr1);
kr1->b.num_subkeys = 2;
kr1->b.subkeys = mockSubKeys(2, sdsnew("new1"), sdsnew("new2"));
zsetSwapAna(zset1_data,0,kr1,&intention,&intention_flags,zset1_ctx);
test_assert(intention == SWAP_IN && intention_flags == 0);
Expand Down Expand Up @@ -1705,7 +1714,8 @@ int swapDataZsetTest(int argc, char **argv, int accurate) {
decrRefCount(zset1_ctx->bdc.sub.subkeys[i]);
}
zfree(zset1_ctx->bdc.sub.subkeys);
zset1_ctx->bdc.sub.subkeys = NULL;
zset1_ctx->bdc.sub.num = 0; // Reset counter
zset1_ctx->bdc.sub.subkeys = NULL; // Reset pointer
freeObjectMeta(zset1_data->new_meta);

// swap out - data not dirty
Expand All @@ -1724,6 +1734,10 @@ int swapDataZsetTest(int argc, char **argv, int accurate) {
zsetAdd(zset1,2.0,f2,ZADD_IN_NONE,&out_flags,NULL);
zsetAdd(zset1,3.0,f3,ZADD_IN_NONE,&out_flags,NULL);
zsetAdd(zset1,4.0,f4,ZADD_IN_NONE,&out_flags,NULL);
// Balance refcount before dbAdd - createSwapData from previous tests accumulated refcount
while (zset1->refcount > 1) {
decrRefCount(zset1);
}
dbAdd(db, key1, &zset1);

// swap del
Expand Down Expand Up @@ -1759,9 +1773,12 @@ int swapDataZsetTest(int argc, char **argv, int accurate) {
decrRefCount(zset1_ctx->bdc.sub.subkeys[i]);
}
zfree(zset1_ctx->bdc.sub.subkeys);
zset1_ctx->bdc.sub.num = 0; // Reset counter
zset1_ctx->bdc.sub.subkeys = NULL; // Reset pointer

zset1_data->new_meta = NULL;
zset1_data->object_meta = m;
zset1_ctx->bdc.sub.num = 2;
zset1_ctx->bdc.sub.subkeys = mockSubKeys(2, sdsdup(f3), sdsdup(f4));
zsetCleanObject(zset1_data, zset1_ctx, 0);
zsetSwapOut(zset1_data, zset1_ctx, 0, NULL);
Expand All @@ -1772,6 +1789,8 @@ int swapDataZsetTest(int argc, char **argv, int accurate) {
decrRefCount(zset1_ctx->bdc.sub.subkeys[i]);
}
zfree(zset1_ctx->bdc.sub.subkeys);
zset1_ctx->bdc.sub.num = 0; // Reset counter
zset1_ctx->bdc.sub.subkeys = NULL; // Reset pointer

/* cold => warm => hot */
decoded = createZsetObject();
Expand Down Expand Up @@ -1828,6 +1847,7 @@ int swapDataZsetTest(int argc, char **argv, int accurate) {
test_assert(zsetLength(s) == 4);

freeZsetSwapData(zset1_data, zset1_ctx);
// Don't decrRefCount here - zset1 is still needed by next test
}

TEST("zset - rdbLoad & rdbSave") {
Expand Down
Loading