Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8565cb4f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
8565cb4f
编写于
12月 20, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/dnode3
上级
aef124af
0b579e58
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
245 addition
and
40 deletion
+245
-40
include/libs/index/index.h
include/libs/index/index.h
+1
-2
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+19
-3
source/libs/index/inc/index_cache.h
source/libs/index/inc/index_cache.h
+6
-6
source/libs/index/inc/index_tfile.h
source/libs/index/inc/index_tfile.h
+46
-0
source/libs/index/src/index.c
source/libs/index/src/index.c
+104
-12
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+38
-17
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+31
-0
未找到文件。
include/libs/index/index.h
浏览文件 @
8565cb4f
...
...
@@ -53,7 +53,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery *pQuery, SIndexTerm
*/
int
indexOpen
(
SIndexOpts
*
opt
,
const
char
*
path
,
SIndex
**
index
);
void
indexClose
(
SIndex
*
index
);
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
terms
,
in
t
uid
);
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
terms
,
uint64_
t
uid
);
int
indexDelete
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
);
int
indexSearch
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
,
SArray
*
result
);
int
indexRebuild
(
SIndex
*
index
,
SIndexOpts
*
opt
);
...
...
@@ -71,7 +71,6 @@ void indexMultiTermDestroy(SIndexMultiTerm *terms);
SIndexOpts
*
indexOptsCreate
();
void
indexOptsDestroy
(
SIndexOpts
*
opts
);
/*
* @param:
* @param:
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
8565cb4f
...
...
@@ -31,6 +31,16 @@
extern
"C"
{
#endif
typedef
enum
{
kTypeValue
,
kTypeDeletion
}
STermValueType
;
typedef
struct
SIndexStat
{
int32_t
totalAdded
;
//
int32_t
totalDeled
;
//
int32_t
totalUpdated
;
//
int32_t
totalTerms
;
//
int32_t
distinctCol
;
// distinct column
}
SIndexStat
;
struct
SIndex
{
#ifdef USE_LUCENE
index_t
*
index
;
...
...
@@ -42,15 +52,21 @@ struct SIndex {
int64_t
suid
;
// current super table id, -1 is normal table
int
colId
;
// field id allocated to cache
int32_t
cVersion
;
// current version allocated to cache
SIndexStat
stat
;
pthread_mutex_t
mtx
;
};
struct
SIndexOpts
{
#ifdef USE_LUCENE
void
*
opts
;
#endif
int32_t
numOfItermLimit
;
int8_t
mergeInterval
;
#endif
#ifdef USE_INVERTED_INDEX
int32_t
cacheSize
;
// MB
// add cache module later
#endif
};
struct
SIndexMultiTermQuery
{
...
...
source/libs/index/inc/index_cache.h
浏览文件 @
8565cb4f
...
...
@@ -16,13 +16,14 @@
#define __INDEX_CACHE_H__
#include "index.h"
#include "indexInt.h"
#include "tlockfree.h"
#include "tskiplist.h"
// -----------------
row
structure in skiplist ---------------------
// -----------------
key
structure in skiplist ---------------------
/* A data row, the format is like below:
* content: |<--totalLen-->|<-- fieldid-->|<--field type -->|<-- value len--->|<-- value -->|<-- uid -->|<--version--->|<-- itermType -->|
* len : |<--int32_t -->|<-- int16_t-->|<-- int
16
_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->|
* len : |<--int32_t -->|<-- int16_t-->|<-- int
8
_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->|
*/
#ifdef __cplusplus
...
...
@@ -40,11 +41,10 @@ IndexCache *indexCacheCreate();
void
indexCacheDestroy
(
void
*
cache
);
int
indexCachePut
(
void
*
cache
,
int16_t
fieldId
,
int16_t
fieldType
,
const
char
*
fieldValue
,
int32_t
fvLen
,
uint32_t
version
,
uint64_t
uid
,
int8_t
operType
);
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
int16_t
colId
,
int32_t
version
,
uint64_t
uid
);
int
indexCacheGet
(
void
*
cache
,
uint64_t
*
rst
);
int
indexCacheSearch
(
void
*
cache
,
SIndex
MultiTermQuery
*
query
,
SArray
*
result
);
//
int indexCacheGet(void *cache, uint64_t *rst);
int
indexCacheSearch
(
void
*
cache
,
SIndex
TermQuery
*
query
,
int16_t
colId
,
int32_t
version
,
SArray
*
result
,
STermValueType
*
s
);
#ifdef __cplusplus
}
...
...
source/libs/index/inc/index_tfile.h
0 → 100644
浏览文件 @
8565cb4f
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* 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/>.
*/
#ifndef __INDEX_TFILE_H__
#define __INDEX_TFILE_H__
#include "index.h"
#include "indexInt.h"
#include "tlockfree.h"
#include "tskiplist.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
IndexTFile
{
T_REF_DECLARE
()
}
IndexTFile
;
IndexTFile
*
indexTFileCreate
();
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
);
#ifdef __cplusplus
}
#endif
#endif
source/libs/index/src/index.c
浏览文件 @
8565cb4f
...
...
@@ -16,12 +16,19 @@
#include "index.h"
#include "indexInt.h"
#include "index_cache.h"
#include "index_tfile.h"
#include "tdef.h"
#ifdef USE_LUCENE
#include "lucene++/Lucene_c.h"
#endif
static
int
uidCompare
(
const
void
*
a
,
const
void
*
b
)
{
uint64_t
u1
=
*
(
uint64_t
*
)
a
;
uint64_t
u2
=
*
(
uint64_t
*
)
b
;
if
(
u1
==
u2
)
{
return
0
;
}
else
{
return
u1
<
u2
?
-
1
:
1
;
}
}
typedef
struct
SIdxColInfo
{
int
colId
;
// generated by index internal
int
cVersion
;
...
...
@@ -30,13 +37,13 @@ typedef struct SIdxColInfo {
static
pthread_once_t
isInit
=
PTHREAD_ONCE_INIT
;
static
void
indexInit
();
static
int
indexMergeCacheIntoTindex
(
struct
SIndex
*
sIdx
)
{
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
indexWarn
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
return
0
;
}
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
term
,
SArray
**
result
);
static
int
indexMergeCacheIntoTindex
(
SIndex
*
sIdx
);
static
void
indexInterResultsDestroy
(
SArray
*
results
);
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
finalResult
);
int
indexOpen
(
SIndexOpts
*
opts
,
const
char
*
path
,
SIndex
**
index
)
{
pthread_once
(
&
isInit
,
indexInit
);
SIndex
*
sIdx
=
calloc
(
1
,
sizeof
(
SIndex
));
...
...
@@ -49,8 +56,8 @@ int indexOpen(SIndexOpts *opts, const char *path, SIndex **index) {
sIdx
->
cache
=
(
void
*
)
indexCacheCreate
();
sIdx
->
tindex
=
NULL
;
sIdx
->
colObj
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
sIdx
->
colId
=
1
;
sIdx
->
colObj
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
sIdx
->
colId
=
1
;
sIdx
->
cVersion
=
1
;
pthread_mutex_init
(
&
sIdx
->
mtx
,
NULL
);
...
...
@@ -73,7 +80,7 @@ void indexClose(SIndex *sIdx) {
return
;
}
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
fVals
,
in
t
uid
)
{
int
indexPut
(
SIndex
*
index
,
SIndexMultiTerm
*
fVals
,
uint64_
t
uid
)
{
#ifdef USE_LUCENE
index_document_t
*
doc
=
index_document_create
();
...
...
@@ -115,7 +122,7 @@ int indexPut(SIndex *index, SIndexMultiTerm * fVals, int uid) {
assert
(
fi
!=
NULL
);
int32_t
colId
=
fi
->
colId
;
int32_t
version
=
index
->
cVersion
;
int
ret
=
indexCachePut
(
index
->
cache
,
colId
,
p
->
colType
,
p
->
colVal
,
p
->
nColVal
,
version
,
uid
,
p
->
operType
);
int
ret
=
indexCachePut
(
index
->
cache
,
p
,
colId
,
version
,
uid
);
if
(
ret
!=
0
)
{
return
ret
;
}
...
...
@@ -162,12 +169,25 @@ int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result
#endif
#ifdef USE_INVERTED_INDEX
EIndexOperatorType
opera
=
multiQuerys
->
opera
;
// relation of querys
SArray
*
interResults
=
taosArrayInit
(
4
,
POINTER_BYTES
);
int
nQuery
=
taosArrayGetSize
(
multiQuerys
->
query
);
for
(
size_t
i
=
0
;
i
<
nQuery
;
i
++
)
{
SIndexTermQuery
*
qTerm
=
taosArrayGet
(
multiQuerys
->
query
,
i
);
SArray
*
tResult
=
NULL
;
indexTermSearch
(
index
,
qTerm
,
&
tResult
);
taosArrayPush
(
interResults
,
(
void
*
)
&
tResult
);
}
indexMergeFinalResults
(
interResults
,
opera
,
result
);
indexInterResultsDestroy
(
interResults
);
#endif
return
1
;
}
int
indexDelete
(
SIndex
*
index
,
SIndexMultiTermQuery
*
query
)
{
#ifdef USE_INVERTED_INDEX
#endif
...
...
@@ -259,3 +279,75 @@ void indexMultiTermDestroy(SIndexMultiTerm *terms) {
void
indexInit
()
{
//do nothing
}
static
int
indexTermSearch
(
SIndex
*
sIdx
,
SIndexTermQuery
*
query
,
SArray
**
result
)
{
int32_t
version
=
-
1
;
int16_t
colId
=
-
1
;
SIdxColInfo
*
colInfo
=
NULL
;
SIndexTerm
*
term
=
query
->
term
;
const
char
*
colName
=
term
->
colName
;
int32_t
nColName
=
term
->
nColName
;
pthread_mutex_lock
(
&
sIdx
->
mtx
);
colInfo
=
taosHashGet
(
sIdx
->
colObj
,
colName
,
nColName
);
if
(
colInfo
==
NULL
)
{
pthread_mutex_unlock
(
&
sIdx
->
mtx
);
return
-
1
;
}
colId
=
colInfo
->
colId
;
version
=
colInfo
->
cVersion
;
pthread_mutex_unlock
(
&
sIdx
->
mtx
);
*
result
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
//TODO: iterator mem and tidex
STermValueType
s
;
if
(
0
==
indexCacheSearch
(
sIdx
->
cache
,
query
,
colId
,
version
,
*
result
,
&
s
))
{
if
(
s
==
kTypeDeletion
)
{
indexInfo
(
"col: %s already drop by other opera"
,
term
->
colName
);
// coloum already drop by other oper, no need to query tindex
return
0
;
}
else
{
if
(
0
!=
indexTFileSearch
(
sIdx
->
tindex
,
query
,
*
result
))
{
indexError
(
"corrupt at index(TFile) col:%s val: %s"
,
term
->
colName
,
term
->
colVal
);
return
-
1
;
}
}
}
else
{
indexError
(
"corrupt at index(cache) col:%s val: %s"
,
term
->
colName
,
term
->
colVal
);
return
-
1
;
}
return
0
;
}
static
void
indexInterResultsDestroy
(
SArray
*
results
)
{
if
(
results
==
NULL
)
{
return
;
}
size_t
sz
=
taosArrayGetSize
(
results
);
for
(
size_t
i
=
0
;
i
<
sz
;
i
++
)
{
SArray
*
p
=
taosArrayGetP
(
results
,
i
);
taosArrayDestroy
(
p
);
}
taosArrayDestroy
(
results
);
}
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
fResults
)
{
//refactor, merge interResults into fResults by oType
SArray
*
first
=
taosArrayGetP
(
interResults
,
0
);
taosArraySort
(
first
,
uidCompare
);
if
(
oType
==
MUST
)
{
}
else
if
(
oType
==
SHOULD
)
{
// tag1 condistion || tag2 condition
}
else
if
(
oType
==
NOT
)
{
// not use currently
}
return
0
;
}
static
int
indexMergeCacheIntoTindex
(
SIndex
*
sIdx
)
{
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
indexWarn
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
return
0
;
}
source/libs/index/src/index_cache.c
浏览文件 @
8565cb4f
...
...
@@ -18,6 +18,9 @@
#define MAX_INDEX_KEY_LEN 256// test only, change later
// 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))
static
char
*
getIndexKey
(
const
void
*
pData
)
{
return
NULL
;
}
...
...
@@ -43,7 +46,7 @@ static int32_t compareKey(const void *l, const void *r) {
rp
+=
sizeof
(
rf
);
// compare field type
int
16
_t
lft
,
rft
;
int
8
_t
lft
,
rft
;
memcpy
(
&
lft
,
lp
,
sizeof
(
lft
));
memcpy
(
&
rft
,
rp
,
sizeof
(
rft
));
lp
+=
sizeof
(
lft
);
...
...
@@ -103,14 +106,13 @@ void indexCacheDestroy(void *cache) {
free
(
pCache
);
}
int
indexCachePut
(
void
*
cache
,
int16_t
fieldId
,
int16_t
fieldType
,
const
char
*
fieldValue
,
int32_t
fvLen
,
uint32_t
version
,
uint64_t
uid
,
int8_t
operType
)
{
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
int16_t
colId
,
int32_t
version
,
uint64_t
uid
)
{
if
(
cache
==
NULL
)
{
return
-
1
;}
IndexCache
*
pCache
=
cache
;
// encode data
int32_t
total
=
sizeof
(
int32_t
)
+
sizeof
(
fieldId
)
+
sizeof
(
fieldType
)
+
sizeof
(
fvLen
)
+
fvLen
+
sizeof
(
version
)
+
sizeof
(
uid
)
+
sizeof
(
operType
);
int32_t
total
=
CACHE_KEY_LEN
(
term
);
char
*
buf
=
calloc
(
1
,
total
);
char
*
p
=
buf
;
...
...
@@ -118,16 +120,16 @@ int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *f
memcpy
(
p
,
&
total
,
sizeof
(
total
));
p
+=
sizeof
(
total
);
memcpy
(
p
,
&
fieldId
,
sizeof
(
field
Id
));
p
+=
sizeof
(
field
Id
);
memcpy
(
p
,
&
colId
,
sizeof
(
col
Id
));
p
+=
sizeof
(
col
Id
);
memcpy
(
p
,
&
fieldType
,
sizeof
(
field
Type
));
p
+=
sizeof
(
field
Type
);
memcpy
(
p
,
&
term
->
colType
,
sizeof
(
term
->
col
Type
));
p
+=
sizeof
(
term
->
col
Type
);
memcpy
(
p
,
&
fvLen
,
sizeof
(
fvLen
));
p
+=
sizeof
(
fvLen
);
memcpy
(
p
,
fieldValue
,
fvLen
);
p
+=
fvLen
;
memcpy
(
p
,
&
term
->
nColVal
,
sizeof
(
term
->
nColVal
));
p
+=
sizeof
(
term
->
nColVal
);
memcpy
(
p
,
term
->
colVal
,
term
->
nColVal
);
p
+=
term
->
nColVal
;
memcpy
(
p
,
&
version
,
sizeof
(
version
));
p
+=
sizeof
(
version
);
...
...
@@ -135,10 +137,11 @@ int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *f
memcpy
(
p
,
&
uid
,
sizeof
(
uid
));
p
+=
sizeof
(
uid
);
memcpy
(
p
,
&
operType
,
sizeof
(
operType
));
p
+=
sizeof
(
operType
);
memcpy
(
p
,
&
term
->
operType
,
sizeof
(
term
->
operType
));
p
+=
sizeof
(
term
->
operType
);
tSkipListPut
(
pCache
->
skiplist
,
(
void
*
)
buf
);
return
0
;
// encode end
}
...
...
@@ -146,7 +149,25 @@ int indexCacheDel(void *cache, int32_t fieldId, const char *fieldValue, int32_t
IndexCache
*
pCache
=
cache
;
return
0
;
}
int
indexCacheSearch
(
void
*
cache
,
SIndexMultiTermQuery
*
query
,
SArray
*
result
)
{
return
0
;
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
int16_t
colId
,
int32_t
version
,
SArray
*
result
,
STermValueType
*
s
)
{
if
(
cache
==
NULL
)
{
return
-
1
;
}
IndexCache
*
pCache
=
cache
;
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
int32_t
keyLen
=
CACHE_KEY_LEN
(
term
);
char
*
buf
=
calloc
(
1
,
keyLen
);
if
(
qtype
==
QUERY_TERM
)
{
}
else
if
(
qtype
==
QUERY_PREFIX
)
{
}
else
if
(
qtype
==
QUERY_SUFFIX
)
{
}
else
if
(
qtype
==
QUERY_REGEX
)
{
}
return
0
;
}
source/libs/index/src/index_tfile.c
0 → 100644
浏览文件 @
8565cb4f
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* 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/>.
*/
#include "index_tfile.h"
IndexTFile
*
indexTFileCreate
()
{
IndexTFile
*
tfile
=
calloc
(
1
,
sizeof
(
IndexTFile
));
return
tfile
;
}
void
IndexTFileDestroy
(
IndexTFile
*
tfile
)
{
free
(
tfile
);
}
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
IndexTFile
*
ptfile
=
(
IndexTFile
*
)
tfile
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录