Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0365c67b
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0365c67b
编写于
12月 25, 2021
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Combine the search results of cache and tfile And Update cache code
上级
a724e85b
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
244 addition
and
341 deletion
+244
-341
source/libs/index/inc/index_cache.h
source/libs/index/inc/index_cache.h
+12
-0
source/libs/index/src/index.c
source/libs/index/src/index.c
+2
-2
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+130
-85
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+3
-1
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+97
-253
未找到文件。
source/libs/index/inc/index_cache.h
浏览文件 @
0365c67b
...
@@ -37,6 +37,17 @@ typedef struct IndexCache {
...
@@ -37,6 +37,17 @@ typedef struct IndexCache {
SSkipList
*
skiplist
;
SSkipList
*
skiplist
;
}
IndexCache
;
}
IndexCache
;
typedef
struct
CacheTerm
{
// key
int32_t
colId
;
int32_t
nColVal
;
char
*
colVal
;
int32_t
version
;
// value
uint64_t
uid
;
int8_t
colType
;
SIndexOperOnColumn
operaType
;
}
CacheTerm
;
//
//
IndexCache
*
indexCacheCreate
();
IndexCache
*
indexCacheCreate
();
...
@@ -47,6 +58,7 @@ int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version,
...
@@ -47,6 +58,7 @@ int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version,
// 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
);
void
indexCacheDebug
(
IndexCache
*
cache
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/index/src/index.c
浏览文件 @
0365c67b
...
@@ -41,7 +41,7 @@ static pthread_once_t isInit = PTHREAD_ONCE_INIT;
...
@@ -41,7 +41,7 @@ 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
indexFlushCacheT
oTindex
(
SIndex
*
sIdx
);
static
int
indexFlushCacheT
File
(
SIndex
*
sIdx
);
static
void
indexInterResultsDestroy
(
SArray
*
results
);
static
void
indexInterResultsDestroy
(
SArray
*
results
);
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
finalResult
);
static
int
indexMergeFinalResults
(
SArray
*
interResults
,
EIndexOperatorType
oType
,
SArray
*
finalResult
);
...
@@ -353,7 +353,7 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType
...
@@ -353,7 +353,7 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType
}
}
return
0
;
return
0
;
}
}
static
int
indexFlushCacheT
oTindex
(
SIndex
*
sIdx
)
{
static
int
indexFlushCacheT
File
(
SIndex
*
sIdx
)
{
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
indexWarn
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
indexWarn
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
...
...
source/libs/index/src/index_cache.c
浏览文件 @
0365c67b
...
@@ -20,81 +20,88 @@
...
@@ -20,81 +20,88 @@
#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) \
//
#define CACHE_KEY_LEN(p) \
(sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + sizeof(p->operType))
//
(sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + sizeof(p->operType))
static
void
cacheTermDestroy
(
CacheTerm
*
ct
)
{
if
(
ct
==
NULL
)
{
return
;
}
free
(
ct
->
colVal
);
free
(
ct
);
}
static
char
*
getIndexKey
(
const
void
*
pData
)
{
static
char
*
getIndexKey
(
const
void
*
pData
)
{
return
NULL
;
CacheTerm
*
p
=
(
CacheTerm
*
)
pData
;
return
(
char
*
)
p
;
}
}
static
int32_t
compareKey
(
const
void
*
l
,
const
void
*
r
)
{
static
int32_t
compareKey
(
const
void
*
l
,
const
void
*
r
)
{
char
*
lp
=
(
char
*
)
l
;
CacheTerm
*
lt
=
(
CacheTerm
*
)
l
;
char
*
rp
=
(
char
*
)
r
;
CacheTerm
*
rt
=
(
CacheTerm
*
)
r
;
// skip total len, not compare
// compare colId
int32_t
ll
,
rl
;
// len
if
(
lt
->
colId
!=
rt
->
colId
)
{
return
lt
->
colId
-
rt
->
colId
;
}
memcpy
(
&
ll
,
lp
,
sizeof
(
int32_t
));
memcpy
(
&
rl
,
rp
,
sizeof
(
int32_t
));
// compare colVal
lp
+=
sizeof
(
int32_t
);
int
i
,
j
;
rp
+=
sizeof
(
int32_t
);
for
(
i
=
0
,
j
=
0
;
i
<
lt
->
nColVal
&&
j
<
rt
->
nColVal
;
i
++
,
j
++
)
{
if
(
lt
->
colVal
[
i
]
==
rt
->
colVal
[
j
])
{
// compare field id
int16_t
lf
,
rf
;
// field id
memcpy
(
&
lf
,
lp
,
sizeof
(
lf
));
memcpy
(
&
rf
,
rp
,
sizeof
(
rf
));
if
(
lf
!=
rf
)
{
return
lf
<
rf
?
-
1
:
1
;
}
lp
+=
sizeof
(
lf
);
rp
+=
sizeof
(
rf
);
// compare field type
int8_t
lft
,
rft
;
memcpy
(
&
lft
,
lp
,
sizeof
(
lft
));
memcpy
(
&
rft
,
rp
,
sizeof
(
rft
));
lp
+=
sizeof
(
lft
);
rp
+=
sizeof
(
rft
);
assert
(
rft
==
rft
);
// skip value len
int32_t
lfl
,
rfl
;
memcpy
(
&
lfl
,
lp
,
sizeof
(
lfl
));
memcpy
(
&
rfl
,
rp
,
sizeof
(
rfl
));
lp
+=
sizeof
(
lfl
);
rp
+=
sizeof
(
rfl
);
// compare value
int32_t
i
,
j
;
for
(
i
=
0
,
j
=
0
;
i
<
lfl
&&
j
<
rfl
;
i
++
,
j
++
)
{
if
(
lp
[
i
]
==
rp
[
j
])
{
continue
;
continue
;
}
else
{
}
else
{
return
l
p
[
i
]
<
rp
[
j
]
?
-
1
:
1
;
return
l
t
->
colVal
[
i
]
<
rt
->
colVal
[
j
]
?
-
1
:
1
;
}
}
}
}
if
(
i
<
l
f
l
)
{
if
(
i
<
l
t
->
nColVa
l
)
{
return
1
;
return
1
;
}
else
if
(
j
<
r
f
l
)
{
}
else
if
(
j
<
r
t
->
nColVa
l
)
{
return
-
1
;
return
-
1
;
}
}
lp
+=
lfl
;
// compare version
rp
+=
rfl
;
return
rt
->
version
-
lt
->
version
;
// skip uid
uint64_t
lu
,
ru
;
// char* lp = (char*)l;
memcpy
(
&
lu
,
lp
,
sizeof
(
lu
));
// char* rp = (char*)r;
memcpy
(
&
ru
,
rp
,
sizeof
(
ru
));
lp
+=
sizeof
(
lu
);
//// compare col id
rp
+=
sizeof
(
ru
);
// int16_t lf, rf; // cold id
// memcpy(&lf, lp, sizeof(lf));
// compare version, desc order
// memcpy(&rf, rp, sizeof(rf));
int32_t
lv
,
rv
;
// if (lf != rf) { return lf < rf ? -1 : 1; }
memcpy
(
&
lv
,
lp
,
sizeof
(
lv
));
memcpy
(
&
rv
,
rp
,
sizeof
(
rv
));
// lp += sizeof(lf);
if
(
lv
!=
rv
)
{
return
lv
>
rv
?
-
1
:
1
;
}
// rp += sizeof(rf);
lp
+=
sizeof
(
lv
);
//// skip value len
rp
+=
sizeof
(
rv
);
// int32_t lfl, rfl;
// not care item type
// memcpy(&lfl, lp, sizeof(lfl));
// memcpy(&rfl, rp, sizeof(rfl));
return
0
;
// lp += sizeof(lfl);
// rp += sizeof(rfl);
//// compare value
// int32_t i, j;
// for (i = 0, j = 0; i < lfl && j < rfl; i++, j++) {
// if (lp[i] == rp[j]) {
// continue;
// } else {
// return lp[i] < rp[j] ? -1 : 1;
// }
//}
// if (i < lfl) {
// return 1;
//} else if (j < rfl) {
// return -1;
//}
// lp += lfl;
// rp += rfl;
//// compare version, desc order
// int32_t lv, rv;
// memcpy(&lv, lp, sizeof(lv));
// memcpy(&rv, rp, sizeof(rv));
// if (lv != rv) { return lv < rv ? 1 : -1; }
// return 0;
}
}
IndexCache
*
indexCacheCreate
()
{
IndexCache
*
indexCacheCreate
()
{
IndexCache
*
cache
=
calloc
(
1
,
sizeof
(
IndexCache
));
IndexCache
*
cache
=
calloc
(
1
,
sizeof
(
IndexCache
));
...
@@ -106,6 +113,18 @@ IndexCache* indexCacheCreate() {
...
@@ -106,6 +113,18 @@ IndexCache* indexCacheCreate() {
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_INDEX_KEY_LEN
,
compareKey
,
SL_ALLOW_DUP_KEY
,
getIndexKey
);
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_INDEX_KEY_LEN
,
compareKey
,
SL_ALLOW_DUP_KEY
,
getIndexKey
);
return
cache
;
return
cache
;
}
}
void
indexCacheDebug
(
IndexCache
*
cache
)
{
SSkipListIterator
*
iter
=
tSkipListCreateIter
(
cache
->
skiplist
);
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
CacheTerm
*
ct
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
ct
!=
NULL
)
{
// TODO, add more debug info
indexInfo
(
"{colId:%d, colVal: %s, version: %d}
\t
"
,
ct
->
colId
,
ct
->
colVal
,
ct
->
version
);
}
}
tSkipListDestroyIter
(
iter
);
}
void
indexCacheDestroy
(
void
*
cache
)
{
void
indexCacheDestroy
(
void
*
cache
)
{
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
...
@@ -119,24 +138,20 @@ int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version,
...
@@ -119,24 +138,20 @@ int indexCachePut(void* cache, SIndexTerm* term, int16_t colId, int32_t version,
IndexCache
*
pCache
=
cache
;
IndexCache
*
pCache
=
cache
;
// encode data
// encode data
int32_t
total
=
CACHE_KEY_LEN
(
term
);
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
if
(
cache
==
NULL
)
{
return
-
1
;
}
char
*
buf
=
calloc
(
1
,
total
);
// set up key
char
*
p
=
buf
;
ct
->
colId
=
colId
;
ct
->
colType
=
term
->
colType
;
SERIALIZE_VAR_TO_BUF
(
p
,
total
,
int32_t
);
ct
->
nColVal
=
term
->
nColVal
;
SERIALIZE_VAR_TO_BUF
(
p
,
colId
,
int16_t
);
ct
->
colVal
=
(
char
*
)
calloc
(
1
,
sizeof
(
char
)
*
(
ct
->
nColVal
+
1
));
memcpy
(
ct
->
colVal
,
term
->
colVal
,
ct
->
nColVal
);
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
colType
);
ct
->
version
=
version
;
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
nColVal
);
SERIALIZE_STR_MEM_TO_BUF
(
p
,
term
,
colVal
,
term
->
nColVal
);
ct
->
uid
=
uid
;
ct
->
operaType
=
term
->
operType
;
SERIALIZE_VAR_TO_BUF
(
p
,
version
,
int32_t
);
SERIALIZE_VAR_TO_BUF
(
p
,
uid
,
uint64_t
);
tSkipListPut
(
pCache
->
skiplist
,
(
char
*
)
ct
);
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
operType
);
tSkipListPut
(
pCache
->
skiplist
,
(
void
*
)
buf
);
return
0
;
return
0
;
// encode end
// encode end
}
}
...
@@ -150,8 +165,39 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t
...
@@ -150,8 +165,39 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t
SIndexTerm
*
term
=
query
->
term
;
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
EIndexQueryType
qtype
=
query
->
qType
;
int32_t
keyLen
=
CACHE_KEY_LEN
(
term
);
CacheTerm
*
ct
=
calloc
(
1
,
sizeof
(
CacheTerm
));
char
*
buf
=
calloc
(
1
,
keyLen
);
if
(
ct
==
NULL
)
{
return
-
1
;
}
ct
->
colId
=
colId
;
ct
->
nColVal
=
term
->
nColVal
;
ct
->
colVal
=
calloc
(
1
,
sizeof
(
char
)
*
(
ct
->
nColVal
+
1
));
memcpy
(
ct
->
colVal
,
term
->
colVal
,
ct
->
nColVal
);
ct
->
version
=
version
;
char
*
key
=
getIndexKey
(
ct
);
// TODO handle multi situation later, and refactor
SSkipListIterator
*
iter
=
tSkipListCreateIterFromVal
(
pCache
->
skiplist
,
key
,
TSDB_DATA_TYPE_BINARY
,
TSDB_ORDER_ASC
);
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
node
=
tSkipListIterGet
(
iter
);
if
(
node
!=
NULL
)
{
CacheTerm
*
c
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
c
->
operaType
==
ADD_VALUE
||
qtype
==
QUERY_TERM
)
{
if
(
c
->
nColVal
==
ct
->
nColVal
&&
strncmp
(
c
->
colVal
,
ct
->
colVal
,
c
->
nColVal
)
==
0
)
{
taosArrayPush
(
result
,
&
c
->
uid
);
*
s
=
kTypeValue
;
}
else
{
break
;
}
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
// table is del, not need
*
s
=
kTypeDeletion
;
break
;
}
}
}
tSkipListDestroyIter
(
iter
);
cacheTermDestroy
(
ct
);
// int32_t keyLen = CACHE_KEY_LEN(term);
// char* buf = calloc(1, keyLen);
if
(
qtype
==
QUERY_TERM
)
{
if
(
qtype
==
QUERY_TERM
)
{
//
//
}
else
if
(
qtype
==
QUERY_PREFIX
)
{
}
else
if
(
qtype
==
QUERY_PREFIX
)
{
...
@@ -161,6 +207,5 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t
...
@@ -161,6 +207,5 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, int16_t colId, int32_t
}
else
if
(
qtype
==
QUERY_REGEX
)
{
}
else
if
(
qtype
==
QUERY_REGEX
)
{
//
//
}
}
return
0
;
return
0
;
}
}
source/libs/index/src/index_tfile.c
浏览文件 @
0365c67b
...
@@ -462,7 +462,9 @@ static int tfileCompare(const void* a, const void* b) {
...
@@ -462,7 +462,9 @@ static int tfileCompare(const void* a, const void* b) {
size_t
aLen
=
strlen
(
aName
);
size_t
aLen
=
strlen
(
aName
);
size_t
bLen
=
strlen
(
bName
);
size_t
bLen
=
strlen
(
bName
);
return
strncmp
(
aName
,
bName
,
aLen
>
bLen
?
aLen
:
bLen
);
int
ret
=
strncmp
(
aName
,
bName
,
aLen
>
bLen
?
aLen
:
bLen
);
if
(
ret
==
0
)
{
return
ret
;
}
return
ret
<
0
?
-
1
:
1
;
}
}
// tfile name suid-colId-version.tindex
// tfile name suid-colId-version.tindex
static
void
tfileGenFileName
(
char
*
filename
,
uint64_t
suid
,
int
colId
,
int
version
)
{
static
void
tfileGenFileName
(
char
*
filename
,
uint64_t
suid
,
int
colId
,
int
version
)
{
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
0365c67b
...
@@ -24,6 +24,22 @@
...
@@ -24,6 +24,22 @@
#include "tskiplist.h"
#include "tskiplist.h"
#include "tutil.h"
#include "tutil.h"
using
namespace
std
;
using
namespace
std
;
class
DebugInfo
{
public:
DebugInfo
(
const
char
*
str
)
:
info
(
str
)
{
std
::
cout
<<
"------------"
<<
info
<<
"
\t
"
<<
"begin"
<<
"-------------"
<<
std
::
endl
;
}
~
DebugInfo
()
{
std
::
cout
<<
"-----------"
<<
info
<<
"
\t
"
<<
"end"
<<
"--------------"
<<
std
::
endl
;
}
private:
std
::
string
info
;
};
class
FstWriter
{
class
FstWriter
{
public:
public:
FstWriter
()
{
FstWriter
()
{
...
@@ -133,7 +149,6 @@ int Performance_fstWriteRecords(FstWriter* b) {
...
@@ -133,7 +149,6 @@ int Performance_fstWriteRecords(FstWriter* b) {
}
}
return
L
*
M
*
N
;
return
L
*
M
*
N
;
}
}
void
Performance_fstReadRecords
(
FstReadMemory
*
m
)
{
void
Performance_fstReadRecords
(
FstReadMemory
*
m
)
{
std
::
string
str
(
"aa"
);
std
::
string
str
(
"aa"
);
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
...
@@ -168,7 +183,6 @@ void checkFstPerf() {
...
@@ -168,7 +183,6 @@ void checkFstPerf() {
Performance_fstReadRecords
(
m
);
Performance_fstReadRecords
(
m
);
delete
m
;
delete
m
;
}
}
void
checkFstPrefixSearch
()
{
void
checkFstPrefixSearch
()
{
FstWriter
*
fw
=
new
FstWriter
;
FstWriter
*
fw
=
new
FstWriter
;
int64_t
s
=
taosGetTimestampUs
();
int64_t
s
=
taosGetTimestampUs
();
...
@@ -246,7 +260,6 @@ void validateFst() {
...
@@ -246,7 +260,6 @@ void validateFst() {
}
}
delete
m
;
delete
m
;
}
}
class
IndexEnv
:
public
::
testing
::
Test
{
class
IndexEnv
:
public
::
testing
::
Test
{
protected:
protected:
virtual
void
SetUp
()
{
virtual
void
SetUp
()
{
...
@@ -265,44 +278,51 @@ class IndexEnv : public ::testing::Test {
...
@@ -265,44 +278,51 @@ class IndexEnv : public ::testing::Test {
SIndex
*
index
;
SIndex
*
index
;
};
};
// TEST_F(IndexEnv, testPut) {
/// TEST_F(IndexEnv, testPut) {
// // single index column
// / // single index column
// {
// / {
// std::string colName("tag1"), colVal("Hello world");
// / std::string colName("tag1"), colVal("Hello world");
// SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(),
// / SIndexTerm* term =
// colVal.size()); SIndexMultiTerm* terms = indexMultiTermCreate(); indexMultiTermAdd(terms, term);
// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), / colVal.size());
//
// for (size_t i = 0; i < 100; i++) {
// int tableId = i;
// int ret = indexPut(index, terms, tableId);
// assert(ret == 0);
// }
// indexMultiTermDestroy(terms);
// }
// // multi index column
// {
// SIndexMultiTerm* terms = indexMultiTermCreate();
// SIndexMultiTerm* terms = indexMultiTermCreate();
// {
// std::string colName("tag1"), colVal("Hello world");
// SIndexTerm* term =
// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size());
// indexMultiTermAdd(terms, term);
// indexMultiTermAdd(terms, term);
// / / for (size_t i = 0; i < 100; i++) {
// / int tableId = i;
// / int ret = indexPut(index, terms, tableId);
// / assert(ret == 0);
// /
// }
// }
// {
// / indexMultiTermDestroy(terms);
// std::string colName("tag2"), colVal("Hello world");
// /
// SIndexTerm* term =
// }
// indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size());
// / // multi index column
// indexMultiTermAdd(terms, term);
// / {
// / SIndexMultiTerm* terms = indexMultiTermCreate();
// / {
// / std::string colName("tag1"), colVal("Hello world");
// / SIndexTerm* term =
// / indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size());
// / indexMultiTermAdd(terms, term);
// /
// }
// }
//
// / {
// for (int i = 0; i < 100; i++) {
// / std::string colName("tag2"), colVal("Hello world");
// int tableId = i;
// / SIndexTerm* term =
// int ret = indexPut(index, terms, tableId);
// / indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), colVal.c_str(), colVal.size());
// assert(ret == 0);
// / indexMultiTermAdd(terms, term);
// /
// }
// }
// indexMultiTermDestroy(terms);
// / / for (int i = 0; i < 100; i++) {
// / int tableId = i;
// / int ret = indexPut(index, terms, tableId);
// / assert(ret == 0);
// /
// }
// }
// //
// / indexMultiTermDestroy(terms);
// /
// }
// / //
// /
//}
//}
class
TFileObj
{
class
TFileObj
{
...
@@ -416,7 +436,6 @@ static void destroyTFileValue(void* val) {
...
@@ -416,7 +436,6 @@ static void destroyTFileValue(void* val) {
taosArrayDestroy
(
tv
->
tableId
);
taosArrayDestroy
(
tv
->
tableId
);
free
(
tv
);
free
(
tv
);
}
}
TEST_F
(
IndexTFileEnv
,
test_tfile_write
)
{
TEST_F
(
IndexTFileEnv
,
test_tfile_write
)
{
TFileValue
*
v1
=
genTFileValue
(
"c"
);
TFileValue
*
v1
=
genTFileValue
(
"c"
);
TFileValue
*
v2
=
genTFileValue
(
"ab"
);
TFileValue
*
v2
=
genTFileValue
(
"ab"
);
...
@@ -492,241 +511,66 @@ class IndexCacheEnv : public ::testing::Test {
...
@@ -492,241 +511,66 @@ class IndexCacheEnv : public ::testing::Test {
CacheObj
*
coj
;
CacheObj
*
coj
;
};
};
#define MAX_TERM_KEY_LEN 128
TEST_F
(
IndexCacheEnv
,
cache_test
)
{
TEST_F
(
IndexCacheEnv
,
cache_test
)
{
int
count
=
10
;
int
version
=
0
;
int16_t
colId
=
0
;
int16_t
colId
=
1
;
uint64_t
suid
=
0
;
int32_t
version
=
10
;
uint64_t
suid
=
100
;
std
::
string
colName
(
"voltage"
);
std
::
string
colName
(
"voltage"
);
std
::
string
colVal
(
"My God"
);
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
colVal
+=
(
'a'
+
i
);
SIndexTerm
*
term
=
indexTermCreate
(
1
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
,
suid
);
version
++
;
}
// coj->Get();
}
typedef
struct
CTerm
{
char
buf
[
16
];
char
version
[
8
];
int
val
;
int
other
;
}
CTerm
;
CTerm
*
cTermCreate
(
const
char
*
str
,
const
char
*
version
,
int
val
)
{
CTerm
*
tm
=
(
CTerm
*
)
calloc
(
1
,
sizeof
(
CTerm
));
memcpy
(
tm
->
buf
,
str
,
strlen
(
str
));
memcpy
(
tm
->
version
,
version
,
strlen
(
version
));
tm
->
val
=
val
;
tm
->
other
=
-
100
;
return
tm
;
}
int
termCompar
(
const
void
*
a
,
const
void
*
b
)
{
printf
(
"a: %s
\t
b: %s
\n
"
,
(
char
*
)
a
,
(
char
*
)
b
);
int
ret
=
strncmp
((
char
*
)
a
,
(
char
*
)
b
,
16
);
if
(
ret
==
0
)
{
//
return
strncmp
((
char
*
)
a
+
16
,
(
char
*
)
b
+
16
,
8
);
}
return
ret
;
}
int
SerialTermTo
(
char
*
buf
,
CTerm
*
term
)
{
char
*
p
=
buf
;
memcpy
(
buf
,
term
->
buf
,
sizeof
(
term
->
buf
));
buf
+=
sizeof
(
term
->
buf
);
// memcpy(buf, term->version, sizeof(term->version));
// buf += sizeof(term->version);
return
buf
-
p
;
}
static
char
*
getTermKey
(
const
void
*
pData
)
{
CTerm
*
p
=
(
CTerm
*
)
pData
;
return
(
char
*
)
p
->
buf
;
}
#define MAX_TERM_KEY_LEN 128
class
SkiplistObj
{
public:
// max_key_len:
//
SkiplistObj
()
{
slt
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_TERM_KEY_LEN
,
termCompar
,
SL_ALLOW_DUP_KEY
,
getTermKey
);
}
int
Put
(
CTerm
*
term
,
uint64_t
suid
)
{
char
buf
[
MAX_TERM_KEY_LEN
]
=
{
0
};
int
sz
=
SerialTermTo
(
buf
,
term
);
char
*
pBuf
=
(
char
*
)
calloc
(
1
,
sz
+
sizeof
(
suid
));
memcpy
(
pBuf
,
buf
,
sz
);
memcpy
(
pBuf
+
sz
,
&
suid
,
sizeof
(
suid
));
// int32_t level, headsize;
// tSkipListNewNodeInfo(slt, &level, &headsize);
// SSkipListNode* node = (SSkipListNode*)calloc(1, headsize + strlen(buf) + sizeof(suid));
// node->level = level;
// char* d = (char*)SL_GET_NODE_DATA(node);
// memcpy(d, buf, strlen(buf));
// memcpy(d + strlen(buf), &suid, sizeof(suid));
SSkipListNode
*
node
=
tSkipListPut
(
slt
,
pBuf
);
tSkipListPrint
(
slt
,
1
);
free
(
pBuf
);
return
0
;
}
int
Get
(
int
key
,
char
*
buf
,
int
version
)
{
// TODO
// CTerm term;
// term.key = key;
//// term.version = version;
// memcpy(term.buf, buf, strlen(buf));
// char tbuf[128] = {0};
// SerialTermTo(tbuf, &term);
// SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
// SSkipListNode* node = tSkipListIterGet(iter);
// CTerm* ct = (CTerm*)SL_GET_NODE_DATA(node);
// printf("key: %d\t, version: %d\t, buf: %s\n", ct->key, ct->version, ct->buf);
// while (iter) {
// assert(tSkipListIterNext(iter) == true);
// SSkipListNode* node = tSkipListIterGet(iter);
// // ugly formate
// CTerm* t = (CTerm*)SL_GET_NODE_KEY(slt, node);
// printf("key: %d\t, version: %d\t, buf: %s\n", t->key, t->version, t->buf);
//}
return
0
;
}
~
SkiplistObj
()
{
// TODO
// indexCacheDestroy(cache);
}
private:
SSkipList
*
slt
;
};
typedef
struct
KV
{
int32_t
k
;
int32_t
v
;
}
KV
;
int
kvCompare
(
const
void
*
a
,
const
void
*
b
)
{
int32_t
av
=
*
(
int32_t
*
)
a
;
int32_t
bv
=
*
(
int32_t
*
)
b
;
return
av
-
bv
;
}
char
*
getKVkey
(
const
void
*
a
)
{
return
(
char
*
)(
&
(((
KV
*
)
a
)
->
v
));
// KV* kv = (KV*)a;
}
int
testKV
()
{
SSkipList
*
slt
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_TERM_KEY_LEN
,
kvCompare
,
SL_DISCARD_DUP_KEY
,
getKVkey
);
{
{
KV
t
=
{.
k
=
1
,
.
v
=
5
};
std
::
string
colVal
(
"v1"
);
tSkipListPut
(
slt
,
(
void
*
)
&
t
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
}
}
{
{
KV
t
=
{.
k
=
2
,
.
v
=
3
};
std
::
string
colVal
(
"v3"
);
tSkipListPut
(
slt
,
(
void
*
)
&
t
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
}
}
KV
value
=
{.
k
=
4
,
.
v
=
5
};
char
*
key
=
getKVkey
(
&
value
);
// const char* key = "Hello";
SArray
*
arr
=
tSkipListGet
(
slt
,
(
SSkipListKey
)
&
key
);
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
arr
);
i
++
)
{
SSkipListNode
*
node
=
(
SSkipListNode
*
)
taosArrayGetP
(
arr
,
i
);
int32_t
*
ct
=
(
int32_t
*
)
SL_GET_NODE_KEY
(
slt
,
node
);
printf
(
"Get key: %d
\n
"
,
*
ct
);
// SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
}
return
1
;
}
int
testComplicate
()
{
SSkipList
*
slt
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_TERM_KEY_LEN
,
termCompar
,
SL_ALLOW_DUP_KEY
,
getTermKey
);
{
{
CTerm
*
tm
=
cTermCreate
(
"val"
,
"v1"
,
10
);
std
::
string
colVal
(
"v2"
);
tSkipListPut
(
slt
,
(
char
*
)
tm
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
}
}
{
{
CTerm
*
tm
=
cTermCreate
(
"val1"
,
"v2"
,
2
);
std
::
string
colVal
(
"v3"
);
tSkipListPut
(
slt
,
(
char
*
)
tm
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
}
}
{
{
CTerm
*
tm
=
cTermCreate
(
"val3"
,
"v3"
,
-
1
);
std
::
string
colVal
(
"v3"
);
tSkipListPut
(
slt
,
(
char
*
)
tm
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
}
}
{
{
CTerm
*
tm
=
cTermCreate
(
"val3"
,
"v4"
,
2
);
std
::
string
colVal
(
"v4"
);
tSkipListPut
(
slt
,
(
char
*
)
tm
);
for
(
size_t
i
=
0
;
i
<
100
;
i
++
)
{
colVal
[
colVal
.
size
()
-
1
]
=
'a'
+
i
;
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
coj
->
Put
(
term
,
colId
,
version
++
,
suid
++
);
}
}
}
{
{
CTerm
*
tm
=
cTermCreate
(
"val3"
,
"v5"
,
-
1
);
std
::
string
colVal
(
"v3"
);
char
*
key
=
getTermKey
(
tm
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
SArray
*
arr
=
tSkipListGet
(
slt
,
(
SSkipListKey
)
key
);
SIndexTermQuery
query
=
{.
term
=
term
,
.
qType
=
QUERY_TERM
};
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
arr
);
i
++
)
{
SArray
*
ret
=
(
SArray
*
)
taosArrayInit
(
4
,
sizeof
(
suid
));
SSkipListNode
*
node
=
(
SSkipListNode
*
)
taosArrayGetP
(
arr
,
i
);
STermValueType
valType
;
CTerm
*
ct
=
(
CTerm
*
)
SL_GET_NODE_KEY
(
slt
,
node
);
printf
(
"other; %d
\t
buf: %s
\t
, version: %s, val: %d
\n
"
,
ct
->
other
,
ct
->
buf
,
ct
->
version
,
ct
->
val
);
coj
->
Get
(
&
query
,
colId
,
10000
,
ret
,
&
valType
);
// SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
assert
(
taosArrayGetSize
(
ret
)
==
3
);
}
free
(
tm
);
taosArrayDestroy
(
arr
);
}
return
1
;
}
int
strCompare
(
const
void
*
a
,
const
void
*
b
)
{
const
char
*
sa
=
(
char
*
)
a
;
const
char
*
sb
=
(
char
*
)
b
;
return
strcmp
(
sa
,
sb
);
}
void
testString
()
{
SSkipList
*
slt
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_BINARY
,
MAX_TERM_KEY_LEN
,
strCompare
,
SL_ALLOW_DUP_KEY
,
getTermKey
);
{
tSkipListPut
(
slt
,
(
void
*
)
"Hello"
);
tSkipListPut
(
slt
,
(
void
*
)
"World"
);
tSkipListPut
(
slt
,
(
void
*
)
"YI"
);
}
}
{
std
::
string
colVal
(
"v2"
);
SIndexTerm
*
term
=
indexTermCreate
(
0
,
ADD_VALUE
,
TSDB_DATA_TYPE_BINARY
,
colName
.
c_str
(),
colName
.
size
(),
colVal
.
c_str
(),
colVal
.
size
());
SIndexTermQuery
query
=
{.
term
=
term
,
.
qType
=
QUERY_TERM
};
SArray
*
ret
=
(
SArray
*
)
taosArrayInit
(
4
,
sizeof
(
suid
));
STermValueType
valType
;
const
char
*
key
=
"YI"
;
coj
->
Get
(
&
query
,
colId
,
10000
,
ret
,
&
valType
);
SArray
*
arr
=
tSkipListGet
(
slt
,
(
SSkipListKey
)
key
);
assert
(
taosArrayGetSize
(
ret
)
==
1
);
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
arr
);
i
++
)
{
SSkipListNode
*
node
=
(
SSkipListNode
*
)
taosArrayGetP
(
arr
,
i
);
char
*
ct
=
(
char
*
)
SL_GET_NODE_KEY
(
slt
,
node
);
printf
(
"Get key: %s
\n
"
,
ct
);
// SSkipListIterator* iter = tSkipListCreateIterFromVal(slt, tbuf, TSDB_DATA_TYPE_BINARY, TSDB_ORDER_ASC);
}
}
}
}
// class IndexSkip : public ::testing::Test {
// protected:
// virtual void SetUp() {
// // TODO
// sObj = new SkiplistObj();
// }
// virtual void TearDown() {
// delete sObj;
// // formate
// }
// SkiplistObj* sObj;
//};
// TEST_F(IndexSkip, skip_test) {
// std::string val("Hello");
// std::string minVal = val;
// for (size_t i = 0; i < 10; i++) {
// CTerm* t = (CTerm*)calloc(1, sizeof(CTerm));
// t->key = 1;
// t->version = i;
//
// val[val.size() - 1] = 'a' + i;
// memcpy(t->buf, val.c_str(), val.size());
// sObj->Put(t, 10);
// free(t);
// }
// sObj->Get(1, (char*)(minVal.c_str()), 1000000);
//}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录