Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8f75b96e
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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,发现更多精彩内容 >>
提交
8f75b96e
编写于
5月 21, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: refator index/transport code
上级
4d18fa08
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
14 deletion
+58
-14
source/libs/index/inc/indexCache.h
source/libs/index/inc/indexCache.h
+1
-0
source/libs/index/src/index.c
source/libs/index/src/index.c
+22
-8
source/libs/index/src/indexCache.c
source/libs/index/src/indexCache.c
+16
-4
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+19
-2
未找到文件。
source/libs/index/inc/indexCache.h
浏览文件 @
8f75b96e
...
...
@@ -63,6 +63,7 @@ typedef struct CacheTerm {
IndexCache
*
indexCacheCreate
(
SIndex
*
idx
,
uint64_t
suid
,
const
char
*
colName
,
int8_t
type
);
void
indexCacheForceToMerge
(
void
*
cache
);
void
indexCacheDestroy
(
void
*
cache
);
Iterate
*
indexCacheIteratorCreate
(
IndexCache
*
cache
);
...
...
source/libs/index/src/index.c
浏览文件 @
8f75b96e
...
...
@@ -124,15 +124,21 @@ END:
void
indexDestroy
(
void
*
handle
)
{
SIndex
*
sIdx
=
handle
;
void
*
iter
=
taosHashIterate
(
sIdx
->
colObj
,
NULL
);
while
(
iter
)
{
IndexCache
**
pCache
=
iter
;
if
(
*
pCache
)
{
// indexAcquireRef(sIdx->refId);
if
(
sIdx
->
colObj
!=
NULL
)
{
void
*
iter
=
taosHashIterate
(
sIdx
->
colObj
,
NULL
);
while
(
iter
)
{
IndexCache
**
pCache
=
iter
;
indexCacheForceToMerge
((
void
*
)(
*
pCache
));
iter
=
taosHashIterate
(
sIdx
->
colObj
,
iter
);
indexCacheUnRef
(
*
pCache
);
}
iter
=
taosHashIterate
(
sIdx
->
colObj
,
iter
);
}
taosHashCleanup
(
sIdx
->
colObj
);
taosHashCleanup
(
sIdx
->
colObj
);
sIdx
->
colObj
=
NULL
;
return
;
}
// indexReleaseRef(sIdx->refId);
taosThreadMutexDestroy
(
&
sIdx
->
mtx
);
indexTFileDestroy
(
sIdx
->
tindex
);
taosMemoryFree
(
sIdx
->
path
);
...
...
@@ -177,7 +183,6 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
taosHashPut
(
index
->
colObj
,
buf
,
sz
,
&
pCache
,
sizeof
(
void
*
));
}
}
taosThreadMutexUnlock
(
&
index
->
mtx
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
...
...
@@ -193,6 +198,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
return
ret
;
}
}
taosThreadMutexUnlock
(
&
index
->
mtx
);
return
0
;
}
int
indexSearch
(
SIndex
*
index
,
SIndexMultiTermQuery
*
multiQuerys
,
SArray
*
result
)
{
...
...
@@ -451,6 +457,14 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
}
// handle flush
Iterate
*
cacheIter
=
indexCacheIteratorCreate
(
pCache
);
if
(
cacheIter
==
NULL
)
{
indexError
(
"%p immtable is empty, ignore merge opera"
,
pCache
);
indexCacheDestroyImm
(
pCache
);
tfileReaderUnRef
(
pReader
);
indexReleaseRef
(
sIdx
->
refId
);
return
0
;
}
Iterate
*
tfileIter
=
tfileIteratorCreate
(
pReader
);
if
(
tfileIter
==
NULL
)
{
indexWarn
(
"empty tfile reader iterator"
);
...
...
source/libs/index/src/indexCache.c
浏览文件 @
8f75b96e
...
...
@@ -429,11 +429,13 @@ void indexCacheDestroy(void* cache) {
}
Iterate
*
indexCacheIteratorCreate
(
IndexCache
*
cache
)
{
if
(
cache
->
imm
==
NULL
)
{
return
NULL
;
}
Iterate
*
iiter
=
taosMemoryCalloc
(
1
,
sizeof
(
Iterate
));
if
(
iiter
==
NULL
)
{
return
NULL
;
}
taosThreadMutexLock
(
&
cache
->
mtx
);
indexMemRef
(
cache
->
imm
);
...
...
@@ -463,12 +465,9 @@ int indexCacheSchedToMerge(IndexCache* pCache) {
schedMsg
.
fp
=
doMergeWork
;
schedMsg
.
ahandle
=
pCache
;
schedMsg
.
thandle
=
NULL
;
// schedMsg.thandle = taosMemoryCalloc(1, sizeof(int64_t));
// memcpy((char*)(schedMsg.thandle), (char*)&(pCache->index->refId), sizeof(int64_t));
schedMsg
.
msg
=
NULL
;
indexAcquireRef
(
pCache
->
index
->
refId
);
taosScheduleTask
(
indexQhandle
,
&
schedMsg
);
return
0
;
}
...
...
@@ -533,6 +532,19 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
return
0
;
// encode end
}
void
indexCacheForceToMerge
(
void
*
cache
)
{
IndexCache
*
pCache
=
cache
;
indexCacheRef
(
pCache
);
taosThreadMutexLock
(
&
pCache
->
mtx
);
indexInfo
(
"%p is forced to merge into tfile"
,
pCache
);
pCache
->
occupiedMem
+=
MEM_THRESHOLD
*
5
;
indexCacheMakeRoomForWrite
(
pCache
);
taosThreadMutexUnlock
(
&
pCache
->
mtx
);
indexCacheUnRef
(
pCache
);
return
;
}
int
indexCacheDel
(
void
*
cache
,
const
char
*
fieldValue
,
int32_t
fvlen
,
uint64_t
uid
,
int8_t
operType
)
{
IndexCache
*
pCache
=
cache
;
return
0
;
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
8f75b96e
...
...
@@ -272,9 +272,26 @@ void validateFst() {
}
delete
m
;
}
static
std
::
string
logDir
=
"/tmp/log"
;
static
void
initLog
()
{
const
char
*
defaultLogFileNamePrefix
=
"taoslog"
;
const
int32_t
maxLogFileNum
=
10
;
tsAsyncLog
=
0
;
sDebugFlag
=
143
;
strcpy
(
tsLogDir
,
logDir
.
c_str
());
taosRemoveDir
(
tsLogDir
);
taosMkDir
(
tsLogDir
);
if
(
taosInitLog
(
defaultLogFileNamePrefix
,
maxLogFileNum
)
<
0
)
{
printf
(
"failed to open log file in directory:%s
\n
"
,
tsLogDir
);
}
}
class
IndexEnv
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
initLog
();
taosRemoveDir
(
path
);
opts
=
indexOptsCreate
();
int
ret
=
indexOpen
(
opts
,
path
,
&
index
);
...
...
@@ -804,7 +821,7 @@ class IndexObj {
}
~
IndexObj
()
{
indexCleanUp
();
//
indexCleanUp();
indexClose
(
idx
);
}
...
...
@@ -884,7 +901,7 @@ TEST_F(IndexEnv2, testIndexOpen) {
SArray
*
result
=
(
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
index
->
Search
(
mq
,
result
);
std
::
cout
<<
"target size: "
<<
taosArrayGetSize
(
result
)
<<
std
::
endl
;
assert
(
taosArrayGetSize
(
result
)
==
400
);
EXPECT_EQ
(
400
,
taosArrayGetSize
(
result
)
);
taosArrayDestroy
(
result
);
indexMultiTermQueryDestroy
(
mq
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录