Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c71c111d
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
c71c111d
编写于
1月 06, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
1月 06, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9621 from taosdata/feature/index_complete
Feature/index complete
上级
33d8177e
ccbbac4e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
17 deletion
+39
-17
source/libs/index/inc/index_cache.h
source/libs/index/inc/index_cache.h
+2
-1
source/libs/index/src/index.c
source/libs/index/src/index.c
+15
-2
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+19
-8
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+0
-3
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+3
-3
未找到文件。
source/libs/index/inc/index_cache.h
浏览文件 @
c71c111d
...
@@ -40,11 +40,12 @@ typedef struct IndexCache {
...
@@ -40,11 +40,12 @@ typedef struct IndexCache {
SIndex
*
index
;
SIndex
*
index
;
char
*
colName
;
char
*
colName
;
int32_t
version
;
int32_t
version
;
int
32_t
nTer
m
;
int
64_t
occupiedMe
m
;
int8_t
type
;
int8_t
type
;
uint64_t
suid
;
uint64_t
suid
;
pthread_mutex_t
mtx
;
pthread_mutex_t
mtx
;
pthread_cond_t
finished
;
}
IndexCache
;
}
IndexCache
;
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
...
...
source/libs/index/src/index.c
浏览文件 @
c71c111d
...
@@ -399,6 +399,8 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -399,6 +399,8 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
if
(
sIdx
==
NULL
)
{
return
-
1
;
}
indexInfo
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
indexInfo
(
"suid %"
PRIu64
" merge cache into tindex"
,
sIdx
->
suid
);
int64_t
st
=
taosGetTimestampUs
();
IndexCache
*
pCache
=
(
IndexCache
*
)
cache
;
IndexCache
*
pCache
=
(
IndexCache
*
)
cache
;
TFileReader
*
pReader
=
tfileGetReaderByCol
(
sIdx
->
tindex
,
pCache
->
suid
,
pCache
->
colName
);
TFileReader
*
pReader
=
tfileGetReaderByCol
(
sIdx
->
tindex
,
pCache
->
suid
,
pCache
->
colName
);
if
(
pReader
==
NULL
)
{
indexWarn
(
"empty tfile reader found"
);
}
if
(
pReader
==
NULL
)
{
indexWarn
(
"empty tfile reader found"
);
}
...
@@ -458,6 +460,7 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -458,6 +460,7 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
}
}
int
ret
=
indexGenTFile
(
sIdx
,
pCache
,
result
);
int
ret
=
indexGenTFile
(
sIdx
,
pCache
,
result
);
indexDestroyTempResult
(
result
);
indexDestroyTempResult
(
result
);
indexCacheDestroyImm
(
pCache
);
indexCacheDestroyImm
(
pCache
);
indexCacheIteratorDestroy
(
cacheIter
);
indexCacheIteratorDestroy
(
cacheIter
);
...
@@ -465,7 +468,14 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
...
@@ -465,7 +468,14 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) {
tfileReaderUnRef
(
pReader
);
tfileReaderUnRef
(
pReader
);
indexCacheUnRef
(
pCache
);
indexCacheUnRef
(
pCache
);
return
0
;
int64_t
cost
=
taosGetTimestampUs
()
-
st
;
if
(
ret
!=
0
)
{
indexError
(
"failed to merge, time cost: %"
PRId64
"ms"
,
cost
/
1000
);
}
else
{
indexInfo
(
"success to merge , time cost: %"
PRId64
"ms"
,
cost
/
1000
);
}
return
ret
;
}
}
void
iterateValueDestroy
(
IterateValue
*
value
,
bool
destroy
)
{
void
iterateValueDestroy
(
IterateValue
*
value
,
bool
destroy
)
{
if
(
destroy
)
{
if
(
destroy
)
{
...
@@ -506,7 +516,10 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
...
@@ -506,7 +516,10 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
pthread_mutex_unlock
(
&
sIdx
->
mtx
);
pthread_mutex_unlock
(
&
sIdx
->
mtx
);
return
ret
;
return
ret
;
END:
END:
tfileWriterClose
(
tw
);
if
(
tw
!=
NULL
)
{
writerCtxDestroy
(
tw
->
ctx
,
true
);
free
(
tw
);
}
return
-
1
;
return
-
1
;
}
}
...
...
source/libs/index/src/index_cache.c
浏览文件 @
c71c111d
...
@@ -21,6 +21,8 @@
...
@@ -21,6 +21,8 @@
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MAX_INDEX_KEY_LEN 256 // test only, change later
#define MEM_TERM_LIMIT 10 * 10000
#define MEM_TERM_LIMIT 10 * 10000
#define MEM_THRESHOLD 1024 * 1024 * 2
#define MEM_ESTIMATE_RADIO 1.5
static
void
indexMemRef
(
MemTable
*
tbl
);
static
void
indexMemRef
(
MemTable
*
tbl
);
static
void
indexMemUnRef
(
MemTable
*
tbl
);
static
void
indexMemUnRef
(
MemTable
*
tbl
);
...
@@ -50,7 +52,11 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
...
@@ -50,7 +52,11 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
cache
->
index
=
idx
;
cache
->
index
=
idx
;
cache
->
version
=
0
;
cache
->
version
=
0
;
cache
->
suid
=
suid
;
cache
->
suid
=
suid
;
cache
->
occupiedMem
=
0
;
pthread_mutex_init
(
&
cache
->
mtx
,
NULL
);
pthread_mutex_init
(
&
cache
->
mtx
,
NULL
);
pthread_cond_init
(
&
cache
->
finished
,
NULL
);
indexCacheRef
(
cache
);
indexCacheRef
(
cache
);
return
cache
;
return
cache
;
}
}
...
@@ -121,6 +127,7 @@ void indexCacheDestroyImm(IndexCache* cache) {
...
@@ -121,6 +127,7 @@ void indexCacheDestroyImm(IndexCache* cache) {
pthread_mutex_lock
(
&
cache
->
mtx
);
pthread_mutex_lock
(
&
cache
->
mtx
);
tbl
=
cache
->
imm
;
tbl
=
cache
->
imm
;
cache
->
imm
=
NULL
;
// or throw int bg thread
cache
->
imm
=
NULL
;
// or throw int bg thread
pthread_cond_broadcast
(
&
cache
->
finished
);
pthread_mutex_unlock
(
&
cache
->
mtx
);
pthread_mutex_unlock
(
&
cache
->
mtx
);
indexMemUnRef
(
tbl
);
indexMemUnRef
(
tbl
);
...
@@ -133,6 +140,9 @@ void indexCacheDestroy(void* cache) {
...
@@ -133,6 +140,9 @@ void indexCacheDestroy(void* cache) {
indexMemUnRef
(
pCache
->
imm
);
indexMemUnRef
(
pCache
->
imm
);
free
(
pCache
->
colName
);
free
(
pCache
->
colName
);
pthread_mutex_destroy
(
&
pCache
->
mtx
);
pthread_cond_destroy
(
&
pCache
->
finished
);
free
(
pCache
);
free
(
pCache
);
}
}
...
@@ -173,19 +183,19 @@ int indexCacheSchedToMerge(IndexCache* pCache) {
...
@@ -173,19 +183,19 @@ int indexCacheSchedToMerge(IndexCache* pCache) {
}
}
static
void
indexCacheMakeRoomForWrite
(
IndexCache
*
cache
)
{
static
void
indexCacheMakeRoomForWrite
(
IndexCache
*
cache
)
{
while
(
true
)
{
while
(
true
)
{
if
(
cache
->
nTerm
<
MEM_TERM_LIMIT
)
{
if
(
cache
->
occupiedMem
*
MEM_ESTIMATE_RADIO
<
MEM_THRESHOLD
)
{
cache
->
nTerm
+=
1
;
break
;
break
;
}
else
if
(
cache
->
imm
!=
NULL
)
{
}
else
if
(
cache
->
imm
!=
NULL
)
{
// TODO: wake up by condition variable
// TODO: wake up by condition variable
pthread_mutex_unlock
(
&
cache
->
mtx
);
// pthread_mutex_unlock(&cache->mtx);
taosMsleep
(
50
);
pthread_cond_wait
(
&
cache
->
finished
,
&
cache
->
mtx
);
pthread_mutex_lock
(
&
cache
->
mtx
);
// taosMsleep(50);
// pthread_mutex_lock(&cache->mtx);
}
else
{
}
else
{
indexCacheRef
(
cache
);
indexCacheRef
(
cache
);
cache
->
imm
=
cache
->
mem
;
cache
->
imm
=
cache
->
mem
;
cache
->
mem
=
indexInternalCacheCreate
(
cache
->
type
);
cache
->
mem
=
indexInternalCacheCreate
(
cache
->
type
);
cache
->
nTerm
=
1
;
cache
->
occupiedMem
=
0
;
// sched to merge
// sched to merge
// unref cache in bgwork
// unref cache in bgwork
indexCacheSchedToMerge
(
cache
);
indexCacheSchedToMerge
(
cache
);
...
@@ -211,8 +221,9 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
...
@@ -211,8 +221,9 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
ct
->
operaType
=
term
->
operType
;
ct
->
operaType
=
term
->
operType
;
// ugly code, refactor later
// ugly code, refactor later
int64_t
estimate
=
sizeof
(
ct
)
+
strlen
(
ct
->
colVal
);
pthread_mutex_lock
(
&
pCache
->
mtx
);
pthread_mutex_lock
(
&
pCache
->
mtx
);
pCache
->
occupiedMem
+=
estimate
;
indexCacheMakeRoomForWrite
(
pCache
);
indexCacheMakeRoomForWrite
(
pCache
);
MemTable
*
tbl
=
pCache
->
mem
;
MemTable
*
tbl
=
pCache
->
mem
;
indexMemRef
(
tbl
);
indexMemRef
(
tbl
);
...
@@ -333,7 +344,7 @@ static int32_t compareKey(const void* l, const void* r) {
...
@@ -333,7 +344,7 @@ static int32_t compareKey(const void* l, const void* r) {
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
)
{
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
)
{
MemTable
*
tbl
=
calloc
(
1
,
sizeof
(
MemTable
));
MemTable
*
tbl
=
calloc
(
1
,
sizeof
(
MemTable
));
indexMemRef
(
tbl
);
indexMemRef
(
tbl
);
if
(
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
tbl
->
mem
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
type
,
MAX_INDEX_KEY_LEN
,
compareKey
,
SL_ALLOW_DUP_KEY
,
getIndexKey
);
tbl
->
mem
=
tSkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
type
,
MAX_INDEX_KEY_LEN
,
compareKey
,
SL_ALLOW_DUP_KEY
,
getIndexKey
);
}
}
return
tbl
;
return
tbl
;
...
...
source/libs/index/src/index_tfile.c
浏览文件 @
c71c111d
...
@@ -346,9 +346,6 @@ int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
...
@@ -346,9 +346,6 @@ int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
}
}
static
bool
tfileIteratorNext
(
Iterate
*
iiter
)
{
static
bool
tfileIteratorNext
(
Iterate
*
iiter
)
{
IterateValue
*
iv
=
&
iiter
->
val
;
IterateValue
*
iv
=
&
iiter
->
val
;
if
(
iv
->
colVal
!=
NULL
&&
iv
->
val
!=
NULL
)
{
// indexError("value in fst: colVal: %s, size: %d", iv->colVal, (int)taosArrayGetSize(iv->val));
}
iterateValueDestroy
(
iv
,
false
);
iterateValueDestroy
(
iv
,
false
);
char
*
colVal
=
NULL
;
char
*
colVal
=
NULL
;
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
c71c111d
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#include "tutil.h"
#include "tutil.h"
using
namespace
std
;
using
namespace
std
;
#define NUM_OF_THREAD
5
#define NUM_OF_THREAD
10
class
DebugInfo
{
class
DebugInfo
{
public:
public:
...
@@ -882,8 +882,8 @@ static void single_write_and_search(IndexObj* idx) {
...
@@ -882,8 +882,8 @@ static void single_write_and_search(IndexObj* idx) {
static
void
multi_write_and_search
(
IndexObj
*
idx
)
{
static
void
multi_write_and_search
(
IndexObj
*
idx
)
{
int
target
=
idx
->
SearchOne
(
"tag1"
,
"Hello"
);
int
target
=
idx
->
SearchOne
(
"tag1"
,
"Hello"
);
target
=
idx
->
SearchOne
(
"tag2"
,
"Test"
);
target
=
idx
->
SearchOne
(
"tag2"
,
"Test"
);
idx
->
WriteMultiMillonData
(
"tag1"
,
"
Hello
"
,
100
*
10000
);
idx
->
WriteMultiMillonData
(
"tag1"
,
"
hello world test
"
,
100
*
10000
);
idx
->
WriteMultiMillonData
(
"tag2"
,
"
Test
"
,
100
*
10000
);
idx
->
WriteMultiMillonData
(
"tag2"
,
"
world test nothing
"
,
100
*
10000
);
}
}
TEST_F
(
IndexEnv2
,
testIndex_serarch_cache_and_tfile
)
{
TEST_F
(
IndexEnv2
,
testIndex_serarch_cache_and_tfile
)
{
std
::
string
path
=
"/tmp/cache_and_tfile"
;
std
::
string
path
=
"/tmp/cache_and_tfile"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录