Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4a83966f
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,发现更多精彩内容 >>
提交
4a83966f
编写于
9月 22, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-1194
上级
384b5104
变更
6
展开全部
显示空白变更内容
内联
并排
Showing
6 changed file
with
205 addition
and
414 deletion
+205
-414
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+1
-1
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+5
-5
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+3
-3
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+9
-9
src/util/inc/tskiplist.h
src/util/inc/tskiplist.h
+35
-155
src/util/src/tskiplist.c
src/util/src/tskiplist.c
+152
-241
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
4a83966f
...
...
@@ -438,7 +438,7 @@ static FORCE_INLINE SDataRow tsdbNextIterRow(SSkipListIterator* pIter) {
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
);
if
(
node
==
NULL
)
return
NULL
;
return
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
node
);
return
(
SDataRow
)
SL_GET_NODE_DATA
(
node
);
}
static
FORCE_INLINE
TSKEY
tsdbNextIterKey
(
SSkipListIterator
*
pIter
)
{
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
4a83966f
...
...
@@ -91,11 +91,11 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
ASSERT
((
pTableData
!=
NULL
)
&&
pTableData
->
uid
==
TABLE_UID
(
pTable
));
int64_t
oldSize
=
SL_
GET_
SIZE
(
pTableData
->
pData
);
if
(
tSkipListPut
(
pTableData
->
pData
,
(
void
*
)(
&
pRow
),
sizeof
(
void
*
)
)
==
NULL
)
{
int64_t
oldSize
=
SL_SIZE
(
pTableData
->
pData
);
if
(
tSkipListPut
(
pTableData
->
pData
,
pRow
)
==
NULL
)
{
tsdbFreeBytes
(
pRepo
,
(
void
*
)
pRow
,
dataRowLen
(
row
));
}
else
{
int64_t
deltaSize
=
SL_
GET_
SIZE
(
pTableData
->
pData
)
-
oldSize
;
int64_t
deltaSize
=
SL_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
;
...
...
@@ -427,7 +427,7 @@ static STableData *tsdbNewTableData(STsdbCfg *pCfg, STable *pTable) {
pTableData
->
pData
=
tSkipListCreate
(
TSDB_DATA_SKIPLIST_LEVEL
,
TSDB_DATA_TYPE_TIMESTAMP
,
TYPE_BYTES
[
TSDB_DATA_TYPE_TIMESTAMP
],
pCfg
->
update
?
SL_
APPEND
_DUP_KEY
:
SL_DISCARD_DUP_KEY
,
tsdbGetTsTupleKey
);
pCfg
->
update
?
SL_
UPDATE
_DUP_KEY
:
SL_DISCARD_DUP_KEY
,
tsdbGetTsTupleKey
);
if
(
pTableData
->
pData
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
...
...
@@ -447,7 +447,7 @@ static void tsdbFreeTableData(STableData *pTableData) {
}
}
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
)
{
return
dataRowTuple
(
*
(
SDataRow
*
)
data
);
}
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
)
{
return
dataRowTuple
(
(
SDataRow
)
data
);
}
static
void
*
tsdbCommitData
(
void
*
arg
)
{
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
arg
;
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
4a83966f
...
...
@@ -643,7 +643,7 @@ static void tsdbOrgMeta(void *pHandle) {
}
static
char
*
getTagIndexKey
(
const
void
*
pData
)
{
STable
*
pTable
=
*
(
STable
*
*
)
pData
;
STable
*
pTable
=
(
STable
*
)
pData
;
STSchema
*
pSchema
=
tsdbGetTableTagSchema
(
pTable
);
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
DEFAULT_TAG_INDEX_COLUMN
);
...
...
@@ -900,7 +900,7 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper
pTable
->
pSuper
=
pSTable
;
tSkipListPut
(
pSTable
->
pIndex
,
(
void
*
)
(
&
pTable
),
sizeof
(
STable
*
)
);
tSkipListPut
(
pSTable
->
pIndex
,
(
void
*
)
pTable
);
if
(
refSuper
)
T_REF_INC
(
pSTable
);
return
0
;
...
...
@@ -1182,7 +1182,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
))
*
(
SL_
GET_
SIZE
(
pTable
->
pIndex
)
+
1
));
tlen
=
(
int
)((
sizeof
(
SListNode
)
+
sizeof
(
SActObj
))
*
(
SL_SIZE
(
pTable
->
pIndex
)
+
1
));
}
else
{
tlen
=
sizeof
(
SListNode
)
+
sizeof
(
SActObj
);
}
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
4a83966f
...
...
@@ -386,7 +386,7 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iter
);
assert
(
node
!=
NULL
);
SDataRow
row
=
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
node
);
SDataRow
row
=
(
SDataRow
)
SL_GET_NODE_DATA
(
node
);
TSKEY
key
=
dataRowKey
(
row
);
// first timestamp in buffer
tsdbDebug
(
"%p uid:%"
PRId64
", tid:%d check data in mem from skey:%"
PRId64
", order:%d, ts range in buf:%"
PRId64
"-%"
PRId64
", lastKey:%"
PRId64
", numOfRows:%"
PRId64
", %p"
,
...
...
@@ -408,7 +408,7 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iiter
);
assert
(
node
!=
NULL
);
SDataRow
row
=
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
node
);
SDataRow
row
=
(
SDataRow
)
SL_GET_NODE_DATA
(
node
);
TSKEY
key
=
dataRowKey
(
row
);
// first timestamp in buffer
tsdbDebug
(
"%p uid:%"
PRId64
", tid:%d check data in imem from skey:%"
PRId64
", order:%d, ts range in buf:%"
PRId64
"-%"
PRId64
", lastKey:%"
PRId64
", numOfRows:%"
PRId64
", %p"
,
...
...
@@ -438,14 +438,14 @@ static SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order
if
(
pCheckInfo
->
iter
)
{
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iter
);
if
(
node
!=
NULL
)
{
rmem
=
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
node
);
rmem
=
(
SDataRow
)
SL_GET_NODE_DATA
(
node
);
}
}
if
(
pCheckInfo
->
iiter
)
{
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iiter
);
if
(
node
!=
NULL
)
{
rimem
=
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
node
);
rimem
=
(
SDataRow
)
SL_GET_NODE_DATA
(
node
);
}
}
...
...
@@ -1358,8 +1358,8 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
* copy them all to result buffer, since it may be overlapped with file data block.
*/
if
(
node
==
NULL
||
((
dataRowKey
(
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
node
))
>
pQueryHandle
->
window
.
ekey
)
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
((
dataRowKey
(
*
(
SDataRow
*
)
SL_GET_NODE_DATA
(
node
))
<
pQueryHandle
->
window
.
ekey
)
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
((
dataRowKey
(
(
SDataRow
)
SL_GET_NODE_DATA
(
node
))
>
pQueryHandle
->
window
.
ekey
)
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
((
dataRowKey
(
(
SDataRow
)
SL_GET_NODE_DATA
(
node
))
<
pQueryHandle
->
window
.
ekey
)
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
// no data in cache or data in cache is greater than the ekey of time window, load data from file block
if
(
cur
->
win
.
skey
==
TSKEY_INITIAL_VAL
)
{
cur
->
win
.
skey
=
tsArray
[
pos
];
...
...
@@ -1864,9 +1864,9 @@ static int32_t getAllTableList(STable* pSuperTable, SArray* list) {
while
(
tSkipListIterNext
(
iter
))
{
SSkipListNode
*
pNode
=
tSkipListIterGet
(
iter
);
STable
*
*
pTable
=
(
STable
*
*
)
SL_GET_NODE_DATA
((
SSkipListNode
*
)
pNode
);
STable
*
pTable
=
(
STable
*
)
SL_GET_NODE_DATA
((
SSkipListNode
*
)
pNode
);
STableKeyInfo
info
=
{.
pTable
=
*
pTable
,
.
lastKey
=
TSKEY_INITIAL_VAL
};
STableKeyInfo
info
=
{.
pTable
=
pTable
,
.
lastKey
=
TSKEY_INITIAL_VAL
};
taosArrayPush
(
list
,
&
info
);
}
...
...
@@ -2434,7 +2434,7 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
static
bool
indexedNodeFilterFp
(
const
void
*
pNode
,
void
*
param
)
{
tQueryInfo
*
pInfo
=
(
tQueryInfo
*
)
param
;
STable
*
pTable
=
*
(
STable
*
*
)(
SL_GET_NODE_DATA
((
SSkipListNode
*
)
pNode
));
STable
*
pTable
=
(
STable
*
)(
SL_GET_NODE_DATA
((
SSkipListNode
*
)
pNode
));
char
*
val
=
NULL
;
...
...
src/util/inc/tskiplist.h
浏览文件 @
4a83966f
...
...
@@ -30,43 +30,27 @@ extern "C" {
// 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
#define SL_UPDATE_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert
// For thread safety setting
#define SL_THREAD_SAFE (uint8_t)0x4
typedef
char
*
SSkipListKey
;
typedef
char
*
(
*
__sl_key_fn_t
)(
const
void
*
);
/**
* the skip list node is located in a consecutive memory area,
* the format of skip list node is as follows:
* +------------+-----------------------+------------------------+-----+------+
* | node level | forward pointer array | backward pointer array | key | data |
* +------------+-----------------------+------------------------+-----+------+
*/
typedef
struct
SSkipListNode
{
uint8_t
level
;
uint8_t
flags
;
void
*
pData
;
struct
SSkipListNode
*
forwards
[];
}
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)]
#define SL_GET_BACKWARD_POINTER(n, _l) \
((SSkipListNode **)((char *)(n) + sizeof(SSkipListNode) + ((n)->level) * POINTER_BYTES))[(_l)]
#define SL_GET_NODE_DATA(n) ((char *)(n) + SL_NODE_HEADER_SIZE((n)->level))
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn(SL_GET_NODE_DATA(n)))
#define SL_GET_SL_MIN_KEY(s) (SL_GET_NODE_KEY((s), SL_GET_FORWARD_POINTER((s)->pHead, 0)))
#define SL_GET_SL_MAX_KEY(s) (SL_GET_NODE_KEY((s), SL_GET_BACKWARD_POINTER((s)->pTail, 0)))
#define SL_NODE_DELETED_FLAG (uint8_t)0x1
#define SL_GET_NODE_LEVEL(n) *(uint8_t *)((n))
#define SL_GET_SIZE(s) (s)->size
#define SL_GET_TSIZE(s) (s)->tsize
#define SL_GET_NODE_DATA(n) (n)->pData
#define SL_IS_NODE_DELETED(n) ((n)->flags & SL_NODE_DELETED_FLAG)
#define SL_SET_NODE_DELETED(n) (n)->flags |= SL_NODE_DELETED_FLAG
#define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)]
#define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)]
/*
* @version 0.3
...
...
@@ -116,13 +100,6 @@ typedef struct tSkipListState {
uint64_t
nTotalElapsedTimeForInsert
;
}
tSkipListState
;
typedef
struct
SSkipListKeyInfo
{
uint8_t
dupKey
:
2
;
// if allow duplicated key in the skip list
uint8_t
type
:
4
;
// key type
uint8_t
freeNode
:
2
;
// free node when destroy the skiplist
uint8_t
len
;
// maximum key length, used in case of string key
}
SSkipListKeyInfo
;
typedef
struct
SSkipList
{
__compar_fn_t
comparFn
;
__sl_key_fn_t
keyFn
;
...
...
@@ -132,8 +109,8 @@ typedef struct SSkipList {
uint8_t
flags
;
uint8_t
type
;
// static info above
uint8_t
level
;
uint32_t
size
;
//
not including duplicate keys
uint32_t
tsize
;
//
including duplicate keys
uint32_t
size
;
//
semantic meaning of size
uint32_t
tsize
;
//
# of all skiplist nodes in this SL
SSkipListNode
*
pHead
;
// point to the first element
SSkipListNode
*
pTail
;
// point to the last element
#if SKIP_LIST_RECORD_PERFORMANCE
...
...
@@ -141,12 +118,6 @@ typedef struct SSkipList {
#endif
}
SSkipList
;
/*
* iterate the skiplist
* this will cause the multi-thread problem, when the skiplist is destroyed, the iterate may
* continue iterating the skiplist, so add the reference count for skiplist
* TODO add the ref for skip list when one iterator is created
*/
typedef
struct
SSkipListIterator
{
SSkipList
*
pSkipList
;
SSkipListNode
*
cur
;
...
...
@@ -154,116 +125,25 @@ typedef struct SSkipListIterator {
int32_t
order
;
// order of the iterator
}
SSkipListIterator
;
/**
*
* @param nMaxLevel maximum skip list level
* @param keyType type of key
* @param dupKey allow the duplicated key in the skip list
* @return
*/
SSkipList
*
tSkipListCreate
(
uint8_t
nMaxLevel
,
uint8_t
keyType
,
uint16_t
keyLen
,
uint8_t
flags
,
__sl_key_fn_t
fn
);
/**
*
* @param pSkipList
* @return NULL will always be returned
*/
void
*
tSkipListDestroy
(
SSkipList
*
pSkipList
);
/**
*
* @param pSkipList
* @param level
* @param headSize
*/
void
tSkipListNewNodeInfo
(
SSkipList
*
pSkipList
,
int32_t
*
level
,
int32_t
*
headSize
);
/**
* put the data into the skiplist
* If failed, NULL will be returned, otherwise, the pNode will be returned.
*
* @param pSkipList
* @param pData
* @param dataLen
* @return
*/
SSkipListNode
*
tSkipListPut
(
SSkipList
*
pSkipList
,
void
*
pData
,
int
dataLen
);
/**
* put the skip list node into the skip list.
* If failed, NULL will be returned, otherwise, the pNode will be returned.
*
* @param pSkipList
* @param pNode
* @return
*/
SSkipListNode
*
tSkipListPutNode
(
SSkipList
*
pSkipList
,
SSkipListNode
*
pNode
);
/**
* get *all* nodes which key are equivalent to pKey
*
* @param pSkipList
* @param pKey
* @return
*/
SArray
*
tSkipListGet
(
SSkipList
*
pSkipList
,
SSkipListKey
pKey
);
/**
* display skip list of the given level, for debug purpose only
* @param pSkipList
* @param nlevel
*/
#define SL_IS_THREAD_SAFE(s) (((s)->flags) & SL_THREAD_SAFE)
#define SL_DUP_MODE(s) (((s)->flags) & ((((uint8_t)1) << 2) - 1))
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn((n)->pData))
#define SL_GET_MIN_KEY(s) SL_GET_NODE_KEY(s, SL_NODE_GET_FORWARD_POINTER((s)->pHead, 0))
#define SL_GET_MAX_KEY(s) SL_GET_NODE_KEY((s), SL_NODE_GET_BACKWARD_POINTER((s)->pTail, 0))
#define SL_SIZE(s) (s)->size
#define SL_TSIZE(s) (s)->tsize
SSkipList
*
tSkipListCreate
(
uint8_t
nMaxLevel
,
uint8_t
keyType
,
uint16_t
keyLen
,
uint8_t
flags
,
__sl_key_fn_t
fn
);
void
tSkipListDestroy
(
SSkipList
*
pSkipList
);
SSkipListNode
*
tSkipListPut
(
SSkipList
*
pSkipList
,
void
*
pData
);
SArray
*
tSkipListGet
(
SSkipList
*
pSkipList
,
SSkipListKey
pKey
);
void
tSkipListPrint
(
SSkipList
*
pSkipList
,
int16_t
nlevel
);
/**
* create skiplist iterator
* @param pSkipList
* @return
*/
SSkipListIterator
*
tSkipListCreateIter
(
SSkipList
*
pSkipList
);
/**
* create skip list iterator from the given node and specified the order
* @param pSkipList
* @param pNode start position, instead of the first node in skip list
* @param order traverse order of the iterator
* @return
*/
SSkipListIterator
*
tSkipListCreateIterFromVal
(
SSkipList
*
pSkipList
,
const
char
*
val
,
int32_t
type
,
int32_t
order
);
/**
* forward the skip list iterator
* @param iter
* @return
*/
SSkipListIterator
*
tSkipListCreateIterFromVal
(
SSkipList
*
pSkipList
,
const
char
*
val
,
int32_t
type
,
int32_t
order
);
bool
tSkipListIterNext
(
SSkipListIterator
*
iter
);
/**
* get the element of skip list node
* @param iter
* @return
*/
SSkipListNode
*
tSkipListIterGet
(
SSkipListIterator
*
iter
);
/**
* destroy the skip list node
* @param iter
* @return
*/
void
*
tSkipListDestroyIter
(
SSkipListIterator
*
iter
);
/*
* remove nodes of the pKey value.
* If more than one node has the same value, all will be removed
*
* @Return
* the count of removed nodes
*/
SSkipListNode
*
tSkipListIterGet
(
SSkipListIterator
*
iter
);
void
*
tSkipListDestroyIter
(
SSkipListIterator
*
iter
);
uint32_t
tSkipListRemove
(
SSkipList
*
pSkipList
,
SSkipListKey
key
);
/*
* remove the specified node in parameters
*/
void
tSkipListRemoveNode
(
SSkipList
*
pSkipList
,
SSkipListNode
*
pNode
);
#ifdef __cplusplus
...
...
src/util/src/tskiplist.c
浏览文件 @
4a83966f
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录