Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
971efd7e
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
971efd7e
编写于
12月 29, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor code
上级
4e94a210
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
71 addition
and
64 deletion
+71
-64
source/libs/index/inc/index_cache.h
source/libs/index/inc/index_cache.h
+0
-1
source/libs/index/src/index.c
source/libs/index/src/index.c
+7
-7
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+64
-56
未找到文件。
source/libs/index/inc/index_cache.h
浏览文件 @
971efd7e
...
@@ -49,7 +49,6 @@ typedef struct IndexCache {
...
@@ -49,7 +49,6 @@ typedef struct IndexCache {
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
typedef
struct
CacheTerm
{
typedef
struct
CacheTerm
{
// key
// key
int32_t
nColVal
;
char
*
colVal
;
char
*
colVal
;
int32_t
version
;
int32_t
version
;
// value
// value
...
...
source/libs/index/src/index.c
浏览文件 @
971efd7e
...
@@ -227,14 +227,15 @@ SIndexOpts* indexOptsCreate() {
...
@@ -227,14 +227,15 @@ SIndexOpts* indexOptsCreate() {
#endif
#endif
return
NULL
;
return
NULL
;
}
}
void
indexOptsDestroy
(
SIndexOpts
*
opts
){
void
indexOptsDestroy
(
SIndexOpts
*
opts
)
{
#ifdef USE_LUCENE
#ifdef USE_LUCENE
#endif
#endif
}
/*
return
;
* @param: oper
}
*
/*
*/
* @param: oper
*
*/
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
opera
)
{
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
opera
)
{
SIndexMultiTermQuery
*
p
=
(
SIndexMultiTermQuery
*
)
malloc
(
sizeof
(
SIndexMultiTermQuery
));
SIndexMultiTermQuery
*
p
=
(
SIndexMultiTermQuery
*
)
malloc
(
sizeof
(
SIndexMultiTermQuery
));
if
(
p
==
NULL
)
{
if
(
p
==
NULL
)
{
...
@@ -403,7 +404,6 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -403,7 +404,6 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
TFileValue
*
tfv
=
tfileValueCreate
(
cv
->
colVal
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayAddAll
(
tfv
->
tableId
,
cv
->
val
);
taosArrayPush
(
result
,
&
tfv
);
taosArrayPush
(
result
,
&
tfv
);
// copy to final Result;
// copy to final Result;
cn
=
cacheIter
->
next
(
cacheIter
);
cn
=
cacheIter
->
next
(
cacheIter
);
}
else
{
}
else
{
...
...
source/libs/index/src/index_cache.c
浏览文件 @
971efd7e
...
@@ -23,21 +23,21 @@
...
@@ -23,21 +23,21 @@
#define MEM_TERM_LIMIT 1000000
#define MEM_TERM_LIMIT 1000000
// ref index_cache.h:22
// ref index_cache.h:22
//#define CACHE_KEY_LEN(p) \
//#define CACHE_KEY_LEN(p) \
// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + sizeof(p->operType))
// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) +
// sizeof(p->operType))
void
indexMemRef
(
MemTable
*
tbl
);
static
void
indexMemRef
(
MemTable
*
tbl
);
void
indexMemUnRef
(
MemTable
*
tbl
);
static
void
indexMemUnRef
(
MemTable
*
tbl
);
void
indexCacheRef
(
IndexCache
*
cache
);
static
void
cacheTermDestroy
(
CacheTerm
*
ct
);
void
indexCacheUnRef
(
IndexCache
*
cache
);
static
char
*
getIndexKey
(
const
void
*
pData
);
static
int32_t
compareKey
(
const
void
*
l
,
const
void
*
r
);
static
void
cacheTermDestroy
(
CacheTerm
*
ct
);
static
char
*
getIndexKey
(
const
void
*
pData
);
static
int32_t
compareKey
(
const
void
*
l
,
const
void
*
r
);
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
);
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
);
static
void
doMergeWork
(
SSchedMsg
*
msg
);
static
void
doMergeWork
(
SSchedMsg
*
msg
);
static
bool
indexCacheIteratorNext
(
Iterate
*
itera
);
static
bool
indexCacheIteratorNext
(
Iterate
*
itera
);
static
IterateValue
*
indexCacheIteratorGetValue
(
Iterate
*
iter
);
static
IterateValue
*
indexCacheIteratorGetValue
(
Iterate
*
iter
);
IndexCache
*
indexCacheCreate
(
SIndex
*
idx
,
const
char
*
colName
,
int8_t
type
)
{
IndexCache
*
indexCacheCreate
(
SIndex
*
idx
,
const
char
*
colName
,
int8_t
type
)
{
...
@@ -86,7 +86,8 @@ void indexCacheDestroySkiplist(SSkipList* slt) {
...
@@ -86,7 +86,8 @@ void indexCacheDestroySkiplist(SSkipList* slt) {
while
(
tSkipListIterNext
(
iter
))
{
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
ct
!=
NULL
)
{}
if
(
ct
!=
NULL
)
{
}
}
}
tSkipListDestroyIter
(
iter
);
tSkipListDestroyIter
(
iter
);
tSkipListDestroy
(
slt
);
tSkipListDestroy
(
slt
);
...
@@ -101,7 +102,9 @@ void indexCacheDestroyImm(IndexCache* cache) {
...
@@ -101,7 +102,9 @@ void indexCacheDestroyImm(IndexCache* cache) {
}
}
void
indexCacheDestroy
(
void
*
cache
)
{
void
indexCacheDestroy
(
void
*
cache
)
{
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
if
(
pCache
==
NULL
)
{
return
;
}
if
(
pCache
==
NULL
)
{
return
;
}
indexMemUnRef
(
pCache
->
mem
);
indexMemUnRef
(
pCache
->
mem
);
indexMemUnRef
(
pCache
->
imm
);
indexMemUnRef
(
pCache
->
imm
);
free
(
pCache
->
colName
);
free
(
pCache
->
colName
);
...
@@ -111,7 +114,9 @@ void indexCacheDestroy(void* cache) {
...
@@ -111,7 +114,9 @@ void indexCacheDestroy(void* cache) {
Iterate
*
indexCacheIteratorCreate
(
IndexCache
*
cache
)
{
Iterate
*
indexCacheIteratorCreate
(
IndexCache
*
cache
)
{
Iterate
*
iiter
=
calloc
(
1
,
sizeof
(
Iterate
));
Iterate
*
iiter
=
calloc
(
1
,
sizeof
(
Iterate
));
if
(
iiter
==
NULL
)
{
return
NULL
;
}
if
(
iiter
==
NULL
)
{
return
NULL
;
}
MemTable
*
tbl
=
cache
->
imm
;
MemTable
*
tbl
=
cache
->
imm
;
iiter
->
val
.
val
=
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
iiter
->
val
.
val
=
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
...
@@ -122,8 +127,9 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
...
@@ -122,8 +127,9 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
return
iiter
;
return
iiter
;
}
}
void
indexCacheIteratorDestroy
(
Iterate
*
iter
)
{
void
indexCacheIteratorDestroy
(
Iterate
*
iter
)
{
if
(
iter
==
NULL
)
{
return
;
}
if
(
iter
==
NULL
)
{
return
;
}
tSkipListDestroyIter
(
iter
->
iter
);
tSkipListDestroyIter
(
iter
->
iter
);
iterateValueDestroy
(
&
iter
->
val
,
true
);
iterateValueDestroy
(
&
iter
->
val
,
true
);
free
(
iter
);
free
(
iter
);
...
@@ -160,18 +166,21 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
...
@@ -160,18 +166,21 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
}
}
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
if
(
cache
==
NULL
)
{
return
-
1
;
}
if
(
cache
==
NULL
)
{
return
-
1
;
}
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
indexCacheRef
(
pCache
);
indexCacheRef
(
pCache
);
// encode data
// encode data
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
if
(
cache
==
NULL
)
{
return
-
1
;
}
if
(
cache
==
NULL
)
{
return
-
1
;
}
// set up key
// set up key
ct
->
colType
=
term
->
colType
;
ct
->
colType
=
term
->
colType
;
ct
->
nColVal
=
term
->
nColVal
;
ct
->
colVal
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
term
->
nColVal
+
1
));
ct
->
colVal
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
ct
->
nColVal
+
1
));
memcpy
(
ct
->
colVal
,
term
->
colVal
,
term
->
nColVal
);
memcpy
(
ct
->
colVal
,
term
->
colVal
,
ct
->
nColVal
);
ct
->
version
=
atomic_add_fetch_32
(
&
pCache
->
version
,
1
);
ct
->
version
=
atomic_add_fetch_32
(
&
pCache
->
version
,
1
);
// set value
// set value
ct
->
uid
=
uid
;
ct
->
uid
=
uid
;
...
@@ -197,7 +206,9 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u
...
@@ -197,7 +206,9 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u
return
0
;
return
0
;
}
}
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SArray
*
result
,
STermValueType
*
s
)
{
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SArray
*
result
,
STermValueType
*
s
)
{
if
(
cache
==
NULL
)
{
return
-
1
;
}
if
(
cache
==
NULL
)
{
return
-
1
;
}
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
SIndexTerm
*
term
=
query
->
term
;
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
EIndexQueryType
qtype
=
query
->
qType
;
...
@@ -211,10 +222,11 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
...
@@ -211,10 +222,11 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
pthread_mutex_unlock
(
&
pCache
->
mtx
);
pthread_mutex_unlock
(
&
pCache
->
mtx
);
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
if
(
ct
==
NULL
)
{
return
-
1
;
}
if
(
ct
==
NULL
)
{
ct
->
nColVal
=
term
->
nColVal
;
return
-
1
;
ct
->
colVal
=
calloc
(
1
,
sizeof
(
char
)
*
(
ct
->
nColVal
+
1
));
}
memcpy
(
ct
->
colVal
,
term
->
colVal
,
ct
->
nColVal
);
ct
->
colVal
=
calloc
(
1
,
sizeof
(
char
)
*
(
term
->
nColVal
+
1
));
memcpy
(
ct
->
colVal
,
term
->
colVal
,
term
->
nColVal
);
ct
->
version
=
atomic_load_32
(
&
pCache
->
version
);
ct
->
version
=
atomic_load_32
(
&
pCache
->
version
);
char
*
key
=
getIndexKey
(
ct
);
char
*
key
=
getIndexKey
(
ct
);
...
@@ -225,7 +237,7 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
...
@@ -225,7 +237,7 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
if
(
node
!=
NULL
)
{
if
(
node
!=
NULL
)
{
CacheTerm
*
c
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
CacheTerm
*
c
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
c
->
operaType
==
ADD_VALUE
||
qtype
==
QUERY_TERM
)
{
if
(
c
->
operaType
==
ADD_VALUE
||
qtype
==
QUERY_TERM
)
{
if
(
c
->
nColVal
==
ct
->
nColVal
&&
strncmp
(
c
->
colVal
,
ct
->
colVal
,
c
->
nC
olVal
)
==
0
)
{
if
(
strcmp
(
c
->
colVal
,
ct
->
c
olVal
)
==
0
)
{
taosArrayPush
(
result
,
&
c
->
uid
);
taosArrayPush
(
result
,
&
c
->
uid
);
*
s
=
kTypeValue
;
*
s
=
kTypeValue
;
}
else
{
}
else
{
...
@@ -257,26 +269,33 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
...
@@ -257,26 +269,33 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV
}
}
void
indexCacheRef
(
IndexCache
*
cache
)
{
void
indexCacheRef
(
IndexCache
*
cache
)
{
if
(
cache
==
NULL
)
{
return
;
}
if
(
cache
==
NULL
)
{
return
;
}
int
ref
=
T_REF_INC
(
cache
);
int
ref
=
T_REF_INC
(
cache
);
UNUSED
(
ref
);
UNUSED
(
ref
);
}
}
void
indexCacheUnRef
(
IndexCache
*
cache
)
{
void
indexCacheUnRef
(
IndexCache
*
cache
)
{
if
(
cache
==
NULL
)
{
return
;
}
if
(
cache
==
NULL
)
{
return
;
}
int
ref
=
T_REF_DEC
(
cache
);
int
ref
=
T_REF_DEC
(
cache
);
if
(
ref
==
0
)
{
indexCacheDestroy
(
cache
);
}
if
(
ref
==
0
)
{
indexCacheDestroy
(
cache
);
}
}
}
void
indexMemRef
(
MemTable
*
tbl
)
{
void
indexMemRef
(
MemTable
*
tbl
)
{
if
(
tbl
==
NULL
)
{
return
;
}
if
(
tbl
==
NULL
)
{
return
;
}
int
ref
=
T_REF_INC
(
tbl
);
int
ref
=
T_REF_INC
(
tbl
);
UNUSED
(
ref
);
UNUSED
(
ref
);
}
}
void
indexMemUnRef
(
MemTable
*
tbl
)
{
void
indexMemUnRef
(
MemTable
*
tbl
)
{
if
(
tbl
==
NULL
)
{
return
;
}
if
(
tbl
==
NULL
)
{
return
;
}
int
ref
=
T_REF_DEC
(
tbl
);
int
ref
=
T_REF_DEC
(
tbl
);
if
(
ref
==
0
)
{
if
(
ref
==
0
)
{
SSkipList
*
slt
=
tbl
->
mem
;
SSkipList
*
slt
=
tbl
->
mem
;
...
@@ -286,8 +305,9 @@ void indexMemUnRef(MemTable* tbl) {
...
@@ -286,8 +305,9 @@ void indexMemUnRef(MemTable* tbl) {
}
}
static
void
cacheTermDestroy
(
CacheTerm
*
ct
)
{
static
void
cacheTermDestroy
(
CacheTerm
*
ct
)
{
if
(
ct
==
NULL
)
{
return
;
}
if
(
ct
==
NULL
)
{
return
;
}
free
(
ct
->
colVal
);
free
(
ct
->
colVal
);
free
(
ct
);
free
(
ct
);
}
}
...
@@ -301,21 +321,11 @@ static int32_t compareKey(const void* l, const void* r) {
...
@@ -301,21 +321,11 @@ static int32_t compareKey(const void* l, const void* r) {
CacheTerm
*
rt
=
(
CacheTerm
*
)
r
;
CacheTerm
*
rt
=
(
CacheTerm
*
)
r
;
// compare colVal
// compare colVal
int
i
,
j
;
int32_t
cmp
=
strcmp
(
lt
->
colVal
,
rt
->
colVal
);
for
(
i
=
0
,
j
=
0
;
i
<
lt
->
nColVal
&&
j
<
rt
->
nColVal
;
i
++
,
j
++
)
{
if
(
cmp
==
0
)
{
if
(
lt
->
colVal
[
i
]
==
rt
->
colVal
[
j
])
{
return
rt
->
version
-
lt
->
version
;
continue
;
}
else
{
return
lt
->
colVal
[
i
]
<
rt
->
colVal
[
j
]
?
-
1
:
1
;
}
}
if
(
i
<
lt
->
nColVal
)
{
return
1
;
}
else
if
(
j
<
rt
->
nColVal
)
{
return
-
1
;
}
}
// compare version
return
cmp
;
return
rt
->
version
-
lt
->
version
;
}
}
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
)
{
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
)
{
...
@@ -334,8 +344,9 @@ static void doMergeWork(SSchedMsg* msg) {
...
@@ -334,8 +344,9 @@ static void doMergeWork(SSchedMsg* msg) {
}
}
static
bool
indexCacheIteratorNext
(
Iterate
*
itera
)
{
static
bool
indexCacheIteratorNext
(
Iterate
*
itera
)
{
SSkipListIterator
*
iter
=
itera
->
iter
;
SSkipListIterator
*
iter
=
itera
->
iter
;
if
(
iter
==
NULL
)
{
return
false
;
}
if
(
iter
==
NULL
)
{
return
false
;
}
IterateValue
*
iv
=
&
itera
->
val
;
IterateValue
*
iv
=
&
itera
->
val
;
iterateValueDestroy
(
iv
,
false
);
iterateValueDestroy
(
iv
,
false
);
...
@@ -349,10 +360,7 @@ static bool indexCacheIteratorNext(Iterate* itera) {
...
@@ -349,10 +360,7 @@ static bool indexCacheIteratorNext(Iterate* itera) {
taosArrayPush
(
iv
->
val
,
&
ct
->
uid
);
taosArrayPush
(
iv
->
val
,
&
ct
->
uid
);
}
}
return
next
;
return
next
;
}
}
static
IterateValue
*
indexCacheIteratorGetValue
(
Iterate
*
iter
)
{
static
IterateValue
*
indexCacheIteratorGetValue
(
Iterate
*
iter
)
{
return
&
iter
->
val
;
}
return
&
iter
->
val
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录