Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dcc78597
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dcc78597
编写于
6月 08, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor index code
上级
9987c664
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
248 addition
and
270 deletion
+248
-270
source/libs/index/inc/indexCache.h
source/libs/index/inc/indexCache.h
+2
-2
source/libs/index/inc/indexComm.h
source/libs/index/inc/indexComm.h
+2
-2
source/libs/index/inc/indexFst.h
source/libs/index/inc/indexFst.h
+29
-30
source/libs/index/inc/indexFstAutomation.h
source/libs/index/inc/indexFstAutomation.h
+13
-13
source/libs/index/src/index.c
source/libs/index/src/index.c
+25
-25
source/libs/index/src/indexCache.c
source/libs/index/src/indexCache.c
+44
-45
source/libs/index/src/indexComm.c
source/libs/index/src/indexComm.c
+2
-2
source/libs/index/src/indexFst.c
source/libs/index/src/indexFst.c
+24
-25
source/libs/index/src/indexFstAutomation.c
source/libs/index/src/indexFstAutomation.c
+21
-21
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+35
-54
source/libs/index/test/fstTest.cc
source/libs/index/test/fstTest.cc
+36
-36
source/libs/index/test/fstUT.cc
source/libs/index/test/fstUT.cc
+8
-8
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+7
-7
未找到文件。
source/libs/index/inc/indexCache.h
浏览文件 @
dcc78597
...
...
@@ -70,7 +70,7 @@ void indexCacheBroadcast(void* cache);
void
indexCacheWait
(
void
*
cache
);
Iterate
*
indexCacheIteratorCreate
(
IndexCache
*
cache
);
void
i
nde
xCacheIteratorDestroy
(
Iterate
*
iiter
);
void
i
d
xCacheIteratorDestroy
(
Iterate
*
iiter
);
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
uint64_t
uid
);
...
...
@@ -82,7 +82,7 @@ void indexCacheUnRef(IndexCache* cache);
void
indexCacheDebug
(
IndexCache
*
cache
);
void
i
nde
xCacheDestroyImm
(
IndexCache
*
cache
);
void
i
d
xCacheDestroyImm
(
IndexCache
*
cache
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/index/inc/indexComm.h
浏览文件 @
dcc78597
...
...
@@ -26,8 +26,8 @@ extern "C" {
extern
char
JSON_COLUMN
[];
extern
char
JSON_VALUE_DELIM
;
char
*
i
nde
xPackJsonData
(
SIndexTerm
*
itm
);
char
*
i
nde
xPackJsonDataPrefix
(
SIndexTerm
*
itm
,
int32_t
*
skip
);
char
*
i
d
xPackJsonData
(
SIndexTerm
*
itm
);
char
*
i
d
xPackJsonDataPrefix
(
SIndexTerm
*
itm
,
int32_t
*
skip
);
typedef
enum
{
MATCH
,
CONTINUE
,
BREAK
}
TExeCond
;
...
...
source/libs/index/inc/indexFst.h
浏览文件 @
dcc78597
...
...
@@ -29,9 +29,9 @@ extern "C" {
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
typedef
struct
Fst
Fst
;
typedef
struct
FstNode
FstNode
;
typedef
struct
StreamWithState
StreamWithState
;
typedef
struct
Fst
Fst
;
typedef
struct
FstNode
FstNode
;
typedef
struct
FStmSt
FStmSt
;
typedef
enum
{
Included
,
Excluded
,
Unbounded
}
FstBound
;
...
...
@@ -40,12 +40,12 @@ typedef struct FstBoundWithData {
FstBound
type
;
}
FstBoundWithData
;
typedef
struct
F
stStrea
mBuilder
{
typedef
struct
F
St
mBuilder
{
Fst
*
fst
;
AutomationCtx
*
aut
;
FAutoCtx
*
aut
;
FstBoundWithData
*
min
;
FstBoundWithData
*
max
;
}
F
stStreamBuilder
,
FstStreamWithState
Builder
;
}
F
StmBuilder
,
FStmSt
Builder
;
typedef
struct
FstRange
{
uint64_t
start
;
...
...
@@ -267,17 +267,17 @@ typedef struct Fst {
Fst
*
fstCreate
(
FstSlice
*
data
);
void
fstDestroy
(
Fst
*
fst
);
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
);
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
);
FstNode
*
fstGetRoot
(
Fst
*
fst
);
FstType
fstGetType
(
Fst
*
fst
);
CompiledAddr
fstGetRootAddr
(
Fst
*
fst
);
Output
fstEmptyFinalOutput
(
Fst
*
fst
,
bool
*
null
);
F
stStreamBuilder
*
fstSearch
(
Fst
*
fst
,
Automation
Ctx
*
ctx
);
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
);
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
);
FstNode
*
fstGetRoot
(
Fst
*
fst
);
FstType
fstGetType
(
Fst
*
fst
);
CompiledAddr
fstGetRootAddr
(
Fst
*
fst
);
Output
fstEmptyFinalOutput
(
Fst
*
fst
,
bool
*
null
);
F
StmBuilder
*
fstSearch
(
Fst
*
fst
,
FAuto
Ctx
*
ctx
);
F
stStreamWithStateBuilder
*
fstSearchWithState
(
Fst
*
fst
,
Automation
Ctx
*
ctx
);
F
StmStBuilder
*
fstSearchWithState
(
Fst
*
fst
,
FAuto
Ctx
*
ctx
);
// into stream to expand later
StreamWithState
*
streamBuilderIntoStream
(
FstStrea
mBuilder
*
sb
);
FStmSt
*
stmBuilderIntoStm
(
FSt
mBuilder
*
sb
);
bool
fstVerify
(
Fst
*
fst
);
...
...
@@ -293,41 +293,40 @@ typedef struct StreamState {
void
streamStateDestroy
(
void
*
s
);
typedef
struct
StreamWithState
{
typedef
struct
FStmSt
{
Fst
*
fst
;
AutomationCtx
*
aut
;
FAutoCtx
*
aut
;
SArray
*
inp
;
FstOutput
emptyOutput
;
SArray
*
stack
;
// <StreamState>
FstBoundWithData
*
endAt
;
}
StreamWithState
;
}
FStmSt
;
typedef
struct
StreamWithStateResu
lt
{
typedef
struct
FStmStRs
lt
{
FstSlice
data
;
FstOutput
out
;
void
*
state
;
}
StreamWithStateResu
lt
;
}
FStmStRs
lt
;
StreamWithStateResu
lt
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
);
void
swsResultDestroy
(
StreamWithStateResu
lt
*
result
);
FStmStRs
lt
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
);
void
swsResultDestroy
(
FStmStRs
lt
*
result
);
typedef
void
*
(
*
StreamCallback
)(
void
*
);
StreamWithState
*
streamWithStateCreate
(
Fst
*
fst
,
AutomationCtx
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
);
FStmSt
*
stmStCreate
(
Fst
*
fst
,
FAutoCtx
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
);
void
st
reamWithStateDestroy
(
StreamWithState
*
sws
);
void
st
mStDestroy
(
FStmSt
*
sws
);
bool
st
reamWithStateSeekMin
(
StreamWithState
*
sws
,
FstBoundWithData
*
min
);
bool
st
mStSeekMin
(
FStmSt
*
sws
,
FstBoundWithData
*
min
);
StreamWithStateResult
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
);
FStmStRslt
*
stmStNextWith
(
FStmSt
*
sws
,
StreamCallback
callback
);
F
stStreamBuilder
*
fstStreamBuilderCreate
(
Fst
*
fst
,
Automation
Ctx
*
aut
);
F
StmBuilder
*
stmBuilderCreate
(
Fst
*
fst
,
FAuto
Ctx
*
aut
);
void
fstStreamBuilderDestroy
(
FstStrea
mBuilder
*
b
);
void
stmBuilderDestroy
(
FSt
mBuilder
*
b
);
// set up bound range
// refator later: to simple code by marco
void
fstStreamBuilderSetRange
(
FstStrea
mBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
);
void
stmBuilderSetRange
(
FSt
mBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
);
#ifdef __cplusplus
}
...
...
source/libs/index/inc/indexFstAutomation.h
浏览文件 @
dcc78597
...
...
@@ -22,24 +22,24 @@ extern "C" {
#include "indexFstUtil.h"
#include "indexInt.h"
typedef
struct
AutomationCtx
Automation
Ctx
;
typedef
struct
FAutoCtx
FAuto
Ctx
;
typedef
enum
AutomationType
{
AUTOMATION_ALWAYS
,
AUTOMATION_PREFIX
,
AUTMMATION_MATCH
}
AutomationType
;
typedef
struct
StartWith
{
Automation
Ctx
*
autoSelf
;
FAuto
Ctx
*
autoSelf
;
}
StartWith
;
typedef
struct
Complement
{
Automation
Ctx
*
autoSelf
;
FAuto
Ctx
*
autoSelf
;
}
Complement
;
// automation
typedef
struct
Automation
Ctx
{
typedef
struct
FAuto
Ctx
{
AutomationType
type
;
void
*
stdata
;
char
*
data
;
}
Automation
Ctx
;
}
FAuto
Ctx
;
typedef
enum
ValueType
{
FST_INT
,
FST_CHAR
,
FST_ARRAY
}
ValueType
;
typedef
enum
StartWithStateKind
{
Done
,
Running
}
StartWithStateKind
;
...
...
@@ -60,16 +60,16 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv);
void
startWithStateValueDestroy
(
void
*
sv
);
typedef
struct
AutomationFunc
{
void
*
(
*
start
)(
Automation
Ctx
*
ctx
);
bool
(
*
isMatch
)(
Automation
Ctx
*
ctx
,
void
*
);
bool
(
*
canMatch
)(
Automation
Ctx
*
ctx
,
void
*
data
);
bool
(
*
willAlwaysMatch
)(
Automation
Ctx
*
ctx
,
void
*
state
);
void
*
(
*
accept
)(
Automation
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
);
void
*
(
*
acceptEof
)(
Automation
Ctx
*
ct
,
void
*
state
);
void
*
(
*
start
)(
FAuto
Ctx
*
ctx
);
bool
(
*
isMatch
)(
FAuto
Ctx
*
ctx
,
void
*
);
bool
(
*
canMatch
)(
FAuto
Ctx
*
ctx
,
void
*
data
);
bool
(
*
willAlwaysMatch
)(
FAuto
Ctx
*
ctx
,
void
*
state
);
void
*
(
*
accept
)(
FAuto
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
);
void
*
(
*
acceptEof
)(
FAuto
Ctx
*
ct
,
void
*
state
);
}
AutomationFunc
;
Automation
Ctx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
);
void
automCtxDestroy
(
Automation
Ctx
*
ctx
);
FAuto
Ctx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
);
void
automCtxDestroy
(
FAuto
Ctx
*
ctx
);
extern
AutomationFunc
automFuncs
[];
#ifdef __cplusplus
...
...
source/libs/index/src/index.c
浏览文件 @
dcc78597
...
...
@@ -77,15 +77,15 @@ typedef struct SIdxColInfo {
static
TdThreadOnce
isInit
=
PTHREAD_ONCE_INIT
;
// static void indexInit();
static
int
i
nde
xTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
int
i
d
xTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
void
i
ndexInterResults
Destroy
(
SArray
*
results
);
static
int
i
nde
xMergeFinalResults
(
SArray
*
in
,
EIndexOperatorType
oType
,
SArray
*
out
);
static
void
i
dxInterRslt
Destroy
(
SArray
*
results
);
static
int
i
d
xMergeFinalResults
(
SArray
*
in
,
EIndexOperatorType
oType
,
SArray
*
out
);
static
int
i
nde
xGenTFile
(
SIndex
*
index
,
IndexCache
*
cache
,
SArray
*
batch
);
static
int
i
d
xGenTFile
(
SIndex
*
index
,
IndexCache
*
cache
,
SArray
*
batch
);
// merge cache and tfile by opera type
static
void
i
nde
xMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
icache
,
IterateValue
*
iTfv
,
SIdxTRslt
*
helper
);
static
void
i
d
xMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
icache
,
IterateValue
*
iTfv
,
SIdxTRslt
*
helper
);
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
// int32_t indexSerialKey(ICacheKey* key, char* buf);
...
...
@@ -221,11 +221,11 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result
for
(
size_t
i
=
0
;
i
<
nQuery
;
i
++
)
{
SIndexTermQuery
*
qterm
=
taosArrayGet
(
multiQuerys
->
query
,
i
);
SArray
*
trslt
=
NULL
;
i
nde
xTermSearch
(
index
,
qterm
,
&
trslt
);
i
d
xTermSearch
(
index
,
qterm
,
&
trslt
);
taosArrayPush
(
iRslts
,
(
void
*
)
&
trslt
);
}
i
nde
xMergeFinalResults
(
iRslts
,
opera
,
result
);
i
ndexInterResults
Destroy
(
iRslts
);
i
d
xMergeFinalResults
(
iRslts
,
opera
,
result
);
i
dxInterRslt
Destroy
(
iRslts
);
return
0
;
}
...
...
@@ -319,7 +319,7 @@ void indexMultiTermDestroy(SIndexMultiTerm* terms) {
taosArrayDestroy
(
terms
);
}
static
int
i
nde
xTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
query
,
SArray
**
result
)
{
static
int
i
d
xTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
query
,
SArray
**
result
)
{
SIndexTerm
*
term
=
query
->
term
;
const
char
*
colName
=
term
->
colName
;
int32_t
nColName
=
term
->
nColName
;
...
...
@@ -374,7 +374,7 @@ END:
idxTRsltDestroy
(
tr
);
return
-
1
;
}
static
void
i
ndexInterResults
Destroy
(
SArray
*
results
)
{
static
void
i
dxInterRslt
Destroy
(
SArray
*
results
)
{
if
(
results
==
NULL
)
{
return
;
}
...
...
@@ -387,7 +387,7 @@ static void indexInterResultsDestroy(SArray* results) {
taosArrayDestroy
(
results
);
}
static
int
i
nde
xMergeFinalResults
(
SArray
*
in
,
EIndexOperatorType
oType
,
SArray
*
out
)
{
static
int
i
d
xMergeFinalResults
(
SArray
*
in
,
EIndexOperatorType
oType
,
SArray
*
out
)
{
// refactor, merge interResults into fResults by oType
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
in
);
i
--
)
{
SArray
*
t
=
taosArrayGetP
(
in
,
i
);
...
...
@@ -407,7 +407,7 @@ static int indexMergeFinalResults(SArray* in, EIndexOperatorType oType, SArray*
return
0
;
}
static
void
i
ndexMayMergeTempToFinalResu
lt
(
SArray
*
result
,
TFileValue
*
tfv
,
SIdxTRslt
*
tr
)
{
static
void
i
dxMayMergeTempToFinalRs
lt
(
SArray
*
result
,
TFileValue
*
tfv
,
SIdxTRslt
*
tr
)
{
int32_t
sz
=
taosArrayGetSize
(
result
);
if
(
sz
>
0
)
{
TFileValue
*
lv
=
taosArrayGetP
(
result
,
sz
-
1
);
...
...
@@ -427,11 +427,11 @@ static void indexMayMergeTempToFinalResult(SArray* result, TFileValue* tfv, SIdx
taosArrayPush
(
result
,
&
tfv
);
}
}
static
void
i
nde
xMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
cv
,
IterateValue
*
tv
,
SIdxTRslt
*
tr
)
{
static
void
i
d
xMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
cv
,
IterateValue
*
tv
,
SIdxTRslt
*
tr
)
{
char
*
colVal
=
(
cv
!=
NULL
)
?
cv
->
colVal
:
tv
->
colVal
;
TFileValue
*
tfv
=
tfileValueCreate
(
colVal
);
i
ndexMayMergeTempToFinalResu
lt
(
result
,
tfv
,
tr
);
i
dxMayMergeTempToFinalRs
lt
(
result
,
tfv
,
tr
);
if
(
cv
!=
NULL
)
{
uint64_t
id
=
*
(
uint64_t
*
)
taosArrayGet
(
cv
->
val
,
0
);
...
...
@@ -446,7 +446,7 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateVal
taosArrayAddAll
(
tr
->
total
,
tv
->
val
);
}
}
static
void
i
ndexDestroyFinalResu
lt
(
SArray
*
result
)
{
static
void
i
dxDestroyFinalRs
lt
(
SArray
*
result
)
{
int32_t
sz
=
result
?
taosArrayGetSize
(
result
)
:
0
;
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
TFileValue
*
tv
=
taosArrayGetP
(
result
,
i
);
...
...
@@ -475,7 +475,7 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
Iterate
*
cacheIter
=
indexCacheIteratorCreate
(
pCache
);
if
(
cacheIter
==
NULL
)
{
indexError
(
"%p immtable is empty, ignore merge opera"
,
pCache
);
i
nde
xCacheDestroyImm
(
pCache
);
i
d
xCacheDestroyImm
(
pCache
);
tfileReaderUnRef
(
pReader
);
atomic_store_32
(
&
pCache
->
merging
,
0
);
if
(
quit
)
{
...
...
@@ -509,26 +509,26 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
comp
=
1
;
}
if
(
comp
==
0
)
{
i
nde
xMergeCacheAndTFile
(
result
,
cv
,
tv
,
tr
);
i
d
xMergeCacheAndTFile
(
result
,
cv
,
tv
,
tr
);
cn
=
cacheIter
->
next
(
cacheIter
);
tn
=
tfileIter
->
next
(
tfileIter
);
}
else
if
(
comp
<
0
)
{
i
nde
xMergeCacheAndTFile
(
result
,
cv
,
NULL
,
tr
);
i
d
xMergeCacheAndTFile
(
result
,
cv
,
NULL
,
tr
);
cn
=
cacheIter
->
next
(
cacheIter
);
}
else
{
i
nde
xMergeCacheAndTFile
(
result
,
NULL
,
tv
,
tr
);
i
d
xMergeCacheAndTFile
(
result
,
NULL
,
tv
,
tr
);
tn
=
tfileIter
->
next
(
tfileIter
);
}
}
i
ndexMayMergeTempToFinalResu
lt
(
result
,
NULL
,
tr
);
i
dxMayMergeTempToFinalRs
lt
(
result
,
NULL
,
tr
);
idxTRsltDestroy
(
tr
);
int
ret
=
i
nde
xGenTFile
(
sIdx
,
pCache
,
result
);
i
ndexDestroyFinalResu
lt
(
result
);
int
ret
=
i
d
xGenTFile
(
sIdx
,
pCache
,
result
);
i
dxDestroyFinalRs
lt
(
result
);
i
nde
xCacheDestroyImm
(
pCache
);
i
d
xCacheDestroyImm
(
pCache
);
i
nde
xCacheIteratorDestroy
(
cacheIter
);
i
d
xCacheIteratorDestroy
(
cacheIter
);
tfileIteratorDestroy
(
tfileIter
);
tfileReaderUnRef
(
pReader
);
...
...
@@ -578,7 +578,7 @@ static int64_t indexGetAvaialbleVer(SIndex* sIdx, IndexCache* cache) {
tfileReaderUnRef
(
rd
);
return
ver
;
}
static
int
i
nde
xGenTFile
(
SIndex
*
sIdx
,
IndexCache
*
cache
,
SArray
*
batch
)
{
static
int
i
d
xGenTFile
(
SIndex
*
sIdx
,
IndexCache
*
cache
,
SArray
*
batch
)
{
int64_t
version
=
indexGetAvaialbleVer
(
sIdx
,
cache
);
indexInfo
(
"file name version: %"
PRId64
""
,
version
);
uint8_t
colType
=
cache
->
type
;
...
...
source/libs/index/src/indexCache.c
浏览文件 @
dcc78597
...
...
@@ -26,15 +26,15 @@
#define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20
#define MEM_ESTIMATE_RADIO 1.5
static
void
i
nde
xMemRef
(
MemTable
*
tbl
);
static
void
i
nde
xMemUnRef
(
MemTable
*
tbl
);
static
void
i
d
xMemRef
(
MemTable
*
tbl
);
static
void
i
d
xMemUnRef
(
MemTable
*
tbl
);
static
void
i
nde
xCacheTermDestroy
(
CacheTerm
*
ct
);
static
int32_t
i
nde
xCacheTermCompare
(
const
void
*
l
,
const
void
*
r
);
static
int32_t
i
nde
xCacheJsonTermCompare
(
const
void
*
l
,
const
void
*
r
);
static
char
*
i
nde
xCacheTermGet
(
const
void
*
pData
);
static
void
i
d
xCacheTermDestroy
(
CacheTerm
*
ct
);
static
int32_t
i
d
xCacheTermCompare
(
const
void
*
l
,
const
void
*
r
);
static
int32_t
i
d
xCacheJsonTermCompare
(
const
void
*
l
,
const
void
*
r
);
static
char
*
i
d
xCacheTermGet
(
const
void
*
pData
);
static
MemTable
*
i
nde
xInternalCacheCreate
(
int8_t
type
);
static
MemTable
*
i
d
xInternalCacheCreate
(
int8_t
type
);
static
int32_t
cacheSearchTerm
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchPrefix
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
...
...
@@ -81,7 +81,7 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe
pCt
->
colVal
=
term
->
colVal
;
pCt
->
version
=
atomic_load_64
(
&
pCache
->
version
);
char
*
key
=
i
nde
xCacheTermGet
(
pCt
);
char
*
key
=
i
d
xCacheTermGet
(
pCt
);
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
while
(
tSkipListIterNext
(
iter
))
{
...
...
@@ -134,7 +134,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt*
pCt
->
colType
=
term
->
colType
;
pCt
->
version
=
atomic_load_64
(
&
pCache
->
version
);
char
*
key
=
i
nde
xCacheTermGet
(
pCt
);
char
*
key
=
i
d
xCacheTermGet
(
pCt
);
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
mem
->
mem
);
while
(
tSkipListIterNext
(
iter
))
{
...
...
@@ -188,10 +188,10 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr
char
*
exBuf
=
NULL
;
if
(
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
exBuf
=
i
nde
xPackJsonData
(
term
);
exBuf
=
i
d
xPackJsonData
(
term
);
pCt
->
colVal
=
exBuf
;
}
char
*
key
=
i
nde
xCacheTermGet
(
pCt
);
char
*
key
=
i
d
xCacheTermGet
(
pCt
);
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
while
(
tSkipListIterNext
(
iter
))
{
...
...
@@ -268,10 +268,10 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
char
*
exBuf
=
NULL
;
if
(
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
term
->
colType
,
TSDB_DATA_TYPE_JSON
))
{
exBuf
=
i
nde
xPackJsonDataPrefix
(
term
,
&
skip
);
exBuf
=
i
d
xPackJsonDataPrefix
(
term
,
&
skip
);
pCt
->
colVal
=
exBuf
;
}
char
*
key
=
i
nde
xCacheTermGet
(
pCt
);
char
*
key
=
i
d
xCacheTermGet
(
pCt
);
// SSkipListIterator* iter = tSkipListCreateIter(mem->mem);
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
mem
->
mem
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
...
...
@@ -324,7 +324,7 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
return
NULL
;
};
cache
->
mem
=
i
nde
xInternalCacheCreate
(
type
);
cache
->
mem
=
i
d
xInternalCacheCreate
(
type
);
cache
->
mem
->
pCache
=
cache
;
cache
->
colName
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
tstrdup
(
JSON_COLUMN
)
:
tstrdup
(
colName
);
cache
->
type
=
type
;
...
...
@@ -347,7 +347,7 @@ void indexCacheDebug(IndexCache* cache) {
taosThreadMutexLock
(
&
cache
->
mtx
);
tbl
=
cache
->
mem
;
i
nde
xMemRef
(
tbl
);
i
d
xMemRef
(
tbl
);
taosThreadMutexUnlock
(
&
cache
->
mtx
);
{
...
...
@@ -363,13 +363,13 @@ void indexCacheDebug(IndexCache* cache) {
}
tSkipListDestroyIter
(
iter
);
i
nde
xMemUnRef
(
tbl
);
i
d
xMemUnRef
(
tbl
);
}
{
taosThreadMutexLock
(
&
cache
->
mtx
);
tbl
=
cache
->
imm
;
i
nde
xMemRef
(
tbl
);
i
d
xMemRef
(
tbl
);
taosThreadMutexUnlock
(
&
cache
->
mtx
);
if
(
tbl
!=
NULL
)
{
SSkipList
*
slt
=
tbl
->
mem
;
...
...
@@ -385,7 +385,7 @@ void indexCacheDebug(IndexCache* cache) {
tSkipListDestroyIter
(
iter
);
}
i
nde
xMemUnRef
(
tbl
);
i
d
xMemUnRef
(
tbl
);
}
}
...
...
@@ -410,7 +410,7 @@ void indexCacheWait(void* cache) {
IndexCache
*
pCache
=
cache
;
taosThreadCondWait
(
&
pCache
->
finished
,
&
pCache
->
mtx
);
}
void
i
nde
xCacheDestroyImm
(
IndexCache
*
cache
)
{
void
i
d
xCacheDestroyImm
(
IndexCache
*
cache
)
{
if
(
cache
==
NULL
)
{
return
;
}
...
...
@@ -423,8 +423,8 @@ void indexCacheDestroyImm(IndexCache* cache) {
taosThreadMutexUnlock
(
&
cache
->
mtx
);
i
nde
xMemUnRef
(
tbl
);
i
nde
xMemUnRef
(
tbl
);
i
d
xMemUnRef
(
tbl
);
i
d
xMemUnRef
(
tbl
);
}
void
indexCacheDestroy
(
void
*
cache
)
{
IndexCache
*
pCache
=
cache
;
...
...
@@ -432,8 +432,8 @@ void indexCacheDestroy(void* cache) {
return
;
}
i
nde
xMemUnRef
(
pCache
->
mem
);
i
nde
xMemUnRef
(
pCache
->
imm
);
i
d
xMemUnRef
(
pCache
->
mem
);
i
d
xMemUnRef
(
pCache
->
imm
);
taosMemoryFree
(
pCache
->
colName
);
taosThreadMutexDestroy
(
&
pCache
->
mtx
);
...
...
@@ -454,7 +454,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
}
taosThreadMutexLock
(
&
cache
->
mtx
);
i
nde
xMemRef
(
cache
->
imm
);
i
d
xMemRef
(
cache
->
imm
);
MemTable
*
tbl
=
cache
->
imm
;
iiter
->
val
.
val
=
taosArrayInit
(
1
,
sizeof
(
uint64_t
));
...
...
@@ -467,7 +467,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
return
iiter
;
}
void
i
nde
xCacheIteratorDestroy
(
Iterate
*
iter
)
{
void
i
d
xCacheIteratorDestroy
(
Iterate
*
iter
)
{
if
(
iter
==
NULL
)
{
return
;
}
...
...
@@ -501,7 +501,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
indexCacheRef
(
cache
);
cache
->
imm
=
cache
->
mem
;
cache
->
mem
=
i
nde
xInternalCacheCreate
(
cache
->
type
);
cache
->
mem
=
i
d
xInternalCacheCreate
(
cache
->
type
);
cache
->
mem
->
pCache
=
cache
;
cache
->
occupiedMem
=
0
;
if
(
quit
==
false
)
{
...
...
@@ -529,7 +529,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
// set up key
ct
->
colType
=
term
->
colType
;
if
(
hasJson
)
{
ct
->
colVal
=
i
nde
xPackJsonData
(
term
);
ct
->
colVal
=
i
d
xPackJsonData
(
term
);
}
else
{
ct
->
colVal
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
(
term
->
nColVal
+
1
));
memcpy
(
ct
->
colVal
,
term
->
colVal
,
term
->
nColVal
);
...
...
@@ -545,9 +545,9 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
pCache
->
occupiedMem
+=
estimate
;
indexCacheMakeRoomForWrite
(
pCache
);
MemTable
*
tbl
=
pCache
->
mem
;
i
nde
xMemRef
(
tbl
);
i
d
xMemRef
(
tbl
);
tSkipListPut
(
tbl
->
mem
,
(
char
*
)
ct
);
i
nde
xMemUnRef
(
tbl
);
i
d
xMemUnRef
(
tbl
);
taosThreadMutexUnlock
(
&
pCache
->
mtx
);
...
...
@@ -598,8 +598,8 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe
taosThreadMutexLock
(
&
pCache
->
mtx
);
mem
=
pCache
->
mem
;
imm
=
pCache
->
imm
;
i
nde
xMemRef
(
mem
);
i
nde
xMemRef
(
imm
);
i
d
xMemRef
(
mem
);
i
d
xMemRef
(
imm
);
taosThreadMutexUnlock
(
&
pCache
->
mtx
);
int
ret
=
(
mem
&&
mem
->
mem
)
?
indexQueryMem
(
mem
,
query
,
result
,
s
)
:
0
;
...
...
@@ -608,8 +608,8 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe
ret
=
(
imm
&&
imm
->
mem
)
?
indexQueryMem
(
imm
,
query
,
result
,
s
)
:
0
;
}
i
nde
xMemUnRef
(
mem
);
i
nde
xMemUnRef
(
imm
);
i
d
xMemUnRef
(
mem
);
i
d
xMemUnRef
(
imm
);
indexInfo
(
"cache search, time cost %"
PRIu64
"us"
,
taosGetTimestampUs
()
-
st
);
return
ret
;
...
...
@@ -632,14 +632,14 @@ void indexCacheUnRef(IndexCache* cache) {
}
}
void
i
nde
xMemRef
(
MemTable
*
tbl
)
{
void
i
d
xMemRef
(
MemTable
*
tbl
)
{
if
(
tbl
==
NULL
)
{
return
;
}
int
ref
=
T_REF_INC
(
tbl
);
UNUSED
(
ref
);
}
void
i
nde
xMemUnRef
(
MemTable
*
tbl
)
{
void
i
d
xMemUnRef
(
MemTable
*
tbl
)
{
if
(
tbl
==
NULL
)
{
return
;
}
...
...
@@ -651,18 +651,18 @@ void indexMemUnRef(MemTable* tbl) {
}
}
static
void
i
nde
xCacheTermDestroy
(
CacheTerm
*
ct
)
{
static
void
i
d
xCacheTermDestroy
(
CacheTerm
*
ct
)
{
if
(
ct
==
NULL
)
{
return
;
}
taosMemoryFree
(
ct
->
colVal
);
taosMemoryFree
(
ct
);
}
static
char
*
i
nde
xCacheTermGet
(
const
void
*
pData
)
{
static
char
*
i
d
xCacheTermGet
(
const
void
*
pData
)
{
CacheTerm
*
p
=
(
CacheTerm
*
)
pData
;
return
(
char
*
)
p
;
}
static
int32_t
i
nde
xCacheTermCompare
(
const
void
*
l
,
const
void
*
r
)
{
static
int32_t
i
d
xCacheTermCompare
(
const
void
*
l
,
const
void
*
r
)
{
CacheTerm
*
lt
=
(
CacheTerm
*
)
l
;
CacheTerm
*
rt
=
(
CacheTerm
*
)
r
;
// compare colVal
...
...
@@ -683,7 +683,7 @@ static int indexFindCh(char* a, char c) {
}
return
p
-
a
;
}
static
int
i
nde
xCacheJsonTermCompareImpl
(
char
*
a
,
char
*
b
)
{
static
int
i
d
xCacheJsonTermCompareImpl
(
char
*
a
,
char
*
b
)
{
// int alen = indexFindCh(a, '&');
// int blen = indexFindCh(b, '&');
...
...
@@ -703,7 +703,7 @@ static int indexCacheJsonTermCompareImpl(char* a, char* b) {
//}
return
0
;
}
static
int32_t
i
nde
xCacheJsonTermCompare
(
const
void
*
l
,
const
void
*
r
)
{
static
int32_t
i
d
xCacheJsonTermCompare
(
const
void
*
l
,
const
void
*
r
)
{
CacheTerm
*
lt
=
(
CacheTerm
*
)
l
;
CacheTerm
*
rt
=
(
CacheTerm
*
)
r
;
// compare colVal
...
...
@@ -713,16 +713,15 @@ static int32_t indexCacheJsonTermCompare(const void* l, const void* r) {
}
return
cmp
;
}
static
MemTable
*
i
nde
xInternalCacheCreate
(
int8_t
type
)
{
static
MemTable
*
i
d
xInternalCacheCreate
(
int8_t
type
)
{
int
ttype
=
INDEX_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
)
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
i
ndexCacheJsonTermCompare
:
inde
xCacheTermCompare
;
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
i
dxCacheJsonTermCompare
:
id
xCacheTermCompare
;
MemTable
*
tbl
=
taosMemoryCalloc
(
1
,
sizeof
(
MemTable
));
i
nde
xMemRef
(
tbl
);
i
d
xMemRef
(
tbl
);
if
(
ttype
==
TSDB_DATA_TYPE_BINARY
||
ttype
==
TSDB_DATA_TYPE_NCHAR
)
{
tbl
->
mem
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
ttype
,
MAX_INDEX_KEY_LEN
,
cmpFn
,
SL_ALLOW_DUP_KEY
,
indexCacheTermGet
);
tbl
->
mem
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
ttype
,
MAX_INDEX_KEY_LEN
,
cmpFn
,
SL_ALLOW_DUP_KEY
,
idxCacheTermGet
);
}
return
tbl
;
}
...
...
source/libs/index/src/indexComm.c
浏览文件 @
dcc78597
...
...
@@ -201,7 +201,7 @@ static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {
_cache_range_compare
indexGetCompare
(
RangeType
ty
)
{
return
rangeCompare
[
ty
];
}
char
*
i
nde
xPackJsonData
(
SIndexTerm
*
itm
)
{
char
*
i
d
xPackJsonData
(
SIndexTerm
*
itm
)
{
/*
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
...
...
@@ -229,7 +229,7 @@ char* indexPackJsonData(SIndexTerm* itm) {
return
buf
;
}
char
*
i
nde
xPackJsonDataPrefix
(
SIndexTerm
*
itm
,
int32_t
*
skip
)
{
char
*
i
d
xPackJsonDataPrefix
(
SIndexTerm
*
itm
,
int32_t
*
skip
)
{
/*
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
...
...
source/libs/index/src/indexFst.c
浏览文件 @
dcc78597
...
...
@@ -1087,19 +1087,19 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
*
out
=
tOut
;
return
true
;
}
F
stStreamBuilder
*
fstSearch
(
Fst
*
fst
,
Automation
Ctx
*
ctx
)
{
F
StmBuilder
*
fstSearch
(
Fst
*
fst
,
FAuto
Ctx
*
ctx
)
{
// refactor later
return
fstStrea
mBuilderCreate
(
fst
,
ctx
);
return
st
mBuilderCreate
(
fst
,
ctx
);
}
StreamWithState
*
streamBuilderIntoStream
(
FstStrea
mBuilder
*
sb
)
{
FStmSt
*
stmBuilderIntoStm
(
FSt
mBuilder
*
sb
)
{
if
(
sb
==
NULL
)
{
return
NULL
;
}
return
st
reamWithState
Create
(
sb
->
fst
,
sb
->
aut
,
sb
->
min
,
sb
->
max
);
return
st
mSt
Create
(
sb
->
fst
,
sb
->
aut
,
sb
->
min
,
sb
->
max
);
}
F
stStreamWithStateBuilder
*
fstSearchWithState
(
Fst
*
fst
,
Automation
Ctx
*
ctx
)
{
F
StmStBuilder
*
fstSearchWithState
(
Fst
*
fst
,
FAuto
Ctx
*
ctx
)
{
// refactor later
return
fstStrea
mBuilderCreate
(
fst
,
ctx
);
return
st
mBuilderCreate
(
fst
,
ctx
);
}
FstNode
*
fstGetRoot
(
Fst
*
fst
)
{
...
...
@@ -1176,9 +1176,8 @@ bool fstBoundWithDataIsIncluded(FstBoundWithData* bound) { return bound->type ==
void
fstBoundDestroy
(
FstBoundWithData
*
bound
)
{
taosMemoryFree
(
bound
);
}
StreamWithState
*
streamWithStateCreate
(
Fst
*
fst
,
AutomationCtx
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
)
{
StreamWithState
*
sws
=
taosMemoryCalloc
(
1
,
sizeof
(
StreamWithState
));
FStmSt
*
stmStCreate
(
Fst
*
fst
,
FAutoCtx
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
)
{
FStmSt
*
sws
=
taosMemoryCalloc
(
1
,
sizeof
(
FStmSt
));
if
(
sws
==
NULL
)
{
return
NULL
;
}
...
...
@@ -1192,11 +1191,11 @@ StreamWithState* streamWithStateCreate(Fst* fst, AutomationCtx* automation, FstB
sws
->
stack
=
(
SArray
*
)
taosArrayInit
(
256
,
sizeof
(
StreamState
));
sws
->
endAt
=
max
;
st
reamWithState
SeekMin
(
sws
,
min
);
st
mSt
SeekMin
(
sws
,
min
);
return
sws
;
}
void
st
reamWithStateDestroy
(
StreamWithState
*
sws
)
{
void
st
mStDestroy
(
FStmSt
*
sws
)
{
if
(
sws
==
NULL
)
{
return
;
}
...
...
@@ -1207,8 +1206,8 @@ void streamWithStateDestroy(StreamWithState* sws) {
taosMemoryFree
(
sws
);
}
bool
st
reamWithStateSeekMin
(
StreamWithState
*
sws
,
FstBoundWithData
*
min
)
{
Automation
Ctx
*
aut
=
sws
->
aut
;
bool
st
mStSeekMin
(
FStmSt
*
sws
,
FstBoundWithData
*
min
)
{
FAuto
Ctx
*
aut
=
sws
->
aut
;
if
(
fstBoundWithDataIsEmpty
(
min
))
{
if
(
fstBoundWithDataIsIncluded
(
min
))
{
sws
->
emptyOutput
.
out
=
fstEmptyFinalOutput
(
sws
->
fst
,
&
(
sws
->
emptyOutput
.
null
));
...
...
@@ -1301,9 +1300,9 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) {
return
false
;
}
StreamWithStateResult
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
)
{
Automation
Ctx
*
aut
=
sws
->
aut
;
FstOutput
output
=
sws
->
emptyOutput
;
FStmStRslt
*
stmStNextWith
(
FStmSt
*
sws
,
StreamCallback
callback
)
{
FAuto
Ctx
*
aut
=
sws
->
aut
;
FstOutput
output
=
sws
->
emptyOutput
;
if
(
output
.
null
==
false
)
{
FstSlice
emptySlice
=
fstSliceCreate
(
NULL
,
0
);
if
(
fstBoundWithDataExceededBy
(
sws
->
endAt
,
&
emptySlice
))
{
...
...
@@ -1367,8 +1366,8 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb
return
NULL
;
}
if
(
FST_NODE_IS_FINAL
(
nextNode
)
&&
isMatch
)
{
FstOutput
fOutput
=
{.
null
=
false
,
.
out
=
out
+
FST_NODE_FINAL_OUTPUT
(
nextNode
)};
StreamWithStateResu
lt
*
result
=
swsResultCreate
(
&
slice
,
fOutput
,
tState
);
FstOutput
fOutput
=
{.
null
=
false
,
.
out
=
out
+
FST_NODE_FINAL_OUTPUT
(
nextNode
)};
FStmStRs
lt
*
result
=
swsResultCreate
(
&
slice
,
fOutput
,
tState
);
taosMemoryFreeClear
(
buf
);
fstSliceDestroy
(
&
slice
);
taosArrayDestroy
(
nodes
);
...
...
@@ -1382,8 +1381,8 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb
return
NULL
;
}
StreamWithStateResu
lt
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
)
{
StreamWithStateResult
*
result
=
taosMemoryCalloc
(
1
,
sizeof
(
StreamWithStateResu
lt
));
FStmStRs
lt
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
)
{
FStmStRslt
*
result
=
taosMemoryCalloc
(
1
,
sizeof
(
FStmStRs
lt
));
if
(
result
==
NULL
)
{
return
NULL
;
}
...
...
@@ -1393,7 +1392,7 @@ StreamWithStateResult* swsResultCreate(FstSlice* data, FstOutput fOut, void* sta
result
->
state
=
state
;
return
result
;
}
void
swsResultDestroy
(
StreamWithStateResu
lt
*
result
)
{
void
swsResultDestroy
(
FStmStRs
lt
*
result
)
{
if
(
NULL
==
result
)
{
return
;
}
...
...
@@ -1411,8 +1410,8 @@ void streamStateDestroy(void* s) {
fstNodeDestroy
(
ss
->
node
);
}
F
stStreamBuilder
*
fstStreamBuilderCreate
(
Fst
*
fst
,
Automation
Ctx
*
aut
)
{
F
stStreamBuilder
*
b
=
taosMemoryCalloc
(
1
,
sizeof
(
FstStrea
mBuilder
));
F
StmBuilder
*
stmBuilderCreate
(
Fst
*
fst
,
FAuto
Ctx
*
aut
)
{
F
StmBuilder
*
b
=
taosMemoryCalloc
(
1
,
sizeof
(
FSt
mBuilder
));
if
(
NULL
==
b
)
{
return
NULL
;
}
...
...
@@ -1423,14 +1422,14 @@ FstStreamBuilder* fstStreamBuilderCreate(Fst* fst, AutomationCtx* aut) {
b
->
max
=
fstBoundStateCreate
(
Unbounded
,
NULL
);
return
b
;
}
void
fstStreamBuilderDestroy
(
FstStrea
mBuilder
*
b
)
{
void
stmBuilderDestroy
(
FSt
mBuilder
*
b
)
{
fstSliceDestroy
(
&
b
->
min
->
data
);
fstSliceDestroy
(
&
b
->
max
->
data
);
taosMemoryFreeClear
(
b
->
min
);
taosMemoryFreeClear
(
b
->
max
);
taosMemoryFree
(
b
);
}
void
fstStreamBuilderSetRange
(
FstStrea
mBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
)
{
void
stmBuilderSetRange
(
FSt
mBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
)
{
if
(
b
==
NULL
)
{
return
;
}
...
...
source/libs/index/src/indexFstAutomation.c
浏览文件 @
dcc78597
...
...
@@ -71,19 +71,19 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) {
}
// iterate fst
static
void
*
alwaysMatchStart
(
Automation
Ctx
*
ctx
)
{
return
NULL
;
}
static
bool
alwaysMatchIsMatch
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
bool
alwaysMatchCanMatch
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
bool
alwaysMatchWillAlwaysMatch
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
alwaysMatchAccpet
(
Automation
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
static
void
*
alwaysMatchAccpetEof
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
static
void
*
alwaysMatchStart
(
FAuto
Ctx
*
ctx
)
{
return
NULL
;
}
static
bool
alwaysMatchIsMatch
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
bool
alwaysMatchCanMatch
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
bool
alwaysMatchWillAlwaysMatch
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
alwaysMatchAccpet
(
FAuto
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
static
void
*
alwaysMatchAccpetEof
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
// prefix query, impl later
static
void
*
prefixStart
(
Automation
Ctx
*
ctx
)
{
static
void
*
prefixStart
(
FAuto
Ctx
*
ctx
)
{
StartWithStateValue
*
data
=
(
StartWithStateValue
*
)(
ctx
->
stdata
);
return
startWithStateValueDump
(
data
);
};
static
bool
prefixIsMatch
(
Automation
Ctx
*
ctx
,
void
*
sv
)
{
static
bool
prefixIsMatch
(
FAuto
Ctx
*
ctx
,
void
*
sv
)
{
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
if
(
ssv
==
NULL
)
{
return
false
;
...
...
@@ -94,15 +94,15 @@ static bool prefixIsMatch(AutomationCtx* ctx, void* sv) {
return
false
;
}
}
static
bool
prefixCanMatch
(
Automation
Ctx
*
ctx
,
void
*
sv
)
{
static
bool
prefixCanMatch
(
FAuto
Ctx
*
ctx
,
void
*
sv
)
{
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
if
(
ssv
==
NULL
)
{
return
false
;
}
return
ssv
->
val
>=
0
;
}
static
bool
prefixWillAlwaysMatch
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
prefixAccept
(
Automation
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
static
bool
prefixWillAlwaysMatch
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
prefixAccept
(
FAuto
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
state
;
if
(
ssv
==
NULL
||
ctx
==
NULL
)
{
return
NULL
;
...
...
@@ -125,18 +125,18 @@ static void* prefixAccept(AutomationCtx* ctx, void* state, uint8_t byte) {
}
return
NULL
;
}
static
void
*
prefixAcceptEof
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
static
void
*
prefixAcceptEof
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
// pattern query, impl later
static
void
*
patternStart
(
Automation
Ctx
*
ctx
)
{
return
NULL
;
}
static
bool
patternIsMatch
(
Automation
Ctx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternCanMatch
(
Automation
Ctx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternWillAlwaysMatch
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
patternStart
(
FAuto
Ctx
*
ctx
)
{
return
NULL
;
}
static
bool
patternIsMatch
(
FAuto
Ctx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternCanMatch
(
FAuto
Ctx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternWillAlwaysMatch
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
patternAccept
(
Automation
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
static
void
*
patternAccept
(
FAuto
Ctx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
static
void
*
patternAcceptEof
(
Automation
Ctx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
static
void
*
patternAcceptEof
(
FAuto
Ctx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
AutomationFunc
automFuncs
[]
=
{
{
alwaysMatchStart
,
alwaysMatchIsMatch
,
alwaysMatchCanMatch
,
alwaysMatchWillAlwaysMatch
,
alwaysMatchAccpet
,
...
...
@@ -146,8 +146,8 @@ AutomationFunc automFuncs[] = {
// add more search type
};
Automation
Ctx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
)
{
AutomationCtx
*
ctx
=
taosMemoryCalloc
(
1
,
sizeof
(
Automation
Ctx
));
FAuto
Ctx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
)
{
FAutoCtx
*
ctx
=
taosMemoryCalloc
(
1
,
sizeof
(
FAuto
Ctx
));
if
(
ctx
==
NULL
)
{
return
NULL
;
}
...
...
@@ -169,7 +169,7 @@ AutomationCtx* automCtxCreate(void* data, AutomationType atype) {
ctx
->
stdata
=
(
void
*
)
sv
;
return
ctx
;
}
void
automCtxDestroy
(
Automation
Ctx
*
ctx
)
{
void
automCtxDestroy
(
FAuto
Ctx
*
ctx
)
{
startWithStateValueDestroy
(
ctx
->
stdata
);
taosMemoryFree
(
ctx
->
data
);
taosMemoryFree
(
ctx
);
...
...
source/libs/index/src/indexTfile.c
浏览文件 @
dcc78597
...
...
@@ -26,15 +26,14 @@
const
static
uint64_t
tfileMagicNumber
=
0xdb4775248b80fb57ull
;
typedef
struct
TFileFstIter
{
F
stStrea
mBuilder
*
fb
;
StreamWithState
*
st
;
Automation
Ctx
*
ctx
;
TFileReader
*
rdr
;
F
St
mBuilder
*
fb
;
FStmSt
*
st
;
FAuto
Ctx
*
ctx
;
TFileReader
*
rdr
;
}
TFileFstIter
;
#define TF_TABLE_TATOAL_SIZE(sz) (sizeof(sz) + sz * sizeof(uint64_t))
static
int
tfileUidCompare
(
const
void
*
a
,
const
void
*
b
);
static
int
tfileStrCompare
(
const
void
*
a
,
const
void
*
b
);
static
int
tfileValueCompare
(
const
void
*
a
,
const
void
*
b
,
const
void
*
param
);
static
void
tfileSerialTableIdsToBuf
(
char
*
buf
,
SArray
*
tableIds
);
...
...
@@ -244,26 +243,21 @@ static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
}
static
int32_t
tfSearchPrefix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxTRslt
*
tr
)
{
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
char
*
p
=
tem
->
colVal
;
uint64_t
sz
=
tem
->
nColVal
;
if
(
hasJson
)
{
p
=
indexPackJsonData
(
tem
);
sz
=
strlen
(
p
);
}
SArray
*
offsets
=
taosArrayInit
(
16
,
sizeof
(
uint64_t
));
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
p
,
AUTOMATION_PREFIX
);
F
stStreamBuilder
*
sb
=
fstSearch
(((
TFileReader
*
)
reader
)
->
fst
,
ctx
);
StreamWithState
*
st
=
streamBuilderIntoStrea
m
(
sb
);
StreamWithStateResult
*
rt
=
NULL
;
while
((
rt
=
st
reamWithState
NextWith
(
st
,
NULL
))
!=
NULL
)
{
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
p
,
AUTOMATION_PREFIX
);
F
StmBuilder
*
sb
=
fstSearch
(((
TFileReader
*
)
reader
)
->
fst
,
ctx
);
FStmSt
*
st
=
stmBuilderIntoSt
m
(
sb
);
FStmStRslt
*
rt
=
NULL
;
while
((
rt
=
st
mSt
NextWith
(
st
,
NULL
))
!=
NULL
)
{
taosArrayPush
(
offsets
,
&
(
rt
->
out
.
out
));
swsResultDestroy
(
rt
);
}
st
reamWithState
Destroy
(
st
);
fstStrea
mBuilderDestroy
(
sb
);
st
mSt
Destroy
(
st
);
st
mBuilderDestroy
(
sb
);
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
offsets
);
i
++
)
{
...
...
@@ -274,27 +268,14 @@ static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
return
TSDB_CODE_TDB_FILE_CORRUPTED
;
}
}
if
(
hasJson
)
{
taosMemoryFree
(
p
);
}
return
0
;
}
static
int32_t
tfSearchSuffix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxTRslt
*
tr
)
{
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
int
ret
=
0
;
char
*
p
=
tem
->
colVal
;
uint64_t
sz
=
tem
->
nColVal
;
if
(
hasJson
)
{
p
=
indexPackJsonData
(
tem
);
sz
=
strlen
(
p
);
}
int64_t
st
=
taosGetTimestampUs
();
FstSlice
key
=
fstSliceCreate
(
p
,
sz
);
/*impl later*/
if
(
hasJson
)
{
taosMemoryFree
(
p
);
}
fstSliceDestroy
(
&
key
);
return
0
;
}
...
...
@@ -305,7 +286,7 @@ static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
char
*
p
=
tem
->
colVal
;
uint64_t
sz
=
tem
->
nColVal
;
if
(
hasJson
)
{
p
=
i
nde
xPackJsonData
(
tem
);
p
=
i
d
xPackJsonData
(
tem
);
sz
=
strlen
(
p
);
}
int64_t
st
=
taosGetTimestampUs
();
...
...
@@ -327,16 +308,16 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr,
SArray
*
offsets
=
taosArrayInit
(
16
,
sizeof
(
uint64_t
));
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
p
,
AUTOMATION_ALWAYS
);
F
stStrea
mBuilder
*
sb
=
fstSearch
(((
TFileReader
*
)
reader
)
->
fst
,
ctx
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
p
,
AUTOMATION_ALWAYS
);
F
St
mBuilder
*
sb
=
fstSearch
(((
TFileReader
*
)
reader
)
->
fst
,
ctx
);
FstSlice
h
=
fstSliceCreate
((
uint8_t
*
)
p
,
skip
);
fstStrea
mBuilderSetRange
(
sb
,
&
h
,
type
);
st
mBuilderSetRange
(
sb
,
&
h
,
type
);
fstSliceDestroy
(
&
h
);
StreamWithState
*
st
=
streamBuilderIntoStrea
m
(
sb
);
StreamWithStateResu
lt
*
rt
=
NULL
;
while
((
rt
=
st
reamWithState
NextWith
(
st
,
NULL
))
!=
NULL
)
{
FStmSt
*
st
=
stmBuilderIntoSt
m
(
sb
);
FStmStRs
lt
*
rt
=
NULL
;
while
((
rt
=
st
mSt
NextWith
(
st
,
NULL
))
!=
NULL
)
{
FstSlice
*
s
=
&
rt
->
data
;
char
*
ch
=
(
char
*
)
fstSliceData
(
s
,
NULL
);
// if (0 != strncmp(ch, tem->colName, tem->nColName)) {
...
...
@@ -354,8 +335,8 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr,
}
swsResultDestroy
(
rt
);
}
st
reamWithState
Destroy
(
st
);
fstStrea
mBuilderDestroy
(
sb
);
st
mSt
Destroy
(
st
);
st
mBuilderDestroy
(
sb
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tfSearchLessThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxTRslt
*
tr
)
{
...
...
@@ -376,7 +357,7 @@ static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
char
*
p
=
tem
->
colVal
;
uint64_t
sz
=
tem
->
nColVal
;
if
(
hasJson
)
{
p
=
i
nde
xPackJsonData
(
tem
);
p
=
i
d
xPackJsonData
(
tem
);
sz
=
strlen
(
p
);
}
int64_t
st
=
taosGetTimestampUs
();
...
...
@@ -401,7 +382,7 @@ static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
}
static
int32_t
tfSearchTerm_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxTRslt
*
tr
)
{
int
ret
=
0
;
char
*
p
=
i
nde
xPackJsonData
(
tem
);
char
*
p
=
i
d
xPackJsonData
(
tem
);
int
sz
=
strlen
(
p
);
int64_t
st
=
taosGetTimestampUs
();
...
...
@@ -456,18 +437,18 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
int
ret
=
0
;
int
skip
=
0
;
char
*
p
=
i
nde
xPackJsonDataPrefix
(
tem
,
&
skip
);
char
*
p
=
i
d
xPackJsonDataPrefix
(
tem
,
&
skip
);
_cache_range_compare
cmpFn
=
indexGetCompare
(
ctype
);
SArray
*
offsets
=
taosArrayInit
(
16
,
sizeof
(
uint64_t
));
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
p
,
AUTOMATION_PREFIX
);
F
stStrea
mBuilder
*
sb
=
fstSearch
(((
TFileReader
*
)
reader
)
->
fst
,
ctx
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
p
,
AUTOMATION_PREFIX
);
F
St
mBuilder
*
sb
=
fstSearch
(((
TFileReader
*
)
reader
)
->
fst
,
ctx
);
StreamWithState
*
st
=
streamBuilderIntoStrea
m
(
sb
);
StreamWithStateResu
lt
*
rt
=
NULL
;
while
((
rt
=
st
reamWithState
NextWith
(
st
,
NULL
))
!=
NULL
)
{
FStmSt
*
st
=
stmBuilderIntoSt
m
(
sb
);
FStmStRs
lt
*
rt
=
NULL
;
while
((
rt
=
st
mSt
NextWith
(
st
,
NULL
))
!=
NULL
)
{
FstSlice
*
s
=
&
rt
->
data
;
int32_t
sz
=
0
;
...
...
@@ -492,8 +473,8 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
taosMemoryFree
(
tmp
);
swsResultDestroy
(
rt
);
}
st
reamWithState
Destroy
(
st
);
fstStrea
mBuilderDestroy
(
sb
);
st
mSt
Destroy
(
st
);
st
mBuilderDestroy
(
sb
);
return
TSDB_CODE_SUCCESS
;
}
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SIdxTRslt
*
tr
)
{
...
...
@@ -704,8 +685,8 @@ static bool tfileIteratorNext(Iterate* iiter) {
char
*
colVal
=
NULL
;
uint64_t
offset
=
0
;
TFileFstIter
*
tIter
=
iiter
->
iter
;
StreamWithStateResult
*
rt
=
streamWithState
NextWith
(
tIter
->
st
,
NULL
);
TFileFstIter
*
tIter
=
iiter
->
iter
;
FStmStRslt
*
rt
=
stmSt
NextWith
(
tIter
->
st
,
NULL
);
if
(
rt
==
NULL
)
{
return
false
;
}
...
...
@@ -739,7 +720,7 @@ static TFileFstIter* tfileFstIteratorCreate(TFileReader* reader) {
iter
->
ctx
=
automCtxCreate
(
NULL
,
AUTOMATION_ALWAYS
);
iter
->
fb
=
fstSearch
(
reader
->
fst
,
iter
->
ctx
);
iter
->
st
=
st
reamBuilderIntoStrea
m
(
iter
->
fb
);
iter
->
st
=
st
mBuilderIntoSt
m
(
iter
->
fb
);
iter
->
rdr
=
reader
;
return
iter
;
}
...
...
@@ -770,8 +751,8 @@ void tfileIteratorDestroy(Iterate* iter) {
iterateValueDestroy
(
iv
,
true
);
TFileFstIter
*
tIter
=
iter
->
iter
;
st
reamWithState
Destroy
(
tIter
->
st
);
fstStrea
mBuilderDestroy
(
tIter
->
fb
);
st
mSt
Destroy
(
tIter
->
st
);
st
mBuilderDestroy
(
tIter
->
fb
);
automCtxDestroy
(
tIter
->
ctx
);
taosMemoryFree
(
tIter
);
...
...
source/libs/index/test/fstTest.cc
浏览文件 @
dcc78597
...
...
@@ -85,11 +85,11 @@ class FstReadMemory {
return
ok
;
}
// add later
bool
Search
(
Automation
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
F
stStreamBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
StreamWithState
*
st
=
streamBuilderIntoStrea
m
(
sb
);
StreamWithStateResult
*
rt
=
NULL
;
while
((
rt
=
st
reamWithState
NextWith
(
st
,
NULL
))
!=
NULL
)
{
bool
Search
(
FAuto
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
F
StmBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
FStmSt
*
st
=
stmBuilderIntoSt
m
(
sb
);
FStmStRslt
*
rt
=
NULL
;
while
((
rt
=
st
mSt
NextWith
(
st
,
NULL
))
!=
NULL
)
{
// result.push_back((uint64_t)(rt->out.out));
FstSlice
*
s
=
&
rt
->
data
;
int32_t
sz
=
0
;
...
...
@@ -99,27 +99,27 @@ class FstReadMemory {
result
.
push_back
(
rt
->
out
.
out
);
swsResultDestroy
(
rt
);
}
st
reamWithState
Destroy
(
st
);
fstStrea
mBuilderDestroy
(
sb
);
st
mSt
Destroy
(
st
);
st
mBuilderDestroy
(
sb
);
return
true
;
}
bool
SearchRange
(
Automation
Ctx
*
ctx
,
const
std
::
string
&
low
,
RangeType
lowType
,
const
std
::
string
&
high
,
bool
SearchRange
(
FAuto
Ctx
*
ctx
,
const
std
::
string
&
low
,
RangeType
lowType
,
const
std
::
string
&
high
,
RangeType
highType
,
std
::
vector
<
uint64_t
>&
result
)
{
F
stStrea
mBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
F
St
mBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
FstSlice
l
=
fstSliceCreate
((
uint8_t
*
)
low
.
c_str
(),
low
.
size
());
FstSlice
h
=
fstSliceCreate
((
uint8_t
*
)
high
.
c_str
(),
high
.
size
());
// range [low, high);
fstStrea
mBuilderSetRange
(
sb
,
&
l
,
lowType
);
fstStrea
mBuilderSetRange
(
sb
,
&
h
,
highType
);
st
mBuilderSetRange
(
sb
,
&
l
,
lowType
);
st
mBuilderSetRange
(
sb
,
&
h
,
highType
);
fstSliceDestroy
(
&
l
);
fstSliceDestroy
(
&
h
);
StreamWithState
*
st
=
streamBuilderIntoStrea
m
(
sb
);
StreamWithStateResu
lt
*
rt
=
NULL
;
while
((
rt
=
st
reamWithState
NextWith
(
st
,
NULL
))
!=
NULL
)
{
FStmSt
*
st
=
stmBuilderIntoSt
m
(
sb
);
FStmStRs
lt
*
rt
=
NULL
;
while
((
rt
=
st
mSt
NextWith
(
st
,
NULL
))
!=
NULL
)
{
// result.push_back((uint64_t)(rt->out.out));
FstSlice
*
s
=
&
rt
->
data
;
int32_t
sz
=
0
;
...
...
@@ -129,11 +129,11 @@ class FstReadMemory {
result
.
push_back
(
rt
->
out
.
out
);
swsResultDestroy
(
rt
);
}
st
reamWithState
Destroy
(
st
);
fstStrea
mBuilderDestroy
(
sb
);
st
mSt
Destroy
(
st
);
st
mBuilderDestroy
(
sb
);
return
true
;
}
bool
SearchWithTimeCostUs
(
Automation
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
bool
SearchWithTimeCostUs
(
FAuto
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
int64_t
s
=
taosGetTimestampUs
();
bool
ok
=
this
->
Search
(
ctx
,
result
);
int64_t
e
=
taosGetTimestampUs
();
...
...
@@ -253,7 +253,7 @@ void checkFstLongTerm() {
// prefix search
// std::vector<uint64_t> result;
//
Automation
Ctx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
//
FAuto
Ctx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
// m->Search(ctx, result);
// std::cout << "size: " << result.size() << std::endl;
// assert(result.size() == count);
...
...
@@ -286,7 +286,7 @@ void checkFstCheckIterator1() {
// prefix search
std
::
vector
<
uint64_t
>
result
;
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"He"
,
AUTOMATION_ALWAYS
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"He"
,
AUTOMATION_ALWAYS
);
m
->
Search
(
ctx
,
result
);
std
::
cout
<<
"size: "
<<
result
.
size
()
<<
std
::
endl
;
// assert(result.size() == count);
...
...
@@ -321,7 +321,7 @@ void checkFstCheckIterator2() {
// prefix search
std
::
vector
<
uint64_t
>
result
;
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"He"
,
AUTOMATION_ALWAYS
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"He"
,
AUTOMATION_ALWAYS
);
m
->
Search
(
ctx
,
result
);
std
::
cout
<<
"size: "
<<
result
.
size
()
<<
std
::
endl
;
// assert(result.size() == count);
...
...
@@ -361,7 +361,7 @@ void checkFstCheckIteratorPrefix() {
// prefix search
std
::
vector
<
uint64_t
>
result
;
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_PREFIX
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_PREFIX
);
m
->
Search
(
ctx
,
result
);
assert
(
result
.
size
()
==
1
);
automCtxDestroy
(
ctx
);
...
...
@@ -370,7 +370,7 @@ void checkFstCheckIteratorPrefix() {
// prefix search
std
::
vector
<
uint64_t
>
result
;
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"Hello"
,
AUTOMATION_PREFIX
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"Hello"
,
AUTOMATION_PREFIX
);
m
->
Search
(
ctx
,
result
);
assert
(
result
.
size
()
==
2
);
automCtxDestroy
(
ctx
);
...
...
@@ -378,7 +378,7 @@ void checkFstCheckIteratorPrefix() {
{
std
::
vector
<
uint64_t
>
result
;
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"jddd"
,
AUTOMATION_PREFIX
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"jddd"
,
AUTOMATION_PREFIX
);
m
->
Search
(
ctx
,
result
);
assert
(
result
.
size
()
==
1
);
automCtxDestroy
(
ctx
);
...
...
@@ -412,7 +412,7 @@ void checkFstCheckIteratorRange1() {
{
// prefix search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GE
,
"e"
,
LT
,
result
);
assert
(
result
.
size
()
==
3
);
...
...
@@ -421,7 +421,7 @@ void checkFstCheckIteratorRange1() {
{
// prefix search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GT
,
"e"
,
LT
,
result
);
assert
(
result
.
size
()
==
2
);
...
...
@@ -430,7 +430,7 @@ void checkFstCheckIteratorRange1() {
{
// prefix search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GT
,
"e"
,
LE
,
result
);
assert
(
result
.
size
()
==
3
);
...
...
@@ -439,7 +439,7 @@ void checkFstCheckIteratorRange1() {
{
// prefix search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GE
,
"e"
,
LE
,
result
);
assert
(
result
.
size
()
==
4
);
...
...
@@ -473,7 +473,7 @@ void checkFstCheckIteratorRange2() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GE
,
"ed"
,
LT
,
result
);
assert
(
result
.
size
()
==
4
);
...
...
@@ -482,7 +482,7 @@ void checkFstCheckIteratorRange2() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"bb"
,
GE
,
"ed"
,
LT
,
result
);
assert
(
result
.
size
()
==
3
);
...
...
@@ -491,7 +491,7 @@ void checkFstCheckIteratorRange2() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GE
,
"ed"
,
LE
,
result
);
assert
(
result
.
size
()
==
5
);
...
...
@@ -501,7 +501,7 @@ void checkFstCheckIteratorRange2() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GT
,
"ed"
,
LE
,
result
);
assert
(
result
.
size
()
==
4
);
...
...
@@ -510,7 +510,7 @@ void checkFstCheckIteratorRange2() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GT
,
"ed"
,
LT
,
result
);
assert
(
result
.
size
()
==
3
);
...
...
@@ -544,7 +544,7 @@ void checkFstCheckIteratorRange3() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"b"
,
GE
,
""
,
(
RangeType
)
10
,
result
);
assert
(
result
.
size
()
==
5
);
...
...
@@ -553,7 +553,7 @@ void checkFstCheckIteratorRange3() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
""
,
(
RangeType
)
20
,
"ab"
,
LE
,
result
);
assert
(
result
.
size
()
==
1
);
...
...
@@ -563,7 +563,7 @@ void checkFstCheckIteratorRange3() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
""
,
(
RangeType
)
30
,
"ab"
,
LT
,
result
);
assert
(
result
.
size
()
==
0
);
...
...
@@ -572,7 +572,7 @@ void checkFstCheckIteratorRange3() {
{
// range search
std
::
vector
<
uint64_t
>
result
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"he"
,
AUTOMATION_ALWAYS
);
// [b, e)
m
->
SearchRange
(
ctx
,
"ed"
,
GT
,
"ed"
,
(
RangeType
)
40
,
result
);
assert
(
result
.
size
()
==
0
);
...
...
source/libs/index/test/fstUT.cc
浏览文件 @
dcc78597
...
...
@@ -106,11 +106,11 @@ class FstReadMemory {
return
ok
;
}
// add later
bool
Search
(
Automation
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
F
stStreamBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
StreamWithState
*
st
=
streamBuilderIntoStrea
m
(
sb
);
StreamWithStateResult
*
rt
=
NULL
;
while
((
rt
=
st
reamWithState
NextWith
(
st
,
NULL
))
!=
NULL
)
{
bool
Search
(
FAuto
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
F
StmBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
FStmSt
*
st
=
stmBuilderIntoSt
m
(
sb
);
FStmStRslt
*
rt
=
NULL
;
while
((
rt
=
st
mSt
NextWith
(
st
,
NULL
))
!=
NULL
)
{
// result.push_back((uint64_t)(rt->out.out));
FstSlice
*
s
=
&
rt
->
data
;
int32_t
sz
=
0
;
...
...
@@ -122,7 +122,7 @@ class FstReadMemory {
std
::
cout
<<
std
::
endl
;
return
true
;
}
bool
SearchWithTimeCostUs
(
Automation
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
bool
SearchWithTimeCostUs
(
FAuto
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
int64_t
s
=
taosGetTimestampUs
();
bool
ok
=
this
->
Search
(
ctx
,
result
);
int64_t
e
=
taosGetTimestampUs
();
...
...
@@ -192,7 +192,7 @@ class TFst {
}
return
fr
->
Get
(
k
,
v
);
}
bool
Search
(
Automation
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
bool
Search
(
FAuto
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
// add more
return
fr
->
Search
(
ctx
,
result
);
}
...
...
@@ -231,7 +231,7 @@ TEST_F(FstEnv, writeNormal) {
assert
(
val
==
0
);
std
::
vector
<
uint64_t
>
rlt
;
AutomationCtx
*
ctx
=
automCtxCreate
((
void
*
)
"ab"
,
AUTOMATION_ALWAYS
);
FAutoCtx
*
ctx
=
automCtxCreate
((
void
*
)
"ab"
,
AUTOMATION_ALWAYS
);
assert
(
fst
->
Search
(
ctx
,
rlt
)
==
true
);
}
TEST_F
(
FstEnv
,
WriteMillonrRecord
)
{}
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
dcc78597
...
...
@@ -106,17 +106,17 @@ class FstReadMemory {
return
ok
;
}
// add later
bool
Search
(
Automation
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
F
stStreamBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
StreamWithState
*
st
=
streamBuilderIntoStrea
m
(
sb
);
StreamWithStateResult
*
rt
=
NULL
;
bool
Search
(
FAuto
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
F
StmBuilder
*
sb
=
fstSearch
(
_fst
,
ctx
);
FStmSt
*
st
=
stmBuilderIntoSt
m
(
sb
);
FStmStRslt
*
rt
=
NULL
;
while
((
rt
=
st
reamWithState
NextWith
(
st
,
NULL
))
!=
NULL
)
{
while
((
rt
=
st
mSt
NextWith
(
st
,
NULL
))
!=
NULL
)
{
result
.
push_back
((
uint64_t
)(
rt
->
out
.
out
));
}
return
true
;
}
bool
SearchWithTimeCostUs
(
Automation
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
bool
SearchWithTimeCostUs
(
FAuto
Ctx
*
ctx
,
std
::
vector
<
uint64_t
>&
result
)
{
int64_t
s
=
taosGetTimestampUs
();
bool
ok
=
this
->
Search
(
ctx
,
result
);
int64_t
e
=
taosGetTimestampUs
();
...
...
@@ -220,7 +220,7 @@ void checkFstPrefixSearch() {
// prefix search
std
::
vector
<
uint64_t
>
result
;
Automation
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"ab"
,
AUTOMATION_PREFIX
);
FAuto
Ctx
*
ctx
=
automCtxCreate
((
void
*
)
"ab"
,
AUTOMATION_PREFIX
);
m
->
Search
(
ctx
,
result
);
assert
(
result
.
size
()
==
count
);
for
(
int
i
=
0
;
i
<
result
.
size
();
i
++
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录