Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
09e91f9a
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
09e91f9a
编写于
9月 16, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1437
上级
dee16dd4
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
606 addition
and
544 deletion
+606
-544
src/query/src/qAst.c
src/query/src/qAst.c
+3
-3
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+12
-28
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+4
-19
src/util/CMakeLists.txt
src/util/CMakeLists.txt
+1
-1
src/util/inc/tskiplist.h
src/util/inc/tskiplist.h
+34
-15
src/util/src/tskiplist.c
src/util/src/tskiplist.c
+550
-476
src/util/tests/skiplistTest.cpp
src/util/tests/skiplistTest.cpp
+2
-2
未找到文件。
src/query/src/qAst.c
浏览文件 @
09e91f9a
...
...
@@ -411,9 +411,9 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
}
if
(
cond
.
start
!=
NULL
)
{
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
cond
.
start
->
v
,
pSkipList
->
keyInfo
.
type
,
TSDB_ORDER_ASC
);
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
cond
.
start
->
v
,
pSkipList
->
type
,
TSDB_ORDER_ASC
);
}
else
{
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)(
cond
.
end
?
cond
.
end
->
v
:
NULL
),
pSkipList
->
keyInfo
.
type
,
TSDB_ORDER_DESC
);
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)(
cond
.
end
?
cond
.
end
->
v
:
NULL
),
pSkipList
->
type
,
TSDB_ORDER_DESC
);
}
if
(
cond
.
start
!=
NULL
)
{
...
...
@@ -468,7 +468,7 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr
tSkipListDestroyIter
(
iter
);
comp
=
true
;
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
cond
.
start
->
v
,
pSkipList
->
keyInfo
.
type
,
TSDB_ORDER_DESC
);
iter
=
tSkipListCreateIterFromVal
(
pSkipList
,
(
char
*
)
cond
.
start
->
v
,
pSkipList
->
type
,
TSDB_ORDER_DESC
);
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
comp
=
comp
&&
(
pQueryInfo
->
compare
(
SL_GET_NODE_KEY
(
pSkipList
,
pNode
),
cond
.
start
->
v
)
==
0
);
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
09e91f9a
...
...
@@ -37,38 +37,25 @@ static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables);
int
tsdbInsertRowToMem
(
STsdbRepo
*
pRepo
,
SDataRow
row
,
STable
*
pTable
)
{
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
int32_t
level
=
0
;
int32_t
headSize
=
0
;
TSKEY
key
=
dataRowKey
(
row
);
SMemTable
*
pMemTable
=
pRepo
->
mem
;
STableData
*
pTableData
=
NULL
;
SSkipList
*
pSList
=
NULL
;
//
SSkipList * pSList = NULL;
if
(
pMemTable
!=
NULL
&&
TABLE_TID
(
pTable
)
<
pMemTable
->
maxTables
&&
pMemTable
->
tData
[
TABLE_TID
(
pTable
)]
!=
NULL
&&
pMemTable
->
tData
[
TABLE_TID
(
pTable
)]
->
uid
==
TABLE_UID
(
pTable
))
{
pTableData
=
pMemTable
->
tData
[
TABLE_TID
(
pTable
)];
pSList
=
pTableData
->
pData
;
}
tSkipListNewNodeInfo
(
pSList
,
&
level
,
&
headSize
);
SSkipListNode
*
pNode
=
(
SSkipListNode
*
)
malloc
(
headSize
+
sizeof
(
SDataRow
*
));
if
(
pNode
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
// if (pMemTable != NULL && TABLE_TID(pTable) < pMemTable->maxTables && pMemTable->tData[TABLE_TID(pTable)] != NULL &&
// pMemTable->tData[TABLE_TID(pTable)]->uid == TABLE_UID(pTable)) {
// pTableData = pMemTable->tData[TABLE_TID(pTable)];
// pSList = pTableData->pData;
// }
void
*
pRow
=
tsdbAllocBytes
(
pRepo
,
dataRowLen
(
row
));
if
(
pRow
==
NULL
)
{
tsdbError
(
"vgId:%d failed to insert row with key %"
PRId64
" to table %s while allocate %d bytes since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
),
dataRowLen
(
row
),
tstrerror
(
terrno
));
free
(
pNode
);
return
-
1
;
}
pNode
->
level
=
level
;
dataRowCpy
(
pRow
,
row
);
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
pNode
)
=
pRow
;
// Operations above may change pRepo->mem, retake those values
ASSERT
(
pRepo
->
mem
!=
NULL
);
...
...
@@ -77,7 +64,6 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
if
(
TABLE_TID
(
pTable
)
>=
pMemTable
->
maxTables
)
{
if
(
tsdbAdjustMemMaxTables
(
pMemTable
,
pMeta
->
maxTables
)
<
0
)
{
tsdbFreeBytes
(
pRepo
,
pRow
,
dataRowLen
(
row
));
free
(
pNode
);
return
-
1
;
}
}
...
...
@@ -97,7 +83,6 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
" to table %s while create new table data object since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
),
tstrerror
(
terrno
));
tsdbFreeBytes
(
pRepo
,
(
void
*
)
pRow
,
dataRowLen
(
row
));
free
(
pNode
);
return
-
1
;
}
...
...
@@ -106,20 +91,19 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
ASSERT
((
pTableData
!=
NULL
)
&&
pTableData
->
uid
==
TABLE_UID
(
pTable
));
if
(
tSkipListPut
(
pTableData
->
pData
,
pNode
)
==
NULL
)
{
int64_t
oldSize
=
SL_GET_SIZE
(
pTableData
->
pData
);
if
(
tSkipListPut
(
pTableData
->
pData
,
(
void
*
)(
&
pRow
),
sizeof
(
void
*
))
==
NULL
)
{
tsdbFreeBytes
(
pRepo
,
(
void
*
)
pRow
,
dataRowLen
(
row
));
free
(
pNode
);
}
else
{
int64_t
deltaSize
=
SL_GET_SIZE
(
pTableData
->
pData
)
-
oldSize
;
if
(
TABLE_LASTKEY
(
pTable
)
<
key
)
TABLE_LASTKEY
(
pTable
)
=
key
;
if
(
pMemTable
->
keyFirst
>
key
)
pMemTable
->
keyFirst
=
key
;
if
(
pMemTable
->
keyLast
<
key
)
pMemTable
->
keyLast
=
key
;
pMemTable
->
numOfRows
++
;
pMemTable
->
numOfRows
+=
deltaSize
;
if
(
pTableData
->
keyFirst
>
key
)
pTableData
->
keyFirst
=
key
;
if
(
pTableData
->
keyLast
<
key
)
pTableData
->
keyLast
=
key
;
pTableData
->
numOfRows
++
;
ASSERT
(
pTableData
->
numOfRows
==
tSkipListGetSize
(
pTableData
->
pData
));
pTableData
->
numOfRows
+=
deltaSize
;
}
tsdbTrace
(
"vgId:%d a row is inserted to table %s tid %d uid %"
PRIu64
" key %"
PRIu64
,
REPO_ID
(
pRepo
),
...
...
@@ -439,7 +423,7 @@ static STableData *tsdbNewTableData(STsdbCfg *pCfg, STable *pTable) {
pTableData
->
numOfRows
=
0
;
pTableData
->
pData
=
tSkipListCreate
(
TSDB_DATA_SKIPLIST_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
TYPE_BYTES
[
TSDB_DATA_TYPE_TIMESTAMP
],
0
,
0
,
1
,
tsdbGetTsTupleKey
);
TYPE_BYTES
[
TSDB_DATA_TYPE_TIMESTAMP
],
/*SL_DISCARD_DUP_KEY*/
SL_APPEND_DUP_KEY
,
tsdbGetTsTupleKey
);
if
(
pTableData
->
pData
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
09e91f9a
...
...
@@ -690,7 +690,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
}
pTable
->
tagVal
=
NULL
;
STColumn
*
pCol
=
schemaColAt
(
pTable
->
tagSchema
,
DEFAULT_TAG_INDEX_COLUMN
);
pTable
->
pIndex
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
colType
(
pCol
),
(
uint8_t
)(
colBytes
(
pCol
)),
1
,
0
,
1
,
getTagIndexKey
);
pTable
->
pIndex
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
colType
(
pCol
),
(
uint8_t
)(
colBytes
(
pCol
)),
SL_ALLOW_DUP_KEY
,
getTagIndexKey
);
if
(
pTable
->
pIndex
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
...
...
@@ -892,23 +892,8 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper
pTable
->
pSuper
=
pSTable
;
int32_t
level
=
0
;
int32_t
headSize
=
0
;
tSkipListPut
(
pSTable
->
pIndex
,
(
void
*
)(
&
pTable
),
sizeof
(
STable
*
));
tSkipListNewNodeInfo
(
pSTable
->
pIndex
,
&
level
,
&
headSize
);
// NOTE: do not allocate the space for key, since in each skip list node, only keep the pointer to pTable, not the
// actual key value, and the key value will be retrieved during query through the pTable and getTagIndexKey function
SSkipListNode
*
pNode
=
calloc
(
1
,
headSize
+
sizeof
(
STable
*
));
if
(
pNode
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
pNode
->
level
=
level
;
memcpy
(
SL_GET_NODE_DATA
(
pNode
),
&
pTable
,
sizeof
(
STable
*
));
tSkipListPut
(
pSTable
->
pIndex
,
pNode
);
if
(
refSuper
)
T_REF_INC
(
pSTable
);
return
0
;
}
...
...
@@ -1165,7 +1150,7 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) {
buf
=
tdDecodeSchema
(
buf
,
&
(
pTable
->
tagSchema
));
STColumn
*
pCol
=
schemaColAt
(
pTable
->
tagSchema
,
DEFAULT_TAG_INDEX_COLUMN
);
pTable
->
pIndex
=
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
colType
(
pCol
),
(
uint8_t
)(
colBytes
(
pCol
)),
1
,
0
,
1
,
getTagIndexKey
);
tSkipListCreate
(
TSDB_SUPER_TABLE_SL_LEVEL
,
colType
(
pCol
),
(
uint8_t
)(
colBytes
(
pCol
)),
SL_ALLOW_DUP_KEY
,
getTagIndexKey
);
if
(
pTable
->
pIndex
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
tsdbFreeTable
(
pTable
);
...
...
@@ -1191,7 +1176,7 @@ static int tsdbGetTableEncodeSize(int8_t act, STable *pTable) {
tlen
=
sizeof
(
SListNode
)
+
sizeof
(
SActObj
)
+
sizeof
(
SActCont
)
+
tsdbEncodeTable
(
NULL
,
pTable
)
+
sizeof
(
TSCKSUM
);
}
else
{
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_SUPER_TABLE
)
{
tlen
=
(
int
)((
sizeof
(
SListNode
)
+
sizeof
(
SActObj
))
*
(
tSkipListGetSize
(
pTable
->
pIndex
)
+
1
));
tlen
=
(
int
)((
sizeof
(
SListNode
)
+
sizeof
(
SActObj
))
*
(
SL_GET_SIZE
(
pTable
->
pIndex
)
+
1
));
}
else
{
tlen
=
sizeof
(
SListNode
)
+
sizeof
(
SActObj
);
}
...
...
src/util/CMakeLists.txt
浏览文件 @
09e91f9a
...
...
@@ -7,7 +7,7 @@ TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4)
IF
(
TD_LINUX
)
TARGET_LINK_LIBRARIES
(
tutil m rt
)
ADD_SUBDIRECTORY
(
tests
)
#
ADD_SUBDIRECTORY(tests)
FIND_PATH
(
ICONV_INCLUDE_EXIST iconv.h /usr/include/ /usr/local/include/
)
IF
(
ICONV_INCLUDE_EXIST
)
...
...
src/util/inc/tskiplist.h
浏览文件 @
09e91f9a
...
...
@@ -27,6 +27,14 @@ extern "C" {
#define MAX_SKIP_LIST_LEVEL 15
#define SKIP_LIST_RECORD_PERFORMANCE 0
// For key property setting
#define SL_ALLOW_DUP_KEY (uint8_t)0x0 // Allow duplicate key exists
#define SL_DISCARD_DUP_KEY (uint8_t)0x1 // Discard duplicate key
#define SL_UPDATA_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert
#define SL_APPEND_DUP_KEY (uint8_t)0x3 // Update duplicate key by append
// For thread safety setting
#define SL_THREAD_SAFE (uint8_t)0x4
typedef
char
*
SSkipListKey
;
typedef
char
*
(
*
__sl_key_fn_t
)(
const
void
*
);
...
...
@@ -41,6 +49,9 @@ typedef struct SSkipListNode {
uint8_t
level
;
}
SSkipListNode
;
#define SL_IS_THREAD_SAFE(flags) ((flags)&SL_THREAD_SAFE)
#define SL_DUP_MODE(flags) ((flags) & ((((uint8_t)1) << 2) - 1))
#define SL_NODE_HEADER_SIZE(_l) (sizeof(SSkipListNode) + ((_l) << 1u) * POINTER_BYTES)
#define SL_GET_FORWARD_POINTER(n, _l) ((SSkipListNode **)((char *)(n) + sizeof(SSkipListNode)))[(_l)]
...
...
@@ -54,6 +65,8 @@ typedef struct SSkipListNode {
#define SL_GET_SL_MAX_KEY(s) (SL_GET_NODE_KEY((s), SL_GET_BACKWARD_POINTER((s)->pTail, 0)))
#define SL_GET_NODE_LEVEL(n) *(uint8_t *)((n))
#define SL_GET_SIZE(s) (s)->size
#define SL_GET_TSIZE(s) (s)->tsize
/*
* @version 0.3
...
...
@@ -113,13 +126,16 @@ typedef struct SSkipListKeyInfo {
typedef
struct
SSkipList
{
__compar_fn_t
comparFn
;
__sl_key_fn_t
keyFn
;
uint32_t
size
;
pthread_rwlock_t
*
lock
;
uint16_t
len
;
uint8_t
maxLevel
;
uint8_t
flags
;
uint8_t
type
;
// static info above
uint8_t
level
;
SSkipListKeyInfo
keyInfo
;
pthread_rwlock_t
*
lock
;
SSkipListNode
*
pHead
;
// point to the first element
SSkipListNode
*
pTail
;
// point to the last element
uint32_t
size
;
// not including duplicate keys
uint32_t
tsize
;
// including duplicate keys
SSkipListNode
*
pHead
;
// point to the first element
SSkipListNode
*
pTail
;
// point to the last element
#if SKIP_LIST_RECORD_PERFORMANCE
tSkipListState
state
;
// skiplist state
#endif
...
...
@@ -145,8 +161,7 @@ typedef struct SSkipListIterator {
* @param dupKey allow the duplicated key in the skip list
* @return
*/
SSkipList
*
tSkipListCreate
(
uint8_t
nMaxLevel
,
uint8_t
keyType
,
uint8_t
keyLen
,
uint8_t
dupKey
,
uint8_t
threadsafe
,
uint8_t
freeNode
,
__sl_key_fn_t
fn
);
SSkipList
*
tSkipListCreate
(
uint8_t
nMaxLevel
,
uint8_t
keyType
,
uint16_t
keyLen
,
uint8_t
flags
,
__sl_key_fn_t
fn
);
/**
*
...
...
@@ -164,30 +179,34 @@ void *tSkipListDestroy(SSkipList *pSkipList);
void
tSkipListNewNodeInfo
(
SSkipList
*
pSkipList
,
int32_t
*
level
,
int32_t
*
headSize
);
/**
* put the
skip list node into the skip list.
* put the
data into the skiplist
* If failed, NULL will be returned, otherwise, the pNode will be returned.
*
* @param pSkipList
* @param pNode
* @param pData
* @param dataLen
* @return
*/
SSkipListNode
*
tSkipListPut
(
SSkipList
*
pSkipList
,
SSkipListNode
*
pNode
);
SSkipListNode
*
tSkipListPut
(
SSkipList
*
pSkipList
,
void
*
pData
,
int
dataLen
);
/**
* get *all* nodes which key are equivalent to pKey
* put the skip list node into the skip list.
* If failed, NULL will be returned, otherwise, the pNode will be returned.
*
* @param pSkipList
* @param p
Key
* @param p
Node
* @return
*/
S
Array
*
tSkipListGet
(
SSkipList
*
pSkipList
,
SSkipListKey
pKey
);
S
SkipListNode
*
tSkipListPutNode
(
SSkipList
*
pSkipList
,
SSkipListNode
*
pNode
);
/**
* get the size of skip list
* get *all* nodes which key are equivalent to pKey
*
* @param pSkipList
* @param pKey
* @return
*/
size_t
tSkipListGetSize
(
const
SSkipList
*
pSkipList
);
SArray
*
tSkipListGet
(
SSkipList
*
pSkipList
,
SSkipListKey
pKey
);
/**
* display skip list of the given level, for debug purpose only
...
...
src/util/src/tskiplist.c
浏览文件 @
09e91f9a
此差异已折叠。
点击以展开。
src/util/tests/skiplistTest.cpp
浏览文件 @
09e91f9a
...
...
@@ -247,7 +247,7 @@ void skiplistPerformanceTest() {
printf
(
"total:%"
PRIu64
" ms, avg:%f
\n
"
,
e
-
s
,
(
e
-
s
)
/
(
double
)
size
);
printf
(
"max level of skiplist:%d, actually level:%d
\n
"
,
pSkipList
->
maxLevel
,
pSkipList
->
level
);
assert
(
tSkipListGetSize
(
pSkipList
)
==
size
);
assert
(
SL_GET_SIZE
(
pSkipList
)
==
size
);
// printf("the level of skiplist is:\n");
//
...
...
@@ -273,7 +273,7 @@ void skiplistPerformanceTest() {
int64_t
et
=
taosGetTimestampMs
();
printf
(
"delete %d data from skiplist, elapased time:%"
PRIu64
"ms
\n
"
,
10000
,
et
-
st
);
assert
(
tSkipListGetSize
(
pSkipList
)
==
size
);
assert
(
SL_GET_SIZE
(
pSkipList
)
==
size
);
tSkipListDestroy
(
pSkipList
);
taosTFree
(
total
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录