Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f057cd19
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
f057cd19
编写于
6月 09, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: refactor idx module
上级
daa2e868
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
46 addition
and
46 deletion
+46
-46
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+11
-11
source/libs/index/src/index.c
source/libs/index/src/index.c
+15
-15
source/libs/index/src/indexCache.c
source/libs/index/src/indexCache.c
+10
-10
source/libs/index/src/indexComm.c
source/libs/index/src/indexComm.c
+3
-3
source/libs/index/src/indexJson.c
source/libs/index/src/indexJson.c
+2
-2
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+5
-5
未找到文件。
source/libs/index/inc/indexInt.h
浏览文件 @
f057cd19
...
...
@@ -133,24 +133,24 @@ typedef struct TFileCacheKey {
}
ICacheKey
;
int
idxFlushCacheToTFile
(
SIndex
*
sIdx
,
void
*
,
bool
quit
);
int64_t
i
nde
xAddRef
(
void
*
p
);
int32_t
i
nde
xRemoveRef
(
int64_t
ref
);
void
i
nde
xAcquireRef
(
int64_t
ref
);
void
i
nde
xReleaseRef
(
int64_t
ref
);
int64_t
i
d
xAddRef
(
void
*
p
);
int32_t
i
d
xRemoveRef
(
int64_t
ref
);
void
i
d
xAcquireRef
(
int64_t
ref
);
void
i
d
xReleaseRef
(
int64_t
ref
);
int32_t
idxSerialCacheKey
(
ICacheKey
*
key
,
char
*
buf
);
// int32_t indexSerialKey(ICacheKey* key, char* buf);
// int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
#define I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
#define I
D
X_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
#define I
NDE
X_TYPE_GET_TYPE(ty) (ty & 0x0F)
#define I
D
X_TYPE_GET_TYPE(ty) (ty & 0x0F)
#define I
NDE
X_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
do {
\
uint8_t oldTy = ty;
\
ty = (ty >> 4) | exTy;
\
ty = (ty << 4) | oldTy;
\
#define I
D
X_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
do { \
uint8_t oldTy = ty; \
ty = (ty >> 4) | exTy; \
ty = (ty << 4) | oldTy; \
} while (0)
#ifdef __cplusplus
...
...
source/libs/index/src/index.c
浏览文件 @
f057cd19
...
...
@@ -90,7 +90,7 @@ static void idxMergeCacheAndTFile(SArray* result, IterateValue* icache, IterateV
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
// int32_t indexSerialKey(ICacheKey* key, char* buf);
static
void
i
nde
xPost
(
void
*
idx
)
{
static
void
i
d
xPost
(
void
*
idx
)
{
SIndex
*
pIdx
=
idx
;
tsem_post
(
&
pIdx
->
sem
);
}
...
...
@@ -118,8 +118,8 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
taosThreadMutexInit
(
&
sIdx
->
mtx
,
NULL
);
tsem_init
(
&
sIdx
->
sem
,
0
,
0
);
sIdx
->
refId
=
i
nde
xAddRef
(
sIdx
);
i
nde
xAcquireRef
(
sIdx
->
refId
);
sIdx
->
refId
=
i
d
xAddRef
(
sIdx
);
i
d
xAcquireRef
(
sIdx
->
refId
);
*
index
=
sIdx
;
return
0
;
...
...
@@ -157,23 +157,23 @@ void indexClose(SIndex* sIdx) {
taosHashCleanup
(
sIdx
->
colObj
);
sIdx
->
colObj
=
NULL
;
}
i
nde
xReleaseRef
(
sIdx
->
refId
);
i
nde
xRemoveRef
(
sIdx
->
refId
);
i
d
xReleaseRef
(
sIdx
->
refId
);
i
d
xRemoveRef
(
sIdx
->
refId
);
}
int64_t
i
nde
xAddRef
(
void
*
p
)
{
int64_t
i
d
xAddRef
(
void
*
p
)
{
// impl
return
taosAddRef
(
indexRefMgt
,
p
);
}
int32_t
i
nde
xRemoveRef
(
int64_t
ref
)
{
int32_t
i
d
xRemoveRef
(
int64_t
ref
)
{
// impl later
return
taosRemoveRef
(
indexRefMgt
,
ref
);
}
void
i
nde
xAcquireRef
(
int64_t
ref
)
{
void
i
d
xAcquireRef
(
int64_t
ref
)
{
// impl
taosAcquireRef
(
indexRefMgt
,
ref
);
}
void
i
nde
xReleaseRef
(
int64_t
ref
)
{
void
i
d
xReleaseRef
(
int64_t
ref
)
{
// impl
taosReleaseRef
(
indexRefMgt
,
ref
);
}
...
...
@@ -289,7 +289,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
tm
->
nColName
=
nColName
;
char
*
buf
=
NULL
;
int32_t
len
=
idxConvertDataToStr
((
void
*
)
colVal
,
I
NDE
X_TYPE_GET_TYPE
(
colType
),
(
void
**
)
&
buf
);
int32_t
len
=
idxConvertDataToStr
((
void
*
)
colVal
,
I
D
X_TYPE_GET_TYPE
(
colType
),
(
void
**
)
&
buf
);
assert
(
len
!=
-
1
);
tm
->
colVal
=
buf
;
...
...
@@ -479,9 +479,9 @@ int idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
tfileReaderUnRef
(
pReader
);
atomic_store_32
(
&
pCache
->
merging
,
0
);
if
(
quit
)
{
i
nde
xPost
(
sIdx
);
i
d
xPost
(
sIdx
);
}
i
nde
xReleaseRef
(
sIdx
->
refId
);
i
d
xReleaseRef
(
sIdx
->
refId
);
return
0
;
}
...
...
@@ -542,9 +542,9 @@ int idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
}
atomic_store_32
(
&
pCache
->
merging
,
0
);
if
(
quit
)
{
i
nde
xPost
(
sIdx
);
i
d
xPost
(
sIdx
);
}
i
nde
xReleaseRef
(
sIdx
->
refId
);
i
d
xReleaseRef
(
sIdx
->
refId
);
return
ret
;
}
...
...
@@ -621,7 +621,7 @@ END:
}
int32_t
idxSerialCacheKey
(
ICacheKey
*
key
,
char
*
buf
)
{
bool
hasJson
=
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
key
->
colType
,
TSDB_DATA_TYPE_JSON
);
bool
hasJson
=
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
key
->
colType
,
TSDB_DATA_TYPE_JSON
);
char
*
p
=
buf
;
char
tbuf
[
65
]
=
{
0
};
...
...
source/libs/index/src/indexCache.c
浏览文件 @
f057cd19
...
...
@@ -187,7 +187,7 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr
pCt
->
version
=
atomic_load_64
(
&
pCache
->
version
);
char
*
exBuf
=
NULL
;
if
(
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
if
(
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
exBuf
=
idxPackJsonData
(
term
);
pCt
->
colVal
=
exBuf
;
}
...
...
@@ -266,7 +266,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
pCt
->
colVal
=
term
->
colVal
;
pCt
->
version
=
atomic_load_64
(
&
pCache
->
version
);
int8_t
dType
=
I
NDE
X_TYPE_GET_TYPE
(
term
->
colType
);
int8_t
dType
=
I
D
X_TYPE_GET_TYPE
(
term
->
colType
);
int
skip
=
0
;
char
*
exBuf
=
NULL
;
if
(
type
==
CONTAINS
)
{
...
...
@@ -342,7 +342,7 @@ IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8
cache
->
mem
=
idxInternalCacheCreate
(
type
);
cache
->
mem
->
pCache
=
cache
;
cache
->
colName
=
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
tstrdup
(
JSON_COLUMN
)
:
tstrdup
(
colName
);
cache
->
colName
=
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
tstrdup
(
JSON_COLUMN
)
:
tstrdup
(
colName
);
cache
->
type
=
type
;
cache
->
index
=
idx
;
cache
->
version
=
0
;
...
...
@@ -354,7 +354,7 @@ IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8
idxCacheRef
(
cache
);
if
(
idx
!=
NULL
)
{
i
nde
xAcquireRef
(
idx
->
refId
);
i
d
xAcquireRef
(
idx
->
refId
);
}
return
cache
;
}
...
...
@@ -455,7 +455,7 @@ void idxCacheDestroy(void* cache) {
taosThreadMutexDestroy
(
&
pCache
->
mtx
);
taosThreadCondDestroy
(
&
pCache
->
finished
);
if
(
pCache
->
index
!=
NULL
)
{
i
nde
xReleaseRef
(((
SIndex
*
)
pCache
->
index
)
->
refId
);
i
d
xReleaseRef
(((
SIndex
*
)
pCache
->
index
)
->
refId
);
}
taosMemoryFree
(
pCache
);
}
...
...
@@ -500,7 +500,7 @@ int idxCacheSchedToMerge(IndexCache* pCache, bool notify) {
schedMsg
.
thandle
=
taosMemoryMalloc
(
1
);
}
schedMsg
.
msg
=
NULL
;
i
nde
xAcquireRef
(
pCache
->
index
->
refId
);
i
d
xAcquireRef
(
pCache
->
index
->
refId
);
taosScheduleTask
(
indexQhandle
,
&
schedMsg
);
return
0
;
}
...
...
@@ -533,7 +533,7 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
if
(
cache
==
NULL
)
{
return
-
1
;
}
bool
hasJson
=
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
);
bool
hasJson
=
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
);
IndexCache
*
pCache
=
cache
;
idxCacheRef
(
pCache
);
...
...
@@ -597,7 +597,7 @@ static int32_t idxQueryMem(MemTable* mem, SIndexTermQuery* query, SIdxTRslt* tr,
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
if
(
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
if
(
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
return
cacheSearch
[
1
][
qtype
](
mem
,
term
,
tr
,
s
);
}
else
{
return
cacheSearch
[
0
][
qtype
](
mem
,
term
,
tr
,
s
);
...
...
@@ -730,9 +730,9 @@ static int32_t idxCacheJsonTermCompare(const void* l, const void* r) {
return
cmp
;
}
static
MemTable
*
idxInternalCacheCreate
(
int8_t
type
)
{
int
ttype
=
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
TSDB_DATA_TYPE_BINARY
:
TSDB_DATA_TYPE_BINARY
;
int
ttype
=
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
TSDB_DATA_TYPE_BINARY
:
TSDB_DATA_TYPE_BINARY
;
int32_t
(
*
cmpFn
)(
const
void
*
l
,
const
void
*
r
)
=
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
idxCacheJsonTermCompare
:
idxCacheTermCompare
;
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
idxCacheJsonTermCompare
:
idxCacheTermCompare
;
MemTable
*
tbl
=
taosMemoryCalloc
(
1
,
sizeof
(
MemTable
));
idxMemRef
(
tbl
);
...
...
source/libs/index/src/indexComm.c
浏览文件 @
f057cd19
...
...
@@ -212,7 +212,7 @@ char* idxPackJsonData(SIndexTerm* itm) {
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
*/
uint8_t
ty
=
I
NDE
X_TYPE_GET_TYPE
(
itm
->
colType
);
uint8_t
ty
=
I
D
X_TYPE_GET_TYPE
(
itm
->
colType
);
int32_t
sz
=
itm
->
nColName
+
itm
->
nColVal
+
sizeof
(
uint8_t
)
+
sizeof
(
JSON_VALUE_DELIM
)
*
2
+
1
;
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sz
);
...
...
@@ -240,7 +240,7 @@ char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) {
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
*/
uint8_t
ty
=
I
NDE
X_TYPE_GET_TYPE
(
itm
->
colType
);
uint8_t
ty
=
I
D
X_TYPE_GET_TYPE
(
itm
->
colType
);
int32_t
sz
=
itm
->
nColName
+
itm
->
nColVal
+
sizeof
(
uint8_t
)
+
sizeof
(
JSON_VALUE_DELIM
)
*
2
+
1
;
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sz
);
...
...
@@ -267,7 +267,7 @@ char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) {
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
*/
uint8_t
ty
=
I
NDE
X_TYPE_GET_TYPE
(
itm
->
colType
);
uint8_t
ty
=
I
D
X_TYPE_GET_TYPE
(
itm
->
colType
);
int32_t
sz
=
itm
->
nColName
+
itm
->
nColVal
+
sizeof
(
uint8_t
)
+
sizeof
(
JSON_VALUE_DELIM
)
*
2
+
1
;
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sz
);
...
...
source/libs/index/src/indexJson.c
浏览文件 @
f057cd19
...
...
@@ -30,7 +30,7 @@ int indexJsonPut(SIndexJson *index, SIndexJsonMultiTerm *terms, uint64_t uid) {
}
else
{
p
->
colType
=
TSDB_DATA_TYPE_DOUBLE
;
}
I
NDE
X_TYPE_ADD_EXTERN_TYPE
(
p
->
colType
,
TSDB_DATA_TYPE_JSON
);
I
D
X_TYPE_ADD_EXTERN_TYPE
(
p
->
colType
,
TSDB_DATA_TYPE_JSON
);
}
// handle put
return
indexPut
(
index
,
terms
,
uid
);
...
...
@@ -48,7 +48,7 @@ int indexJsonSearch(SIndexJson *index, SIndexJsonMultiTermQuery *tq, SArray *res
}
else
{
p
->
colType
=
TSDB_DATA_TYPE_DOUBLE
;
}
I
NDE
X_TYPE_ADD_EXTERN_TYPE
(
p
->
colType
,
TSDB_DATA_TYPE_JSON
);
I
D
X_TYPE_ADD_EXTERN_TYPE
(
p
->
colType
,
TSDB_DATA_TYPE_JSON
);
}
// handle search
return
indexSearch
(
index
,
tq
,
result
);
...
...
source/libs/index/src/indexTfile.c
浏览文件 @
f057cd19
...
...
@@ -281,7 +281,7 @@ static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
return
0
;
}
static
int32_t
tfSearchRegex
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxTRslt
*
tr
)
{
bool
hasJson
=
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
bool
hasJson
=
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
int
ret
=
0
;
char
*
p
=
tem
->
colVal
;
...
...
@@ -457,7 +457,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
}
else
if
(
0
!=
strncmp
(
ch
,
p
,
skip
))
{
continue
;
}
cond
=
cmpFn
(
ch
+
skip
,
tem
->
colVal
,
I
NDE
X_TYPE_GET_TYPE
(
tem
->
colType
));
cond
=
cmpFn
(
ch
+
skip
,
tem
->
colVal
,
I
D
X_TYPE_GET_TYPE
(
tem
->
colType
));
}
if
(
MATCH
==
cond
)
{
tfileReaderLoadTableIds
((
TFileReader
*
)
reader
,
rt
->
out
.
out
,
tr
->
total
);
...
...
@@ -476,7 +476,7 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTRslt* tr
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
int
ret
=
0
;
if
(
I
NDE
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
if
(
I
D
X_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
ret
=
tfSearch
[
1
][
qtype
](
reader
,
term
,
tr
);
}
else
{
ret
=
tfSearch
[
0
][
qtype
](
reader
,
term
,
tr
);
...
...
@@ -536,7 +536,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) {
__compar_fn_t
fn
;
int8_t
colType
=
tw
->
header
.
colType
;
colType
=
I
NDE
X_TYPE_GET_TYPE
(
colType
);
colType
=
I
D
X_TYPE_GET_TYPE
(
colType
);
if
(
colType
==
TSDB_DATA_TYPE_BINARY
||
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
fn
=
tfileStrCompare
;
}
else
{
...
...
@@ -845,7 +845,7 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) {
TFileHeader
*
header
=
&
write
->
header
;
uint8_t
colType
=
header
->
colType
;
colType
=
I
NDE
X_TYPE_GET_TYPE
(
colType
);
colType
=
I
D
X_TYPE_GET_TYPE
(
colType
);
FstSlice
key
=
fstSliceCreate
((
uint8_t
*
)(
tval
->
colVal
),
(
size_t
)
strlen
(
tval
->
colVal
));
if
(
fstBuilderInsert
(
write
->
fb
,
key
,
tval
->
offset
))
{
fstSliceDestroy
(
&
key
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录