Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5d4d7b47
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
5d4d7b47
编写于
12月 21, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update index TFile manage and format code
上级
6fe118c5
变更
22
展开全部
显示空白变更内容
内联
并排
Showing
22 changed file
with
2212 addition
and
2030 deletion
+2212
-2030
include/libs/index/index.h
include/libs/index/index.h
+31
-32
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+73
-48
source/libs/index/inc/index_cache.h
source/libs/index/inc/index_cache.h
+10
-10
source/libs/index/inc/index_fst.h
source/libs/index/inc/index_fst.h
+139
-147
source/libs/index/inc/index_fst_automation.h
source/libs/index/inc/index_fst_automation.h
+21
-27
source/libs/index/inc/index_fst_common.h
source/libs/index/inc/index_fst_common.h
+2
-2
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+14
-21
source/libs/index/inc/index_fst_node.h
source/libs/index/inc/index_fst_node.h
+12
-11
source/libs/index/inc/index_fst_registry.h
source/libs/index/inc/index_fst_registry.h
+23
-24
source/libs/index/inc/index_fst_util.h
source/libs/index/inc/index_fst_util.h
+51
-51
source/libs/index/inc/index_tfile.h
source/libs/index/inc/index_tfile.h
+41
-48
source/libs/index/inc/index_util.h
source/libs/index/inc/index_util.h
+16
-17
source/libs/index/src/index.c
source/libs/index/src/index.c
+144
-142
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+66
-60
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+639
-679
source/libs/index/src/index_fst_automation.c
source/libs/index/src/index_fst_automation.c
+55
-77
source/libs/index/src/index_fst_common.c
source/libs/index/src/index_fst_common.c
+513
-287
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+55
-51
source/libs/index/src/index_fst_node.c
source/libs/index/src/index_fst_node.c
+56
-51
source/libs/index/src/index_fst_registry.c
source/libs/index/src/index_fst_registry.c
+80
-78
source/libs/index/src/index_fst_util.c
source/libs/index/src/index_fst_util.c
+67
-70
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+104
-97
未找到文件。
include/libs/index/index.h
浏览文件 @
5d4d7b47
...
@@ -39,11 +39,11 @@ typedef enum {
...
@@ -39,11 +39,11 @@ typedef enum {
}
SIndexOperOnColumn
;
}
SIndexOperOnColumn
;
typedef
enum
{
MUST
=
0
,
SHOULD
=
1
,
NOT
=
2
}
EIndexOperatorType
;
typedef
enum
{
MUST
=
0
,
SHOULD
=
1
,
NOT
=
2
}
EIndexOperatorType
;
typedef
enum
{
QUERY_TERM
=
0
,
QUERY_PREFIX
=
1
,
QUERY_SUFFIX
=
2
,
QUERY_REGEX
=
3
}
EIndexQueryType
;
typedef
enum
{
QUERY_TERM
=
0
,
QUERY_PREFIX
=
1
,
QUERY_SUFFIX
=
2
,
QUERY_REGEX
=
3
}
EIndexQueryType
;
/*
/*
* @param: oper
* @param: oper
*
*
*/
*/
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
oper
);
SIndexMultiTermQuery
*
indexMultiTermQueryCreate
(
EIndexOperatorType
oper
);
void
indexMultiTermQueryDestroy
(
SIndexMultiTermQuery
*
pQuery
);
void
indexMultiTermQueryDestroy
(
SIndexMultiTermQuery
*
pQuery
);
int
indexMultiTermQueryAdd
(
SIndexMultiTermQuery
*
pQuery
,
SIndexTerm
*
term
,
EIndexQueryType
type
);
int
indexMultiTermQueryAdd
(
SIndexMultiTermQuery
*
pQuery
,
SIndexTerm
*
term
,
EIndexQueryType
type
);
...
@@ -76,11 +76,10 @@ void indexOptsDestroy(SIndexOpts *opts);
...
@@ -76,11 +76,10 @@ void indexOptsDestroy(SIndexOpts *opts);
* @param:
* @param:
*/
*/
SIndexTerm
*
indexTermCreate
(
int64_t
suid
,
SIndexOperOnColumn
operType
,
uint8_t
colType
,
SIndexTerm
*
indexTermCreate
(
int64_t
suid
,
SIndexOperOnColumn
operType
,
uint8_t
colType
,
const
char
*
colName
,
const
char
*
colName
,
int32_t
nColName
,
const
char
*
colVal
,
int32_t
nColVal
);
int32_t
nColName
,
const
char
*
colVal
,
int32_t
nColVal
);
void
indexTermDestroy
(
SIndexTerm
*
p
);
void
indexTermDestroy
(
SIndexTerm
*
p
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
5d4d7b47
...
@@ -18,20 +18,19 @@
...
@@ -18,20 +18,19 @@
#include "index.h"
#include "index.h"
#include "index_fst.h"
#include "index_fst.h"
#include "tlog.h"
#include "thash.h"
#include "taos.h"
#include "taos.h"
#include "thash.h"
#include "tlog.h"
#ifdef USE_LUCENE
#ifdef USE_LUCENE
#include <lucene++/Lucene_c.h>
#include <lucene++/Lucene_c.h>
#endif
#endif
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
typedef
enum
{
kTypeValue
,
kTypeDeletion
}
STermValueType
;
typedef
enum
{
kTypeValue
,
kTypeDeletion
}
STermValueType
;
typedef
struct
SIndexStat
{
typedef
struct
SIndexStat
{
int32_t
totalAdded
;
//
int32_t
totalAdded
;
//
...
@@ -45,9 +44,9 @@ struct SIndex {
...
@@ -45,9 +44,9 @@ struct SIndex {
#ifdef USE_LUCENE
#ifdef USE_LUCENE
index_t
*
index
;
index_t
*
index
;
#endif
#endif
void
*
cache
;
void
*
cache
;
void
*
tindex
;
void
*
tindex
;
SHashObj
*
colObj
;
// < field name, field id>
SHashObj
*
colObj
;
// < field name, field id>
int64_t
suid
;
// current super table id, -1 is normal table
int64_t
suid
;
// current super table id, -1 is normal table
int
colId
;
// field id allocated to cache
int
colId
;
// field id allocated to cache
...
@@ -66,12 +65,11 @@ struct SIndexOpts {
...
@@ -66,12 +65,11 @@ struct SIndexOpts {
int32_t
cacheSize
;
// MB
int32_t
cacheSize
;
// MB
// add cache module later
// add cache module later
#endif
#endif
};
};
struct
SIndexMultiTermQuery
{
struct
SIndexMultiTermQuery
{
EIndexOperatorType
opera
;
EIndexOperatorType
opera
;
SArray
*
query
;
SArray
*
query
;
};
};
// field and key;
// field and key;
...
@@ -79,26 +77,53 @@ typedef struct SIndexTerm {
...
@@ -79,26 +77,53 @@ typedef struct SIndexTerm {
int64_t
suid
;
int64_t
suid
;
SIndexOperOnColumn
operType
;
// oper type, add/del/update
SIndexOperOnColumn
operType
;
// oper type, add/del/update
uint8_t
colType
;
// term data type, str/interger/json
uint8_t
colType
;
// term data type, str/interger/json
char
*
colName
;
char
*
colName
;
int32_t
nColName
;
int32_t
nColName
;
char
*
colVal
;
char
*
colVal
;
int32_t
nColVal
;
int32_t
nColVal
;
}
SIndexTerm
;
}
SIndexTerm
;
typedef
struct
SIndexTermQuery
{
typedef
struct
SIndexTermQuery
{
SIndexTerm
*
term
;
SIndexTerm
*
term
;
EIndexQueryType
qType
;
EIndexQueryType
qType
;
}
SIndexTermQuery
;
}
SIndexTermQuery
;
#define indexFatal(...) \
do { \
#define indexFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("index FATAL ", 255, __VA_ARGS__); }} while(0)
if (sDebugFlag & DEBUG_FATAL) { \
#define indexError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("index ERROR ", 255, __VA_ARGS__); }} while(0)
taosPrintLog("index FATAL ", 255, __VA_ARGS__); \
#define indexWarn(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("index WARN ", 255, __VA_ARGS__); }} while(0)
} \
#define indexInfo(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("index ", 255, __VA_ARGS__); }} while(0)
} while (0)
#define indexDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); }} while(0)
#define indexError(...) \
#define indexTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); }} while(0)
do { \
if (sDebugFlag & DEBUG_ERROR) { \
taosPrintLog("index ERROR ", 255, __VA_ARGS__); \
} \
} while (0)
#define indexWarn(...) \
do { \
if (sDebugFlag & DEBUG_WARN) { \
taosPrintLog("index WARN ", 255, __VA_ARGS__); \
} \
} while (0)
#define indexInfo(...) \
do { \
if (sDebugFlag & DEBUG_INFO) { \
taosPrintLog("index ", 255, __VA_ARGS__); \
} \
} while (0)
#define indexDebug(...) \
do { \
if (sDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("index ", sDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define indexTrace(...) \
do { \
if (sDebugFlag & DEBUG_TRACE) { \
taosPrintLog("index ", sDebugFlag, __VA_ARGS__); \
} \
} while (0)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/index/inc/index_cache.h
浏览文件 @
5d4d7b47
...
@@ -22,8 +22,10 @@
...
@@ -22,8 +22,10 @@
// ----------------- key structure in skiplist ---------------------
// ----------------- key structure in skiplist ---------------------
/* A data row, the format is like below:
/* A data row, the format is like below:
* content: |<--totalLen-->|<-- fieldid-->|<--field type -->|<-- value len--->|<-- value -->|<-- uid -->|<--version--->|<-- itermType -->|
* content: |<--totalLen-->|<-- fieldid-->|<--field type-->|<-- value len--->|
* len : |<--int32_t -->|<-- int16_t-->|<-- int8_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->|
* |<-- value -->|<--uid -->|<--version--->|<-- itermType -->|
* len : |<--int32_t -->|<-- int16_t-->|<-- int8_t --->|<--- int32_t --->|
* <--valuelen->|<--uint64_t->| * <-- int32_t-->|<-- int8_t --->|
*/
*/
#ifdef __cplusplus
#ifdef __cplusplus
...
@@ -35,7 +37,6 @@ typedef struct IndexCache {
...
@@ -35,7 +37,6 @@ typedef struct IndexCache {
SSkipList
*
skiplist
;
SSkipList
*
skiplist
;
}
IndexCache
;
}
IndexCache
;
//
//
IndexCache
*
indexCacheCreate
();
IndexCache
*
indexCacheCreate
();
...
@@ -43,13 +44,12 @@ void indexCacheDestroy(void *cache);
...
@@ -43,13 +44,12 @@ void indexCacheDestroy(void *cache);
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
int16_t
colId
,
int32_t
version
,
uint64_t
uid
);
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
int16_t
colId
,
int32_t
version
,
uint64_t
uid
);
//int indexCacheGet(void *cache, uint64_t *rst);
// int indexCacheGet(void *cache, uint64_t *rst);
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
int16_t
colId
,
int32_t
version
,
SArray
*
result
,
STermValueType
*
s
);
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
int16_t
colId
,
int32_t
version
,
SArray
*
result
,
STermValueType
*
s
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
#endif
#endif
source/libs/index/inc/index_fst.h
浏览文件 @
5d4d7b47
...
@@ -20,11 +20,11 @@
...
@@ -20,11 +20,11 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "tarray.h"
#include "index_fst_util.h"
#include "index_fst_registry.h"
#include "index_fst_counting_writer.h"
#include "index_fst_automation.h"
#include "index_fst_automation.h"
#include "index_fst_counting_writer.h"
#include "index_fst_registry.h"
#include "index_fst_util.h"
#include "tarray.h"
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
...
@@ -32,7 +32,7 @@ typedef struct Fst Fst;
...
@@ -32,7 +32,7 @@ typedef struct Fst Fst;
typedef
struct
FstNode
FstNode
;
typedef
struct
FstNode
FstNode
;
typedef
struct
StreamWithState
StreamWithState
;
typedef
struct
StreamWithState
StreamWithState
;
typedef
enum
{
Included
,
Excluded
,
Unbounded
}
FstBound
;
typedef
enum
{
Included
,
Excluded
,
Unbounded
}
FstBound
;
typedef
struct
FstBoundWithData
{
typedef
struct
FstBoundWithData
{
FstSlice
data
;
FstSlice
data
;
...
@@ -40,8 +40,8 @@ typedef struct FstBoundWithData {
...
@@ -40,8 +40,8 @@ typedef struct FstBoundWithData {
}
FstBoundWithData
;
}
FstBoundWithData
;
typedef
struct
FstStreamBuilder
{
typedef
struct
FstStreamBuilder
{
Fst
*
fst
;
Fst
*
fst
;
AutomationCtx
*
aut
;
AutomationCtx
*
aut
;
FstBoundWithData
*
min
;
FstBoundWithData
*
min
;
FstBoundWithData
*
max
;
FstBoundWithData
*
max
;
}
FstStreamBuilder
,
FstStreamWithStateBuilder
;
}
FstStreamBuilder
,
FstStreamWithStateBuilder
;
...
@@ -51,18 +51,15 @@ typedef struct FstRange {
...
@@ -51,18 +51,15 @@ typedef struct FstRange {
uint64_t
end
;
uint64_t
end
;
}
FstRange
;
}
FstRange
;
typedef
enum
{
GE
,
GT
,
LE
,
LT
}
RangeType
;
typedef
enum
{
OneTransNext
,
OneTrans
,
AnyTrans
,
EmptyFinal
}
State
;
typedef
enum
{
Ordered
,
OutOfOrdered
,
DuplicateKey
}
OrderType
;
typedef
enum
{
GE
,
GT
,
LE
,
LT
}
RangeType
;
FstBoundWithData
*
fstBoundStateCreate
(
FstBound
type
,
FstSlice
*
data
);
typedef
enum
{
OneTransNext
,
OneTrans
,
AnyTrans
,
EmptyFinal
}
State
;
typedef
enum
{
Ordered
,
OutOfOrdered
,
DuplicateKey
}
OrderType
;
FstBoundWithData
*
fstBoundStateCreate
(
FstBound
type
,
FstSlice
*
data
);
bool
fstBoundWithDataExceededBy
(
FstBoundWithData
*
bound
,
FstSlice
*
slice
);
bool
fstBoundWithDataExceededBy
(
FstBoundWithData
*
bound
,
FstSlice
*
slice
);
bool
fstBoundWithDataIsEmpty
(
FstBoundWithData
*
bound
);
bool
fstBoundWithDataIsEmpty
(
FstBoundWithData
*
bound
);
bool
fstBoundWithDataIsIncluded
(
FstBoundWithData
*
bound
);
bool
fstBoundWithDataIsIncluded
(
FstBoundWithData
*
bound
);
typedef
struct
FstOutput
{
typedef
struct
FstOutput
{
bool
null
;
bool
null
;
Output
out
;
Output
out
;
...
@@ -82,76 +79,71 @@ typedef struct FstUnFinishedNodes {
...
@@ -82,76 +79,71 @@ typedef struct FstUnFinishedNodes {
FstUnFinishedNodes
*
fstUnFinishedNodesCreate
();
FstUnFinishedNodes
*
fstUnFinishedNodesCreate
();
void
fstUnFinishedNodesDestroy
(
FstUnFinishedNodes
*
node
);
void
fstUnFinishedNodesDestroy
(
FstUnFinishedNodes
*
node
);
void
fstUnFinishedNodesPushEmpty
(
FstUnFinishedNodes
*
nodes
,
bool
isFinal
);
void
fstUnFinishedNodesPushEmpty
(
FstUnFinishedNodes
*
nodes
,
bool
isFinal
);
FstBuilderNode
*
fstUnFinishedNodesPopRoot
(
FstUnFinishedNodes
*
nodes
);
FstBuilderNode
*
fstUnFinishedNodesPopFreeze
(
FstUnFinishedNodes
*
nodes
,
CompiledAddr
addr
);
FstBuilderNode
*
fstUnFinishedNodesPopEmpty
(
FstUnFinishedNodes
*
nodes
);
void
fstUnFinishedNodesSetRootOutput
(
FstUnFinishedNodes
*
node
,
Output
out
);
void
fstUnFinishedNodesSetRootOutput
(
FstUnFinishedNodes
*
node
,
Output
out
);
void
fstUnFinishedNodesTopLastFreeze
(
FstUnFinishedNodes
*
node
,
CompiledAddr
addr
);
void
fstUnFinishedNodesTopLastFreeze
(
FstUnFinishedNodes
*
node
,
CompiledAddr
addr
);
void
fstUnFinishedNodesAddSuffix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
out
);
void
fstUnFinishedNodesAddSuffix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
out
);
uint64_t
fstUnFinishedNodesFindCommPrefix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
);
uint64_t
fstUnFinishedNodesFindCommPrefix
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
);
uint64_t
fstUnFinishedNodesFindCommPrefixAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
);
FstBuilderNode
*
fstUnFinishedNodesPopRoot
(
FstUnFinishedNodes
*
nodes
);
FstBuilderNode
*
fstUnFinishedNodesPopFreeze
(
FstUnFinishedNodes
*
nodes
,
CompiledAddr
addr
);
FstBuilderNode
*
fstUnFinishedNodesPopEmpty
(
FstUnFinishedNodes
*
nodes
);
uint64_t
fstUnFinishedNodesFindCommPrefixAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
);
typedef
struct
FstBuilder
{
typedef
struct
FstBuilder
{
FstCountingWriter
*
wrt
;
// The FST raw data is written directly to `wtr`.
FstCountingWriter
*
wrt
;
// The FST raw data is written directly to `wtr`.
FstUnFinishedNodes
*
unfinished
;
// The stack of unfinished nodes
FstUnFinishedNodes
*
unfinished
;
// The stack of unfinished nodes
FstRegistry
*
registry
;
// A map of finished nodes.
FstRegistry
*
registry
;
// A map of finished nodes.
FstSlice
last
;
// The last word added
FstSlice
last
;
// The last word added
CompiledAddr
lastAddr
;
// The address of the last compiled node
CompiledAddr
lastAddr
;
// The address of the last compiled node
uint64_t
len
;
// num of keys added
uint64_t
len
;
// num of keys added
}
FstBuilder
;
}
FstBuilder
;
FstBuilder
*
fstBuilderCreate
(
void
*
w
,
FstType
ty
);
FstBuilder
*
fstBuilderCreate
(
void
*
w
,
FstType
ty
);
void
fstBuilderDestroy
(
FstBuilder
*
b
);
void
fstBuilderDestroy
(
FstBuilder
*
b
);
void
fstBuilderInsertOutput
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
void
fstBuilderInsertOutput
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
bool
fstBuilderInsert
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
bool
fstBuilderInsert
(
FstBuilder
*
b
,
FstSlice
bs
,
Output
in
);
OrderType
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDup
);
void
fstBuilderCompileFrom
(
FstBuilder
*
b
,
uint64_t
istate
);
void
fstBuilderCompileFrom
(
FstBuilder
*
b
,
uint64_t
istate
);
CompiledAddr
fstBuilderCompile
(
FstBuilder
*
b
,
FstBuilderNode
*
bn
);
void
*
fstBuilerIntoInner
(
FstBuilder
*
b
);
void
*
fstBuilerIntoInner
(
FstBuilder
*
b
);
void
fstBuilderFinish
(
FstBuilder
*
b
);
void
fstBuilderFinish
(
FstBuilder
*
b
);
OrderType
fstBuilderCheckLastKey
(
FstBuilder
*
b
,
FstSlice
bs
,
bool
ckDup
);
CompiledAddr
fstBuilderCompile
(
FstBuilder
*
b
,
FstBuilderNode
*
bn
);
typedef
struct
FstTransitions
{
typedef
struct
FstTransitions
{
FstNode
*
node
;
FstNode
*
node
;
FstRange
range
;
FstRange
range
;
}
FstTransitions
;
}
FstTransitions
;
//FstState and relation function
//
FstState and relation function
typedef
struct
FstState
{
typedef
struct
FstState
{
State
state
;
State
state
;
uint8_t
val
;
uint8_t
val
;
}
FstState
;
}
FstState
;
FstState
fstStateCreateFrom
(
FstSlice
*
data
,
CompiledAddr
addr
);
FstState
fstStateCreateFrom
(
FstSlice
*
data
,
CompiledAddr
addr
);
FstState
fstStateCreate
(
State
state
);
FstState
fstStateCreate
(
State
state
);
//compile
//
compile
void
fstStateCompileForOneTransNext
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
uint8_t
inp
);
void
fstStateCompileForOneTransNext
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
uint8_t
inp
);
void
fstStateCompileForOneTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstTransition
*
trn
);
void
fstStateCompileForOneTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstTransition
*
trn
);
void
fstStateCompileForAnyTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
);
void
fstStateCompileForAnyTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
);
// set_comm_input
// set_comm_input
void
fstStateSetCommInput
(
FstState
*
state
,
uint8_t
inp
);
void
fstStateSetCommInput
(
FstState
*
state
,
uint8_t
inp
);
// comm_input
// comm_input
uint8_t
fstStateCommInput
(
FstState
*
state
,
bool
*
null
);
uint8_t
fstStateCommInput
(
FstState
*
state
,
bool
*
null
);
// input_len
// input_len
uint64_t
fstStateInputLen
(
FstState
*
state
);
uint64_t
fstStateInputLen
(
FstState
*
state
);
// end_addr
// end_addr
uint64_t
fstStateEndAddrForOneTransNext
(
FstState
*
state
,
FstSlice
*
data
);
uint64_t
fstStateEndAddrForOneTransNext
(
FstState
*
state
,
FstSlice
*
data
);
uint64_t
fstStateEndAddrForOneTrans
(
FstState
*
state
,
FstSlice
*
data
,
PackSizes
sizes
);
uint64_t
fstStateEndAddrForOneTrans
(
FstState
*
state
,
FstSlice
*
data
,
PackSizes
sizes
);
uint64_t
fstStateEndAddrForAnyTrans
(
FstState
*
state
,
uint64_t
version
,
FstSlice
*
date
,
PackSizes
sizes
,
uint64_t
nTrans
);
uint64_t
fstStateEndAddrForAnyTrans
(
FstState
*
state
,
uint64_t
version
,
FstSlice
*
date
,
PackSizes
sizes
,
uint64_t
nTrans
);
// input
// input
uint8_t
fstStateInput
(
FstState
*
state
,
FstNode
*
node
);
uint8_t
fstStateInput
(
FstState
*
state
,
FstNode
*
node
);
uint8_t
fstStateInputForAnyTrans
(
FstState
*
state
,
FstNode
*
node
,
uint64_t
i
);
uint8_t
fstStateInputForAnyTrans
(
FstState
*
state
,
FstNode
*
node
,
uint64_t
i
);
...
@@ -180,14 +172,11 @@ uint64_t fstStateNtrans(FstState *state, FstSlice *slice);
...
@@ -180,14 +172,11 @@ uint64_t fstStateNtrans(FstState *state, FstSlice *slice);
Output
fstStateFinalOutput
(
FstState
*
state
,
uint64_t
version
,
FstSlice
*
date
,
PackSizes
sizes
,
uint64_t
nTrans
);
Output
fstStateFinalOutput
(
FstState
*
state
,
uint64_t
version
,
FstSlice
*
date
,
PackSizes
sizes
,
uint64_t
nTrans
);
uint64_t
fstStateFindInput
(
FstState
*
state
,
FstNode
*
node
,
uint8_t
b
,
bool
*
null
);
uint64_t
fstStateFindInput
(
FstState
*
state
,
FstNode
*
node
,
uint8_t
b
,
bool
*
null
);
#define FST_STATE_ONE_TRNAS_NEXT(node) (node->state.state == OneTransNext)
#define FST_STATE_ONE_TRNAS_NEXT(node) (node->state.state == OneTransNext)
#define FST_STATE_ONE_TRNAS(node) (node->state.state == OneTrans)
#define FST_STATE_ONE_TRNAS(node) (node->state.state == OneTrans)
#define FST_STATE_ANY_TRANS(node) (node->state.state == AnyTrans)
#define FST_STATE_ANY_TRANS(node) (node->state.state == AnyTrans)
#define FST_STATE_EMPTY_FINAL(node) (node->state.state == EmptyFinal)
#define FST_STATE_EMPTY_FINAL(node) (node->state.state == EmptyFinal)
typedef
struct
FstLastTransition
{
typedef
struct
FstLastTransition
{
uint8_t
inp
;
uint8_t
inp
;
Output
out
;
Output
out
;
...
@@ -198,13 +187,12 @@ typedef struct FstLastTransition {
...
@@ -198,13 +187,12 @@ typedef struct FstLastTransition {
* TODO: simple function name
* TODO: simple function name
*/
*/
typedef
struct
FstBuilderNodeUnfinished
{
typedef
struct
FstBuilderNodeUnfinished
{
FstBuilderNode
*
node
;
FstBuilderNode
*
node
;
FstLastTransition
*
last
;
FstLastTransition
*
last
;
}
FstBuilderNodeUnfinished
;
}
FstBuilderNodeUnfinished
;
void
fstBuilderNodeUnfinishedLastCompiled
(
FstBuilderNodeUnfinished
*
node
,
CompiledAddr
addr
);
void
fstBuilderNodeUnfinishedLastCompiled
(
FstBuilderNodeUnfinished
*
node
,
CompiledAddr
addr
);
void
fstBuilderNodeUnfinishedAddOutputPrefix
(
FstBuilderNodeUnfinished
*
node
,
Output
out
);
void
fstBuilderNodeUnfinishedAddOutputPrefix
(
FstBuilderNodeUnfinished
*
node
,
Output
out
);
/*
/*
...
@@ -222,27 +210,31 @@ typedef struct FstNode {
...
@@ -222,27 +210,31 @@ typedef struct FstNode {
Output
finalOutput
;
Output
finalOutput
;
}
FstNode
;
}
FstNode
;
// If this node is final and has a terminal output value, then it is, returned. Otherwise, a zero output is returned
// If this node is final and has a terminal output value, then it is, returned.
// Otherwise, a zero output is returned
#define FST_NODE_FINAL_OUTPUT(node) node->finalOutput
#define FST_NODE_FINAL_OUTPUT(node) node->finalOutput
// Returns true if and only if this node corresponds to a final or "match", state in the finite state transducer.
// Returns true if and only if this node corresponds to a final or "match",
// state in the finite state transducer.
#define FST_NODE_IS_FINAL(node) node->isFinal
#define FST_NODE_IS_FINAL(node) node->isFinal
// Returns the number of transitions in this node, The maximum number of transitions is 256.
// Returns the number of transitions in this node, The maximum number of
// transitions is 256.
#define FST_NODE_LEN(node) node->nTrans
#define FST_NODE_LEN(node) node->nTrans
// Returns true if and only if this node has zero transitions.
// Returns true if and only if this node has zero transitions.
#define FST_NODE_IS_EMPTYE(node) (node->nTrans == 0)
#define FST_NODE_IS_EMPTYE(node) (node->nTrans == 0)
// Return the address of this node.
// Return the address of this node.
#define FST_NODE_ADDR(node) node->start
#define FST_NODE_ADDR(node) node->start
FstNode
*
fstNodeCreate
(
int64_t
version
,
CompiledAddr
addr
,
FstSlice
*
data
);
FstNode
*
fstNodeCreate
(
int64_t
version
,
CompiledAddr
addr
,
FstSlice
*
data
);
void
fstNodeDestroy
(
FstNode
*
fstNode
);
void
fstNodeDestroy
(
FstNode
*
fstNode
);
FstTransitions
fstNodeTransitionIter
(
FstNode
*
node
);
FstTransitions
fstNodeTransitionIter
(
FstNode
*
node
);
FstTransitions
*
fstNodeTransitions
(
FstNode
*
node
);
FstTransitions
*
fstNodeTransitions
(
FstNode
*
node
);
bool
fstNodeGetTransitionAt
(
FstNode
*
node
,
uint64_t
i
,
FstTransition
*
res
);
bool
fstNodeGetTransitionAt
(
FstNode
*
node
,
uint64_t
i
,
FstTransition
*
res
);
bool
fstNodeGetTransitionAddrAt
(
FstNode
*
node
,
uint64_t
i
,
CompiledAddr
*
res
);
bool
fstNodeGetTransitionAddrAt
(
FstNode
*
node
,
uint64_t
i
,
CompiledAddr
*
res
);
bool
fstNodeFindInput
(
FstNode
*
node
,
uint8_t
b
,
uint64_t
*
res
);
bool
fstNodeFindInput
(
FstNode
*
node
,
uint8_t
b
,
uint64_t
*
res
);
bool
fstNodeCompile
(
FstNode
*
node
,
void
*
w
,
CompiledAddr
lastAddr
,
CompiledAddr
addr
,
FstBuilderNode
*
builderNode
);
bool
fstNodeCompile
(
FstNode
*
node
,
void
*
w
,
CompiledAddr
lastAddr
,
CompiledAddr
addr
,
FstBuilderNode
*
builderNode
);
FstSlice
fstNodeAsSlice
(
FstNode
*
node
);
FstSlice
fstNodeAsSlice
(
FstNode
*
node
);
// ops
// ops
...
@@ -255,7 +247,6 @@ typedef struct FstIndexedValue {
...
@@ -255,7 +247,6 @@ typedef struct FstIndexedValue {
FstLastTransition
*
fstLastTransitionCreate
(
uint8_t
inp
,
Output
out
);
FstLastTransition
*
fstLastTransitionCreate
(
uint8_t
inp
,
Output
out
);
void
fstLastTransitionDestroy
(
FstLastTransition
*
trn
);
void
fstLastTransitionDestroy
(
FstLastTransition
*
trn
);
typedef
struct
FstMeta
{
typedef
struct
FstMeta
{
uint64_t
version
;
uint64_t
version
;
CompiledAddr
rootAddr
;
CompiledAddr
rootAddr
;
...
@@ -265,67 +256,69 @@ typedef struct FstMeta {
...
@@ -265,67 +256,69 @@ typedef struct FstMeta {
}
FstMeta
;
}
FstMeta
;
typedef
struct
Fst
{
typedef
struct
Fst
{
FstMeta
*
meta
;
FstMeta
*
meta
;
FstSlice
*
data
;
//
FstSlice
*
data
;
//
FstNode
*
root
;
//
FstNode
*
root
;
//
}
Fst
;
}
Fst
;
// refactor simple function
// refactor simple function
Fst
*
fstCreate
(
FstSlice
*
data
);
Fst
*
fstCreate
(
FstSlice
*
data
);
void
fstDestroy
(
Fst
*
fst
);
void
fstDestroy
(
Fst
*
fst
);
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
);
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
);
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
);
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
);
FstNode
*
fstGetRoot
(
Fst
*
fst
);
FstNode
*
fstGetRoot
(
Fst
*
fst
);
FstType
fstGetType
(
Fst
*
fst
);
FstType
fstGetType
(
Fst
*
fst
);
CompiledAddr
fstGetRootAddr
(
Fst
*
fst
);
CompiledAddr
fstGetRootAddr
(
Fst
*
fst
);
Output
fstEmptyFinalOutput
(
Fst
*
fst
,
bool
*
null
);
Output
fstEmptyFinalOutput
(
Fst
*
fst
,
bool
*
null
);
FstStreamBuilder
*
fstSearch
(
Fst
*
fst
,
AutomationCtx
*
ctx
);
FstStreamBuilder
*
fstSearch
(
Fst
*
fst
,
AutomationCtx
*
ctx
);
FstStreamWithStateBuilder
*
fstSearchWithState
(
Fst
*
fst
,
AutomationCtx
*
ctx
);
FstStreamWithStateBuilder
*
fstSearchWithState
(
Fst
*
fst
,
AutomationCtx
*
ctx
);
// into stream to expand later
// into stream to expand later
StreamWithState
*
streamBuilderIntoStream
(
FstStreamBuilder
*
sb
);
StreamWithState
*
streamBuilderIntoStream
(
FstStreamBuilder
*
sb
);
bool
fstVerify
(
Fst
*
fst
);
bool
fstVerify
(
Fst
*
fst
);
// refactor this function
//refactor this function
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
);
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
);
typedef
struct
StreamState
{
typedef
struct
StreamState
{
FstNode
*
node
;
FstNode
*
node
;
uint64_t
trans
;
uint64_t
trans
;
FstOutput
out
;
FstOutput
out
;
void
*
autState
;
void
*
autState
;
}
StreamState
;
}
StreamState
;
void
streamStateDestroy
(
void
*
s
);
void
streamStateDestroy
(
void
*
s
);
typedef
struct
StreamWithState
{
typedef
struct
StreamWithState
{
Fst
*
fst
;
Fst
*
fst
;
AutomationCtx
*
aut
;
AutomationCtx
*
aut
;
SArray
*
inp
;
SArray
*
inp
;
FstOutput
emptyOutput
;
FstOutput
emptyOutput
;
SArray
*
stack
;
// <StreamState>
SArray
*
stack
;
// <StreamState>
FstBoundWithData
*
endAt
;
FstBoundWithData
*
endAt
;
}
StreamWithState
;
}
StreamWithState
;
typedef
struct
StreamWithStateResult
{
typedef
struct
StreamWithStateResult
{
FstSlice
data
;
FstSlice
data
;
FstOutput
out
;
FstOutput
out
;
void
*
state
;
void
*
state
;
}
StreamWithStateResult
;
}
StreamWithStateResult
;
StreamWithStateResult
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
);
StreamWithStateResult
*
swsResultCreate
(
FstSlice
*
data
,
FstOutput
fOut
,
void
*
state
);
void
swsResultDestroy
(
StreamWithStateResult
*
result
);
void
swsResultDestroy
(
StreamWithStateResult
*
result
);
typedef
void
*
(
*
StreamCallback
)(
void
*
);
typedef
void
*
(
*
StreamCallback
)(
void
*
);
StreamWithState
*
streamWithStateCreate
(
Fst
*
fst
,
AutomationCtx
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
)
;
StreamWithState
*
streamWithStateCreate
(
Fst
*
fst
,
AutomationCtx
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
);
void
streamWithStateDestroy
(
StreamWithState
*
sws
);
void
streamWithStateDestroy
(
StreamWithState
*
sws
);
bool
streamWithStateSeekMin
(
StreamWithState
*
sws
,
FstBoundWithData
*
min
);
bool
streamWithStateSeekMin
(
StreamWithState
*
sws
,
FstBoundWithData
*
min
);
StreamWithStateResult
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
);
StreamWithStateResult
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
);
FstStreamBuilder
*
fstStreamBuilderCreate
(
Fst
*
fst
,
AutomationCtx
*
aut
);
FstStreamBuilder
*
fstStreamBuilderCreate
(
Fst
*
fst
,
AutomationCtx
*
aut
);
// set up bound range
// set up bound range
...
@@ -333,7 +326,6 @@ FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, AutomationCtx *aut);
...
@@ -333,7 +326,6 @@ FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, AutomationCtx *aut);
FstStreamBuilder
*
fstStreamBuilderRange
(
FstStreamBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
);
FstStreamBuilder
*
fstStreamBuilderRange
(
FstStreamBuilder
*
b
,
FstSlice
*
val
,
RangeType
type
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/index/inc/index_fst_automation.h
浏览文件 @
5d4d7b47
...
@@ -21,13 +21,9 @@ extern "C" {
...
@@ -21,13 +21,9 @@ extern "C" {
#include "index_fst_util.h"
#include "index_fst_util.h"
typedef
struct
AutomationCtx
AutomationCtx
;
typedef
struct
AutomationCtx
AutomationCtx
;
typedef
enum
AutomationType
{
typedef
enum
AutomationType
{
AUTOMATION_PREFIX
,
AUTMMATION_MATCH
}
AutomationType
;
AUTOMATION_PREFIX
,
AUTMMATION_MATCH
}
AutomationType
;
typedef
struct
StartWith
{
typedef
struct
StartWith
{
AutomationCtx
*
autoSelf
;
AutomationCtx
*
autoSelf
;
...
@@ -40,12 +36,11 @@ typedef struct Complement {
...
@@ -40,12 +36,11 @@ typedef struct Complement {
// automation
// automation
typedef
struct
AutomationCtx
{
typedef
struct
AutomationCtx
{
AutomationType
type
;
AutomationType
type
;
void
*
stdata
;
void
*
stdata
;
char
*
data
;
char
*
data
;
}
AutomationCtx
;
}
AutomationCtx
;
typedef
enum
ValueType
{
FST_INT
,
FST_CHAR
,
FST_ARRAY
}
ValueType
;
typedef
enum
ValueType
{
FST_INT
,
FST_CHAR
,
FST_ARRAY
}
ValueType
;
typedef
enum
StartWithStateKind
{
Done
,
Running
}
StartWithStateKind
;
typedef
enum
StartWithStateKind
{
Done
,
Running
}
StartWithStateKind
;
typedef
struct
StartWithStateValue
{
typedef
struct
StartWithStateValue
{
...
@@ -53,24 +48,23 @@ typedef struct StartWithStateValue {
...
@@ -53,24 +48,23 @@ typedef struct StartWithStateValue {
ValueType
type
;
ValueType
type
;
union
{
union
{
int
val
;
int
val
;
char
*
ptr
;
char
*
ptr
;
SArray
*
arr
;
SArray
*
arr
;
// add more type
// add more type
}
;
};
}
StartWithStateValue
;
}
StartWithStateValue
;
StartWithStateValue
*
startWithStateValueCreate
(
StartWithStateKind
kind
,
ValueType
ty
,
void
*
val
);
StartWithStateValue
*
startWithStateValueCreate
(
StartWithStateKind
kind
,
ValueType
ty
,
void
*
val
);
StartWithStateValue
*
startWithStateValueDump
(
StartWithStateValue
*
sv
);
StartWithStateValue
*
startWithStateValueDump
(
StartWithStateValue
*
sv
);
void
startWithStateValueDestroy
(
void
*
sv
);
void
startWithStateValueDestroy
(
void
*
sv
);
typedef
struct
AutomationFunc
{
typedef
struct
AutomationFunc
{
void
*
(
*
start
)(
AutomationCtx
*
ctx
)
;
void
*
(
*
start
)(
AutomationCtx
*
ctx
);
bool
(
*
isMatch
)(
AutomationCtx
*
ctx
,
void
*
);
bool
(
*
isMatch
)(
AutomationCtx
*
ctx
,
void
*
);
bool
(
*
canMatch
)(
AutomationCtx
*
ctx
,
void
*
data
);
bool
(
*
canMatch
)(
AutomationCtx
*
ctx
,
void
*
data
);
bool
(
*
willAlwaysMatch
)(
AutomationCtx
*
ctx
,
void
*
state
);
bool
(
*
willAlwaysMatch
)(
AutomationCtx
*
ctx
,
void
*
state
);
void
*
(
*
accept
)(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
);
void
*
(
*
accept
)(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
);
void
*
(
*
acceptEof
)(
AutomationCtx
*
ct
,
void
*
state
);
void
*
(
*
acceptEof
)(
AutomationCtx
*
ct
,
void
*
state
);
}
AutomationFunc
;
}
AutomationFunc
;
AutomationCtx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
);
AutomationCtx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
);
...
...
source/libs/index/inc/index_fst_common.h
浏览文件 @
5d4d7b47
#ifndef __INDEX_FST_COMM_H__
#ifndef __INDEX_FST_COMM_H__
#define __INDEX_FST_COMM_H__
#define __INDEX_FST_COMM_H__
#include "tutil.h"
extern
const
uint8_t
COMMON_INPUTS
[];
extern
const
uint8_t
COMMON_INPUTS
[];
extern
c
har
const
COMMON_INPUTS_INV
[];
extern
c
onst
char
COMMON_INPUTS_INV
[];
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
...
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
5d4d7b47
...
@@ -22,11 +22,10 @@ extern "C" {
...
@@ -22,11 +22,10 @@ extern "C" {
#include "tfile.h"
#include "tfile.h"
#define DefaultMem 1024 * 1024
#define DefaultMem 1024*1024
static
char
tmpFile
[]
=
"./index"
;
static
char
tmpFile
[]
=
"./index"
;
typedef
enum
WriterType
{
TMemory
,
TFile
}
WriterType
;
typedef
enum
WriterType
{
TMemory
,
TFile
}
WriterType
;
typedef
struct
WriterCtx
{
typedef
struct
WriterCtx
{
int
(
*
write
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
write
)(
struct
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
...
@@ -40,7 +39,7 @@ typedef struct WriterCtx {
...
@@ -40,7 +39,7 @@ typedef struct WriterCtx {
}
file
;
}
file
;
struct
{
struct
{
int32_t
capa
;
int32_t
capa
;
char
*
buf
;
char
*
buf
;
}
mem
;
}
mem
;
};
};
int32_t
offset
;
int32_t
offset
;
...
@@ -51,14 +50,13 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len);
...
@@ -51,14 +50,13 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len);
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
);
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
);
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
);
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
);
void
writerCtxDestroy
(
WriterCtx
*
w
);
void
writerCtxDestroy
(
WriterCtx
*
w
);
typedef
uint32_t
CheckSummer
;
typedef
uint32_t
CheckSummer
;
typedef
struct
FstCountingWriter
{
typedef
struct
FstCountingWriter
{
void
*
wrt
;
// wrap any writer that counts and checksum bytes written
void
*
wrt
;
// wrap any writer that counts and checksum bytes written
uint64_t
count
;
uint64_t
count
;
CheckSummer
summer
;
CheckSummer
summer
;
}
FstCountingWriter
;
}
FstCountingWriter
;
...
@@ -69,17 +67,14 @@ int fstCountingWriterRead(FstCountingWriter *write, uint8_t *buf, uint32_t len);
...
@@ -69,17 +67,14 @@ int fstCountingWriterRead(FstCountingWriter *write, uint8_t *buf, uint32_t len);
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
);
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
);
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
);
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
);
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wtr
);
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wtr
);
void
fstCountingWriterDestroy
(
FstCountingWriter
*
w
);
void
fstCountingWriterDestroy
(
FstCountingWriter
*
w
);
void
fstCountingWriterPackUintIn
(
FstCountingWriter
*
writer
,
uint64_t
n
,
uint8_t
nBytes
);
void
fstCountingWriterPackUintIn
(
FstCountingWriter
*
writer
,
uint64_t
n
,
uint8_t
nBytes
);
uint8_t
fstCountingWriterPackUint
(
FstCountingWriter
*
writer
,
uint64_t
n
);
uint8_t
fstCountingWriterPackUint
(
FstCountingWriter
*
writer
,
uint64_t
n
);
#define FST_WRITER_COUNT(writer) (writer->count)
#define FST_WRITER_COUNT(writer) (writer->count)
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
...
@@ -89,5 +84,3 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n);
...
@@ -89,5 +84,3 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n);
#endif
#endif
#endif
#endif
source/libs/index/inc/index_fst_node.h
浏览文件 @
5d4d7b47
...
@@ -20,17 +20,17 @@
...
@@ -20,17 +20,17 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "index_fst_util.h"
#include "index_fst_counting_writer.h"
#include "index_fst_counting_writer.h"
#include "index_fst_util.h"
#define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal)
#define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal)
#define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0)
#define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0)
#define FST_BUILDER_NODE_FINALOUTPUT_ISZERO(bn) (bn->finalOutput == 0)
#define FST_BUILDER_NODE_FINALOUTPUT_ISZERO(bn) (bn->finalOutput == 0)
typedef
struct
FstTransition
{
typedef
struct
FstTransition
{
uint8_t
inp
;
//
The byte input associated with this transition.
uint8_t
inp
;
//
The byte input associated with this transition.
Output
out
;
//The output associated with this transition
Output
out
;
// The output associated with this transition
CompiledAddr
addr
;
//
The address of the node that this transition points to
CompiledAddr
addr
;
//
The address of the node that this transition points to
}
FstTransition
;
}
FstTransition
;
typedef
struct
FstBuilderNode
{
typedef
struct
FstBuilderNode
{
...
@@ -45,7 +45,8 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
...
@@ -45,7 +45,8 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
);
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
);
//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
// bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt,
// CompiledAddr lastAddr, CompiledAddr startAddr);
bool
fstBuilderNodeEqual
(
FstBuilderNode
*
n1
,
FstBuilderNode
*
n2
);
bool
fstBuilderNodeEqual
(
FstBuilderNode
*
n1
,
FstBuilderNode
*
n2
);
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
);
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
);
...
...
source/libs/index/inc/index_fst_registry.h
浏览文件 @
5d4d7b47
...
@@ -19,9 +19,9 @@
...
@@ -19,9 +19,9 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "index_fst_node.h"
#include "index_fst_util.h"
#include "index_fst_util.h"
#include "tarray.h"
#include "tarray.h"
#include "index_fst_node.h"
typedef
struct
FstRegistryCell
{
typedef
struct
FstRegistryCell
{
CompiledAddr
addr
;
CompiledAddr
addr
;
...
@@ -29,38 +29,37 @@ typedef struct FstRegistryCell {
...
@@ -29,38 +29,37 @@ typedef struct FstRegistryCell {
}
FstRegistryCell
;
}
FstRegistryCell
;
#define FST_REGISTRY_CELL_IS_EMPTY(cell) (cell->addr == NONE_ADDRESS)
#define FST_REGISTRY_CELL_IS_EMPTY(cell) (cell->addr == NONE_ADDRESS)
#define FST_REGISTRY_CELL_INSERT(cell, tAddr) do {cell->addr = tAddr;} while(0)
#define FST_REGISTRY_CELL_INSERT(cell, tAddr) \
do { \
cell->addr = tAddr; \
} while (0)
//typedef struct FstRegistryCache {
//
typedef struct FstRegistryCache {
// SArray *cells;
// SArray *cells;
// uint32_t start;
// uint32_t start;
// uint32_t end;
// uint32_t end;
//} FstRegistryCache;
//} FstRegistryCache;
typedef
enum
{
FOUND
,
NOTFOUND
,
REJECTED
}
FstRegistryEntryState
;
typedef
enum
{
FOUND
,
NOTFOUND
,
REJECTED
}
FstRegistryEntryState
;
typedef
struct
FstRegistryEntry
{
typedef
struct
FstRegistryEntry
{
FstRegistryEntryState
state
;
FstRegistryEntryState
state
;
CompiledAddr
addr
;
CompiledAddr
addr
;
FstRegistryCell
*
cell
;
FstRegistryCell
*
cell
;
}
FstRegistryEntry
;
}
FstRegistryEntry
;
// Registry relation function
// Registry relation function
typedef
struct
FstRegistry
{
typedef
struct
FstRegistry
{
SArray
*
table
;
//<FstRegistryCell>
SArray
*
table
;
//<FstRegistryCell>
uint64_t
tableSize
;
// num of rows
uint64_t
tableSize
;
// num of rows
uint64_t
mruSize
;
// num of columns
uint64_t
mruSize
;
// num of columns
}
FstRegistry
;
}
FstRegistry
;
//
//
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
);
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
);
void
fstRegistryDestroy
(
FstRegistry
*
registry
);
void
fstRegistryDestroy
(
FstRegistry
*
registry
);
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
);
FstRegistryEntry
*
fstRegistryGetEntry
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
);
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
);
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
source/libs/index/inc/index_fst_util.h
浏览文件 @
5d4d7b47
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef __INDEX_FST_UTIL_H__
#ifndef __INDEX_FST_UTIL_H__
#define __INDEX_FST_UTIL_H__
#define __INDEX_FST_UTIL_H__
...
@@ -21,16 +20,15 @@
...
@@ -21,16 +20,15 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "tarray.h"
#include "index_fst_common.h"
#include "index_fst_common.h"
#include "tarray.h"
typedef
uint64_t
FstType
;
typedef
uint64_t
FstType
;
typedef
uint64_t
CompiledAddr
;
typedef
uint64_t
CompiledAddr
;
typedef
uint64_t
Output
;
typedef
uint64_t
Output
;
typedef
uint8_t
PackSizes
;
typedef
uint8_t
PackSizes
;
// A sentinel value used to indicate an empty final state
//A sentinel value used to indicate an empty final state
extern
const
CompiledAddr
EMPTY_ADDRESS
;
extern
const
CompiledAddr
EMPTY_ADDRESS
;
/// A sentinel value used to indicate an invalid state.
/// A sentinel value used to indicate an invalid state.
extern
const
CompiledAddr
NONE_ADDRESS
;
extern
const
CompiledAddr
NONE_ADDRESS
;
...
@@ -48,29 +46,33 @@ extern const uint64_t TRANS_INDEX_THRESHOLD;
...
@@ -48,29 +46,33 @@ extern const uint64_t TRANS_INDEX_THRESHOLD;
//
//
// `0` is a legal value which means there are no transitions/outputs
// `0` is a legal value which means there are no transitions/outputs
#define FST_SET_TRANSITION_PACK_SIZE(v, sz) \
do { \
v = (v & 0b00001111) | (sz << 4); \
} while (0)
#define FST_GET_TRANSITION_PACK_SIZE(v) (((v)&0b11110000) >> 4)
#define FST_SET_OUTPUT_PACK_SIZE(v, sz) \
do { \
v = (v & 0b11110000) | sz; \
} while (0)
#define FST_GET_OUTPUT_PACK_SIZE(v) ((v)&0b00001111)
#define FST_SET_TRANSITION_PACK_SIZE(v, sz) do {v = (v & 0b00001111) | (sz << 4); } while(0)
#define COMMON_INPUT(idx) COMMON_INPUTS_INV[(idx)-1]
#define FST_GET_TRANSITION_PACK_SIZE(v) (((v) & 0b11110000) >> 4)
#define FST_SET_OUTPUT_PACK_SIZE(v, sz) do { v = (v & 0b11110000) | sz; } while(0)
#define FST_GET_OUTPUT_PACK_SIZE(v) ((v) & 0b00001111)
#define COMMON_INPUT(idx) COMMON_INPUTS_INV[(idx) - 1]
#define COMMON_INDEX(v, max, val) do { \
#define COMMON_INDEX(v, max, val) \
val = ((uint16_t)COMMON_INPUTS[v] + 1)%256; \
do { \
val = val > max ? 0: val; \
val = ((uint16_t)COMMON_INPUTS[v] + 1) % 256; \
} while(0)
val = val > max ? 0 : val; \
} while (0)
// uint8_t commonInput(uint8_t idx);
//uint8_t commonInput(uint8_t idx);
// uint8_t commonIdx(uint8_t v, uint8_t max);
//uint8_t commonIdx(uint8_t v, uint8_t max);
uint8_t
packSize
(
uint64_t
n
);
uint8_t
packSize
(
uint64_t
n
);
uint64_t
unpackUint64
(
uint8_t
*
ch
,
uint8_t
sz
);
uint64_t
unpackUint64
(
uint8_t
*
ch
,
uint8_t
sz
);
uint8_t
packDeltaSize
(
CompiledAddr
nodeAddr
,
CompiledAddr
transAddr
);
uint8_t
packDeltaSize
(
CompiledAddr
nodeAddr
,
CompiledAddr
transAddr
);
CompiledAddr
unpackDelta
(
char
*
data
,
uint64_t
len
,
uint64_t
nodeAddr
);
CompiledAddr
unpackDelta
(
char
*
data
,
uint64_t
len
,
uint64_t
nodeAddr
);
typedef
struct
FstString
{
typedef
struct
FstString
{
uint8_t
*
data
;
uint8_t
*
data
;
uint32_t
len
;
uint32_t
len
;
...
@@ -95,9 +97,9 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
...
@@ -95,9 +97,9 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
//// stack
//// stack
//
//
//typedef (*StackFreeElemFn)(void *elem);
//
typedef (*StackFreeElemFn)(void *elem);
//
//
//typedef struct FstStack {
//
typedef struct FstStack {
// void *first;
// void *first;
// void *end;
// void *end;
// size_t elemSize;
// size_t elemSize;
...
@@ -106,15 +108,13 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
...
@@ -106,15 +108,13 @@ uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
//} FstStack;
//} FstStack;
//
//
//
//
//
FstStack* fstStackCreate(size_t elemSize, stackFreeElem);
//
FstStack* fstStackCreate(size_t elemSize, stackFreeElem);
//void *fstStackPush(FstStack *s, void *elem);
//
void *fstStackPush(FstStack *s, void *elem);
//void *fstStackTop(FstStack *s);
//
void *fstStackTop(FstStack *s);
//
size_t fstStackLen(FstStack *s);
//
size_t fstStackLen(FstStack *s);
//
void fstStackDestory(FstStack *);
//
void fstStackDestory(FstStack *);
//
//
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/index/inc/index_tfile.h
浏览文件 @
5d4d7b47
...
@@ -17,10 +17,10 @@
...
@@ -17,10 +17,10 @@
#include "index.h"
#include "index.h"
#include "indexInt.h"
#include "indexInt.h"
#include "tlockfree.h"
#include "index_tfile.h"
#include "index_fst_counting_writer.h"
#include "index_fst.h"
#include "index_fst.h"
#include "index_fst_counting_writer.h"
#include "index_tfile.h"
#include "tlockfree.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -48,7 +48,6 @@ typedef struct TFileCacheKey {
...
@@ -48,7 +48,6 @@ typedef struct TFileCacheKey {
int32_t
nColName
;
int32_t
nColName
;
}
TFileCacheKey
;
}
TFileCacheKey
;
// table cache
// table cache
// refactor to LRU cache later
// refactor to LRU cache later
typedef
struct
TFileCache
{
typedef
struct
TFileCache
{
...
@@ -57,49 +56,47 @@ typedef struct TFileCache {
...
@@ -57,49 +56,47 @@ typedef struct TFileCache {
// add more param
// add more param
}
TFileCache
;
}
TFileCache
;
typedef
struct
TFileWriter
{
typedef
struct
TFileWriter
{
FstBuilder
*
fb
;
FstBuilder
*
fb
;
WriterCtx
*
ctx
;
WriterCtx
*
ctx
;
}
TFileWriter
;
}
TFileWriter
;
typedef
struct
TFileReader
{
typedef
struct
TFileReader
{
T_REF_DECLARE
()
T_REF_DECLARE
()
Fst
*
fst
;
Fst
*
fst
;
WriterCtx
*
ctx
;
WriterCtx
*
ctx
;
TFileReadHeader
header
;
}
TFileReader
;
}
TFileReader
;
typedef
struct
IndexTFile
{
typedef
struct
IndexTFile
{
char
*
path
;
char
*
path
;
TFileCache
*
cache
;
TFileCache
*
cache
;
TFileWriter
*
tw
;
TFileWriter
*
tw
;
}
IndexTFile
;
}
IndexTFile
;
typedef
struct
TFileWriterOpt
{
typedef
struct
TFileWriterOpt
{
uint64_t
suid
;
uint64_t
suid
;
int8_t
colType
;
int8_t
colType
;
char
*
colName
;
char
*
colName
;
int32_t
nColName
;
int32_t
nColName
;
int32_t
version
;
int32_t
version
;
}
TFileWriterOpt
;
}
TFileWriterOpt
;
typedef
struct
TFileReaderOpt
{
typedef
struct
TFileReaderOpt
{
uint64_t
suid
;
uint64_t
suid
;
char
*
colName
;
char
*
colName
;
int32_t
nColName
;
int32_t
nColName
;
}
TFileReaderOpt
;
}
TFileReaderOpt
;
// tfile cache, manage tindex reader
// tfile cache, manage tindex reader
TFileCache
*
tfileCacheCreate
(
const
char
*
path
);
TFileCache
*
tfileCacheCreate
(
const
char
*
path
);
void
tfileCacheDestroy
(
TFileCache
*
tcache
);
void
tfileCacheDestroy
(
TFileCache
*
tcache
);
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
);
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
);
void
tfileCachePut
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
,
TFileReader
*
reader
);
void
tfileCachePut
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
,
TFileReader
*
reader
);
TFileReader
*
tfileReaderCreate
();
TFileReader
*
tfileReaderCreate
();
void
TFileReaderDestroy
(
TFileReader
*
reader
);
void
TFileReaderDestroy
(
TFileReader
*
reader
);
TFileWriter
*
tfileWriterCreate
(
const
char
*
suid
,
const
char
*
colName
);
TFileWriter
*
tfileWriterCreate
(
const
char
*
suid
,
const
char
*
colName
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
...
@@ -108,13 +105,9 @@ IndexTFile *indexTFileCreate(const char *path);
...
@@ -108,13 +105,9 @@ IndexTFile *indexTFileCreate(const char *path);
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
);
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
);
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
);
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
#endif
#endif
source/libs/index/inc/index_util.h
浏览文件 @
5d4d7b47
...
@@ -34,7 +34,7 @@ extern "C" {
...
@@ -34,7 +34,7 @@ extern "C" {
#define SERIALIZE_VAR_TO_BUF(buf, var, type) \
#define SERIALIZE_VAR_TO_BUF(buf, var, type) \
do { \
do { \
type c = var; \
type c = var; \
assert(sizeof(var) == sizeof(type));
\
assert(sizeof(var) == sizeof(type));
\
memcpy((void *)buf, (void *)&c, sizeof(c)); \
memcpy((void *)buf, (void *)&c, sizeof(c)); \
buf += sizeof(c); \
buf += sizeof(c); \
} while (0)
} while (0)
...
@@ -42,10 +42,9 @@ extern "C" {
...
@@ -42,10 +42,9 @@ extern "C" {
#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
do { \
do { \
memcpy((void *)buf, (void *)var, len); \
memcpy((void *)buf, (void *)var, len); \
buf += len;
\
buf += len;
\
} while (0)
} while (0)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/index/src/index.c
浏览文件 @
5d4d7b47
...
@@ -26,8 +26,11 @@
...
@@ -26,8 +26,11 @@
static
int
uidCompare
(
const
void
*
a
,
const
void
*
b
)
{
static
int
uidCompare
(
const
void
*
a
,
const
void
*
b
)
{
uint64_t
u1
=
*
(
uint64_t
*
)
a
;
uint64_t
u1
=
*
(
uint64_t
*
)
a
;
uint64_t
u2
=
*
(
uint64_t
*
)
b
;
uint64_t
u2
=
*
(
uint64_t
*
)
b
;
if
(
u1
==
u2
)
{
return
0
;
}
if
(
u1
==
u2
)
{
else
{
return
u1
<
u2
?
-
1
:
1
;
}
return
0
;
}
else
{
return
u1
<
u2
?
-
1
:
1
;
}
}
}
typedef
struct
SIdxColInfo
{
typedef
struct
SIdxColInfo
{
int
colId
;
// generated by index internal
int
colId
;
// generated by index internal
...
@@ -37,7 +40,6 @@ typedef struct SIdxColInfo {
...
@@ -37,7 +40,6 @@ typedef struct SIdxColInfo {
static
pthread_once_t
isInit
=
PTHREAD_ONCE_INIT
;
static
pthread_once_t
isInit
=
PTHREAD_ONCE_INIT
;
static
void
indexInit
();
static
void
indexInit
();
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
int
indexMergeCacheIntoTindex
(
SIndex
*
sIdx
);
static
int
indexMergeCacheIntoTindex
(
SIndex
*
sIdx
);
...
@@ -47,14 +49,16 @@ static int indexMergeFinalResults(SArray *interResults, EIndexOperatorType oType
...
@@ -47,14 +49,16 @@ static int indexMergeFinalResults(SArray *interResults, EIndexOperatorType oType
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
pthread_once
(
&
isInit
,
indexInit
);
pthread_once
(
&
isInit
,
indexInit
);
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
#ifdef USE_LUCENE
#ifdef USE_LUCENE
index_t
*
index
=
index_open
(
path
);
index_t
*
index
=
index_open
(
path
);
sIdx
->
index
=
index
;
sIdx
->
index
=
index
;
#endif
#endif
sIdx
->
cache
=
(
void
*
)
indexCacheCreate
();
sIdx
->
cache
=
(
void
*
)
indexCacheCreate
();
sIdx
->
tindex
=
NULL
;
sIdx
->
tindex
=
NULL
;
sIdx
->
colObj
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
sIdx
->
colObj
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
sIdx
->
colId
=
1
;
sIdx
->
colId
=
1
;
...
@@ -80,8 +84,7 @@ void indexClose(SIndex *sIdx) {
...
@@ -80,8 +84,7 @@ void indexClose(SIndex *sIdx) {
return
;
return
;
}
}
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
fVals
,
uint64_t
uid
)
{
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
fVals
,
uint64_t
uid
)
{
#ifdef USE_LUCENE
#ifdef USE_LUCENE
index_document_t
*
doc
=
index_document_create
();
index_document_t
*
doc
=
index_document_create
();
...
@@ -100,10 +103,10 @@ int indexPut(SIndex *index, SIndexMultiTerm * fVals, uint64_t uid) {
...
@@ -100,10 +103,10 @@ int indexPut(SIndex *index, SIndexMultiTerm * fVals, uint64_t uid) {
#ifdef USE_INVERTED_INDEX
#ifdef USE_INVERTED_INDEX
//TODO(yihao): reduce the lock range
// TODO(yihao): reduce the lock range
pthread_mutex_lock
(
&
index
->
mtx
);
pthread_mutex_lock
(
&
index
->
mtx
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIdxColInfo
*
fi
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
SIdxColInfo
*
fi
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
if
(
fi
==
NULL
)
{
if
(
fi
==
NULL
)
{
SIdxColInfo
tfi
=
{.
colId
=
index
->
colId
};
SIdxColInfo
tfi
=
{.
colId
=
index
->
colId
};
...
@@ -111,13 +114,13 @@ int indexPut(SIndex *index, SIndexMultiTerm * fVals, uint64_t uid) {
...
@@ -111,13 +114,13 @@ int indexPut(SIndex *index, SIndexMultiTerm * fVals, uint64_t uid) {
index
->
colId
++
;
index
->
colId
++
;
taosHashPut
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
,
&
tfi
,
sizeof
(
tfi
));
taosHashPut
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
,
&
tfi
,
sizeof
(
tfi
));
}
else
{
}
else
{
//
TODO, del
//
TODO, del
}
}
}
}
pthread_mutex_unlock
(
&
index
->
mtx
);
pthread_mutex_unlock
(
&
index
->
mtx
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
fVals
);
i
++
)
{
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIndexTerm
*
p
=
taosArrayGetP
(
fVals
,
i
);
SIdxColInfo
*
fi
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
SIdxColInfo
*
fi
=
taosHashGet
(
index
->
colObj
,
p
->
colName
,
p
->
nColName
);
assert
(
fi
!=
NULL
);
assert
(
fi
!=
NULL
);
int32_t
colId
=
fi
->
colId
;
int32_t
colId
=
fi
->
colId
;
...
@@ -138,11 +141,11 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
...
@@ -138,11 +141,11 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
int
nQuery
=
taosArrayGetSize
(
multiQuerys
->
query
);
int
nQuery
=
taosArrayGetSize
(
multiQuerys
->
query
);
char
**
fields
=
malloc
(
sizeof
(
char
*
)
*
nQuery
);
char
**
fields
=
malloc
(
sizeof
(
char
*
)
*
nQuery
);
char
**
keys
=
malloc
(
sizeof
(
char
*
)
*
nQuery
);
char
**
keys
=
malloc
(
sizeof
(
char
*
)
*
nQuery
);
int
*
types
=
malloc
(
sizeof
(
int
)
*
nQuery
);
int
*
types
=
malloc
(
sizeof
(
int
)
*
nQuery
);
for
(
int
i
=
0
;
i
<
nQuery
;
i
++
)
{
for
(
int
i
=
0
;
i
<
nQuery
;
i
++
)
{
SIndexTermQuery
*
p
=
taosArrayGet
(
multiQuerys
->
query
,
i
);
SIndexTermQuery
*
p
=
taosArrayGet
(
multiQuerys
->
query
,
i
);
SIndexTerm
*
term
=
p
->
field_value
;
SIndexTerm
*
term
=
p
->
field_value
;
fields
[
i
]
=
calloc
(
1
,
term
->
nKey
+
1
);
fields
[
i
]
=
calloc
(
1
,
term
->
nKey
+
1
);
keys
[
i
]
=
calloc
(
1
,
term
->
nVal
+
1
);
keys
[
i
]
=
calloc
(
1
,
term
->
nVal
+
1
);
...
@@ -152,7 +155,7 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
...
@@ -152,7 +155,7 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
types
[
i
]
=
(
int
)(
p
->
type
);
types
[
i
]
=
(
int
)(
p
->
type
);
}
}
int
*
tResult
=
NULL
;
int
*
tResult
=
NULL
;
int
tsz
=
0
;
int
tsz
=
0
;
index_multi_search
(
index
->
index
,
(
const
char
**
)
fields
,
(
const
char
**
)
keys
,
types
,
nQuery
,
opera
,
&
tResult
,
&
tsz
);
index_multi_search
(
index
->
index
,
(
const
char
**
)
fields
,
(
const
char
**
)
keys
,
types
,
nQuery
,
opera
,
&
tResult
,
&
tsz
);
for
(
int
i
=
0
;
i
<
tsz
;
i
++
)
{
for
(
int
i
=
0
;
i
<
tsz
;
i
++
)
{
...
@@ -175,7 +178,7 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
...
@@ -175,7 +178,7 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
int
nQuery
=
taosArrayGetSize
(
multiQuerys
->
query
);
int
nQuery
=
taosArrayGetSize
(
multiQuerys
->
query
);
for
(
size_t
i
=
0
;
i
<
nQuery
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
nQuery
;
i
++
)
{
SIndexTermQuery
*
qTerm
=
taosArrayGet
(
multiQuerys
->
query
,
i
);
SIndexTermQuery
*
qTerm
=
taosArrayGet
(
multiQuerys
->
query
,
i
);
SArray
*
tResult
=
NULL
;
SArray
*
tResult
=
NULL
;
indexTermSearch
(
index
,
qTerm
,
&
tResult
);
indexTermSearch
(
index
,
qTerm
,
&
tResult
);
taosArrayPush
(
interResults
,
(
void
*
)
&
tResult
);
taosArrayPush
(
interResults
,
(
void
*
)
&
tResult
);
}
}
...
@@ -186,38 +189,36 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
...
@@ -186,38 +189,36 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
return
1
;
return
1
;
}
}
int
indexDelete
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
)
{
int
indexDelete
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
)
{
#ifdef USE_INVERTED_INDEX
#ifdef USE_INVERTED_INDEX
#endif
#endif
return
1
;
return
1
;
}
}
int
indexRebuild
(
SIndex
*
index
,
SIndexOpts
*
opts
)
{
int
indexRebuild
(
SIndex
*
index
,
SIndexOpts
*
opts
){
#ifdef USE_INVERTED_INDEX
#ifdef USE_INVERTED_INDEX
#endif
#endif
}
}
SIndexOpts
*
indexOptsCreate
()
{
SIndexOpts
*
indexOptsCreate
()
{
#ifdef USE_LUCENE
#ifdef USE_LUCENE
#endif
#endif
return
NULL
;
return
NULL
;
}
}
void
indexOptsDestroy
(
SIndexOpts
*
opts
)
{
void
indexOptsDestroy
(
SIndexOpts
*
opts
){
#ifdef USE_LUCENE
#ifdef USE_LUCENE
#endif
#endif
}
}
/*
/*
* @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
)
{
return
NULL
;
}
if
(
p
==
NULL
)
{
return
NULL
;
}
p
->
opera
=
opera
;
p
->
opera
=
opera
;
p
->
query
=
taosArrayInit
(
4
,
sizeof
(
SIndexTermQuery
));
p
->
query
=
taosArrayInit
(
4
,
sizeof
(
SIndexTermQuery
));
return
p
;
return
p
;
...
@@ -230,19 +231,21 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery *pQuery) {
...
@@ -230,19 +231,21 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery *pQuery) {
taosArrayDestroy
(
pQuery
->
query
);
taosArrayDestroy
(
pQuery
->
query
);
free
(
pQuery
);
free
(
pQuery
);
};
};
int
indexMultiTermQueryAdd
(
SIndexMultiTermQuery
*
pQuery
,
SIndexTerm
*
term
,
EIndexQueryType
qType
){
int
indexMultiTermQueryAdd
(
SIndexMultiTermQuery
*
pQuery
,
SIndexTerm
*
term
,
EIndexQueryType
qType
)
{
SIndexTermQuery
q
=
{.
qType
=
qType
,
.
term
=
term
};
SIndexTermQuery
q
=
{.
qType
=
qType
,
.
term
=
term
};
taosArrayPush
(
pQuery
->
query
,
&
q
);
taosArrayPush
(
pQuery
->
query
,
&
q
);
return
0
;
return
0
;
}
}
SIndexTerm
*
indexTermCreate
(
int64_t
suid
,
SIndexOperOnColumn
oper
,
uint8_t
colType
,
const
char
*
colName
,
SIndexTerm
*
indexTermCreate
(
int64_t
suid
,
SIndexOperOnColumn
oper
,
uint8_t
colType
,
const
char
*
colName
,
int32_t
nColName
,
const
char
*
colVal
,
int32_t
nColVal
)
{
int32_t
nColName
,
const
char
*
colVal
,
int32_t
nColVal
)
{
SIndexTerm
*
t
=
(
SIndexTerm
*
)
calloc
(
1
,
(
sizeof
(
SIndexTerm
)));
SIndexTerm
*
t
=
(
SIndexTerm
*
)
calloc
(
1
,
(
sizeof
(
SIndexTerm
)));
if
(
t
==
NULL
)
{
return
NULL
;
}
if
(
t
==
NULL
)
{
return
NULL
;
}
t
->
suid
=
suid
;
t
->
suid
=
suid
;
t
->
operType
=
oper
;
t
->
operType
=
oper
;
t
->
colType
=
colType
;
t
->
colType
=
colType
;
t
->
colName
=
(
char
*
)
calloc
(
1
,
nColName
+
1
);
t
->
colName
=
(
char
*
)
calloc
(
1
,
nColName
+
1
);
...
@@ -260,9 +263,7 @@ void indexTermDestroy(SIndexTerm *p) {
...
@@ -260,9 +263,7 @@ void indexTermDestroy(SIndexTerm *p) {
free
(
p
);
free
(
p
);
}
}
SIndexMultiTerm
*
indexMultiTermCreate
()
{
SIndexMultiTerm
*
indexMultiTermCreate
()
{
return
taosArrayInit
(
4
,
sizeof
(
SIndexTerm
*
));
}
return
taosArrayInit
(
4
,
sizeof
(
SIndexTerm
*
));
}
int
indexMultiTermAdd
(
SIndexMultiTerm
*
terms
,
SIndexTerm
*
term
)
{
int
indexMultiTermAdd
(
SIndexMultiTerm
*
terms
,
SIndexTerm
*
term
)
{
taosArrayPush
(
terms
,
&
term
);
taosArrayPush
(
terms
,
&
term
);
...
@@ -277,7 +278,7 @@ void indexMultiTermDestroy(SIndexMultiTerm *terms) {
...
@@ -277,7 +278,7 @@ void indexMultiTermDestroy(SIndexMultiTerm *terms) {
}
}
void
indexInit
()
{
void
indexInit
()
{
//do nothing
//
do nothing
}
}
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
query
,
SArray
**
result
)
{
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
query
,
SArray
**
result
)
{
int32_t
version
=
-
1
;
int32_t
version
=
-
1
;
...
@@ -299,7 +300,7 @@ static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *query, SArray **result
...
@@ -299,7 +300,7 @@ static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *query, SArray **result
pthread_mutex_unlock
(
&
sIdx
->
mtx
);
pthread_mutex_unlock
(
&
sIdx
->
mtx
);
*
result
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
*
result
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
//TODO: iterator mem and tidex
//
TODO: iterator mem and tidex
STermValueType
s
;
STermValueType
s
;
if
(
0
==
indexCacheSearch
(
sIdx
->
cache
,
query
,
colId
,
version
,
*
result
,
&
s
))
{
if
(
0
==
indexCacheSearch
(
sIdx
->
cache
,
query
,
colId
,
version
,
*
result
,
&
s
))
{
if
(
s
==
kTypeDeletion
)
{
if
(
s
==
kTypeDeletion
)
{
...
@@ -319,7 +320,9 @@ static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *query, SArray **result
...
@@ -319,7 +320,9 @@ static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *query, SArray **result
return
0
;
return
0
;
}
}
static
void
indexInterResultsDestroy
(
SArray
*
results
)
{
static
void
indexInterResultsDestroy
(
SArray
*
results
)
{
if
(
results
==
NULL
)
{
return
;
}
if
(
results
==
NULL
)
{
return
;
}
size_t
sz
=
taosArrayGetSize
(
results
);
size_t
sz
=
taosArrayGetSize
(
results
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
...
@@ -327,10 +330,9 @@ static void indexInterResultsDestroy(SArray *results) {
...
@@ -327,10 +330,9 @@ static void indexInterResultsDestroy(SArray *results) {
taosArrayDestroy
(
p
);
taosArrayDestroy
(
p
);
}
}
taosArrayDestroy
(
results
);
taosArrayDestroy
(
results
);
}
}
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
fResults
)
{
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
fResults
)
{
//refactor, merge interResults into fResults by oType
//
refactor, merge interResults into fResults by oType
SArray
*
first
=
taosArrayGetP
(
interResults
,
0
);
SArray
*
first
=
taosArrayGetP
(
interResults
,
0
);
taosArraySort
(
first
,
uidCompare
);
taosArraySort
(
first
,
uidCompare
);
taosArrayRemoveDuplicate
(
first
,
uidCompare
,
NULL
);
taosArrayRemoveDuplicate
(
first
,
uidCompare
,
NULL
);
...
...
source/libs/index/src/index_cache.c
浏览文件 @
5d4d7b47
...
@@ -14,17 +14,17 @@
...
@@ -14,17 +14,17 @@
*/
*/
#include "index_cache.h"
#include "index_cache.h"
#include "tcompare.h"
#include "index_util.h"
#include "index_util.h"
#include "tcompare.h"
#define MAX_INDEX_KEY_LEN 256// test only, change later
#define MAX_INDEX_KEY_LEN 256
// test only, change later
// ref index_cache.h:22
// ref index_cache.h:22
#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))
#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))
static
char
*
getIndexKey
(
const
void
*
pData
)
{
static
char
*
getIndexKey
(
const
void
*
pData
)
{
return
NULL
;
}
return
NULL
;
}
static
int32_t
compareKey
(
const
void
*
l
,
const
void
*
r
)
{
static
int32_t
compareKey
(
const
void
*
l
,
const
void
*
r
)
{
char
*
lp
=
(
char
*
)
l
;
char
*
lp
=
(
char
*
)
l
;
char
*
rp
=
(
char
*
)
r
;
char
*
rp
=
(
char
*
)
r
;
...
@@ -41,7 +41,7 @@ static int32_t compareKey(const void *l, const void *r) {
...
@@ -41,7 +41,7 @@ static int32_t compareKey(const void *l, const void *r) {
memcpy
(
&
lf
,
lp
,
sizeof
(
lf
));
memcpy
(
&
lf
,
lp
,
sizeof
(
lf
));
memcpy
(
&
rf
,
rp
,
sizeof
(
rf
));
memcpy
(
&
rf
,
rp
,
sizeof
(
rf
));
if
(
lf
!=
rf
)
{
if
(
lf
!=
rf
)
{
return
lf
<
rf
?
-
1
:
1
;
return
lf
<
rf
?
-
1
:
1
;
}
}
lp
+=
sizeof
(
lf
);
lp
+=
sizeof
(
lf
);
rp
+=
sizeof
(
rf
);
rp
+=
sizeof
(
rf
);
...
@@ -64,11 +64,17 @@ static int32_t compareKey(const void *l, const void *r) {
...
@@ -64,11 +64,17 @@ static int32_t compareKey(const void *l, const void *r) {
// compare value
// compare value
int32_t
i
,
j
;
int32_t
i
,
j
;
for
(
i
=
0
,
j
=
0
;
i
<
lfl
&&
j
<
rfl
;
i
++
,
j
++
)
{
for
(
i
=
0
,
j
=
0
;
i
<
lfl
&&
j
<
rfl
;
i
++
,
j
++
)
{
if
(
lp
[
i
]
==
rp
[
j
])
{
continue
;
}
if
(
lp
[
i
]
==
rp
[
j
])
{
else
{
return
lp
[
i
]
<
rp
[
j
]
?
-
1
:
1
;}
continue
;
}
else
{
return
lp
[
i
]
<
rp
[
j
]
?
-
1
:
1
;
}
}
if
(
i
<
lfl
)
{
return
1
;
}
else
if
(
j
<
rfl
)
{
return
-
1
;
}
}
if
(
i
<
lfl
)
{
return
1
;}
else
if
(
j
<
rfl
)
{
return
-
1
;
}
lp
+=
lfl
;
lp
+=
lfl
;
rp
+=
rfl
;
rp
+=
rfl
;
...
@@ -91,32 +97,35 @@ static int32_t compareKey(const void *l, const void *r) {
...
@@ -91,32 +97,35 @@ static int32_t compareKey(const void *l, const void *r) {
// not care item type
// not care item type
return
0
;
return
0
;
}
}
IndexCache
*
indexCacheCreate
()
{
IndexCache
*
indexCacheCreate
()
{
IndexCache
*
cache
=
calloc
(
1
,
sizeof
(
IndexCache
));
IndexCache
*
cache
=
calloc
(
1
,
sizeof
(
IndexCache
));
cache
->
skiplist
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_INDEX_KEY_LEN
,
compareKey
,
SL_ALLOW_DUP_KEY
,
getIndexKey
);
cache
->
skiplist
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_INDEX_KEY_LEN
,
compareKey
,
SL_ALLOW_DUP_KEY
,
getIndexKey
);
return
cache
;
return
cache
;
}
}
void
indexCacheDestroy
(
void
*
cache
)
{
void
indexCacheDestroy
(
void
*
cache
)
{
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
if
(
pCache
==
NULL
)
{
return
;
}
if
(
pCache
==
NULL
)
{
return
;
}
tSkipListDestroy
(
pCache
->
skiplist
);
tSkipListDestroy
(
pCache
->
skiplist
);
free
(
pCache
);
free
(
pCache
);
}
}
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
int16_t
colId
,
int32_t
version
,
uint64_t
uid
)
{
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
int16_t
colId
,
int32_t
version
,
uint64_t
uid
)
{
if
(
cache
==
NULL
)
{
return
-
1
;}
if
(
cache
==
NULL
)
{
return
-
1
;
}
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
// encode data
// encode data
int32_t
total
=
CACHE_KEY_LEN
(
term
);
int32_t
total
=
CACHE_KEY_LEN
(
term
);
char
*
buf
=
calloc
(
1
,
total
);
char
*
buf
=
calloc
(
1
,
total
);
char
*
p
=
buf
;
char
*
p
=
buf
;
SERIALIZE_VAR_TO_BUF
(
p
,
total
,
int32_t
);
SERIALIZE_VAR_TO_BUF
(
p
,
total
,
int32_t
);
SERIALIZE_VAR_TO_BUF
(
p
,
colId
,
int16_t
);
SERIALIZE_VAR_TO_BUF
(
p
,
colId
,
int16_t
);
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
colType
);
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
colType
);
...
@@ -131,31 +140,28 @@ int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version,
...
@@ -131,31 +140,28 @@ int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version,
tSkipListPut
(
pCache
->
skiplist
,
(
void
*
)
buf
);
tSkipListPut
(
pCache
->
skiplist
,
(
void
*
)
buf
);
return
0
;
return
0
;
// encode end
// encode end
}
}
int
indexCacheDel
(
void
*
cache
,
int32_t
fieldId
,
const
char
*
fieldValue
,
int32_t
fvlen
,
uint64_t
uid
,
int8_t
operType
)
{
int
indexCacheDel
(
void
*
cache
,
int32_t
fieldId
,
const
char
*
fieldValue
,
int32_t
fvlen
,
uint64_t
uid
,
int8_t
operType
)
{
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
return
0
;
return
0
;
}
}
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
int16_t
colId
,
int32_t
version
,
SArray
*
result
,
STermValueType
*
s
)
{
int
indexCacheSearch
(
if
(
cache
==
NULL
)
{
return
-
1
;
}
void
*
cache
,
SIndexTermQuery
*
query
,
int16_t
colId
,
int32_t
version
,
SArray
*
result
,
STermValueType
*
s
)
{
IndexCache
*
pCache
=
cache
;
if
(
cache
==
NULL
)
{
SIndexTerm
*
term
=
query
->
term
;
return
-
1
;
}
IndexCache
*
pCache
=
cache
;
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
EIndexQueryType
qtype
=
query
->
qType
;
int32_t
keyLen
=
CACHE_KEY_LEN
(
term
);
int32_t
keyLen
=
CACHE_KEY_LEN
(
term
);
char
*
buf
=
calloc
(
1
,
keyLen
);
char
*
buf
=
calloc
(
1
,
keyLen
);
if
(
qtype
==
QUERY_TERM
)
{
if
(
qtype
==
QUERY_TERM
)
{
}
else
if
(
qtype
==
QUERY_PREFIX
)
{
}
else
if
(
qtype
==
QUERY_PREFIX
)
{
}
else
if
(
qtype
==
QUERY_SUFFIX
)
{
}
else
if
(
qtype
==
QUERY_SUFFIX
)
{
}
else
if
(
qtype
==
QUERY_REGEX
)
{
}
else
if
(
qtype
==
QUERY_REGEX
)
{
}
}
return
0
;
return
0
;
}
}
source/libs/index/src/index_fst.c
浏览文件 @
5d4d7b47
此差异已折叠。
点击以展开。
source/libs/index/src/index_fst_automation.c
浏览文件 @
5d4d7b47
...
@@ -15,10 +15,11 @@
...
@@ -15,10 +15,11 @@
#include "index_fst_automation.h"
#include "index_fst_automation.h"
StartWithStateValue
*
startWithStateValueCreate
(
StartWithStateKind
kind
,
ValueType
ty
,
void
*
val
)
{
StartWithStateValue
*
startWithStateValueCreate
(
StartWithStateKind
kind
,
ValueType
ty
,
void
*
val
)
{
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
if
(
nsv
==
NULL
)
{
return
NULL
;
}
if
(
nsv
==
NULL
)
{
return
NULL
;
}
nsv
->
kind
=
kind
;
nsv
->
kind
=
kind
;
nsv
->
type
=
ty
;
nsv
->
type
=
ty
;
...
@@ -29,14 +30,16 @@ StartWithStateValue *startWithStateValueCreate(StartWithStateKind kind, ValueTyp
...
@@ -29,14 +30,16 @@ StartWithStateValue *startWithStateValueCreate(StartWithStateKind kind, ValueTyp
nsv
->
ptr
=
(
char
*
)
calloc
(
1
,
len
+
1
);
nsv
->
ptr
=
(
char
*
)
calloc
(
1
,
len
+
1
);
memcpy
(
nsv
->
ptr
,
val
,
len
);
memcpy
(
nsv
->
ptr
,
val
,
len
);
}
else
if
(
ty
==
FST_ARRAY
)
{
}
else
if
(
ty
==
FST_ARRAY
)
{
//
TODO,
//
TODO,
//
nsv->arr = taosArrayFromList()
//
nsv->arr = taosArrayFromList()
}
}
return
nsv
;
return
nsv
;
}
}
void
startWithStateValueDestroy
(
void
*
val
)
{
void
startWithStateValueDestroy
(
void
*
val
)
{
StartWithStateValue
*
sv
=
(
StartWithStateValue
*
)
val
;
StartWithStateValue
*
sv
=
(
StartWithStateValue
*
)
val
;
if
(
sv
==
NULL
)
{
return
;
}
if
(
sv
==
NULL
)
{
return
;
}
if
(
sv
->
type
==
FST_INT
)
{
if
(
sv
->
type
==
FST_INT
)
{
//
//
...
@@ -49,10 +52,12 @@ void startWithStateValueDestroy(void *val) {
...
@@ -49,10 +52,12 @@ void startWithStateValueDestroy(void *val) {
}
}
StartWithStateValue
*
startWithStateValueDump
(
StartWithStateValue
*
sv
)
{
StartWithStateValue
*
startWithStateValueDump
(
StartWithStateValue
*
sv
)
{
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
StartWithStateValue
*
nsv
=
calloc
(
1
,
sizeof
(
StartWithStateValue
));
if
(
nsv
==
NULL
)
{
return
NULL
;
}
if
(
nsv
==
NULL
)
{
return
NULL
;
}
nsv
->
kind
=
sv
->
kind
;
nsv
->
kind
=
sv
->
kind
;
nsv
->
type
=
sv
->
type
;
nsv
->
type
=
sv
->
type
;
if
(
nsv
->
type
==
FST_INT
)
{
if
(
nsv
->
type
==
FST_INT
)
{
nsv
->
val
=
sv
->
val
;
nsv
->
val
=
sv
->
val
;
}
else
if
(
nsv
->
type
==
FST_CHAR
)
{
}
else
if
(
nsv
->
type
==
FST_CHAR
)
{
...
@@ -64,27 +69,26 @@ StartWithStateValue *startWithStateValueDump(StartWithStateValue *sv) {
...
@@ -64,27 +69,26 @@ StartWithStateValue *startWithStateValueDump(StartWithStateValue *sv) {
return
nsv
;
return
nsv
;
}
}
// prefix query, impl later
// prefix query, impl later
static
void
*
prefixStart
(
AutomationCtx
*
ctx
)
{
static
void
*
prefixStart
(
AutomationCtx
*
ctx
)
{
StartWithStateValue
*
data
=
(
StartWithStateValue
*
)(
ctx
->
stdata
);
StartWithStateValue
*
data
=
(
StartWithStateValue
*
)(
ctx
->
stdata
);
return
startWithStateValueDump
(
data
);
return
startWithStateValueDump
(
data
);
};
};
static
bool
prefixIsMatch
(
AutomationCtx
*
ctx
,
void
*
sv
)
{
static
bool
prefixIsMatch
(
AutomationCtx
*
ctx
,
void
*
sv
)
{
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
return
ssv
->
val
==
strlen
(
ctx
->
data
);
return
ssv
->
val
==
strlen
(
ctx
->
data
);
}
}
static
bool
prefixCanMatch
(
AutomationCtx
*
ctx
,
void
*
sv
)
{
static
bool
prefixCanMatch
(
AutomationCtx
*
ctx
,
void
*
sv
)
{
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
sv
;
return
ssv
->
val
>=
0
;
return
ssv
->
val
>=
0
;
}
}
static
bool
prefixWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
static
bool
prefixWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
return
true
;
static
void
*
prefixAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
}
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
state
;
static
void
*
prefixAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
if
(
ssv
==
NULL
||
ctx
==
NULL
)
{
StartWithStateValue
*
ssv
=
(
StartWithStateValue
*
)
state
;
return
NULL
;
if
(
ssv
==
NULL
||
ctx
==
NULL
)
{
return
NULL
;
}
}
char
*
data
=
ctx
->
data
;
char
*
data
=
ctx
->
data
;
if
(
ssv
->
kind
==
Done
)
{
if
(
ssv
->
kind
==
Done
)
{
...
@@ -102,55 +106,30 @@ static void* prefixAccept(AutomationCtx *ctx, void *state, uint8_t byte) {
...
@@ -102,55 +106,30 @@ static void* prefixAccept(AutomationCtx *ctx, void *state, uint8_t byte) {
}
}
return
NULL
;
return
NULL
;
}
}
static
void
*
prefixAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
static
void
*
prefixAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
return
NULL
;
}
// pattern query, impl later
// pattern query, impl later
static
void
*
patternStart
(
AutomationCtx
*
ctx
)
{
static
void
*
patternStart
(
AutomationCtx
*
ctx
)
{
return
NULL
;
}
return
NULL
;
static
bool
patternIsMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
return
true
;
}
}
static
bool
patternCanMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternIsMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
static
bool
patternWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
return
true
;
}
static
bool
patternCanMatch
(
AutomationCtx
*
ctx
,
void
*
data
)
{
return
true
;
}
static
bool
patternWillAlwaysMatch
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
true
;
}
static
void
*
patternAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
static
void
*
patternAccept
(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
)
{
return
NULL
;
}
return
NULL
;
}
static
void
*
patternAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
static
void
*
patternAcceptEof
(
AutomationCtx
*
ctx
,
void
*
state
)
{
return
NULL
;
}
return
NULL
;
}
AutomationFunc
automFuncs
[]
=
{{
AutomationFunc
automFuncs
[]
=
{
prefixStart
,
{
prefixStart
,
prefixIsMatch
,
prefixCanMatch
,
prefixWillAlwaysMatch
,
prefixAccept
,
prefixAcceptEof
},
prefixIsMatch
,
{
patternStart
,
patternIsMatch
,
patternCanMatch
,
patternWillAlwaysMatch
,
patternAccept
,
patternAcceptEof
}
prefixCanMatch
,
prefixWillAlwaysMatch
,
prefixAccept
,
prefixAcceptEof
},
{
patternStart
,
patternIsMatch
,
patternCanMatch
,
patternWillAlwaysMatch
,
patternAccept
,
patternAcceptEof
}
// add more search type
// add more search type
};
};
AutomationCtx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
)
{
AutomationCtx
*
automCtxCreate
(
void
*
data
,
AutomationType
atype
)
{
AutomationCtx
*
ctx
=
calloc
(
1
,
sizeof
(
AutomationCtx
));
AutomationCtx
*
ctx
=
calloc
(
1
,
sizeof
(
AutomationCtx
));
if
(
ctx
==
NULL
)
{
return
NULL
;
}
if
(
ctx
==
NULL
)
{
return
NULL
;
}
StartWithStateValue
*
sv
=
NULL
;
StartWithStateValue
*
sv
=
NULL
;
if
(
atype
==
AUTOMATION_PREFIX
)
{
if
(
atype
==
AUTOMATION_PREFIX
)
{
...
@@ -158,14 +137,13 @@ AutomationCtx* automCtxCreate(void *data,AutomationType atype) {
...
@@ -158,14 +137,13 @@ AutomationCtx* automCtxCreate(void *data,AutomationType atype) {
sv
=
startWithStateValueCreate
(
Running
,
FST_INT
,
&
val
);
sv
=
startWithStateValueCreate
(
Running
,
FST_INT
,
&
val
);
ctx
->
stdata
=
(
void
*
)
sv
;
ctx
->
stdata
=
(
void
*
)
sv
;
}
else
if
(
atype
==
AUTMMATION_MATCH
)
{
}
else
if
(
atype
==
AUTMMATION_MATCH
)
{
}
else
{
}
else
{
// add more search type
// add more search type
}
}
char
*
src
=
(
char
*
)
data
;
char
*
src
=
(
char
*
)
data
;
size_t
len
=
strlen
(
src
);
size_t
len
=
strlen
(
src
);
char
*
dst
=
(
char
*
)
malloc
(
len
*
sizeof
(
char
)
+
1
);
char
*
dst
=
(
char
*
)
malloc
(
len
*
sizeof
(
char
)
+
1
);
memcpy
(
dst
,
src
,
len
);
memcpy
(
dst
,
src
,
len
);
dst
[
len
]
=
0
;
dst
[
len
]
=
0
;
...
...
source/libs/index/src/index_fst_common.c
浏览文件 @
5d4d7b47
...
@@ -12,8 +12,7 @@
...
@@ -12,8 +12,7 @@
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "index_fst_common.h"
#include "tutil.h"
const
uint8_t
COMMON_INPUTS
[]
=
{
const
uint8_t
COMMON_INPUTS
[]
=
{
84
,
// '\x00'
84
,
// '\x00'
...
@@ -275,33 +274,260 @@ const uint8_t COMMON_INPUTS[] = {
...
@@ -275,33 +274,260 @@ const uint8_t COMMON_INPUTS[] = {
};
};
const
char
COMMON_INPUTS_INV
[]
=
{
const
char
COMMON_INPUTS_INV
[]
=
{
't'
,
'e'
,
'/'
,
'o'
,
'a'
,
's'
,
'r'
,
'i'
,
'p'
,
'c'
,
'n'
,
'w'
,
't'
,
'.'
,
'h'
,
'l'
,
'm'
,
'-'
,
'd'
,
'u'
,
'0'
,
'1'
,
'2'
,
'g'
,
'='
,
'e'
,
':'
,
'b'
,
'f'
,
'3'
,
'y'
,
'5'
,
'&'
,
'_'
,
'4'
,
'v'
,
'9'
,
'6'
,
'/'
,
'7'
,
'8'
,
'k'
,
'%'
,
'?'
,
'x'
,
'C'
,
'D'
,
'A'
,
'S'
,
'F'
,
'I'
,
'o'
,
'B'
,
'E'
,
'j'
,
'P'
,
'T'
,
'z'
,
'R'
,
'N'
,
'M'
,
'+'
,
'L'
,
'O'
,
'a'
,
'q'
,
'H'
,
'G'
,
'W'
,
'U'
,
'V'
,
','
,
'Y'
,
'K'
,
'J'
,
'Z'
,
'X'
,
's'
,
'Q'
,
';'
,
')'
,
'('
,
'~'
,
'['
,
']'
,
'$'
,
'!'
,
'\''
,
'*'
,
'@'
,
'r'
,
'\x00'
,
'\x01'
,
'\x02'
,
'\x03'
,
'\x04'
,
'\x05'
,
'\x06'
,
'\x07'
,
'i'
,
'\x08'
,
'\t'
,
'\n'
,
'\x0b'
,
'\x0c'
,
'\r'
,
'\x0e'
,
'\x0f'
,
'\x10'
,
'p'
,
'\x11'
,
'\x12'
,
'\x13'
,
'\x14'
,
'\x15'
,
'\x16'
,
'\x17'
,
'\x18'
,
'c'
,
'\x19'
,
'\x1a'
,
'\x1b'
,
'\x1c'
,
'\x1d'
,
'\x1e'
,
'\x1f'
,
' '
,
'"'
,
'n'
,
'#'
,
'<'
,
'>'
,
'\\'
,
'^'
,
'`'
,
'{'
,
'|'
,
'}'
,
'\x7f'
,
'\x80'
,
'w'
,
'\x81'
,
'\x82'
,
'\x83'
,
'\x84'
,
'\x85'
,
'\x86'
,
'\x87'
,
'\x88'
,
'.'
,
'\x89'
,
'\x8a'
,
'\x8b'
,
'\x8c'
,
'\x8d'
,
'\x8e'
,
'\x8f'
,
'\x90'
,
'h'
,
'\x91'
,
'\x92'
,
'\x93'
,
'\x94'
,
'\x95'
,
'\x96'
,
'\x97'
,
'\x98'
,
'l'
,
'\x99'
,
'\x9a'
,
'\x9b'
,
'\x9c'
,
'\x9d'
,
'\x9e'
,
'\x9f'
,
'\xa0'
,
'm'
,
'\xa1'
,
'\xa2'
,
'\xa3'
,
'\xa4'
,
'\xa5'
,
'\xa6'
,
'\xa7'
,
'\xa8'
,
'-'
,
'\xa9'
,
'\xaa'
,
'\xab'
,
'\xac'
,
'\xad'
,
'\xae'
,
'\xaf'
,
'\xb0'
,
'd'
,
'\xb1'
,
'\xb2'
,
'\xb3'
,
'\xb4'
,
'\xb5'
,
'\xb6'
,
'\xb7'
,
'\xb8'
,
'u'
,
'\xb9'
,
'\xba'
,
'\xbb'
,
'\xbc'
,
'\xbd'
,
'\xbe'
,
'\xbf'
,
'\xc0'
,
'0'
,
'\xc1'
,
'\xc2'
,
'\xc3'
,
'\xc4'
,
'\xc5'
,
'\xc6'
,
'\xc7'
,
'\xc8'
,
'1'
,
'\xc9'
,
'\xca'
,
'\xcb'
,
'\xcc'
,
'\xcd'
,
'\xce'
,
'\xcf'
,
'\xd0'
,
'2'
,
'\xd1'
,
'\xd2'
,
'\xd3'
,
'\xd4'
,
'\xd5'
,
'\xd6'
,
'\xd7'
,
'\xd8'
,
'g'
,
'\xd9'
,
'\xda'
,
'\xdb'
,
'\xdc'
,
'\xdd'
,
'\xde'
,
'\xdf'
,
'\xe0'
,
'='
,
'\xe1'
,
'\xe2'
,
'\xe3'
,
'\xe4'
,
'\xe5'
,
'\xe6'
,
'\xe7'
,
'\xe8'
,
':'
,
'\xe9'
,
'\xea'
,
'\xeb'
,
'\xec'
,
'\xed'
,
'\xee'
,
'\xef'
,
'\xf0'
,
'b'
,
'\xf1'
,
'\xf2'
,
'\xf3'
,
'\xf4'
,
'\xf5'
,
'\xf6'
,
'\xf7'
,
'\xf8'
,
'f'
,
'\xf9'
,
'\xfa'
,
'\xfb'
,
'\xfc'
,
'\xfd'
,
'\xfe'
,
'\xff'
,
'3'
,
'y'
,
'5'
,
'&'
,
'_'
,
'4'
,
'v'
,
'9'
,
'6'
,
'7'
,
'8'
,
'k'
,
'%'
,
'?'
,
'x'
,
'C'
,
'D'
,
'A'
,
'S'
,
'F'
,
'I'
,
'B'
,
'E'
,
'j'
,
'P'
,
'T'
,
'z'
,
'R'
,
'N'
,
'M'
,
'+'
,
'L'
,
'O'
,
'q'
,
'H'
,
'G'
,
'W'
,
'U'
,
'V'
,
','
,
'Y'
,
'K'
,
'J'
,
'Z'
,
'X'
,
'Q'
,
';'
,
')'
,
'('
,
'~'
,
'['
,
']'
,
'$'
,
'!'
,
'\''
,
'*'
,
'@'
,
'\x00'
,
'\x01'
,
'\x02'
,
'\x03'
,
'\x04'
,
'\x05'
,
'\x06'
,
'\x07'
,
'\x08'
,
'\t'
,
'\n'
,
'\x0b'
,
'\x0c'
,
'\r'
,
'\x0e'
,
'\x0f'
,
'\x10'
,
'\x11'
,
'\x12'
,
'\x13'
,
'\x14'
,
'\x15'
,
'\x16'
,
'\x17'
,
'\x18'
,
'\x19'
,
'\x1a'
,
'\x1b'
,
'\x1c'
,
'\x1d'
,
'\x1e'
,
'\x1f'
,
' '
,
'"'
,
'#'
,
'<'
,
'>'
,
'\\'
,
'^'
,
'`'
,
'{'
,
'|'
,
'}'
,
'\x7f'
,
'\x80'
,
'\x81'
,
'\x82'
,
'\x83'
,
'\x84'
,
'\x85'
,
'\x86'
,
'\x87'
,
'\x88'
,
'\x89'
,
'\x8a'
,
'\x8b'
,
'\x8c'
,
'\x8d'
,
'\x8e'
,
'\x8f'
,
'\x90'
,
'\x91'
,
'\x92'
,
'\x93'
,
'\x94'
,
'\x95'
,
'\x96'
,
'\x97'
,
'\x98'
,
'\x99'
,
'\x9a'
,
'\x9b'
,
'\x9c'
,
'\x9d'
,
'\x9e'
,
'\x9f'
,
'\xa0'
,
'\xa1'
,
'\xa2'
,
'\xa3'
,
'\xa4'
,
'\xa5'
,
'\xa6'
,
'\xa7'
,
'\xa8'
,
'\xa9'
,
'\xaa'
,
'\xab'
,
'\xac'
,
'\xad'
,
'\xae'
,
'\xaf'
,
'\xb0'
,
'\xb1'
,
'\xb2'
,
'\xb3'
,
'\xb4'
,
'\xb5'
,
'\xb6'
,
'\xb7'
,
'\xb8'
,
'\xb9'
,
'\xba'
,
'\xbb'
,
'\xbc'
,
'\xbd'
,
'\xbe'
,
'\xbf'
,
'\xc0'
,
'\xc1'
,
'\xc2'
,
'\xc3'
,
'\xc4'
,
'\xc5'
,
'\xc6'
,
'\xc7'
,
'\xc8'
,
'\xc9'
,
'\xca'
,
'\xcb'
,
'\xcc'
,
'\xcd'
,
'\xce'
,
'\xcf'
,
'\xd0'
,
'\xd1'
,
'\xd2'
,
'\xd3'
,
'\xd4'
,
'\xd5'
,
'\xd6'
,
'\xd7'
,
'\xd8'
,
'\xd9'
,
'\xda'
,
'\xdb'
,
'\xdc'
,
'\xdd'
,
'\xde'
,
'\xdf'
,
'\xe0'
,
'\xe1'
,
'\xe2'
,
'\xe3'
,
'\xe4'
,
'\xe5'
,
'\xe6'
,
'\xe7'
,
'\xe8'
,
'\xe9'
,
'\xea'
,
'\xeb'
,
'\xec'
,
'\xed'
,
'\xee'
,
'\xef'
,
'\xf0'
,
'\xf1'
,
'\xf2'
,
'\xf3'
,
'\xf4'
,
'\xf5'
,
'\xf6'
,
'\xf7'
,
'\xf8'
,
'\xf9'
,
'\xfa'
,
'\xfb'
,
'\xfc'
,
'\xfd'
,
'\xfe'
,
'\xff'
,
};
};
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
5d4d7b47
...
@@ -12,10 +12,10 @@
...
@@ -12,10 +12,10 @@
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "
tutil
.h"
#include "
index_fst_counting_writer
.h"
#include "indexInt.h"
#include "indexInt.h"
#include "index_fst_util.h"
#include "index_fst_util.h"
#include "
index_fst_counting_writer
.h"
#include "
tutil
.h"
static
int
writeCtxDoWrite
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
static
int
writeCtxDoWrite
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
if
(
ctx
->
offset
+
len
>
ctx
->
limit
)
{
if
(
ctx
->
offset
+
len
>
ctx
->
limit
)
{
...
@@ -25,7 +25,7 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len) {
...
@@ -25,7 +25,7 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len) {
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
assert
(
len
==
tfWrite
(
ctx
->
file
.
fd
,
buf
,
len
));
assert
(
len
==
tfWrite
(
ctx
->
file
.
fd
,
buf
,
len
));
}
else
{
}
else
{
memcpy
(
ctx
->
mem
.
buf
+
ctx
->
offset
,
buf
,
len
);
memcpy
(
ctx
->
mem
.
buf
+
ctx
->
offset
,
buf
,
len
);
}
}
ctx
->
offset
+=
len
;
ctx
->
offset
+=
len
;
return
len
;
return
len
;
...
@@ -43,17 +43,19 @@ static int writeCtxDoRead(WriterCtx *ctx, uint8_t *buf, int len) {
...
@@ -43,17 +43,19 @@ static int writeCtxDoRead(WriterCtx *ctx, uint8_t *buf, int len) {
}
}
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
//tfFsync(ctx->fd);
//
tfFsync(ctx->fd);
//tfFlush(ctx->file.fd);
//
tfFlush(ctx->file.fd);
}
else
{
}
else
{
// do nothing
// do nothing
}
}
return
1
;
return
1
;
}
}
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
)
{
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
)
{
WriterCtx
*
ctx
=
calloc
(
1
,
sizeof
(
WriterCtx
));
WriterCtx
*
ctx
=
calloc
(
1
,
sizeof
(
WriterCtx
));
if
(
ctx
==
NULL
)
{
return
NULL
;
}
if
(
ctx
==
NULL
)
{
return
NULL
;
}
ctx
->
type
=
type
;
ctx
->
type
=
type
;
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
...
@@ -81,7 +83,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char *path, bool readOnly, int
...
@@ -81,7 +83,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char *path, bool readOnly, int
return
ctx
;
return
ctx
;
END:
END:
if
(
ctx
->
type
==
TMemory
)
{
free
(
ctx
->
mem
.
buf
);
}
if
(
ctx
->
type
==
TMemory
)
{
free
(
ctx
->
mem
.
buf
);
}
free
(
ctx
);
free
(
ctx
);
}
}
void
writerCtxDestroy
(
WriterCtx
*
ctx
)
{
void
writerCtxDestroy
(
WriterCtx
*
ctx
)
{
...
@@ -93,10 +97,11 @@ void writerCtxDestroy(WriterCtx *ctx) {
...
@@ -93,10 +97,11 @@ void writerCtxDestroy(WriterCtx *ctx) {
free
(
ctx
);
free
(
ctx
);
}
}
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wrt
)
{
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wrt
)
{
FstCountingWriter
*
cw
=
calloc
(
1
,
sizeof
(
FstCountingWriter
));
FstCountingWriter
*
cw
=
calloc
(
1
,
sizeof
(
FstCountingWriter
));
if
(
cw
==
NULL
)
{
return
NULL
;
}
if
(
cw
==
NULL
)
{
return
NULL
;
}
cw
->
wrt
=
wrt
;
cw
->
wrt
=
wrt
;
//(void *)(writerCtxCreate(TFile, readOnly));
//(void *)(writerCtxCreate(TFile, readOnly));
...
@@ -105,12 +110,14 @@ FstCountingWriter *fstCountingWriterCreate(void *wrt) {
...
@@ -105,12 +110,14 @@ FstCountingWriter *fstCountingWriterCreate(void *wrt) {
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
// free wrt object: close fd or free mem
// free wrt object: close fd or free mem
fstCountingWriterFlush
(
cw
);
fstCountingWriterFlush
(
cw
);
//writerCtxDestroy((WriterCtx *)(cw->wrt));
//
writerCtxDestroy((WriterCtx *)(cw->wrt));
free
(
cw
);
free
(
cw
);
}
}
int
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
int
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
if
(
write
==
NULL
)
{
return
0
;
}
if
(
write
==
NULL
)
{
return
0
;
}
// update checksum
// update checksum
// write data to file/socket or mem
// write data to file/socket or mem
WriterCtx
*
ctx
=
write
->
wrt
;
WriterCtx
*
ctx
=
write
->
wrt
;
...
@@ -121,21 +128,20 @@ int fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t len)
...
@@ -121,21 +128,20 @@ int fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t len)
return
len
;
return
len
;
}
}
int
fstCountingWriterRead
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
int
fstCountingWriterRead
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
if
(
write
==
NULL
)
{
return
0
;
}
if
(
write
==
NULL
)
{
return
0
;
}
WriterCtx
*
ctx
=
write
->
wrt
;
WriterCtx
*
ctx
=
write
->
wrt
;
int
nRead
=
ctx
->
read
(
ctx
,
buf
,
len
);
int
nRead
=
ctx
->
read
(
ctx
,
buf
,
len
);
//assert(nRead == len);
//
assert(nRead == len);
return
nRead
;
return
nRead
;
}
}
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
return
0
;
}
return
0
;
}
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
WriterCtx
*
ctx
=
write
->
wrt
;
WriterCtx
*
ctx
=
write
->
wrt
;
ctx
->
flush
(
ctx
);
ctx
->
flush
(
ctx
);
//write->wtr->flush
//
write->wtr->flush
return
1
;
return
1
;
}
}
...
@@ -156,5 +162,3 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n) {
...
@@ -156,5 +162,3 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n) {
fstCountingWriterPackUintIn
(
writer
,
n
,
nBytes
);
fstCountingWriterPackUintIn
(
writer
,
n
,
nBytes
);
return
nBytes
;
return
nBytes
;
}
}
source/libs/index/src/index_fst_node.c
浏览文件 @
5d4d7b47
...
@@ -22,23 +22,27 @@ FstBuilderNode *fstBuilderNodeDefault() {
...
@@ -22,23 +22,27 @@ FstBuilderNode *fstBuilderNodeDefault() {
return
bn
;
return
bn
;
}
}
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
)
{
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
)
{
if
(
node
==
NULL
)
{
return
;
}
if
(
node
==
NULL
)
{
return
;
}
taosArrayDestroy
(
node
->
trans
);
taosArrayDestroy
(
node
->
trans
);
free
(
node
);
free
(
node
);
}
}
bool
fstBuilderNodeEqual
(
FstBuilderNode
*
n1
,
FstBuilderNode
*
n2
)
{
bool
fstBuilderNodeEqual
(
FstBuilderNode
*
n1
,
FstBuilderNode
*
n2
)
{
if
(
n1
==
n2
)
{
return
true
;
}
if
(
n1
==
n2
)
{
if
(
n1
==
NULL
||
n2
==
NULL
)
{
return
true
;
}
if
(
n1
==
NULL
||
n2
==
NULL
)
{
return
false
;
return
false
;
}
}
if
(
n1
->
isFinal
!=
n2
->
isFinal
||
n1
->
finalOutput
!=
n2
->
finalOutput
)
{
if
(
n1
->
isFinal
!=
n2
->
isFinal
||
n1
->
finalOutput
!=
n2
->
finalOutput
)
{
return
false
;
return
false
;
}
}
size_t
s1
=
n1
->
trans
?
taosArrayGetSize
(
n1
->
trans
)
:
0
;
size_t
s1
=
n1
->
trans
?
taosArrayGetSize
(
n1
->
trans
)
:
0
;
size_t
s2
=
n2
->
trans
?
taosArrayGetSize
(
n2
->
trans
)
:
0
;
size_t
s2
=
n2
->
trans
?
taosArrayGetSize
(
n2
->
trans
)
:
0
;
if
(
s1
!=
s2
)
{
if
(
s1
!=
s2
)
{
return
false
;
return
false
;
}
}
...
@@ -54,7 +58,9 @@ bool fstBuilderNodeEqual(FstBuilderNode *n1, FstBuilderNode *n2) {
...
@@ -54,7 +58,9 @@ bool fstBuilderNodeEqual(FstBuilderNode *n1, FstBuilderNode *n2) {
}
}
FstBuilderNode
*
fstBuilderNodeClone
(
FstBuilderNode
*
src
)
{
FstBuilderNode
*
fstBuilderNodeClone
(
FstBuilderNode
*
src
)
{
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
FstBuilderNode
*
node
=
malloc
(
sizeof
(
FstBuilderNode
));
if
(
node
==
NULL
)
{
return
NULL
;
}
if
(
node
==
NULL
)
{
return
NULL
;
}
//
//
size_t
sz
=
taosArrayGetSize
(
src
->
trans
);
size_t
sz
=
taosArrayGetSize
(
src
->
trans
);
...
@@ -69,16 +75,17 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src) {
...
@@ -69,16 +75,17 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src) {
node
->
isFinal
=
src
->
isFinal
;
node
->
isFinal
=
src
->
isFinal
;
node
->
finalOutput
=
src
->
finalOutput
;
node
->
finalOutput
=
src
->
finalOutput
;
return
node
;
return
node
;
}
}
// not destroy src, User's bussiness
// not destroy src, User's bussiness
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
)
{
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
)
{
if
(
dst
==
NULL
||
src
==
NULL
)
{
return
;
}
if
(
dst
==
NULL
||
src
==
NULL
)
{
return
;
}
dst
->
isFinal
=
src
->
isFinal
;
dst
->
isFinal
=
src
->
isFinal
;
dst
->
finalOutput
=
src
->
finalOutput
;
dst
->
finalOutput
=
src
->
finalOutput
;
//release free avoid mem leak
//
release free avoid mem leak
taosArrayDestroy
(
dst
->
trans
);
taosArrayDestroy
(
dst
->
trans
);
size_t
sz
=
taosArrayGetSize
(
src
->
trans
);
size_t
sz
=
taosArrayGetSize
(
src
->
trans
);
dst
->
trans
=
taosArrayInit
(
sz
,
sizeof
(
FstTransition
));
dst
->
trans
=
taosArrayInit
(
sz
,
sizeof
(
FstTransition
));
...
@@ -88,28 +95,26 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
...
@@ -88,28 +95,26 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
}
}
}
}
// bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr
//
bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr
startAddr) {
// startAddr) {
//size_t sz = taosArrayGetSize(b->trans);
// size_t sz = taosArrayGetSize(b->trans);
//
assert(sz < 256);
//
assert(sz < 256);
//if (FST_BUILDER_NODE_IS_FINAL(b)
// if (FST_BUILDER_NODE_IS_FINAL(b)
// && FST_BUILDER_NODE_TRANS_ISEMPTY(b)
// && FST_BUILDER_NODE_TRANS_ISEMPTY(b)
// && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {
// && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {
// return true;
// return true;
//} else if (sz != 1 || b->isFinal) {
//} else if (sz != 1 || b->isFinal) {
// // AnyTrans->Compile(w, addr, node);
// // AnyTrans->Compile(w, addr, node);
//} else {
//} else {
// FstTransition *tran = taosArrayGet(b->trans, 0);
// FstTransition *tran = taosArrayGet(b->trans, 0);
// if (tran->addr == lastAddr && tran->out == 0) {
// if (tran->addr == lastAddr && tran->out == 0) {
// //OneTransNext::compile(w, lastAddr, tran->inp);
// //OneTransNext::compile(w, lastAddr, tran->inp);
// return true;
// return true;
// } else {
// } else {
// //OneTrans::Compile(w, lastAddr, *tran);
// //OneTrans::Compile(w, lastAddr, *tran);
// return true;
// return true;
// }
// }
//}
//}
//return true;
// return true;
//}
//}
source/libs/index/src/index_fst_registry.c
浏览文件 @
5d4d7b47
...
@@ -15,9 +15,8 @@
...
@@ -15,9 +15,8 @@
#include "index_fst_registry.h"
#include "index_fst_registry.h"
uint64_t
fstRegistryHash
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
)
{
uint64_t
fstRegistryHash
(
FstRegistry
*
registry
,
FstBuilderNode
*
bNode
)
{
//TODO(yihaoDeng): refactor later
//
TODO(yihaoDeng): refactor later
const
uint64_t
FNV_PRIME
=
1099511628211
;
const
uint64_t
FNV_PRIME
=
1099511628211
;
uint64_t
h
=
14695981039346656037u
;
uint64_t
h
=
14695981039346656037u
;
...
@@ -29,14 +28,15 @@ uint64_t fstRegistryHash(FstRegistry *registry, FstBuilderNode *bNode) {
...
@@ -29,14 +28,15 @@ uint64_t fstRegistryHash(FstRegistry *registry, FstBuilderNode *bNode) {
FstTransition
*
trn
=
taosArrayGet
(
bNode
->
trans
,
i
);
FstTransition
*
trn
=
taosArrayGet
(
bNode
->
trans
,
i
);
h
=
(
h
^
(
uint64_t
)(
trn
->
inp
))
*
FNV_PRIME
;
h
=
(
h
^
(
uint64_t
)(
trn
->
inp
))
*
FNV_PRIME
;
h
=
(
h
^
(
uint64_t
)(
trn
->
out
))
*
FNV_PRIME
;
h
=
(
h
^
(
uint64_t
)(
trn
->
out
))
*
FNV_PRIME
;
h
=
(
h
^
(
uint64_t
)(
trn
->
addr
))
*
FNV_PRIME
;
h
=
(
h
^
(
uint64_t
)(
trn
->
addr
))
*
FNV_PRIME
;
}
}
return
h
%
(
registry
->
tableSize
);
return
h
%
(
registry
->
tableSize
);
}
}
static
void
fstRegistryCellSwap
(
SArray
*
arr
,
uint32_t
a
,
uint32_t
b
)
{
static
void
fstRegistryCellSwap
(
SArray
*
arr
,
uint32_t
a
,
uint32_t
b
)
{
size_t
sz
=
taosArrayGetSize
(
arr
);
size_t
sz
=
taosArrayGetSize
(
arr
);
if
(
a
>=
sz
||
b
>=
sz
)
{
return
;
}
if
(
a
>=
sz
||
b
>=
sz
)
{
return
;
}
FstRegistryCell
*
cell1
=
(
FstRegistryCell
*
)
taosArrayGet
(
arr
,
a
);
FstRegistryCell
*
cell1
=
(
FstRegistryCell
*
)
taosArrayGet
(
arr
,
a
);
FstRegistryCell
*
cell2
=
(
FstRegistryCell
*
)
taosArrayGet
(
arr
,
b
);
FstRegistryCell
*
cell2
=
(
FstRegistryCell
*
)
taosArrayGet
(
arr
,
b
);
...
@@ -53,24 +53,28 @@ static void fstRegistryCellSwap(SArray *arr, uint32_t a, uint32_t b) {
...
@@ -53,24 +53,28 @@ static void fstRegistryCellSwap(SArray *arr, uint32_t a, uint32_t b) {
static
void
fstRegistryCellPromote
(
SArray
*
arr
,
uint32_t
start
,
uint32_t
end
)
{
static
void
fstRegistryCellPromote
(
SArray
*
arr
,
uint32_t
start
,
uint32_t
end
)
{
size_t
sz
=
taosArrayGetSize
(
arr
);
size_t
sz
=
taosArrayGetSize
(
arr
);
if
(
start
>=
sz
&&
end
>=
sz
)
{
return
;
}
if
(
start
>=
sz
&&
end
>=
sz
)
{
return
;
}
assert
(
start
>=
end
);
assert
(
start
>=
end
);
int32_t
s
=
(
int32_t
)
start
;
int32_t
s
=
(
int32_t
)
start
;
int32_t
e
=
(
int32_t
)
end
;
int32_t
e
=
(
int32_t
)
end
;
while
(
s
>
e
)
{
while
(
s
>
e
)
{
fstRegistryCellSwap
(
arr
,
s
-
1
,
s
);
fstRegistryCellSwap
(
arr
,
s
-
1
,
s
);
s
-=
1
;
s
-=
1
;
}
}
}
}
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
)
{
FstRegistry
*
fstRegistryCreate
(
uint64_t
tableSize
,
uint64_t
mruSize
)
{
FstRegistry
*
registry
=
malloc
(
sizeof
(
FstRegistry
));
FstRegistry
*
registry
=
malloc
(
sizeof
(
FstRegistry
));
if
(
registry
==
NULL
)
{
return
NULL
;}
if
(
registry
==
NULL
)
{
return
NULL
;
}
uint64_t
nCells
=
tableSize
*
mruSize
;
uint64_t
nCells
=
tableSize
*
mruSize
;
SArray
*
tb
=
(
SArray
*
)
taosArrayInit
(
nCells
,
sizeof
(
FstRegistryCell
));
SArray
*
tb
=
(
SArray
*
)
taosArrayInit
(
nCells
,
sizeof
(
FstRegistryCell
));
if
(
NULL
==
tb
)
{
if
(
NULL
==
tb
)
{
free
(
registry
);
free
(
registry
);
return
NULL
;
return
NULL
;
...
@@ -88,7 +92,9 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
...
@@ -88,7 +92,9 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
}
}
void
fstRegistryDestroy
(
FstRegistry
*
registry
)
{
void
fstRegistryDestroy
(
FstRegistry
*
registry
)
{
if
(
registry
==
NULL
)
{
return
;
}
if
(
registry
==
NULL
)
{
return
;
}
SArray
*
tb
=
registry
->
table
;
SArray
*
tb
=
registry
->
table
;
size_t
sz
=
taosArrayGetSize
(
tb
);
size_t
sz
=
taosArrayGetSize
(
tb
);
...
@@ -111,10 +117,10 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
...
@@ -111,10 +117,10 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
FstRegistryEntry
*
entry
=
malloc
(
sizeof
(
FstRegistryEntry
));
FstRegistryEntry
*
entry
=
malloc
(
sizeof
(
FstRegistryEntry
));
if
(
end
-
start
==
1
)
{
if
(
end
-
start
==
1
)
{
FstRegistryCell
*
cell
=
taosArrayGet
(
registry
->
table
,
start
);
FstRegistryCell
*
cell
=
taosArrayGet
(
registry
->
table
,
start
);
//
cell->isNode &&
//
cell->isNode &&
if
(
cell
->
addr
!=
NONE_ADDRESS
&&
fstBuilderNodeEqual
(
cell
->
node
,
bNode
))
{
if
(
cell
->
addr
!=
NONE_ADDRESS
&&
fstBuilderNodeEqual
(
cell
->
node
,
bNode
))
{
entry
->
state
=
FOUND
;
entry
->
state
=
FOUND
;
entry
->
addr
=
cell
->
addr
;
entry
->
addr
=
cell
->
addr
;
return
entry
;
return
entry
;
}
else
{
}
else
{
fstBuilderNodeCloneFrom
(
cell
->
node
,
bNode
);
fstBuilderNodeCloneFrom
(
cell
->
node
,
bNode
);
...
@@ -136,7 +142,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
...
@@ -136,7 +142,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
fstRegistryCellSwap
(
registry
->
table
,
start
,
start
+
1
);
fstRegistryCellSwap
(
registry
->
table
,
start
,
start
+
1
);
return
entry
;
return
entry
;
}
}
//
clone from bNode, refactor later
//
clone from bNode, refactor later
fstBuilderNodeCloneFrom
(
cell2
->
node
,
bNode
);
fstBuilderNodeCloneFrom
(
cell2
->
node
,
bNode
);
fstRegistryCellSwap
(
registry
->
table
,
start
,
start
+
1
);
fstRegistryCellSwap
(
registry
->
table
,
start
,
start
+
1
);
...
@@ -157,7 +163,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
...
@@ -157,7 +163,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
if
(
i
>=
end
)
{
if
(
i
>=
end
)
{
uint64_t
last
=
end
-
1
;
uint64_t
last
=
end
-
1
;
FstRegistryCell
*
cell
=
(
FstRegistryCell
*
)
taosArrayGet
(
registry
->
table
,
last
);
FstRegistryCell
*
cell
=
(
FstRegistryCell
*
)
taosArrayGet
(
registry
->
table
,
last
);
//
clone from bNode, refactor later
//
clone from bNode, refactor later
fstBuilderNodeCloneFrom
(
cell
->
node
,
bNode
);
fstBuilderNodeCloneFrom
(
cell
->
node
,
bNode
);
fstRegistryCellPromote
(
registry
->
table
,
last
,
start
);
fstRegistryCellPromote
(
registry
->
table
,
last
,
start
);
...
@@ -168,8 +174,4 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
...
@@ -168,8 +174,4 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
}
}
return
entry
;
return
entry
;
}
}
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
)
{
void
fstRegistryEntryDestroy
(
FstRegistryEntry
*
entry
)
{
free
(
entry
);
}
free
(
entry
);
}
source/libs/index/src/index_fst_util.c
浏览文件 @
5d4d7b47
...
@@ -15,9 +15,7 @@
...
@@ -15,9 +15,7 @@
#include "index_fst_util.h"
#include "index_fst_util.h"
#include "index_fst_common.h"
#include "index_fst_common.h"
// A sentinel value used to indicate an empty final state
//A sentinel value used to indicate an empty final state
const
CompiledAddr
EMPTY_ADDRESS
=
0
;
const
CompiledAddr
EMPTY_ADDRESS
=
0
;
/// A sentinel value used to indicate an invalid state.
/// A sentinel value used to indicate an invalid state.
const
CompiledAddr
NONE_ADDRESS
=
1
;
const
CompiledAddr
NONE_ADDRESS
=
1
;
...
@@ -31,21 +29,18 @@ const uint64_t VERSION = 3;
...
@@ -31,21 +29,18 @@ const uint64_t VERSION = 3;
const
uint64_t
TRANS_INDEX_THRESHOLD
=
32
;
const
uint64_t
TRANS_INDEX_THRESHOLD
=
32
;
// uint8_t commonInput(uint8_t idx) {
//uint8_t commonInput(uint8_t idx) {
// if (idx == 0) { return -1; }
// if (idx == 0) { return -1; }
// else {
// else {
// return COMMON_INPUTS_INV[idx - 1];
// return COMMON_INPUTS_INV[idx - 1];
// }
// }
//}
//}
//
//
//uint8_t commonIdx(uint8_t v, uint8_t max) {
//
uint8_t commonIdx(uint8_t v, uint8_t max) {
// uint8_t v = ((uint16_t)tCOMMON_INPUTS[v] + 1)%256;
// uint8_t v = ((uint16_t)tCOMMON_INPUTS[v] + 1)%256;
// return v > max ? 0: v;
// return v > max ? 0: v;
//}
//}
uint8_t
packSize
(
uint64_t
n
)
{
uint8_t
packSize
(
uint64_t
n
)
{
if
(
n
<
(
1u
<<
8
))
{
if
(
n
<
(
1u
<<
8
))
{
return
1
;
return
1
;
...
@@ -107,15 +102,14 @@ FstSlice fstSliceCreate(uint8_t *data, uint64_t len) {
...
@@ -107,15 +102,14 @@ FstSlice fstSliceCreate(uint8_t *data, uint64_t len) {
FstSlice
fstSliceCopy
(
FstSlice
*
s
,
int32_t
start
,
int32_t
end
)
{
FstSlice
fstSliceCopy
(
FstSlice
*
s
,
int32_t
start
,
int32_t
end
)
{
FstString
*
str
=
s
->
str
;
FstString
*
str
=
s
->
str
;
str
->
ref
++
;
str
->
ref
++
;
//
uint8_t *buf = fstSliceData(s, &alen);
//
uint8_t *buf = fstSliceData(s, &alen);
//start = buf + start - (buf - s->start);
//
start = buf + start - (buf - s->start);
//
end = buf + end - (buf - s->start);
//
end = buf + end - (buf - s->start);
FstSlice
t
=
{.
str
=
str
,
.
start
=
start
+
s
->
start
,
.
end
=
end
+
s
->
start
};
FstSlice
t
=
{.
str
=
str
,
.
start
=
start
+
s
->
start
,
.
end
=
end
+
s
->
start
};
return
t
;
return
t
;
}
}
FstSlice
fstSliceDeepCopy
(
FstSlice
*
s
,
int32_t
start
,
int32_t
end
)
{
FstSlice
fstSliceDeepCopy
(
FstSlice
*
s
,
int32_t
start
,
int32_t
end
)
{
int32_t
tlen
=
end
-
start
+
1
;
int32_t
tlen
=
end
-
start
+
1
;
int32_t
slen
;
int32_t
slen
;
uint8_t
*
data
=
fstSliceData
(
s
,
&
slen
);
uint8_t
*
data
=
fstSliceData
(
s
,
&
slen
);
...
@@ -135,9 +129,7 @@ FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end) {
...
@@ -135,9 +129,7 @@ FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end) {
ans
.
end
=
tlen
-
1
;
ans
.
end
=
tlen
-
1
;
return
ans
;
return
ans
;
}
}
bool
fstSliceIsEmpty
(
FstSlice
*
s
)
{
bool
fstSliceIsEmpty
(
FstSlice
*
s
)
{
return
s
->
str
==
NULL
||
s
->
str
->
len
==
0
||
s
->
start
<
0
||
s
->
end
<
0
;
}
return
s
->
str
==
NULL
||
s
->
str
->
len
==
0
||
s
->
start
<
0
||
s
->
end
<
0
;
}
uint8_t
*
fstSliceData
(
FstSlice
*
s
,
int32_t
*
size
)
{
uint8_t
*
fstSliceData
(
FstSlice
*
s
,
int32_t
*
size
)
{
FstString
*
str
=
s
->
str
;
FstString
*
str
=
s
->
str
;
...
@@ -165,27 +157,32 @@ int fstSliceCompare(FstSlice *a, FstSlice *b) {
...
@@ -165,27 +157,32 @@ int fstSliceCompare(FstSlice *a, FstSlice *b) {
for
(
i
=
0
,
j
=
0
;
i
<
alen
&&
j
<
blen
;
i
++
,
j
++
)
{
for
(
i
=
0
,
j
=
0
;
i
<
alen
&&
j
<
blen
;
i
++
,
j
++
)
{
uint8_t
x
=
aBuf
[
i
];
uint8_t
x
=
aBuf
[
i
];
uint8_t
y
=
bBuf
[
j
];
uint8_t
y
=
bBuf
[
j
];
if
(
x
==
y
)
{
continue
;}
if
(
x
==
y
)
{
else
if
(
x
<
y
)
{
return
-
1
;
}
continue
;
else
{
return
1
;
};
}
else
if
(
x
<
y
)
{
return
-
1
;
}
else
{
return
1
;
};
}
if
(
i
<
alen
)
{
return
1
;
}
else
if
(
j
<
blen
)
{
return
-
1
;
}
else
{
return
0
;
}
}
if
(
i
<
alen
)
{
return
1
;
}
else
if
(
j
<
blen
)
{
return
-
1
;
}
else
{
return
0
;
}
}
}
//FstStack* fstStackCreate(size_t elemSize, StackFreeElem freeFn) {
//
FstStack* fstStackCreate(size_t elemSize, StackFreeElem freeFn) {
// FstStack *s = calloc(1, sizeof(FstStack));
// FstStack *s = calloc(1, sizeof(FstStack));
// if (s == NULL) { return NULL; }
// if (s == NULL) { return NULL; }
// s->
// s->
// s->freeFn
// s->freeFn
//
//
//}
//}
//void *fstStackPush(FstStack *s, void *elem);
// void *fstStackPush(FstStack *s, void *elem);
//void *fstStackTop(FstStack *s);
// void *fstStackTop(FstStack *s);
//size_t fstStackLen(FstStack *s);
// size_t fstStackLen(FstStack *s);
//void *fstStackGetAt(FstStack *s, size_t i);
// void *fstStackGetAt(FstStack *s, size_t i);
//void fstStackDestory(FstStack *);
// void fstStackDestory(FstStack *);
source/libs/index/src/index_tfile.c
浏览文件 @
5d4d7b47
...
@@ -16,18 +16,18 @@
...
@@ -16,18 +16,18 @@
//#include <sys/types.h>
//#include <sys/types.h>
//#include <dirent.h>
//#include <dirent.h>
#include "index_tfile.h"
#include "index_tfile.h"
#include "index.h"
#include "index_fst.h"
#include "index_fst.h"
#include "index_fst_counting_writer.h"
#include "index_util.h"
#include "index_util.h"
#include "taosdef.h"
#include "taosdef.h"
#include "index.h"
#include "index_fst_counting_writer.h"
static
FORCE_INLINE
int
tfile
LoadHeader
(
WriterCtx
*
ctx
,
TFileReadHeader
*
h
eader
)
{
static
FORCE_INLINE
int
tfile
ReadLoadHeader
(
TFileReader
*
r
eader
)
{
//TODO simple tfile header later
//
TODO simple tfile header later
char
buf
[
TFILE_HADER_PRE_SIZE
];
char
buf
[
TFILE_HADER_PRE_SIZE
];
char
*
p
=
buf
;
char
*
p
=
buf
;
int64_t
nread
=
ctx
->
read
(
ctx
,
buf
,
TFILE_HADER_PRE_SIZE
);
TFileReadHeader
*
header
=
&
reader
->
header
;
int64_t
nread
=
reader
->
ctx
->
read
(
reader
->
ctx
,
buf
,
TFILE_HADER_PRE_SIZE
);
assert
(
nread
==
TFILE_HADER_PRE_SIZE
);
assert
(
nread
==
TFILE_HADER_PRE_SIZE
);
memcpy
(
&
header
->
suid
,
p
,
sizeof
(
header
->
suid
));
memcpy
(
&
header
->
suid
,
p
,
sizeof
(
header
->
suid
));
...
@@ -39,20 +39,22 @@ static FORCE_INLINE int tfileLoadHeader(WriterCtx *ctx, TFileReadHeader *header)
...
@@ -39,20 +39,22 @@ static FORCE_INLINE int tfileLoadHeader(WriterCtx *ctx, TFileReadHeader *header)
int32_t
colLen
=
0
;
int32_t
colLen
=
0
;
memcpy
(
&
colLen
,
p
,
sizeof
(
colLen
));
memcpy
(
&
colLen
,
p
,
sizeof
(
colLen
));
assert
(
colLen
<
sizeof
(
header
->
colName
));
assert
(
colLen
<
sizeof
(
header
->
colName
));
nread
=
ctx
->
read
(
ctx
,
header
->
colName
,
colLen
);
nread
=
reader
->
ctx
->
read
(
reader
->
ctx
,
header
->
colName
,
colLen
);
assert
(
nread
==
colLen
);
assert
(
nread
==
colLen
);
nread
=
ctx
->
read
(
ctx
,
&
header
->
colType
,
sizeof
(
header
->
colType
));
nread
=
reader
->
ctx
->
read
(
reader
->
ctx
,
&
header
->
colType
,
sizeof
(
header
->
colType
));
return
0
;
return
0
;
};
};
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
)
{
static
int
tfileGetFileList
(
const
char
*
path
,
SArray
*
result
)
{
DIR
*
dir
=
opendir
(
path
);
DIR
*
dir
=
opendir
(
path
);
if
(
NULL
==
dir
)
{
return
-
1
;
}
if
(
NULL
==
dir
)
{
return
-
1
;
}
struct
dirent
*
entry
;
struct
dirent
*
entry
;
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
size_t
len
=
strlen
(
entry
->
d_name
);
size_t
len
=
strlen
(
entry
->
d_name
);
char
*
buf
=
calloc
(
1
,
len
+
1
);
char
*
buf
=
calloc
(
1
,
len
+
1
);
memcpy
(
buf
,
entry
->
d_name
,
len
);
memcpy
(
buf
,
entry
->
d_name
,
len
);
taosArrayPush
(
result
,
&
buf
);
taosArrayPush
(
result
,
&
buf
);
}
}
...
@@ -90,7 +92,9 @@ static void tfileSerialCacheKey(TFileCacheKey *key, char *buf) {
...
@@ -90,7 +92,9 @@ static void tfileSerialCacheKey(TFileCacheKey *key, char *buf) {
TFileCache
*
tfileCacheCreate
(
const
char
*
path
)
{
TFileCache
*
tfileCacheCreate
(
const
char
*
path
)
{
TFileCache
*
tcache
=
calloc
(
1
,
sizeof
(
TFileCache
));
TFileCache
*
tcache
=
calloc
(
1
,
sizeof
(
TFileCache
));
if
(
tcache
==
NULL
)
{
return
NULL
;
}
if
(
tcache
==
NULL
)
{
return
NULL
;
}
tcache
->
tableCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
tcache
->
tableCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
tcache
->
capacity
=
64
;
tcache
->
capacity
=
64
;
...
@@ -99,7 +103,7 @@ TFileCache *tfileCacheCreate(const char *path) {
...
@@ -99,7 +103,7 @@ TFileCache *tfileCacheCreate(const char *path) {
tfileGetFileList
(
path
,
files
);
tfileGetFileList
(
path
,
files
);
taosArraySort
(
files
,
tfileCompare
);
taosArraySort
(
files
,
tfileCompare
);
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
files
);
i
++
)
{
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
files
);
i
++
)
{
char
*
file
=
taosArrayGetP
(
files
,
i
);
char
*
file
=
taosArrayGetP
(
files
,
i
);
uint64_t
suid
;
uint64_t
suid
;
int
colId
,
version
;
int
colId
,
version
;
if
(
0
!=
tfileParseFileName
(
file
,
&
suid
,
&
colId
,
&
version
))
{
if
(
0
!=
tfileParseFileName
(
file
,
&
suid
,
&
colId
,
&
version
))
{
...
@@ -107,29 +111,41 @@ TFileCache *tfileCacheCreate(const char *path) {
...
@@ -107,29 +111,41 @@ TFileCache *tfileCacheCreate(const char *path) {
continue
;
continue
;
}
}
TFileReader
*
reader
=
calloc
(
1
,
sizeof
(
TFileReader
));
WriterCtx
*
wc
=
writerCtxCreate
(
TFile
,
file
,
true
,
1024
*
64
);
reader
->
ctx
=
writerCtxCreate
(
TFile
,
file
,
true
,
1024
*
64
);
if
(
wc
==
NULL
)
{
if
(
reader
->
ctx
==
NULL
)
{
TFileReaderDestroy
(
reader
);
indexError
(
"failed to open index: %s"
,
file
);
indexError
(
"failed to open index: %s"
,
file
);
goto
End
;
goto
End
;
}
}
TFileRead
Header
header
=
{
0
};
TFileRead
er
*
reader
=
tfileReaderCreate
(
wc
);
if
(
0
!=
tfile
LoadHeader
(
reader
->
ctx
,
&
h
eader
))
{
if
(
0
!=
tfile
ReadLoadHeader
(
r
eader
))
{
TFileReaderDestroy
(
reader
);
TFileReaderDestroy
(
reader
);
indexError
(
"failed to load index header, index Id: %s"
,
file
);
indexError
(
"failed to load index header, index Id: %s"
,
file
);
goto
End
;
}
}
}
}
taosArrayDestroyEx
(
files
,
tfileDestroyFileName
);
taosArrayDestroyEx
(
files
,
tfileDestroyFileName
);
return
tcache
;
return
tcache
;
End:
End:
tfileCacheDestroy
(
tcache
);
taosArrayDestroyEx
(
files
,
tfileDestroyFileName
);
taosArrayDestroyEx
(
files
,
tfileDestroyFileName
);
return
NULL
;
return
NULL
;
}
}
void
tfileCacheDestroy
(
TFileCache
*
tcache
)
{
void
tfileCacheDestroy
(
TFileCache
*
tcache
)
{
if
(
tcache
==
NULL
)
{
return
;
}
// free table cache
TFileReader
**
reader
=
taosHashIterate
(
tcache
->
tableCache
,
NULL
);
while
(
reader
)
{
TFileReader
*
p
=
*
reader
;
indexInfo
(
"drop table cache suid: %"
PRIu64
", colName: %s, colType: %d"
,
p
->
header
.
suid
,
p
->
header
.
colName
,
p
->
header
.
colType
);
TFileReaderDestroy
(
p
);
reader
=
taosHashIterate
(
tcache
->
tableCache
,
reader
);
}
taosHashCleanup
(
tcache
->
tableCache
);
free
(
tcache
);
free
(
tcache
);
}
}
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
)
{
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
)
{
...
@@ -145,56 +161,47 @@ void tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader)
...
@@ -145,56 +161,47 @@ void tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader)
return
;
return
;
}
}
TFileReader
*
tfileReaderCreate
(
WriterCtx
*
ctx
)
{
TFileReader
*
tfileReaderCreate
()
{
TFileReader
*
reader
=
calloc
(
1
,
sizeof
(
TFileReader
));
if
(
reader
==
NULL
)
{
return
NULL
;
}
reader
->
ctx
=
ctx
;
// T_REF_INC(reader);
return
reader
;
}
}
void
TFileReaderDestroy
(
TFileReader
*
reader
)
{
void
TFileReaderDestroy
(
TFileReader
*
reader
)
{
if
(
reader
==
NULL
)
{
return
;
}
if
(
reader
==
NULL
)
{
return
;
}
// T_REF_INC(reader);
writerCtxDestroy
(
reader
->
ctx
);
writerCtxDestroy
(
reader
->
ctx
);
free
(
reader
);
free
(
reader
);
}
}
TFileWriter
*
tfileWriterCreate
(
const
char
*
suid
,
const
char
*
colName
);
TFileWriter
*
tfileWriterCreate
(
const
char
*
suid
,
const
char
*
colName
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
IndexTFile
*
indexTFileCreate
(
const
char
*
path
)
{
IndexTFile
*
indexTFileCreate
(
const
char
*
path
)
{
IndexTFile
*
tfile
=
calloc
(
1
,
sizeof
(
IndexTFile
));
IndexTFile
*
tfile
=
calloc
(
1
,
sizeof
(
IndexTFile
));
tfile
->
cache
=
tfileCacheCreate
(
path
);
tfile
->
cache
=
tfileCacheCreate
(
path
);
return
tfile
;
return
tfile
;
}
}
void
IndexTFileDestroy
(
IndexTFile
*
tfile
)
{
void
IndexTFileDestroy
(
IndexTFile
*
tfile
)
{
free
(
tfile
);
}
free
(
tfile
);
}
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
IndexTFile
*
pTfile
=
(
IndexTFile
*
)
tfile
;
IndexTFile
*
pTfile
=
(
IndexTFile
*
)
tfile
;
SIndexTerm
*
term
=
query
->
term
;
SIndexTerm
*
term
=
query
->
term
;
TFileCacheKey
key
=
{.
suid
=
term
->
suid
,
TFileCacheKey
key
=
{
.
colType
=
term
->
colType
,
.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
version
=
0
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
};
.
version
=
0
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
};
TFileReader
*
reader
=
tfileCacheGet
(
pTfile
->
cache
,
&
key
);
TFileReader
*
reader
=
tfileCacheGet
(
pTfile
->
cache
,
&
key
);
return
0
;
return
0
;
}
}
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
TFileWriterOpt
wOpt
=
{.
suid
=
term
->
suid
,
TFileWriterOpt
wOpt
=
{
.
colType
=
term
->
colType
,
.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
,
.
version
=
1
};
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
,
.
version
=
1
};
return
0
;
return
0
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录