fix tq invalid free
This commit is contained in:
parent
9edc17e575
commit
5ebc77961d
|
@ -92,6 +92,8 @@ int32_t tqStoreClose(TqMetaStore*);
|
|||
//int32_t tqStoreDelete(TqMetaStore*);
|
||||
//int32_t TqStoreCommitAll(TqMetaStore*);
|
||||
int32_t tqStorePersist(TqMetaStore*);
|
||||
//clean deleted idx and data from persistent file
|
||||
int32_t tqStoreCompact(TqMetaStore*);
|
||||
|
||||
void* tqHandleGet(TqMetaStore*, int64_t key);
|
||||
int32_t tqHandleMovePut(TqMetaStore*, int64_t key, void* value);
|
||||
|
|
|
@ -153,9 +153,9 @@ TqMetaStore* tqStoreOpen(const char* path,
|
|||
} else {
|
||||
pNode->handle.valueInUse = TQ_DELETE_TOKEN;
|
||||
}
|
||||
serializedObj = POINTER_SHIFT(serializedObj, serializedObj->ssize);
|
||||
if(serializedObj->ssize != sizeof(TqSerializedHead)) {
|
||||
pMeta->deserializer(serializedObj, &pNode->handle.valueInTxn);
|
||||
TqSerializedHead* ptr = POINTER_SHIFT(serializedObj, serializedObj->ssize);
|
||||
if(ptr->ssize != sizeof(TqSerializedHead)) {
|
||||
pMeta->deserializer(ptr, &pNode->handle.valueInTxn);
|
||||
} else {
|
||||
pNode->handle.valueInTxn = TQ_DELETE_TOKEN;
|
||||
}
|
||||
|
@ -591,3 +591,8 @@ int32_t tqHandleClear(TqMetaStore* pMeta, int64_t key) {
|
|||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
//TODO: clean deleted idx and data from persistent file
|
||||
int32_t tqStoreCompact(TqMetaStore *pMeta) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,10 @@ TEST_F(TqMetaTest, copyPutTest) {
|
|||
|
||||
Foo* pFoo = (Foo*) tqHandleGet(pMeta, 1);
|
||||
EXPECT_EQ(pFoo == NULL, true);
|
||||
|
||||
tqHandleCommit(pMeta, 1);
|
||||
pFoo = (Foo*) tqHandleGet(pMeta, 1);
|
||||
EXPECT_EQ(pFoo->a, 3);
|
||||
}
|
||||
|
||||
TEST_F(TqMetaTest, persistTest) {
|
||||
|
@ -135,6 +139,42 @@ TEST_F(TqMetaTest, deleteTest) {
|
|||
pMeta = tqStoreOpen(pathName,
|
||||
FooSerializer, FooDeserializer, FooDeleter);
|
||||
ASSERT(pMeta);
|
||||
|
||||
pFoo = (Foo*) tqHandleGet(pMeta, 1);
|
||||
EXPECT_EQ(pFoo == NULL, true);
|
||||
}
|
||||
|
||||
TEST_F(TqMetaTest, intxnPersist) {
|
||||
Foo* pFoo = (Foo*)malloc(sizeof(Foo));
|
||||
pFoo->a = 3;
|
||||
tqHandleMovePut(pMeta, 1, pFoo);
|
||||
tqHandleCommit(pMeta, 1);
|
||||
|
||||
Foo* pBar = (Foo*)malloc(sizeof(Foo));
|
||||
pBar->a = 4;
|
||||
tqHandleMovePut(pMeta, 1, pBar);
|
||||
|
||||
Foo* pFoo1 = (Foo*)tqHandleGet(pMeta, 1);
|
||||
EXPECT_EQ(pFoo1->a, 3);
|
||||
|
||||
tqStoreClose(pMeta);
|
||||
pMeta = tqStoreOpen(pathName,
|
||||
FooSerializer, FooDeserializer, FooDeleter);
|
||||
ASSERT(pMeta);
|
||||
|
||||
pFoo1 = (Foo*)tqHandleGet(pMeta, 1);
|
||||
EXPECT_EQ(pFoo1->a, 3);
|
||||
|
||||
tqHandleCommit(pMeta, 1);
|
||||
|
||||
pFoo1 = (Foo*)tqHandleGet(pMeta, 1);
|
||||
EXPECT_EQ(pFoo1->a, 4);
|
||||
|
||||
tqStoreClose(pMeta);
|
||||
pMeta = tqStoreOpen(pathName,
|
||||
FooSerializer, FooDeserializer, FooDeleter);
|
||||
ASSERT(pMeta);
|
||||
|
||||
pFoo1 = (Foo*)tqHandleGet(pMeta, 1);
|
||||
EXPECT_EQ(pFoo1->a, 4);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue