Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c56743d8
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看板
提交
c56743d8
编写于
3月 18, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into feature/tq
上级
cc0c0293
bb913611
变更
77
展开全部
隐藏空白更改
内联
并排
Showing
77 changed file
with
4863 addition
and
2789 deletion
+4863
-2789
cmake/cmake.options
cmake/cmake.options
+7
-0
cmake/iconv_CMakeLists.txt.in
cmake/iconv_CMakeLists.txt.in
+12
-0
contrib/CMakeLists.txt
contrib/CMakeLists.txt
+15
-10
include/common/tmsg.h
include/common/tmsg.h
+8
-15
include/common/ttokendef.h
include/common/ttokendef.h
+141
-122
include/common/ttypes.h
include/common/ttypes.h
+1
-1
include/common/tvariant.h
include/common/tvariant.h
+1
-1
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+25
-0
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+4
-0
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+1
-1
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+3
-0
include/libs/parser/parser.h
include/libs/parser/parser.h
+1
-0
include/libs/qcom/query.h
include/libs/qcom/query.h
+4
-0
include/os/osFile.h
include/os/osFile.h
+1
-30
include/os/osString.h
include/os/osString.h
+30
-10
include/util/taoserror.h
include/util/taoserror.h
+1
-0
include/util/tcompare.h
include/util/tcompare.h
+1
-1
include/util/tdef.h
include/util/tdef.h
+1
-1
include/util/tjson.h
include/util/tjson.h
+2
-0
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+2
-1
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+2
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+4
-5
source/client/src/tmq.c
source/client/src/tmq.c
+8
-22
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+7
-3
source/common/src/tvariant.c
source/common/src/tvariant.c
+22
-22
source/dnode/vnode/src/inc/tsdbDBDef.h
source/dnode/vnode/src/inc/tsdbDBDef.h
+3
-2
source/dnode/vnode/src/meta/metaBDBImpl.c
source/dnode/vnode/src/meta/metaBDBImpl.c
+1
-1
source/dnode/vnode/src/tq/tqRead.c
source/dnode/vnode/src/tq/tqRead.c
+7
-1
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+45
-39
source/dnode/vnode/src/vnd/vnodeWrite.c
source/dnode/vnode/src/vnd/vnodeWrite.c
+3
-0
source/dnode/vnode/test/tsdbSmaTest.cpp
source/dnode/vnode/test/tsdbSmaTest.cpp
+27
-23
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+11
-2
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+2
-3
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+256
-11
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+15
-2
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+19
-2
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+113
-16
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+114
-2
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+2
-2
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+1
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+119
-1
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+8
-6
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+2090
-1690
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+1
-2
source/libs/parser/test/parserAstTest.cpp
source/libs/parser/test/parserAstTest.cpp
+17
-0
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+282
-175
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+8
-2
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+4
-4
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+1
-1
source/libs/sync/inc/syncCommit.h
source/libs/sync/inc/syncCommit.h
+60
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+0
-1
source/libs/sync/inc/syncOnMessage.h
source/libs/sync/inc/syncOnMessage.h
+40
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+124
-17
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+2
-1
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+74
-13
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+50
-9
source/libs/sync/src/syncOnMessage.c
source/libs/sync/src/syncOnMessage.c
+40
-0
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+28
-0
source/libs/sync/test/syncEncodeTest.cpp
source/libs/sync/test/syncEncodeTest.cpp
+10
-42
source/libs/sync/test/syncReplicateTest.cpp
source/libs/sync/test/syncReplicateTest.cpp
+126
-0
source/libs/sync/test/syncWriteTest.cpp
source/libs/sync/test/syncWriteTest.cpp
+180
-0
source/libs/tfs/src/tfs.c
source/libs/tfs/src/tfs.c
+2
-1
source/os/CMakeLists.txt
source/os/CMakeLists.txt
+6
-1
source/os/src/osFile.c
source/os/src/osFile.c
+17
-0
source/os/src/osLocale.c
source/os/src/osLocale.c
+1
-1
source/os/src/osString.c
source/os/src/osString.c
+73
-277
source/util/src/tcompare.c
source/util/src/tcompare.c
+9
-9
source/util/src/tjson.c
source/util/src/tjson.c
+24
-1
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+3
-0
tests/script/tsim/insert/basic1.sim
tests/script/tsim/insert/basic1.sim
+94
-0
tests/script/tsim/query/interval-offset.sim
tests/script/tsim/query/interval-offset.sim
+292
-0
tests/script/tsim/query/interval.sim
tests/script/tsim/query/interval.sim
+131
-155
tools/shell/src/backup/shellDarwin.c
tools/shell/src/backup/shellDarwin.c
+3
-4
tools/shell/src/shellCommand.c
tools/shell/src/shellCommand.c
+13
-15
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+4
-4
tools/shell/src/shellLinux.c
tools/shell/src/shellLinux.c
+3
-4
未找到文件。
cmake/cmake.options
浏览文件 @
c56743d8
...
@@ -18,6 +18,13 @@ IF(${TD_WINDOWS})
...
@@ -18,6 +18,13 @@ IF(${TD_WINDOWS})
ON
ON
)
)
MESSAGE("build iconv Win32")
option(
BUILD_WITH_ICONV
"If build iconv on Windows"
ON
)
ENDIF ()
ENDIF ()
IF(${TD_LINUX} MATCHES TRUE)
IF(${TD_LINUX} MATCHES TRUE)
...
...
cmake/iconv_CMakeLists.txt.in
0 → 100644
浏览文件 @
c56743d8
# iconv
ExternalProject_Add(iconv
GIT_REPOSITORY https://github.com/win-iconv/win-iconv.git
GIT_TAG v0.0.8
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/iconv"
BINARY_DIR ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
\ No newline at end of file
contrib/CMakeLists.txt
浏览文件 @
c56743d8
...
@@ -83,6 +83,11 @@ if(${BUILD_WITH_NURAFT})
...
@@ -83,6 +83,11 @@ if(${BUILD_WITH_NURAFT})
cat
(
"
${
CMAKE_SUPPORT_DIR
}
/nuraft_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
cat
(
"
${
CMAKE_SUPPORT_DIR
}
/nuraft_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
endif
(
${
BUILD_WITH_NURAFT
}
)
endif
(
${
BUILD_WITH_NURAFT
}
)
# iconv
if
(
${
BUILD_WITH_ICONV
}
)
cat
(
"
${
CMAKE_SUPPORT_DIR
}
/iconv_CMakeLists.txt.in"
${
CONTRIB_TMP_FILE
}
)
endif
(
${
BUILD_WITH_ICONV
}
)
# download dependencies
# download dependencies
configure_file
(
${
CONTRIB_TMP_FILE
}
"
${
CMAKE_CONTRIB_DIR
}
/deps-download/CMakeLists.txt"
)
configure_file
(
${
CONTRIB_TMP_FILE
}
"
${
CMAKE_CONTRIB_DIR
}
/deps-download/CMakeLists.txt"
)
execute_process
(
COMMAND
"
${
CMAKE_COMMAND
}
"
-G
"
${
CMAKE_GENERATOR
}
"
.
execute_process
(
COMMAND
"
${
CMAKE_COMMAND
}
"
-G
"
${
CMAKE_GENERATOR
}
"
.
...
@@ -208,14 +213,10 @@ endif(${BUILD_WITH_TRAFT})
...
@@ -208,14 +213,10 @@ endif(${BUILD_WITH_TRAFT})
# LIBUV
# LIBUV
if
(
${
BUILD_WITH_UV
}
)
if
(
${
BUILD_WITH_UV
}
)
if
(
NOT
${
CMAKE_SYSTEM_NAME
}
MATCHES
"Windows"
)
if
(
${
TD_WINDOWS
}
)
MESSAGE
(
"Windows need set no-sign-compare"
)
file
(
READ
"libuv/include/uv.h"
CONTENTS
)
add_compile_options
(
-Wno-sign-compare
)
string
(
REGEX REPLACE
"/([
\r
]*)
\n
struct uv_tcp_s {"
"/
\\
1
\n
typedef BOOL (PASCAL *LPFN_CONNECTEX) (SOCKET s, const struct sockaddr* name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength,LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped);
\\
1
\n
struct uv_tcp_s {"
CONTENTS_NEW
"
${
CONTENTS
}
"
)
endif
()
file
(
WRITE
"libuv/include/uv.h"
"
${
CONTENTS_NEW
}
"
)
if
(
${
CMAKE_SYSTEM_NAME
}
MATCHES
"Windows"
)
file
(
READ
"libuv/include/uv.h"
CONTENTS
)
string
(
REGEX REPLACE
"/([
\r
]*)
\n
struct uv_tcp_s {"
"/
\\
1
\n
typedef BOOL (PASCAL *LPFN_CONNECTEX) (SOCKET s, const struct sockaddr* name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength,LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped);
\\
1
\n
struct uv_tcp_s {"
CONTENTS_NEW
"
${
CONTENTS
}
"
)
file
(
WRITE
"libuv/include/uv.h"
"
${
CONTENTS_NEW
}
"
)
endif
()
endif
()
add_subdirectory
(
libuv
)
add_subdirectory
(
libuv
)
endif
(
${
BUILD_WITH_UV
}
)
endif
(
${
BUILD_WITH_UV
}
)
...
@@ -249,10 +250,14 @@ endif(${BUILD_WITH_SQLITE})
...
@@ -249,10 +250,14 @@ endif(${BUILD_WITH_SQLITE})
# pthread
# pthread
if
(
${
BUILD_PTHREAD
}
)
if
(
${
BUILD_PTHREAD
}
)
ADD_DEFINITIONS
(
"-DPTW32_STATIC_LIB"
)
add_definitions
(
-DPTW32_STATIC_LIB
)
add_subdirectory
(
pthread
-win32
)
add_subdirectory
(
pthread
)
endif
(
${
BUILD_PTHREAD
}
)
endif
(
${
BUILD_PTHREAD
}
)
# iconv
if
(
${
BUILD_WITH_ICONV
}
)
add_subdirectory
(
iconv
)
endif
(
${
BUILD_WITH_ICONV
}
)
# ================================================================================================
# ================================================================================================
# Build test
# Build test
...
...
include/common/tmsg.h
浏览文件 @
c56743d8
...
@@ -111,15 +111,16 @@ typedef enum _mgmt_table {
...
@@ -111,15 +111,16 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_MAX
,
TSDB_MGMT_TABLE_MAX
,
}
EShowType
;
}
EShowType
;
#define TSDB_ALTER_TABLE_ADD_TAG 1
#define TSDB_ALTER_TABLE_ADD_TAG 1
#define TSDB_ALTER_TABLE_DROP_TAG 2
#define TSDB_ALTER_TABLE_DROP_TAG 2
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME 3
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME 3
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4
#define TSDB_ALTER_TABLE_ADD_COLUMN 5
#define TSDB_ALTER_TABLE_ADD_COLUMN 5
#define TSDB_ALTER_TABLE_DROP_COLUMN 6
#define TSDB_ALTER_TABLE_DROP_COLUMN 6
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES 7
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES 7
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES 8
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES 8
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS 9
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME 10
#define TSDB_FILL_NONE 0
#define TSDB_FILL_NONE 0
#define TSDB_FILL_NULL 1
#define TSDB_FILL_NULL 1
...
@@ -2052,27 +2053,19 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
...
@@ -2052,27 +2053,19 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
sliding
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
sliding
);
if
(
pSma
->
exprLen
>
0
)
{
if
(
pSma
->
exprLen
>
0
)
{
pSma
->
expr
=
(
char
*
)
calloc
(
pSma
->
exprLen
,
1
);
if
((
buf
=
taosDecodeString
(
buf
,
&
pSma
->
expr
))
==
NULL
)
{
if
(
pSma
->
expr
!=
NULL
)
{
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
expr
);
}
else
{
tdDestroyTSma
(
pSma
);
tdDestroyTSma
(
pSma
);
return
NULL
;
return
NULL
;
}
}
}
else
{
}
else
{
pSma
->
expr
=
NULL
;
pSma
->
expr
=
NULL
;
}
}
if
(
pSma
->
tagsFilterLen
>
0
)
{
if
(
pSma
->
tagsFilterLen
>
0
)
{
pSma
->
tagsFilter
=
(
char
*
)
calloc
(
pSma
->
tagsFilterLen
,
1
);
if
((
buf
=
taosDecodeString
(
buf
,
&
pSma
->
tagsFilter
))
==
NULL
)
{
if
(
pSma
->
tagsFilter
!=
NULL
)
{
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
tagsFilter
);
}
else
{
tdDestroyTSma
(
pSma
);
tdDestroyTSma
(
pSma
);
return
NULL
;
return
NULL
;
}
}
}
else
{
}
else
{
pSma
->
tagsFilter
=
NULL
;
pSma
->
tagsFilter
=
NULL
;
}
}
...
...
include/common/ttokendef.h
浏览文件 @
c56743d8
...
@@ -34,128 +34,147 @@
...
@@ -34,128 +34,147 @@
#define TK_NK_REM 16
#define TK_NK_REM 16
#define TK_NK_CONCAT 17
#define TK_NK_CONCAT 17
#define TK_CREATE 18
#define TK_CREATE 18
#define TK_USER 19
#define TK_ACCOUNT 19
#define TK_PASS 20
#define TK_NK_ID 20
#define TK_NK_STRING 21
#define TK_PASS 21
#define TK_ALTER 22
#define TK_NK_STRING 22
#define TK_PRIVILEGE 23
#define TK_ALTER 23
#define TK_DROP 24
#define TK_PPS 24
#define TK_SHOW 25
#define TK_TSERIES 25
#define TK_USERS 26
#define TK_STORAGE 26
#define TK_DNODE 27
#define TK_STREAMS 27
#define TK_PORT 28
#define TK_QTIME 28
#define TK_NK_INTEGER 29
#define TK_DBS 29
#define TK_DNODES 30
#define TK_USERS 30
#define TK_NK_ID 31
#define TK_CONNS 31
#define TK_NK_IPTOKEN 32
#define TK_STATE 32
#define TK_QNODE 33
#define TK_USER 33
#define TK_ON 34
#define TK_PRIVILEGE 34
#define TK_QNODES 35
#define TK_DROP 35
#define TK_DATABASE 36
#define TK_SHOW 36
#define TK_DATABASES 37
#define TK_DNODE 37
#define TK_USE 38
#define TK_PORT 38
#define TK_IF 39
#define TK_NK_INTEGER 39
#define TK_NOT 40
#define TK_DNODES 40
#define TK_EXISTS 41
#define TK_NK_IPTOKEN 41
#define TK_BLOCKS 42
#define TK_LOCAL 42
#define TK_CACHE 43
#define TK_QNODE 43
#define TK_CACHELAST 44
#define TK_ON 44
#define TK_COMP 45
#define TK_QNODES 45
#define TK_DAYS 46
#define TK_DATABASE 46
#define TK_FSYNC 47
#define TK_DATABASES 47
#define TK_MAXROWS 48
#define TK_USE 48
#define TK_MINROWS 49
#define TK_IF 49
#define TK_KEEP 50
#define TK_NOT 50
#define TK_PRECISION 51
#define TK_EXISTS 51
#define TK_QUORUM 52
#define TK_BLOCKS 52
#define TK_REPLICA 53
#define TK_CACHE 53
#define TK_TTL 54
#define TK_CACHELAST 54
#define TK_WAL 55
#define TK_COMP 55
#define TK_VGROUPS 56
#define TK_DAYS 56
#define TK_SINGLE_STABLE 57
#define TK_FSYNC 57
#define TK_STREAM_MODE 58
#define TK_MAXROWS 58
#define TK_TABLE 59
#define TK_MINROWS 59
#define TK_NK_LP 60
#define TK_KEEP 60
#define TK_NK_RP 61
#define TK_PRECISION 61
#define TK_STABLE 62
#define TK_QUORUM 62
#define TK_TABLES 63
#define TK_REPLICA 63
#define TK_STABLES 64
#define TK_TTL 64
#define TK_USING 65
#define TK_WAL 65
#define TK_TAGS 66
#define TK_VGROUPS 66
#define TK_NK_DOT 67
#define TK_SINGLE_STABLE 67
#define TK_NK_COMMA 68
#define TK_STREAM_MODE 68
#define TK_COMMENT 69
#define TK_RETENTIONS 69
#define TK_BOOL 70
#define TK_FILE_FACTOR 70
#define TK_TINYINT 71
#define TK_NK_FLOAT 71
#define TK_SMALLINT 72
#define TK_TABLE 72
#define TK_INT 73
#define TK_NK_LP 73
#define TK_INTEGER 74
#define TK_NK_RP 74
#define TK_BIGINT 75
#define TK_STABLE 75
#define TK_FLOAT 76
#define TK_TABLES 76
#define TK_DOUBLE 77
#define TK_STABLES 77
#define TK_BINARY 78
#define TK_ADD 78
#define TK_TIMESTAMP 79
#define TK_COLUMN 79
#define TK_NCHAR 80
#define TK_MODIFY 80
#define TK_UNSIGNED 81
#define TK_RENAME 81
#define TK_JSON 82
#define TK_TAG 82
#define TK_VARCHAR 83
#define TK_SET 83
#define TK_MEDIUMBLOB 84
#define TK_NK_EQ 84
#define TK_BLOB 85
#define TK_USING 85
#define TK_VARBINARY 86
#define TK_TAGS 86
#define TK_DECIMAL 87
#define TK_NK_DOT 87
#define TK_SMA 88
#define TK_NK_COMMA 88
#define TK_INDEX 89
#define TK_COMMENT 89
#define TK_FULLTEXT 90
#define TK_BOOL 90
#define TK_FUNCTION 91
#define TK_TINYINT 91
#define TK_INTERVAL 92
#define TK_SMALLINT 92
#define TK_TOPIC 93
#define TK_INT 93
#define TK_AS 94
#define TK_INTEGER 94
#define TK_MNODES 95
#define TK_BIGINT 95
#define TK_NK_FLOAT 96
#define TK_FLOAT 96
#define TK_NK_BOOL 97
#define TK_DOUBLE 97
#define TK_NK_VARIABLE 98
#define TK_BINARY 98
#define TK_BETWEEN 99
#define TK_TIMESTAMP 99
#define TK_IS 100
#define TK_NCHAR 100
#define TK_NULL 101
#define TK_UNSIGNED 101
#define TK_NK_LT 102
#define TK_JSON 102
#define TK_NK_GT 103
#define TK_VARCHAR 103
#define TK_NK_LE 104
#define TK_MEDIUMBLOB 104
#define TK_NK_GE 105
#define TK_BLOB 105
#define TK_NK_NE 106
#define TK_VARBINARY 106
#define TK_NK_EQ 107
#define TK_DECIMAL 107
#define TK_LIKE 108
#define TK_SMA 108
#define TK_MATCH 109
#define TK_ROLLUP 109
#define TK_NMATCH 110
#define TK_INDEX 110
#define TK_IN 111
#define TK_FULLTEXT 111
#define TK_FROM 112
#define TK_FUNCTION 112
#define TK_JOIN 113
#define TK_INTERVAL 113
#define TK_INNER 114
#define TK_TOPIC 114
#define TK_SELECT 115
#define TK_AS 115
#define TK_DISTINCT 116
#define TK_MNODES 116
#define TK_WHERE 117
#define TK_NK_BOOL 117
#define TK_PARTITION 118
#define TK_NK_VARIABLE 118
#define TK_BY 119
#define TK_BETWEEN 119
#define TK_SESSION 120
#define TK_IS 120
#define TK_STATE_WINDOW 121
#define TK_NULL 121
#define TK_SLIDING 122
#define TK_NK_LT 122
#define TK_FILL 123
#define TK_NK_GT 123
#define TK_VALUE 124
#define TK_NK_LE 124
#define TK_NONE 125
#define TK_NK_GE 125
#define TK_PREV 126
#define TK_NK_NE 126
#define TK_LINEAR 127
#define TK_LIKE 127
#define TK_NEXT 128
#define TK_MATCH 128
#define TK_GROUP 129
#define TK_NMATCH 129
#define TK_HAVING 130
#define TK_IN 130
#define TK_ORDER 131
#define TK_FROM 131
#define TK_SLIMIT 132
#define TK_JOIN 132
#define TK_SOFFSET 133
#define TK_INNER 133
#define TK_LIMIT 134
#define TK_SELECT 134
#define TK_OFFSET 135
#define TK_DISTINCT 135
#define TK_ASC 136
#define TK_WHERE 136
#define TK_DESC 137
#define TK_PARTITION 137
#define TK_NULLS 138
#define TK_BY 138
#define TK_FIRST 139
#define TK_SESSION 139
#define TK_LAST 140
#define TK_STATE_WINDOW 140
#define TK_SLIDING 141
#define TK_FILL 142
#define TK_VALUE 143
#define TK_NONE 144
#define TK_PREV 145
#define TK_LINEAR 146
#define TK_NEXT 147
#define TK_GROUP 148
#define TK_HAVING 149
#define TK_ORDER 150
#define TK_SLIMIT 151
#define TK_SOFFSET 152
#define TK_LIMIT 153
#define TK_OFFSET 154
#define TK_ASC 155
#define TK_DESC 156
#define TK_NULLS 157
#define TK_FIRST 158
#define TK_LAST 159
#define TK_NK_SPACE 300
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
#define TK_NK_COMMENT 301
...
...
include/common/ttypes.h
浏览文件 @
c56743d8
...
@@ -27,7 +27,7 @@ extern "C" {
...
@@ -27,7 +27,7 @@ extern "C" {
typedef
int32_t
VarDataOffsetT
;
typedef
int32_t
VarDataOffsetT
;
typedef
uint32_t
TDRowLenT
;
typedef
uint32_t
TDRowLenT
;
typedef
uint8_t
TDRowValT
;
typedef
uint8_t
TDRowValT
;
typedef
uint16_t
col_id_t
;
typedef
int16_t
col_id_t
;
typedef
int8_t
col_type_t
;
typedef
int8_t
col_type_t
;
#pragma pack(push, 1)
#pragma pack(push, 1)
...
...
include/common/tvariant.h
浏览文件 @
c56743d8
...
@@ -31,7 +31,7 @@ typedef struct SVariant {
...
@@ -31,7 +31,7 @@ typedef struct SVariant {
uint64_t
u
;
uint64_t
u
;
double
d
;
double
d
;
char
*
pz
;
char
*
pz
;
wchar_t
*
wpz
;
TdUcs4
*
ucs4
;
SArray
*
arr
;
// only for 'in' query to hold value list, not value for a field
SArray
*
arr
;
// only for 'in' query to hold value list, not value for a field
};
};
}
SVariant
;
}
SVariant
;
...
...
include/libs/nodes/cmdnodes.h
浏览文件 @
c56743d8
...
@@ -127,6 +127,18 @@ typedef struct SDropSuperTableStmt {
...
@@ -127,6 +127,18 @@ typedef struct SDropSuperTableStmt {
bool
ignoreNotExists
;
bool
ignoreNotExists
;
}
SDropSuperTableStmt
;
}
SDropSuperTableStmt
;
typedef
struct
SAlterTableStmt
{
ENodeType
type
;
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
int8_t
alterType
;
char
colName
[
TSDB_COL_NAME_LEN
];
char
newColName
[
TSDB_COL_NAME_LEN
];
STableOptions
*
pOptions
;
SDataType
dataType
;
SValueNode
*
pVal
;
}
SAlterTableStmt
;
typedef
struct
SCreateUserStmt
{
typedef
struct
SCreateUserStmt
{
ENodeType
type
;
ENodeType
type
;
char
useName
[
TSDB_USER_LEN
];
char
useName
[
TSDB_USER_LEN
];
...
@@ -158,6 +170,13 @@ typedef struct SDropDnodeStmt {
...
@@ -158,6 +170,13 @@ typedef struct SDropDnodeStmt {
int32_t
port
;
int32_t
port
;
}
SDropDnodeStmt
;
}
SDropDnodeStmt
;
typedef
struct
SAlterDnodeStmt
{
ENodeType
type
;
int32_t
dnodeId
;
char
config
[
TSDB_DNODE_CONFIG_LEN
];
char
value
[
TSDB_DNODE_VALUE_LEN
];
}
SAlterDnodeStmt
;
typedef
struct
SShowStmt
{
typedef
struct
SShowStmt
{
ENodeType
type
;
ENodeType
type
;
char
dbName
[
TSDB_DB_NAME_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
...
@@ -215,6 +234,12 @@ typedef struct SDropTopicStmt {
...
@@ -215,6 +234,12 @@ typedef struct SDropTopicStmt {
bool
ignoreNotExists
;
bool
ignoreNotExists
;
}
SDropTopicStmt
;
}
SDropTopicStmt
;
typedef
struct
SAlterLocalStmt
{
ENodeType
type
;
char
config
[
TSDB_DNODE_CONFIG_LEN
];
char
value
[
TSDB_DNODE_VALUE_LEN
];
}
SAlterLocalStmt
;
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
include/libs/nodes/nodes.h
浏览文件 @
c56743d8
...
@@ -85,6 +85,7 @@ typedef enum ENodeType {
...
@@ -85,6 +85,7 @@ typedef enum ENodeType {
QUERY_NODE_DROP_TABLE_CLAUSE
,
QUERY_NODE_DROP_TABLE_CLAUSE
,
QUERY_NODE_DROP_TABLE_STMT
,
QUERY_NODE_DROP_TABLE_STMT
,
QUERY_NODE_DROP_SUPER_TABLE_STMT
,
QUERY_NODE_DROP_SUPER_TABLE_STMT
,
QUERY_NODE_ALTER_TABLE_STMT
,
QUERY_NODE_SHOW_TABLES_STMT
,
// temp
QUERY_NODE_SHOW_TABLES_STMT
,
// temp
QUERY_NODE_SHOW_STABLES_STMT
,
QUERY_NODE_SHOW_STABLES_STMT
,
QUERY_NODE_CREATE_USER_STMT
,
QUERY_NODE_CREATE_USER_STMT
,
...
@@ -94,6 +95,7 @@ typedef enum ENodeType {
...
@@ -94,6 +95,7 @@ typedef enum ENodeType {
QUERY_NODE_USE_DATABASE_STMT
,
QUERY_NODE_USE_DATABASE_STMT
,
QUERY_NODE_CREATE_DNODE_STMT
,
QUERY_NODE_CREATE_DNODE_STMT
,
QUERY_NODE_DROP_DNODE_STMT
,
QUERY_NODE_DROP_DNODE_STMT
,
QUERY_NODE_ALTER_DNODE_STMT
,
QUERY_NODE_SHOW_DNODES_STMT
,
QUERY_NODE_SHOW_DNODES_STMT
,
QUERY_NODE_SHOW_VGROUPS_STMT
,
QUERY_NODE_SHOW_VGROUPS_STMT
,
QUERY_NODE_SHOW_MNODES_STMT
,
QUERY_NODE_SHOW_MNODES_STMT
,
...
@@ -104,6 +106,7 @@ typedef enum ENodeType {
...
@@ -104,6 +106,7 @@ typedef enum ENodeType {
QUERY_NODE_DROP_QNODE_STMT
,
QUERY_NODE_DROP_QNODE_STMT
,
QUERY_NODE_CREATE_TOPIC_STMT
,
QUERY_NODE_CREATE_TOPIC_STMT
,
QUERY_NODE_DROP_TOPIC_STMT
,
QUERY_NODE_DROP_TOPIC_STMT
,
QUERY_NODE_ALTER_LOCAL_STMT
,
// logic plan node
// logic plan node
QUERY_NODE_LOGIC_PLAN_SCAN
,
QUERY_NODE_LOGIC_PLAN_SCAN
,
...
@@ -163,6 +166,7 @@ SNodeList* nodesMakeList();
...
@@ -163,6 +166,7 @@ SNodeList* nodesMakeList();
int32_t
nodesListAppend
(
SNodeList
*
pList
,
SNodeptr
pNode
);
int32_t
nodesListAppend
(
SNodeList
*
pList
,
SNodeptr
pNode
);
int32_t
nodesListStrictAppend
(
SNodeList
*
pList
,
SNodeptr
pNode
);
int32_t
nodesListStrictAppend
(
SNodeList
*
pList
,
SNodeptr
pNode
);
int32_t
nodesListAppendList
(
SNodeList
*
pTarget
,
SNodeList
*
pSrc
);
int32_t
nodesListAppendList
(
SNodeList
*
pTarget
,
SNodeList
*
pSrc
);
int32_t
nodesListStrictAppendList
(
SNodeList
*
pTarget
,
SNodeList
*
pSrc
);
SListCell
*
nodesListErase
(
SNodeList
*
pList
,
SListCell
*
pCell
);
SListCell
*
nodesListErase
(
SNodeList
*
pList
,
SListCell
*
pCell
);
SNodeptr
nodesListGetNode
(
SNodeList
*
pList
,
int32_t
index
);
SNodeptr
nodesListGetNode
(
SNodeList
*
pList
,
int32_t
index
);
void
nodesDestroyList
(
SNodeList
*
pList
);
void
nodesDestroyList
(
SNodeList
*
pList
);
...
...
include/libs/nodes/plannodes.h
浏览文件 @
c56743d8
...
@@ -26,7 +26,6 @@ extern "C" {
...
@@ -26,7 +26,6 @@ extern "C" {
typedef
struct
SLogicNode
{
typedef
struct
SLogicNode
{
ENodeType
type
;
ENodeType
type
;
int32_t
id
;
SNodeList
*
pTargets
;
// SColumnNode
SNodeList
*
pTargets
;
// SColumnNode
SNode
*
pConditions
;
SNode
*
pConditions
;
SNodeList
*
pChildren
;
SNodeList
*
pChildren
;
...
@@ -167,6 +166,7 @@ typedef struct SScanPhysiNode {
...
@@ -167,6 +166,7 @@ typedef struct SScanPhysiNode {
typedef
SScanPhysiNode
SSystemTableScanPhysiNode
;
typedef
SScanPhysiNode
SSystemTableScanPhysiNode
;
typedef
SScanPhysiNode
STagScanPhysiNode
;
typedef
SScanPhysiNode
STagScanPhysiNode
;
typedef
SScanPhysiNode
SStreamScanPhysiNode
;
typedef
struct
STableScanPhysiNode
{
typedef
struct
STableScanPhysiNode
{
SScanPhysiNode
scan
;
SScanPhysiNode
scan
;
...
...
include/libs/nodes/querynodes.h
浏览文件 @
c56743d8
...
@@ -23,6 +23,9 @@ extern "C" {
...
@@ -23,6 +23,9 @@ extern "C" {
#include "nodes.h"
#include "nodes.h"
#include "tmsg.h"
#include "tmsg.h"
#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags) * sizeof(SSchema)))
#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
typedef
struct
SRawExprNode
{
typedef
struct
SRawExprNode
{
ENodeType
nodeType
;
ENodeType
nodeType
;
char
*
p
;
char
*
p
;
...
...
include/libs/parser/parser.h
浏览文件 @
c56743d8
...
@@ -26,6 +26,7 @@ typedef struct SParseContext {
...
@@ -26,6 +26,7 @@ typedef struct SParseContext {
uint64_t
requestId
;
uint64_t
requestId
;
int32_t
acctId
;
int32_t
acctId
;
const
char
*
db
;
const
char
*
db
;
bool
streamQuery
;
void
*
pTransporter
;
void
*
pTransporter
;
SEpSet
mgmtEpSet
;
SEpSet
mgmtEpSet
;
const
char
*
pSql
;
// sql string
const
char
*
pSql
;
// sql string
...
...
include/libs/qcom/query.h
浏览文件 @
c56743d8
...
@@ -49,6 +49,10 @@ typedef struct STableComInfo {
...
@@ -49,6 +49,10 @@ typedef struct STableComInfo {
int32_t
rowSize
;
// row size of the schema
int32_t
rowSize
;
// row size of the schema
}
STableComInfo
;
}
STableComInfo
;
typedef
struct
SIndexMeta
{
}
SIndexMeta
;
/*
/*
* ASSERT(sizeof(SCTableMeta) == 24)
* ASSERT(sizeof(SCTableMeta) == 24)
* ASSERT(tableType == TSDB_CHILD_TABLE)
* ASSERT(tableType == TSDB_CHILD_TABLE)
...
...
include/os/osFile.h
浏览文件 @
c56743d8
...
@@ -22,15 +22,6 @@ extern "C" {
...
@@ -22,15 +22,6 @@ extern "C" {
#include "osSocket.h"
#include "osSocket.h"
#if defined(WINDOWS)
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
#else
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
#endif
int64_t
taosRead
(
FileFd
fd
,
void
*
buf
,
int64_t
count
);
// If the error is in a third-party library, place this header file under the third-party library header file.
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#ifndef ALLOW_FORBID_FUNC
#define open OPEN_FUNC_TAOS_FORBID
#define open OPEN_FUNC_TAOS_FORBID
...
@@ -42,6 +33,7 @@ int64_t taosRead(FileFd fd, void *buf, int64_t count);
...
@@ -42,6 +33,7 @@ int64_t taosRead(FileFd fd, void *buf, int64_t count);
#define close CLOSE_FUNC_TAOS_FORBID
#define close CLOSE_FUNC_TAOS_FORBID
#define fclose FCLOSE_FUNC_TAOS_FORBID
#define fclose FCLOSE_FUNC_TAOS_FORBID
#define fsync FSYNC_FUNC_TAOS_FORBID
#define fsync FSYNC_FUNC_TAOS_FORBID
#define getline GETLINE_FUNC_TAOS_FORBID
// #define fflush FFLUSH_FUNC_TAOS_FORBID
// #define fflush FFLUSH_FUNC_TAOS_FORBID
#endif
#endif
...
@@ -49,15 +41,6 @@ int64_t taosRead(FileFd fd, void *buf, int64_t count);
...
@@ -49,15 +41,6 @@ int64_t taosRead(FileFd fd, void *buf, int64_t count);
#define PATH_MAX 256
#define PATH_MAX 256
#endif
#endif
typedef
int32_t
FileFd
;
typedef
struct
TdFile
{
pthread_rwlock_t
rwlock
;
int
refId
;
FileFd
fd
;
FILE
*
fp
;
}
*
TdFilePtr
,
TdFile
;
typedef
struct
TdFile
*
TdFilePtr
;
typedef
struct
TdFile
*
TdFilePtr
;
#define TD_FILE_CTEATE 0x0001
#define TD_FILE_CTEATE 0x0001
...
@@ -95,10 +78,6 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
...
@@ -95,10 +78,6 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
);
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
);
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...);
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...);
#if defined(WINDOWS)
#define __restrict__
#endif // WINDOWS
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict__
ptrBuf
);
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict__
ptrBuf
);
int32_t
taosEOFFile
(
TdFilePtr
pFile
);
int32_t
taosEOFFile
(
TdFilePtr
pFile
);
...
@@ -111,15 +90,7 @@ int32_t taosRemoveFile(const char *path);
...
@@ -111,15 +90,7 @@ int32_t taosRemoveFile(const char *path);
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
);
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
);
#if defined(_TD_DARWIN_64)
typedef
int32_t
SocketFd
;
int64_t
taosSendFile
(
SocketFd
fdDst
,
FileFd
pFileSrc
,
int64_t
*
offset
,
int64_t
size
);
int64_t
taosFSendFile
(
FILE
*
pFileOut
,
FILE
*
pFileIn
,
int64_t
*
offset
,
int64_t
size
);
#else
int64_t
taosSendFile
(
SocketFd
fdDst
,
TdFilePtr
pFileSrc
,
int64_t
*
offset
,
int64_t
size
);
int64_t
taosFSendFile
(
TdFilePtr
pFileOut
,
TdFilePtr
pFileIn
,
int64_t
*
offset
,
int64_t
size
);
int64_t
taosFSendFile
(
TdFilePtr
pFileOut
,
TdFilePtr
pFileIn
,
int64_t
*
offset
,
int64_t
size
);
#endif
void
*
taosMmapReadOnlyFile
(
TdFilePtr
pFile
,
int64_t
length
);
void
*
taosMmapReadOnlyFile
(
TdFilePtr
pFile
,
int64_t
length
);
bool
taosValidFile
(
TdFilePtr
pFile
);
bool
taosValidFile
(
TdFilePtr
pFile
);
...
...
include/os/osString.h
浏览文件 @
c56743d8
...
@@ -20,16 +20,28 @@
...
@@ -20,16 +20,28 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
typedef
wchar_t
TdWchar
;
typedef
int32_t
TdUcs4
;
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define iconv_open ICONV_OPEN_FUNC_TAOS_FORBID
#define iconv_close ICONV_CLOSE_FUNC_TAOS_FORBID
#define iconv ICONV_FUNC_TAOS_FORBID
#define wcwidth WCWIDTH_FUNC_TAOS_FORBID
#define wcswidth WCSWIDTH_FUNC_TAOS_FORBID
#define mbtowc MBTOWC_FUNC_TAOS_FORBID
#define mbstowcs MBSTOWCS_FUNC_TAOS_FORBID
#define wctomb WCTOMB_FUNC_TAOS_FORBID
#define wcstombs WCSTOMBS_FUNC_TAOS_FORBID
#define wcsncpy WCSNCPY_FUNC_TAOS_FORBID
#define wchar_t WCHAR_T_FUNC_TAOS_FORBID
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#define tstrdup(str) _strdup(str)
#define tstrdup(str) _strdup(str)
#define tstrndup(str, size) _strndup(str, size)
int32_t
tgetline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
int32_t
twcslen
(
const
wchar_t
*
wcs
);
#else
#else
#define tstrdup(str) strdup(str)
#define tstrdup(str) strdup(str)
#define tstrndup(str, size) strndup(str, size)
#define tgetline(lineptr, n, stream) getline(lineptr, n, stream)
#define twcslen wcslen
#endif
#endif
#define tstrncpy(dst, src, size) \
#define tstrncpy(dst, src, size) \
...
@@ -38,14 +50,22 @@ extern "C" {
...
@@ -38,14 +50,22 @@ extern "C" {
(dst)[(size)-1] = 0; \
(dst)[(size)-1] = 0; \
} while (0)
} while (0)
int32_t
taosUcs4len
(
TdUcs4
*
ucs4
);
int64_t
taosStr2int64
(
const
char
*
str
);
int64_t
taosStr2int64
(
const
char
*
str
);
// USE_LIBICONV
int32_t
taosUcs4ToMbs
(
TdUcs4
*
ucs4
,
int32_t
ucs4_max_len
,
char
*
mbs
);
int32_t
taosUcs4ToMbs
(
void
*
ucs4
,
int32_t
ucs4_max_len
,
char
*
mbs
);
bool
taosMbsToUcs4
(
const
char
*
mbs
,
size_t
mbs_len
,
TdUcs4
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
);
bool
taosMbsToUcs4
(
const
char
*
mbs
,
size_t
mbs_len
,
char
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
);
int32_t
tasoUcs4Compare
(
TdUcs4
*
f1_ucs4
,
TdUcs4
*
f2_ucs4
,
int32_t
bytes
);
int32_t
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int32_t
bytes
,
int8_t
ncharSize
);
TdUcs4
*
tasoUcs4Copy
(
TdUcs4
*
target_ucs4
,
TdUcs4
*
source_ucs4
,
int32_t
len_ucs4
);
bool
taosValidateEncodec
(
const
char
*
encodec
);
bool
taosValidateEncodec
(
const
char
*
encodec
);
int32_t
taosWcharWidth
(
TdWchar
wchar
);
int32_t
taosWcharsWidth
(
TdWchar
*
pWchar
,
int32_t
size
);
int32_t
taosMbToWchar
(
TdWchar
*
pWchar
,
const
char
*
pStr
,
int32_t
size
);
int32_t
taosMbsToWchars
(
TdWchar
*
pWchars
,
const
char
*
pStrs
,
int32_t
size
);
int32_t
taosWcharToMb
(
char
*
pStr
,
TdWchar
wchar
);
int32_t
taosWcharsToMbs
(
char
*
pStrs
,
TdWchar
*
pWchars
,
int32_t
size
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
include/util/taoserror.h
浏览文件 @
c56743d8
...
@@ -482,6 +482,7 @@ int32_t* taosGetErrno();
...
@@ -482,6 +482,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_PASSWD_EMPTY TAOS_DEF_ERROR_CODE(0, 0x2611)
#define TSDB_CODE_PAR_PASSWD_EMPTY TAOS_DEF_ERROR_CODE(0, 0x2611)
#define TSDB_CODE_PAR_INVALID_PORT TAOS_DEF_ERROR_CODE(0, 0x2612)
#define TSDB_CODE_PAR_INVALID_PORT TAOS_DEF_ERROR_CODE(0, 0x2612)
#define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613)
#define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613)
#define TSDB_CODE_PAR_EXPRIE_STATEMENT TAOS_DEF_ERROR_CODE(0, 0x2614)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
include/util/tcompare.h
浏览文件 @
c56743d8
...
@@ -46,7 +46,7 @@ typedef struct SPatternCompareInfo {
...
@@ -46,7 +46,7 @@ typedef struct SPatternCompareInfo {
int32_t
patternMatch
(
const
char
*
pattern
,
const
char
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
patternMatch
(
const
char
*
pattern
,
const
char
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
WCSPatternMatch
(
const
wchar_t
*
pattern
,
const
wchar_t
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
WCSPatternMatch
(
const
TdUcs4
*
pattern
,
const
TdUcs4
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
);
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
);
int32_t
taosArrayCompareString
(
const
void
*
a
,
const
void
*
b
);
...
...
include/util/tdef.h
浏览文件 @
c56743d8
...
@@ -41,7 +41,7 @@ extern const int32_t TYPE_BYTES[15];
...
@@ -41,7 +41,7 @@ extern const int32_t TYPE_BYTES[15];
#define DOUBLE_BYTES sizeof(double)
#define DOUBLE_BYTES sizeof(double)
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
#define TSDB_KEYSIZE sizeof(TSKEY)
#define TSDB_KEYSIZE sizeof(TSKEY)
#define TSDB_NCHAR_SIZE sizeof(
int32_t
)
#define TSDB_NCHAR_SIZE sizeof(
TdUcs4
)
// NULL definition
// NULL definition
#define TSDB_DATA_BOOL_NULL 0x02
#define TSDB_DATA_BOOL_NULL 0x02
...
...
include/util/tjson.h
浏览文件 @
c56743d8
...
@@ -44,6 +44,7 @@ int32_t tjsonGetIntValue(const SJson* pJson, const char* pName, int32_t* pVal);
...
@@ -44,6 +44,7 @@ int32_t tjsonGetIntValue(const SJson* pJson, const char* pName, int32_t* pVal);
int32_t
tjsonGetSmallIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
int16_t
*
pVal
);
int32_t
tjsonGetSmallIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
int16_t
*
pVal
);
int32_t
tjsonGetTinyIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
int8_t
*
pVal
);
int32_t
tjsonGetTinyIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
int8_t
*
pVal
);
int32_t
tjsonGetUBigIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint64_t
*
pVal
);
int32_t
tjsonGetUBigIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint64_t
*
pVal
);
int32_t
tjsonGetUIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint32_t
*
pVal
);
int32_t
tjsonGetUTinyIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint8_t
*
pVal
);
int32_t
tjsonGetUTinyIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint8_t
*
pVal
);
int32_t
tjsonGetBoolValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
bool
*
pVal
);
int32_t
tjsonGetBoolValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
bool
*
pVal
);
int32_t
tjsonGetDoubleValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
double
*
pVal
);
int32_t
tjsonGetDoubleValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
double
*
pVal
);
...
@@ -60,6 +61,7 @@ int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void*
...
@@ -60,6 +61,7 @@ int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void*
typedef
int32_t
(
*
FToObject
)(
const
SJson
*
pJson
,
void
*
pObj
);
typedef
int32_t
(
*
FToObject
)(
const
SJson
*
pJson
,
void
*
pObj
);
int32_t
tjsonToObject
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
*
pObj
);
int32_t
tjsonToObject
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
*
pObj
);
int32_t
tjsonMakeObject
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
**
pObj
,
int32_t
objSize
);
int32_t
tjsonToArray
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
*
pArray
,
int32_t
itemSize
);
int32_t
tjsonToArray
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
*
pArray
,
int32_t
itemSize
);
char
*
tjsonToString
(
const
SJson
*
pJson
);
char
*
tjsonToString
(
const
SJson
*
pJson
);
...
...
source/client/inc/clientInt.h
浏览文件 @
c56743d8
...
@@ -179,6 +179,7 @@ typedef struct SRequestObj {
...
@@ -179,6 +179,7 @@ typedef struct SRequestObj {
uint64_t
requestId
;
uint64_t
requestId
;
int32_t
type
;
// request type
int32_t
type
;
// request type
STscObj
*
pTscObj
;
STscObj
*
pTscObj
;
char
*
pDb
;
char
*
sqlstr
;
// sql string
char
*
sqlstr
;
// sql string
int32_t
sqlLen
;
int32_t
sqlLen
;
int64_t
self
;
int64_t
self
;
...
@@ -229,7 +230,7 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
...
@@ -229,7 +230,7 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
int32_t
buildRequest
(
STscObj
*
pTscObj
,
const
char
*
sql
,
int
sqlLen
,
SRequestObj
**
pRequest
);
int32_t
buildRequest
(
STscObj
*
pTscObj
,
const
char
*
sql
,
int
sqlLen
,
SRequestObj
**
pRequest
);
int32_t
parseSql
(
SRequestObj
*
pRequest
,
SQuery
**
pQuery
);
int32_t
parseSql
(
SRequestObj
*
pRequest
,
bool
streamQuery
,
SQuery
**
pQuery
);
int32_t
getPlan
(
SRequestObj
*
pRequest
,
SQuery
*
pQuery
,
SQueryPlan
**
pPlan
,
SArray
*
pNodeList
);
int32_t
getPlan
(
SRequestObj
*
pRequest
,
SQuery
*
pQuery
,
SQueryPlan
**
pPlan
,
SArray
*
pNodeList
);
// --- heartbeat
// --- heartbeat
...
...
source/client/src/clientEnv.c
浏览文件 @
c56743d8
...
@@ -150,6 +150,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty
...
@@ -150,6 +150,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty
return
NULL
;
return
NULL
;
}
}
pRequest
->
pDb
=
getDbOfConnection
(
pObj
);
pRequest
->
requestId
=
generateRequestId
();
pRequest
->
requestId
=
generateRequestId
();
pRequest
->
metric
.
start
=
taosGetTimestampMs
();
pRequest
->
metric
.
start
=
taosGetTimestampMs
();
...
@@ -180,6 +181,7 @@ static void doDestroyRequest(void *p) {
...
@@ -180,6 +181,7 @@ static void doDestroyRequest(void *p) {
tfree
(
pRequest
->
msgBuf
);
tfree
(
pRequest
->
msgBuf
);
tfree
(
pRequest
->
sqlstr
);
tfree
(
pRequest
->
sqlstr
);
tfree
(
pRequest
->
pInfo
);
tfree
(
pRequest
->
pInfo
);
tfree
(
pRequest
->
pDb
);
doFreeReqResultInfo
(
&
pRequest
->
body
.
resInfo
);
doFreeReqResultInfo
(
&
pRequest
->
body
.
resInfo
);
qDestroyQueryPlan
(
pRequest
->
body
.
pDag
);
qDestroyQueryPlan
(
pRequest
->
body
.
pDag
);
...
...
source/client/src/clientImpl.c
浏览文件 @
c56743d8
...
@@ -137,13 +137,14 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj*
...
@@ -137,13 +137,14 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj*
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
parseSql
(
SRequestObj
*
pRequest
,
SQuery
**
pQuery
)
{
int32_t
parseSql
(
SRequestObj
*
pRequest
,
bool
streamQuery
,
SQuery
**
pQuery
)
{
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
STscObj
*
pTscObj
=
pRequest
->
pTscObj
;
SParseContext
cxt
=
{
SParseContext
cxt
=
{
.
requestId
=
pRequest
->
requestId
,
.
requestId
=
pRequest
->
requestId
,
.
acctId
=
pTscObj
->
acctId
,
.
acctId
=
pTscObj
->
acctId
,
.
db
=
getDbOfConnection
(
pTscObj
),
.
db
=
pRequest
->
pDb
,
.
streamQuery
=
streamQuery
,
.
pSql
=
pRequest
->
sqlstr
,
.
pSql
=
pRequest
->
sqlstr
,
.
sqlLen
=
pRequest
->
sqlLen
,
.
sqlLen
=
pRequest
->
sqlLen
,
.
pMsg
=
pRequest
->
msgBuf
,
.
pMsg
=
pRequest
->
msgBuf
,
...
@@ -154,7 +155,6 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
...
@@ -154,7 +155,6 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
cxt
.
mgmtEpSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
cxt
.
mgmtEpSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
int32_t
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
cxt
.
pCatalog
);
int32_t
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
cxt
.
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
cxt
.
db
);
return
code
;
return
code
;
}
}
...
@@ -163,7 +163,6 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
...
@@ -163,7 +163,6 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
setResSchemaInfo
(
&
pRequest
->
body
.
resInfo
,
(
*
pQuery
)
->
pResSchema
,
(
*
pQuery
)
->
numOfResCols
);
setResSchemaInfo
(
&
pRequest
->
body
.
resInfo
,
(
*
pQuery
)
->
pResSchema
,
(
*
pQuery
)
->
numOfResCols
);
}
}
tfree
(
cxt
.
db
);
return
code
;
return
code
;
}
}
...
@@ -249,7 +248,7 @@ TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) {
...
@@ -249,7 +248,7 @@ TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) {
terrno
=
TSDB_CODE_SUCCESS
;
terrno
=
TSDB_CODE_SUCCESS
;
CHECK_CODE_GOTO
(
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
),
_return
);
CHECK_CODE_GOTO
(
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
),
_return
);
CHECK_CODE_GOTO
(
parseSql
(
pRequest
,
&
pQuery
),
_return
);
CHECK_CODE_GOTO
(
parseSql
(
pRequest
,
false
,
&
pQuery
),
_return
);
if
(
pQuery
->
directRpc
)
{
if
(
pQuery
->
directRpc
)
{
CHECK_CODE_GOTO
(
execDdlQuery
(
pRequest
,
pQuery
),
_return
);
CHECK_CODE_GOTO
(
execDdlQuery
(
pRequest
,
pQuery
),
_return
);
...
...
source/client/src/tmq.c
浏览文件 @
c56743d8
...
@@ -482,38 +482,24 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
...
@@ -482,38 +482,24 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
}
}
tscDebug
(
"start to create topic, %s"
,
topicName
);
tscDebug
(
"start to create topic, %s"
,
topicName
);
#if 0
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
pQueryNode->streamQuery = true;
CHECK_CODE_GOTO
(
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
),
_return
);
CHECK_CODE_GOTO
(
parseSql
(
pRequest
,
true
,
&
pQueryNode
),
_return
);
// todo check for invalid sql statement and return with error code
// todo check for invalid sql statement and return with error code
SSchema* schema = NULL;
CHECK_CODE_GOTO
(
nodesNodeToString
(
pQueryNode
->
pRoot
,
false
,
&
pStr
,
NULL
),
_return
);
int32_t numOfCols = 0;
CHECK_CODE_GOTO(getPlan(pRequest, pQueryNode, &pRequest->body.pDag, NULL), _return);
pStr = qQueryPlanToString(pRequest->body.pDag);
if (pStr == NULL) {
goto _return;
}
/*printf("%s\n", pStr);*/
/*printf("%s\n", pStr);*/
// The topic should be related to a database that the queried table is belonged to.
SName
name
=
{
.
acctId
=
pTscObj
->
acctId
,
.
type
=
TSDB_TABLE_NAME_T
};
SName name = {0};
strcpy
(
name
.
dbname
,
pRequest
->
pDb
);
char dbName[TSDB_DB_FNAME_LEN] = {0};
strcpy
(
name
.
tname
,
topicName
);
// tNameGetFullDbName(&((SQueryStmtInfo*)pQueryNode)->pTableMetaInfo[0]->name, dbName);
tNameFromString(&name, dbName, T_NAME_ACCT | T_NAME_DB);
tNameFromString(&name, topicName, T_NAME_TABLE);
SCMCreateTopicReq
req
=
{
SCMCreateTopicReq
req
=
{
.
igExists
=
1
,
.
igExists
=
1
,
.
physicalPlan
= (char*)pStr,
.
ast
=
(
char
*
)
pStr
,
.
sql
=
(
char
*
)
sql
,
.
sql
=
(
char
*
)
sql
,
.logicalPlan = (char*)"no logic plan",
};
};
tNameExtractFullName
(
&
name
,
req
.
name
);
tNameExtractFullName
(
&
name
,
req
.
name
);
...
@@ -536,7 +522,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
...
@@ -536,7 +522,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
asyncSendMsgToServer
(
pTscObj
->
pAppInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
sendInfo
);
asyncSendMsgToServer
(
pTscObj
->
pAppInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
sendInfo
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
#endif
_return:
_return:
qDestroyQuery
(
pQueryNode
);
qDestroyQuery
(
pQueryNode
);
/*if (sendInfo != NULL) {*/
/*if (sendInfo != NULL) {*/
...
...
source/common/src/tdatablock.c
浏览文件 @
c56743d8
...
@@ -1072,6 +1072,10 @@ void blockDataClearup(SSDataBlock* pDataBlock) {
...
@@ -1072,6 +1072,10 @@ void blockDataClearup(SSDataBlock* pDataBlock) {
}
}
int32_t
blockDataEnsureColumnCapacity
(
SColumnInfoData
*
pColumn
,
uint32_t
numOfRows
)
{
int32_t
blockDataEnsureColumnCapacity
(
SColumnInfoData
*
pColumn
,
uint32_t
numOfRows
)
{
if
(
0
==
numOfRows
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
info
.
type
))
{
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
info
.
type
))
{
char
*
tmp
=
realloc
(
pColumn
->
varmeta
.
offset
,
sizeof
(
int32_t
)
*
numOfRows
);
char
*
tmp
=
realloc
(
pColumn
->
varmeta
.
offset
,
sizeof
(
int32_t
)
*
numOfRows
);
if
(
tmp
==
NULL
)
{
if
(
tmp
==
NULL
)
{
...
@@ -1092,7 +1096,7 @@ int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRo
...
@@ -1092,7 +1096,7 @@ int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRo
pColumn
->
nullbitmap
=
tmp
;
pColumn
->
nullbitmap
=
tmp
;
memset
(
pColumn
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
memset
(
pColumn
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
assert
(
pColumn
->
info
.
bytes
);
tmp
=
realloc
(
pColumn
->
pData
,
numOfRows
*
pColumn
->
info
.
bytes
);
tmp
=
realloc
(
pColumn
->
pData
,
numOfRows
*
pColumn
->
info
.
bytes
);
if
(
tmp
==
NULL
)
{
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
...
@@ -1137,7 +1141,7 @@ void* blockDataDestroy(SSDataBlock* pBlock) {
...
@@ -1137,7 +1141,7 @@ void* blockDataDestroy(SSDataBlock* pBlock) {
taosArrayDestroy
(
pBlock
->
pDataBlock
);
taosArrayDestroy
(
pBlock
->
pDataBlock
);
tfree
(
pBlock
->
pBlockAgg
);
tfree
(
pBlock
->
pBlockAgg
);
tfree
(
pBlock
);
//
tfree(pBlock);
return
NULL
;
return
NULL
;
}
}
...
@@ -1190,7 +1194,7 @@ int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) {
...
@@ -1190,7 +1194,7 @@ int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) {
}
}
int32_t
len
=
colDataGetLength
(
pColData
,
rows
);
int32_t
len
=
colDataGetLength
(
pColData
,
rows
);
taosEncodeFixedI32
(
buf
,
len
);
t
len
+=
t
aosEncodeFixedI32
(
buf
,
len
);
tlen
+=
taosEncodeBinary
(
buf
,
pColData
->
pData
,
len
);
tlen
+=
taosEncodeBinary
(
buf
,
pColData
->
pData
,
len
);
}
}
...
...
source/common/src/tvariant.c
浏览文件 @
c56743d8
...
@@ -199,8 +199,8 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
...
@@ -199,8 +199,8 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
case
TSDB_DATA_TYPE_NCHAR
:
{
// here we get the nchar length from raw binary bits length
case
TSDB_DATA_TYPE_NCHAR
:
{
// here we get the nchar length from raw binary bits length
size_t
lenInwchar
=
len
/
TSDB_NCHAR_SIZE
;
size_t
lenInwchar
=
len
/
TSDB_NCHAR_SIZE
;
pVar
->
wpz
=
calloc
(
1
,
(
lenInwchar
+
1
)
*
TSDB_NCHAR_SIZE
);
pVar
->
ucs4
=
calloc
(
1
,
(
lenInwchar
+
1
)
*
TSDB_NCHAR_SIZE
);
memcpy
(
pVar
->
wpz
,
pz
,
lenInwchar
*
TSDB_NCHAR_SIZE
);
memcpy
(
pVar
->
ucs4
,
pz
,
lenInwchar
*
TSDB_NCHAR_SIZE
);
pVar
->
nLen
=
(
int32_t
)
len
;
pVar
->
nLen
=
(
int32_t
)
len
;
break
;
break
;
...
@@ -343,7 +343,7 @@ int32_t taosVariantToString(SVariant *pVar, char *dst) {
...
@@ -343,7 +343,7 @@ int32_t taosVariantToString(SVariant *pVar, char *dst) {
case
TSDB_DATA_TYPE_NCHAR
:
{
case
TSDB_DATA_TYPE_NCHAR
:
{
dst
[
0
]
=
'\''
;
dst
[
0
]
=
'\''
;
taosUcs4ToMbs
(
pVar
->
wpz
,
(
twcslen
(
pVar
->
wpz
)
+
1
)
*
TSDB_NCHAR_SIZE
,
dst
+
1
);
taosUcs4ToMbs
(
pVar
->
ucs4
,
(
taosUcs4len
(
pVar
->
ucs4
)
+
1
)
*
TSDB_NCHAR_SIZE
,
dst
+
1
);
int32_t
len
=
(
int32_t
)
strlen
(
dst
);
int32_t
len
=
(
int32_t
)
strlen
(
dst
);
dst
[
len
]
=
'\''
;
dst
[
len
]
=
'\''
;
dst
[
len
+
1
]
=
0
;
dst
[
len
+
1
]
=
0
;
...
@@ -384,7 +384,7 @@ static FORCE_INLINE int32_t convertToBoolImpl(char *pStr, int32_t len) {
...
@@ -384,7 +384,7 @@ static FORCE_INLINE int32_t convertToBoolImpl(char *pStr, int32_t len) {
}
}
}
}
static
FORCE_INLINE
int32_t
wcsconvertToBoolImpl
(
wchar_t
*
pstr
,
int32_t
len
)
{
static
FORCE_INLINE
int32_t
wcsconvertToBoolImpl
(
TdUcs4
*
pstr
,
int32_t
len
)
{
if
((
wcsncasecmp
(
pstr
,
L"true"
,
len
)
==
0
)
&&
(
len
==
4
))
{
if
((
wcsncasecmp
(
pstr
,
L"true"
,
len
)
==
0
)
&&
(
len
==
4
))
{
return
TSDB_TRUE
;
return
TSDB_TRUE
;
}
else
if
(
wcsncasecmp
(
pstr
,
L"false"
,
len
)
==
0
&&
(
len
==
5
))
{
}
else
if
(
wcsncasecmp
(
pstr
,
L"false"
,
len
)
==
0
&&
(
len
==
5
))
{
...
@@ -412,11 +412,11 @@ static int32_t toBinary(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
...
@@ -412,11 +412,11 @@ static int32_t toBinary(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
pBuf
=
realloc
(
pBuf
,
newSize
+
1
);
pBuf
=
realloc
(
pBuf
,
newSize
+
1
);
}
}
taosUcs4ToMbs
(
pVariant
->
wpz
,
(
int32_t
)
newSize
,
pBuf
);
taosUcs4ToMbs
(
pVariant
->
ucs4
,
(
int32_t
)
newSize
,
pBuf
);
free
(
pVariant
->
wpz
);
free
(
pVariant
->
ucs4
);
pBuf
[
newSize
]
=
0
;
pBuf
[
newSize
]
=
0
;
}
else
{
}
else
{
taosUcs4ToMbs
(
pVariant
->
wpz
,
(
int32_t
)
newSize
,
*
pDest
);
taosUcs4ToMbs
(
pVariant
->
ucs4
,
(
int32_t
)
newSize
,
*
pDest
);
}
}
}
else
{
}
else
{
...
@@ -460,8 +460,8 @@ static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
...
@@ -460,8 +460,8 @@ static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
}
}
if
(
*
pDest
==
pVariant
->
pz
)
{
if
(
*
pDest
==
pVariant
->
pz
)
{
wchar_t
*
pWStr
=
calloc
(
1
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
TdUcs4
*
pWStr
=
calloc
(
1
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
bool
ret
=
taosMbsToUcs4
(
pDst
,
nLen
,
(
char
*
)
pWStr
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
NULL
);
bool
ret
=
taosMbsToUcs4
(
pDst
,
nLen
,
pWStr
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
NULL
);
if
(
!
ret
)
{
if
(
!
ret
)
{
tfree
(
pWStr
);
tfree
(
pWStr
);
return
-
1
;
return
-
1
;
...
@@ -469,21 +469,21 @@ static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
...
@@ -469,21 +469,21 @@ static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
// free the binary buffer in the first place
// free the binary buffer in the first place
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
free
(
pVariant
->
wpz
);
free
(
pVariant
->
ucs4
);
}
}
pVariant
->
wpz
=
pWStr
;
pVariant
->
ucs4
=
pWStr
;
*
pDestSize
=
t
wcslen
(
pVariant
->
wpz
);
*
pDestSize
=
t
aosUcs4len
(
pVariant
->
ucs4
);
// shrink the allocate memory, no need to check here.
// shrink the allocate memory, no need to check here.
char
*
tmp
=
realloc
(
pVariant
->
wpz
,
(
*
pDestSize
+
1
)
*
TSDB_NCHAR_SIZE
);
char
*
tmp
=
realloc
(
pVariant
->
ucs4
,
(
*
pDestSize
+
1
)
*
TSDB_NCHAR_SIZE
);
assert
(
tmp
!=
NULL
);
assert
(
tmp
!=
NULL
);
pVariant
->
wpz
=
(
wchar_t
*
)
tmp
;
pVariant
->
ucs4
=
(
TdUcs4
*
)
tmp
;
}
else
{
}
else
{
int32_t
output
=
0
;
int32_t
output
=
0
;
bool
ret
=
taosMbsToUcs4
(
pDst
,
nLen
,
*
pDest
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
&
output
);
bool
ret
=
taosMbsToUcs4
(
pDst
,
nLen
,
(
TdUcs4
*
)
*
pDest
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
&
output
);
if
(
!
ret
)
{
if
(
!
ret
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -554,7 +554,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
...
@@ -554,7 +554,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
*result = res;
*result = res;
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
errno = 0;
errno = 0;
wchar_t
*endPtr = NULL;
TdUcs4
*endPtr = NULL;
SToken token = {0};
SToken token = {0};
token.n = tGetToken(pVariant->pz, &token.type);
token.n = tGetToken(pVariant->pz, &token.type);
...
@@ -564,7 +564,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
...
@@ -564,7 +564,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
}
}
if (token.type == TK_FLOAT) {
if (token.type == TK_FLOAT) {
double v = wcstod(pVariant->
wpz
, &endPtr);
double v = wcstod(pVariant->
ucs4
, &endPtr);
if (releaseVariantPtr) {
if (releaseVariantPtr) {
free(pVariant->pz);
free(pVariant->pz);
pVariant->nLen = 0;
pVariant->nLen = 0;
...
@@ -583,7 +583,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
...
@@ -583,7 +583,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
setNull((char *)result, type, tDataTypes[type].bytes);
setNull((char *)result, type, tDataTypes[type].bytes);
return 0;
return 0;
} else {
} else {
int64_t val = wcstoll(pVariant->
wpz
, &endPtr, 10);
int64_t val = wcstoll(pVariant->
ucs4
, &endPtr, 10);
if (releaseVariantPtr) {
if (releaseVariantPtr) {
free(pVariant->pz);
free(pVariant->pz);
pVariant->nLen = 0;
pVariant->nLen = 0;
...
@@ -649,7 +649,7 @@ static int32_t convertToBool(SVariant *pVariant, int64_t *pDest) {
...
@@ -649,7 +649,7 @@ static int32_t convertToBool(SVariant *pVariant, int64_t *pDest) {
*
pDest
=
ret
;
*
pDest
=
ret
;
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
if
((
ret
=
wcsconvertToBoolImpl
(
pVariant
->
wpz
,
pVariant
->
nLen
))
<
0
)
{
if
((
ret
=
wcsconvertToBoolImpl
(
pVariant
->
ucs4
,
pVariant
->
nLen
))
<
0
)
{
return
ret
;
return
ret
;
}
}
*
pDest
=
ret
;
*
pDest
=
ret
;
...
@@ -899,7 +899,7 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
...
@@ -899,7 +899,7 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
return
-
1
;
return
-
1
;
}
}
}
else
{
}
else
{
wcsncpy
((
wchar_t
*
)
payload
,
pVariant
->
wpz
,
pVariant
->
nLen
);
tasoUcs4Copy
((
TdUcs4
*
)
payload
,
pVariant
->
ucs4
,
pVariant
->
nLen
);
}
}
}
}
}
else
{
}
else
{
...
@@ -913,7 +913,7 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
...
@@ -913,7 +913,7 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
return
-
1
;
return
-
1
;
}
}
}
else
{
}
else
{
memcpy
(
p
,
pVariant
->
wpz
,
pVariant
->
nLen
);
memcpy
(
p
,
pVariant
->
ucs4
,
pVariant
->
nLen
);
newlen
=
pVariant
->
nLen
;
newlen
=
pVariant
->
nLen
;
}
}
...
@@ -979,7 +979,7 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type) {
...
@@ -979,7 +979,7 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type) {
pVariant
->
d
=
v
;
pVariant
->
d
=
v
;
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
errno
=
0
;
errno
=
0
;
double
v
=
wcstod
(
pVariant
->
wpz
,
NULL
);
double
v
=
wcstod
(
pVariant
->
ucs4
,
NULL
);
if
((
errno
==
ERANGE
&&
v
==
-
1
)
||
(
isinf
(
v
)
||
isnan
(
v
)))
{
if
((
errno
==
ERANGE
&&
v
==
-
1
)
||
(
isinf
(
v
)
||
isnan
(
v
)))
{
free
(
pVariant
->
pz
);
free
(
pVariant
->
pz
);
return
-
1
;
return
-
1
;
...
...
source/dnode/vnode/src/inc/tsdbDBDef.h
浏览文件 @
c56743d8
...
@@ -26,8 +26,9 @@ typedef struct SDBFile SDBFile;
...
@@ -26,8 +26,9 @@ typedef struct SDBFile SDBFile;
typedef
DB_ENV
*
TDBEnv
;
typedef
DB_ENV
*
TDBEnv
;
struct
SDBFile
{
struct
SDBFile
{
DB
*
pDB
;
int32_t
fid
;
char
*
path
;
DB
*
pDB
;
char
*
path
;
};
};
int32_t
tsdbOpenDBF
(
TDBEnv
pEnv
,
SDBFile
*
pDBF
);
int32_t
tsdbOpenDBF
(
TDBEnv
pEnv
,
SDBFile
*
pDBF
);
...
...
source/dnode/vnode/src/meta/metaBDBImpl.c
浏览文件 @
c56743d8
...
@@ -884,7 +884,7 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) {
...
@@ -884,7 +884,7 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) {
STSmaWrapper
*
metaGetSmaInfoByTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
STSmaWrapper
*
metaGetSmaInfoByTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
STSmaWrapper
*
pSW
=
NULL
;
STSmaWrapper
*
pSW
=
NULL
;
pSW
=
calloc
(
sizeof
(
*
pSW
),
1
);
pSW
=
calloc
(
1
,
sizeof
(
*
pSW
)
);
if
(
pSW
==
NULL
)
{
if
(
pSW
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
...
...
source/dnode/vnode/src/tq/tqRead.c
浏览文件 @
c56743d8
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "tdatablock.h"
#include "vnode.h"
#include "vnode.h"
STqReadHandle
*
tqInitSubmitMsgScanner
(
SMeta
*
pMeta
)
{
STqReadHandle
*
tqInitSubmitMsgScanner
(
SMeta
*
pMeta
)
{
...
@@ -128,10 +129,13 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
...
@@ -128,10 +129,13 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
int
j
=
0
;
int
j
=
0
;
for
(
int32_t
i
=
0
;
i
<
colNumNeed
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
colNumNeed
;
i
++
)
{
int
32_t
colId
=
*
(
int32
_t
*
)
taosArrayGet
(
pHandle
->
pColIdList
,
i
);
int
16_t
colId
=
*
(
int16
_t
*
)
taosArrayGet
(
pHandle
->
pColIdList
,
i
);
while
(
j
<
pSchemaWrapper
->
nCols
&&
pSchemaWrapper
->
pSchema
[
j
].
colId
<
colId
)
{
while
(
j
<
pSchemaWrapper
->
nCols
&&
pSchemaWrapper
->
pSchema
[
j
].
colId
<
colId
)
{
j
++
;
j
++
;
}
}
if
(
j
>=
pSchemaWrapper
->
nCols
)
{
continue
;
}
SSchema
*
pColSchema
=
&
pSchemaWrapper
->
pSchema
[
j
];
SSchema
*
pColSchema
=
&
pSchemaWrapper
->
pSchema
[
j
];
SColumnInfoData
colInfo
=
{
0
};
SColumnInfoData
colInfo
=
{
0
};
int
sz
=
numOfRows
*
pColSchema
->
bytes
;
int
sz
=
numOfRows
*
pColSchema
->
bytes
;
...
@@ -145,6 +149,8 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
...
@@ -145,6 +149,8 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
taosArrayDestroy
(
pArray
);
taosArrayDestroy
(
pArray
);
return
NULL
;
return
NULL
;
}
}
blockDataEnsureColumnCapacity
(
&
colInfo
,
numOfRows
);
taosArrayPush
(
pArray
,
&
colInfo
);
taosArrayPush
(
pArray
,
&
colInfo
);
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
c56743d8
...
@@ -3386,7 +3386,7 @@ void filterPrepare(void* expr, void* param) {
...
@@ -3386,7 +3386,7 @@ void filterPrepare(void* expr, void* param) {
if (size < (uint32_t)pSchema->bytes) {
if (size < (uint32_t)pSchema->bytes) {
size = pSchema->bytes;
size = pSchema->bytes;
}
}
// to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(
wchar_t
) space.
// to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(
TdUcs4
) space.
pInfo->q = calloc(1, size + TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
pInfo->q = calloc(1, size + TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
tVariantDump(pCond, pInfo->q, pSchema->type, true);
tVariantDump(pCond, pInfo->q, pSchema->type, true);
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
c56743d8
...
@@ -156,10 +156,6 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) {
...
@@ -156,10 +156,6 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) {
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
if
(
*
pEnv
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
*
pEnv
==
NULL
)
{
if
(
*
pEnv
==
NULL
)
{
if
((
*
pEnv
=
tsdbNewSmaEnv
(
pTsdb
,
path
))
==
NULL
)
{
if
((
*
pEnv
=
tsdbNewSmaEnv
(
pTsdb
,
path
))
==
NULL
)
{
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
...
@@ -213,11 +209,14 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
...
@@ -213,11 +209,14 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
// TODO: lock. lazy mode when update expired window, or hungry mode during tsdbNew.
/**
* 1. Lazy mode utilized when init SSmaStat to update expired window(or hungry mode when tsdbNew).
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
* tsdbInitSmaStat invoked in other multithread environment later.
*/
if
(
*
pSmaStat
==
NULL
)
{
if
(
*
pSmaStat
==
NULL
)
{
*
pSmaStat
=
(
SSmaStat
*
)
calloc
(
1
,
sizeof
(
SSmaStat
));
*
pSmaStat
=
(
SSmaStat
*
)
calloc
(
1
,
sizeof
(
SSmaStat
));
if
(
*
pSmaStat
==
NULL
)
{
if
(
*
pSmaStat
==
NULL
)
{
// TODO: unlock
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
...
@@ -227,11 +226,9 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
...
@@ -227,11 +226,9 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
if
((
*
pSmaStat
)
->
smaStatItems
==
NULL
)
{
if
((
*
pSmaStat
)
->
smaStatItems
==
NULL
)
{
tfree
(
*
pSmaStat
);
tfree
(
*
pSmaStat
);
// TODO: unlock
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
}
}
// TODO: unlock
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -259,10 +256,15 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
...
@@ -259,10 +256,15 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
int32_t
tsdbDestroySmaState
(
SSmaStat
*
pSmaStat
)
{
int32_t
tsdbDestroySmaState
(
SSmaStat
*
pSmaStat
)
{
if
(
pSmaStat
)
{
if
(
pSmaStat
)
{
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
SSmaStatItem
*
item
=
taosHashIterate
(
pSmaStat
->
smaStatItems
,
NULL
);
void
*
item
=
taosHashIterate
(
pSmaStat
->
smaStatItems
,
NULL
);
while
(
item
!=
NULL
)
{
while
(
item
!=
NULL
)
{
tfree
(
item
->
pSma
);
SSmaStatItem
*
pItem
=
*
(
SSmaStatItem
**
)
item
;
taosHashCleanup
(
item
->
expiredWindows
);
if
(
pItem
!=
NULL
)
{
tdDestroyTSma
(
pItem
->
pSma
);
tfree
(
pItem
->
pSma
);
taosHashCleanup
(
pItem
->
expiredWindows
);
tfree
(
pItem
);
}
item
=
taosHashIterate
(
pSmaStat
->
smaStatItems
,
item
);
item
=
taosHashIterate
(
pSmaStat
->
smaStatItems
,
item
);
}
}
taosHashCleanup
(
pSmaStat
->
smaStatItems
);
taosHashCleanup
(
pSmaStat
->
smaStatItems
);
...
@@ -270,15 +272,17 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
...
@@ -270,15 +272,17 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
}
}
static
int32_t
tsdbCheckAndInitSmaEnv
(
STsdb
*
pTsdb
,
int8_t
smaType
)
{
static
int32_t
tsdbCheckAndInitSmaEnv
(
STsdb
*
pTsdb
,
int8_t
smaType
)
{
SSmaEnv
*
pEnv
=
NULL
;
// return if already init
// return if already init
switch
(
smaType
)
{
switch
(
smaType
)
{
case
TSDB_SMA_TYPE_TIME_RANGE
:
case
TSDB_SMA_TYPE_TIME_RANGE
:
if
(
pTsdb
->
pTSmaEnv
)
{
if
(
(
pEnv
=
(
SSmaEnv
*
)
atomic_load_ptr
(
&
pTsdb
->
pTSmaEnv
))
!=
NULL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
break
;
break
;
case
TSDB_SMA_TYPE_ROLLUP
:
case
TSDB_SMA_TYPE_ROLLUP
:
if
(
pTsdb
->
pRSmaEnv
)
{
if
(
(
pEnv
=
(
SSmaEnv
*
)
atomic_load_ptr
(
&
pTsdb
->
pRSmaEnv
))
!=
NULL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
break
;
break
;
...
@@ -289,9 +293,10 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
...
@@ -289,9 +293,10 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
// init sma env
// init sma env
tsdbLockRepo
(
pTsdb
);
tsdbLockRepo
(
pTsdb
);
if
(
pTsdb
->
pTSmaEnv
==
NULL
)
{
pEnv
=
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_load_ptr
(
&
pTsdb
->
pTSmaEnv
)
:
atomic_load_ptr
(
&
pTsdb
->
pRSmaEnv
);
if
(
pEnv
==
NULL
)
{
char
rname
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
rname
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
aname
[
TSDB_FILENAME_LEN
*
2
+
32
]
=
{
0
};
// TODO: make TMPNAME_LEN public as TSDB_FILENAME_LEN?
char
aname
[
TSDB_FILENAME_LEN
]
=
{
0
};
// use TSDB_FILENAME_LEN currently
SDiskID
did
=
{
0
};
SDiskID
did
=
{
0
};
tfsAllocDisk
(
pTsdb
->
pTfs
,
TFS_PRIMARY_LEVEL
,
&
did
);
tfsAllocDisk
(
pTsdb
->
pTfs
,
TFS_PRIMARY_LEVEL
,
&
did
);
...
@@ -307,17 +312,13 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
...
@@ -307,17 +312,13 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
SSmaEnv
*
pEnv
=
NULL
;
if
(
tsdbInitSmaEnv
(
pTsdb
,
aname
,
&
pEnv
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tsdbInitSmaEnv
(
pTsdb
,
aname
,
&
pEnv
)
!=
TSDB_CODE_SUCCESS
)
{
tsdbUnlockRepo
(
pTsdb
);
tsdbUnlockRepo
(
pTsdb
);
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
if
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
{
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_store_ptr
(
&
pTsdb
->
pTSmaEnv
,
pEnv
)
pTsdb
->
pTSmaEnv
=
pEnv
;
:
atomic_store_ptr
(
&
pTsdb
->
pRSmaEnv
,
pEnv
);
}
else
{
pTsdb
->
pRSmaEnv
=
pEnv
;
}
}
}
tsdbUnlockRepo
(
pTsdb
);
tsdbUnlockRepo
(
pTsdb
);
...
@@ -357,8 +358,10 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, ETsdbSmaType smaType, char *msg) {
...
@@ -357,8 +358,10 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, ETsdbSmaType smaType, char *msg) {
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SHashObj
*
pItemsHash
=
SMA_ENV_STAT_ITEMS
(
pEnv
);
SHashObj
*
pItemsHash
=
SMA_ENV_STAT_ITEMS
(
pEnv
);
TASSERT
(
pEnv
!=
NULL
&&
pStat
!=
NULL
&&
pItemsHash
!=
NULL
);
tsdbRefSmaStat
(
pTsdb
,
pStat
);
tsdbRefSmaStat
(
pTsdb
,
pStat
);
SSmaStatItem
*
pItem
=
(
SSmaStatItem
*
)
taosHashGet
(
pItemsHash
,
&
indexUid
,
sizeof
(
indexUid
));
SSmaStatItem
*
pItem
=
taosHashGet
(
pItemsHash
,
&
indexUid
,
sizeof
(
indexUid
));
if
(
pItem
==
NULL
)
{
if
(
pItem
==
NULL
)
{
pItem
=
tsdbNewSmaStatItem
(
TSDB_SMA_STAT_EXPIRED
);
// TODO use the real state
pItem
=
tsdbNewSmaStatItem
(
TSDB_SMA_STAT_EXPIRED
);
// TODO use the real state
if
(
pItem
==
NULL
)
{
if
(
pItem
==
NULL
)
{
...
@@ -419,9 +422,9 @@ static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t ind
...
@@ -419,9 +422,9 @@ static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t ind
tsdbRefSmaStat
(
pTsdb
,
pStat
);
tsdbRefSmaStat
(
pTsdb
,
pStat
);
if
(
pStat
&&
pStat
->
smaStatItems
)
{
if
(
pStat
&&
pStat
->
smaStatItems
)
{
pItem
=
*
(
SSmaStatItem
**
)
taosHashGet
(
pStat
->
smaStatItems
,
&
indexUid
,
sizeof
(
indexUid
));
pItem
=
taosHashGet
(
pStat
->
smaStatItems
,
&
indexUid
,
sizeof
(
indexUid
));
}
}
if
(
pItem
!=
NULL
)
{
if
(
(
pItem
!=
NULL
)
&&
((
pItem
=
*
(
SSmaStatItem
**
)
pItem
)
!=
NULL
)
)
{
// pItem resides in hash buffer all the time unless drop sma index
// pItem resides in hash buffer all the time unless drop sma index
// TODO: multithread protect
// TODO: multithread protect
if
(
taosHashRemove
(
pItem
->
expiredWindows
,
&
skey
,
sizeof
(
TSKEY
))
!=
0
)
{
if
(
taosHashRemove
(
pItem
->
expiredWindows
,
&
skey
,
sizeof
(
TSKEY
))
!=
0
)
{
...
@@ -492,7 +495,7 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
...
@@ -492,7 +495,7 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
* @brief Insert TSma data blocks to DB File build by B+Tree
* @brief Insert TSma data blocks to DB File build by B+Tree
*
*
* @param pSmaH
* @param pSmaH
* @param smaKey
* @param smaKey
tableUid-colId-skeyOfWindow(8-2-8)
* @param keyLen
* @param keyLen
* @param pData
* @param pData
* @param dataLen
* @param dataLen
...
@@ -500,12 +503,11 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
...
@@ -500,12 +503,11 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
*/
*/
static
int32_t
tsdbInsertTSmaBlocks
(
STSmaWriteH
*
pSmaH
,
void
*
smaKey
,
uint32_t
keyLen
,
void
*
pData
,
uint32_t
dataLen
)
{
static
int32_t
tsdbInsertTSmaBlocks
(
STSmaWriteH
*
pSmaH
,
void
*
smaKey
,
uint32_t
keyLen
,
void
*
pData
,
uint32_t
dataLen
)
{
SDBFile
*
pDBFile
=
&
pSmaH
->
dFile
;
SDBFile
*
pDBFile
=
&
pSmaH
->
dFile
;
// TODO: insert sma data blocks into B+Tree
tsdbDebug
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIu16
"-%"
PRIx64
", dataLen %d"
,
tsdbDebug
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIu16
"-%"
PRIx64
", dataLen %d"
,
REPO_ID
(
pSmaH
->
pTsdb
),
pDBFile
->
path
,
*
(
tb_uid_t
*
)
smaKey
,
*
(
uint16_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
REPO_ID
(
pSmaH
->
pTsdb
),
pDBFile
->
path
,
*
(
tb_uid_t
*
)
smaKey
,
*
(
uint16_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
10
),
dataLen
);
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
10
),
dataLen
);
// TODO: insert sma data blocks into B+Tree(TDB)
if
(
tsdbSaveSmaToDB
(
pDBFile
,
smaKey
,
keyLen
,
pData
,
dataLen
)
!=
0
)
{
if
(
tsdbSaveSmaToDB
(
pDBFile
,
smaKey
,
keyLen
,
pData
,
dataLen
)
!=
0
)
{
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
...
@@ -562,34 +564,34 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit
...
@@ -562,34 +564,34 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit
return
interval
/
1e3
;
return
interval
/
1e3
;
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// nano second
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// nano second
return
interval
/
1e6
;
return
interval
/
1e6
;
}
else
{
}
else
{
// ms
return
interval
;
return
interval
;
}
}
break
;
break
;
case
TSDB_TIME_PRECISION_MICRO
:
case
TSDB_TIME_PRECISION_MICRO
:
if
(
TIME_UNIT_MICROSECOND
==
intervalUnit
)
{
// us
if
(
TIME_UNIT_MICROSECOND
==
intervalUnit
)
{
// us
return
interval
;
return
interval
;
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// n
ano second
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// n
s
return
interval
/
1e3
;
return
interval
/
1e3
;
}
else
{
}
else
{
// ms
return
interval
*
1e3
;
return
interval
*
1e3
;
}
}
break
;
break
;
case
TSDB_TIME_PRECISION_NANO
:
case
TSDB_TIME_PRECISION_NANO
:
if
(
TIME_UNIT_MICROSECOND
==
intervalUnit
)
{
if
(
TIME_UNIT_MICROSECOND
==
intervalUnit
)
{
// us
return
interval
*
1e3
;
return
interval
*
1e3
;
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// n
ano second
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// n
s
return
interval
;
return
interval
;
}
else
{
}
else
{
// ms
return
interval
*
1e6
;
return
interval
*
1e6
;
}
}
break
;
break
;
default:
// ms
default:
// ms
if
(
TIME_UNIT_MICROSECOND
==
intervalUnit
)
{
// us
if
(
TIME_UNIT_MICROSECOND
==
intervalUnit
)
{
// us
return
interval
/
1e3
;
return
interval
/
1e3
;
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// n
ano second
}
else
if
(
TIME_UNIT_NANOSECOND
==
intervalUnit
)
{
// n
s
return
interval
/
1e6
;
return
interval
/
1e6
;
}
else
{
}
else
{
// ms
return
interval
;
return
interval
;
}
}
break
;
break
;
...
@@ -661,9 +663,13 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
...
@@ -661,9 +663,13 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
static
int32_t
tsdbSetTSmaDataFile
(
STSmaWriteH
*
pSmaH
,
STSmaDataWrapper
*
pData
,
int32_t
storageLevel
,
int32_t
fid
)
{
static
int32_t
tsdbSetTSmaDataFile
(
STSmaWriteH
*
pSmaH
,
STSmaDataWrapper
*
pData
,
int32_t
storageLevel
,
int32_t
fid
)
{
STsdb
*
pTsdb
=
pSmaH
->
pTsdb
;
STsdb
*
pTsdb
=
pSmaH
->
pTsdb
;
ASSERT
(
pSmaH
->
dFile
.
path
==
NULL
&&
pSmaH
->
dFile
.
pDB
==
NULL
);
ASSERT
(
pSmaH
->
dFile
.
path
==
NULL
&&
pSmaH
->
dFile
.
pDB
==
NULL
);
pSmaH
->
dFile
.
fid
=
fid
;
char
tSmaFile
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
tSmaFile
[
TSDB_FILENAME_LEN
]
=
{
0
};
snprintf
(
tSmaFile
,
TSDB_FILENAME_LEN
,
"v%df%d.tsma"
,
REPO_ID
(
pTsdb
),
fid
);
snprintf
(
tSmaFile
,
TSDB_FILENAME_LEN
,
"v%df%d.tsma"
,
REPO_ID
(
pTsdb
),
fid
);
pSmaH
->
dFile
.
path
=
strdup
(
tSmaFile
);
pSmaH
->
dFile
.
path
=
strdup
(
tSmaFile
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -703,7 +709,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
...
@@ -703,7 +709,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
STsdbCfg
*
pCfg
=
REPO_CFG
(
pTsdb
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pTsdb
);
STSmaDataWrapper
*
pData
=
(
STSmaDataWrapper
*
)
msg
;
STSmaDataWrapper
*
pData
=
(
STSmaDataWrapper
*
)
msg
;
if
(
!
pTsdb
->
pTSmaEnv
)
{
if
(
!
atomic_load_ptr
(
&
pTsdb
->
pTSmaEnv
)
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
terrno
=
TSDB_CODE_INVALID_PTR
;
tsdbWarn
(
"vgId:%d insert tSma data failed since pTSmaEnv is NULL"
,
REPO_ID
(
pTsdb
));
tsdbWarn
(
"vgId:%d insert tSma data failed since pTSmaEnv is NULL"
,
REPO_ID
(
pTsdb
));
return
terrno
;
return
terrno
;
...
@@ -881,15 +887,15 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
...
@@ -881,15 +887,15 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
static
int32_t
tsdbGetTSmaDataImpl
(
STsdb
*
pTsdb
,
STSmaDataWrapper
*
pData
,
int64_t
indexUid
,
int64_t
interval
,
static
int32_t
tsdbGetTSmaDataImpl
(
STsdb
*
pTsdb
,
STSmaDataWrapper
*
pData
,
int64_t
indexUid
,
int64_t
interval
,
int8_t
intervalUnit
,
tb_uid_t
tableUid
,
col_id_t
colId
,
TSKEY
querySKey
,
int8_t
intervalUnit
,
tb_uid_t
tableUid
,
col_id_t
colId
,
TSKEY
querySKey
,
int32_t
nMaxResult
)
{
int32_t
nMaxResult
)
{
if
(
!
pTsdb
->
pTSmaEnv
)
{
if
(
!
atomic_load_ptr
(
&
pTsdb
->
pTSmaEnv
)
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
terrno
=
TSDB_CODE_INVALID_PTR
;
tsdbWarn
(
"vgId:%d getTSmaDataImpl failed since pTSmaEnv is NULL"
,
REPO_ID
(
pTsdb
));
tsdbWarn
(
"vgId:%d getTSmaDataImpl failed since pTSmaEnv is NULL"
,
REPO_ID
(
pTsdb
));
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
tsdbRefSmaStat
(
pTsdb
,
SMA_ENV_STAT
(
pTsdb
->
pTSmaEnv
));
tsdbRefSmaStat
(
pTsdb
,
SMA_ENV_STAT
(
pTsdb
->
pTSmaEnv
));
SSmaStatItem
*
pItem
=
*
(
SSmaStatItem
**
)
taosHashGet
(
SMA_ENV_STAT_ITEMS
(
pTsdb
->
pTSmaEnv
),
&
indexUid
,
sizeof
(
indexUid
));
SSmaStatItem
*
pItem
=
taosHashGet
(
SMA_ENV_STAT_ITEMS
(
pTsdb
->
pTSmaEnv
),
&
indexUid
,
sizeof
(
indexUid
));
if
(
pItem
==
NULL
)
{
if
(
(
pItem
==
NULL
)
||
((
pItem
=
*
(
SSmaStatItem
**
)
pItem
)
==
NULL
)
)
{
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
// it's NULL.
// it's NULL.
tsdbUnRefSmaStat
(
pTsdb
,
SMA_ENV_STAT
(
pTsdb
->
pTSmaEnv
));
tsdbUnRefSmaStat
(
pTsdb
,
SMA_ENV_STAT
(
pTsdb
->
pTSmaEnv
));
...
...
source/dnode/vnode/src/vnd/vnodeWrite.c
浏览文件 @
c56743d8
...
@@ -144,6 +144,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
...
@@ -144,6 +144,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
return
-
1
;
return
-
1
;
}
}
// record current timezone of server side
tstrncpy
(
vCreateSmaReq
.
tSma
.
timezone
,
tsTimezone
,
TD_TIMEZONE_LEN
);
if
(
metaCreateTSma
(
pVnode
->
pMeta
,
&
vCreateSmaReq
)
<
0
)
{
if
(
metaCreateTSma
(
pVnode
->
pMeta
,
&
vCreateSmaReq
)
<
0
)
{
// TODO: handle error
// TODO: handle error
tdDestroyTSma
(
&
vCreateSmaReq
.
tSma
);
tdDestroyTSma
(
&
vCreateSmaReq
.
tSma
);
...
...
source/dnode/vnode/test/tsdbSmaTest.cpp
浏览文件 @
c56743d8
...
@@ -49,7 +49,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
...
@@ -49,7 +49,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
STSmaWrapper
tSmaWrapper
=
{.
number
=
1
,
.
tSma
=
&
tSma
};
STSmaWrapper
tSmaWrapper
=
{.
number
=
1
,
.
tSma
=
&
tSma
};
uint32_t
bufLen
=
tEncodeTSmaWrapper
(
NULL
,
&
tSmaWrapper
);
uint32_t
bufLen
=
tEncodeTSmaWrapper
(
NULL
,
&
tSmaWrapper
);
void
*
buf
=
calloc
(
bufLen
,
1
);
void
*
buf
=
calloc
(
1
,
bufLen
);
ASSERT_NE
(
buf
,
nullptr
);
ASSERT_NE
(
buf
,
nullptr
);
STSmaWrapper
*
pSW
=
(
STSmaWrapper
*
)
buf
;
STSmaWrapper
*
pSW
=
(
STSmaWrapper
*
)
buf
;
...
@@ -84,6 +84,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
...
@@ -84,6 +84,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
}
}
// resource release
// resource release
tfree
(
pSW
);
tdDestroyTSma
(
&
tSma
);
tdDestroyTSma
(
&
tSma
);
tdDestroyTSmaWrapper
(
&
dstTSmaWrapper
);
tdDestroyTSmaWrapper
(
&
dstTSmaWrapper
);
}
}
...
@@ -113,7 +114,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
...
@@ -113,7 +114,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
tSma
.
tableUid
=
tbUid
;
tSma
.
tableUid
=
tbUid
;
tSma
.
exprLen
=
strlen
(
expr
);
tSma
.
exprLen
=
strlen
(
expr
);
tSma
.
expr
=
(
char
*
)
calloc
(
tSma
.
exprLen
+
1
,
1
);
tSma
.
expr
=
(
char
*
)
calloc
(
1
,
tSma
.
exprLen
+
1
);
ASSERT_NE
(
tSma
.
expr
,
nullptr
);
ASSERT_NE
(
tSma
.
expr
,
nullptr
);
tstrncpy
(
tSma
.
expr
,
expr
,
tSma
.
exprLen
+
1
);
tstrncpy
(
tSma
.
expr
,
expr
,
tSma
.
exprLen
+
1
);
...
@@ -251,12 +252,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
...
@@ -251,12 +252,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
tSma
.
tableUid
=
tbUid
;
tSma
.
tableUid
=
tbUid
;
tSma
.
exprLen
=
strlen
(
expr
);
tSma
.
exprLen
=
strlen
(
expr
);
tSma
.
expr
=
(
char
*
)
calloc
(
tSma
.
exprLen
+
1
,
1
);
tSma
.
expr
=
(
char
*
)
calloc
(
1
,
tSma
.
exprLen
+
1
);
ASSERT_NE
(
tSma
.
expr
,
nullptr
);
ASSERT_NE
(
tSma
.
expr
,
nullptr
);
tstrncpy
(
tSma
.
expr
,
expr
,
tSma
.
exprLen
+
1
);
tstrncpy
(
tSma
.
expr
,
expr
,
tSma
.
exprLen
+
1
);
tSma
.
tagsFilterLen
=
strlen
(
tagsFilter
);
tSma
.
tagsFilterLen
=
strlen
(
tagsFilter
);
tSma
.
tagsFilter
=
(
char
*
)
calloc
(
tSma
.
tagsFilterLen
+
1
,
1
);
tSma
.
tagsFilter
=
(
char
*
)
calloc
(
1
,
tSma
.
tagsFilterLen
+
1
);
ASSERT_NE
(
tSma
.
tagsFilter
,
nullptr
);
ASSERT_NE
(
tSma
.
tagsFilter
,
nullptr
);
tstrncpy
(
tSma
.
tagsFilter
,
tagsFilter
,
tSma
.
tagsFilterLen
+
1
);
tstrncpy
(
tSma
.
tagsFilter
,
tagsFilter
,
tSma
.
tagsFilterLen
+
1
);
...
@@ -273,20 +274,20 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
...
@@ -273,20 +274,20 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
// step 2: insert data
// step 2: insert data
STSmaDataWrapper
*
pSmaData
=
NULL
;
STSmaDataWrapper
*
pSmaData
=
NULL
;
STsdb
tsdb
=
{
0
}
;
STsdb
*
pTsdb
=
(
STsdb
*
)
calloc
(
1
,
sizeof
(
STsdb
))
;
STsdbCfg
*
pCfg
=
&
tsdb
.
config
;
STsdbCfg
*
pCfg
=
&
pTsdb
->
config
;
tsdb
.
pMeta
=
pMeta
;
pTsdb
->
pMeta
=
pMeta
;
tsdb
.
vgId
=
2
;
pTsdb
->
vgId
=
2
;
tsdb
.
config
.
daysPerFile
=
10
;
// default days is 10
pTsdb
->
config
.
daysPerFile
=
10
;
// default days is 10
tsdb
.
config
.
keep1
=
30
;
pTsdb
->
config
.
keep1
=
30
;
tsdb
.
config
.
keep2
=
90
;
pTsdb
->
config
.
keep2
=
90
;
tsdb
.
config
.
keep
=
365
;
pTsdb
->
config
.
keep
=
365
;
tsdb
.
config
.
precision
=
TSDB_TIME_PRECISION_MILLI
;
pTsdb
->
config
.
precision
=
TSDB_TIME_PRECISION_MILLI
;
tsdb
.
config
.
update
=
TD_ROW_OVERWRITE_UPDATE
;
pTsdb
->
config
.
update
=
TD_ROW_OVERWRITE_UPDATE
;
tsdb
.
config
.
compression
=
TWO_STAGE_COMP
;
pTsdb
->
config
.
compression
=
TWO_STAGE_COMP
;
switch
(
tsdb
.
config
.
precision
)
{
switch
(
pTsdb
->
config
.
precision
)
{
case
TSDB_TIME_PRECISION_MILLI
:
case
TSDB_TIME_PRECISION_MILLI
:
skey1
*=
1e3
;
skey1
*=
1e3
;
break
;
break
;
...
@@ -304,12 +305,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
...
@@ -304,12 +305,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
SDiskCfg
pDisks
=
{.
level
=
0
,
.
primary
=
1
};
SDiskCfg
pDisks
=
{.
level
=
0
,
.
primary
=
1
};
strncpy
(
pDisks
.
dir
,
"/var/lib/taos"
,
TSDB_FILENAME_LEN
);
strncpy
(
pDisks
.
dir
,
"/var/lib/taos"
,
TSDB_FILENAME_LEN
);
int32_t
numOfDisks
=
1
;
int32_t
numOfDisks
=
1
;
tsdb
.
pTfs
=
tfsOpen
(
&
pDisks
,
numOfDisks
);
pTsdb
->
pTfs
=
tfsOpen
(
&
pDisks
,
numOfDisks
);
ASSERT_NE
(
tsdb
.
pTfs
,
nullptr
);
ASSERT_NE
(
pTsdb
->
pTfs
,
nullptr
);
char
*
msg
=
(
char
*
)
calloc
(
1
,
100
);
char
*
msg
=
(
char
*
)
calloc
(
1
,
100
);
ASSERT_NE
(
msg
,
nullptr
);
ASSERT_NE
(
msg
,
nullptr
);
ASSERT_EQ
(
tsdbUpdateSmaWindow
(
&
t
sdb
,
TSDB_SMA_TYPE_TIME_RANGE
,
msg
),
0
);
ASSERT_EQ
(
tsdbUpdateSmaWindow
(
pT
sdb
,
TSDB_SMA_TYPE_TIME_RANGE
,
msg
),
0
);
// init
// init
int32_t
allocCnt
=
0
;
int32_t
allocCnt
=
0
;
...
@@ -367,13 +368,13 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
...
@@ -367,13 +368,13 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
ASSERT_GE
(
bufSize
,
pSmaData
->
dataLen
);
ASSERT_GE
(
bufSize
,
pSmaData
->
dataLen
);
// execute
// execute
ASSERT_EQ
(
tsdbInsertTSmaData
(
&
t
sdb
,
(
char
*
)
pSmaData
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
tsdbInsertTSmaData
(
pT
sdb
,
(
char
*
)
pSmaData
),
TSDB_CODE_SUCCESS
);
// step 3: query
// step 3: query
uint32_t
checkDataCnt
=
0
;
uint32_t
checkDataCnt
=
0
;
for
(
int32_t
t
=
0
;
t
<
numOfTables
;
++
t
)
{
for
(
int32_t
t
=
0
;
t
<
numOfTables
;
++
t
)
{
for
(
col_id_t
c
=
0
;
c
<
numOfCols
;
++
c
)
{
for
(
col_id_t
c
=
0
;
c
<
numOfCols
;
++
c
)
{
ASSERT_EQ
(
tsdbGetTSmaData
(
&
t
sdb
,
NULL
,
indexUid1
,
interval1
,
intervalUnit1
,
tbUid
+
t
,
ASSERT_EQ
(
tsdbGetTSmaData
(
pT
sdb
,
NULL
,
indexUid1
,
interval1
,
intervalUnit1
,
tbUid
+
t
,
c
+
PRIMARYKEY_TIMESTAMP_COL_ID
,
skey1
,
1
),
c
+
PRIMARYKEY_TIMESTAMP_COL_ID
,
skey1
,
1
),
TSDB_CODE_SUCCESS
);
TSDB_CODE_SUCCESS
);
++
checkDataCnt
;
++
checkDataCnt
;
...
@@ -383,9 +384,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
...
@@ -383,9 +384,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
printf
(
"%s:%d The sma data check count for insert and query is %"
PRIu32
"
\n
"
,
__FILE__
,
__LINE__
,
checkDataCnt
);
printf
(
"%s:%d The sma data check count for insert and query is %"
PRIu32
"
\n
"
,
__FILE__
,
__LINE__
,
checkDataCnt
);
// release data
// release data
tfree
(
msg
);
taosTZfree
(
buf
);
taosTZfree
(
buf
);
// release meta
// release meta
tdDestroyTSma
(
&
tSma
);
tdDestroyTSma
(
&
tSma
);
tfsClose
(
pTsdb
->
pTfs
);
tsdbClose
(
pTsdb
);
metaClose
(
pMeta
);
metaClose
(
pMeta
);
}
}
#endif
#endif
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
c56743d8
...
@@ -2349,6 +2349,9 @@ _return:
...
@@ -2349,6 +2349,9 @@ _return:
CTG_API_LEAVE
(
code
);
CTG_API_LEAVE
(
code
);
}
}
int32_t
catalogUpdateVgEpSet
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int32_t
vgId
,
SEpSet
*
epSet
)
{
}
int32_t
catalogRemoveDB
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
uint64_t
dbId
)
{
int32_t
catalogRemoveDB
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
uint64_t
dbId
)
{
CTG_API_ENTER
();
CTG_API_ENTER
();
...
@@ -2394,6 +2397,9 @@ _return:
...
@@ -2394,6 +2397,9 @@ _return:
CTG_API_LEAVE
(
code
);
CTG_API_LEAVE
(
code
);
}
}
int32_t
catalogGetIndexMeta
(
SCatalog
*
pCtg
,
void
*
pTrans
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
const
char
*
pIndexName
,
SIndexMeta
**
pIndexMeta
)
{
}
int32_t
catalogGetTableMeta
(
SCatalog
*
pCtg
,
void
*
pTrans
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
{
int32_t
catalogGetTableMeta
(
SCatalog
*
pCtg
,
void
*
pTrans
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
{
CTG_API_ENTER
();
CTG_API_ENTER
();
...
@@ -2662,12 +2668,15 @@ _return:
...
@@ -2662,12 +2668,15 @@ _return:
int32_t
catalogGetQnodeList
(
SCatalog
*
pCtg
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
SArray
*
pQnodeList
)
{
int32_t
catalogGetQnodeList
(
SCatalog
*
pCtg
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
SArray
*
pQnodeList
)
{
CTG_API_ENTER
();
CTG_API_ENTER
();
int32_t
code
=
0
;
if
(
NULL
==
pCtg
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pQnodeList
)
{
if
(
NULL
==
pCtg
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pQnodeList
)
{
CTG_API_LEAVE
(
TSDB_CODE_CTG_INVALID_INPUT
);
CTG_API_LEAVE
(
TSDB_CODE_CTG_INVALID_INPUT
);
}
}
//TODO
CTG_ERR_JRET
(
ctgGetQnodeListFromMnode
(
pCtg
,
pRpc
,
pMgmtEps
,
&
pQnodeList
));
_return:
CTG_API_LEAVE
(
TSDB_CODE_SUCCESS
);
CTG_API_LEAVE
(
TSDB_CODE_SUCCESS
);
}
}
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
c56743d8
...
@@ -190,7 +190,6 @@ static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) {
...
@@ -190,7 +190,6 @@ static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) {
}
}
static
SNode
*
logicNodeCopy
(
const
SLogicNode
*
pSrc
,
SLogicNode
*
pDst
)
{
static
SNode
*
logicNodeCopy
(
const
SLogicNode
*
pSrc
,
SLogicNode
*
pDst
)
{
COPY_SCALAR_FIELD
(
id
);
CLONE_NODE_LIST_FIELD
(
pTargets
);
CLONE_NODE_LIST_FIELD
(
pTargets
);
CLONE_NODE_FIELD
(
pConditions
);
CLONE_NODE_FIELD
(
pConditions
);
CLONE_NODE_LIST_FIELD
(
pChildren
);
CLONE_NODE_LIST_FIELD
(
pChildren
);
...
@@ -198,7 +197,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
...
@@ -198,7 +197,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
}
}
static
STableMeta
*
tableMetaClone
(
const
STableMeta
*
pSrc
)
{
static
STableMeta
*
tableMetaClone
(
const
STableMeta
*
pSrc
)
{
int32_t
len
=
sizeof
(
STableMeta
)
+
(
pSrc
->
tableInfo
.
numOfTags
+
pSrc
->
tableInfo
.
numOfColumns
)
*
sizeof
(
SSchema
);
int32_t
len
=
TABLE_META_SIZE
(
pSrc
);
STableMeta
*
pDst
=
malloc
(
len
);
STableMeta
*
pDst
=
malloc
(
len
);
if
(
NULL
==
pDst
)
{
if
(
NULL
==
pDst
)
{
return
NULL
;
return
NULL
;
...
@@ -208,7 +207,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) {
...
@@ -208,7 +207,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) {
}
}
static
SVgroupsInfo
*
vgroupsInfoClone
(
const
SVgroupsInfo
*
pSrc
)
{
static
SVgroupsInfo
*
vgroupsInfoClone
(
const
SVgroupsInfo
*
pSrc
)
{
int32_t
len
=
sizeof
(
SVgroupsInfo
)
+
pSrc
->
numOfVgroups
*
sizeof
(
SVgroupInfo
);
int32_t
len
=
VGROUPS_INFO_SIZE
(
pSrc
);
SVgroupsInfo
*
pDst
=
malloc
(
len
);
SVgroupsInfo
*
pDst
=
malloc
(
len
);
if
(
NULL
==
pDst
)
{
if
(
NULL
==
pDst
)
{
return
NULL
;
return
NULL
;
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
c56743d8
...
@@ -193,7 +193,17 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
...
@@ -193,7 +193,17 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
return
code
;
return
code
;
}
}
static
const
char
*
jkLogicPlanId
=
"Id"
;
static
int32_t
jsonToTableMeta
(
const
SJson
*
pJson
,
void
*
pObj
)
{
STableMeta
*
pNode
=
(
STableMeta
*
)
pObj
;
int32_t
code
=
tjsonGetUBigIntValue
(
pJson
,
jkTableMetaUid
,
&
pNode
->
uid
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetUBigIntValue
(
pJson
,
jkTableMetaSuid
,
&
pNode
->
suid
);
}
return
code
;
}
static
const
char
*
jkLogicPlanTargets
=
"Targets"
;
static
const
char
*
jkLogicPlanTargets
=
"Targets"
;
static
const
char
*
jkLogicPlanConditions
=
"Conditions"
;
static
const
char
*
jkLogicPlanConditions
=
"Conditions"
;
static
const
char
*
jkLogicPlanChildren
=
"Children"
;
static
const
char
*
jkLogicPlanChildren
=
"Children"
;
...
@@ -201,10 +211,7 @@ static const char* jkLogicPlanChildren = "Children";
...
@@ -201,10 +211,7 @@ static const char* jkLogicPlanChildren = "Children";
static
int32_t
logicPlanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
logicPlanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SLogicNode
*
pNode
=
(
const
SLogicNode
*
)
pObj
;
const
SLogicNode
*
pNode
=
(
const
SLogicNode
*
)
pObj
;
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkLogicPlanId
,
pNode
->
id
);
int32_t
code
=
nodeListToJson
(
pJson
,
jkLogicPlanTargets
,
pNode
->
pTargets
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkLogicPlanTargets
,
pNode
->
pTargets
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkLogicPlanConditions
,
nodeToJson
,
pNode
->
pConditions
);
code
=
tjsonAddObject
(
pJson
,
jkLogicPlanConditions
,
nodeToJson
,
pNode
->
pConditions
);
}
}
...
@@ -445,6 +452,14 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
...
@@ -445,6 +452,14 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
return
code
;
return
code
;
}
}
static
int32_t
physiStreamScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiStreamScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
static
const
char
*
jkProjectPhysiPlanProjections
=
"Projections"
;
static
const
char
*
jkProjectPhysiPlanProjections
=
"Projections"
;
static
int32_t
physiProjectNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
physiProjectNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
...
@@ -1273,6 +1288,193 @@ static int32_t jsonToFunctionNode(const SJson* pJson, void* pObj) {
...
@@ -1273,6 +1288,193 @@ static int32_t jsonToFunctionNode(const SJson* pJson, void* pObj) {
return
code
;
return
code
;
}
}
static
const
char
*
jkTableDbName
=
"DbName"
;
static
const
char
*
jkTableTableName
=
"tableName"
;
static
const
char
*
jkTableTableAlias
=
"tableAlias"
;
static
int32_t
tableNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
STableNode
*
pNode
=
(
const
STableNode
*
)
pObj
;
int32_t
code
=
exprNodeToJson
(
pObj
,
pJson
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkTableDbName
,
pNode
->
dbName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkTableTableName
,
pNode
->
tableName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkTableTableAlias
,
pNode
->
tableAlias
);
}
return
code
;
}
static
int32_t
jsonToTableNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
STableNode
*
pNode
=
(
STableNode
*
)
pObj
;
int32_t
code
=
jsonToExprNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkTableDbName
,
pNode
->
dbName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkTableTableName
,
pNode
->
tableName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkTableTableAlias
,
pNode
->
tableAlias
);
}
return
code
;
}
static
const
char
*
jkEpSetInUse
=
"InUse"
;
static
const
char
*
jkEpSetNumOfEps
=
"NumOfEps"
;
static
const
char
*
jkEpSetEps
=
"Eps"
;
static
int32_t
epSetToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SEpSet
*
pNode
=
(
const
SEpSet
*
)
pObj
;
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkEpSetInUse
,
pNode
->
inUse
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkEpSetNumOfEps
,
pNode
->
numOfEps
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddArray
(
pJson
,
jkEpSetEps
,
epToJson
,
pNode
->
eps
,
sizeof
(
SEp
),
pNode
->
numOfEps
);
}
return
code
;
}
static
int32_t
jsonToEpSet
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SEpSet
*
pNode
=
(
SEpSet
*
)
pObj
;
int32_t
code
=
tjsonGetTinyIntValue
(
pJson
,
jkEpSetInUse
,
&
pNode
->
inUse
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetTinyIntValue
(
pJson
,
jkEpSetNumOfEps
,
&
pNode
->
numOfEps
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonToArray
(
pJson
,
jkEpSetEps
,
jsonToEp
,
pNode
->
eps
,
sizeof
(
SEp
));
}
return
code
;
}
static
const
char
*
jkVgroupInfoVgId
=
"VgId"
;
static
const
char
*
jkVgroupInfoHashBegin
=
"HashBegin"
;
static
const
char
*
jkVgroupInfoHashEnd
=
"HashEnd"
;
static
const
char
*
jkVgroupInfoEpSet
=
"EpSet"
;
static
const
char
*
jkVgroupInfoNumOfTable
=
"NumOfTable"
;
static
int32_t
vgroupInfoToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SVgroupInfo
*
pNode
=
(
const
SVgroupInfo
*
)
pObj
;
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkVgroupInfoVgId
,
pNode
->
vgId
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkVgroupInfoHashBegin
,
pNode
->
hashBegin
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkVgroupInfoHashEnd
,
pNode
->
hashEnd
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkVgroupInfoEpSet
,
epSetToJson
,
&
pNode
->
epSet
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkVgroupInfoNumOfTable
,
pNode
->
numOfTable
);
}
return
code
;
}
static
int32_t
jsonToVgroupInfo
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SVgroupInfo
*
pNode
=
(
SVgroupInfo
*
)
pObj
;
int32_t
code
=
tjsonGetIntValue
(
pJson
,
jkVgroupInfoVgId
,
&
pNode
->
vgId
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetUIntValue
(
pJson
,
jkVgroupInfoHashBegin
,
&
pNode
->
hashBegin
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetUIntValue
(
pJson
,
jkVgroupInfoHashEnd
,
&
pNode
->
hashEnd
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonToObject
(
pJson
,
jkVgroupInfoEpSet
,
jsonToEpSet
,
&
pNode
->
epSet
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetIntValue
(
pJson
,
jkVgroupInfoNumOfTable
,
&
pNode
->
numOfTable
);
}
return
code
;
}
static
const
char
*
jkVgroupsInfoNum
=
"Num"
;
static
const
char
*
jkVgroupsInfoVgroups
=
"Vgroups"
;
static
int32_t
vgroupsInfoToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SVgroupsInfo
*
pNode
=
(
const
SVgroupsInfo
*
)
pObj
;
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkVgroupsInfoNum
,
pNode
->
numOfVgroups
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddArray
(
pJson
,
jkVgroupsInfoVgroups
,
vgroupInfoToJson
,
pNode
->
vgroups
,
sizeof
(
SVgroupInfo
),
pNode
->
numOfVgroups
);
}
return
code
;
}
static
int32_t
jsonToVgroupsInfo
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SVgroupsInfo
*
pNode
=
(
SVgroupsInfo
*
)
pObj
;
int32_t
code
=
tjsonGetIntValue
(
pJson
,
jkVgroupsInfoNum
,
&
pNode
->
numOfVgroups
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonToArray
(
pJson
,
jkVgroupsInfoVgroups
,
jsonToVgroupInfo
,
pNode
->
vgroups
,
sizeof
(
SVgroupInfo
));
}
return
code
;
}
static
const
char
*
jkRealTableMetaSize
=
"MetaSize"
;
static
const
char
*
jkRealTableMeta
=
"Meta"
;
static
const
char
*
jkRealTableVgroupsInfoSize
=
"VgroupsInfoSize"
;
static
const
char
*
jkRealTableVgroupsInfo
=
"VgroupsInfo"
;
static
int32_t
realTableNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SRealTableNode
*
pNode
=
(
const
SRealTableNode
*
)
pObj
;
int32_t
code
=
tableNodeToJson
(
pObj
,
pJson
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkRealTableMetaSize
,
TABLE_META_SIZE
(
pNode
->
pMeta
));
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkRealTableMeta
,
tableMetaToJson
,
pNode
->
pMeta
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkRealTableVgroupsInfoSize
,
VGROUPS_INFO_SIZE
(
pNode
->
pVgroupList
));
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkRealTableVgroupsInfo
,
vgroupsInfoToJson
,
pNode
->
pVgroupList
);
}
return
code
;
}
static
int32_t
jsonToRealTableNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SRealTableNode
*
pNode
=
(
SRealTableNode
*
)
pObj
;
int32_t
objSize
=
0
;
int32_t
code
=
jsonToTableNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetIntValue
(
pJson
,
jkRealTableMetaSize
,
&
objSize
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonMakeObject
(
pJson
,
jkRealTableMeta
,
jsonToTableMeta
,
(
void
**
)
&
pNode
->
pMeta
,
objSize
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetIntValue
(
pJson
,
jkRealTableVgroupsInfoSize
,
&
objSize
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonMakeObject
(
pJson
,
jkRealTableVgroupsInfo
,
jsonToVgroupsInfo
,
(
void
**
)
&
pNode
->
pVgroupList
,
objSize
);
}
return
code
;
}
static
const
char
*
jkGroupingSetType
=
"GroupingSetType"
;
static
const
char
*
jkGroupingSetType
=
"GroupingSetType"
;
static
const
char
*
jkGroupingSetParameter
=
"Parameters"
;
static
const
char
*
jkGroupingSetParameter
=
"Parameters"
;
...
@@ -1464,7 +1666,7 @@ static const char* jkSelectStmtSlimit = "Slimit";
...
@@ -1464,7 +1666,7 @@ static const char* jkSelectStmtSlimit = "Slimit";
static
int32_t
selectStmtTojson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
selectStmtTojson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SSelectStmt
*
pNode
=
(
const
SSelectStmt
*
)
pObj
;
const
SSelectStmt
*
pNode
=
(
const
SSelectStmt
*
)
pObj
;
int32_t
code
=
tjsonAdd
Integer
ToObject
(
pJson
,
jkSelectStmtDistinct
,
pNode
->
isDistinct
);
int32_t
code
=
tjsonAdd
Bool
ToObject
(
pJson
,
jkSelectStmtDistinct
,
pNode
->
isDistinct
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkSelectStmtProjections
,
pNode
->
pProjectionList
);
code
=
nodeListToJson
(
pJson
,
jkSelectStmtProjections
,
pNode
->
pProjectionList
);
}
}
...
@@ -1499,6 +1701,44 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
...
@@ -1499,6 +1701,44 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
return
code
;
return
code
;
}
}
static
int32_t
jsonToSelectStmt
(
const
SJson
*
pJson
,
void
*
pObj
)
{
SSelectStmt
*
pNode
=
(
SSelectStmt
*
)
pObj
;
int32_t
code
=
tjsonGetBoolValue
(
pJson
,
jkSelectStmtDistinct
,
&
pNode
->
isDistinct
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkSelectStmtProjections
,
&
pNode
->
pProjectionList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSelectStmtFrom
,
&
pNode
->
pFromTable
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSelectStmtWhere
,
&
pNode
->
pWhere
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkSelectStmtPartitionBy
,
&
pNode
->
pPartitionByList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSelectStmtWindow
,
&
pNode
->
pWindow
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkSelectStmtGroupBy
,
&
pNode
->
pGroupByList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSelectStmtHaving
,
&
pNode
->
pHaving
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkSelectStmtOrderBy
,
&
pNode
->
pOrderByList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSelectStmtLimit
,
&
pNode
->
pLimit
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkSelectStmtSlimit
,
&
pNode
->
pSlimit
);
}
return
code
;
}
static
int32_t
specificNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
specificNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
switch
(
nodeType
(
pObj
))
{
switch
(
nodeType
(
pObj
))
{
case
QUERY_NODE_COLUMN
:
case
QUERY_NODE_COLUMN
:
...
@@ -1512,6 +1752,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
...
@@ -1512,6 +1752,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case
QUERY_NODE_FUNCTION
:
case
QUERY_NODE_FUNCTION
:
return
functionNodeToJson
(
pObj
,
pJson
);
return
functionNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_REAL_TABLE
:
return
realTableNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_TEMP_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
case
QUERY_NODE_JOIN_TABLE
:
case
QUERY_NODE_JOIN_TABLE
:
break
;
break
;
...
@@ -1565,9 +1806,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
...
@@ -1565,9 +1806,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
return
physiTagScanNodeToJson
(
pObj
,
pJson
);
return
physiTagScanNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
return
physiTableScanNodeToJson
(
pObj
,
pJson
);
return
physiTableScanNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
break
;
return
physiStreamScanNodeToJson
(
pObj
,
pJson
)
;
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
return
physiProjectNodeToJson
(
pObj
,
pJson
);
return
physiProjectNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
...
@@ -1589,6 +1829,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
...
@@ -1589,6 +1829,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case
QUERY_NODE_PHYSICAL_PLAN
:
case
QUERY_NODE_PHYSICAL_PLAN
:
return
planToJson
(
pObj
,
pJson
);
return
planToJson
(
pObj
,
pJson
);
default:
default:
assert
(
0
);
break
;
break
;
}
}
nodesWarn
(
"specificNodeToJson unknown node = %s"
,
nodesNodeName
(
nodeType
(
pObj
)));
nodesWarn
(
"specificNodeToJson unknown node = %s"
,
nodesNodeName
(
nodeType
(
pObj
)));
...
@@ -1607,7 +1848,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
...
@@ -1607,7 +1848,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return
jsonToLogicConditionNode
(
pJson
,
pObj
);
return
jsonToLogicConditionNode
(
pJson
,
pObj
);
case
QUERY_NODE_FUNCTION
:
case
QUERY_NODE_FUNCTION
:
return
jsonToFunctionNode
(
pJson
,
pObj
);
return
jsonToFunctionNode
(
pJson
,
pObj
);
// case QUERY_NODE_REAL_TABLE:
case
QUERY_NODE_REAL_TABLE
:
return
jsonToRealTableNode
(
pJson
,
pObj
);
// case QUERY_NODE_TEMP_TABLE:
// case QUERY_NODE_TEMP_TABLE:
// case QUERY_NODE_JOIN_TABLE:
// case QUERY_NODE_JOIN_TABLE:
// break;
// break;
...
@@ -1633,8 +1875,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
...
@@ -1633,8 +1875,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return
jsonToDownstreamSourceNode
(
pJson
,
pObj
);
return
jsonToDownstreamSourceNode
(
pJson
,
pObj
);
// case QUERY_NODE_SET_OPERATOR:
// case QUERY_NODE_SET_OPERATOR:
// break;
// break;
//
case QUERY_NODE_SELECT_STMT:
case
QUERY_NODE_SELECT_STMT
:
//
return jsonToSelectStmt(pJson, pObj);
return
jsonToSelectStmt
(
pJson
,
pObj
);
// case QUERY_NODE_LOGIC_PLAN_SCAN:
// case QUERY_NODE_LOGIC_PLAN_SCAN:
// return jsonToLogicScanNode(pJson, pObj);
// return jsonToLogicScanNode(pJson, pObj);
// case QUERY_NODE_LOGIC_PLAN_JOIN:
// case QUERY_NODE_LOGIC_PLAN_JOIN:
...
@@ -1647,6 +1889,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
...
@@ -1647,6 +1889,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return
jsonToPhysiTagScanNode
(
pJson
,
pObj
);
return
jsonToPhysiTagScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
return
jsonToPhysiTableScanNode
(
pJson
,
pObj
);
return
jsonToPhysiTableScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
return
jsonToPhysiStreamScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
return
jsonToPhysiProjectNode
(
pJson
,
pObj
);
return
jsonToPhysiProjectNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
...
@@ -1768,6 +2012,7 @@ int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
...
@@ -1768,6 +2012,7 @@ int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
int32_t
code
=
makeNodeByJson
(
pJson
,
pNode
);
int32_t
code
=
makeNodeByJson
(
pJson
,
pNode
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesDestroyNode
(
*
pNode
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
NULL
;
terrno
=
code
;
terrno
=
code
;
return
code
;
return
code
;
}
}
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
c56743d8
...
@@ -125,6 +125,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
...
@@ -125,6 +125,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
return
makeNode
(
type
,
sizeof
(
SCreateDnodeStmt
));
return
makeNode
(
type
,
sizeof
(
SCreateDnodeStmt
));
case
QUERY_NODE_DROP_DNODE_STMT
:
case
QUERY_NODE_DROP_DNODE_STMT
:
return
makeNode
(
type
,
sizeof
(
SDropDnodeStmt
));
return
makeNode
(
type
,
sizeof
(
SDropDnodeStmt
));
case
QUERY_NODE_ALTER_DNODE_STMT
:
return
makeNode
(
type
,
sizeof
(
SAlterDnodeStmt
));
case
QUERY_NODE_SHOW_DNODES_STMT
:
case
QUERY_NODE_SHOW_DNODES_STMT
:
return
makeNode
(
type
,
sizeof
(
SShowStmt
));
return
makeNode
(
type
,
sizeof
(
SShowStmt
));
case
QUERY_NODE_SHOW_VGROUPS_STMT
:
case
QUERY_NODE_SHOW_VGROUPS_STMT
:
...
@@ -168,7 +170,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
...
@@ -168,7 +170,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN
:
return
makeNode
(
type
,
sizeof
(
STableSeqScanPhysiNode
));
return
makeNode
(
type
,
sizeof
(
STableSeqScanPhysiNode
));
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
return
makeNode
(
type
,
sizeof
(
SNode
));
return
makeNode
(
type
,
sizeof
(
S
StreamScanPhysi
Node
));
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
return
makeNode
(
type
,
sizeof
(
SProjectPhysiNode
));
return
makeNode
(
type
,
sizeof
(
SProjectPhysiNode
));
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
...
@@ -357,6 +359,17 @@ int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) {
...
@@ -357,6 +359,17 @@ int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
nodesListStrictAppendList
(
SNodeList
*
pTarget
,
SNodeList
*
pSrc
)
{
if
(
NULL
==
pSrc
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
int32_t
code
=
nodesListAppendList
(
pTarget
,
pSrc
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesDestroyList
(
pSrc
);
}
return
code
;
}
SListCell
*
nodesListErase
(
SNodeList
*
pList
,
SListCell
*
pCell
)
{
SListCell
*
nodesListErase
(
SNodeList
*
pList
,
SListCell
*
pCell
)
{
if
(
NULL
==
pCell
->
pPrev
)
{
if
(
NULL
==
pCell
->
pPrev
)
{
pList
->
pHead
=
pCell
->
pNext
;
pList
->
pHead
=
pCell
->
pNext
;
...
@@ -571,7 +584,7 @@ typedef struct SCollectFuncsCxt {
...
@@ -571,7 +584,7 @@ typedef struct SCollectFuncsCxt {
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
SCollectFuncsCxt
*
pCxt
=
(
SCollectFuncsCxt
*
)
pContext
;
SCollectFuncsCxt
*
pCxt
=
(
SCollectFuncsCxt
*
)
pContext
;
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
pCxt
->
classifier
(((
SFunctionNode
*
)
pNode
)
->
funcId
))
{
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
pCxt
->
classifier
(((
SFunctionNode
*
)
pNode
)
->
funcId
))
{
pCxt
->
errCode
=
nodesList
Append
(
pCxt
->
pFuncs
,
pNode
);
pCxt
->
errCode
=
nodesList
StrictAppend
(
pCxt
->
pFuncs
,
nodesCloneNode
(
pNode
)
);
return
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_IGNORE_CHILD
:
DEAL_RES_ERROR
);
return
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_IGNORE_CHILD
:
DEAL_RES_ERROR
);
}
}
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
c56743d8
...
@@ -50,8 +50,10 @@ typedef enum EDatabaseOptionType {
...
@@ -50,8 +50,10 @@ typedef enum EDatabaseOptionType {
DB_OPTION_TTL
,
DB_OPTION_TTL
,
DB_OPTION_WAL
,
DB_OPTION_WAL
,
DB_OPTION_VGROUPS
,
DB_OPTION_VGROUPS
,
DB_OPTION_SINGLESTABLE
,
DB_OPTION_SINGLE_STABLE
,
DB_OPTION_STREAMMODE
,
DB_OPTION_STREAM_MODE
,
DB_OPTION_RETENTIONS
,
DB_OPTION_FILE_FACTOR
,
DB_OPTION_MAX
DB_OPTION_MAX
}
EDatabaseOptionType
;
}
EDatabaseOptionType
;
...
@@ -65,6 +67,11 @@ typedef enum ETableOptionType {
...
@@ -65,6 +67,11 @@ typedef enum ETableOptionType {
TABLE_OPTION_MAX
TABLE_OPTION_MAX
}
ETableOptionType
;
}
ETableOptionType
;
typedef
struct
SAlterOption
{
int32_t
type
;
SToken
val
;
}
SAlterOption
;
extern
SToken
nil_token
;
extern
SToken
nil_token
;
void
initAstCreateContext
(
SParseContext
*
pParseCxt
,
SAstCreateContext
*
pCxt
);
void
initAstCreateContext
(
SParseContext
*
pParseCxt
,
SAstCreateContext
*
pCxt
);
...
@@ -110,13 +117,16 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
...
@@ -110,13 +117,16 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createDefaultDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createDefaultDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createDefaultAlterDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setDatabaseOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
EDatabaseOptionType
type
,
const
SToken
*
pVal
);
SNode
*
setDatabaseOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
EDatabaseOptionType
type
,
const
SToken
*
pVal
);
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createDropDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pDbName
);
SNode
*
createDropDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pDbName
);
SNode
*
createAlterDatabaseStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createAlterDatabaseStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createDefaultTableOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createDefaultTableOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createDefaultAlterTableOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
ETableOptionType
type
,
const
SToken
*
pVal
);
SNode
*
setTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
ETableOptionType
type
,
const
SToken
*
pVal
);
SNode
*
setTableSmaOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pSma
);
SNode
*
setTableSmaOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pSma
);
SNode
*
setTableRollupOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pFuncs
);
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
);
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
);
SDataType
createDataType
(
uint8_t
type
);
SDataType
createDataType
(
uint8_t
type
);
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
);
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
);
...
@@ -126,6 +136,11 @@ SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables
...
@@ -126,6 +136,11 @@ SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables
SNode
*
createDropTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createDropTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createDropTableStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pTables
);
SNode
*
createDropTableStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pTables
);
SNode
*
createDropSuperTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createDropSuperTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createAlterTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
SNode
*
pOptions
);
SNode
*
createAlterTableAddModifyCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
,
SDataType
dataType
);
SNode
*
createAlterTableDropCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
);
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pOldColName
,
const
SToken
*
pNewColName
);
SNode
*
createAlterTableSetTag
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
const
SToken
*
pTagName
,
SNode
*
pVal
);
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
);
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDbName
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDbName
);
SNode
*
createCreateUserStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pUserName
,
const
SToken
*
pPassword
);
SNode
*
createCreateUserStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pUserName
,
const
SToken
*
pPassword
);
...
@@ -133,6 +148,7 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int
...
@@ -133,6 +148,7 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int
SNode
*
createDropUserStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pUserName
);
SNode
*
createDropUserStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pUserName
);
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
);
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
);
SNode
*
createDropDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
);
SNode
*
createDropDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
);
SNode
*
createAlterDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
const
SToken
*
pIndexName
,
const
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
);
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
const
SToken
*
pIndexName
,
const
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
);
SNode
*
createIndexOption
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pFuncs
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
);
SNode
*
createIndexOption
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pFuncs
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
);
SNode
*
createDropIndexStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pIndexName
,
const
SToken
*
pTableName
);
SNode
*
createDropIndexStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pIndexName
,
const
SToken
*
pTableName
);
...
@@ -140,6 +156,7 @@ SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId);
...
@@ -140,6 +156,7 @@ SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId);
SNode
*
createDropQnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnodeId
);
SNode
*
createDropQnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnodeId
);
SNode
*
createCreateTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pTopicName
,
SNode
*
pQuery
,
const
SToken
*
pSubscribeDbName
);
SNode
*
createCreateTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pTopicName
,
SNode
*
pQuery
,
const
SToken
*
pSubscribeDbName
);
SNode
*
createDropTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pTopicName
);
SNode
*
createDropTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pTopicName
);
SNode
*
createAlterLocalStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/parser/inc/sql.y
浏览文件 @
c56743d8
...
@@ -21,13 +21,15 @@
...
@@ -21,13 +21,15 @@
#include "parAst.h"
#include "parAst.h"
}
}
%syntax_error {
%syntax_error {
if(TOKEN.z) {
if (pCxt->valid) {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
if(TOKEN.z) {
} else {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
} else {
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
}
pCxt->valid = false;
}
}
pCxt->valid = false;
}
}
%left OR.
%left OR.
...
@@ -41,6 +43,41 @@
...
@@ -41,6 +43,41 @@
%left NK_CONCAT.
%left NK_CONCAT.
//%right NK_BITNOT.
//%right NK_BITNOT.
/************************************************ create/alter account *****************************************/
cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
cmd ::= ALTER ACCOUNT NK_ID alter_account_options. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
%type account_options { int32_t }
%destructor account_options { }
account_options ::= . { }
account_options ::= account_options PPS literal. { }
account_options ::= account_options TSERIES literal. { }
account_options ::= account_options STORAGE literal. { }
account_options ::= account_options STREAMS literal. { }
account_options ::= account_options QTIME literal. { }
account_options ::= account_options DBS literal. { }
account_options ::= account_options USERS literal. { }
account_options ::= account_options CONNS literal. { }
account_options ::= account_options STATE literal. { }
%type alter_account_options { int32_t }
%destructor alter_account_options { }
alter_account_options ::= alter_account_option. { }
alter_account_options ::= alter_account_options alter_account_option. { }
%type alter_account_option { int32_t }
%destructor alter_account_option { }
alter_account_option ::= PASS literal. { }
alter_account_option ::= PPS literal. { }
alter_account_option ::= TSERIES literal. { }
alter_account_option ::= STORAGE literal. { }
alter_account_option ::= STREAMS literal. { }
alter_account_option ::= QTIME literal. { }
alter_account_option ::= DBS literal. { }
alter_account_option ::= USERS literal. { }
alter_account_option ::= CONNS literal. { }
alter_account_option ::= STATE literal. { }
/************************************************ create/alter/drop/show user *****************************************/
/************************************************ create/alter/drop/show user *****************************************/
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); }
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); }
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); }
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); }
...
@@ -48,12 +85,16 @@ cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B).
...
@@ -48,12 +85,16 @@ cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B).
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
/************************************************ create/drop/
show dnode ******
****************************************/
/************************************************ create/drop/
alter/show dnode
****************************************/
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); }
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); }
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, NULL); }
cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B) NK_STRING(C). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, &C); }
cmd ::= ALTER ALL DNODES NK_STRING(A). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, NULL); }
cmd ::= ALTER ALL DNODES NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, &B); }
%type dnode_endpoint { SToken }
%type dnode_endpoint { SToken }
%destructor dnode_endpoint { }
%destructor dnode_endpoint { }
...
@@ -64,9 +105,13 @@ dnode_endpoint(A) ::= NK_STRING(B).
...
@@ -64,9 +105,13 @@ dnode_endpoint(A) ::= NK_STRING(B).
dnode_host_name(A) ::= NK_ID(B). { A = B; }
dnode_host_name(A) ::= NK_ID(B). { A = B; }
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
/************************************************ alter local *********************************************************/
cmd ::= ALTER LOCAL NK_STRING(A). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, NULL); }
cmd ::= ALTER LOCAL NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, &B); }
/************************************************ create/drop qnode ***************************************************/
/************************************************ create/drop qnode ***************************************************/
cmd ::= CREATE QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateQnodeStmt(pCxt, &A); }
cmd ::= CREATE QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateQnodeStmt(pCxt, &A); }
cmd ::= DROP QNODE ON DNODE NK_INTEGER(A).
{ pCxt->pRootNode = createDropQnodeStmt(pCxt, &A); }
cmd ::= DROP QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropQnodeStmt(pCxt, &A); }
cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL); }
cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL); }
/************************************************ create/drop/show/use database ***************************************/
/************************************************ create/drop/show/use database ***************************************/
...
@@ -74,7 +119,7 @@ cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C).
...
@@ -74,7 +119,7 @@ cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C).
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); }
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); }
cmd ::= ALTER DATABASE db_name(A)
db_options(B).
{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); }
cmd ::= ALTER DATABASE db_name(A)
alter_db_options(B).
{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); }
%type not_exists_opt { bool }
%type not_exists_opt { bool }
%destructor not_exists_opt { }
%destructor not_exists_opt { }
...
@@ -102,20 +147,55 @@ db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C).
...
@@ -102,20 +147,55 @@ db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C).
db_options(A) ::= db_options(B) TTL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_TTL, &C); }
db_options(A) ::= db_options(B) TTL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_TTL, &C); }
db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL, &C); }
db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL, &C); }
db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); }
db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); }
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLESTABLE, &C); }
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); }
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAMMODE, &C); }
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAM_MODE, &C); }
db_options(A) ::= db_options(B) RETENTIONS NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, &C); }
db_options(A) ::= db_options(B) FILE_FACTOR NK_FLOAT(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FILE_FACTOR, &C); }
alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabaseOption(pCxt, A, B.type, &B.val); }
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseOption(pCxt, B, C.type, &C.val); }
%type alter_db_option { SAlterOption }
%destructor alter_db_option { }
alter_db_option(A) ::= BLOCKS NK_INTEGER(B). { A.type = DB_OPTION_BLOCKS; A.val = B; }
alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.val = B; }
alter_db_option(A) ::= KEEP NK_INTEGER(B). { A.type = DB_OPTION_KEEP; A.val = B; }
alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; }
alter_db_option(A) ::= QUORUM NK_INTEGER(B). { A.type = DB_OPTION_QUORUM; A.val = B; }
alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.val = B; }
/************************************************ create/drop/show table/stable ***************************************/
/************************************************ create/drop/show table/stable ***************************************/
cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B)
cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B)
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);
}
cmd ::= CREATE TABLE multi_create_clause(A). { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, A);}
cmd ::= CREATE TABLE multi_create_clause(A). { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, A);
}
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);
}
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); }
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); }
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); }
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); }
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = A; }
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableOption(pCxt, B, C); }
alter_table_clause(A) ::=
full_table_name(B) ADD COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D); }
alter_table_clause(A) ::= full_table_name(B) DROP COLUMN column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_COLUMN, &C); }
alter_table_clause(A) ::=
full_table_name(B) MODIFY COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &C, D); }
alter_table_clause(A) ::=
full_table_name(B) RENAME COLUMN column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &C, &D); }
alter_table_clause(A) ::=
full_table_name(B) ADD TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_TAG, &C, D); }
alter_table_clause(A) ::= full_table_name(B) DROP TAG column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_TAG, &C); }
alter_table_clause(A) ::=
full_table_name(B) MODIFY TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &C, D); }
alter_table_clause(A) ::=
full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); }
alter_table_clause(A) ::=
full_table_name(B) SET TAG column_name(C) NK_EQ literal(D). { A = createAlterTableSetTag(pCxt, B, &C, D); }
%type multi_create_clause { SNodeList* }
%type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); }
%destructor multi_create_clause { nodesDestroyList($$); }
multi_create_clause(A) ::= create_subtable_clause(B). { A = createNodeList(pCxt, B); }
multi_create_clause(A) ::= create_subtable_clause(B). { A = createNodeList(pCxt, B); }
...
@@ -183,11 +263,21 @@ tags_def_opt(A) ::= tags_def(B).
...
@@ -183,11 +263,21 @@ tags_def_opt(A) ::= tags_def(B).
%destructor tags_def { nodesDestroyList($$); }
%destructor tags_def { nodesDestroyList($$); }
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
table_options(A) ::= . { A = createDefaultTableOptions(pCxt);}
table_options(A) ::= . { A = createDefaultTableOptions(pCxt);
}
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &C); }
table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &C); }
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); }
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); }
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); }
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); }
table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableRollupOption(pCxt, B, C); }
alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); }
alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableOption(pCxt, B, C.type, &C.val); }
%type alter_table_option { SAlterOption }
%destructor alter_table_option { }
alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.val = B; }
alter_table_option(A) ::= KEEP NK_INTEGER(B). { A.type = TABLE_OPTION_KEEP; A.val = B; }
alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.val = B; }
%type col_name_list { SNodeList* }
%type col_name_list { SNodeList* }
%destructor col_name_list { nodesDestroyList($$); }
%destructor col_name_list { nodesDestroyList($$); }
...
@@ -196,6 +286,13 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C).
...
@@ -196,6 +286,13 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C).
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
%type func_name_list { SNodeList* }
%destructor func_name_list { nodesDestroyList($$); }
func_name_list(A) ::= func_name(B). { A = createNodeList(pCxt, B); }
func_name_list(A) ::= func_name_list(B) NK_COMMA col_name(C). { A = addNodeToList(pCxt, B, C); }
func_name(A) ::= function_name(B). { A = createFunctionNode(pCxt, &B, NULL); }
/************************************************ create index ********************************************************/
/************************************************ create index ********************************************************/
cmd ::= CREATE SMA INDEX index_name(A) ON table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &A, &B, NULL, C); }
cmd ::= CREATE SMA INDEX index_name(A) ON table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &A, &B, NULL, C); }
cmd ::= CREATE FULLTEXT INDEX
cmd ::= CREATE FULLTEXT INDEX
...
@@ -546,7 +643,7 @@ query_expression_body(A) ::=
...
@@ -546,7 +643,7 @@ query_expression_body(A) ::=
query_primary(A) ::= query_specification(B). { A = B; }
query_primary(A) ::= query_specification(B). { A = B; }
//query_primary(A) ::=
//query_primary(A) ::=
// NK_LP query_expression_body(B)
// NK_LP query_expression_body(B)
// order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B;}
// order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B;
}
%type order_by_clause_opt { SNodeList* }
%type order_by_clause_opt { SNodeList* }
%destructor order_by_clause_opt { nodesDestroyList($$); }
%destructor order_by_clause_opt { nodesDestroyList($$); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
c56743d8
...
@@ -246,6 +246,16 @@ static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptio
...
@@ -246,6 +246,16 @@ static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptio
return
pOptions
;
return
pOptions
;
}
}
static
SDatabaseOptions
*
setDbRetentions
(
SAstCreateContext
*
pCxt
,
SDatabaseOptions
*
pOptions
,
const
SToken
*
pVal
)
{
// todo
return
pOptions
;
}
static
SDatabaseOptions
*
setDbFileFactor
(
SAstCreateContext
*
pCxt
,
SDatabaseOptions
*
pOptions
,
const
SToken
*
pVal
)
{
// todo
return
pOptions
;
}
static
void
initSetDatabaseOptionFp
()
{
static
void
initSetDatabaseOptionFp
()
{
setDbOptionFuncs
[
DB_OPTION_BLOCKS
]
=
setDbBlocks
;
setDbOptionFuncs
[
DB_OPTION_BLOCKS
]
=
setDbBlocks
;
setDbOptionFuncs
[
DB_OPTION_CACHE
]
=
setDbCache
;
setDbOptionFuncs
[
DB_OPTION_CACHE
]
=
setDbCache
;
...
@@ -262,8 +272,10 @@ static void initSetDatabaseOptionFp() {
...
@@ -262,8 +272,10 @@ static void initSetDatabaseOptionFp() {
setDbOptionFuncs
[
DB_OPTION_TTL
]
=
setDbTtl
;
setDbOptionFuncs
[
DB_OPTION_TTL
]
=
setDbTtl
;
setDbOptionFuncs
[
DB_OPTION_WAL
]
=
setDbWal
;
setDbOptionFuncs
[
DB_OPTION_WAL
]
=
setDbWal
;
setDbOptionFuncs
[
DB_OPTION_VGROUPS
]
=
setDbVgroups
;
setDbOptionFuncs
[
DB_OPTION_VGROUPS
]
=
setDbVgroups
;
setDbOptionFuncs
[
DB_OPTION_SINGLESTABLE
]
=
setDbSingleStable
;
setDbOptionFuncs
[
DB_OPTION_SINGLE_STABLE
]
=
setDbSingleStable
;
setDbOptionFuncs
[
DB_OPTION_STREAMMODE
]
=
setDbStreamMode
;
setDbOptionFuncs
[
DB_OPTION_STREAM_MODE
]
=
setDbStreamMode
;
setDbOptionFuncs
[
DB_OPTION_RETENTIONS
]
=
setDbRetentions
;
setDbOptionFuncs
[
DB_OPTION_FILE_FACTOR
]
=
setDbFileFactor
;
}
}
static
STableOptions
*
setTableKeep
(
SAstCreateContext
*
pCxt
,
STableOptions
*
pOptions
,
const
SToken
*
pVal
)
{
static
STableOptions
*
setTableKeep
(
SAstCreateContext
*
pCxt
,
STableOptions
*
pOptions
,
const
SToken
*
pVal
)
{
...
@@ -772,6 +784,29 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
...
@@ -772,6 +784,29 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
return
(
SNode
*
)
pOptions
;
return
(
SNode
*
)
pOptions
;
}
}
SNode
*
createDefaultAlterDatabaseOptions
(
SAstCreateContext
*
pCxt
)
{
SDatabaseOptions
*
pOptions
=
nodesMakeNode
(
QUERY_NODE_DATABASE_OPTIONS
);
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
numOfBlocks
=
-
1
;
pOptions
->
cacheBlockSize
=
-
1
;
pOptions
->
cachelast
=
-
1
;
pOptions
->
compressionLevel
=
-
1
;
pOptions
->
daysPerFile
=
-
1
;
pOptions
->
fsyncPeriod
=
-
1
;
pOptions
->
maxRowsPerBlock
=
-
1
;
pOptions
->
minRowsPerBlock
=
-
1
;
pOptions
->
keep
=
-
1
;
pOptions
->
precision
=
-
1
;
pOptions
->
quorum
=
-
1
;
pOptions
->
replica
=
-
1
;
pOptions
->
ttl
=
-
1
;
pOptions
->
walLevel
=
-
1
;
pOptions
->
numOfVgroups
=
-
1
;
pOptions
->
singleStable
=
-
1
;
pOptions
->
streamMode
=
-
1
;
return
(
SNode
*
)
pOptions
;
}
SNode
*
setDatabaseOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
EDatabaseOptionType
type
,
const
SToken
*
pVal
)
{
SNode
*
setDatabaseOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
EDatabaseOptionType
type
,
const
SToken
*
pVal
)
{
return
(
SNode
*
)
setDbOptionFuncs
[
type
](
pCxt
,
(
SDatabaseOptions
*
)
pOptions
,
pVal
);
return
(
SNode
*
)
setDbOptionFuncs
[
type
](
pCxt
,
(
SDatabaseOptions
*
)
pOptions
,
pVal
);
}
}
...
@@ -818,6 +853,14 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
...
@@ -818,6 +853,14 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
return
(
SNode
*
)
pOptions
;
return
(
SNode
*
)
pOptions
;
}
}
SNode
*
createDefaultAlterTableOptions
(
SAstCreateContext
*
pCxt
)
{
STableOptions
*
pOptions
=
nodesMakeNode
(
QUERY_NODE_TABLE_OPTIONS
);
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
keep
=
-
1
;
pOptions
->
ttl
=
-
1
;
return
(
SNode
*
)
pOptions
;
}
SNode
*
setTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
ETableOptionType
type
,
const
SToken
*
pVal
)
{
SNode
*
setTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
ETableOptionType
type
,
const
SToken
*
pVal
)
{
return
(
SNode
*
)
setTableOptionFuncs
[
type
](
pCxt
,
(
STableOptions
*
)
pOptions
,
pVal
);
return
(
SNode
*
)
setTableOptionFuncs
[
type
](
pCxt
,
(
STableOptions
*
)
pOptions
,
pVal
);
}
}
...
@@ -827,6 +870,11 @@ SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pS
...
@@ -827,6 +870,11 @@ SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pS
return
pOptions
;
return
pOptions
;
}
}
SNode
*
setTableRollupOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SNodeList
*
pFuncs
)
{
// todo
return
pOptions
;
}
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
)
{
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
)
{
SColumnDefNode
*
pCol
=
(
SColumnDefNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN_DEF
);
SColumnDefNode
*
pCol
=
(
SColumnDefNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN_DEF
);
CHECK_OUT_OF_MEM
(
pCol
);
CHECK_OUT_OF_MEM
(
pCol
);
...
@@ -912,6 +960,49 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S
...
@@ -912,6 +960,49 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createAlterTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
SNode
*
pOptions
)
{
SAlterTableStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_TABLE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
alterType
=
TSDB_ALTER_TABLE_UPDATE_OPTIONS
;
pStmt
->
pOptions
=
(
STableOptions
*
)
pOptions
;
return
(
SNode
*
)
pStmt
;
}
SNode
*
createAlterTableAddModifyCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
,
SDataType
dataType
)
{
SAlterTableStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_TABLE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
alterType
=
alterType
;
strncpy
(
pStmt
->
colName
,
pColName
->
z
,
pColName
->
n
);
pStmt
->
dataType
=
dataType
;
return
(
SNode
*
)
pStmt
;
}
SNode
*
createAlterTableDropCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
)
{
SAlterTableStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_TABLE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
alterType
=
alterType
;
strncpy
(
pStmt
->
colName
,
pColName
->
z
,
pColName
->
n
);
return
(
SNode
*
)
pStmt
;
}
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pOldColName
,
const
SToken
*
pNewColName
)
{
SAlterTableStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_TABLE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
alterType
=
alterType
;
strncpy
(
pStmt
->
colName
,
pOldColName
->
z
,
pOldColName
->
n
);
strncpy
(
pStmt
->
newColName
,
pNewColName
->
z
,
pNewColName
->
n
);
return
(
SNode
*
)
pStmt
;
}
SNode
*
createAlterTableSetTag
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
const
SToken
*
pTagName
,
SNode
*
pVal
)
{
SAlterTableStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_TABLE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
alterType
=
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
;
strncpy
(
pStmt
->
colName
,
pTagName
->
z
,
pTagName
->
n
);
pStmt
->
pVal
=
(
SValueNode
*
)
pVal
;
return
(
SNode
*
)
pStmt
;
}
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
)
{
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
)
{
SUseDatabaseStmt
*
pStmt
=
(
SUseDatabaseStmt
*
)
nodesMakeNode
(
QUERY_NODE_USE_DATABASE_STMT
);
SUseDatabaseStmt
*
pStmt
=
(
SUseDatabaseStmt
*
)
nodesMakeNode
(
QUERY_NODE_USE_DATABASE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
CHECK_OUT_OF_MEM
(
pStmt
);
...
@@ -1009,6 +1100,17 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
...
@@ -1009,6 +1100,17 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createAlterDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
)
{
SAlterDnodeStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_DNODE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
dnodeId
=
strtol
(
pDnode
->
z
,
NULL
,
10
);
trimString
(
pConfig
->
z
,
pConfig
->
n
,
pStmt
->
config
,
sizeof
(
pStmt
->
config
));
if
(
NULL
!=
pValue
)
{
trimString
(
pValue
->
z
,
pValue
->
n
,
pStmt
->
value
,
sizeof
(
pStmt
->
value
));
}
return
(
SNode
*
)
pStmt
;
}
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
const
SToken
*
pIndexName
,
const
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
)
{
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
const
SToken
*
pIndexName
,
const
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
)
{
if
(
!
checkIndexName
(
pCxt
,
pIndexName
)
||
!
checkTableName
(
pCxt
,
pTableName
))
{
if
(
!
checkIndexName
(
pCxt
,
pIndexName
)
||
!
checkTableName
(
pCxt
,
pTableName
))
{
return
NULL
;
return
NULL
;
...
@@ -1077,3 +1179,13 @@ SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const
...
@@ -1077,3 +1179,13 @@ SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const
pStmt
->
ignoreNotExists
=
ignoreNotExists
;
pStmt
->
ignoreNotExists
=
ignoreNotExists
;
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createAlterLocalStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
)
{
SAlterLocalStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_LOCAL_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
trimString
(
pConfig
->
z
,
pConfig
->
n
,
pStmt
->
config
,
sizeof
(
pStmt
->
config
));
if
(
NULL
!=
pValue
)
{
trimString
(
pValue
->
z
,
pValue
->
n
,
pStmt
->
value
,
sizeof
(
pStmt
->
value
));
}
return
(
SNode
*
)
pStmt
;
}
source/libs/parser/src/parInsert.c
浏览文件 @
c56743d8
...
@@ -622,7 +622,7 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
...
@@ -622,7 +622,7 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
int32_t
output
=
0
;
int32_t
output
=
0
;
const
char
*
rowEnd
=
tdRowEnd
(
rb
->
pBuf
);
const
char
*
rowEnd
=
tdRowEnd
(
rb
->
pBuf
);
if
(
!
taosMbsToUcs4
(
value
,
len
,
(
char
*
)
varDataVal
(
rowEnd
),
pa
->
schema
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
if
(
!
taosMbsToUcs4
(
value
,
len
,
(
TdUcs4
*
)
varDataVal
(
rowEnd
),
pa
->
schema
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
}
varDataSetLen
(
rowEnd
,
output
);
varDataSetLen
(
rowEnd
,
output
);
...
@@ -725,7 +725,7 @@ static int32_t KvRowAppend(const void *value, int32_t len, void *param) {
...
@@ -725,7 +725,7 @@ static int32_t KvRowAppend(const void *value, int32_t len, void *param) {
}
else
if
(
TSDB_DATA_TYPE_NCHAR
==
type
)
{
}
else
if
(
TSDB_DATA_TYPE_NCHAR
==
type
)
{
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
int32_t
output
=
0
;
int32_t
output
=
0
;
if
(
!
taosMbsToUcs4
(
value
,
len
,
varDataVal
(
pa
->
buf
),
pa
->
schema
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
if
(
!
taosMbsToUcs4
(
value
,
len
,
(
TdUcs4
*
)
varDataVal
(
pa
->
buf
),
pa
->
schema
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
}
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
c56743d8
...
@@ -28,6 +28,7 @@ typedef struct SKeyword {
...
@@ -28,6 +28,7 @@ typedef struct SKeyword {
// keywords in sql string
// keywords in sql string
static
SKeyword
keywordTable
[]
=
{
static
SKeyword
keywordTable
[]
=
{
{
"ACCOUNT"
,
TK_ACCOUNT
},
{
"ALL"
,
TK_ALL
},
{
"ALL"
,
TK_ALL
},
{
"ALTER"
,
TK_ALTER
},
{
"ALTER"
,
TK_ALTER
},
{
"AND"
,
TK_AND
},
{
"AND"
,
TK_AND
},
...
@@ -168,7 +169,6 @@ static SKeyword keywordTable[] = {
...
@@ -168,7 +169,6 @@ static SKeyword keywordTable[] = {
// {"SCORES", TK_SCORES},
// {"SCORES", TK_SCORES},
// {"GRANTS", TK_GRANTS},
// {"GRANTS", TK_GRANTS},
// {"DOT", TK_DOT},
// {"DOT", TK_DOT},
// {"ACCOUNT", TK_ACCOUNT},
// {"DESCRIBE", TK_DESCRIBE},
// {"DESCRIBE", TK_DESCRIBE},
// {"SYNCDB", TK_SYNCDB},
// {"SYNCDB", TK_SYNCDB},
// {"LOCAL", TK_LOCAL},
// {"LOCAL", TK_LOCAL},
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
c56743d8
...
@@ -126,7 +126,7 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol
...
@@ -126,7 +126,7 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol
static
int32_t
createColumnNodeByTable
(
STranslateContext
*
pCxt
,
const
STableNode
*
pTable
,
SNodeList
*
pList
)
{
static
int32_t
createColumnNodeByTable
(
STranslateContext
*
pCxt
,
const
STableNode
*
pTable
,
SNodeList
*
pList
)
{
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
const
STableMeta
*
pMeta
=
((
SRealTableNode
*
)
pTable
)
->
pMeta
;
const
STableMeta
*
pMeta
=
((
SRealTableNode
*
)
pTable
)
->
pMeta
;
int32_t
nums
=
pMeta
->
tableInfo
.
numOfColumns
+
((
TSDB_SUPER_TABLE
==
pMeta
->
tableType
)
?
pMeta
->
tableInfo
.
numOfTags
:
0
);
int32_t
nums
=
pMeta
->
tableInfo
.
numOfColumns
+
((
TSDB_SUPER_TABLE
==
pMeta
->
tableType
)
?
pMeta
->
tableInfo
.
numOfTags
:
0
);
for
(
int32_t
i
=
0
;
i
<
nums
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
nums
;
++
i
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
if
(
NULL
==
pCol
)
{
...
@@ -499,6 +499,10 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
...
@@ -499,6 +499,10 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
}
}
static
int32_t
setTableVgroupList
(
SParseContext
*
pCxt
,
SName
*
name
,
SRealTableNode
*
pRealTable
)
{
static
int32_t
setTableVgroupList
(
SParseContext
*
pCxt
,
SName
*
name
,
SRealTableNode
*
pRealTable
)
{
if
(
pCxt
->
streamQuery
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
TSDB_SUPER_TABLE
==
pRealTable
->
pMeta
->
tableType
)
{
if
(
TSDB_SUPER_TABLE
==
pRealTable
->
pMeta
->
tableType
)
{
SArray
*
vgroupList
=
NULL
;
SArray
*
vgroupList
=
NULL
;
int32_t
code
=
catalogGetTableDistVgInfo
(
pCxt
->
pCatalog
,
pCxt
->
pTransporter
,
&
pCxt
->
mgmtEpSet
,
name
,
&
vgroupList
);
int32_t
code
=
catalogGetTableDistVgInfo
(
pCxt
->
pCatalog
,
pCxt
->
pTransporter
,
&
pCxt
->
mgmtEpSet
,
name
,
&
vgroupList
);
...
@@ -962,6 +966,73 @@ static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableS
...
@@ -962,6 +966,73 @@ static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableS
return
doTranslateDropSuperTable
(
pCxt
,
&
tableName
,
pStmt
->
ignoreNotExists
);
return
doTranslateDropSuperTable
(
pCxt
,
&
tableName
,
pStmt
->
ignoreNotExists
);
}
}
static
int32_t
setAlterTableField
(
SAlterTableStmt
*
pStmt
,
SMAltertbReq
*
pAlterReq
)
{
pAlterReq
->
pFields
=
taosArrayInit
(
2
,
sizeof
(
TAOS_FIELD
));
if
(
NULL
==
pAlterReq
->
pFields
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
switch
(
pStmt
->
alterType
)
{
case
TSDB_ALTER_TABLE_ADD_TAG
:
case
TSDB_ALTER_TABLE_DROP_TAG
:
case
TSDB_ALTER_TABLE_ADD_COLUMN
:
case
TSDB_ALTER_TABLE_DROP_COLUMN
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
:
case
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
:
{
TAOS_FIELD
field
=
{
.
type
=
pStmt
->
dataType
.
type
,
.
bytes
=
pStmt
->
dataType
.
bytes
};
strcpy
(
field
.
name
,
pStmt
->
colName
);
taosArrayPush
(
pAlterReq
->
pFields
,
&
field
);
break
;
}
case
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
{
TAOS_FIELD
oldField
=
{
0
};
strcpy
(
oldField
.
name
,
pStmt
->
colName
);
taosArrayPush
(
pAlterReq
->
pFields
,
&
oldField
);
TAOS_FIELD
newField
=
{
0
};
strcpy
(
oldField
.
name
,
pStmt
->
newColName
);
taosArrayPush
(
pAlterReq
->
pFields
,
&
newField
);
break
;
}
default:
break
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateAlterTable
(
STranslateContext
*
pCxt
,
SAlterTableStmt
*
pStmt
)
{
SMAltertbReq
alterReq
=
{
0
};
SName
tableName
=
{
.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
pCxt
->
pParseCxt
->
acctId
};
strcpy
(
tableName
.
dbname
,
pStmt
->
dbName
);
strcpy
(
tableName
.
tname
,
pStmt
->
tableName
);
tNameExtractFullName
(
&
tableName
,
alterReq
.
name
);
alterReq
.
alterType
=
pStmt
->
alterType
;
alterReq
.
numOfFields
=
1
;
if
(
TSDB_ALTER_TABLE_UPDATE_OPTIONS
==
pStmt
->
alterType
)
{
// todo
}
else
{
if
(
TSDB_CODE_SUCCESS
!=
setAlterTableField
(
pStmt
,
&
alterReq
))
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
pCxt
->
pCmdMsg
=
malloc
(
sizeof
(
SCmdMsgInfo
));
if
(
NULL
==
pCxt
->
pCmdMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pCxt
->
pCmdMsg
->
epSet
=
pCxt
->
pParseCxt
->
mgmtEpSet
;
pCxt
->
pCmdMsg
->
msgType
=
TDMT_MND_ALTER_STB
;
pCxt
->
pCmdMsg
->
msgLen
=
tSerializeSMAlterStbReq
(
NULL
,
0
,
&
alterReq
);
pCxt
->
pCmdMsg
->
pMsg
=
malloc
(
pCxt
->
pCmdMsg
->
msgLen
);
if
(
NULL
==
pCxt
->
pCmdMsg
->
pMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
tSerializeSMAlterStbReq
(
pCxt
->
pCmdMsg
->
pMsg
,
pCxt
->
pCmdMsg
->
msgLen
,
&
alterReq
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateUseDatabase
(
STranslateContext
*
pCxt
,
SUseDatabaseStmt
*
pStmt
)
{
static
int32_t
translateUseDatabase
(
STranslateContext
*
pCxt
,
SUseDatabaseStmt
*
pStmt
)
{
SName
name
=
{
0
};
SName
name
=
{
0
};
tNameSetDbName
(
&
name
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
strlen
(
pStmt
->
dbName
));
tNameSetDbName
(
&
name
,
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
strlen
(
pStmt
->
dbName
));
...
@@ -1099,6 +1170,28 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt
...
@@ -1099,6 +1170,28 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
translateAlterDnode
(
STranslateContext
*
pCxt
,
SAlterDnodeStmt
*
pStmt
)
{
SMCfgDnodeReq
cfgReq
=
{
0
};
cfgReq
.
dnodeId
=
pStmt
->
dnodeId
;
strcpy
(
cfgReq
.
config
,
pStmt
->
config
);
strcpy
(
cfgReq
.
value
,
pStmt
->
value
);
pCxt
->
pCmdMsg
=
malloc
(
sizeof
(
SCmdMsgInfo
));
if
(
NULL
==
pCxt
->
pCmdMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pCxt
->
pCmdMsg
->
epSet
=
pCxt
->
pParseCxt
->
mgmtEpSet
;
pCxt
->
pCmdMsg
->
msgType
=
TDMT_MND_CONFIG_DNODE
;
pCxt
->
pCmdMsg
->
msgLen
=
tSerializeSMCfgDnodeReq
(
NULL
,
0
,
&
cfgReq
);
pCxt
->
pCmdMsg
->
pMsg
=
malloc
(
pCxt
->
pCmdMsg
->
msgLen
);
if
(
NULL
==
pCxt
->
pCmdMsg
->
pMsg
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
tSerializeSMCfgDnodeReq
(
pCxt
->
pCmdMsg
->
pMsg
,
pCxt
->
pCmdMsg
->
msgLen
,
&
cfgReq
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
nodeTypeToShowType
(
ENodeType
nt
)
{
static
int32_t
nodeTypeToShowType
(
ENodeType
nt
)
{
switch
(
nt
)
{
switch
(
nt
)
{
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_DATABASES_STMT
:
...
@@ -1300,6 +1393,7 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p
...
@@ -1300,6 +1393,7 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p
SCMCreateTopicReq
createReq
=
{
0
};
SCMCreateTopicReq
createReq
=
{
0
};
if
(
NULL
!=
pStmt
->
pQuery
)
{
if
(
NULL
!=
pStmt
->
pQuery
)
{
pCxt
->
pParseCxt
->
streamQuery
=
true
;
int32_t
code
=
translateQuery
(
pCxt
,
pStmt
->
pQuery
);
int32_t
code
=
translateQuery
(
pCxt
,
pStmt
->
pQuery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesNodeToString
(
pStmt
->
pQuery
,
false
,
&
createReq
.
ast
,
NULL
);
code
=
nodesNodeToString
(
pStmt
->
pQuery
,
false
,
&
createReq
.
ast
,
NULL
);
...
@@ -1364,6 +1458,11 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt
...
@@ -1364,6 +1458,11 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
translateAlterLocal
(
STranslateContext
*
pCxt
,
SAlterLocalStmt
*
pStmt
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateQuery
(
STranslateContext
*
pCxt
,
SNode
*
pNode
)
{
static
int32_t
translateQuery
(
STranslateContext
*
pCxt
,
SNode
*
pNode
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pNode
))
{
switch
(
nodeType
(
pNode
))
{
...
@@ -1388,6 +1487,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
...
@@ -1388,6 +1487,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
code
=
translateDropSuperTable
(
pCxt
,
(
SDropSuperTableStmt
*
)
pNode
);
code
=
translateDropSuperTable
(
pCxt
,
(
SDropSuperTableStmt
*
)
pNode
);
break
;
break
;
case
QUERY_NODE_ALTER_TABLE_STMT
:
code
=
translateAlterTable
(
pCxt
,
(
SAlterTableStmt
*
)
pNode
);
break
;
case
QUERY_NODE_CREATE_USER_STMT
:
case
QUERY_NODE_CREATE_USER_STMT
:
code
=
translateCreateUser
(
pCxt
,
(
SCreateUserStmt
*
)
pNode
);
code
=
translateCreateUser
(
pCxt
,
(
SCreateUserStmt
*
)
pNode
);
break
;
break
;
...
@@ -1406,6 +1508,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
...
@@ -1406,6 +1508,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case
QUERY_NODE_DROP_DNODE_STMT
:
case
QUERY_NODE_DROP_DNODE_STMT
:
code
=
translateDropDnode
(
pCxt
,
(
SDropDnodeStmt
*
)
pNode
);
code
=
translateDropDnode
(
pCxt
,
(
SDropDnodeStmt
*
)
pNode
);
break
;
break
;
case
QUERY_NODE_ALTER_DNODE_STMT
:
code
=
translateAlterDnode
(
pCxt
,
(
SAlterDnodeStmt
*
)
pNode
);
break
;
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_STABLES_STMT
:
case
QUERY_NODE_SHOW_STABLES_STMT
:
case
QUERY_NODE_SHOW_USERS_STMT
:
case
QUERY_NODE_SHOW_USERS_STMT
:
...
@@ -1436,6 +1541,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
...
@@ -1436,6 +1541,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case
QUERY_NODE_DROP_TOPIC_STMT
:
case
QUERY_NODE_DROP_TOPIC_STMT
:
code
=
translateDropTopic
(
pCxt
,
(
SDropTopicStmt
*
)
pNode
);
code
=
translateDropTopic
(
pCxt
,
(
SDropTopicStmt
*
)
pNode
);
break
;
break
;
case
QUERY_NODE_ALTER_LOCAL_STMT
:
code
=
translateAlterLocal
(
pCxt
,
(
SAlterLocalStmt
*
)
pNode
);
break
;
default:
default:
break
;
break
;
}
}
...
@@ -1855,6 +1963,11 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
...
@@ -1855,6 +1963,11 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
return
rewriteToVnodeModifOpStmt
(
pQuery
,
pBufArray
);
return
rewriteToVnodeModifOpStmt
(
pQuery
,
pBufArray
);
}
}
static
int32_t
rewriteAlterTable
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
rewriteQuery
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
static
int32_t
rewriteQuery
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pQuery
->
pRoot
))
{
switch
(
nodeType
(
pQuery
->
pRoot
))
{
...
@@ -1866,6 +1979,11 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
...
@@ -1866,6 +1979,11 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
case
QUERY_NODE_CREATE_MULTI_TABLE_STMT
:
case
QUERY_NODE_CREATE_MULTI_TABLE_STMT
:
code
=
rewriteCreateMultiTable
(
pCxt
,
pQuery
);
code
=
rewriteCreateMultiTable
(
pCxt
,
pQuery
);
break
;
break
;
case
QUERY_NODE_ALTER_TABLE_STMT
:
if
(
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
==
((
SAlterTableStmt
*
)
pQuery
->
pRoot
)
->
alterType
)
{
code
=
rewriteAlterTable
(
pCxt
,
pQuery
);
}
break
;
default:
default:
break
;
break
;
}
}
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
c56743d8
...
@@ -46,17 +46,19 @@ static char* getSyntaxErrFormat(int32_t errCode) {
...
@@ -46,17 +46,19 @@ static char* getSyntaxErrFormat(int32_t errCode) {
case
TSDB_CODE_PAR_NOT_SINGLE_GROUP
:
case
TSDB_CODE_PAR_NOT_SINGLE_GROUP
:
return
"Not a single-group group function"
;
return
"Not a single-group group function"
;
case
TSDB_CODE_PAR_TAGS_NOT_MATCHED
:
case
TSDB_CODE_PAR_TAGS_NOT_MATCHED
:
return
"
t
ags number not matched"
;
return
"
T
ags number not matched"
;
case
TSDB_CODE_PAR_INVALID_TAG_NAME
:
case
TSDB_CODE_PAR_INVALID_TAG_NAME
:
return
"
i
nvalid tag name : %s"
;
return
"
I
nvalid tag name : %s"
;
case
TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG
:
case
TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG
:
return
"
n
ame or password too long"
;
return
"
N
ame or password too long"
;
case
TSDB_CODE_PAR_PASSWD_EMPTY
:
case
TSDB_CODE_PAR_PASSWD_EMPTY
:
return
"
p
assword can not be empty"
;
return
"
P
assword can not be empty"
;
case
TSDB_CODE_PAR_INVALID_PORT
:
case
TSDB_CODE_PAR_INVALID_PORT
:
return
"
p
ort should be an integer that is less than 65535 and greater than 0"
;
return
"
P
ort should be an integer that is less than 65535 and greater than 0"
;
case
TSDB_CODE_PAR_INVALID_ENDPOINT
:
case
TSDB_CODE_PAR_INVALID_ENDPOINT
:
return
"endpoint should be in the format of 'fqdn:port'"
;
return
"Endpoint should be in the format of 'fqdn:port'"
;
case
TSDB_CODE_PAR_EXPRIE_STATEMENT
:
return
"This statement is no longer supported"
;
case
TSDB_CODE_OUT_OF_MEMORY
:
case
TSDB_CODE_OUT_OF_MEMORY
:
return
"Out of memory"
;
return
"Out of memory"
;
default:
default:
...
...
source/libs/parser/src/sql.c
浏览文件 @
c56743d8
此差异已折叠。
点击以展开。
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
c56743d8
...
@@ -13,12 +13,11 @@
...
@@ -13,12 +13,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "mockCatalogService.h"
#include <iomanip>
#include <iomanip>
#include <iostream>
#include <iostream>
#include <map>
#include <map>
#include "tdatablock.h"
#include "tdatablock.h"
#include "mockCatalogService.h"
#include "tname.h"
#include "tname.h"
#include "ttypes.h"
#include "ttypes.h"
...
...
source/libs/parser/test/parserAstTest.cpp
浏览文件 @
c56743d8
...
@@ -302,6 +302,13 @@ TEST_F(ParserTest, createUser) {
...
@@ -302,6 +302,13 @@ TEST_F(ParserTest, createUser) {
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
}
}
TEST_F
(
ParserTest
,
alterAccount
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"alter account ac_wxy pass '123456'"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_PAR_EXPRIE_STATEMENT
));
}
TEST_F
(
ParserTest
,
createDnode
)
{
TEST_F
(
ParserTest
,
createDnode
)
{
setDatabase
(
"root"
,
"test"
);
setDatabase
(
"root"
,
"test"
);
...
@@ -312,6 +319,16 @@ TEST_F(ParserTest, createDnode) {
...
@@ -312,6 +319,16 @@ TEST_F(ParserTest, createDnode) {
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
}
}
TEST_F
(
ParserTest
,
alterDnode
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"alter dnode 1 'resetLog'"
);
ASSERT_TRUE
(
run
());
bind
(
"alter dnode 1 'debugFlag' '134'"
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
ParserTest
,
createDatabase
)
{
TEST_F
(
ParserTest
,
createDatabase
)
{
setDatabase
(
"root"
,
"test"
);
setDatabase
(
"root"
,
"test"
);
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
c56743d8
此差异已折叠。
点击以展开。
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
c56743d8
...
@@ -259,15 +259,21 @@ static SPhysiNode* createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* p
...
@@ -259,15 +259,21 @@ static SPhysiNode* createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* p
return
(
SPhysiNode
*
)
pTableScan
;
return
(
SPhysiNode
*
)
pTableScan
;
}
}
static
SPhysiNode
*
createStreamScanPhysiNode
(
SPhysiPlanContext
*
pCxt
,
SSubplan
*
pSubplan
,
SScanLogicNode
*
pScanLogicNode
)
{
SStreamScanPhysiNode
*
pTableScan
=
(
SStreamScanPhysiNode
*
)
makePhysiNode
(
pCxt
,
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
);
CHECK_ALLOC
(
pTableScan
,
NULL
);
CHECK_CODE
(
initScanPhysiNode
(
pCxt
,
pScanLogicNode
,
(
SScanPhysiNode
*
)
pTableScan
),
(
SPhysiNode
*
)
pTableScan
);
return
(
SPhysiNode
*
)
pTableScan
;
}
static
SPhysiNode
*
createScanPhysiNode
(
SPhysiPlanContext
*
pCxt
,
SSubplan
*
pSubplan
,
SScanLogicNode
*
pScanLogicNode
)
{
static
SPhysiNode
*
createScanPhysiNode
(
SPhysiPlanContext
*
pCxt
,
SSubplan
*
pSubplan
,
SScanLogicNode
*
pScanLogicNode
)
{
switch
(
pScanLogicNode
->
scanType
)
{
switch
(
pScanLogicNode
->
scanType
)
{
case
SCAN_TYPE_TAG
:
case
SCAN_TYPE_TAG
:
return
createTagScanPhysiNode
(
pCxt
,
pScanLogicNode
);
return
createTagScanPhysiNode
(
pCxt
,
pScanLogicNode
);
case
SCAN_TYPE_TABLE
:
case
SCAN_TYPE_TABLE
:
return
createTableScanPhysiNode
(
pCxt
,
pSubplan
,
pScanLogicNode
);
return
createTableScanPhysiNode
(
pCxt
,
pSubplan
,
pScanLogicNode
);
case
SCAN_TYPE_STABLE
:
case
SCAN_TYPE_STREAM
:
case
SCAN_TYPE_STREAM
:
break
;
return
createStreamScanPhysiNode
(
pCxt
,
pSubplan
,
pScanLogicNode
)
;
default:
default:
break
;
break
;
}
}
...
...
source/libs/scalar/src/filter.c
浏览文件 @
c56743d8
...
@@ -1813,7 +1813,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
...
@@ -1813,7 +1813,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
if
(
type
==
TSDB_DATA_TYPE_NCHAR
&&
if
(
type
==
TSDB_DATA_TYPE_NCHAR
&&
(
unit
->
compare
.
optr
==
OP_TYPE_MATCH
||
unit
->
compare
.
optr
==
OP_TYPE_NMATCH
)){
(
unit
->
compare
.
optr
==
OP_TYPE_MATCH
||
unit
->
compare
.
optr
==
OP_TYPE_NMATCH
)){
char
newValData
[
TSDB_REGEX_STRING_DEFAULT_LEN
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
char
newValData
[
TSDB_REGEX_STRING_DEFAULT_LEN
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
int32_t
len
=
taosUcs4ToMbs
(
varDataVal
(
fi
->
data
),
varDataLen
(
fi
->
data
),
varDataVal
(
newValData
));
int32_t
len
=
taosUcs4ToMbs
(
(
TdUcs4
*
)
varDataVal
(
fi
->
data
),
varDataLen
(
fi
->
data
),
varDataVal
(
newValData
));
if
(
len
<
0
){
if
(
len
<
0
){
qError
(
"filterInitValFieldData taosUcs4ToMbs error 1"
);
qError
(
"filterInitValFieldData taosUcs4ToMbs error 1"
);
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
...
@@ -2992,7 +2992,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa
...
@@ -2992,7 +2992,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa
if
(
info
->
cunits
[
uidx
].
dataType
==
TSDB_DATA_TYPE_NCHAR
&&
(
info
->
cunits
[
uidx
].
optr
==
OP_TYPE_MATCH
||
info
->
cunits
[
uidx
].
optr
==
OP_TYPE_NMATCH
)){
if
(
info
->
cunits
[
uidx
].
dataType
==
TSDB_DATA_TYPE_NCHAR
&&
(
info
->
cunits
[
uidx
].
optr
==
OP_TYPE_MATCH
||
info
->
cunits
[
uidx
].
optr
==
OP_TYPE_NMATCH
)){
char
*
newColData
=
calloc
(
info
->
cunits
[
uidx
].
dataSize
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
,
1
);
char
*
newColData
=
calloc
(
info
->
cunits
[
uidx
].
dataSize
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
,
1
);
int32_t
len
=
taosUcs4ToMbs
(
varDataVal
(
colData
),
varDataLen
(
colData
),
varDataVal
(
newColData
));
int32_t
len
=
taosUcs4ToMbs
(
(
TdUcs4
*
)
varDataVal
(
colData
),
varDataLen
(
colData
),
varDataVal
(
newColData
));
if
(
len
<
0
){
if
(
len
<
0
){
qError
(
"castConvert1 taosUcs4ToMbs error"
);
qError
(
"castConvert1 taosUcs4ToMbs error"
);
}
else
{
}
else
{
...
@@ -3052,7 +3052,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg
...
@@ -3052,7 +3052,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg
}
else
{
}
else
{
if
(
cunit
->
dataType
==
TSDB_DATA_TYPE_NCHAR
&&
(
cunit
->
optr
==
OP_TYPE_MATCH
||
cunit
->
optr
==
OP_TYPE_NMATCH
)){
if
(
cunit
->
dataType
==
TSDB_DATA_TYPE_NCHAR
&&
(
cunit
->
optr
==
OP_TYPE_MATCH
||
cunit
->
optr
==
OP_TYPE_NMATCH
)){
char
*
newColData
=
calloc
(
cunit
->
dataSize
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
,
1
);
char
*
newColData
=
calloc
(
cunit
->
dataSize
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
,
1
);
int32_t
len
=
taosUcs4ToMbs
(
varDataVal
(
colData
),
varDataLen
(
colData
),
varDataVal
(
newColData
));
int32_t
len
=
taosUcs4ToMbs
(
(
TdUcs4
*
)
varDataVal
(
colData
),
varDataLen
(
colData
),
varDataVal
(
newColData
));
if
(
len
<
0
){
if
(
len
<
0
){
qError
(
"castConvert1 taosUcs4ToMbs error"
);
qError
(
"castConvert1 taosUcs4ToMbs error"
);
}
else
{
}
else
{
...
@@ -3433,7 +3433,7 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
...
@@ -3433,7 +3433,7 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
varDataCopy
(
dst
,
src
);
varDataCopy
(
dst
,
src
);
continue
;
continue
;
}
}
bool
ret
=
taosMbsToUcs4
(
varDataVal
(
src
),
varDataLen
(
src
),
varDataVal
(
dst
),
bufSize
,
&
len
);
bool
ret
=
taosMbsToUcs4
(
varDataVal
(
src
),
varDataLen
(
src
),
(
TdUcs4
*
)
varDataVal
(
dst
),
bufSize
,
&
len
);
if
(
!
ret
)
{
if
(
!
ret
)
{
qError
(
"filterConverNcharColumns taosMbsToUcs4 error"
);
qError
(
"filterConverNcharColumns taosMbsToUcs4 error"
);
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
c56743d8
...
@@ -316,7 +316,7 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t
...
@@ -316,7 +316,7 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t
tmp
=
realloc
(
tmp
,
bufSize
);
tmp
=
realloc
(
tmp
,
bufSize
);
}
}
int
len
=
taosUcs4ToMbs
(
varDataVal
(
pIn
->
data
),
varDataLen
(
pIn
->
data
),
tmp
);
int
len
=
taosUcs4ToMbs
(
(
TdUcs4
*
)
varDataVal
(
pIn
->
data
),
varDataLen
(
pIn
->
data
),
tmp
);
if
(
len
<
0
){
if
(
len
<
0
){
sclError
(
"castConvert taosUcs4ToMbs error 1"
);
sclError
(
"castConvert taosUcs4ToMbs error 1"
);
tfree
(
tmp
);
tfree
(
tmp
);
...
...
source/libs/sync/inc/syncCommit.h
0 → 100644
浏览文件 @
c56743d8
/*
* 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 _TD_LIBS_SYNC_COMMIT_H
#define _TD_LIBS_SYNC_COMMIT_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "syncInt.h"
#include "taosdef.h"
// \* Leader i advances its commitIndex.
// \* This is done as a separate step from handling AppendEntries responses,
// \* in part to minimize atomic regions, and in part so that leaders of
// \* single-server clusters are able to mark entries committed.
// AdvanceCommitIndex(i) ==
// /\ state[i] = Leader
// /\ LET \* The set of servers that agree up through index.
// Agree(index) == {i} \cup {k \in Server :
// matchIndex[i][k] >= index}
// \* The maximum indexes for which a quorum agrees
// agreeIndexes == {index \in 1..Len(log[i]) :
// Agree(index) \in Quorum}
// \* New value for commitIndex'[i]
// newCommitIndex ==
// IF /\ agreeIndexes /= {}
// /\ log[i][Max(agreeIndexes)].term = currentTerm[i]
// THEN
// Max(agreeIndexes)
// ELSE
// commitIndex[i]
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
//
void
syncMaybeAdvanceCommitIndex
(
SSyncNode
*
pSyncNode
);
bool
syncAgreeIndex
(
SSyncNode
*
pSyncNode
,
SRaftId
*
pRaftId
,
SyncIndex
index
);
bool
syncAgree
(
SSyncNode
*
pSyncNode
,
SyncIndex
index
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_LIBS_SYNC_COMMIT_H*/
source/libs/sync/inc/syncInt.h
浏览文件 @
c56743d8
...
@@ -236,7 +236,6 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode);
...
@@ -236,7 +236,6 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode);
// raft vote --------------
// raft vote --------------
void
syncNodeVoteForTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
,
SRaftId
*
pRaftId
);
void
syncNodeVoteForTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
,
SRaftId
*
pRaftId
);
void
syncNodeVoteForSelf
(
SSyncNode
*
pSyncNode
);
void
syncNodeVoteForSelf
(
SSyncNode
*
pSyncNode
);
void
syncNodeMaybeAdvanceCommitIndex
(
SSyncNode
*
pSyncNode
);
// for debug --------------
// for debug --------------
void
syncNodePrint
(
SSyncNode
*
pObj
);
void
syncNodePrint
(
SSyncNode
*
pObj
);
...
...
source/libs/sync/inc/syncOnMessage.h
浏览文件 @
c56743d8
...
@@ -25,6 +25,46 @@ extern "C" {
...
@@ -25,6 +25,46 @@ extern "C" {
#include <stdlib.h>
#include <stdlib.h>
#include "taosdef.h"
#include "taosdef.h"
// TLA+ Spec
// Receive(m) ==
// LET i == m.mdest
// j == m.msource
// IN \* Any RPC with a newer term causes the recipient to advance
// \* its term first. Responses with stale terms are ignored.
// \/ UpdateTerm(i, j, m)
// \/ /\ m.mtype = RequestVoteRequest
// /\ HandleRequestVoteRequest(i, j, m)
// \/ /\ m.mtype = RequestVoteResponse
// /\ \/ DropStaleResponse(i, j, m)
// \/ HandleRequestVoteResponse(i, j, m)
// \/ /\ m.mtype = AppendEntriesRequest
// /\ HandleAppendEntriesRequest(i, j, m)
// \/ /\ m.mtype = AppendEntriesResponse
// /\ \/ DropStaleResponse(i, j, m)
// \/ HandleAppendEntriesResponse(i, j, m)
// DuplicateMessage(m) ==
// /\ Send(m)
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
// DropMessage(m) ==
// /\ Discard(m)
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
// Next == /\ \/ \E i \in Server : Restart(i)
// \/ \E i \in Server : Timeout(i)
// \/ \E i,j \in Server : RequestVote(i, j)
// \/ \E i \in Server : BecomeLeader(i)
// \/ \E i \in Server, v \in Value : ClientRequest(i, v)
// \/ \E i \in Server : AdvanceCommitIndex(i)
// \/ \E i,j \in Server : AppendEntries(i, j)
// \/ \E m \in DOMAIN messages : Receive(m)
// \/ \E m \in DOMAIN messages : DuplicateMessage(m)
// \/ \E m \in DOMAIN messages : DropMessage(m)
// \* History variable that tracks every log ever:
// /\ allLogs' = allLogs \cup {log[i] : i \in Server}
//
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
c56743d8
...
@@ -94,6 +94,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -94,6 +94,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
}
}
assert
(
pMsg
->
term
<=
ths
->
pRaftStore
->
currentTerm
);
assert
(
pMsg
->
term
<=
ths
->
pRaftStore
->
currentTerm
);
// reset elect timer
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
{
ths
->
leaderCache
=
pMsg
->
srcId
;
ths
->
leaderCache
=
pMsg
->
srcId
;
syncNodeResetElectTimer
(
ths
);
syncNodeResetElectTimer
(
ths
);
...
@@ -135,38 +136,117 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -135,38 +136,117 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_CANDIDATE
)
{
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_CANDIDATE
)
{
syncNodeBecomeFollower
(
ths
);
syncNodeBecomeFollower
(
ths
);
//
need ret
?
//
ret or reply
?
return
ret
;
return
ret
;
}
}
// accept request
// accept request
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
&&
logOK
)
{
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
&&
logOK
)
{
bool
matchSuccess
=
false
;
bool
preMatch
=
false
;
if
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
&&
if
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
&&
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
)
==
SYNC_INDEX_INVALID
)
{
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
)
==
SYNC_INDEX_INVALID
)
{
matchSuccess
=
true
;
preMatch
=
true
;
}
}
if
(
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
&&
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
if
(
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
&&
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
SSyncRaftEntry
*
pPreEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
pMsg
->
prevLogIndex
);
SSyncRaftEntry
*
pPreEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
pMsg
->
prevLogIndex
);
assert
(
pPreEntry
!=
NULL
);
assert
(
pPreEntry
!=
NULL
);
if
(
pMsg
->
prevLogTerm
==
pPreEntry
->
term
)
{
if
(
pMsg
->
prevLogTerm
==
pPreEntry
->
term
)
{
matchSuccess
=
true
;
preMatch
=
true
;
}
}
syncEntryDestory
(
pPreEntry
);
syncEntryDestory
(
pPreEntry
);
}
}
if
(
matchSuccess
)
{
if
(
preMatch
)
{
// delete conflict entries
// must has preIndex in local log
if
(
pMsg
->
prevLogIndex
<
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
assert
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
));
SyncIndex
fromIndex
=
pMsg
->
prevLogIndex
+
1
;
ths
->
pLogStore
->
truncate
(
ths
->
pLogStore
,
fromIndex
);
bool
hasExtraEntries
=
pMsg
->
prevLogIndex
<
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
);
}
bool
hasAppendEntries
=
pMsg
->
dataLen
>
0
;
if
(
hasExtraEntries
&&
hasAppendEntries
)
{
// conflict
bool
conflict
=
false
;
SyncIndex
extraIndex
=
pMsg
->
prevLogIndex
+
1
;
SSyncRaftEntry
*
pExtraEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
extraIndex
);
assert
(
pExtraEntry
!=
NULL
);
SSyncRaftEntry
*
pAppendEntry
=
syncEntryDeserialize
(
pMsg
->
data
,
pMsg
->
dataLen
);
assert
(
pAppendEntry
!=
NULL
);
assert
(
extraIndex
==
pAppendEntry
->
index
);
if
(
pExtraEntry
->
term
==
pAppendEntry
->
term
)
{
conflict
=
true
;
}
if
(
conflict
)
{
// roll back
SyncIndex
delBegin
=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
);
SyncIndex
delEnd
=
extraIndex
;
// notice! reverse roll back!
for
(
SyncIndex
index
=
delEnd
;
index
>=
delBegin
;
--
index
)
{
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
SSyncRaftEntry
*
pRollBackEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
index
);
assert
(
pRollBackEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
ths
->
pFsm
->
FpRollBackCb
(
ths
->
pFsm
,
&
rpcMsg
,
pRollBackEntry
->
index
,
pRollBackEntry
->
isWeak
,
0
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncEntryDestory
(
pRollBackEntry
);
}
}
// delete confict entries
ths
->
pLogStore
->
truncate
(
ths
->
pLogStore
,
extraIndex
);
// append new entries
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
// pre commit
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
0
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
}
// free memory
syncEntryDestory
(
pExtraEntry
);
syncEntryDestory
(
pAppendEntry
);
// append one entry
}
else
if
(
hasExtraEntries
&&
!
hasAppendEntries
)
{
if
(
pMsg
->
dataLen
>
0
)
{
// do nothing
SSyncRaftEntry
*
pEntry
=
syncEntryDeserialize
(
pMsg
->
data
,
pMsg
->
dataLen
);
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pEntry
);
}
else
if
(
!
hasExtraEntries
&&
hasAppendEntries
)
{
syncEntryDestory
(
pEntry
);
SSyncRaftEntry
*
pAppendEntry
=
syncEntryDeserialize
(
pMsg
->
data
,
pMsg
->
dataLen
);
assert
(
pAppendEntry
!=
NULL
);
// append new entries
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
// pre commit
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pAppendEntry
->
index
,
pAppendEntry
->
isWeak
,
0
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
// free memory
syncEntryDestory
(
pAppendEntry
);
}
else
if
(
!
hasExtraEntries
&&
!
hasAppendEntries
)
{
// do nothing
}
else
{
assert
(
0
);
}
}
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
();
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
();
...
@@ -175,7 +255,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -175,7 +255,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
success
=
true
;
pReply
->
success
=
true
;
if
(
pMsg
->
dataLen
>
0
)
{
if
(
hasAppendEntries
)
{
pReply
->
matchIndex
=
pMsg
->
prevLogIndex
+
1
;
pReply
->
matchIndex
=
pMsg
->
prevLogIndex
+
1
;
}
else
{
}
else
{
pReply
->
matchIndex
=
pMsg
->
prevLogIndex
;
pReply
->
matchIndex
=
pMsg
->
prevLogIndex
;
...
@@ -201,11 +281,38 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -201,11 +281,38 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
syncAppendEntriesReplyDestroy
(
pReply
);
syncAppendEntriesReplyDestroy
(
pReply
);
}
}
// maybe update commit index from leader
if
(
pMsg
->
commitIndex
>
ths
->
commitIndex
)
{
if
(
pMsg
->
commitIndex
>
ths
->
commitIndex
)
{
// has commit entry in local
if
(
pMsg
->
commitIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
if
(
pMsg
->
commitIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
// commit
SyncIndex
beginIndex
=
ths
->
commitIndex
+
1
;
SyncIndex
endIndex
=
pMsg
->
commitIndex
;
// update commit index
ths
->
commitIndex
=
pMsg
->
commitIndex
;
ths
->
commitIndex
=
pMsg
->
commitIndex
;
// call back Wal
ths
->
pLogStore
->
updateCommitIndex
(
ths
->
pLogStore
,
ths
->
commitIndex
);
ths
->
pLogStore
->
updateCommitIndex
(
ths
->
pLogStore
,
ths
->
commitIndex
);
// execute fsm
if
(
ths
->
pFsm
!=
NULL
)
{
for
(
SyncIndex
i
=
beginIndex
;
i
<=
endIndex
;
++
i
)
{
if
(
i
!=
SYNC_INDEX_INVALID
)
{
SSyncRaftEntry
*
pEntry
=
ths
->
pLogStore
->
getEntry
(
ths
->
pLogStore
,
i
);
assert
(
pEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
)
{
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
);
}
rpcFreeCont
(
rpcMsg
.
pCont
);
syncEntryDestory
(
pEntry
);
}
}
}
}
}
}
}
}
}
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
c56743d8
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
*/
*/
#include "syncAppendEntriesReply.h"
#include "syncAppendEntriesReply.h"
#include "syncCommit.h"
#include "syncIndexMgr.h"
#include "syncIndexMgr.h"
#include "syncInt.h"
#include "syncInt.h"
#include "syncRaftLog.h"
#include "syncRaftLog.h"
...
@@ -59,7 +60,7 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
...
@@ -59,7 +60,7 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
// maybe commit
// maybe commit
sync
Node
MaybeAdvanceCommitIndex
(
ths
);
syncMaybeAdvanceCommitIndex
(
ths
);
}
else
{
}
else
{
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
c56743d8
...
@@ -13,9 +13,12 @@
...
@@ -13,9 +13,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "syncCommit.h"
#include "syncIndexMgr.h"
#include "syncIndexMgr.h"
#include "syncInt.h"
#include "syncInt.h"
#include "syncRaftLog.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
// \* Leader i advances its commitIndex.
// \* Leader i advances its commitIndex.
// \* This is done as a separate step from handling AppendEntries responses,
// \* This is done as a separate step from handling AppendEntries responses,
...
@@ -40,28 +43,86 @@
...
@@ -40,28 +43,86 @@
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
//
//
void
sync
Node
MaybeAdvanceCommitIndex
(
SSyncNode
*
pSyncNode
)
{
void
syncMaybeAdvanceCommitIndex
(
SSyncNode
*
pSyncNode
)
{
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pNextIndex"
,
pSyncNode
->
pNextIndex
);
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pNextIndex"
,
pSyncNode
->
pNextIndex
);
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pMatchIndex"
,
pSyncNode
->
pMatchIndex
);
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pMatchIndex"
,
pSyncNode
->
pMatchIndex
);
// update commit index
// update commit index
SyncIndex
newCommitIndex
=
pSyncNode
->
commitIndex
;
if
(
pSyncNode
->
pFsm
!=
NULL
)
{
for
(
SyncIndex
index
=
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
);
index
>
pSyncNode
->
commitIndex
;
SyncIndex
beginIndex
=
SYNC_INDEX_INVALID
;
++
index
)
{
SyncIndex
endIndex
=
SYNC_INDEX_INVALID
;
bool
agree
=
syncAgree
(
pSyncNode
,
index
);
for
(
SyncIndex
i
=
beginIndex
;
i
<=
endIndex
;
++
i
)
{
if
(
agree
)
{
SSyncRaftEntry
*
pEntry
=
pSyncNode
->
pLogStore
->
getEntry
(
pSyncNode
->
pLogStore
,
i
);
// term
SSyncRaftEntry
*
pEntry
=
pSyncNode
->
pLogStore
->
getEntry
(
pSyncNode
->
pLogStore
,
index
);
assert
(
pEntry
!=
NULL
);
assert
(
pEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
// cannot commit, even if quorum agree. need check term!
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
pEntry
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
// update commit index
newCommitIndex
=
index
;
break
;
}
}
}
if
(
newCommitIndex
>
pSyncNode
->
commitIndex
)
{
SyncIndex
beginIndex
=
pSyncNode
->
commitIndex
+
1
;
SyncIndex
endIndex
=
newCommitIndex
;
// update commit index
pSyncNode
->
commitIndex
=
newCommitIndex
;
// call back Wal
pSyncNode
->
pLogStore
->
updateCommitIndex
(
pSyncNode
->
pLogStore
,
pSyncNode
->
commitIndex
);
// execute fsm
if
(
pSyncNode
->
pFsm
!=
NULL
)
{
for
(
SyncIndex
i
=
beginIndex
;
i
<=
endIndex
;
++
i
)
{
if
(
i
!=
SYNC_INDEX_INVALID
)
{
SSyncRaftEntry
*
pEntry
=
pSyncNode
->
pLogStore
->
getEntry
(
pSyncNode
->
pLogStore
,
i
);
assert
(
pEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
pSyncNode
->
pFsm
->
FpCommitCb
!=
NULL
)
{
if
(
pSyncNode
->
pFsm
->
FpCommitCb
!=
NULL
)
{
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
);
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
pEntry
->
index
,
pEntry
->
isWeak
,
0
);
}
rpcFreeCont
(
rpcMsg
.
pCont
);
syncEntryDestory
(
pEntry
);
}
}
}
}
}
}
bool
syncAgreeIndex
(
SSyncNode
*
pSyncNode
,
SRaftId
*
pRaftId
,
SyncIndex
index
)
{
// I am leader, I agree
if
(
syncUtilSameId
(
pRaftId
,
&
(
pSyncNode
->
myRaftId
))
&&
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
return
true
;
}
rpcFreeCont
(
rpcMsg
.
pCont
);
// follower agree
syncEntryDestory
(
pEntry
);
SyncIndex
matchIndex
=
syncIndexMgrGetIndex
(
pSyncNode
->
pMatchIndex
,
pRaftId
);
if
(
matchIndex
>=
index
)
{
return
true
;
}
// not agree
return
false
;
}
bool
syncAgree
(
SSyncNode
*
pSyncNode
,
SyncIndex
index
)
{
int
agreeCount
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
if
(
syncAgreeIndex
(
pSyncNode
,
&
(
pSyncNode
->
replicasId
[
i
]),
index
))
{
++
agreeCount
;
}
if
(
agreeCount
>=
pSyncNode
->
quorum
)
{
return
true
;
}
}
}
}
return
false
;
}
}
\ No newline at end of file
source/libs/sync/src/syncMain.c
浏览文件 @
c56743d8
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include "sync.h"
#include "sync.h"
#include "syncAppendEntries.h"
#include "syncAppendEntries.h"
#include "syncAppendEntriesReply.h"
#include "syncAppendEntriesReply.h"
#include "syncCommit.h"
#include "syncElection.h"
#include "syncElection.h"
#include "syncEnv.h"
#include "syncEnv.h"
#include "syncIndexMgr.h"
#include "syncIndexMgr.h"
...
@@ -59,11 +60,14 @@ int64_t syncStart(const SSyncInfo* pSyncInfo) {
...
@@ -59,11 +60,14 @@ int64_t syncStart(const SSyncInfo* pSyncInfo) {
int32_t
ret
=
0
;
int32_t
ret
=
0
;
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
pSyncInfo
);
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
pSyncInfo
);
assert
(
pSyncNode
!=
NULL
);
assert
(
pSyncNode
!=
NULL
);
// todo : return ref id
return
ret
;
return
ret
;
}
}
void
syncStop
(
int64_t
rid
)
{
void
syncStop
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
NULL
;
// get pointer from rid
// todo : get pointer from rid
SSyncNode
*
pSyncNode
=
NULL
;
syncNodeClose
(
pSyncNode
);
syncNodeClose
(
pSyncNode
);
}
}
...
@@ -73,8 +77,10 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) {
...
@@ -73,8 +77,10 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) {
}
}
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
SSyncNode
*
pSyncNode
=
NULL
;
// get pointer from rid
// todo : get pointer from rid
SSyncNode
*
pSyncNode
=
NULL
;
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
SyncClientRequest
*
pSyncMsg
=
syncClientRequestBuild2
(
pMsg
,
0
,
isWeak
);
SyncClientRequest
*
pSyncMsg
=
syncClientRequestBuild2
(
pMsg
,
0
,
isWeak
);
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
...
@@ -85,13 +91,14 @@ int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
...
@@ -85,13 +91,14 @@ int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
}
else
{
}
else
{
sTrace
(
"syncForwardToPeer not leader, %s"
,
syncUtilState2String
(
pSyncNode
->
state
));
sTrace
(
"syncForwardToPeer not leader, %s"
,
syncUtilState2String
(
pSyncNode
->
state
));
ret
=
-
1
;
// need define err code !!
ret
=
-
1
;
//
todo :
need define err code !!
}
}
return
ret
;
return
ret
;
}
}
ESyncState
syncGetMyRole
(
int64_t
rid
)
{
ESyncState
syncGetMyRole
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
NULL
;
// get pointer from rid
// todo : get pointer from rid
SSyncNode
*
pSyncNode
=
NULL
;
return
pSyncNode
->
state
;
return
pSyncNode
->
state
;
}
}
...
@@ -150,6 +157,30 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
...
@@ -150,6 +157,30 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
// init life cycle
// init life cycle
// TLA+ Spec
// InitHistoryVars == /\ elections = {}
// /\ allLogs = {}
// /\ voterLog = [i \in Server |-> [j \in {} |-> <<>>]]
// InitServerVars == /\ currentTerm = [i \in Server |-> 1]
// /\ state = [i \in Server |-> Follower]
// /\ votedFor = [i \in Server |-> Nil]
// InitCandidateVars == /\ votesResponded = [i \in Server |-> {}]
// /\ votesGranted = [i \in Server |-> {}]
// \* The values nextIndex[i][i] and matchIndex[i][i] are never read, since the
// \* leader does not send itself messages. It's still easier to include these
// \* in the functions.
// InitLeaderVars == /\ nextIndex = [i \in Server |-> [j \in Server |-> 1]]
// /\ matchIndex = [i \in Server |-> [j \in Server |-> 0]]
// InitLogVars == /\ log = [i \in Server |-> << >>]
// /\ commitIndex = [i \in Server |-> 0]
// Init == /\ messages = [m \in {} |-> 0]
// /\ InitHistoryVars
// /\ InitServerVars
// /\ InitCandidateVars
// /\ InitLeaderVars
// /\ InitLogVars
//
// init TLA+ server vars
// init TLA+ server vars
pSyncNode
->
state
=
TAOS_SYNC_STATE_FOLLOWER
;
pSyncNode
->
state
=
TAOS_SYNC_STATE_FOLLOWER
;
pSyncNode
->
pRaftStore
=
raftStoreOpen
(
pSyncNode
->
raftStorePath
);
pSyncNode
->
pRaftStore
=
raftStoreOpen
(
pSyncNode
->
raftStorePath
);
...
@@ -170,7 +201,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
...
@@ -170,7 +201,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
// init TLA+ log vars
// init TLA+ log vars
pSyncNode
->
pLogStore
=
logStoreCreate
(
pSyncNode
);
pSyncNode
->
pLogStore
=
logStoreCreate
(
pSyncNode
);
assert
(
pSyncNode
->
pLogStore
!=
NULL
);
assert
(
pSyncNode
->
pLogStore
!=
NULL
);
pSyncNode
->
commitIndex
=
0
;
pSyncNode
->
commitIndex
=
SYNC_INDEX_INVALID
;
// init ping timer
// init ping timer
pSyncNode
->
pPingTimer
=
NULL
;
pSyncNode
->
pPingTimer
=
NULL
;
...
@@ -727,6 +758,16 @@ static int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
...
@@ -727,6 +758,16 @@ static int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
return
ret
;
return
ret
;
}
}
// TLA+ Spec
// ClientRequest(i, v) ==
// /\ state[i] = Leader
// /\ LET entry == [term |-> currentTerm[i],
// value |-> v]
// newLog == Append(log[i], entry)
// IN log' = [log EXCEPT ![i] = newLog]
// /\ UNCHANGED <<messages, serverVars, candidateVars,
// leaderVars, commitIndex>>
//
static
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
)
{
static
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
syncClientRequestLog2
(
"==syncNodeOnClientRequestCb=="
,
pMsg
);
syncClientRequestLog2
(
"==syncNodeOnClientRequestCb=="
,
pMsg
);
...
@@ -739,9 +780,6 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
...
@@ -739,9 +780,6 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pEntry
);
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pEntry
);
// only myself, maybe commit
syncNodeMaybeAdvanceCommitIndex
(
ths
);
// start replicate right now!
// start replicate right now!
syncNodeReplicate
(
ths
);
syncNodeReplicate
(
ths
);
...
@@ -756,6 +794,9 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
...
@@ -756,6 +794,9 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
rpcFreeCont
(
rpcMsg
.
pCont
);
// only myself, maybe commit
syncMaybeAdvanceCommitIndex
(
ths
);
}
else
{
}
else
{
// pre commit
// pre commit
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
...
...
source/libs/sync/src/syncOnMessage.c
浏览文件 @
c56743d8
...
@@ -14,3 +14,43 @@
...
@@ -14,3 +14,43 @@
*/
*/
#include "syncOnMessage.h"
#include "syncOnMessage.h"
// TLA+ Spec
// Receive(m) ==
// LET i == m.mdest
// j == m.msource
// IN \* Any RPC with a newer term causes the recipient to advance
// \* its term first. Responses with stale terms are ignored.
// \/ UpdateTerm(i, j, m)
// \/ /\ m.mtype = RequestVoteRequest
// /\ HandleRequestVoteRequest(i, j, m)
// \/ /\ m.mtype = RequestVoteResponse
// /\ \/ DropStaleResponse(i, j, m)
// \/ HandleRequestVoteResponse(i, j, m)
// \/ /\ m.mtype = AppendEntriesRequest
// /\ HandleAppendEntriesRequest(i, j, m)
// \/ /\ m.mtype = AppendEntriesResponse
// /\ \/ DropStaleResponse(i, j, m)
// \/ HandleAppendEntriesResponse(i, j, m)
// DuplicateMessage(m) ==
// /\ Send(m)
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
// DropMessage(m) ==
// /\ Discard(m)
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
// Next == /\ \/ \E i \in Server : Restart(i)
// \/ \E i \in Server : Timeout(i)
// \/ \E i,j \in Server : RequestVote(i, j)
// \/ \E i \in Server : BecomeLeader(i)
// \/ \E i \in Server, v \in Value : ClientRequest(i, v)
// \/ \E i \in Server : AdvanceCommitIndex(i)
// \/ \E i,j \in Server : AppendEntries(i, j)
// \/ \E m \in DOMAIN messages : Receive(m)
// \/ \E m \in DOMAIN messages : DuplicateMessage(m)
// \/ \E m \in DOMAIN messages : DropMessage(m)
// \* History variable that tracks every log ever:
// /\ allLogs' = allLogs \cup {log[i] : i \in Server}
//
\ No newline at end of file
source/libs/sync/test/CMakeLists.txt
浏览文件 @
c56743d8
...
@@ -29,6 +29,8 @@ add_executable(syncPingTimerTest2 "")
...
@@ -29,6 +29,8 @@ add_executable(syncPingTimerTest2 "")
add_executable
(
syncPingSelfTest
""
)
add_executable
(
syncPingSelfTest
""
)
add_executable
(
syncElectTest
""
)
add_executable
(
syncElectTest
""
)
add_executable
(
syncEncodeTest
""
)
add_executable
(
syncEncodeTest
""
)
add_executable
(
syncWriteTest
""
)
add_executable
(
syncReplicateTest
""
)
target_sources
(
syncTest
target_sources
(
syncTest
...
@@ -155,6 +157,14 @@ target_sources(syncEncodeTest
...
@@ -155,6 +157,14 @@ target_sources(syncEncodeTest
PRIVATE
PRIVATE
"syncEncodeTest.cpp"
"syncEncodeTest.cpp"
)
)
target_sources
(
syncWriteTest
PRIVATE
"syncWriteTest.cpp"
)
target_sources
(
syncReplicateTest
PRIVATE
"syncReplicateTest.cpp"
)
target_include_directories
(
syncTest
target_include_directories
(
syncTest
...
@@ -317,6 +327,16 @@ target_include_directories(syncEncodeTest
...
@@ -317,6 +327,16 @@ target_include_directories(syncEncodeTest
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
)
target_include_directories
(
syncWriteTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncReplicateTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
target_link_libraries
(
syncTest
...
@@ -443,6 +463,14 @@ target_link_libraries(syncEncodeTest
...
@@ -443,6 +463,14 @@ target_link_libraries(syncEncodeTest
sync
sync
gtest_main
gtest_main
)
)
target_link_libraries
(
syncWriteTest
sync
gtest_main
)
target_link_libraries
(
syncReplicateTest
sync
gtest_main
)
enable_testing
()
enable_testing
()
...
...
source/libs/sync/test/syncEncodeTest.cpp
浏览文件 @
c56743d8
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
#include "syncRaftLog.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
#include "syncUtil.h"
#include "syncRaftLog.h"
void
logTest
()
{
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sTrace
(
"--- sync log test: trace"
);
...
@@ -25,11 +24,11 @@ int32_t myIndex = 0;
...
@@ -25,11 +24,11 @@ int32_t myIndex = 0;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SSyncInfo
syncInfo
;
SSyncInfo
syncInfo
;
SSyncFSM
*
pFsm
;
SSyncFSM
*
pFsm
;
SWal
*
pWal
;
SWal
*
pWal
;
SSyncNode
*
pSyncNode
;
SSyncNode
*
pSyncNode
;
SSyncNode
*
syncNodeInit
()
{
SSyncNode
*
syncNodeInit
()
{
syncInfo
.
vgId
=
1234
;
syncInfo
.
vgId
=
1234
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
...
@@ -54,7 +53,7 @@ SSyncNode* syncNodeInit() {
...
@@ -54,7 +53,7 @@ SSyncNode* syncNodeInit() {
syncInfo
.
pWal
=
pWal
;
syncInfo
.
pWal
=
pWal
;
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
pCfg
->
myIndex
=
myIndex
;
pCfg
->
replicaNum
=
replicaNum
;
pCfg
->
replicaNum
=
replicaNum
;
...
@@ -81,43 +80,12 @@ SSyncNode* syncNodeInit() {
...
@@ -81,43 +80,12 @@ SSyncNode* syncNodeInit() {
return
pSyncNode
;
return
pSyncNode
;
}
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
logStoreTest
()
{
logStorePrint2
((
char
*
)
"logStoreTest"
,
pSyncNode
->
pLogStore
);
assert
(
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
==
SYNC_INDEX_INVALID
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
int32_t
dataLen
=
10
;
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
dataLen
);
assert
(
pEntry
!=
NULL
);
pEntry
->
msgType
=
1
;
pEntry
->
originalRpcType
=
2
;
pEntry
->
seqNum
=
3
;
pEntry
->
isWeak
=
true
;
pEntry
->
term
=
100
;
pEntry
->
index
=
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
+
1
;
snprintf
(
pEntry
->
data
,
dataLen
,
"value%d"
,
i
);
// syncEntryPrint2((char*)"write entry:", pEntry);
pSyncNode
->
pLogStore
->
appendEntry
(
pSyncNode
->
pLogStore
,
pEntry
);
syncEntryDestory
(
pEntry
);
if
(
i
==
0
)
{
assert
(
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
==
SYNC_INDEX_BEGIN
);
}
}
logStorePrint2
((
char
*
)
"after appendEntry"
,
pSyncNode
->
pLogStore
);
pSyncNode
->
pLogStore
->
truncate
(
pSyncNode
->
pLogStore
,
3
);
logStorePrint2
((
char
*
)
"after truncate 3"
,
pSyncNode
->
pLogStore
);
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
free
(
s
);
free
(
s
);
}
}
...
@@ -181,7 +149,7 @@ int main(int argc, char **argv) {
...
@@ -181,7 +149,7 @@ int main(int argc, char **argv) {
myIndex
=
atoi
(
argv
[
1
]);
myIndex
=
atoi
(
argv
[
1
]);
}
}
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]);
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]);
assert
(
ret
==
0
);
assert
(
ret
==
0
);
ret
=
syncEnvStart
();
ret
=
syncEnvStart
();
...
@@ -210,7 +178,7 @@ int main(int argc, char **argv) {
...
@@ -210,7 +178,7 @@ int main(int argc, char **argv) {
syncEntryPrint2
((
char
*
)
"==step4=="
,
pMsg4
);
syncEntryPrint2
((
char
*
)
"==step4=="
,
pMsg4
);
// log, relog
// log, relog
SSyncNode
*
pSyncNode
=
syncNodeInit
();
SSyncNode
*
pSyncNode
=
syncNodeInit
();
assert
(
pSyncNode
!=
NULL
);
assert
(
pSyncNode
!=
NULL
);
SSyncRaftEntry
*
pEntry
=
pMsg4
;
SSyncRaftEntry
*
pEntry
=
pMsg4
;
pSyncNode
->
pLogStore
->
appendEntry
(
pSyncNode
->
pLogStore
,
pEntry
);
pSyncNode
->
pLogStore
->
appendEntry
(
pSyncNode
->
pLogStore
,
pEntry
);
...
...
source/libs/sync/test/syncReplicateTest.cpp
0 → 100644
浏览文件 @
c56743d8
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
uint16_t
ports
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
int32_t
replicaNum
=
3
;
int32_t
myIndex
=
0
;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SSyncInfo
syncInfo
;
SSyncFSM
*
pFsm
;
SWal
*
pWal
;
SSyncNode
*
gSyncNode
;
SSyncNode
*
syncNodeInit
()
{
syncInfo
.
vgId
=
1234
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
queue
=
gSyncIO
->
pMsgQ
;
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"./elect_test_%d"
,
myIndex
);
int
code
=
walInit
();
assert
(
code
==
0
);
SWalCfg
walCfg
;
memset
(
&
walCfg
,
0
,
sizeof
(
SWalCfg
));
walCfg
.
vgId
=
syncInfo
.
vgId
;
walCfg
.
fsyncPeriod
=
1000
;
walCfg
.
retentionPeriod
=
1000
;
walCfg
.
rollPeriod
=
1000
;
walCfg
.
retentionSize
=
1000
;
walCfg
.
segSize
=
1000
;
walCfg
.
level
=
TAOS_WAL_FSYNC
;
char
tmpdir
[
128
];
snprintf
(
tmpdir
,
sizeof
(
tmpdir
),
"./elect_test_wal_%d"
,
myIndex
);
pWal
=
walOpen
(
tmpdir
,
&
walCfg
);
assert
(
pWal
!=
NULL
);
syncInfo
.
pWal
=
pWal
;
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
pCfg
->
replicaNum
=
replicaNum
;
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
pCfg
->
nodeInfo
[
i
].
nodePort
=
ports
[
i
];
snprintf
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
,
sizeof
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
),
"%s"
,
"127.0.0.1"
);
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
}
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
&
syncInfo
);
assert
(
pSyncNode
!=
NULL
);
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncRequestVote
=
pSyncNode
->
FpOnRequestVote
;
gSyncIO
->
FpOnSyncRequestVoteReply
=
pSyncNode
->
FpOnRequestVoteReply
;
gSyncIO
->
FpOnSyncAppendEntries
=
pSyncNode
->
FpOnAppendEntries
;
gSyncIO
->
FpOnSyncAppendEntriesReply
=
pSyncNode
->
FpOnAppendEntriesReply
;
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncTimeout
=
pSyncNode
->
FpOnTimeout
;
gSyncIO
->
pSyncNode
=
pSyncNode
;
return
pSyncNode
;
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
free
(
s
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
myIndex
=
0
;
if
(
argc
>=
2
)
{
myIndex
=
atoi
(
argv
[
1
]);
}
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]);
assert
(
ret
==
0
);
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
gSyncNode
=
syncInitTest
();
assert
(
gSyncNode
!=
NULL
);
syncNodePrint2
((
char
*
)
""
,
gSyncNode
);
initRaftId
(
gSyncNode
);
//---------------------------
while
(
1
)
{
sTrace
(
"while 1 sleep, state: %d, %s, electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, electTimerMS:%d"
,
gSyncNode
->
state
,
syncUtilState2String
(
gSyncNode
->
state
),
gSyncNode
->
electTimerLogicClock
,
gSyncNode
->
electTimerLogicClockUser
,
gSyncNode
->
electTimerMS
);
taosMsleep
(
1000
);
}
return
0
;
}
source/libs/sync/test/syncWriteTest.cpp
0 → 100644
浏览文件 @
c56743d8
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncRaftEntry.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
uint16_t
ports
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
int32_t
replicaNum
=
1
;
int32_t
myIndex
=
0
;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SSyncInfo
syncInfo
;
SSyncFSM
*
pFsm
;
SWal
*
pWal
;
SSyncNode
*
gSyncNode
;
void
CommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==CommitCb=="
,
(
SRpcMsg
*
)
pBuf
);
}
void
PreCommitCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==PreCommitCb=="
,
(
SRpcMsg
*
)
pBuf
);
}
void
RollBackCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pBuf
,
SyncIndex
index
,
bool
isWeak
,
int32_t
code
)
{
printf
(
"==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d
\n
"
,
pFsm
,
index
,
isWeak
,
code
);
syncRpcMsgPrint2
((
char
*
)
"==RollBackCb=="
,
(
SRpcMsg
*
)
pBuf
);
}
void
initFsm
()
{
pFsm
=
(
SSyncFSM
*
)
malloc
(
sizeof
(
SSyncFSM
));
pFsm
->
FpCommitCb
=
CommitCb
;
pFsm
->
FpPreCommitCb
=
PreCommitCb
;
pFsm
->
FpRollBackCb
=
RollBackCb
;
}
SSyncNode
*
syncNodeInit
()
{
syncInfo
.
vgId
=
1234
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
queue
=
gSyncIO
->
pMsgQ
;
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./write_test"
);
int
code
=
walInit
();
assert
(
code
==
0
);
SWalCfg
walCfg
;
memset
(
&
walCfg
,
0
,
sizeof
(
SWalCfg
));
walCfg
.
vgId
=
syncInfo
.
vgId
;
walCfg
.
fsyncPeriod
=
1000
;
walCfg
.
retentionPeriod
=
1000
;
walCfg
.
rollPeriod
=
1000
;
walCfg
.
retentionSize
=
1000
;
walCfg
.
segSize
=
1000
;
walCfg
.
level
=
TAOS_WAL_FSYNC
;
pWal
=
walOpen
(
"./write_test_wal"
,
&
walCfg
);
assert
(
pWal
!=
NULL
);
syncInfo
.
pWal
=
pWal
;
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
pCfg
->
replicaNum
=
replicaNum
;
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
pCfg
->
nodeInfo
[
i
].
nodePort
=
ports
[
i
];
snprintf
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
,
sizeof
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
),
"%s"
,
"127.0.0.1"
);
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
}
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
&
syncInfo
);
assert
(
pSyncNode
!=
NULL
);
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncClientRequest
=
pSyncNode
->
FpOnClientRequest
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncRequestVote
=
pSyncNode
->
FpOnRequestVote
;
gSyncIO
->
FpOnSyncRequestVoteReply
=
pSyncNode
->
FpOnRequestVoteReply
;
gSyncIO
->
FpOnSyncAppendEntries
=
pSyncNode
->
FpOnAppendEntries
;
gSyncIO
->
FpOnSyncAppendEntriesReply
=
pSyncNode
->
FpOnAppendEntriesReply
;
gSyncIO
->
FpOnSyncTimeout
=
pSyncNode
->
FpOnTimeout
;
gSyncIO
->
pSyncNode
=
pSyncNode
;
return
pSyncNode
;
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
free
(
s
);
}
}
SRpcMsg
*
step0
()
{
SRpcMsg
*
pMsg
=
(
SRpcMsg
*
)
malloc
(
sizeof
(
SRpcMsg
));
memset
(
pMsg
,
0
,
sizeof
(
SRpcMsg
));
pMsg
->
msgType
=
9999
;
pMsg
->
contLen
=
32
;
pMsg
->
pCont
=
malloc
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"hello, world"
);
return
pMsg
;
}
SyncClientRequest
*
step1
(
const
SRpcMsg
*
pMsg
)
{
SyncClientRequest
*
pRetMsg
=
syncClientRequestBuild2
(
pMsg
,
123
,
true
);
return
pRetMsg
;
}
int
main
(
int
argc
,
char
**
argv
)
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
void
logTest
();
myIndex
=
0
;
if
(
argc
>=
2
)
{
myIndex
=
atoi
(
argv
[
1
]);
}
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]);
assert
(
ret
==
0
);
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
taosRemoveDir
(
"./wal_test"
);
initFsm
();
gSyncNode
=
syncInitTest
();
assert
(
gSyncNode
!=
NULL
);
syncNodePrint2
((
char
*
)
""
,
gSyncNode
);
initRaftId
(
gSyncNode
);
// step0
SRpcMsg
*
pMsg0
=
step0
();
syncRpcMsgPrint2
((
char
*
)
"==step0=="
,
pMsg0
);
// step1
SyncClientRequest
*
pMsg1
=
step1
(
pMsg0
);
syncClientRequestPrint2
((
char
*
)
"==step1=="
,
pMsg1
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
SyncClientRequest
*
pSyncClientRequest
=
pMsg1
;
SRpcMsg
rpcMsg
;
syncClientRequest2RpcMsg
(
pSyncClientRequest
,
&
rpcMsg
);
gSyncNode
->
FpEqMsg
(
gSyncNode
->
queue
,
&
rpcMsg
);
taosMsleep
(
1000
);
}
while
(
1
)
{
sTrace
(
"while 1 sleep"
);
taosMsleep
(
1000
);
}
return
0
;
}
source/libs/tfs/src/tfs.c
浏览文件 @
c56743d8
...
@@ -204,7 +204,8 @@ void tfsDirname(const STfsFile *pFile, char *dest) {
...
@@ -204,7 +204,8 @@ void tfsDirname(const STfsFile *pFile, char *dest) {
void
tfsAbsoluteName
(
STfs
*
pTfs
,
SDiskID
diskId
,
const
char
*
rname
,
char
*
aname
)
{
void
tfsAbsoluteName
(
STfs
*
pTfs
,
SDiskID
diskId
,
const
char
*
rname
,
char
*
aname
)
{
STfsDisk
*
pDisk
=
TFS_DISK_AT
(
pTfs
,
diskId
);
STfsDisk
*
pDisk
=
TFS_DISK_AT
(
pTfs
,
diskId
);
snprintf
(
aname
,
TMPNAME_LEN
,
"%s%s%s"
,
pDisk
->
path
,
TD_DIRSEP
,
rname
);
snprintf
(
aname
,
TSDB_FILENAME_LEN
,
"%s%s%s"
,
pDisk
->
path
,
TD_DIRSEP
,
rname
);
}
}
int32_t
tfsRemoveFile
(
const
STfsFile
*
pFile
)
{
return
taosRemoveFile
(
pFile
->
aname
);
}
int32_t
tfsRemoveFile
(
const
STfsFile
*
pFile
)
{
return
taosRemoveFile
(
pFile
->
aname
);
}
...
...
source/os/CMakeLists.txt
浏览文件 @
c56743d8
...
@@ -5,9 +5,14 @@ target_include_directories(
...
@@ -5,9 +5,14 @@ target_include_directories(
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/os"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/os"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/util"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/util"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/contrib/pthread
-win32
"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/contrib/pthread"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/contrib/gnuregex"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/contrib/gnuregex"
)
)
# iconv
find_path
(
IconvApiIncludes iconv.h PATHS
)
if
(
NOT IconvApiIncludes
)
add_definitions
(
-DDISALLOW_NCHAR_WITHOUT_ICONV
)
endif
()
target_link_libraries
(
target_link_libraries
(
os pthread dl rt m
os pthread dl rt m
)
)
source/os/src/osFile.c
浏览文件 @
c56743d8
...
@@ -46,6 +46,23 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
...
@@ -46,6 +46,23 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
#define O_TEXT LINUX_FILE_NO_TEXT_OPTION
#define O_TEXT LINUX_FILE_NO_TEXT_OPTION
#endif
#endif
#if defined(WINDOWS)
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
#else
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
#endif
typedef
int32_t
FileFd
;
typedef
struct
TdFile
{
pthread_rwlock_t
rwlock
;
int
refId
;
FileFd
fd
;
FILE
*
fp
;
}
*
TdFilePtr
,
TdFile
;
#define FILE_WITH_LOCK 1
#define FILE_WITH_LOCK 1
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
...
...
source/os/src/osLocale.c
浏览文件 @
c56743d8
...
@@ -81,7 +81,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
...
@@ -81,7 +81,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
}
}
if
(
!
taosValidateEncodec
(
inCharSet
))
{
if
(
!
taosValidateEncodec
(
inCharSet
))
{
printf
(
"Invalid charset:%s, please set the valid charset in config file"
,
inCharSet
);
printf
(
"Invalid charset:%s, please set the valid charset in config file
\n
"
,
inCharSet
);
exit
(
-
1
);
exit
(
-
1
);
}
}
}
}
...
...
source/os/src/osString.c
浏览文件 @
c56743d8
...
@@ -13,22 +13,69 @@
...
@@ -13,22 +13,69 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include <malloc.h>
#include "os.h"
#include "os.h"
#include "tdef.h"
#include <wchar.h>
#include <wctype.h>
#ifndef DISALLOW_NCHAR_WITHOUT_ICONV
#include "iconv.h"
#endif
extern
int
wcwidth
(
wchar_t
c
);
extern
int
wcswidth
(
const
wchar_t
*
s
,
size_t
n
);
int64_t
taosStr2int64
(
const
char
*
str
)
{
int64_t
taosStr2int64
(
const
char
*
str
)
{
char
*
endptr
=
NULL
;
char
*
endptr
=
NULL
;
return
strtoll
(
str
,
&
endptr
,
10
);
return
strtoll
(
str
,
&
endptr
,
10
);
}
}
#ifdef USE_LIBICONV
int32_t
tasoUcs4Compare
(
TdUcs4
*
f1_ucs4
,
TdUcs4
*
f2_ucs4
,
int32_t
bytes
)
{
#include "iconv.h"
for
(
int32_t
i
=
0
;
i
<
bytes
;
i
+=
sizeof
(
TdUcs4
))
{
int32_t
f1
=
*
(
int32_t
*
)((
char
*
)
f1_ucs4
+
i
);
int32_t
f2
=
*
(
int32_t
*
)((
char
*
)
f2_ucs4
+
i
);
if
((
f1
==
0
&&
f2
!=
0
)
||
(
f1
!=
0
&&
f2
==
0
))
{
return
f1
-
f2
;
}
else
if
(
f1
==
0
&&
f2
==
0
)
{
return
0
;
}
if
(
f1
!=
f2
)
{
return
f1
-
f2
;
}
}
return
0
;
#if 0
int32_t ucs4_max_len = bytes + 4;
char *f1_mbs = calloc(bytes, 1);
char *f2_mbs = calloc(bytes, 1);
if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) {
return -1;
}
if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) {
return -1;
}
int32_t ret = strcmp(f1_mbs, f2_mbs);
free(f1_mbs);
free(f2_mbs);
return ret;
#endif
}
int32_t
taosUcs4ToMbs
(
void
*
ucs4
,
int32_t
ucs4_max_len
,
char
*
mbs
)
{
TdUcs4
*
tasoUcs4Copy
(
TdUcs4
*
target_ucs4
,
TdUcs4
*
source_ucs4
,
int32_t
len_ucs4
)
{
assert
(
malloc_usable_size
(
target_ucs4
)
>=
len_ucs4
*
sizeof
(
TdUcs4
));
return
memcpy
(
target_ucs4
,
source_ucs4
,
len_ucs4
*
sizeof
(
TdUcs4
));
}
int32_t
taosUcs4ToMbs
(
TdUcs4
*
ucs4
,
int32_t
ucs4_max_len
,
char
*
mbs
)
{
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
printf
(
"Nchar cannot be read and written without iconv, please install iconv library and recompile TDengine.
\n
"
);
return
-
1
;
#else
iconv_t
cd
=
iconv_open
(
tsCharset
,
DEFAULT_UNICODE_ENCODEC
);
iconv_t
cd
=
iconv_open
(
tsCharset
,
DEFAULT_UNICODE_ENCODEC
);
size_t
ucs4_input_len
=
ucs4_max_len
;
size_t
ucs4_input_len
=
ucs4_max_len
;
size_t
outLen
=
ucs4_max_len
;
size_t
outLen
=
ucs4_max_len
;
...
@@ -39,14 +86,19 @@ int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
...
@@ -39,14 +86,19 @@ int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
iconv_close
(
cd
);
iconv_close
(
cd
);
return
(
int32_t
)(
ucs4_max_len
-
outLen
);
return
(
int32_t
)(
ucs4_max_len
-
outLen
);
#endif
}
}
bool
taosMbsToUcs4
(
char
*
mbs
,
size_t
mbsLength
,
char
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
)
{
bool
taosMbsToUcs4
(
const
char
*
mbs
,
size_t
mbsLength
,
TdUcs4
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
)
{
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
printf
(
"Nchar cannot be read and written without iconv, please install iconv library and recompile TDengine.
\n
"
);
return
-
1
;
#else
memset
(
ucs4
,
0
,
ucs4_max_len
);
memset
(
ucs4
,
0
,
ucs4_max_len
);
iconv_t
cd
=
iconv_open
(
DEFAULT_UNICODE_ENCODEC
,
tsCharset
);
iconv_t
cd
=
iconv_open
(
DEFAULT_UNICODE_ENCODEC
,
tsCharset
);
size_t
ucs4_input_len
=
mbsLength
;
size_t
ucs4_input_len
=
mbsLength
;
size_t
outLeft
=
ucs4_max_len
;
size_t
outLeft
=
ucs4_max_len
;
if
(
iconv
(
cd
,
&
mbs
,
&
ucs4_input_len
,
&
ucs4
,
&
outLeft
)
==
-
1
)
{
if
(
iconv
(
cd
,
(
char
**
)
&
mbs
,
&
ucs4_input_len
,
(
char
**
)
&
ucs4
,
&
outLeft
)
==
-
1
)
{
iconv_close
(
cd
);
iconv_close
(
cd
);
return
false
;
return
false
;
}
}
...
@@ -60,9 +112,14 @@ bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len
...
@@ -60,9 +112,14 @@ bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len
}
}
return
true
;
return
true
;
#endif
}
}
bool
taosValidateEncodec
(
const
char
*
encodec
)
{
bool
taosValidateEncodec
(
const
char
*
encodec
)
{
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
printf
(
"Nchar cannot be read and written without iconv, please install iconv library and recompile TDengine.
\n
"
);
return
true
;
#else
iconv_t
cd
=
iconv_open
(
encodec
,
DEFAULT_UNICODE_ENCODEC
);
iconv_t
cd
=
iconv_open
(
encodec
,
DEFAULT_UNICODE_ENCODEC
);
if
(
cd
==
(
iconv_t
)(
-
1
))
{
if
(
cd
==
(
iconv_t
)(
-
1
))
{
return
false
;
return
false
;
...
@@ -70,214 +127,11 @@ bool taosValidateEncodec(const char *encodec) {
...
@@ -70,214 +127,11 @@ bool taosValidateEncodec(const char *encodec) {
iconv_close
(
cd
);
iconv_close
(
cd
);
return
true
;
return
true
;
}
#else
int32_t
taosUcs4ToMbs
(
void
*
ucs4
,
int32_t
ucs4_max_len
,
char
*
mbs
)
{
mbstate_t
state
=
{
0
};
int32_t
len
=
(
int32_t
)
wcsnrtombs
(
NULL
,
(
const
wchar_t
**
)
&
ucs4
,
ucs4_max_len
/
4
,
0
,
&
state
);
if
(
len
<
0
)
{
return
-
1
;
}
memset
(
&
state
,
0
,
sizeof
(
state
));
len
=
wcsnrtombs
(
mbs
,
(
const
wchar_t
**
)
&
ucs4
,
ucs4_max_len
/
4
,
(
size_t
)
len
,
&
state
);
if
(
len
<
0
)
{
return
-
1
;
}
return
len
;
}
bool
taosMbsToUcs4
(
const
char
*
mbs
,
size_t
mbsLength
,
char
*
ucs4
,
int32_t
ucs4_max_len
,
int32_t
*
len
)
{
memset
(
ucs4
,
0
,
ucs4_max_len
);
mbstate_t
state
=
{
0
};
int32_t
retlen
=
mbsnrtowcs
((
wchar_t
*
)
ucs4
,
(
const
char
**
)
&
mbs
,
mbsLength
,
ucs4_max_len
/
4
,
&
state
);
*
len
=
retlen
;
return
retlen
>=
0
;
}
bool
taosValidateEncodec
(
const
char
*
encodec
)
{
return
true
;
}
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
/*
* windows implementation
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#if STDC_HEADERS
#include <stdlib.h>
#else
char
*
malloc
(),
*
realloc
();
#endif
#endif
/* Always add at least this many bytes when extending the buffer. */
#define MIN_CHUNK 64
/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
+ OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
malloc (or NULL), pointing to *N characters of space. It is realloc'd
as necessary. Return the number of characters read (not including the
null terminator), or -1 on error or EOF. On a -1 return, the caller
should check feof(), if not then errno has been set to indicate
the error. */
int32_t
getstr
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
,
char
terminator
,
int32_t
offset
)
{
int32_t
nchars_avail
;
/* Allocated but unused chars in *LINEPTR. */
char
*
read_pos
;
/* Where we're reading into *LINEPTR. */
int32_t
ret
;
if
(
!
lineptr
||
!
n
||
!
stream
)
{
errno
=
EINVAL
;
return
-
1
;
}
if
(
!*
lineptr
)
{
*
n
=
MIN_CHUNK
;
*
lineptr
=
malloc
(
*
n
);
if
(
!*
lineptr
)
{
errno
=
ENOMEM
;
return
-
1
;
}
}
nchars_avail
=
(
int32_t
)(
*
n
-
offset
);
read_pos
=
*
lineptr
+
offset
;
for
(;;)
{
int32_t
save_errno
;
register
int32_t
c
=
getc
(
stream
);
save_errno
=
errno
;
/* We always want at least one char left in the buffer, since we
always (unless we get an error while reading the first char)
NUL-terminate the line buffer. */
assert
((
*
lineptr
+
*
n
)
==
(
read_pos
+
nchars_avail
));
if
(
nchars_avail
<
2
)
{
if
(
*
n
>
MIN_CHUNK
)
*
n
*=
2
;
else
*
n
+=
MIN_CHUNK
;
nchars_avail
=
(
int32_t
)(
*
n
+
*
lineptr
-
read_pos
);
char
*
lineptr1
=
realloc
(
*
lineptr
,
*
n
);
if
(
!
lineptr1
)
{
errno
=
ENOMEM
;
return
-
1
;
}
*
lineptr
=
lineptr1
;
read_pos
=
*
n
-
nchars_avail
+
*
lineptr
;
assert
((
*
lineptr
+
*
n
)
==
(
read_pos
+
nchars_avail
));
}
if
(
ferror
(
stream
))
{
/* Might like to return partial line, but there is no
place for us to store errno. And we don't want to just
lose errno. */
errno
=
save_errno
;
return
-
1
;
}
if
(
c
==
EOF
)
{
/* Return partial line, if any. */
if
(
read_pos
==
*
lineptr
)
return
-
1
;
else
break
;
}
*
read_pos
++
=
c
;
nchars_avail
--
;
if
(
c
==
terminator
)
/* Return the line. */
break
;
}
/* Done - NUL terminate and return the number of chars read. */
*
read_pos
=
'\0'
;
ret
=
(
int32_t
)(
read_pos
-
(
*
lineptr
+
offset
));
return
ret
;
}
int32_t
tgetline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
)
{
return
getstr
(
lineptr
,
n
,
stream
,
'\n'
,
0
);
}
/*
* Get next token from string *stringp, where tokens are possibly-empty
* strings separated by characters from delim.
*
* Writes NULs into the string at *stringp to end tokens.
* delim need not remain constant from call to call.
* On return, *stringp points past the last NUL written (if there might
* be further tokens), or is NULL (if there are definitely no moretokens).
*
* If *stringp is NULL, strsep returns NULL.
*/
char
*
strsep
(
char
**
stringp
,
const
char
*
delim
)
{
char
*
s
;
const
char
*
spanp
;
int32_t
c
,
sc
;
char
*
tok
;
if
((
s
=
*
stringp
)
==
NULL
)
return
(
NULL
);
for
(
tok
=
s
;;)
{
c
=
*
s
++
;
spanp
=
delim
;
do
{
if
((
sc
=
*
spanp
++
)
==
c
)
{
if
(
c
==
0
)
s
=
NULL
;
else
s
[
-
1
]
=
0
;
*
stringp
=
s
;
return
(
tok
);
}
}
while
(
sc
!=
0
);
}
/* NOTREACHED */
}
char
*
getpass
(
const
char
*
prefix
)
{
static
char
passwd
[
TSDB_PASSWORD_LEN
]
=
{
0
};
memset
(
passwd
,
0
,
TSDB_PASSWORD_LEN
);
//printf("%s", prefix);
int32_t
index
=
0
;
char
ch
;
while
(
index
<
TSDB_PASSWORD_LEN
)
{
ch
=
getch
();
if
(
ch
==
'\n'
||
ch
==
'\r'
)
{
break
;
}
else
{
passwd
[
index
++
]
=
ch
;
}
}
return
passwd
;
}
}
int32_t
t
wcslen
(
const
wchar_t
*
wcs
)
{
int32_t
t
aosUcs4len
(
TdUcs4
*
ucs4
)
{
int32_t
*
wstr
=
(
int32_t
*
)
wcs
;
TdUcs4
*
wstr
=
(
TdUcs4
*
)
ucs4
;
if
(
NULL
==
wstr
)
{
if
(
NULL
==
wstr
)
{
return
0
;
return
0
;
}
}
...
@@ -292,73 +146,15 @@ int32_t twcslen(const wchar_t *wcs) {
...
@@ -292,73 +146,15 @@ int32_t twcslen(const wchar_t *wcs) {
return
n
;
return
n
;
}
}
int32_t
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int32_t
bytes
)
{
for
(
int32_t
i
=
0
;
i
<
bytes
;
i
+=
TSDB_NCHAR_SIZE
)
{
int32_t
f1
=
*
(
int32_t
*
)((
char
*
)
f1_ucs4
+
i
);
int32_t
f2
=
*
(
int32_t
*
)((
char
*
)
f2_ucs4
+
i
);
if
((
f1
==
0
&&
f2
!=
0
)
||
(
f1
!=
0
&&
f2
==
0
))
{
return
f1
-
f2
;
}
else
if
(
f1
==
0
&&
f2
==
0
)
{
return
0
;
}
if
(
f1
!=
f2
)
{
return
f1
-
f2
;
}
}
return
0
;
#if 0
int32_t ucs4_max_len = bytes + 4;
char *f1_mbs = calloc(bytes, 1);
char *f2_mbs = calloc(bytes, 1);
if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) {
return -1;
}
if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) {
return -1;
}
int32_t ret = strcmp(f1_mbs, f2_mbs);
free(f1_mbs);
free(f2_mbs);
return ret;
#endif
}
/* Copy memory to memory until the specified number of bytes
int32_t
taosWcharWidth
(
TdWchar
wchar
)
{
return
wcwidth
(
wchar
);
}
has been copied, return pointer to following byte.
Overlap is NOT handled correctly. */
void
*
mempcpy
(
void
*
dest
,
const
void
*
src
,
size_t
len
)
{
return
(
char
*
)
memcpy
(
dest
,
src
,
len
)
+
len
;
}
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
int32_t
taosWcharsWidth
(
TdWchar
*
pWchar
,
int32_t
size
)
{
return
wcswidth
(
pWchar
,
size
);
}
char
*
stpcpy
(
char
*
dest
,
const
char
*
src
)
{
size_t
len
=
strlen
(
src
);
return
(
char
*
)
memcpy
(
dest
,
src
,
len
+
1
)
+
len
;
}
/* Copy no more than N characters of SRC to DEST, returning the address of
the terminating '\0' in DEST, if any, or else DEST + N. */
char
*
stpncpy
(
char
*
dest
,
const
char
*
src
,
size_t
n
)
{
size_t
size
=
strnlen
(
src
,
n
);
memcpy
(
dest
,
src
,
size
);
dest
+=
size
;
if
(
size
==
n
)
return
dest
;
return
memset
(
dest
,
'\0'
,
n
-
size
);
}
#else
int32_t
taosMbToWchar
(
TdWchar
*
pWchar
,
const
char
*
pStr
,
int32_t
size
)
{
return
mbtowc
(
pWchar
,
pStr
,
size
);
}
/*
int32_t
taosMbsToWchars
(
TdWchar
*
pWchars
,
const
char
*
pStrs
,
int32_t
size
)
{
return
mbstowcs
(
pWchars
,
pStrs
,
size
);
}
* linux and darwin implementation
*/
int32_t
tasoUcs4Compare
(
void
*
f1_ucs4
,
void
*
f2_ucs4
,
int32_t
bytes
,
int8_t
ncharSize
)
{
int32_t
taosWcharToMb
(
char
*
pStr
,
TdWchar
wchar
)
{
return
wctomb
(
pStr
,
wchar
);
}
return
wcsncmp
((
wchar_t
*
)
f1_ucs4
,
(
wchar_t
*
)
f2_ucs4
,
bytes
/
ncharSize
);
}
#endif
int32_t
taosWcharsToMbs
(
char
*
pStrs
,
TdWchar
*
pWchars
,
int32_t
size
)
{
return
wcstombs
(
pStrs
,
pWchars
,
size
);
}
source/util/src/tcompare.c
浏览文件 @
c56743d8
...
@@ -208,7 +208,7 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
...
@@ -208,7 +208,7 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
if
(
len1
!=
len2
)
{
if
(
len1
!=
len2
)
{
return
len1
>
len2
?
1
:
-
1
;
return
len1
>
len2
?
1
:
-
1
;
}
else
{
}
else
{
int32_t
ret
=
memcmp
((
wchar_t
*
)
pLeft
,
(
wchar_t
*
)
pRight
,
len1
);
int32_t
ret
=
memcmp
((
TdUcs4
*
)
pLeft
,
(
TdUcs4
*
)
pRight
,
len1
);
if
(
ret
==
0
)
{
if
(
ret
==
0
)
{
return
0
;
return
0
;
}
else
{
}
else
{
...
@@ -295,10 +295,10 @@ int32_t patternMatch(const char *patterStr, const char *str, size_t size, const
...
@@ -295,10 +295,10 @@ int32_t patternMatch(const char *patterStr, const char *str, size_t size, const
return
(
str
[
j
]
==
0
||
j
>=
size
)
?
TSDB_PATTERN_MATCH
:
TSDB_PATTERN_NOMATCH
;
return
(
str
[
j
]
==
0
||
j
>=
size
)
?
TSDB_PATTERN_MATCH
:
TSDB_PATTERN_NOMATCH
;
}
}
int32_t
WCSPatternMatch
(
const
wchar_t
*
patterStr
,
const
wchar_t
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
)
{
int32_t
WCSPatternMatch
(
const
TdUcs4
*
patterStr
,
const
TdUcs4
*
str
,
size_t
size
,
const
SPatternCompareInfo
*
pInfo
)
{
wchar_t
c
,
c1
;
TdUcs4
c
,
c1
;
wchar_t
matchOne
=
L'_'
;
// "_"
TdUcs4
matchOne
=
L'_'
;
// "_"
wchar_t
matchAll
=
L'%'
;
// "%"
TdUcs4
matchAll
=
L'%'
;
// "%"
int32_t
i
=
0
;
int32_t
i
=
0
;
int32_t
j
=
0
;
int32_t
j
=
0
;
...
@@ -315,7 +315,7 @@ int32_t WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t siz
...
@@ -315,7 +315,7 @@ int32_t WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t siz
return
TSDB_PATTERN_MATCH
;
return
TSDB_PATTERN_MATCH
;
}
}
wchar_t
accept
[
3
]
=
{
towupper
(
c
),
towlower
(
c
),
0
};
TdUcs4
accept
[
3
]
=
{
towupper
(
c
),
towlower
(
c
),
0
};
while
(
1
)
{
while
(
1
)
{
size_t
n
=
wcscspn
(
str
,
accept
);
size_t
n
=
wcscspn
(
str
,
accept
);
...
@@ -424,10 +424,10 @@ int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight) {
...
@@ -424,10 +424,10 @@ int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight) {
assert
(
varDataLen
(
pRight
)
<=
TSDB_MAX_FIELD_LEN
*
TSDB_NCHAR_SIZE
);
assert
(
varDataLen
(
pRight
)
<=
TSDB_MAX_FIELD_LEN
*
TSDB_NCHAR_SIZE
);
wchar_t
*
pattern
=
calloc
(
varDataLen
(
pRight
)
+
1
,
sizeof
(
wchar_t
)
);
char
*
pattern
=
calloc
(
varDataLen
(
pRight
)
+
TSDB_NCHAR_SIZE
,
1
);
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
int32_t
ret
=
WCSPatternMatch
(
pattern
,
(
const
wchar_t
*
)
varDataVal
(
pLeft
),
varDataLen
(
pLeft
)
/
TSDB_NCHAR_SIZE
,
&
pInfo
);
int32_t
ret
=
WCSPatternMatch
(
(
TdUcs4
*
)
pattern
,
(
TdUcs4
*
)
varDataVal
(
pLeft
),
varDataLen
(
pLeft
)
/
TSDB_NCHAR_SIZE
,
&
pInfo
);
free
(
pattern
);
free
(
pattern
);
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
...
@@ -647,7 +647,7 @@ int32_t doCompare(const char *f1, const char *f2, int32_t type, size_t size) {
...
@@ -647,7 +647,7 @@ int32_t doCompare(const char *f1, const char *f2, int32_t type, size_t size) {
if
(
t1
->
len
!=
t2
->
len
)
{
if
(
t1
->
len
!=
t2
->
len
)
{
return
t1
->
len
>
t2
->
len
?
1
:
-
1
;
return
t1
->
len
>
t2
->
len
?
1
:
-
1
;
}
}
int32_t
ret
=
memcmp
((
wchar_t
*
)
t1
,
(
wchar_t
*
)
t2
,
t2
->
len
);
int32_t
ret
=
memcmp
((
TdUcs4
*
)
t1
,
(
TdUcs4
*
)
t2
,
t2
->
len
);
if
(
ret
==
0
)
{
if
(
ret
==
0
)
{
return
ret
;
return
ret
;
}
}
...
...
source/util/src/tjson.c
浏览文件 @
c56743d8
...
@@ -202,9 +202,16 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV
...
@@ -202,9 +202,16 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV
return
(
errno
==
ERANGE
||
errno
==
EINVAL
)
?
TSDB_CODE_FAILED
:
TSDB_CODE_SUCCESS
;
return
(
errno
==
ERANGE
||
errno
==
EINVAL
)
?
TSDB_CODE_FAILED
:
TSDB_CODE_SUCCESS
;
}
}
int32_t
tjsonGetUIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint32_t
*
pVal
)
{
uint64_t
val
=
0
;
int32_t
code
=
tjsonGetUBigIntValue
(
pJson
,
pName
,
&
val
);
*
pVal
=
val
;
return
code
;
}
int32_t
tjsonGetUTinyIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint8_t
*
pVal
)
{
int32_t
tjsonGetUTinyIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint8_t
*
pVal
)
{
uint64_t
val
=
0
;
uint64_t
val
=
0
;
int32_t
code
=
tjsonGetUBigIntValue
(
pJson
,
pName
,
&
val
);
int32_t
code
=
tjsonGetUBigIntValue
(
pJson
,
pName
,
&
val
);
*
pVal
=
val
;
*
pVal
=
val
;
return
code
;
return
code
;
}
}
...
@@ -239,6 +246,22 @@ int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, voi
...
@@ -239,6 +246,22 @@ int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, voi
return
func
(
pJsonObj
,
pObj
);
return
func
(
pJsonObj
,
pObj
);
}
}
int32_t
tjsonMakeObject
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
**
pObj
,
int32_t
objSize
)
{
if
(
objSize
<=
0
)
{
return
TSDB_CODE_SUCCESS
;
}
SJson
*
pJsonObj
=
tjsonGetObjectItem
(
pJson
,
pName
);
if
(
NULL
==
pJsonObj
)
{
return
TSDB_CODE_FAILED
;
}
*
pObj
=
calloc
(
1
,
objSize
);
if
(
NULL
==
*
pObj
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
func
(
pJsonObj
,
*
pObj
);
}
int32_t
tjsonToArray
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
*
pArray
,
int32_t
itemSize
)
{
int32_t
tjsonToArray
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
*
pArray
,
int32_t
itemSize
)
{
const
cJSON
*
jArray
=
tjsonGetObjectItem
(
pJson
,
pName
);
const
cJSON
*
jArray
=
tjsonGetObjectItem
(
pJson
,
pName
);
int32_t
size
=
(
NULL
==
jArray
?
0
:
tjsonGetArraySize
(
jArray
));
int32_t
size
=
(
NULL
==
jArray
?
0
:
tjsonGetArraySize
(
jArray
));
...
...
tests/script/jenkins/basic.txt
浏览文件 @
c56743d8
...
@@ -18,4 +18,7 @@
...
@@ -18,4 +18,7 @@
# ---- insert
# ---- insert
./test.sh -f tsim/insert/basic0.sim
./test.sh -f tsim/insert/basic0.sim
# ---- query
./test.sh -f tsim/query/interval.sim
#======================b1-end===============
#======================b1-end===============
tests/script/tsim/insert/basic1.sim
0 → 100644
浏览文件 @
c56743d8
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sleep 50
sql connect
print =============== create database
sql create database d1
sql show databases
if $rows != 1 then
return -1
endi
print $data00 $data01 $data02
sql use d1
print =============== create super table, include all type
sql create table if not exists stb (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(16), c9 nchar(16), c10 timestamp, c11 tinyint unsigned, c12 smallint unsigned, c13 int unsigned, c14 bigint unsigned) tags (t1 bool, t2 tinyint, t3 smallint, t4 int, t5 bigint, t6 float, t7 double, t8 binary(16), t9 nchar(16), t10 timestamp, t11 tinyint unsigned, t12 smallint unsigned, t13 int unsigned, t14 bigint unsigned)
sql create stable if not exists stb_1 (ts timestamp, i int) tags (j int)
sql create table stb_2 (ts timestamp, i int) tags (j int)
sql create stable stb_3 (ts timestamp, i int) tags (j int)
sql show stables
if $rows != 4 then
return -1
endi
print =============== create child table
sql create table c1 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
sql create table c2 using stb tags(false, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 2', 'child tbl 2', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
sql show tables
if $rows != 2 then
return -1
endi
print =============== insert data, mode1: one row one table in sql
print =============== insert data, mode1: mulit rows one table in sql
print =============== insert data, mode1: one rows mulit table in sql
print =============== insert data, mode1: mulit rows mulit table in sql
sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+2s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
print =============== query data
sql select * from c1
if $rows != 4 then
return -1
endi
if $data01 != true then
return -1
endi
if $data02 != -1 then
return -1
endi
if $data03 != -2 then
return -1
endi
print =============== query data from st
sql select * from st
if $rows != 4 then
return -1
endi
print =============== stop and restart taosd
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode1 -s start
sleep 2000
print =============== query data
sql select * from c1
if $rows != 4 then
return -1
endi
if $data01 != true then
return -1
endi
if $data02 != -1 then
return -1
endi
if $data03 != -2 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
tests/script/tsim/query/interval-offset.sim
0 → 100644
浏览文件 @
c56743d8
此差异已折叠。
点击以展开。
tests/script/tsim/query/interval.sim
浏览文件 @
c56743d8
此差异已折叠。
点击以展开。
tools/shell/src/backup/shellDarwin.c
浏览文件 @
c56743d8
...
@@ -28,7 +28,6 @@
...
@@ -28,7 +28,6 @@
int
indicator
=
1
;
int
indicator
=
1
;
struct
termios
oldtio
;
struct
termios
oldtio
;
extern
int
wcwidth
(
wchar_t
c
);
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
...
@@ -426,7 +425,7 @@ void showOnScreen(Command *cmd) {
...
@@ -426,7 +425,7 @@ void showOnScreen(Command *cmd) {
w
.
ws_row
=
30
;
w
.
ws_row
=
30
;
}
}
wchar_t
wc
;
TdWchar
wc
;
int
size
=
0
;
int
size
=
0
;
// Print out the command.
// Print out the command.
...
@@ -441,11 +440,11 @@ void showOnScreen(Command *cmd) {
...
@@ -441,11 +440,11 @@ void showOnScreen(Command *cmd) {
int
remain_column
=
w
.
ws_col
;
int
remain_column
=
w
.
ws_col
;
/* size = cmd->commandSize + prompt_size; */
/* size = cmd->commandSize + prompt_size; */
for
(
char
*
str
=
total_string
;
size
<
cmd
->
commandSize
+
prompt_size
;)
{
for
(
char
*
str
=
total_string
;
size
<
cmd
->
commandSize
+
prompt_size
;)
{
int
ret
=
mbtowc
(
&
wc
,
str
,
MB_CUR_MAX
);
int
ret
=
taosMbToWchar
(
&
wc
,
str
,
MB_CUR_MAX
);
if
(
ret
<
0
)
break
;
if
(
ret
<
0
)
break
;
size
+=
ret
;
size
+=
ret
;
/* assert(size >= 0); */
/* assert(size >= 0); */
int
width
=
wcw
idth
(
wc
);
int
width
=
taosWcharW
idth
(
wc
);
if
(
remain_column
>
width
)
{
if
(
remain_column
>
width
)
{
printf
(
"%lc"
,
wc
);
printf
(
"%lc"
,
wc
);
remain_column
-=
width
;
remain_column
-=
width
;
...
...
tools/shell/src/shellCommand.c
浏览文件 @
c56743d8
此差异已折叠。
点击以展开。
tools/shell/src/shellEngine.c
浏览文件 @
c56743d8
...
@@ -560,12 +560,12 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) {
...
@@ -560,12 +560,12 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) {
}
}
static
void
shellPrintNChar
(
const
char
*
str
,
int
length
,
int
width
)
{
static
void
shellPrintNChar
(
const
char
*
str
,
int
length
,
int
width
)
{
wchar_t
tail
[
3
];
TdWchar
tail
[
3
];
int
pos
=
0
,
cols
=
0
,
totalCols
=
0
,
tailLen
=
0
;
int
pos
=
0
,
cols
=
0
,
totalCols
=
0
,
tailLen
=
0
;
while
(
pos
<
length
)
{
while
(
pos
<
length
)
{
wchar_t
wc
;
TdWchar
wc
;
int
bytes
=
mbtowc
(
&
wc
,
str
+
pos
,
MB_CUR_MAX
);
int
bytes
=
taosMbToWchar
(
&
wc
,
str
+
pos
,
MB_CUR_MAX
);
if
(
bytes
==
0
)
{
if
(
bytes
==
0
)
{
break
;
break
;
}
}
...
@@ -577,7 +577,7 @@ static void shellPrintNChar(const char *str, int length, int width) {
...
@@ -577,7 +577,7 @@ static void shellPrintNChar(const char *str, int length, int width) {
#ifdef WINDOWS
#ifdef WINDOWS
int
w
=
bytes
;
int
w
=
bytes
;
#else
#else
int
w
=
wcw
idth
(
wc
);
int
w
=
taosWcharW
idth
(
wc
);
#endif
#endif
if
(
w
<=
0
)
{
if
(
w
<=
0
)
{
continue
;
continue
;
...
...
tools/shell/src/shellLinux.c
浏览文件 @
c56743d8
...
@@ -31,7 +31,6 @@
...
@@ -31,7 +31,6 @@
int
indicator
=
1
;
int
indicator
=
1
;
struct
termios
oldtio
;
struct
termios
oldtio
;
extern
int
wcwidth
(
wchar_t
c
);
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
const
char
*
argp_program_version
=
version
;
const
char
*
argp_program_version
=
version
;
const
char
*
argp_program_bug_address
=
"<support@taosdata.com>"
;
const
char
*
argp_program_bug_address
=
"<support@taosdata.com>"
;
...
@@ -456,7 +455,7 @@ void showOnScreen(Command *cmd) {
...
@@ -456,7 +455,7 @@ void showOnScreen(Command *cmd) {
w
.
ws_row
=
30
;
w
.
ws_row
=
30
;
}
}
wchar_t
wc
;
TdWchar
wc
;
int
size
=
0
;
int
size
=
0
;
// Print out the command.
// Print out the command.
...
@@ -471,11 +470,11 @@ void showOnScreen(Command *cmd) {
...
@@ -471,11 +470,11 @@ void showOnScreen(Command *cmd) {
int
remain_column
=
w
.
ws_col
;
int
remain_column
=
w
.
ws_col
;
/* size = cmd->commandSize + prompt_size; */
/* size = cmd->commandSize + prompt_size; */
for
(
char
*
str
=
total_string
;
size
<
cmd
->
commandSize
+
prompt_size
;)
{
for
(
char
*
str
=
total_string
;
size
<
cmd
->
commandSize
+
prompt_size
;)
{
int
ret
=
mbtowc
(
&
wc
,
str
,
MB_CUR_MAX
);
int
ret
=
taosMbToWchar
(
&
wc
,
str
,
MB_CUR_MAX
);
if
(
ret
<
0
)
break
;
if
(
ret
<
0
)
break
;
size
+=
ret
;
size
+=
ret
;
/* assert(size >= 0); */
/* assert(size >= 0); */
int
width
=
wcw
idth
(
wc
);
int
width
=
taosWcharW
idth
(
wc
);
if
(
remain_column
>
width
)
{
if
(
remain_column
>
width
)
{
printf
(
"%lc"
,
wc
);
printf
(
"%lc"
,
wc
);
remain_column
-=
width
;
remain_column
-=
width
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录