Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9b5b74b8
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b5b74b8
编写于
3月 02, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-13039] fix bug and memory leak in the unit test.
上级
1bb95873
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
384 addition
and
367 deletion
+384
-367
include/util/tcache.h
include/util/tcache.h
+3
-49
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-1
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+9
-16
source/libs/executor/test/executorTests.cpp
source/libs/executor/test/executorTests.cpp
+5
-1
source/util/src/tcache.c
source/util/src/tcache.c
+270
-178
source/util/src/thash.c
source/util/src/thash.c
+10
-55
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+11
-7
source/util/test/arrayTest.cpp
source/util/test/arrayTest.cpp
+5
-0
source/util/test/encodeTest.cpp
source/util/test/encodeTest.cpp
+4
-4
source/util/test/hashTest.cpp
source/util/test/hashTest.cpp
+7
-2
source/util/test/pageBufferTest.cpp
source/util/test/pageBufferTest.cpp
+59
-54
未找到文件。
include/util/tcache.h
浏览文件 @
9b5b74b8
...
...
@@ -40,55 +40,9 @@ typedef struct SCacheStatis {
int64_t
refreshCount
;
}
SCacheStatis
;
struct
STrashElem
;
typedef
struct
SCacheDataNode
{
uint64_t
addedTime
;
// the added time when this element is added or updated into cache
uint64_t
lifespan
;
// life duration when this element should be remove from cache
uint64_t
expireTime
;
// expire time
uint64_t
signature
;
struct
STrashElem
*
pTNodeHeader
;
// point to trash node head
uint16_t
keySize
:
15
;
// max key size: 32kb
bool
inTrashcan
:
1
;
// denote if it is in trash or not
uint32_t
size
;
// allocated size for current SCacheDataNode
T_REF_DECLARE
()
char
*
key
;
char
data
[];
}
SCacheDataNode
;
typedef
struct
STrashElem
{
struct
STrashElem
*
prev
;
struct
STrashElem
*
next
;
SCacheDataNode
*
pData
;
}
STrashElem
;
typedef
struct
SCacheObj
SCacheObj
;
/*
* to accommodate the old data which has the same key value of new one in hashList
* when an new node is put into cache, if an existed one with the same key:
* 1. if the old one does not be referenced, update it.
* 2. otherwise, move the old one to pTrash, addedTime the new one.
*
* when the node in pTrash does not be referenced, it will be release at the expired expiredTime
*/
typedef
struct
{
int64_t
totalSize
;
// total allocated buffer in this hash table, SCacheObj is not included.
int64_t
refreshTime
;
STrashElem
*
pTrash
;
char
*
name
;
SCacheStatis
statistics
;
SHashObj
*
pHashTable
;
__cache_free_fn_t
freeFp
;
uint32_t
numOfElemsInTrash
;
// number of element in trash
uint8_t
deleting
;
// set the deleting flag to stop refreshing ASAP.
pthread_t
refreshWorker
;
bool
extendLifespan
;
// auto extend life span when one item is accessed.
int64_t
checkTick
;
// tick used to record the check times of the refresh threads
#if defined(LINUX)
pthread_rwlock_t
lock
;
#else
pthread_mutex_t
lock
;
#endif
}
SCacheObj
;
struct
STrashElem
;
/**
* initialize the cache object
...
...
@@ -141,7 +95,7 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data);
* @param data
* @return
*/
void
*
taosCacheTransfer
(
SCacheObj
*
pCacheObj
,
void
**
data
);
void
*
taosCacheTransfer
Data
(
SCacheObj
*
pCacheObj
,
void
**
data
);
/**
* remove data in cache, the data will not be removed immediately.
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
9b5b74b8
...
...
@@ -615,7 +615,7 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray
SOperatorInfo
*
createProjectOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createLimitOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
);
SOperatorInfo
*
createIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
S
Interval
*
pInterval
,
S
ExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
);
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
9b5b74b8
...
...
@@ -6224,7 +6224,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
);
updateOutputBuf
(
&
pProjectInfo
->
binfo
,
&
pProjectInfo
->
bufC
apacity
,
pBlock
->
info
.
rows
);
updateOutputBuf
(
pInfo
,
&
pInfo
->
c
apacity
,
pBlock
->
info
.
rows
);
projectApplyFunctions
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
...
...
@@ -6274,7 +6274,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
// the pDataBlock are always the same one, no need to call this again
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
);
updateOutputBuf
(
&
pProjectInfo
->
binfo
,
&
pProjectInfo
->
bufC
apacity
,
pBlock
->
info
.
rows
);
updateOutputBuf
(
pInfo
,
&
pInfo
->
c
apacity
,
pBlock
->
info
.
rows
);
projectApplyFunctions
(
pRuntimeEnv
,
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
pRes
->
info
.
rows
=
getNumOfResult
(
pInfo
->
pCtx
,
pOperator
->
numOfOutput
);
...
...
@@ -7273,24 +7273,18 @@ SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorIn
return
pOperator
;
}
SOperatorInfo
*
createIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
SOperatorInfo
*
createIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SArray
*
pExprInfo
,
S
Interval
*
pInterval
,
S
ExecTaskInfo
*
pTaskInfo
)
{
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
initAggSup
(
&
pInfo
->
aggSup
,
pExprInfo
);
// todo:
pInfo
->
order
=
TSDB_ORDER_ASC
;
pInfo
->
precision
=
TSDB_TIME_PRECISION_MICRO
;
pInfo
->
win
.
skey
=
INT64_MIN
;
pInfo
->
win
.
ekey
=
INT64_MAX
;
pInfo
->
interval
.
intervalUnit
=
's'
;
pInfo
->
interval
.
slidingUnit
=
's'
;
pInfo
->
interval
.
interval
=
1000
;
pInfo
->
interval
.
sliding
=
1000
;
pInfo
->
win
=
pTaskInfo
->
window
;
pInfo
->
interval
=
*
pInterval
;
int32_t
code
=
createDiskbasedBuf
(
&
pInfo
->
pResultBuf
,
4096
,
4096
*
256
,
0
,
"/tmp/"
);
int32_t
code
=
createDiskbasedBuf
(
&
pInfo
->
pResultBuf
,
4096
,
4096
*
256
,
pTaskInfo
->
id
.
str
,
"/tmp/"
);
int32_t
numOfOutput
=
taosArrayGetSize
(
pExprInfo
);
pInfo
->
binfo
.
pCtx
=
createSqlFunctionCtx_rv
(
pExprInfo
,
&
pInfo
->
binfo
.
rowCellInfoOffset
,
&
pInfo
->
binfo
.
resRowSize
);
pInfo
->
binfo
.
pRes
=
createOutputBuf_rv
(
pExprInfo
,
pInfo
->
binfo
.
capacity
);
...
...
@@ -7305,16 +7299,15 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pEx
pOperator
->
pExpr
=
exprArrayDup
(
pExprInfo
);
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
numOfOutput
=
numOfOutput
;
pOperator
->
numOfOutput
=
taosArrayGetSize
(
pExprInfo
)
;
pOperator
->
info
=
pInfo
;
pOperator
->
nextDataFn
=
doIntervalAgg
;
pOperator
->
closeFn
=
destroyBasicOperatorInfo
;
pOperator
->
nextDataFn
=
doIntervalAgg
;
pOperator
->
closeFn
=
destroyBasicOperatorInfo
;
code
=
appendDownstream
(
pOperator
,
&
downstream
,
1
);
return
pOperator
;
}
SOperatorInfo
*
createAllTimeIntervalOperatorInfo
(
STaskRuntimeEnv
*
pRuntimeEnv
,
SOperatorInfo
*
downstream
,
SExprInfo
*
pExpr
,
int32_t
numOfOutput
)
{
STableIntervalOperatorInfo
*
pInfo
=
calloc
(
1
,
sizeof
(
STableIntervalOperatorInfo
));
...
...
source/libs/executor/test/executorTests.cpp
浏览文件 @
9b5b74b8
...
...
@@ -548,7 +548,11 @@ TEST(testCase, time_interval_Operator_Test) {
SOperatorInfo
*
p
=
createDummyOperator
(
1
,
1
,
2000
,
data_asc
,
2
);
SExecTaskInfo
ti
=
{
0
};
SOperatorInfo
*
pOperator
=
createIntervalOperatorInfo
(
p
,
pExprInfo
,
&
ti
);
SInterval
interval
=
{
0
};
interval
.
sliding
=
interval
.
interval
=
1000
;
interval
.
slidingUnit
=
interval
.
intervalUnit
=
'a'
;
SOperatorInfo
*
pOperator
=
createIntervalOperatorInfo
(
p
,
pExprInfo
,
&
interval
,
&
ti
);
bool
newgroup
=
false
;
SSDataBlock
*
pRes
=
NULL
;
...
...
source/util/src/tcache.c
浏览文件 @
9b5b74b8
此差异已折叠。
点击以展开。
source/util/src/thash.c
浏览文件 @
9b5b74b8
...
...
@@ -21,7 +21,6 @@
// the add ref count operation may trigger the warning if the reference count is greater than the MAX_WARNING_REF_COUNT
#define MAX_WARNING_REF_COUNT 10000
#define EXT_SIZE 1024
#define HASH_MAX_CAPACITY (1024 * 1024 * 16)
#define HASH_DEFAULT_LOAD_FACTOR (0.75)
#define HASH_INDEX(v, c) ((v) & ((c)-1))
...
...
@@ -211,14 +210,14 @@ static void pushfrontNodeInEntryList(SHashEntry *pEntry, SHashNode *pNode);
static
FORCE_INLINE
bool
taosHashTableEmpty
(
const
SHashObj
*
pHashObj
);
/**
* initialize a hash table
*
* @param capacity initial capacity of the hash table
* @param fn hash function
* @param update whether the hash table allows in place update
* @param type whether the hash table has per entry lock
* @return hash table object
* @param pHashObj
* @return
*/
static
FORCE_INLINE
bool
taosHashTableEmpty
(
const
SHashObj
*
pHashObj
)
{
return
taosHashGetSize
(
pHashObj
)
==
0
;
}
SHashObj
*
taosHashInit
(
size_t
capacity
,
_hash_fn_t
fn
,
bool
update
,
SHashLockTypeE
type
)
{
if
(
fn
==
NULL
)
{
assert
(
0
);
...
...
@@ -296,10 +295,6 @@ int32_t taosHashGetSize(const SHashObj *pHashObj) {
return
(
int32_t
)
atomic_load_64
(
&
pHashObj
->
size
);
}
static
FORCE_INLINE
bool
taosHashTableEmpty
(
const
SHashObj
*
pHashObj
)
{
return
taosHashGetSize
(
pHashObj
)
==
0
;
}
int32_t
taosHashPut
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
data
,
size_t
size
)
{
if
(
pHashObj
==
NULL
||
key
==
NULL
||
keyLen
==
0
)
{
return
-
1
;
...
...
@@ -318,6 +313,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
taosHashWUnlock
(
pHashObj
);
}
// disable resize
taosHashRLock
(
pHashObj
);
int32_t
slot
=
HASH_INDEX
(
hashVal
,
pHashObj
->
capacity
);
...
...
@@ -326,11 +322,13 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
taosHashEntryWLock
(
pHashObj
,
pe
);
SHashNode
*
pNode
=
pe
->
next
;
#if 0
if (pe->num > 0) {
assert(pNode != NULL);
} else {
assert(pNode == NULL);
}
#endif
SHashNode
*
prev
=
NULL
;
while
(
pNode
)
{
...
...
@@ -369,7 +367,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
// enable resize
taosHashRUnlock
(
pHashObj
);
return
pHashObj
->
enableUpdate
?
0
:
-
1
;
}
}
...
...
@@ -532,49 +529,6 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) {
return
taosHashRemoveWithData
(
pHashObj
,
key
,
keyLen
,
NULL
,
0
);
}
void
taosHashCondTraverse
(
SHashObj
*
pHashObj
,
bool
(
*
fp
)(
void
*
,
void
*
),
void
*
param
)
{
if
(
pHashObj
==
NULL
||
taosHashTableEmpty
(
pHashObj
)
||
fp
==
NULL
)
{
return
;
}
// disable the resize process
taosHashRLock
(
pHashObj
);
int32_t
numOfEntries
=
(
int32_t
)
pHashObj
->
capacity
;
for
(
int32_t
i
=
0
;
i
<
numOfEntries
;
++
i
)
{
SHashEntry
*
pEntry
=
pHashObj
->
hashList
[
i
];
if
(
pEntry
->
num
==
0
)
{
continue
;
}
taosHashEntryWLock
(
pHashObj
,
pEntry
);
SHashNode
*
pPrevNode
=
NULL
;
SHashNode
*
pNode
=
pEntry
->
next
;
while
(
pNode
!=
NULL
)
{
if
(
fp
(
param
,
GET_HASH_NODE_DATA
(
pNode
)))
{
pPrevNode
=
pNode
;
pNode
=
pNode
->
next
;
}
else
{
if
(
pPrevNode
==
NULL
)
{
pEntry
->
next
=
pNode
->
next
;
}
else
{
pPrevNode
->
next
=
pNode
->
next
;
}
pEntry
->
num
-=
1
;
atomic_sub_fetch_64
(
&
pHashObj
->
size
,
1
);
SHashNode
*
next
=
pNode
->
next
;
FREE_HASH_NODE
(
pNode
);
pNode
=
next
;
}
}
taosHashEntryWUnlock
(
pHashObj
,
pEntry
);
}
taosHashRUnlock
(
pHashObj
);
}
void
taosHashClear
(
SHashObj
*
pHashObj
)
{
if
(
pHashObj
==
NULL
)
{
return
;
...
...
@@ -897,6 +851,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) {
taosHashRUnlock
(
pHashObj
);
}
//TODO remove it
void
*
taosHashAcquire
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
)
{
void
*
p
=
NULL
;
return
taosHashGetImpl
(
pHashObj
,
key
,
keyLen
,
&
p
,
0
,
true
);
...
...
source/util/src/tpagedbuf.c
浏览文件 @
9b5b74b8
...
...
@@ -269,11 +269,12 @@ static SPageInfo* registerPage(SDiskbasedBuf* pBuf, int32_t groupId, int32_t pag
SPageInfo
*
ppi
=
malloc
(
sizeof
(
SPageInfo
));
ppi
->
pageId
=
pageId
;
ppi
->
pData
=
NULL
;
ppi
->
pData
=
NULL
;
ppi
->
offset
=
-
1
;
ppi
->
length
=
-
1
;
ppi
->
used
=
true
;
ppi
->
pn
=
NULL
;
ppi
->
used
=
true
;
ppi
->
pn
=
NULL
;
ppi
->
dirty
=
false
;
return
*
(
SPageInfo
**
)
taosArrayPush
(
list
,
&
ppi
);
}
...
...
@@ -471,7 +472,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
}
else
{
// not in memory
assert
((
*
pi
)
->
pData
==
NULL
&&
(
*
pi
)
->
pn
==
NULL
&&
(
*
pi
)
->
length
>=
0
&&
(
*
pi
)
->
offset
>=
0
);
assert
((
*
pi
)
->
pData
==
NULL
&&
(
*
pi
)
->
pn
==
NULL
&&
(
((
*
pi
)
->
length
>=
0
&&
(
*
pi
)
->
offset
>=
0
)
||
((
*
pi
)
->
length
==
-
1
&&
(
*
pi
)
->
offset
==
-
1
))
);
char
*
availablePage
=
NULL
;
if
(
NO_IN_MEM_AVAILABLE_PAGES
(
pBuf
))
{
...
...
@@ -493,9 +494,12 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
lruListPushFront
(
pBuf
->
lruList
,
*
pi
);
(
*
pi
)
->
used
=
true
;
int32_t
code
=
loadPageFromDisk
(
pBuf
,
*
pi
);
if
(
code
!=
0
)
{
return
NULL
;
// some data has been flushed to disk, and needs to be loaded into buffer again.
if
((
*
pi
)
->
length
>
0
&&
(
*
pi
)
->
offset
>=
0
)
{
int32_t
code
=
loadPageFromDisk
(
pBuf
,
*
pi
);
if
(
code
!=
0
)
{
return
NULL
;
}
}
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
...
...
source/util/test/arrayTest.cpp
浏览文件 @
9b5b74b8
...
...
@@ -43,6 +43,9 @@ static void remove_batch_test() {
taosArrayPush
(
delList
,
&
a
);
taosArrayRemoveBatch
(
pa
,
(
const
int32_t
*
)
TARRAY_GET_START
(
delList
),
taosArrayGetSize
(
delList
));
EXPECT_EQ
(
taosArrayGetSize
(
pa
),
17
);
taosArrayDestroy
(
pa
);
taosArrayDestroy
(
delList
);
}
}
// namespace
...
...
@@ -79,4 +82,6 @@ TEST(arrayTest, array_search_test) {
}
}
taosArrayDestroy
(
pa
);
}
source/util/test/encodeTest.cpp
浏览文件 @
9b5b74b8
...
...
@@ -201,8 +201,8 @@ TEST(td_encode_test, encode_decode_cstr) {
}
}
delete
buf
;
delete
cstr
;
delete
[]
buf
;
delete
[]
cstr
;
}
typedef
struct
{
...
...
@@ -354,7 +354,7 @@ static int32_t tSFinalReq_v2_decode(SCoder *pCoder, SFinalReq_v2 *ps2) {
tEndDecode
(
pCoder
);
return
0
;
}
#if 0
TEST(td_encode_test, compound_struct_encode_test) {
SCoder encoder, decoder;
uint8_t * buf1;
...
...
@@ -436,5 +436,5 @@ TEST(td_encode_test, compound_struct_encode_test) {
GTEST_ASSERT_EQ(dreq21.v_b, req2.v_b);
tCoderClear(&decoder);
}
#endif
#pragma GCC diagnostic pop
\ No newline at end of file
source/util/test/hashTest.cpp
浏览文件 @
9b5b74b8
...
...
@@ -106,7 +106,7 @@ void noLockPerformanceTest() {
ASSERT_EQ
(
taosHashGetSize
(
hashTable
),
0
);
char
key
[
128
]
=
{
0
};
int32_t
num
=
5000
000
;
int32_t
num
=
5000
;
int64_t
st
=
taosGetTimestampUs
();
...
...
@@ -186,10 +186,15 @@ void acquireRleaseTest() {
printf
(
"%s,expect:%s"
,
pdata
->
p
,
str3
);
ASSERT_TRUE
(
strcmp
(
pdata
->
p
,
str3
)
==
0
);
tfree
(
pdata
->
p
);
taosHashRelease
(
hashTable
,
pdata
);
num
=
taosHashGetSize
(
hashTable
);
ASSERT_EQ
(
num
,
1
);
taosHashCleanup
(
hashTable
);
tfree
(
data
.
p
);
}
}
...
...
source/util/test/pageBufferTest.cpp
浏览文件 @
9b5b74b8
...
...
@@ -12,145 +12,150 @@
namespace
{
// simple test
void
simpleTest
()
{
SDiskbasedBuf
*
p
Result
Buf
=
NULL
;
int32_t
ret
=
createDiskbasedBuf
(
&
p
Result
Buf
,
1024
,
4096
,
""
,
"/tmp/"
);
SDiskbasedBuf
*
pBuf
=
NULL
;
int32_t
ret
=
createDiskbasedBuf
(
&
pBuf
,
1024
,
4096
,
""
,
"/tmp/"
);
int32_t
pageId
=
0
;
int32_t
groupId
=
0
;
SFilePage
*
pBufPage
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
pBufPage
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
ASSERT_TRUE
(
pBufPage
!=
NULL
);
ASSERT_EQ
(
getTotalBufSize
(
p
Result
Buf
),
1024
);
ASSERT_EQ
(
getTotalBufSize
(
pBuf
),
1024
);
SIDList
list
=
getDataBufPagesIdList
(
p
Result
Buf
,
groupId
);
SIDList
list
=
getDataBufPagesIdList
(
pBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
list
),
1
);
ASSERT_EQ
(
getNumOfBufGroupId
(
p
Result
Buf
),
1
);
ASSERT_EQ
(
getNumOfBufGroupId
(
pBuf
),
1
);
releaseBufPage
(
p
Result
Buf
,
pBufPage
);
releaseBufPage
(
pBuf
,
pBufPage
);
SFilePage
*
pBufPage1
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
pBufPage1
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
t
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t
==
pBufPage1
);
SFilePage
*
pBufPage2
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage2
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t1
==
pBufPage2
);
SFilePage
*
pBufPage3
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t2
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage3
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t2
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t2
==
pBufPage3
);
SFilePage
*
pBufPage4
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t3
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage4
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t3
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t3
==
pBufPage4
);
SFilePage
*
pBufPage5
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pResultBuf
,
groupId
,
&
pageId
));
SFilePage
*
t4
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pResultBuf
,
pageId
));
releaseBufPage
(
pBuf
,
pBufPage2
);
SFilePage
*
pBufPage5
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t4
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t4
==
pBufPage5
);
destroyDiskbasedBuf
(
p
Result
Buf
);
destroyDiskbasedBuf
(
pBuf
);
}
void
writeDownTest
()
{
SDiskbasedBuf
*
p
Result
Buf
=
NULL
;
int32_t
ret
=
createDiskbasedBuf
(
&
p
Result
Buf
,
1024
,
4
*
1024
,
"1"
,
"/tmp/"
);
SDiskbasedBuf
*
pBuf
=
NULL
;
int32_t
ret
=
createDiskbasedBuf
(
&
pBuf
,
1024
,
4
*
1024
,
"1"
,
"/tmp/"
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
int32_t
groupId
=
0
;
int32_t
nx
=
12345
;
SFilePage
*
pBufPage
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
pBufPage
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
ASSERT_TRUE
(
pBufPage
!=
NULL
);
*
(
int32_t
*
)(
pBufPage
->
data
)
=
nx
;
writePageId
=
pageId
;
releaseBufPage
(
pResultBuf
,
pBufPage
);
setBufPageDirty
(
pBufPage
,
true
);
releaseBufPage
(
pBuf
,
pBufPage
);
SFilePage
*
pBufPage1
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage1
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
SFilePage
*
pBufPage2
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t2
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage2
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t2
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
SFilePage
*
pBufPage3
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t3
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage3
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t3
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
SFilePage
*
pBufPage4
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t4
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage4
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t4
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
releaseBufPage
(
p
Result
Buf
,
t4
);
releaseBufPage
(
pBuf
,
t4
);
// flush the written page to disk, and read it out again
SFilePage
*
pBufPagex
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
writePageId
));
SFilePage
*
pBufPagex
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
writePageId
));
ASSERT_EQ
(
*
(
int32_t
*
)
pBufPagex
->
data
,
nx
);
SArray
*
pa
=
getDataBufPagesIdList
(
p
Result
Buf
,
groupId
);
SArray
*
pa
=
getDataBufPagesIdList
(
pBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
5
);
destroyDiskbasedBuf
(
p
Result
Buf
);
destroyDiskbasedBuf
(
pBuf
);
}
void
recyclePageTest
()
{
SDiskbasedBuf
*
p
Result
Buf
=
NULL
;
int32_t
ret
=
createDiskbasedBuf
(
&
p
Result
Buf
,
1024
,
4
*
1024
,
"1"
,
"/tmp/"
);
SDiskbasedBuf
*
pBuf
=
NULL
;
int32_t
ret
=
createDiskbasedBuf
(
&
pBuf
,
1024
,
4
*
1024
,
"1"
,
"/tmp/"
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
int32_t
groupId
=
0
;
int32_t
nx
=
12345
;
SFilePage
*
pBufPage
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
pBufPage
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
ASSERT_TRUE
(
pBufPage
!=
NULL
);
releaseBufPage
(
p
Result
Buf
,
pBufPage
);
releaseBufPage
(
pBuf
,
pBufPage
);
SFilePage
*
pBufPage1
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage1
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
SFilePage
*
pBufPage2
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t2
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage2
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t2
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
SFilePage
*
pBufPage3
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t3
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage3
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t3
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
SFilePage
*
pBufPage4
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t4
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage4
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t4
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
releaseBufPage
(
p
Result
Buf
,
t4
);
releaseBufPage
(
pBuf
,
t4
);
SFilePage
*
pBufPage5
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
p
Result
Buf
,
groupId
,
&
pageId
));
SFilePage
*
t5
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
pageId
));
SFilePage
*
pBufPage5
=
static_cast
<
SFilePage
*>
(
getNewBufPage
(
pBuf
,
groupId
,
&
pageId
));
SFilePage
*
t5
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
pageId
));
ASSERT_TRUE
(
t5
==
pBufPage5
);
ASSERT_TRUE
(
pageId
==
5
);
releaseBufPage
(
pBuf
,
t5
);
// flush the written page to disk, and read it out again
SFilePage
*
pBufPagex
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
writePageId
));
SFilePage
*
pBufPagex
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
writePageId
));
*
(
int32_t
*
)(
pBufPagex
->
data
)
=
nx
;
writePageId
=
pageId
;
// update the data
releaseBufPage
(
p
Result
Buf
,
pBufPagex
);
releaseBufPage
(
pBuf
,
pBufPagex
);
SFilePage
*
pBufPagex1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
p
Result
Buf
,
1
));
SFilePage
*
pBufPagex1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
1
));
SArray
*
pa
=
getDataBufPagesIdList
(
p
Result
Buf
,
groupId
);
SArray
*
pa
=
getDataBufPagesIdList
(
pBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
6
);
destroyDiskbasedBuf
(
p
Result
Buf
);
destroyDiskbasedBuf
(
pBuf
);
}
}
// namespace
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录