Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN产品汪
TDengine
提交
9f1996f4
T
TDengine
项目概览
CSDN产品汪
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
5
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9f1996f4
编写于
3月 07, 2020
作者:
H
hzcheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make code compile
上级
3562f612
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
1055 addition
and
6 deletion
+1055
-6
src/client/src/tscAst.c
src/client/src/tscAst.c
+1
-1
src/util/inc/sskiplist.h
src/util/inc/sskiplist.h
+205
-0
src/util/src/sskiplist.c
src/util/src/sskiplist.c
+844
-0
src/util/src/thistogram.c
src/util/src/thistogram.c
+5
-5
未找到文件。
src/client/src/tscAst.c
浏览文件 @
9f1996f4
...
...
@@ -21,7 +21,7 @@
#include "tscSyntaxtreefunction.h"
#include "tschemautil.h"
#include "taosdef.h"
#include "
t
skiplist.h"
#include "
s
skiplist.h"
#include "tsqldef.h"
#include "tsqlfunction.h"
#include "tstoken.h"
...
...
src/util/inc/sskiplist.h
0 → 100644
浏览文件 @
9f1996f4
/*
* 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 TBASE_TSKIPLIST_H
#define TBASE_TSKIPLIST_H
#ifdef __cplusplus
extern
"C"
{
#endif
#define MAX_SKIP_LIST_LEVEL 20
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include "os.h"
#include "ttypes.h"
/*
* key of each node
* todo move to as the global structure in all search codes...
*/
const
static
size_t
SKIP_LIST_STR_KEY_LENGTH_THRESHOLD
=
15
;
typedef
tVariant
tSkipListKey
;
typedef
enum
tSkipListPointQueryType
{
INCLUDE_POINT_QUERY
,
EXCLUDE_POINT_QUERY
,
}
tSkipListPointQueryType
;
typedef
struct
tSkipListNode
{
uint16_t
nLevel
;
char
*
pData
;
struct
tSkipListNode
**
pForward
;
struct
tSkipListNode
**
pBackward
;
tSkipListKey
key
;
}
tSkipListNode
;
/*
* @version 0.2
* @date 2017/11/12
* the simple version of SkipList.
* for multi-thread safe purpose, we employ pthread_rwlock_t to guarantee to generate
* deterministic result. Later, we will remove the lock in SkipList to further
* enhance the performance. In this case, one should use the concurrent skip list (by
* using michael-scott algorithm) instead of this simple version in a multi-thread
* environment, to achieve higher performance of read/write operations.
*
* Note: Duplicated primary key situation.
* In case of duplicated primary key, two ways can be employed to handle this situation:
* 1. add as normal insertion with out special process.
* 2. add an overflow pointer at each list node, all nodes with the same key will be added
* in the overflow pointer. In this case, the total steps of each search will be reduced significantly.
* Currently, we implement the skip list in a line with the first means, maybe refactor it soon.
*
* Memory consumption: the memory alignment causes many memory wasted. So, employ a memory
* pool will significantly reduce the total memory consumption, as well as the calloc/malloc operation costs.
*
* 3. use the iterator pattern to refactor all routines to make it more clean
*/
// state struct, record following information:
// number of links in each level.
// avg search steps, for latest 1000 queries
// avg search rsp time, for latest 1000 queries
// total memory size
typedef
struct
tSkipListState
{
// in bytes, sizeof(tSkipList)+sizeof(tSkipListNode)*tSkipList->nSize
uint64_t
nTotalMemSize
;
uint64_t
nLevelNodeCnt
[
MAX_SKIP_LIST_LEVEL
];
uint64_t
queryCount
;
// total query count
/*
* only record latest 1000 queries
* when the value==1000, = 0,
* nTotalStepsForQueries = 0,
* nTotalElapsedTimeForQueries = 0
*/
uint64_t
nRecQueries
;
uint16_t
nTotalStepsForQueries
;
uint64_t
nTotalElapsedTimeForQueries
;
uint16_t
nInsertObjs
;
uint16_t
nTotalStepsForInsert
;
uint64_t
nTotalElapsedTimeForInsert
;
}
tSkipListState
;
typedef
struct
tSkipList
{
tSkipListNode
pHead
;
uint64_t
nSize
;
uint16_t
nMaxLevel
;
uint16_t
nLevel
;
uint16_t
keyType
;
uint16_t
nMaxKeyLen
;
__compar_fn_t
comparator
;
pthread_rwlock_t
lock
;
// will be removed soon
tSkipListState
state
;
// skiplist state
}
tSkipList
;
/*
* 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 skiplist when one iterator is created
*/
typedef
struct
SSkipListIterator
{
tSkipList
*
pSkipList
;
tSkipListNode
*
cur
;
int64_t
num
;
}
SSkipListIterator
;
/*
* query condition structure to denote the range query
* todo merge the point query cond with range query condition
*/
typedef
struct
tSKipListQueryCond
{
// when the upper bounding == lower bounding, it is a point query
tSkipListKey
lowerBnd
;
tSkipListKey
upperBnd
;
int32_t
lowerBndRelOptr
;
// relation operator to denote if lower bound is
int32_t
upperBndRelOptr
;
// included or not
}
tSKipListQueryCond
;
tSkipList
*
SSkipListCreate
(
int16_t
nMaxLevel
,
int16_t
keyType
,
int16_t
nMaxKeyLen
);
void
*
SSkipListDestroy
(
tSkipList
*
pSkipList
);
// create skip list key
tSkipListKey
SSkipListCreateKey
(
int32_t
type
,
char
*
val
,
size_t
keyLength
);
// destroy skip list key
void
tSkipListDestroyKey
(
tSkipListKey
*
pKey
);
// put data into skiplist
tSkipListNode
*
SSkipListPut
(
tSkipList
*
pSkipList
,
void
*
pData
,
tSkipListKey
*
pKey
,
int32_t
insertIdenticalKey
);
/*
* get only *one* node of which key is equalled to pKey, even there are more
* than one nodes are of the same key
*/
tSkipListNode
*
tSkipListGetOne
(
tSkipList
*
pSkipList
,
tSkipListKey
*
pKey
);
/*
* get all data with the same keys
*/
int32_t
tSkipListGets
(
tSkipList
*
pSkipList
,
tSkipListKey
*
pKey
,
tSkipListNode
***
pRes
);
int32_t
tSkipListIterateList
(
tSkipList
*
pSkipList
,
tSkipListNode
***
pRes
,
bool
(
*
fp
)(
tSkipListNode
*
,
void
*
),
void
*
param
);
/*
* remove only one node of the pKey value.
* If more than one node has the same value, any one will be removed
*
* @Return
* true: one node has been removed
* false: no node has been removed
*/
bool
tSkipListRemove
(
tSkipList
*
pSkipList
,
tSkipListKey
*
pKey
);
/*
* remove the specified node in parameters
*/
void
tSkipListRemoveNode
(
tSkipList
*
pSkipList
,
tSkipListNode
*
pNode
);
// for debug purpose only
void
SSkipListPrint
(
tSkipList
*
pSkipList
,
int16_t
nlevel
);
/*
* range query & single point query function
*/
int32_t
tSkipListQuery
(
tSkipList
*
pSkipList
,
tSKipListQueryCond
*
pQueryCond
,
tSkipListNode
***
pResult
);
/*
* include/exclude point query
*/
int32_t
tSkipListPointQuery
(
tSkipList
*
pSkipList
,
tSkipListKey
*
pKey
,
int32_t
numOfKey
,
tSkipListPointQueryType
type
,
tSkipListNode
***
pResult
);
int32_t
tSkipListIteratorReset
(
tSkipList
*
pSkipList
,
SSkipListIterator
*
iter
);
bool
tSkipListIteratorNext
(
SSkipListIterator
*
iter
);
tSkipListNode
*
tSkipListIteratorGet
(
SSkipListIterator
*
iter
);
#ifdef __cplusplus
}
#endif
#endif // TBASE_TSKIPLIST_H
src/util/src/sskiplist.c
0 → 100644
浏览文件 @
9f1996f4
此差异已折叠。
点击以展开。
src/util/src/thistogram.c
浏览文件 @
9f1996f4
...
...
@@ -126,7 +126,7 @@ SHistogramInfo* tHistogramCreate(int32_t numOfEntries) {
SHistogramInfo
*
pHisto
=
malloc
(
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
(
numOfEntries
+
1
));
#if !defined(USE_ARRAYLIST)
pHisto
->
pList
=
t
SkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
pHisto
->
pList
=
S
SkipListCreate
(
MAX_SKIP_LIST_LEVEL
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
SInsertSupporter
*
pss
=
malloc
(
sizeof
(
SInsertSupporter
));
pss
->
numOfEntries
=
pHisto
->
maxEntries
;
pss
->
pSkipList
=
pHisto
->
pList
;
...
...
@@ -185,7 +185,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
SHistBin
*
entry
=
calloc
(
1
,
sizeof
(
SHistBin
));
entry
->
val
=
val
;
tSkipListNode
*
pResNode
=
t
SkipListPut
((
*
pHisto
)
->
pList
,
entry
,
&
key
,
0
);
tSkipListNode
*
pResNode
=
S
SkipListPut
((
*
pHisto
)
->
pList
,
entry
,
&
key
,
0
);
SHistBin
*
pEntry1
=
(
SHistBin
*
)
pResNode
->
pData
;
pEntry1
->
index
=
-
1
;
...
...
@@ -239,7 +239,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
// set the right value for loser-tree
assert
((
*
pHisto
)
->
pLoserTree
!=
NULL
);
if
(
!
(
*
pHisto
)
->
ordered
)
{
t
SkipListPrint
((
*
pHisto
)
->
pList
,
1
);
S
SkipListPrint
((
*
pHisto
)
->
pList
,
1
);
SLoserTreeInfo
*
pTree
=
(
*
pHisto
)
->
pLoserTree
;
tSkipListNode
*
pHead
=
(
*
pHisto
)
->
pList
->
pHead
.
pForward
[
0
];
...
...
@@ -281,7 +281,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
printf
(
"delta is:%lf
\n
"
,
pEntry1
->
delta
);
t
SkipListPrint
((
*
pHisto
)
->
pList
,
1
);
S
SkipListPrint
((
*
pHisto
)
->
pList
,
1
);
/* the chosen node */
tSkipListNode
*
pNode
=
(
*
pHisto
)
->
pLoserTree
->
pNode
[
0
].
pData
;
...
...
@@ -319,7 +319,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
tLoserTreeAdjust
(
pTree
,
pEntry
->
index
+
pTree
->
numOfEntries
);
// remove the next node in skiplist
tSkipListRemoveNode
((
*
pHisto
)
->
pList
,
pNext
);
t
SkipListPrint
((
*
pHisto
)
->
pList
,
1
);
S
SkipListPrint
((
*
pHisto
)
->
pList
,
1
);
tLoserTreeDisplay
((
*
pHisto
)
->
pLoserTree
);
}
else
{
// add to heap
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录