Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ac7d250a
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看板
提交
ac7d250a
编写于
1月 04, 2023
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin' into enh/TD-21108
上级
38d1e868
89425dc4
变更
119
展开全部
隐藏空白更改
内联
并排
Showing
119 changed file
with
1580 addition
and
2103 deletion
+1580
-2103
cmake/cmake.define
cmake/cmake.define
+8
-2
cmake/cmake.version
cmake/cmake.version
+1
-1
cmake/taosadapter_CMakeLists.txt.in
cmake/taosadapter_CMakeLists.txt.in
+1
-1
include/common/tmsgcb.h
include/common/tmsgcb.h
+4
-0
include/common/trow.h
include/common/trow.h
+0
-1
include/libs/function/function.h
include/libs/function/function.h
+0
-1
include/libs/sync/sync.h
include/libs/sync/sync.h
+2
-0
include/util/taoserror.h
include/util/taoserror.h
+1
-0
include/util/tbuffer.h
include/util/tbuffer.h
+0
-168
include/util/tjson.h
include/util/tjson.h
+21
-0
include/util/tlog.h
include/util/tlog.h
+7
-0
source/client/src/clientTmq.c
source/client/src/clientTmq.c
+5
-3
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
+1
-1
source/dnode/mgmt/mgmt_snode/src/smWorker.c
source/dnode/mgmt/mgmt_snode/src/smWorker.c
+5
-7
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
+1
-1
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+8
-5
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
+6
-10
source/dnode/mgmt/node_mgmt/src/dmTransport.c
source/dnode/mgmt/node_mgmt/src/dmTransport.c
+2
-0
source/dnode/mgmt/node_util/inc/dmUtil.h
source/dnode/mgmt/node_util/inc/dmUtil.h
+1
-0
source/dnode/mgmt/node_util/src/dmEps.c
source/dnode/mgmt/node_util/src/dmEps.c
+71
-11
source/dnode/mgmt/node_util/src/dmFile.c
source/dnode/mgmt/node_util/src/dmFile.c
+1
-1
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+1
-1
source/dnode/mnode/impl/src/mndDef.c
source/dnode/mnode/impl/src/mndDef.c
+1
-1
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+8
-3
source/dnode/mnode/impl/src/mndShow.c
source/dnode/mnode/impl/src/mndShow.c
+1
-1
source/dnode/mnode/impl/src/mndSma.c
source/dnode/mnode/impl/src/mndSma.c
+11
-7
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+12
-4
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+47
-43
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+6
-2
source/dnode/mnode/impl/src/mndTelem.c
source/dnode/mnode/impl/src/mndTelem.c
+0
-1
source/dnode/mnode/impl/src/mndTopic.c
source/dnode/mnode/impl/src/mndTopic.c
+5
-3
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+2
-2
source/dnode/vnode/src/tq/tqMeta.c
source/dnode/vnode/src/tq/tqMeta.c
+1
-2
source/dnode/vnode/src/tq/tqOffset.c
source/dnode/vnode/src/tq/tqOffset.c
+22
-6
source/dnode/vnode/src/tq/tqSink.c
source/dnode/vnode/src/tq/tqSink.c
+1
-1
source/dnode/vnode/src/tq/tqSnapshot.c
source/dnode/vnode/src/tq/tqSnapshot.c
+3
-1
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+48
-49
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
+52
-55
source/dnode/vnode/src/vnd/vnodeCfg.c
source/dnode/vnode/src/vnd/vnodeCfg.c
+31
-13
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+4
-2
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+5
-2
source/dnode/vnode/src/vnd/vnodeSnapshot.c
source/dnode/vnode/src/vnd/vnodeSnapshot.c
+4
-0
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+2
-1
source/libs/executor/inc/executil.h
source/libs/executor/inc/executil.h
+4
-1
source/libs/executor/src/dataInserter.c
source/libs/executor/src/dataInserter.c
+10
-3
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+4
-2
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+35
-1
source/libs/executor/src/groupoperator.c
source/libs/executor/src/groupoperator.c
+16
-3
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+4
-0
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+14
-0
source/libs/executor/src/tsort.c
source/libs/executor/src/tsort.c
+9
-0
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+1
-1
source/libs/function/src/detail/tminmax.c
source/libs/function/src/detail/tminmax.c
+10
-5
source/libs/function/src/tfunctionInt.c
source/libs/function/src/tfunctionInt.c
+0
-1
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+3
-2
source/libs/index/inc/indexUtil.h
source/libs/index/inc/indexUtil.h
+0
-1
source/libs/index/src/index.c
source/libs/index/src/index.c
+3
-1
source/libs/index/src/indexComm.c
source/libs/index/src/indexComm.c
+2
-3
source/libs/index/src/indexFilter.c
source/libs/index/src/indexFilter.c
+3
-1
source/libs/index/src/indexFst.c
source/libs/index/src/indexFst.c
+28
-32
source/libs/index/src/indexFstDfa.c
source/libs/index/src/indexFstDfa.c
+3
-2
source/libs/index/src/indexFstFile.c
source/libs/index/src/indexFstFile.c
+9
-5
source/libs/index/src/indexFstRegister.c
source/libs/index/src/indexFstRegister.c
+2
-2
source/libs/index/src/indexFstUtil.c
source/libs/index/src/indexFstUtil.c
+0
-1
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+8
-8
source/libs/stream/src/streamMeta.c
source/libs/stream/src/streamMeta.c
+1
-0
source/libs/stream/src/streamState.c
source/libs/stream/src/streamState.c
+1
-1
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+14
-2
source/libs/sync/inc/syncRaftCfg.h
source/libs/sync/inc/syncRaftCfg.h
+3
-58
source/libs/sync/inc/syncUtil.h
source/libs/sync/inc/syncUtil.h
+8
-11
source/libs/sync/src/syncElection.c
source/libs/sync/src/syncElection.c
+1
-1
source/libs/sync/src/syncEnv.c
source/libs/sync/src/syncEnv.c
+1
-1
source/libs/sync/src/syncIndexMgr.c
source/libs/sync/src/syncIndexMgr.c
+17
-37
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+116
-149
source/libs/sync/src/syncPipeline.c
source/libs/sync/src/syncPipeline.c
+10
-13
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+168
-324
source/libs/sync/src/syncRaftStore.c
source/libs/sync/src/syncRaftStore.c
+0
-7
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+3
-14
source/libs/sync/src/syncTimeout.c
source/libs/sync/src/syncTimeout.c
+10
-8
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+83
-281
source/libs/sync/test/syncRaftCfgIndexTest.cpp
source/libs/sync/test/syncRaftCfgIndexTest.cpp
+12
-12
source/libs/sync/test/syncRaftCfgTest.cpp
source/libs/sync/test/syncRaftCfgTest.cpp
+28
-28
source/libs/sync/test/sync_test_lib/inc/syncTest.h
source/libs/sync/test/sync_test_lib/inc/syncTest.h
+5
-0
source/libs/sync/test/sync_test_lib/src/syncBatch.c
source/libs/sync/test/sync_test_lib/src/syncBatch.c
+1
-1
source/libs/sync/test/sync_test_lib/src/syncIO.c
source/libs/sync/test/sync_test_lib/src/syncIO.c
+71
-7
source/libs/sync/test/sync_test_lib/src/syncIndexMgrDebug.c
source/libs/sync/test/sync_test_lib/src/syncIndexMgrDebug.c
+2
-2
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
+10
-10
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
+2
-2
source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c
source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c
+7
-6
source/libs/sync/test/sync_test_lib/src/syncUtilDebug.c
source/libs/sync/test/sync_test_lib/src/syncUtilDebug.c
+5
-4
source/libs/sync/test/sync_test_lib/src/syncVoteMgrDebug.c
source/libs/sync/test/sync_test_lib/src/syncVoteMgrDebug.c
+4
-4
source/libs/transport/src/tmsgcb.c
source/libs/transport/src/tmsgcb.c
+4
-1
source/libs/transport/src/trans.c
source/libs/transport/src/trans.c
+3
-12
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+8
-5
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+5
-2
source/libs/transport/src/transSvr.c
source/libs/transport/src/transSvr.c
+16
-10
source/os/src/osFile.c
source/os/src/osFile.c
+17
-51
source/util/src/talgo.c
source/util/src/talgo.c
+1
-1
source/util/src/tbuffer.c
source/util/src/tbuffer.c
+0
-424
source/util/src/tcompare.c
source/util/src/tcompare.c
+3
-3
source/util/src/tcompression.c
source/util/src/tcompression.c
+93
-45
source/util/src/tdigest.c
source/util/src/tdigest.c
+5
-4
source/util/src/terror.c
source/util/src/terror.c
+2
-1
source/util/src/texception.c
source/util/src/texception.c
+7
-6
source/util/src/tlosertree.c
source/util/src/tlosertree.c
+3
-3
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+19
-15
source/util/src/trbtree.c
source/util/src/trbtree.c
+8
-7
source/util/src/tref.c
source/util/src/tref.c
+1
-1
source/util/src/ttimer.c
source/util/src/ttimer.c
+2
-3
source/util/src/tutil.c
source/util/src/tutil.c
+13
-4
tests/parallel_test/cases.task
tests/parallel_test/cases.task
+5
-0
tests/pytest/auto_crash_gen.py
tests/pytest/auto_crash_gen.py
+7
-10
tests/pytest/auto_crash_gen_valgrind.py
tests/pytest/auto_crash_gen_valgrind.py
+7
-9
tests/pytest/auto_crash_gen_valgrind_cluster.py
tests/pytest/auto_crash_gen_valgrind_cluster.py
+7
-9
tests/script/tmp/data.sim
tests/script/tmp/data.sim
+10
-2
tests/script/tsim/insert/insert_select.sim
tests/script/tsim/insert/insert_select.sim
+20
-0
tests/system-test/2-query/blockSMA.py
tests/system-test/2-query/blockSMA.py
+146
-0
utils/tsim/inc/simInt.h
utils/tsim/inc/simInt.h
+1
-1
utils/tsim/src/simSystem.c
utils/tsim/src/simSystem.c
+3
-3
未找到文件。
cmake/cmake.define
浏览文件 @
ac7d250a
...
...
@@ -117,12 +117,18 @@ ELSE ()
IF (${BUILD_SANITIZER})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3 -Wformat=0")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3 -Wformat=0")
MESSAGE(STATUS "
Will c
ompile with Address Sanitizer!")
MESSAGE(STATUS "
C
ompile with Address Sanitizer!")
ELSE ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation -Wno-format-y2k")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation -Wno-format-y2k")
ENDIF ()
# disable all assert
IF ((${DISABLE_ASSERT} MATCHES "true") OR (${DISABLE_ASSERTS} MATCHES "true"))
ADD_DEFINITIONS(-DDISABLE_ASSERT)
MESSAGE(STATUS "Disable all asserts")
ENDIF()
INCLUDE(CheckCCompilerFlag)
IF (TD_ARM_64 OR TD_ARM_32)
SET(COMPILER_SUPPORT_SSE42 false)
...
...
@@ -155,7 +161,7 @@ ELSE ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
ENDIF()
MESSAGE(STATUS "SIMD instructions (AVX/AVX2) is ACTIVATED")
MESSAGE(STATUS "SIMD instructions (
FMA/
AVX/AVX2) is ACTIVATED")
ENDIF()
ENDIF ()
cmake/cmake.version
浏览文件 @
ac7d250a
...
...
@@ -2,7 +2,7 @@
IF (DEFINED VERNUMBER)
SET(TD_VER_NUMBER ${VERNUMBER})
ELSE ()
SET(TD_VER_NUMBER "3.0.2.
1
")
SET(TD_VER_NUMBER "3.0.2.
2
")
ENDIF ()
IF (DEFINED VERCOMPATIBLE)
...
...
cmake/taosadapter_CMakeLists.txt.in
浏览文件 @
ac7d250a
...
...
@@ -2,7 +2,7 @@
# taosadapter
ExternalProject_Add(taosadapter
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
GIT_TAG
5662a6d
GIT_TAG
a2e9920
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
...
...
include/common/tmsgcb.h
浏览文件 @
ac7d250a
...
...
@@ -39,6 +39,7 @@ typedef enum {
QUEUE_MAX
,
}
EQueueType
;
typedef
int32_t
(
*
UpdateDnodeInfoFp
)(
void
*
pData
,
int32_t
*
dnodeId
,
int64_t
*
clusterId
,
char
*
fqdn
,
uint16_t
*
port
);
typedef
int32_t
(
*
PutToQueueFp
)(
void
*
pMgmt
,
EQueueType
qtype
,
SRpcMsg
*
pMsg
);
typedef
int32_t
(
*
GetQueueSizeFp
)(
void
*
pMgmt
,
int32_t
vgId
,
EQueueType
qtype
);
typedef
int32_t
(
*
SendReqFp
)(
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
);
...
...
@@ -48,6 +49,7 @@ typedef void (*ReleaseHandleFp)(SRpcHandleInfo* pHandle, int8_t type);
typedef
void
(
*
ReportStartup
)(
const
char
*
name
,
const
char
*
desc
);
typedef
struct
{
void
*
data
;
void
*
mgmt
;
void
*
clientRpc
;
PutToQueueFp
putToQueueFp
;
...
...
@@ -57,6 +59,7 @@ typedef struct {
RegisterBrokenLinkArgFp
registerBrokenLinkArgFp
;
ReleaseHandleFp
releaseHandleFp
;
ReportStartup
reportStartupFp
;
UpdateDnodeInfoFp
updateDnodeInfoFp
;
}
SMsgCb
;
void
tmsgSetDefault
(
const
SMsgCb
*
msgcb
);
...
...
@@ -67,6 +70,7 @@ void tmsgSendRsp(SRpcMsg* pMsg);
void
tmsgRegisterBrokenLinkArg
(
SRpcMsg
*
pMsg
);
void
tmsgReleaseHandle
(
SRpcHandleInfo
*
pHandle
,
int8_t
type
);
void
tmsgReportStartup
(
const
char
*
name
,
const
char
*
desc
);
int32_t
tmsgUpdateDnodeInfo
(
int32_t
*
dnodeId
,
int64_t
*
clusterId
,
char
*
fqdn
,
uint16_t
*
port
);
#ifdef __cplusplus
}
...
...
include/common/trow.h
浏览文件 @
ac7d250a
...
...
@@ -20,7 +20,6 @@
#include "talgo.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tbuffer.h"
#include "tdataformat.h"
#include "tdef.h"
#include "ttypes.h"
...
...
include/libs/function/function.h
浏览文件 @
ac7d250a
...
...
@@ -20,7 +20,6 @@
extern
"C"
{
#endif
#include "tbuffer.h"
#include "tcommon.h"
#include "tvariant.h"
...
...
include/libs/sync/sync.h
浏览文件 @
ac7d250a
...
...
@@ -78,6 +78,8 @@ typedef enum {
}
ESyncState
;
typedef
struct
SNodeInfo
{
int64_t
clusterId
;
int32_t
nodeId
;
uint16_t
nodePort
;
char
nodeFqdn
[
TSDB_FQDN_LEN
];
}
SNodeInfo
;
...
...
include/util/taoserror.h
浏览文件 @
ac7d250a
...
...
@@ -345,6 +345,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_TOPIC_SUBSCRIBED TAOS_DEF_ERROR_CODE(0, 0x03EB)
#define TSDB_CODE_MND_CGROUP_USED TAOS_DEF_ERROR_CODE(0, 0x03EC)
#define TSDB_CODE_MND_TOPIC_MUST_BE_DELETED TAOS_DEF_ERROR_CODE(0, 0x03ED)
#define TSDB_CODE_MND_INVALID_SUB_OPTION TAOS_DEF_ERROR_CODE(0, 0x03EE)
#define TSDB_CODE_MND_IN_REBALANCE TAOS_DEF_ERROR_CODE(0, 0x03EF)
// mnode-stream
...
...
include/util/tbuffer.h
已删除
100644 → 0
浏览文件 @
38d1e868
/*
* Copyright (c) 2020 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_UTIL_BUFFER_H_
#define _TD_UTIL_BUFFER_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
////////////////////////////////////////////////////////////////////////////////
// usage example
/*
#include <stdio.h>
#include "texception.h"
int32_t main( int32_t argc, char** argv ) {
SBufferWriter bw = tbufInitWriter( NULL, false );
TRY( 1 ) {
//--------------------- write ------------------------
// reserve 1024 bytes for the buffer to improve performance
tbufEnsureCapacity( &bw, 1024 );
// reserve space for the interger count
size_t pos = tbufReserve( &bw, sizeof(int32_t) );
// write 5 integers to the buffer
for( int32_t i = 0; i < 5; i++) {
tbufWriteInt32( &bw, i );
}
// write the integer count to buffer at reserved position
tbufWriteInt32At( &bw, pos, 5 );
// write a string to the buffer
tbufWriteString( &bw, "this is a string.\n" );
// acquire the result and close the write buffer
size_t size = tbufTell( &bw );
char* data = tbufGetData( &bw, false );
//------------------------ read -----------------------
SBufferReader br = tbufInitReader( data, size, false );
// read & print out all integers
int32_t count = tbufReadInt32( &br );
for( int32_t i = 0; i < count; i++ ) {
printf( "%d\n", tbufReadInt32(&br) );
}
// read & print out a string
puts( tbufReadString(&br, NULL) );
// try read another integer, this result in an error as there no this integer
tbufReadInt32( &br );
printf( "you should not see this message.\n" );
} CATCH( code ) {
printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code );
} END_TRY
tbufCloseWriter( &bw );
return 0;
}
*/
typedef
struct
SBufferReader
{
bool
endian
;
const
char
*
data
;
size_t
pos
;
size_t
size
;
}
SBufferReader
;
typedef
struct
SBufferWriter
{
bool
endian
;
char
*
data
;
size_t
pos
;
size_t
size
;
void
*
(
*
allocator
)(
void
*
,
size_t
);
}
SBufferWriter
;
// common functions & macros for both reader & writer
#define tbufTell(buf) ((buf)->pos)
/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */
// *Allocator*, function to allocate memory, will use 'realloc' if NULL
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically
#define tbufInitWriter(Allocator, Endian) \
{ .endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator)) }
void
tbufCloseWriter
(
SBufferWriter
*
buf
);
void
tbufEnsureCapacity
(
SBufferWriter
*
buf
,
size_t
size
);
size_t
tbufReserve
(
SBufferWriter
*
buf
,
size_t
size
);
char
*
tbufGetData
(
SBufferWriter
*
buf
,
bool
takeOver
);
void
tbufWrite
(
SBufferWriter
*
buf
,
const
void
*
data
,
size_t
size
);
void
tbufWriteAt
(
SBufferWriter
*
buf
,
size_t
pos
,
const
void
*
data
,
size_t
size
);
void
tbufWriteStringLen
(
SBufferWriter
*
buf
,
const
char
*
str
,
size_t
len
);
void
tbufWriteString
(
SBufferWriter
*
buf
,
const
char
*
str
);
// the prototype of tbufWriteBinary and tbufWrite are identical
// the difference is: tbufWriteBinary writes the length of the data to the buffer
// first, then the actual data, which means the reader don't need to know data
// size before read. Write only write the data itself, which means the reader
// need to know data size before read.
void
tbufWriteBinary
(
SBufferWriter
*
buf
,
const
void
*
data
,
size_t
len
);
void
tbufWriteBool
(
SBufferWriter
*
buf
,
bool
data
);
void
tbufWriteBoolAt
(
SBufferWriter
*
buf
,
size_t
pos
,
bool
data
);
void
tbufWriteChar
(
SBufferWriter
*
buf
,
char
data
);
void
tbufWriteCharAt
(
SBufferWriter
*
buf
,
size_t
pos
,
char
data
);
void
tbufWriteInt8
(
SBufferWriter
*
buf
,
int8_t
data
);
void
tbufWriteInt8At
(
SBufferWriter
*
buf
,
size_t
pos
,
int8_t
data
);
void
tbufWriteUint8
(
SBufferWriter
*
buf
,
uint8_t
data
);
void
tbufWriteUint8At
(
SBufferWriter
*
buf
,
size_t
pos
,
uint8_t
data
);
void
tbufWriteInt16
(
SBufferWriter
*
buf
,
int16_t
data
);
void
tbufWriteInt16At
(
SBufferWriter
*
buf
,
size_t
pos
,
int16_t
data
);
void
tbufWriteUint16
(
SBufferWriter
*
buf
,
uint16_t
data
);
void
tbufWriteUint16At
(
SBufferWriter
*
buf
,
size_t
pos
,
uint16_t
data
);
void
tbufWriteInt32
(
SBufferWriter
*
buf
,
int32_t
data
);
void
tbufWriteInt32At
(
SBufferWriter
*
buf
,
size_t
pos
,
int32_t
data
);
void
tbufWriteUint32
(
SBufferWriter
*
buf
,
uint32_t
data
);
void
tbufWriteUint32At
(
SBufferWriter
*
buf
,
size_t
pos
,
uint32_t
data
);
void
tbufWriteInt64
(
SBufferWriter
*
buf
,
int64_t
data
);
void
tbufWriteInt64At
(
SBufferWriter
*
buf
,
size_t
pos
,
int64_t
data
);
void
tbufWriteUint64
(
SBufferWriter
*
buf
,
uint64_t
data
);
void
tbufWriteUint64At
(
SBufferWriter
*
buf
,
size_t
pos
,
uint64_t
data
);
void
tbufWriteFloat
(
SBufferWriter
*
buf
,
float
data
);
void
tbufWriteFloatAt
(
SBufferWriter
*
buf
,
size_t
pos
,
float
data
);
void
tbufWriteDouble
(
SBufferWriter
*
buf
,
double
data
);
void
tbufWriteDoubleAt
(
SBufferWriter
*
buf
,
size_t
pos
,
double
data
);
/* ------------------------ BUFFER READER FUNCTIONS AND MACROS ------------------------ */
// *Endian*, if true, reader functions of primitive types will do 'ntoh' automatically
#define tbufInitReader(Data, Size, Endian) \
{ .endian = (Endian), .data = (Data), .pos = 0, .size = ((Data) == NULL ? 0 : (Size)) }
size_t
tbufSkip
(
SBufferReader
*
buf
,
size_t
size
);
const
char
*
tbufRead
(
SBufferReader
*
buf
,
size_t
size
);
void
tbufReadToBuffer
(
SBufferReader
*
buf
,
void
*
dst
,
size_t
size
);
const
char
*
tbufReadString
(
SBufferReader
*
buf
,
size_t
*
len
);
size_t
tbufReadToString
(
SBufferReader
*
buf
,
char
*
dst
,
size_t
size
);
const
char
*
tbufReadBinary
(
SBufferReader
*
buf
,
size_t
*
len
);
size_t
tbufReadToBinary
(
SBufferReader
*
buf
,
void
*
dst
,
size_t
size
);
bool
tbufReadBool
(
SBufferReader
*
buf
);
char
tbufReadChar
(
SBufferReader
*
buf
);
int8_t
tbufReadInt8
(
SBufferReader
*
buf
);
uint8_t
tbufReadUint8
(
SBufferReader
*
buf
);
int16_t
tbufReadInt16
(
SBufferReader
*
buf
);
uint16_t
tbufReadUint16
(
SBufferReader
*
buf
);
int32_t
tbufReadInt32
(
SBufferReader
*
buf
);
uint32_t
tbufReadUint32
(
SBufferReader
*
buf
);
int64_t
tbufReadInt64
(
SBufferReader
*
buf
);
uint64_t
tbufReadUint64
(
SBufferReader
*
buf
);
float
tbufReadFloat
(
SBufferReader
*
buf
);
double
tbufReadDouble
(
SBufferReader
*
buf
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_UTIL_BUFFER_H_*/
include/util/tjson.h
浏览文件 @
ac7d250a
...
...
@@ -30,6 +30,27 @@ extern "C" {
val = _tmp; \
} while (0)
#define tjsonGetInt32ValueFromDouble(pJson, pName, val, code) \
do { \
double _tmp = 0; \
code = tjsonGetDoubleValue(pJson, pName, &_tmp); \
val = (int32_t)_tmp; \
} while (0)
#define tjsonGetInt8ValueFromDouble(pJson, pName, val, code) \
do { \
double _tmp = 0; \
code = tjsonGetDoubleValue(pJson, pName, &_tmp); \
val = (int8_t)_tmp; \
} while (0)
#define tjsonGetUInt16ValueFromDouble(pJson, pName, val, code) \
do { \
double _tmp = 0; \
code = tjsonGetDoubleValue(pJson, pName, &_tmp); \
val = (uint16_t)_tmp; \
} while (0)
typedef
void
SJson
;
SJson
*
tjsonCreateObject
();
...
...
include/util/tlog.h
浏览文件 @
ac7d250a
...
...
@@ -85,12 +85,19 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
bool
taosAssertDebug
(
bool
condition
,
const
char
*
file
,
int32_t
line
,
const
char
*
format
,
...);
bool
taosAssertRelease
(
bool
condition
);
// Disable all asserts that may compromise the performance.
#if defined DISABLE_ASSERT
#define ASSERT(condition)
#define ASSERTS(condition, ...)
#else
#define ASSERTS(condition, ...) taosAssertDebug(condition, __FILE__, __LINE__, __VA_ARGS__)
#ifdef NDEBUG
#define ASSERT(condition) taosAssertRelease(condition)
#else
#define ASSERT(condition) taosAssertDebug(condition, __FILE__, __LINE__, "assert info not provided")
#endif
#endif
void
taosLogCrashInfo
(
char
*
nodeType
,
char
*
pMsg
,
int64_t
msgLen
,
int
signum
,
void
*
sigInfo
);
void
taosReadCrashInfo
(
char
*
filepath
,
char
**
pMsg
,
int64_t
*
pMsgLen
,
TdFilePtr
*
pFd
);
...
...
source/client/src/clientTmq.c
浏览文件 @
ac7d250a
...
...
@@ -912,10 +912,12 @@ void tmqFreeImpl(void* handle) {
tmq_t
*
tmq
=
(
tmq_t
*
)
handle
;
// TODO stop timer
tmqClearUnhandleMsg
(
tmq
);
if
(
tmq
->
mqueue
)
taosCloseQueue
(
tmq
->
mqueue
);
if
(
tmq
->
mqueue
)
{
tmqClearUnhandleMsg
(
tmq
);
taosCloseQueue
(
tmq
->
mqueue
);
}
if
(
tmq
->
delayedTask
)
taosCloseQueue
(
tmq
->
delayedTask
);
if
(
tmq
->
qall
)
taosFreeQall
(
tmq
->
qall
);
taosFreeQall
(
tmq
->
qall
);
tsem_destroy
(
&
tmq
->
rspSem
);
...
...
source/dnode/mgmt/mgmt_mnode/src/mmFile.c
浏览文件 @
ac7d250a
...
...
@@ -180,6 +180,6 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
return
-
1
;
}
dDebug
(
"succe
ss
ed to write %s, deployed:%d"
,
realfile
,
pOption
->
deploy
);
dDebug
(
"succeed to write %s, deployed:%d"
,
realfile
,
pOption
->
deploy
);
return
0
;
}
source/dnode/mgmt/mgmt_snode/src/smWorker.c
浏览文件 @
ac7d250a
...
...
@@ -58,11 +58,7 @@ static void smProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
dTrace
(
"msg:%p, get from snode-stream queue"
,
pMsg
);
int32_t
code
=
sndProcessStreamMsg
(
pMgmt
->
pSnode
,
pMsg
);
if
(
code
<
0
)
{
if
(
pMsg
)
{
dGError
(
"snd, msg:%p failed to process stream msg %s since %s"
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
),
terrstr
(
code
));
}
else
{
dGError
(
"snd, msg:%p failed to process stream empty msg since %s"
,
pMsg
,
terrstr
(
code
));
}
dGError
(
"snd, msg:%p failed to process stream msg %s since %s"
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
),
terrstr
(
code
));
smSendRsp
(
pMsg
,
terrno
);
}
...
...
@@ -161,8 +157,10 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
smPutNodeMsgToWriteQueue
(
pMgmt
,
pMsg
);
break
;
default:
ASSERTS
(
0
,
"msg:%p failed to put into snode queue since %s, type:%s qtype:%d"
,
pMsg
,
terrstr
(),
TMSG_INFO
(
pMsg
->
msgType
),
qtype
);
terrno
=
TSDB_CODE_INVALID_PARA
;
rpcFreeCont
(
pMsg
->
pCont
);
taosFreeQitem
(
pMsg
);
return
-
1
;
}
return
0
;
}
...
...
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
浏览文件 @
ac7d250a
...
...
@@ -215,7 +215,7 @@ _OVER:
if
(
code
!=
0
)
return
-
1
;
dInfo
(
"succe
ss
ed to write %s, numOfVnodes:%d"
,
realfile
,
numOfVnodes
);
dInfo
(
"succeed to write %s, numOfVnodes:%d"
,
realfile
,
numOfVnodes
);
code
=
taosRenameFile
(
file
,
realfile
);
if
(
code
!=
0
)
{
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
ac7d250a
...
...
@@ -132,10 +132,12 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
pCfg
->
syncCfg
.
myIndex
=
pCreate
->
selfIndex
;
pCfg
->
syncCfg
.
replicaNum
=
pCreate
->
replica
;
memset
(
&
pCfg
->
syncCfg
.
nodeInfo
,
0
,
sizeof
(
pCfg
->
syncCfg
.
nodeInfo
));
for
(
int
i
=
0
;
i
<
pCreate
->
replica
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
pCreate
->
replica
;
++
i
)
{
SNodeInfo
*
pNode
=
&
pCfg
->
syncCfg
.
nodeInfo
[
i
];
pNode
->
nodeId
=
pCreate
->
replicas
[
i
].
id
;
pNode
->
nodePort
=
pCreate
->
replicas
[
i
].
port
;
tstrncpy
(
pNode
->
nodeFqdn
,
pCreate
->
replicas
[
i
].
fqdn
,
sizeof
(
pNode
->
nodeFqdn
));
tstrncpy
(
pNode
->
nodeFqdn
,
pCreate
->
replicas
[
i
].
fqdn
,
TSDB_FQDN_LEN
);
(
void
)
tmsgUpdateDnodeInfo
(
&
pNode
->
nodeId
,
&
pNode
->
clusterId
,
pNode
->
nodeFqdn
,
&
pNode
->
nodePort
);
}
}
...
...
@@ -188,8 +190,8 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
req
.
walRollPeriod
,
req
.
walSegmentSize
,
req
.
hashMethod
,
req
.
hashBegin
,
req
.
hashEnd
,
req
.
hashPrefix
,
req
.
hashSuffix
,
req
.
replica
,
req
.
selfIndex
,
req
.
strict
);
for
(
int32_t
i
=
0
;
i
<
req
.
replica
;
++
i
)
{
dInfo
(
"vgId:%d, replica:%d
id:%d fqdn:%s port:%u"
,
req
.
vgId
,
i
,
req
.
replicas
[
i
].
id
,
req
.
replicas
[
i
].
fqdn
,
req
.
replicas
[
i
].
port
);
dInfo
(
"vgId:%d, replica:%d
ep:%s:%u dnode:%d"
,
req
.
vgId
,
i
,
req
.
replicas
[
i
].
fqdn
,
req
.
replicas
[
i
].
port
,
req
.
replicas
[
i
].
id
);
}
SReplica
*
pReplica
=
&
req
.
replicas
[
req
.
selfIndex
];
...
...
@@ -286,7 +288,8 @@ int32_t vmProcessAlterVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
dInfo
(
"vgId:%d, start to alter vnode, replica:%d selfIndex:%d strict:%d"
,
alterReq
.
vgId
,
alterReq
.
replica
,
alterReq
.
selfIndex
,
alterReq
.
strict
);
for
(
int32_t
i
=
0
;
i
<
alterReq
.
replica
;
++
i
)
{
dInfo
(
"vgId:%d, replica:%d ep:%s:%u"
,
alterReq
.
vgId
,
i
,
alterReq
.
replicas
[
i
].
fqdn
,
alterReq
.
replicas
[
i
].
port
);
SReplica
*
pReplica
=
&
alterReq
.
replicas
[
i
];
dInfo
(
"vgId:%d, replica:%d ep:%s:%u dnode:%d"
,
alterReq
.
vgId
,
i
,
pReplica
->
fqdn
,
pReplica
->
port
,
pReplica
->
port
);
}
if
(
alterReq
.
replica
<=
0
||
alterReq
.
selfIndex
<
0
||
alterReq
.
selfIndex
>=
alterReq
.
replica
)
{
...
...
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
浏览文件 @
ac7d250a
...
...
@@ -86,12 +86,8 @@ static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
int32_t
code
=
vnodeProcessFetchMsg
(
pVnode
->
pImpl
,
pMsg
,
pInfo
);
if
(
code
!=
0
)
{
if
(
terrno
!=
0
)
code
=
terrno
;
if
(
pMsg
)
{
dGError
(
"vgId:%d, msg:%p failed to process stream msg %s since %s"
,
pVnode
->
vgId
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
),
terrstr
(
code
));
}
else
{
dGError
(
"vgId:%d, msg:%p failed to process stream empty msg since %s"
,
pVnode
->
vgId
,
pMsg
,
terrstr
(
code
));
}
dGError
(
"vgId:%d, msg:%p failed to process stream msg %s since %s"
,
pVnode
->
vgId
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
),
terrstr
(
code
));
vmSendRsp
(
pMsg
,
code
);
}
...
...
@@ -146,16 +142,16 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
return
-
1
;
}
SMsgHead
*
pHead
=
pMsg
->
pCont
;
int32_t
code
=
0
;
SMsgHead
*
pHead
=
pMsg
->
pCont
;
int32_t
code
=
0
;
pHead
->
contLen
=
ntohl
(
pHead
->
contLen
);
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
SVnodeObj
*
pVnode
=
vmAcquireVnode
(
pMgmt
,
pHead
->
vgId
);
if
(
pVnode
==
NULL
)
{
dGError
(
"vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d"
,
pHead
->
vgId
,
pMsg
,
terrstr
(),
TMSG_INFO
(
pMsg
->
msgType
),
qtype
,
pHead
->
contLen
);
dGError
(
"vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d"
,
pHead
->
vgId
,
pMsg
,
terrstr
(),
TMSG_INFO
(
pMsg
->
msgType
),
qtype
,
pHead
->
contLen
);
return
terrno
!=
0
?
terrno
:
-
1
;
}
...
...
source/dnode/mgmt/node_mgmt/src/dmTransport.c
浏览文件 @
ac7d250a
...
...
@@ -345,6 +345,8 @@ SMsgCb dmGetMsgcb(SDnode *pDnode) {
.
registerBrokenLinkArgFp
=
dmRegisterBrokenLinkArg
,
.
releaseHandleFp
=
dmReleaseHandle
,
.
reportStartupFp
=
dmReportStartup
,
.
updateDnodeInfoFp
=
dmUpdateDnodeInfo
,
.
data
=
&
pDnode
->
data
,
};
return
msgCb
;
}
source/dnode/mgmt/node_util/inc/dmUtil.h
浏览文件 @
ac7d250a
...
...
@@ -167,6 +167,7 @@ void dmUpdateEps(SDnodeData *pData, SArray *pDnodeEps);
void
dmGetMnodeEpSet
(
SDnodeData
*
pData
,
SEpSet
*
pEpSet
);
void
dmGetMnodeEpSetForRedirect
(
SDnodeData
*
pData
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
void
dmSetMnodeEpSet
(
SDnodeData
*
pData
,
SEpSet
*
pEpSet
);
int32_t
dmUpdateDnodeInfo
(
void
*
pData
,
int32_t
*
dnodeId
,
int64_t
*
clusterId
,
char
*
fqdn
,
uint16_t
*
port
);
#ifdef __cplusplus
}
...
...
source/dnode/mgmt/node_util/src/dmEps.c
浏览文件 @
ac7d250a
...
...
@@ -182,22 +182,25 @@ _OVER:
}
int32_t
dmWriteEps
(
SDnodeData
*
pData
)
{
int32_t
code
=
-
1
;
char
*
content
=
NULL
;
TdFilePtr
pFile
=
NULL
;
char
file
[
PATH_MAX
]
=
{
0
};
char
realfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%sdnode%sdnode.json.bak"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%sdnode%sdnode.json"
,
tsDataDir
,
TD_DIRSEP
,
TD_DIRSEP
);
TdFilePtr
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
dError
(
"failed to
write
%s since %s"
,
file
,
strerror
(
errno
));
dError
(
"failed to
open
%s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
goto
_OVER
;
}
int32_t
len
=
0
;
int32_t
maxLen
=
256
*
1024
;
c
har
*
c
ontent
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
content
=
taosMemoryCalloc
(
1
,
maxLen
+
1
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
dnodeId
\"
: %d,
\n
"
,
pData
->
dnodeId
);
...
...
@@ -221,20 +224,39 @@ int32_t dmWriteEps(SDnodeData *pData) {
}
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
taosWriteFile
(
pFile
,
content
,
len
);
taosFsyncFile
(
pFile
);
if
(
taosWriteFile
(
pFile
,
content
,
len
)
!=
len
)
{
dError
(
"failed to write %s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_OVER
;
}
if
(
taosFsyncFile
(
pFile
)
<
0
)
{
dError
(
"failed to fsync %s since %s"
,
file
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_OVER
;
}
taosCloseFile
(
&
pFile
);
taosMemoryFree
(
content
);
taosMemoryFree
Clear
(
content
);
if
(
taosRenameFile
(
file
,
realfile
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to rename %s since %s"
,
file
,
terrstr
());
return
-
1
;
goto
_OVER
;
}
code
=
0
;
pData
->
updateTime
=
taosGetTimestampMs
();
dDebug
(
"successed to write %s, dnodeVer:%"
PRId64
,
realfile
,
pData
->
dnodeVer
);
return
0
;
dInfo
(
"succeed to write %s, dnodeVer:%"
PRId64
,
realfile
,
pData
->
dnodeVer
);
_OVER:
if
(
content
!=
NULL
)
taosMemoryFreeClear
(
content
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
code
!=
0
)
{
dError
(
"failed to write file %s since %s"
,
realfile
,
terrstr
());
}
return
code
;
}
void
dmUpdateEps
(
SDnodeData
*
pData
,
SArray
*
eps
)
{
...
...
@@ -332,3 +354,41 @@ void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet) {
dInfo
(
"mnode index:%d %s:%u"
,
i
,
pEpSet
->
eps
[
i
].
fqdn
,
pEpSet
->
eps
[
i
].
port
);
}
}
int32_t
dmUpdateDnodeInfo
(
void
*
data
,
int32_t
*
dnodeId
,
int64_t
*
clusterId
,
char
*
fqdn
,
uint16_t
*
port
)
{
SDnodeData
*
pData
=
data
;
int32_t
ret
=
-
1
;
taosThreadRwlockRdlock
(
&
pData
->
lock
);
if
(
*
dnodeId
<=
0
)
{
for
(
int32_t
i
=
0
;
i
<
(
int32_t
)
taosArrayGetSize
(
pData
->
dnodeEps
);
++
i
)
{
SDnodeEp
*
pDnodeEp
=
taosArrayGet
(
pData
->
dnodeEps
,
i
);
if
(
strcmp
(
pDnodeEp
->
ep
.
fqdn
,
fqdn
)
==
0
&&
pDnodeEp
->
ep
.
port
==
*
port
)
{
dInfo
(
"dnode:%s:%u, update dnodeId from %d to %d"
,
fqdn
,
*
port
,
*
dnodeId
,
pDnodeEp
->
id
);
*
dnodeId
=
pDnodeEp
->
id
;
*
clusterId
=
pData
->
clusterId
;
ret
=
0
;
}
}
if
(
ret
!=
0
)
{
dInfo
(
"dnode:%s:%u, failed to update dnodeId:%d"
,
fqdn
,
*
port
,
*
dnodeId
);
}
}
else
{
SDnodeEp
*
pDnodeEp
=
taosHashGet
(
pData
->
dnodeHash
,
dnodeId
,
sizeof
(
int32_t
));
if
(
pDnodeEp
)
{
if
(
strcmp
(
pDnodeEp
->
ep
.
fqdn
,
fqdn
)
!=
0
)
{
dInfo
(
"dnode:%d, update port from %s to %s"
,
*
dnodeId
,
fqdn
,
pDnodeEp
->
ep
.
fqdn
);
tstrncpy
(
fqdn
,
pDnodeEp
->
ep
.
fqdn
,
TSDB_FQDN_LEN
);
}
if
(
pDnodeEp
->
ep
.
port
!=
*
port
)
{
dInfo
(
"dnode:%d, update port from %u to %u"
,
*
dnodeId
,
*
port
,
pDnodeEp
->
ep
.
port
);
*
port
=
pDnodeEp
->
ep
.
port
;
}
*
clusterId
=
pData
->
clusterId
;
ret
=
0
;
}
else
{
dInfo
(
"dnode:%d, failed to update dnode info"
,
*
dnodeId
);
}
}
taosThreadRwlockUnlock
(
&
pData
->
lock
);
return
ret
;
}
\ No newline at end of file
source/dnode/mgmt/node_util/src/dmFile.c
浏览文件 @
ac7d250a
...
...
@@ -105,7 +105,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
return
-
1
;
}
dInfo
(
"succe
ss
ed to write %s, deployed:%d"
,
realfile
,
deployed
);
dInfo
(
"succeed to write %s, deployed:%d"
,
realfile
,
deployed
);
code
=
0
;
_OVER:
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
ac7d250a
...
...
@@ -112,7 +112,6 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
cfg
.
hashMethod
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
numOfRetensions
,
_OVER
)
for
(
int32_t
i
=
0
;
i
<
pDb
->
cfg
.
numOfRetensions
;
++
i
)
{
ASSERT
(
taosArrayGetSize
(
pDb
->
cfg
.
pRetensions
)
==
pDb
->
cfg
.
numOfRetensions
);
SRetention
*
pRetension
=
taosArrayGet
(
pDb
->
cfg
.
pRetensions
,
i
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pRetension
->
freq
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pRetension
->
keep
,
_OVER
)
...
...
@@ -364,6 +363,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
if
(
pCfg
->
hashPrefix
<
TSDB_MIN_HASH_PREFIX
||
pCfg
->
hashPrefix
>
TSDB_MAX_HASH_PREFIX
)
return
-
1
;
if
(
pCfg
->
hashSuffix
<
TSDB_MIN_HASH_SUFFIX
||
pCfg
->
hashSuffix
>
TSDB_MAX_HASH_SUFFIX
)
return
-
1
;
if
(
pCfg
->
tsdbPageSize
<
TSDB_MIN_TSDB_PAGESIZE
||
pCfg
->
tsdbPageSize
>
TSDB_MAX_TSDB_PAGESIZE
)
return
-
1
;
if
(
taosArrayGetSize
(
pCfg
->
pRetensions
)
!=
pCfg
->
numOfRetensions
)
return
-
1
;
terrno
=
0
;
return
terrno
;
...
...
source/dnode/mnode/impl/src/mndDef.c
浏览文件 @
ac7d250a
...
...
@@ -489,7 +489,7 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
tlen
+=
tEncodeSMqConsumerEp
(
buf
,
pConsumerEp
);
cnt
++
;
}
ASSERT
(
cnt
==
sz
)
;
if
(
cnt
!=
sz
)
return
-
1
;
tlen
+=
taosEncodeArray
(
buf
,
pSub
->
unassignedVgs
,
(
FEncode
)
tEncodeSMqVgEp
);
tlen
+=
taosEncodeString
(
buf
,
pSub
->
dbName
);
return
tlen
;
...
...
source/dnode/mnode/impl/src/mndMnode.c
浏览文件 @
ac7d250a
...
...
@@ -21,6 +21,7 @@
#include "mndSync.h"
#include "mndTrans.h"
#include "tmisce.h"
#include "mndCluster.h"
#define MNODE_VER_NUMBER 1
#define MNODE_RESERVE_SIZE 64
...
...
@@ -743,8 +744,12 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
if
(
objStatus
==
SDB_STATUS_READY
||
objStatus
==
SDB_STATUS_CREATING
)
{
SNodeInfo
*
pNode
=
&
cfg
.
nodeInfo
[
cfg
.
replicaNum
];
tstrncpy
(
pNode
->
nodeFqdn
,
pObj
->
pDnode
->
fqdn
,
sizeof
(
pNode
->
nodeFqdn
));
pNode
->
nodeId
=
pObj
->
pDnode
->
id
;
pNode
->
clusterId
=
mndGetClusterId
(
pMnode
);
pNode
->
nodePort
=
pObj
->
pDnode
->
port
;
tstrncpy
(
pNode
->
nodeFqdn
,
pObj
->
pDnode
->
fqdn
,
TSDB_FQDN_LEN
);
(
void
)
tmsgUpdateDnodeInfo
(
&
pNode
->
nodeId
,
&
pNode
->
clusterId
,
pNode
->
nodeFqdn
,
&
pNode
->
nodePort
);
mInfo
(
"vgId:1, ep:%s:%u dnode:%d"
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
,
pNode
->
nodeId
);
if
(
pObj
->
pDnode
->
id
==
pMnode
->
selfDnodeId
)
{
cfg
.
myIndex
=
cfg
.
replicaNum
;
}
...
...
@@ -758,7 +763,6 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
mInfo
(
"vgId:1, mnode sync not reconfig since readyMnodes:%d updatingMnodes:%d"
,
readyMnodes
,
updatingMnodes
);
return
;
}
// ASSERT(0);
if
(
cfg
.
myIndex
==
-
1
)
{
#if 1
...
...
@@ -775,7 +779,8 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
mInfo
(
"vgId:1, mnode sync reconfig, replica:%d myIndex:%d"
,
cfg
.
replicaNum
,
cfg
.
myIndex
);
for
(
int32_t
i
=
0
;
i
<
cfg
.
replicaNum
;
++
i
)
{
SNodeInfo
*
pNode
=
&
cfg
.
nodeInfo
[
i
];
mInfo
(
"vgId:1, index:%d, fqdn:%s port:%d"
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
);
mInfo
(
"vgId:1, index:%d, ep:%s:%u dnode:%d cluster:%"
PRId64
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
,
pNode
->
nodeId
,
pNode
->
clusterId
);
}
int32_t
code
=
syncReconfig
(
pMnode
->
syncMgmt
.
sync
,
&
cfg
);
...
...
source/dnode/mnode/impl/src/mndShow.c
浏览文件 @
ac7d250a
...
...
@@ -111,7 +111,7 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_USER_PRIVILEGES
,
len
)
==
0
)
{
type
=
TSDB_MGMT_TABLE_PRIVILEGES
;
}
else
{
// ASSERT(0
);
mError
(
"invalid show name:%s len:%d"
,
name
,
len
);
}
return
type
;
...
...
source/dnode/mnode/impl/src/mndSma.c
浏览文件 @
ac7d250a
...
...
@@ -488,7 +488,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
memcpy
(
smaObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
smaObj
.
createdTime
=
taosGetTimestampMs
();
smaObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
ASSERT
(
smaObj
.
uid
!=
0
);
char
resultTbName
[
TSDB_TABLE_FNAME_LEN
+
16
]
=
{
0
};
snprintf
(
resultTbName
,
TSDB_TABLE_FNAME_LEN
+
16
,
"%s_td_tsma_rst_tb"
,
pCreate
->
name
);
memcpy
(
smaObj
.
dstTbName
,
resultTbName
,
TSDB_TABLE_FNAME_LEN
);
...
...
@@ -558,13 +558,15 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
streamObj
.
ast
,
&
pAst
)
<
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_INVALID_SMA_OPTION
;
mError
(
"sma:%s, failed to create since parse ast error"
,
smaObj
.
name
);
return
-
1
;
}
// extract output schema from ast
if
(
qExtractResultSchema
(
pAst
,
(
int32_t
*
)
&
streamObj
.
outputSchema
.
nCols
,
&
streamObj
.
outputSchema
.
pSchema
)
!=
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_INVALID_SMA_OPTION
;
mError
(
"sma:%s, failed to create since extract result schema error"
,
smaObj
.
name
);
return
-
1
;
}
...
...
@@ -579,15 +581,18 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
};
if
(
qCreateQueryPlan
(
&
cxt
,
&
pPlan
,
NULL
)
<
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_INVALID_SMA_OPTION
;
mError
(
"sma:%s, failed to create since create query plan error"
,
smaObj
.
name
);
return
-
1
;
}
// save physcial plan
if
(
nodesNodeToString
((
SNode
*
)
pPlan
,
false
,
&
streamObj
.
physicalPlan
,
NULL
)
!=
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_INVALID_SMA_OPTION
;
mError
(
"sma:%s, failed to create since save physcial plan error"
,
smaObj
.
name
);
return
-
1
;
}
if
(
pAst
!=
NULL
)
nodesDestroyNode
(
pAst
);
nodesDestroyNode
((
SNode
*
)
pPlan
);
...
...
@@ -826,14 +831,13 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p
if
(
mndDropStreamTasks
(
pMnode
,
pTrans
,
pStream
)
<
0
)
{
mError
(
"stream:%s, failed to drop task since %s"
,
pStream
->
name
,
terrstr
());
sdbRelease
(
pMnode
->
pSdb
,
pStream
);
ASSERT
(
0
);
goto
_OVER
;
}
// drop stream
if
(
mndPersistDropStreamLog
(
pMnode
,
pTrans
,
pStream
)
<
0
)
{
mError
(
"stream:%s, failed to drop log since %s"
,
pStream
->
name
,
terrstr
());
sdbRelease
(
pMnode
->
pSdb
,
pStream
);
ASSERT
(
0
);
goto
_OVER
;
}
}
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
ac7d250a
...
...
@@ -1177,7 +1177,9 @@ static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName,
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pTopic
->
ast
,
&
pAst
)
!=
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC
;
mError
(
"topic:%s, create ast error"
,
pTopic
->
name
);
sdbRelease
(
pSdb
,
pTopic
);
return
-
1
;
}
...
...
@@ -1222,7 +1224,9 @@ static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pStream
->
ast
,
&
pAst
)
!=
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_INVALID_STREAM_OPTION
;
mError
(
"stream:%s, create ast error"
,
pStream
->
name
);
sdbRelease
(
pSdb
,
pStream
);
return
-
1
;
}
...
...
@@ -2094,7 +2098,9 @@ static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName,
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pTopic
->
ast
,
&
pAst
)
!=
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_INVALID_TOPIC_OPTION
;
mError
(
"topic:%s, create ast error"
,
pTopic
->
name
);
sdbRelease
(
pSdb
,
pTopic
);
return
-
1
;
}
...
...
@@ -2141,7 +2147,9 @@ static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName,
SNode
*
pAst
=
NULL
;
if
(
nodesStringToNode
(
pStream
->
ast
,
&
pAst
)
!=
0
)
{
ASSERT
(
0
);
terrno
=
TSDB_CODE_MND_INVALID_STREAM_OPTION
;
mError
(
"stream:%s, create ast error"
,
pStream
->
name
);
sdbRelease
(
pSdb
,
pStream
);
return
-
1
;
}
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
ac7d250a
...
...
@@ -96,18 +96,12 @@ static SMqSubscribeObj *mndCreateSub(SMnode *pMnode, const SMqTopicObj *pTopic,
pSub
->
subType
=
pTopic
->
subType
;
pSub
->
withMeta
=
pTopic
->
withMeta
;
ASSERT
(
pSub
->
unassignedVgs
->
size
==
0
);
ASSERT
(
taosHashGetSize
(
pSub
->
consumerHash
)
==
0
);
if
(
mndSchedInitSubEp
(
pMnode
,
pTopic
,
pSub
)
<
0
)
{
tDeleteSubscribeObj
(
pSub
);
taosMemoryFree
(
pSub
);
return
NULL
;
}
ASSERT
(
pSub
->
unassignedVgs
->
size
>
0
);
ASSERT
(
taosHashGetSize
(
pSub
->
consumerHash
)
==
0
);
return
pSub
;
}
...
...
@@ -144,7 +138,10 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri
static
int32_t
mndPersistSubChangeVgReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqSubscribeObj
*
pSub
,
const
SMqRebOutputVg
*
pRebVg
)
{
ASSERT
(
pRebVg
->
oldConsumerId
!=
pRebVg
->
newConsumerId
);
if
(
pRebVg
->
oldConsumerId
==
pRebVg
->
newConsumerId
)
{
terrno
=
TSDB_CODE_MND_INVALID_SUB_OPTION
;
return
-
1
;
}
void
*
buf
;
int32_t
tlen
;
...
...
@@ -155,8 +152,8 @@ static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SM
int32_t
vgId
=
pRebVg
->
pVgEp
->
vgId
;
SVgObj
*
pVgObj
=
mndAcquireVgroup
(
pMnode
,
vgId
);
if
(
pVgObj
==
NULL
)
{
ASSERT
(
0
);
taosMemoryFree
(
buf
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
@@ -206,9 +203,9 @@ static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
}
static
int32_t
mndDoRebalance
(
SMnode
*
pMnode
,
const
SMqRebInputObj
*
pInput
,
SMqRebOutputObj
*
pOutput
)
{
int32_t
totalVgNum
=
pOutput
->
pSub
->
vgNum
;
mInfo
(
"
mq rebalance: subscription: %s, vgNum: %d"
,
pOutput
->
pSub
->
key
,
pOutput
->
pSub
->
vgNum
);
int32_t
totalVgNum
=
pOutput
->
pSub
->
vgNum
;
const
char
*
sub
=
pOutput
->
pSub
->
key
;
mInfo
(
"
sub:%s, mq rebalance vgNum:%d"
,
sub
,
pOutput
->
pSub
->
vgNum
);
// 1. build temporary hash(vgId -> SMqRebOutputVg) to store modified vg
SHashObj
*
pHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
...
...
@@ -218,11 +215,10 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
int32_t
actualRemoved
=
0
;
for
(
int32_t
i
=
0
;
i
<
removedNum
;
i
++
)
{
int64_t
consumerId
=
*
(
int64_t
*
)
taosArrayGet
(
pInput
->
pRebInfo
->
removedConsumers
,
i
);
ASSERT
(
consumerId
>
0
);
SMqConsumerEp
*
pConsumerEp
=
taosHashGet
(
pOutput
->
pSub
->
consumerHash
,
&
consumerId
,
sizeof
(
int64_t
));
ASSERT
(
pConsumerEp
);
if
(
pConsumerEp
)
{
ASSERT
(
consumerId
==
pConsumerEp
->
consumerId
);
actualRemoved
++
;
int32_t
consumerVgNum
=
taosArrayGetSize
(
pConsumerEp
->
vgs
);
for
(
int32_t
j
=
0
;
j
<
consumerVgNum
;
j
++
)
{
...
...
@@ -233,7 +229,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
.
pVgEp
=
pVgEp
,
};
taosHashPut
(
pHash
,
&
pVgEp
->
vgId
,
sizeof
(
int32_t
),
&
outputVg
,
sizeof
(
SMqRebOutputVg
));
mInfo
(
"
mq rebalance: remove vgId:%d from consumer:%"
PRId64
,
pVgEp
->
vgId
,
consumerId
);
mInfo
(
"
sub:%s, mq rebalance remove vgId:%d from consumer:%"
PRId64
,
sub
,
pVgEp
->
vgId
,
consumerId
);
}
taosArrayDestroy
(
pConsumerEp
->
vgs
);
taosHashRemove
(
pOutput
->
pSub
->
consumerHash
,
&
consumerId
,
sizeof
(
int64_t
));
...
...
@@ -241,7 +237,10 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
taosArrayPush
(
pOutput
->
removedConsumers
,
&
consumerId
);
}
}
ASSERT
(
removedNum
==
actualRemoved
);
if
(
removedNum
!=
actualRemoved
)
{
mError
(
"sub:%s, mq rebalance removedNum:%d not matched with actual:%d"
,
sub
,
removedNum
,
actualRemoved
);
}
// if previously no consumer, there are vgs not assigned
{
...
...
@@ -254,7 +253,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
.
pVgEp
=
pVgEp
,
};
taosHashPut
(
pHash
,
&
pVgEp
->
vgId
,
sizeof
(
int32_t
),
&
rebOutput
,
sizeof
(
SMqRebOutputVg
));
mInfo
(
"
mq rebalance: remove vgId:%d from unassigned"
,
pVgEp
->
vgId
);
mInfo
(
"
sub:%s, mq rebalance remove vgId:%d from unassigned"
,
sub
,
pVgEp
->
vgId
);
}
}
...
...
@@ -268,8 +267,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
minVgCnt
=
totalVgNum
/
afterRebConsumerNum
;
imbConsumerNum
=
totalVgNum
%
afterRebConsumerNum
;
}
mInfo
(
"
mq rebalance: %d consumer after rebalance, at least %d vg each, %d consumer has more vg"
,
afterRebConsumerNum
,
minVgCnt
,
imbConsumerNum
);
mInfo
(
"
sub:%s, mq rebalance %d consumer after rebalance, at least %d vg each, %d consumer has more vg"
,
sub
,
afterRebConsumerNum
,
minVgCnt
,
imbConsumerNum
);
// 4. first scan: remove consumer more than wanted, put to remove hash
int32_t
imbCnt
=
0
;
...
...
@@ -278,7 +277,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
if
(
pIter
==
NULL
)
break
;
SMqConsumerEp
*
pConsumerEp
=
(
SMqConsumerEp
*
)
pIter
;
ASSERT
(
pConsumerEp
->
consumerId
>
0
);
int32_t
consumerVgNum
=
taosArrayGetSize
(
pConsumerEp
->
vgs
);
// all old consumers still existing are touched
// TODO optimize: touch only consumer whose vgs changed
...
...
@@ -298,7 +297,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
.
pVgEp
=
pVgEp
,
};
taosHashPut
(
pHash
,
&
pVgEp
->
vgId
,
sizeof
(
int32_t
),
&
outputVg
,
sizeof
(
SMqRebOutputVg
));
mInfo
(
"
mq rebalance: remove vgId:%d from consumer:%"
PRId64
",(first scan)"
,
pVgEp
->
vgId
,
mInfo
(
"
sub:%s, mq rebalance remove vgId:%d from consumer:%"
PRId64
",(first scan)"
,
sub
,
pVgEp
->
vgId
,
pConsumerEp
->
consumerId
);
}
imbCnt
++
;
...
...
@@ -313,7 +312,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
.
pVgEp
=
pVgEp
,
};
taosHashPut
(
pHash
,
&
pVgEp
->
vgId
,
sizeof
(
int32_t
),
&
outputVg
,
sizeof
(
SMqRebOutputVg
));
mInfo
(
"
mq rebalance: remove vgId:%d from consumer:%"
PRId64
",(first scan)"
,
pVgEp
->
vgId
,
mInfo
(
"
sub:%s, mq rebalance remove vgId:%d from consumer:%"
PRId64
",(first scan)"
,
sub
,
pVgEp
->
vgId
,
pConsumerEp
->
consumerId
);
}
}
...
...
@@ -325,13 +324,13 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
int32_t
consumerNum
=
taosArrayGetSize
(
pInput
->
pRebInfo
->
newConsumers
);
for
(
int32_t
i
=
0
;
i
<
consumerNum
;
i
++
)
{
int64_t
consumerId
=
*
(
int64_t
*
)
taosArrayGet
(
pInput
->
pRebInfo
->
newConsumers
,
i
);
ASSERT
(
consumerId
>
0
);
SMqConsumerEp
newConsumerEp
;
newConsumerEp
.
consumerId
=
consumerId
;
newConsumerEp
.
vgs
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
taosHashPut
(
pOutput
->
pSub
->
consumerHash
,
&
consumerId
,
sizeof
(
int64_t
),
&
newConsumerEp
,
sizeof
(
SMqConsumerEp
));
taosArrayPush
(
pOutput
->
newConsumers
,
&
consumerId
);
mInfo
(
"
mq rebalance: add new consumer:%"
PRId64
,
consumerId
);
mInfo
(
"
sub:%s, mq rebalance add new consumer:%"
PRId64
,
sub
,
consumerId
);
}
}
...
...
@@ -344,13 +343,16 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
if
(
pIter
==
NULL
)
break
;
SMqConsumerEp
*
pConsumerEp
=
(
SMqConsumerEp
*
)
pIter
;
ASSERT
(
pConsumerEp
->
consumerId
>
0
);
// push until equal minVg
while
(
taosArrayGetSize
(
pConsumerEp
->
vgs
)
<
minVgCnt
)
{
// iter hash and find one vg
pRemovedIter
=
taosHashIterate
(
pHash
,
pRemovedIter
);
ASSERT
(
pRemovedIter
);
if
(
pRemovedIter
==
NULL
)
{
mError
(
"sub:%s, removed iter is null"
,
sub
);
continue
;
}
pRebVg
=
(
SMqRebOutputVg
*
)
pRemovedIter
;
// push
taosArrayPush
(
pConsumerEp
->
vgs
,
&
pRebVg
->
pVgEp
);
...
...
@@ -361,7 +363,6 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
}
}
ASSERT
(
pIter
==
NULL
);
// 7. handle unassigned vg
if
(
taosHashGetSize
(
pOutput
->
pSub
->
consumerHash
)
!=
0
)
{
// if has consumer, assign all left vg
...
...
@@ -377,9 +378,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
}
while
(
1
)
{
pIter
=
taosHashIterate
(
pOutput
->
pSub
->
consumerHash
,
pIter
);
ASSERT
(
pIter
);
pConsumerEp
=
(
SMqConsumerEp
*
)
pIter
;
ASSERT
(
pConsumerEp
->
consumerId
>
0
);
if
(
taosArrayGetSize
(
pConsumerEp
->
vgs
)
==
minVgCnt
)
{
break
;
}
...
...
@@ -404,19 +404,19 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
pIter
=
taosHashIterate
(
pHash
,
pIter
);
if
(
pIter
==
NULL
)
break
;
pRebOutput
=
(
SMqRebOutputVg
*
)
pIter
;
ASSERT
(
pRebOutput
->
newConsumerId
==
-
1
);
taosArrayPush
(
pOutput
->
pSub
->
unassignedVgs
,
&
pRebOutput
->
pVgEp
);
taosArrayPush
(
pOutput
->
rebVgs
,
pRebOutput
);
mInfo
(
"
mq rebalance: unassign vgId:%d (second scan)"
,
pRebOutput
->
pVgEp
->
vgId
);
mInfo
(
"
sub:%s, mq rebalance unassign vgId:%d (second scan)"
,
sub
,
pRebOutput
->
pVgEp
->
vgId
);
}
}
// 8. generate logs
mInfo
(
"
mq rebalance: calculation completed, rebalanced vg:"
);
mInfo
(
"
sub:%s, mq rebalance calculation completed, rebalanced vg"
,
sub
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pOutput
->
rebVgs
);
i
++
)
{
SMqRebOutputVg
*
pOutputRebVg
=
taosArrayGet
(
pOutput
->
rebVgs
,
i
);
mInfo
(
"
mq rebalance: vgId:%d, moved from consumer:%"
PRId64
", to consumer:%"
PRId64
,
pOutputRebVg
->
pVgEp
->
vgId
,
pOutputRebVg
->
oldConsumerId
,
pOutputRebVg
->
newConsumerId
);
mInfo
(
"
sub:%s, mq rebalance vgId:%d, moved from consumer:%"
PRId64
", to consumer:%"
PRId64
,
sub
,
pOutputRebVg
->
pVgEp
->
vgId
,
pOutputRebVg
->
oldConsumerId
,
pOutputRebVg
->
newConsumerId
);
}
{
void
*
pIter
=
NULL
;
...
...
@@ -425,10 +425,11 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
if
(
pIter
==
NULL
)
break
;
SMqConsumerEp
*
pConsumerEp
=
(
SMqConsumerEp
*
)
pIter
;
int32_t
sz
=
taosArrayGetSize
(
pConsumerEp
->
vgs
);
mInfo
(
"
mq rebalance: final cfg: consumer %"
PRId64
" has %d vg"
,
pConsumerEp
->
consumerId
,
sz
);
mInfo
(
"
sub:%s, mq rebalance final cfg: consumer %"
PRId64
" has %d vg"
,
sub
,
pConsumerEp
->
consumerId
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqVgEp
*
pVgEp
=
taosArrayGetP
(
pConsumerEp
->
vgs
,
i
);
mInfo
(
"mq rebalance: final cfg: vg %d to consumer %"
PRId64
""
,
pVgEp
->
vgId
,
pConsumerEp
->
consumerId
);
mInfo
(
"sub:%s, mq rebalance final cfg: vg %d to consumer %"
PRId64
""
,
sub
,
pVgEp
->
vgId
,
pConsumerEp
->
consumerId
);
}
}
}
...
...
@@ -487,7 +488,7 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
consumerNum
=
taosArrayGetSize
(
pOutput
->
newConsumers
);
for
(
int32_t
i
=
0
;
i
<
consumerNum
;
i
++
)
{
int64_t
consumerId
=
*
(
int64_t
*
)
taosArrayGet
(
pOutput
->
newConsumers
,
i
);
ASSERT
(
consumerId
>
0
);
SMqConsumerObj
*
pConsumerOld
=
mndAcquireConsumer
(
pMnode
,
consumerId
);
SMqConsumerObj
*
pConsumerNew
=
tNewSMqConsumerObj
(
pConsumerOld
->
consumerId
,
pConsumerOld
->
cgroup
);
pConsumerNew
->
updateType
=
CONSUMER_UPDATE__ADD
;
...
...
@@ -497,7 +498,6 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
taosArrayPush
(
pConsumerNew
->
rebNewTopics
,
&
topic
);
mndReleaseConsumer
(
pMnode
,
pConsumerOld
);
if
(
mndSetConsumerCommitLogs
(
pMnode
,
pTrans
,
pConsumerNew
)
!=
0
)
{
ASSERT
(
0
);
tDeleteSMqConsumerObj
(
pConsumerNew
);
taosMemoryFree
(
pConsumerNew
);
goto
REB_FAIL
;
...
...
@@ -510,7 +510,7 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
consumerNum
=
taosArrayGetSize
(
pOutput
->
removedConsumers
);
for
(
int32_t
i
=
0
;
i
<
consumerNum
;
i
++
)
{
int64_t
consumerId
=
*
(
int64_t
*
)
taosArrayGet
(
pOutput
->
removedConsumers
,
i
);
ASSERT
(
consumerId
>
0
);
SMqConsumerObj
*
pConsumerOld
=
mndAcquireConsumer
(
pMnode
,
consumerId
);
SMqConsumerObj
*
pConsumerNew
=
tNewSMqConsumerObj
(
pConsumerOld
->
consumerId
,
pConsumerOld
->
cgroup
);
pConsumerNew
->
updateType
=
CONSUMER_UPDATE__REMOVE
;
...
...
@@ -520,7 +520,6 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
taosArrayPush
(
pConsumerNew
->
rebRemovedTopics
,
&
topic
);
mndReleaseConsumer
(
pMnode
,
pConsumerOld
);
if
(
mndSetConsumerCommitLogs
(
pMnode
,
pTrans
,
pConsumerNew
)
!=
0
)
{
ASSERT
(
0
);
tDeleteSMqConsumerObj
(
pConsumerNew
);
taosMemoryFree
(
pConsumerNew
);
goto
REB_FAIL
;
...
...
@@ -577,7 +576,6 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
char
cgroup
[
TSDB_CGROUP_LEN
];
mndSplitSubscribeKey
(
pRebInfo
->
key
,
topic
,
cgroup
,
true
);
SMqTopicObj
*
pTopic
=
mndAcquireTopic
(
pMnode
,
topic
);
/*ASSERT(pTopic);*/
if
(
pTopic
==
NULL
)
{
mError
(
"mq rebalance %s failed since topic %s not exist, abort"
,
pRebInfo
->
key
,
topic
);
continue
;
...
...
@@ -585,8 +583,14 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
taosRLockLatch
(
&
pTopic
->
lock
);
rebOutput
.
pSub
=
mndCreateSub
(
pMnode
,
pTopic
,
pRebInfo
->
key
);
if
(
rebOutput
.
pSub
==
NULL
)
{
mError
(
"mq rebalance %s failed create sub since %s, abort"
,
pRebInfo
->
key
,
terrstr
());
taosRUnLockLatch
(
&
pTopic
->
lock
);
mndReleaseTopic
(
pMnode
,
pTopic
);
continue
;
}
memcpy
(
rebOutput
.
pSub
->
dbName
,
pTopic
->
db
,
TSDB_DB_FNAME_LEN
);
ASSERT
(
taosHashGetSize
(
rebOutput
.
pSub
->
consumerHash
)
==
0
);
taosRUnLockLatch
(
&
pTopic
->
lock
);
mndReleaseTopic
(
pMnode
,
pTopic
);
...
...
@@ -606,7 +610,6 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
// if add more consumer to balanced subscribe,
// possibly no vg is changed
/*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/
if
(
mndPersistRebResult
(
pMnode
,
pMsg
,
&
rebOutput
)
<
0
)
{
mError
(
"mq rebalance persist rebalance output error, possibly vnode splitted or dropped"
);
...
...
@@ -693,6 +696,7 @@ static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) {
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
void
*
buf
=
NULL
;
int32_t
tlen
=
tEncodeSubscribeObj
(
NULL
,
pSub
);
if
(
tlen
<=
0
)
goto
SUB_ENCODE_OVER
;
int32_t
size
=
sizeof
(
int32_t
)
+
tlen
+
MND_SUBSCRIBE_RESERVE_SIZE
;
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_SUBSCRIBE
,
MND_SUBSCRIBE_VER_NUMBER
,
size
);
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
ac7d250a
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "mndSync.h"
#include "mndCluster.h"
#include "mndTrans.h"
static
int32_t
mndSyncEqCtrlMsg
(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
)
{
...
...
@@ -297,9 +298,12 @@ int32_t mndInitSync(SMnode *pMnode) {
pCfg
->
myIndex
=
pMgmt
->
selfIndex
;
for
(
int32_t
i
=
0
;
i
<
pMgmt
->
numOfReplicas
;
++
i
)
{
SNodeInfo
*
pNode
=
&
pCfg
->
nodeInfo
[
i
];
tstrncpy
(
pNode
->
nodeFqdn
,
pMgmt
->
replicas
[
i
].
fqdn
,
sizeof
(
pNode
->
nodeFqdn
))
;
pNode
->
nodeId
=
pMgmt
->
replicas
[
i
].
id
;
pNode
->
nodePort
=
pMgmt
->
replicas
[
i
].
port
;
mInfo
(
"vgId:1, index:%d ep:%s:%u"
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
);
tstrncpy
(
pNode
->
nodeFqdn
,
pMgmt
->
replicas
[
i
].
fqdn
,
sizeof
(
pNode
->
nodeFqdn
));
(
void
)
tmsgUpdateDnodeInfo
(
&
pNode
->
nodeId
,
&
pNode
->
clusterId
,
pNode
->
nodeFqdn
,
&
pNode
->
nodePort
);
mInfo
(
"vgId:1, index:%d ep:%s:%u dnode:%d cluster:%"
PRId64
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
,
pNode
->
nodeId
,
pNode
->
clusterId
);
}
tsem_init
(
&
pMgmt
->
syncSem
,
0
,
0
);
...
...
source/dnode/mnode/impl/src/mndTelem.c
浏览文件 @
ac7d250a
...
...
@@ -17,7 +17,6 @@
#include "mndTelem.h"
#include "mndCluster.h"
#include "mndSync.h"
#include "tbuffer.h"
#include "thttp.h"
#include "tjson.h"
...
...
source/dnode/mnode/impl/src/mndTopic.c
浏览文件 @
ac7d250a
...
...
@@ -384,7 +384,11 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
topicObj
.
subType
=
pCreate
->
subType
;
topicObj
.
withMeta
=
pCreate
->
withMeta
;
if
(
topicObj
.
withMeta
)
{
ASSERT
(
topicObj
.
subType
!=
TOPIC_SUB_TYPE__COLUMN
);
if
(
topicObj
.
subType
==
TOPIC_SUB_TYPE__COLUMN
)
{
terrno
=
TSDB_CODE_MND_INVALID_TOPIC_OPTION
;
mError
(
"topic:%s, failed to create since %s"
,
pCreate
->
name
,
terrstr
());
return
-
1
;
}
}
if
(
pCreate
->
subType
==
TOPIC_SUB_TYPE__COLUMN
)
{
...
...
@@ -499,7 +503,6 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
if
(
code
<
0
)
{
sdbRelease
(
pSdb
,
pVgroup
);
mndTransDrop
(
pTrans
);
ASSERT
(
0
);
return
-
1
;
}
void
*
buf
=
taosMemoryCalloc
(
1
,
sizeof
(
SMsgHead
)
+
len
);
...
...
@@ -723,7 +726,6 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
// TODO check if rebalancing
if
(
mndDropSubByTopic
(
pMnode
,
pTrans
,
dropReq
.
name
)
<
0
)
{
/*ASSERT(0);*/
mError
(
"topic:%s, failed to drop since %s"
,
pTopic
->
name
,
terrstr
());
mndTransDrop
(
pTrans
);
mndReleaseTopic
(
pMnode
,
pTopic
);
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
ac7d250a
...
...
@@ -772,8 +772,8 @@ static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
return
0
;
}
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
//
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
//
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
static
FORCE_INLINE
TSDBROW
*
tsdbTbDataIterGet
(
STbDataIter
*
pIter
)
{
if
(
pIter
==
NULL
)
return
NULL
;
...
...
source/dnode/vnode/src/tq/tqMeta.c
浏览文件 @
ac7d250a
...
...
@@ -284,8 +284,7 @@ int32_t tqMetaRestoreHandle(STQ* pTq) {
handle
.
pRef
=
walOpenRef
(
pTq
->
pVnode
->
pWal
);
if
(
handle
.
pRef
==
NULL
)
{
ASSERT
(
0
);
return
-
1
;
continue
;
}
walRefVer
(
handle
.
pRef
,
handle
.
snapshotVer
);
...
...
source/dnode/vnode/src/tq/tqOffset.c
浏览文件 @
ac7d250a
...
...
@@ -46,21 +46,37 @@ int32_t tqOffsetRestoreFromFile(STqOffsetStore* pStore, const char* fname) {
}
int32_t
size
=
htonl
(
head
.
size
);
void
*
memBuf
=
taosMemoryCalloc
(
1
,
size
);
if
(
memBuf
==
NULL
)
{
return
-
1
;
}
if
((
code
=
taosReadFile
(
pFile
,
memBuf
,
size
))
!=
size
)
{
ASSERT
(
0
);
// TODO handle error
taosMemoryFree
(
memBuf
);
return
-
1
;
}
STqOffset
offset
;
SDecoder
decoder
;
tDecoderInit
(
&
decoder
,
memBuf
,
size
);
if
(
tDecodeSTqOffset
(
&
decoder
,
&
offset
)
<
0
)
{
ASSERT
(
0
);
taosMemoryFree
(
memBuf
);
tDecoderClear
(
&
decoder
);
return
-
1
;
}
tDecoderClear
(
&
decoder
);
if
(
taosHashPut
(
pStore
->
pHash
,
offset
.
subKey
,
strlen
(
offset
.
subKey
),
&
offset
,
sizeof
(
STqOffset
))
<
0
)
{
ASSERT
(
0
);
// TODO
return
-
1
;
}
if
(
offset
.
val
.
type
==
TMQ_OFFSET__LOG
)
{
STqHandle
*
pHandle
=
taosHashGet
(
pStore
->
pTq
->
pHandle
,
offset
.
subKey
,
strlen
(
offset
.
subKey
));
if
(
pHandle
)
{
if
(
walRefVer
(
pHandle
->
pRef
,
offset
.
val
.
version
)
<
0
)
{
tqError
(
"vgId: %d, tq handle %s ref ver %"
PRId64
"error"
,
pStore
->
pTq
->
pVnode
->
config
.
vgId
,
pHandle
->
subKey
,
offset
.
val
.
version
);
}
}
}
taosMemoryFree
(
memBuf
);
}
...
...
@@ -124,7 +140,7 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
const
char
*
sysErrStr
=
strerror
(
errno
);
tqError
(
"vgId:%d, cannot open file %s when commit offset since %s"
,
pStore
->
pTq
->
pVnode
->
config
.
vgId
,
fname
,
sysErrStr
);
ASSERT
(
0
);
taosMemoryFree
(
fname
);
return
-
1
;
}
taosMemoryFree
(
fname
);
...
...
source/dnode/vnode/src/tq/tqSink.c
浏览文件 @
ac7d250a
...
...
@@ -64,7 +64,7 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl
.
startTs
=
startTs
,
.
endTs
=
endTs
,
};
strncpy
(
req
.
tbname
,
name
,
TSDB_TABLE_NAME_LEN
);
strncpy
(
req
.
tbname
,
name
,
TSDB_TABLE_NAME_LEN
-
1
);
taosMemoryFree
(
name
);
/*tqDebug("stream delete msg, active: vgId:%d, ts:%" PRId64 " name:%s", pVnode->config.vgId, ts, name);*/
taosArrayPush
(
deleteReq
->
deleteReqs
,
&
req
);
...
...
source/dnode/vnode/src/tq/tqSnapshot.c
浏览文件 @
ac7d250a
...
...
@@ -175,6 +175,8 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) {
if
(
code
)
goto
_err
;
}
int
vgId
=
TD_VID
(
pWriter
->
pTq
->
pVnode
);
taosMemoryFree
(
pWriter
);
*
ppWriter
=
NULL
;
...
...
@@ -186,7 +188,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) {
return
code
;
_err:
tqError
(
"vgId:%d, tq snapshot writer close failed since %s"
,
TD_VID
(
pWriter
->
pTq
->
pVnode
)
,
tstrerror
(
code
));
tqError
(
"vgId:%d, tq snapshot writer close failed since %s"
,
vgId
,
tstrerror
(
code
));
return
code
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
ac7d250a
...
...
@@ -19,9 +19,13 @@
#define SL_MAX_LEVEL 5
// sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l) * 2
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + ((l) << 4))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + ((l) << 4))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
#define SL_GET_NODE_FORWARD(n, l) ((SMemSkipListNode *)atomic_load_64((int64_t *)&SL_NODE_FORWARD(n, l)))
#define SL_GET_NODE_BACKWARD(n, l) ((SMemSkipListNode *)atomic_load_64((int64_t *)&SL_NODE_BACKWARD(n, l)))
#define SL_SET_NODE_FORWARD(n, l, p) atomic_store_64((int64_t *)&SL_NODE_FORWARD(n, l), (int64_t)(p))
#define SL_SET_NODE_BACKWARD(n, l, p) atomic_store_64((int64_t *)&SL_NODE_BACKWARD(n, l), (int64_t)(p))
#define SL_MOVE_BACKWARD 0x1
#define SL_MOVE_FROM_POS 0x2
...
...
@@ -246,18 +250,18 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDa
if
(
pFrom
==
NULL
)
{
// create from head or tail
if
(
backward
)
{
pIter
->
pNode
=
SL_NODE_BACKWARD
(
pTbData
->
sl
.
pTail
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_BACKWARD
(
pTbData
->
sl
.
pTail
,
0
);
}
else
{
pIter
->
pNode
=
SL_NODE_FORWARD
(
pTbData
->
sl
.
pHead
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_FORWARD
(
pTbData
->
sl
.
pHead
,
0
);
}
}
else
{
// create from a key
if
(
backward
)
{
tbDataMovePosTo
(
pTbData
,
pos
,
pFrom
,
SL_MOVE_BACKWARD
);
pIter
->
pNode
=
SL_NODE_BACKWARD
(
pos
[
0
],
0
);
pIter
->
pNode
=
SL_
GET_
NODE_BACKWARD
(
pos
[
0
],
0
);
}
else
{
tbDataMovePosTo
(
pTbData
,
pos
,
pFrom
,
0
);
pIter
->
pNode
=
SL_NODE_FORWARD
(
pos
[
0
],
0
);
pIter
->
pNode
=
SL_
GET_
NODE_FORWARD
(
pos
[
0
],
0
);
}
}
}
...
...
@@ -271,7 +275,7 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) {
return
false
;
}
pIter
->
pNode
=
SL_NODE_BACKWARD
(
pIter
->
pNode
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_BACKWARD
(
pIter
->
pNode
,
0
);
if
(
pIter
->
pNode
==
pIter
->
pTbData
->
sl
.
pHead
)
{
return
false
;
}
...
...
@@ -282,7 +286,7 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) {
return
false
;
}
pIter
->
pNode
=
SL_NODE_FORWARD
(
pIter
->
pNode
,
0
);
pIter
->
pNode
=
SL_
GET_
NODE_FORWARD
(
pIter
->
pNode
,
0
);
if
(
pIter
->
pNode
==
pIter
->
pTbData
->
sl
.
pTail
)
{
return
false
;
}
...
...
@@ -335,7 +339,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid
int8_t
maxLevel
=
pMemTable
->
pTsdb
->
pVnode
->
config
.
tsdbCfg
.
slLevel
;
ASSERT
(
pPool
!=
NULL
);
pTbData
=
vnodeBufPoolMalloc
(
pPool
,
sizeof
(
*
pTbData
)
+
SL_NODE_SIZE
(
maxLevel
)
*
2
);
pTbData
=
vnodeBufPoolMalloc
Aligned
(
pPool
,
sizeof
(
*
pTbData
)
+
SL_NODE_SIZE
(
maxLevel
)
*
2
);
if
(
pTbData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
...
...
@@ -408,7 +412,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
if
(
fromPos
)
px
=
pos
[
pTbData
->
sl
.
level
-
1
];
for
(
int8_t
iLevel
=
pTbData
->
sl
.
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
pn
=
SL_NODE_BACKWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_BACKWARD
(
px
,
iLevel
);
while
(
pn
!=
pTbData
->
sl
.
pHead
)
{
tKey
.
version
=
pn
->
version
;
tKey
.
ts
=
pn
->
pTSRow
->
ts
;
...
...
@@ -418,7 +422,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
break
;
}
else
{
px
=
pn
;
pn
=
SL_NODE_BACKWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_BACKWARD
(
px
,
iLevel
);
}
}
...
...
@@ -438,7 +442,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
if
(
fromPos
)
px
=
pos
[
pTbData
->
sl
.
level
-
1
];
for
(
int8_t
iLevel
=
pTbData
->
sl
.
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
pn
=
SL_NODE_FORWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_FORWARD
(
px
,
iLevel
);
while
(
pn
!=
pTbData
->
sl
.
pTail
)
{
tKey
.
version
=
pn
->
version
;
tKey
.
ts
=
pn
->
pTSRow
->
ts
;
...
...
@@ -448,7 +452,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
break
;
}
else
{
px
=
pn
;
pn
=
SL_NODE_FORWARD
(
px
,
iLevel
);
pn
=
SL_
GET_
NODE_FORWARD
(
px
,
iLevel
);
}
}
...
...
@@ -474,58 +478,53 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN
int8_t
level
;
SMemSkipListNode
*
pNode
;
SVBufPool
*
pPool
=
pMemTable
->
pTsdb
->
pVnode
->
inUse
;
int64_t
nSize
;
// node
//
create
node
level
=
tsdbMemSkipListRandLevel
(
&
pTbData
->
sl
);
ASSERT
(
pPool
!=
NULL
);
pNode
=
(
SMemSkipListNode
*
)
vnodeBufPoolMalloc
(
pPool
,
SL_NODE_SIZE
(
level
)
);
nSize
=
SL_NODE_SIZE
(
level
);
pNode
=
(
SMemSkipListNode
*
)
vnodeBufPoolMalloc
Aligned
(
pPool
,
nSize
+
pRow
->
len
);
if
(
pNode
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pNode
->
level
=
level
;
pNode
->
version
=
version
;
pNode
->
pTSRow
=
vnodeBufPoolMalloc
(
pPool
,
pRow
->
len
);
if
(
NULL
==
pNode
->
pTSRow
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pNode
->
pTSRow
=
(
STSRow
*
)((
char
*
)
pNode
+
nSize
);
memcpy
(
pNode
->
pTSRow
,
pRow
,
pRow
->
len
);
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pn
=
pos
[
iLevel
];
SMemSkipListNode
*
px
;
if
(
forward
)
{
px
=
SL_NODE_FORWARD
(
pn
,
iLevel
);
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
pn
;
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
px
;
}
else
{
px
=
SL_NODE_BACKWARD
(
pn
,
iLevel
);
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
px
;
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
pn
;
// set node
if
(
forward
)
{
for
(
int8_t
iLevel
=
0
;
iLevel
<
level
;
iLevel
++
)
{
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
SL_NODE_FORWARD
(
pos
[
iLevel
],
iLevel
);
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
pos
[
iLevel
];
}
}
else
{
for
(
int8_t
iLevel
=
0
;
iLevel
<
level
;
iLevel
++
)
{
SL_NODE_FORWARD
(
pNode
,
iLevel
)
=
pos
[
iLevel
];
SL_NODE_BACKWARD
(
pNode
,
iLevel
)
=
SL_NODE_BACKWARD
(
pos
[
iLevel
],
iLevel
);
}
}
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pn
=
pos
[
iLevel
];
SMemSkipListNode
*
px
;
// set forward and backward
if
(
forward
)
{
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pNext
=
pos
[
iLevel
]
->
forwards
[
iLevel
];
if
(
forward
)
{
px
=
SL_NODE_FORWARD
(
pn
,
iLevel
);
SL_NODE_FORWARD
(
pn
,
iLevel
)
=
pNode
;
SL_NODE_BACKWARD
(
px
,
iLevel
)
=
pNode
;
}
else
{
px
=
SL_NODE_BACKWARD
(
pn
,
iLevel
);
SL_SET_NODE_FORWARD
(
pos
[
iLevel
],
iLevel
,
pNode
);
SL_SET_NODE_BACKWARD
(
pNext
,
iLevel
,
pNode
);
SL_NODE_FORWARD
(
px
,
iLevel
)
=
pNode
;
SL_NODE_BACKWARD
(
pn
,
iLevel
)
=
pNode
;
pos
[
iLevel
]
=
pNode
;
}
}
else
{
for
(
int8_t
iLevel
=
level
-
1
;
iLevel
>=
0
;
iLevel
--
)
{
SMemSkipListNode
*
pPrev
=
pos
[
iLevel
]
->
forwards
[
pos
[
iLevel
]
->
level
+
iLevel
];
SL_SET_NODE_FORWARD
(
pPrev
,
iLevel
,
pNode
);
SL_SET_NODE_BACKWARD
(
pos
[
iLevel
],
iLevel
,
pNode
);
pos
[
iLevel
]
=
pNode
;
pos
[
iLevel
]
=
pNode
;
}
}
pTbData
->
sl
.
size
++
;
...
...
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
浏览文件 @
ac7d250a
...
...
@@ -76,6 +76,7 @@ static int32_t tFDataIterCmprFn(const SRBTreeNode* pNode1, const SRBTreeNode* pN
static
int32_t
tsdbSnapReadOpenFile
(
STsdbSnapReader
*
pReader
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
SDFileSet
dFileSet
=
{.
fid
=
pReader
->
fid
};
SDFileSet
*
pSet
=
taosArraySearch
(
pReader
->
fs
.
aDFileSet
,
&
dFileSet
,
tDFileSetCmprFn
,
TD_GT
);
...
...
@@ -83,7 +84,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
pReader
->
fid
=
pSet
->
fid
;
code
=
tsdbDataFReaderOpen
(
&
pReader
->
pDataFReader
,
pReader
->
pTsdb
,
pSet
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
pReader
->
pIter
=
NULL
;
tRBTreeCreate
(
&
pReader
->
rbt
,
tFDataIterCmprFn
);
...
...
@@ -93,13 +94,13 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
pIter
->
type
=
SNAP_DATA_FILE_ITER
;
code
=
tsdbReadBlockIdx
(
pReader
->
pDataFReader
,
pIter
->
aBlockIdx
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
for
(
pIter
->
iBlockIdx
=
0
;
pIter
->
iBlockIdx
<
taosArrayGetSize
(
pIter
->
aBlockIdx
);
pIter
->
iBlockIdx
++
)
{
pIter
->
pBlockIdx
=
(
SBlockIdx
*
)
taosArrayGet
(
pIter
->
aBlockIdx
,
pIter
->
iBlockIdx
);
code
=
tsdbReadDataBlk
(
pReader
->
pDataFReader
,
pIter
->
pBlockIdx
,
&
pIter
->
mBlock
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
for
(
pIter
->
iBlock
=
0
;
pIter
->
iBlock
<
pIter
->
mBlock
.
nItem
;
pIter
->
iBlock
++
)
{
SDataBlk
dataBlk
;
...
...
@@ -108,7 +109,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
if
(
dataBlk
.
minVer
>
pReader
->
ever
||
dataBlk
.
maxVer
<
pReader
->
sver
)
continue
;
code
=
tsdbReadDataBlockEx
(
pReader
->
pDataFReader
,
&
dataBlk
,
&
pIter
->
bData
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
ASSERT
(
pIter
->
pBlockIdx
->
suid
==
pIter
->
bData
.
suid
);
ASSERT
(
pIter
->
pBlockIdx
->
uid
==
pIter
->
bData
.
uid
);
...
...
@@ -139,7 +140,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
pIter
->
iStt
=
iStt
;
code
=
tsdbReadSttBlk
(
pReader
->
pDataFReader
,
iStt
,
pIter
->
aSttBlk
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
for
(
pIter
->
iSttBlk
=
0
;
pIter
->
iSttBlk
<
taosArrayGetSize
(
pIter
->
aSttBlk
);
pIter
->
iSttBlk
++
)
{
SSttBlk
*
pSttBlk
=
(
SSttBlk
*
)
taosArrayGet
(
pIter
->
aSttBlk
,
pIter
->
iSttBlk
);
...
...
@@ -148,7 +149,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
if
(
pSttBlk
->
maxVer
<
pReader
->
sver
)
continue
;
code
=
tsdbReadSttBlockEx
(
pReader
->
pDataFReader
,
iStt
,
pSttBlk
,
&
pIter
->
bData
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
for
(
pIter
->
iRow
=
0
;
pIter
->
iRow
<
pIter
->
bData
.
nRow
;
pIter
->
iRow
++
)
{
int64_t
rowVer
=
pIter
->
bData
.
aVersion
[
pIter
->
iRow
];
...
...
@@ -169,13 +170,13 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
pIter
++
;
}
tsdbInfo
(
"vgId:%d, vnode snapshot tsdb open data file to read for %s, fid:%d"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
pReader
->
pTsdb
->
path
,
pReader
->
fid
);
return
code
;
_err:
tsdbError
(
"vgId:%d, vnode snapshot tsdb snap read open file failed since %s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
tstrerror
(
code
));
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d, %s failed since %s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
__func__
,
tstrerror
(
code
))
;
}
else
{
tsdbInfo
(
"vgId:%d, %s done, path:%s, fid:%d"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
__func__
,
pReader
->
pTsdb
->
path
,
pReader
->
fid
);
}
return
code
;
}
...
...
@@ -318,12 +319,14 @@ _exit:
static
int32_t
tsdbSnapReadData
(
STsdbSnapReader
*
pReader
,
uint8_t
**
ppData
)
{
int32_t
code
=
0
;
STsdb
*
pTsdb
=
pReader
->
pTsdb
;
int32_t
lino
=
0
;
STsdb
*
pTsdb
=
pReader
->
pTsdb
;
while
(
true
)
{
if
(
pReader
->
pDataFReader
==
NULL
)
{
code
=
tsdbSnapReadOpenFile
(
pReader
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
if
(
pReader
->
pDataFReader
==
NULL
)
break
;
...
...
@@ -338,17 +341,17 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
SBlockData
*
pBlockData
=
&
pReader
->
bData
;
code
=
tsdbUpdateTableSchema
(
pTsdb
->
pVnode
->
pMeta
,
id
.
suid
,
id
.
uid
,
&
pReader
->
skmTable
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
code
=
tBlockDataInit
(
pBlockData
,
&
id
,
pReader
->
skmTable
.
pTSchema
,
NULL
,
0
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
while
(
pRowInfo
->
suid
==
id
.
suid
&&
pRowInfo
->
uid
==
id
.
uid
)
{
code
=
tBlockDataAppendRow
(
pBlockData
,
&
pRowInfo
->
row
,
NULL
,
pRowInfo
->
uid
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
code
=
tsdbSnapNextRow
(
pReader
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
pRowInfo
=
tsdbSnapGetRow
(
pReader
);
if
(
pRowInfo
==
NULL
)
{
...
...
@@ -360,21 +363,22 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
}
code
=
tsdbSnapCmprData
(
pReader
,
ppData
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
break
;
}
return
code
;
_err:
tsdbError
(
"vgId:%d, vnode snapshot tsdb read data for %s failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
pTsdb
->
path
,
tstrerror
(
code
));
_exit:
if
(
code
)
{
tsdbError
(
"vgId:%d, %s failed since %s, path:%s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
tstrerror
(
code
),
pTsdb
->
path
);
}
return
code
;
}
static
int32_t
tsdbSnapReadDel
(
STsdbSnapReader
*
pReader
,
uint8_t
**
ppData
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
lino
=
0
;
STsdb
*
pTsdb
=
pReader
->
pTsdb
;
SDelFile
*
pDelFile
=
pReader
->
fs
.
pDelFile
;
...
...
@@ -385,11 +389,11 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
// open
code
=
tsdbDelFReaderOpen
(
&
pReader
->
pDelFReader
,
pDelFile
,
pTsdb
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
// read index
code
=
tsdbReadDelIdx
(
pReader
->
pDelFReader
,
pReader
->
aDelIdx
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
pReader
->
iDelIdx
=
0
;
}
...
...
@@ -405,7 +409,7 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
pReader
->
iDelIdx
++
;
code
=
tsdbReadDelData
(
pReader
->
pDelFReader
,
pDelIdx
,
pReader
->
aDelData
);
if
(
code
)
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
int32_t
size
=
0
;
for
(
int32_t
iDelData
=
0
;
iDelData
<
taosArrayGetSize
(
pReader
->
aDelData
);
iDelData
++
)
{
...
...
@@ -422,7 +426,7 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
*
ppData
=
taosMemoryMalloc
(
sizeof
(
SSnapDataHdr
)
+
size
);
if
(
*
ppData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
)
;
}
SSnapDataHdr
*
pHdr
=
(
SSnapDataHdr
*
)(
*
ppData
);
...
...
@@ -449,11 +453,9 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
}
_exit:
return
code
;
_err:
tsdbError
(
"vgId:%d, vnode snapshot tsdb read del for %s failed since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
pTsdb
->
path
,
tstrerror
(
code
));
if
(
code
)
{
tsdbError
(
"vgId:%d, %s failed since %s, path:%s"
,
TD_VID
(
pTsdb
->
pVnode
),
__func__
,
tstrerror
(
code
),
pTsdb
->
path
);
}
return
code
;
}
...
...
@@ -591,44 +593,39 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) {
int32_t
tsdbSnapRead
(
STsdbSnapReader
*
pReader
,
uint8_t
**
ppData
)
{
int32_t
code
=
0
;
int32_t
lino
=
0
;
*
ppData
=
NULL
;
// read data file
if
(
!
pReader
->
dataDone
)
{
code
=
tsdbSnapReadData
(
pReader
,
ppData
);
if
(
code
)
{
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
*
ppData
)
{
goto
_exit
;
}
else
{
if
(
*
ppData
)
{
goto
_exit
;
}
else
{
pReader
->
dataDone
=
1
;
}
pReader
->
dataDone
=
1
;
}
}
// read del file
if
(
!
pReader
->
delDone
)
{
code
=
tsdbSnapReadDel
(
pReader
,
ppData
);
if
(
code
)
{
goto
_err
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
if
(
*
ppData
)
{
goto
_exit
;
}
else
{
if
(
*
ppData
)
{
goto
_exit
;
}
else
{
pReader
->
delDone
=
1
;
}
pReader
->
delDone
=
1
;
}
}
_exit:
tsdbDebug
(
"vgId:%d, vnode snapshot tsdb read for %s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
pReader
->
pTsdb
->
path
);
return
code
;
_err:
tsdbError
(
"vgId:%d, vnode snapshot tsdb read for %s failed since %s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
pReader
->
pTsdb
->
path
,
tstrerror
(
code
));
if
(
code
)
{
tsdbError
(
"vgId:%d, %s failed since %s, path:%s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
__func__
,
tstrerror
(
code
),
pReader
->
pTsdb
->
path
);
}
else
{
tsdbDebug
(
"vgId:%d, %s done, path:%s"
,
TD_VID
(
pReader
->
pTsdb
->
pVnode
),
__func__
,
pReader
->
pTsdb
->
path
);
}
return
code
;
}
...
...
source/dnode/vnode/src/vnd/vnodeCfg.c
浏览文件 @
ac7d250a
...
...
@@ -125,13 +125,22 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
if
(
tjsonAddIntegerToObject
(
pJson
,
"vndStats.timeseries"
,
pCfg
->
vndStats
.
numOfTimeSeries
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"vndStats.ntimeseries"
,
pCfg
->
vndStats
.
numOfNTimeSeries
)
<
0
)
return
-
1
;
SJson
*
pNodeInfoArr
=
tjsonCreateArray
();
tjsonAddItemToObject
(
pJson
,
"syncCfg.nodeInfo"
,
pNodeInfoArr
);
SJson
*
nodeInfo
=
tjsonCreateArray
();
if
(
nodeInfo
==
NULL
)
return
-
1
;
if
(
tjsonAddItemToObject
(
pJson
,
"syncCfg.nodeInfo"
,
nodeInfo
)
<
0
)
return
-
1
;
vDebug
(
"vgId:%d, encode config, replicas:%d selfIndex:%d"
,
pCfg
->
vgId
,
pCfg
->
syncCfg
.
replicaNum
,
pCfg
->
syncCfg
.
myIndex
);
for
(
int
i
=
0
;
i
<
pCfg
->
syncCfg
.
replicaNum
;
++
i
)
{
SJson
*
pNodeInfo
=
tjsonCreateObject
();
tjsonAddIntegerToObject
(
pNodeInfo
,
"nodePort"
,
(
pCfg
->
syncCfg
.
nodeInfo
)[
i
].
nodePort
);
tjsonAddStringToObject
(
pNodeInfo
,
"nodeFqdn"
,
(
pCfg
->
syncCfg
.
nodeInfo
)[
i
].
nodeFqdn
);
tjsonAddItemToArray
(
pNodeInfoArr
,
pNodeInfo
);
SJson
*
info
=
tjsonCreateObject
();
SNodeInfo
*
pNode
=
(
SNodeInfo
*
)
&
pCfg
->
syncCfg
.
nodeInfo
[
i
];
if
(
info
==
NULL
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
info
,
"nodePort"
,
pNode
->
nodePort
)
<
0
)
return
-
1
;
if
(
tjsonAddStringToObject
(
info
,
"nodeFqdn"
,
pNode
->
nodeFqdn
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
info
,
"nodeId"
,
pNode
->
nodeId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
info
,
"clusterId"
,
pNode
->
clusterId
)
<
0
)
return
-
1
;
if
(
tjsonAddItemToArray
(
nodeInfo
,
info
)
<
0
)
return
-
1
;
vDebug
(
"vgId:%d, encode config, replica:%d ep:%s:%u dnode:%d"
,
pCfg
->
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
,
pNode
->
nodeId
);
}
return
0
;
...
...
@@ -240,15 +249,24 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
tjsonGetNumberValue
(
pJson
,
"vndStats.ntimeseries"
,
pCfg
->
vndStats
.
numOfNTimeSeries
,
code
);
if
(
code
<
0
)
return
-
1
;
SJson
*
pNodeInfoArr
=
tjsonGetObjectItem
(
pJson
,
"syncCfg.nodeInfo"
);
int
arraySize
=
tjsonGetArraySize
(
pNodeInfoArr
);
assert
(
arraySize
==
pCfg
->
syncCfg
.
replicaNum
)
;
SJson
*
nodeInfo
=
tjsonGetObjectItem
(
pJson
,
"syncCfg.nodeInfo"
);
int
arraySize
=
tjsonGetArraySize
(
nodeInfo
);
if
(
arraySize
!=
pCfg
->
syncCfg
.
replicaNum
)
return
-
1
;
vDebug
(
"vgId:%d, decode config, replicas:%d selfIndex:%d"
,
pCfg
->
vgId
,
pCfg
->
syncCfg
.
replicaNum
,
pCfg
->
syncCfg
.
myIndex
);
for
(
int
i
=
0
;
i
<
arraySize
;
++
i
)
{
SJson
*
pNodeInfo
=
tjsonGetArrayItem
(
pNodeInfoArr
,
i
);
assert
(
pNodeInfo
!=
NULL
);
tjsonGetNumberValue
(
pNodeInfo
,
"nodePort"
,
(
pCfg
->
syncCfg
.
nodeInfo
)[
i
].
nodePort
,
code
);
tjsonGetStringValue
(
pNodeInfo
,
"nodeFqdn"
,
(
pCfg
->
syncCfg
.
nodeInfo
)[
i
].
nodeFqdn
);
SJson
*
info
=
tjsonGetArrayItem
(
nodeInfo
,
i
);
SNodeInfo
*
pNode
=
&
pCfg
->
syncCfg
.
nodeInfo
[
i
];
if
(
info
==
NULL
)
return
-
1
;
tjsonGetNumberValue
(
info
,
"nodePort"
,
pNode
->
nodePort
,
code
);
if
(
code
<
0
)
return
-
1
;
tjsonGetStringValue
(
info
,
"nodeFqdn"
,
pNode
->
nodeFqdn
);
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
info
,
"nodeId"
,
pNode
->
nodeId
,
code
);
tjsonGetNumberValue
(
info
,
"clusterId"
,
pNode
->
clusterId
,
code
);
vDebug
(
"vgId:%d, decode config, replica:%d ep:%s:%u dnode:%d"
,
pCfg
->
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
,
pNode
->
nodeId
);
}
tjsonGetNumberValue
(
pJson
,
"tsdbPageSize"
,
pCfg
->
tsdbPageSize
,
code
);
...
...
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
ac7d250a
...
...
@@ -105,8 +105,8 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
// free info binary
taosMemoryFree
(
data
);
vInfo
(
"vgId:%d, vnode info is saved, fname:%s replica:%d"
,
pInfo
->
config
.
vgId
,
fname
,
pInfo
->
config
.
syncCfg
.
replicaNum
);
vInfo
(
"vgId:%d, vnode info is saved, fname:%s replica:%d
selfIndex:%d
"
,
pInfo
->
config
.
vgId
,
fname
,
pInfo
->
config
.
syncCfg
.
replicaNum
,
pInfo
->
config
.
syncCfg
.
myIndex
);
return
0
;
...
...
@@ -206,6 +206,8 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
}
else
{
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s"
,
pVnode
->
path
);
}
vDebug
(
"vgId:%d, save config while prepare commit"
,
TD_VID
(
pVnode
));
if
(
vnodeSaveInfo
(
dir
,
&
pInfo
->
info
)
<
0
)
{
code
=
terrno
;
TSDB_CHECK_CODE
(
code
,
lino
,
_exit
);
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
ac7d250a
...
...
@@ -48,6 +48,7 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
info
.
state
.
applied
=
-
1
;
info
.
state
.
commitID
=
0
;
vInfo
(
"vgId:%d, save config while create"
,
pCfg
->
vgId
);
if
(
vnodeSaveInfo
(
dir
,
&
info
)
<
0
||
vnodeCommitInfo
(
dir
,
&
info
)
<
0
)
{
vError
(
"vgId:%d, failed to save vnode config since %s"
,
pCfg
?
pCfg
->
vgId
:
0
,
tstrerror
(
terrno
));
return
-
1
;
...
...
@@ -79,12 +80,14 @@ int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs) {
pCfg
->
replicaNum
=
pReq
->
replica
;
memset
(
&
pCfg
->
nodeInfo
,
0
,
sizeof
(
pCfg
->
nodeInfo
));
vInfo
(
"vgId:%d, save config, replicas:%d selfIndex:%d"
,
pReq
->
vgId
,
pCfg
->
replicaNum
,
pCfg
->
myIndex
);
vInfo
(
"vgId:%d, save config
while alter
, replicas:%d selfIndex:%d"
,
pReq
->
vgId
,
pCfg
->
replicaNum
,
pCfg
->
myIndex
);
for
(
int
i
=
0
;
i
<
pReq
->
replica
;
++
i
)
{
SNodeInfo
*
pNode
=
&
pCfg
->
nodeInfo
[
i
];
pNode
->
nodeId
=
pReq
->
replicas
[
i
].
id
;
pNode
->
nodePort
=
pReq
->
replicas
[
i
].
port
;
tstrncpy
(
pNode
->
nodeFqdn
,
pReq
->
replicas
[
i
].
fqdn
,
sizeof
(
pNode
->
nodeFqdn
));
vInfo
(
"vgId:%d, save config, replica:%d ep:%s:%u"
,
pReq
->
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
);
(
void
)
tmsgUpdateDnodeInfo
(
&
pNode
->
nodeId
,
&
pNode
->
clusterId
,
pNode
->
nodeFqdn
,
&
pNode
->
nodePort
);
vInfo
(
"vgId:%d, replica:%d ep:%s:%u dnode:%d"
,
pReq
->
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
,
pNode
->
nodeId
);
}
info
.
config
.
syncCfg
=
*
pCfg
;
...
...
source/dnode/vnode/src/vnd/vnodeSnapshot.c
浏览文件 @
ac7d250a
...
...
@@ -405,6 +405,10 @@ static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_
}
else
{
snprintf
(
dir
,
TSDB_FILENAME_LEN
,
"%s"
,
pWriter
->
pVnode
->
path
);
}
SVnode
*
pVnode
=
pWriter
->
pVnode
;
pWriter
->
info
.
config
=
pVnode
->
config
;
vDebug
(
"vgId:%d, save config while write snapshot"
,
pWriter
->
pVnode
->
config
.
vgId
);
if
(
vnodeSaveInfo
(
dir
,
&
pWriter
->
info
)
<
0
)
{
code
=
terrno
;
goto
_exit
;
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
ac7d250a
...
...
@@ -578,7 +578,8 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
vInfo
(
"vgId:%d, start to open sync, replica:%d selfIndex:%d"
,
pVnode
->
config
.
vgId
,
pCfg
->
replicaNum
,
pCfg
->
myIndex
);
for
(
int32_t
i
=
0
;
i
<
pCfg
->
replicaNum
;
++
i
)
{
SNodeInfo
*
pNode
=
&
pCfg
->
nodeInfo
[
i
];
vInfo
(
"vgId:%d, index:%d ep:%s:%u"
,
pVnode
->
config
.
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
);
vInfo
(
"vgId:%d, index:%d ep:%s:%u dnode:%d cluster:%"
PRId64
,
pVnode
->
config
.
vgId
,
i
,
pNode
->
nodeFqdn
,
pNode
->
nodePort
,
pNode
->
nodeId
,
pNode
->
clusterId
);
}
pVnode
->
sync
=
syncOpen
(
&
syncInfo
);
...
...
source/libs/executor/inc/executil.h
浏览文件 @
ac7d250a
...
...
@@ -18,7 +18,6 @@
#include "function.h"
#include "nodes.h"
#include "plannodes.h"
#include "tbuffer.h"
#include "tcommon.h"
#include "tpagedbuf.h"
#include "tsimplehash.h"
...
...
@@ -116,6 +115,10 @@ struct SResultRowEntryInfo* getResultEntryInfo(const SResultRow* pRow, int32_t i
static
FORCE_INLINE
SResultRow
*
getResultRowByPos
(
SDiskbasedBuf
*
pBuf
,
SResultRowPosition
*
pos
,
bool
forUpdate
)
{
SFilePage
*
bufPage
=
(
SFilePage
*
)
getBufPage
(
pBuf
,
pos
->
pageId
);
if
(
NULL
==
bufPage
)
{
return
NULL
;
}
if
(
forUpdate
)
{
setBufPageDirty
(
bufPage
,
true
);
}
...
...
source/libs/executor/src/dataInserter.c
浏览文件 @
ac7d250a
...
...
@@ -41,6 +41,7 @@ typedef struct SDataInserterHandle {
SHashObj
*
pCols
;
int32_t
status
;
bool
queryEnd
;
bool
fullOrderColList
;
uint64_t
useconds
;
uint64_t
cachedSize
;
TdThreadMutex
mutex
;
...
...
@@ -125,7 +126,6 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) {
int64_t
uid
=
pInserter
->
pNode
->
tableId
;
int64_t
suid
=
pInserter
->
pNode
->
stableId
;
int32_t
vgId
=
pInserter
->
pNode
->
vgId
;
bool
fullCol
=
(
pInserter
->
pNode
->
pCols
->
length
==
pTSchema
->
numOfCols
);
SSubmitReq
*
ret
=
NULL
;
int32_t
sz
=
taosArrayGetSize
(
pBlocks
);
...
...
@@ -176,7 +176,7 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) {
const
STColumn
*
pColumn
=
&
pTSchema
->
columns
[
k
];
SColumnInfoData
*
pColData
=
NULL
;
int16_t
colIdx
=
k
;
if
(
!
fullCol
)
{
if
(
!
pInserter
->
fullOrderColList
)
{
int16_t
*
slotId
=
taosHashGet
(
pInserter
->
pCols
,
&
pColumn
->
colId
,
sizeof
(
pColumn
->
colId
));
if
(
NULL
==
slotId
)
{
continue
;
...
...
@@ -212,7 +212,7 @@ int32_t dataBlockToSubmit(SDataInserterHandle* pInserter, SSubmitReq** pReq) {
tdAppendColValToRow
(
&
rb
,
pColumn
->
colId
,
pColumn
->
type
,
TD_VTYPE_NORM
,
data
,
true
,
pColumn
->
offset
,
k
);
}
}
if
(
!
fullCol
)
{
if
(
!
pInserter
->
fullOrderColList
)
{
rb
.
hasNone
=
true
;
}
tdSRowEnd
(
&
rb
);
...
...
@@ -346,12 +346,19 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat
return
TSDB_CODE_OUT_OF_MEMORY
;
}
inserter
->
fullOrderColList
=
pInserterNode
->
pCols
->
length
==
inserter
->
pSchema
->
numOfCols
;
inserter
->
pCols
=
taosHashInit
(
pInserterNode
->
pCols
->
length
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_SMALLINT
),
false
,
HASH_NO_LOCK
);
SNode
*
pNode
=
NULL
;
int32_t
i
=
0
;
FOREACH
(
pNode
,
pInserterNode
->
pCols
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
taosHashPut
(
inserter
->
pCols
,
&
pCol
->
colId
,
sizeof
(
pCol
->
colId
),
&
pCol
->
slotId
,
sizeof
(
pCol
->
slotId
));
if
(
inserter
->
fullOrderColList
&&
pCol
->
colId
!=
inserter
->
pSchema
->
columns
[
i
].
colId
)
{
inserter
->
fullOrderColList
=
false
;
}
++
i
;
}
tsem_init
(
&
inserter
->
ready
,
0
,
0
);
...
...
source/libs/executor/src/executil.c
浏览文件 @
ac7d250a
...
...
@@ -1726,8 +1726,10 @@ STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowI
return
w
;
}
w
=
getResultRowByPos
(
pBuf
,
&
pResultRowInfo
->
cur
,
false
)
->
win
;
SResultRow
*
pRow
=
getResultRowByPos
(
pBuf
,
&
pResultRowInfo
->
cur
,
false
);
if
(
pRow
)
{
w
=
pRow
->
win
;
}
// in case of typical time window, we can calculate time window directly.
if
(
w
.
skey
>
ts
||
w
.
ekey
<
ts
)
{
w
=
doCalculateTimeWindow
(
ts
,
pInterval
);
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
ac7d250a
...
...
@@ -150,6 +150,11 @@ SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, i
pData
->
num
=
sizeof
(
SFilePage
);
}
else
{
pData
=
getBufPage
(
pResultBuf
,
*
currentPageId
);
if
(
pData
==
NULL
)
{
qError
(
"failed to get buffer, code:%s"
,
tstrerror
(
terrno
));
return
NULL
;
}
pageId
=
*
currentPageId
;
if
(
pData
->
num
+
interBufSize
>
getBufPageSize
(
pResultBuf
))
{
...
...
@@ -200,6 +205,10 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
if
(
isIntervalQuery
)
{
if
(
p1
!=
NULL
)
{
// the *p1 may be NULL in case of sliding+offset exists.
pResult
=
getResultRowByPos
(
pResultBuf
,
p1
,
true
);
if
(
NULL
==
pResult
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
ASSERT
(
pResult
->
pageId
==
p1
->
pageId
&&
pResult
->
offset
==
p1
->
offset
);
}
}
else
{
...
...
@@ -208,6 +217,10 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
if
(
p1
!=
NULL
)
{
// todo
pResult
=
getResultRowByPos
(
pResultBuf
,
p1
,
true
);
if
(
NULL
==
pResult
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
ASSERT
(
pResult
->
pageId
==
p1
->
pageId
&&
pResult
->
offset
==
p1
->
offset
);
}
}
...
...
@@ -216,6 +229,10 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
if
(
pResultRowInfo
->
cur
.
pageId
!=
-
1
&&
((
pResult
==
NULL
)
||
(
pResult
->
pageId
!=
pResultRowInfo
->
cur
.
pageId
)))
{
SResultRowPosition
pos
=
pResultRowInfo
->
cur
;
SFilePage
*
pPage
=
getBufPage
(
pResultBuf
,
pos
.
pageId
);
if
(
pPage
==
NULL
)
{
qError
(
"failed to get buffer, code:%s, %s"
,
tstrerror
(
terrno
),
GET_TASKID
(
pTaskInfo
));
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
releaseBufPage
(
pResultBuf
,
pPage
);
}
...
...
@@ -223,6 +240,9 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
if
(
pResult
==
NULL
)
{
ASSERT
(
pSup
->
resultRowSize
>
0
);
pResult
=
getNewResultRow
(
pResultBuf
,
&
pSup
->
currentPageId
,
pSup
->
resultRowSize
);
if
(
pResult
==
NULL
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
// add a new result set for a new group
SResultRowPosition
pos
=
{.
pageId
=
pResult
->
pageId
,
.
offset
=
pResult
->
offset
};
...
...
@@ -260,6 +280,11 @@ static int32_t addNewWindowResultBuf(SResultRow* pWindowRes, SDiskbasedBuf* pRes
}
else
{
SPageInfo
*
pi
=
getLastPageInfo
(
list
);
pData
=
getBufPage
(
pResultBuf
,
getPageId
(
pi
));
if
(
pData
==
NULL
)
{
qError
(
"failed to get buffer, code:%s"
,
tstrerror
(
terrno
));
return
terrno
;
}
pageId
=
getPageId
(
pi
);
if
(
pData
->
num
+
size
>
getBufPageSize
(
pResultBuf
))
{
...
...
@@ -912,7 +937,7 @@ void doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uin
if
(
pResultRow
->
pageId
==
-
1
)
{
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
pAggInfo
->
aggSup
.
pResultBuf
,
pAggInfo
->
binfo
.
pRes
->
info
.
rowSize
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
;
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
)
;
}
}
...
...
@@ -993,6 +1018,11 @@ static void doCopyResultToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SR
int32_t
finalizeResultRows
(
SDiskbasedBuf
*
pBuf
,
SResultRowPosition
*
resultRowPosition
,
SExprSupp
*
pSup
,
SSDataBlock
*
pBlock
,
SExecTaskInfo
*
pTaskInfo
)
{
SFilePage
*
page
=
getBufPage
(
pBuf
,
resultRowPosition
->
pageId
);
if
(
page
==
NULL
)
{
qError
(
"failed to get buffer, code:%s, %s"
,
tstrerror
(
terrno
),
GET_TASKID
(
pTaskInfo
));
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
SResultRow
*
pRow
=
(
SResultRow
*
)((
char
*
)
page
+
resultRowPosition
->
offset
);
SqlFunctionCtx
*
pCtx
=
pSup
->
pCtx
;
...
...
@@ -1036,6 +1066,10 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprS
for
(
int32_t
i
=
pGroupResInfo
->
index
;
i
<
numOfRows
;
i
+=
1
)
{
SResKeyPos
*
pPos
=
taosArrayGetP
(
pGroupResInfo
->
pRows
,
i
);
SFilePage
*
page
=
getBufPage
(
pBuf
,
pPos
->
pos
.
pageId
);
if
(
page
==
NULL
)
{
qError
(
"failed to get buffer, code:%s, %s"
,
tstrerror
(
terrno
),
GET_TASKID
(
pTaskInfo
));
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
SResultRow
*
pRow
=
(
SResultRow
*
)((
char
*
)
page
+
pPos
->
pos
.
offset
);
...
...
source/libs/executor/src/groupoperator.c
浏览文件 @
ac7d250a
...
...
@@ -492,13 +492,17 @@ _error:
static
void
doHashPartition
(
SOperatorInfo
*
pOperator
,
SSDataBlock
*
pBlock
)
{
SPartitionOperatorInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
rows
;
++
j
)
{
recordNewGroupKeys
(
pInfo
->
pGroupCols
,
pInfo
->
pGroupColVals
,
pBlock
,
j
);
int32_t
len
=
buildGroupKeys
(
pInfo
->
keyBuf
,
pInfo
->
pGroupColVals
);
SDataGroupInfo
*
pGroupInfo
=
NULL
;
void
*
pPage
=
getCurrentDataGroupInfo
(
pInfo
,
&
pGroupInfo
,
len
);
if
(
pPage
==
NULL
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
pGroupInfo
->
numOfRows
+=
1
;
...
...
@@ -595,6 +599,10 @@ void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDataGroupInf
}
else
{
int32_t
*
curId
=
taosArrayGetLast
(
p
->
pPageList
);
pPage
=
getBufPage
(
pInfo
->
pBuf
,
*
curId
);
if
(
pPage
==
NULL
)
{
qError
(
"failed to get buffer, code:%s"
,
tstrerror
(
terrno
));
return
pPage
;
}
int32_t
*
rows
=
(
int32_t
*
)
pPage
;
if
(
*
rows
>=
pInfo
->
rowCapacity
)
{
...
...
@@ -674,7 +682,8 @@ static int compareDataGroupInfo(const void* group1, const void* group2) {
static
SSDataBlock
*
buildPartitionResult
(
SOperatorInfo
*
pOperator
)
{
SPartitionOperatorInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SDataGroupInfo
*
pGroupInfo
=
(
pInfo
->
groupIndex
!=
-
1
)
?
taosArrayGet
(
pInfo
->
sortedGroupArray
,
pInfo
->
groupIndex
)
:
NULL
;
if
(
pInfo
->
groupIndex
==
-
1
||
pInfo
->
pageIndex
>=
taosArrayGetSize
(
pGroupInfo
->
pPageList
))
{
...
...
@@ -692,7 +701,11 @@ static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) {
int32_t
*
pageId
=
taosArrayGet
(
pGroupInfo
->
pPageList
,
pInfo
->
pageIndex
);
void
*
page
=
getBufPage
(
pInfo
->
pBuf
,
*
pageId
);
if
(
page
==
NULL
)
{
qError
(
"failed to get buffer, code:%s, %s"
,
tstrerror
(
terrno
),
GET_TASKID
(
pTaskInfo
));
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
blockDataEnsureCapacity
(
pInfo
->
binfo
.
pRes
,
pInfo
->
rowCapacity
);
blockDataFromBuf1
(
pInfo
->
binfo
.
pRes
,
page
,
pInfo
->
rowCapacity
);
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
ac7d250a
...
...
@@ -170,6 +170,10 @@ static SResultRow* getTableGroupOutputBuf(SOperatorInfo* pOperator, uint64_t gro
}
*
pPage
=
getBufPage
(
pTableScanInfo
->
base
.
pdInfo
.
pAggSup
->
pResultBuf
,
p1
->
pageId
);
if
(
NULL
==
*
pPage
)
{
return
NULL
;
}
return
(
SResultRow
*
)((
char
*
)(
*
pPage
)
+
p1
->
offset
);
}
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
ac7d250a
...
...
@@ -636,6 +636,10 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num
}
SResultRow
*
pr
=
getResultRowByPos
(
pInfo
->
aggSup
.
pResultBuf
,
p1
,
false
);
if
(
NULL
==
pr
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
ASSERT
(
pr
->
offset
==
p1
->
offset
&&
pr
->
pageId
==
p1
->
pageId
);
if
(
pr
->
closed
)
{
...
...
@@ -1315,6 +1319,10 @@ static void setInverFunction(SqlFunctionCtx* pCtx, int32_t num, EStreamType type
static
void
doClearWindowImpl
(
SResultRowPosition
*
p1
,
SDiskbasedBuf
*
pResultBuf
,
SExprSupp
*
pSup
,
int32_t
numOfOutput
)
{
SResultRow
*
pResult
=
getResultRowByPos
(
pResultBuf
,
p1
,
false
);
if
(
NULL
==
pResult
)
{
return
;
}
SqlFunctionCtx
*
pCtx
=
pSup
->
pCtx
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
pCtx
[
i
].
resultInfo
=
getResultEntryInfo
(
pResult
,
i
,
pSup
->
rowEntryInfoOffset
);
...
...
@@ -1328,6 +1336,9 @@ static void doClearWindowImpl(SResultRowPosition* p1, SDiskbasedBuf* pResultBuf,
}
}
SFilePage
*
bufPage
=
getBufPage
(
pResultBuf
,
p1
->
pageId
);
if
(
NULL
==
bufPage
)
{
return
;
}
setBufPageDirty
(
bufPage
,
true
);
releaseBufPage
(
pResultBuf
,
bufPage
);
}
...
...
@@ -4114,6 +4125,9 @@ void destroyMAIOperatorInfo(void* param) {
static
SResultRow
*
doSetSingleOutputTupleBuf
(
SResultRowInfo
*
pResultRowInfo
,
SAggSupporter
*
pSup
)
{
SResultRow
*
pResult
=
getNewResultRow
(
pSup
->
pResultBuf
,
&
pSup
->
currentPageId
,
pSup
->
resultRowSize
);
if
(
NULL
==
pResult
)
{
return
pResult
;
}
pResultRowInfo
->
cur
=
(
SResultRowPosition
){.
pageId
=
pResult
->
pageId
,
.
offset
=
pResult
->
offset
};
return
pResult
;
}
...
...
source/libs/executor/src/tsort.c
浏览文件 @
ac7d250a
...
...
@@ -270,6 +270,10 @@ static int32_t sortComparInit(SMsortComparParam* pParam, SArray* pSources, int32
int32_t
*
pPgId
=
taosArrayGet
(
pSource
->
pageIdList
,
pSource
->
pageIndex
);
void
*
pPage
=
getBufPage
(
pHandle
->
pBuf
,
*
pPgId
);
if
(
NULL
==
pPage
)
{
return
terrno
;
}
code
=
blockDataFromBuf
(
pSource
->
src
.
pBlock
,
pPage
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
@@ -337,6 +341,11 @@ static int32_t adjustMergeTreeForNextTuple(SSortSource* pSource, SMultiwayMergeT
int32_t
*
pPgId
=
taosArrayGet
(
pSource
->
pageIdList
,
pSource
->
pageIndex
);
void
*
pPage
=
getBufPage
(
pHandle
->
pBuf
,
*
pPgId
);
if
(
pPage
==
NULL
)
{
qError
(
"failed to get buffer, code:%s"
,
tstrerror
(
terrno
));
return
terrno
;
}
int32_t
code
=
blockDataFromBuf
(
pSource
->
src
.
pBlock
,
pPage
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
ac7d250a
...
...
@@ -784,7 +784,7 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
pEntryInfo
->
isNullRes
=
(
pEntryInfo
->
numOfRes
==
0
)
?
1
:
0
;
if
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_FLOAT
)
{
float
v
=
*
(
float
*
)
&
pRes
->
v
;
float
v
=
GET_FLOAT_VAL
(
&
pRes
->
v
)
;
colDataAppend
(
pCol
,
currentRow
,
(
const
char
*
)
&
v
,
pEntryInfo
->
isNullRes
);
}
else
{
colDataAppend
(
pCol
,
currentRow
,
(
const
char
*
)
&
pRes
->
v
,
pEntryInfo
->
isNullRes
);
...
...
source/libs/function/src/detail/tminmax.c
浏览文件 @
ac7d250a
...
...
@@ -737,7 +737,12 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
}
if
(
!
pBuf
->
assign
)
{
pBuf
->
v
=
*
(
int64_t
*
)
tval
;
if
(
type
==
TSDB_DATA_TYPE_FLOAT
)
{
GET_FLOAT_VAL
(
&
pBuf
->
v
)
=
GET_DOUBLE_VAL
(
tval
);
}
else
{
pBuf
->
v
=
GET_INT64_VAL
(
tval
);
}
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
index
=
findRowIndex
(
pInput
->
startRowIndex
,
pInput
->
numOfRows
,
pCol
,
tval
);
if
(
index
>=
0
)
{
...
...
@@ -751,7 +756,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
int64_t
val
=
GET_INT64_VAL
(
tval
);
if
((
prev
<
val
)
^
isMinFunc
)
{
*
(
int64_t
*
)
&
pBuf
->
v
=
val
;
GET_INT64_VAL
(
&
pBuf
->
v
)
=
val
;
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
index
=
findRowIndex
(
pInput
->
startRowIndex
,
pInput
->
numOfRows
,
pCol
,
tval
);
if
(
index
>=
0
)
{
...
...
@@ -765,7 +770,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
uint64_t
val
=
GET_UINT64_VAL
(
tval
);
if
((
prev
<
val
)
^
isMinFunc
)
{
*
(
uint64_t
*
)
&
pBuf
->
v
=
val
;
GET_UINT64_VAL
(
&
pBuf
->
v
)
=
val
;
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
index
=
findRowIndex
(
pInput
->
startRowIndex
,
pInput
->
numOfRows
,
pCol
,
tval
);
if
(
index
>=
0
)
{
...
...
@@ -779,7 +784,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
double
val
=
GET_DOUBLE_VAL
(
tval
);
if
((
prev
<
val
)
^
isMinFunc
)
{
*
(
double
*
)
&
pBuf
->
v
=
val
;
GET_DOUBLE_VAL
(
&
pBuf
->
v
)
=
val
;
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
index
=
findRowIndex
(
pInput
->
startRowIndex
,
pInput
->
numOfRows
,
pCol
,
tval
);
if
(
index
>=
0
)
{
...
...
@@ -793,7 +798,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
float
val
=
GET_DOUBLE_VAL
(
tval
);
if
((
prev
<
val
)
^
isMinFunc
)
{
*
(
float
*
)
&
pBuf
->
v
=
val
;
GET_FLOAT_VAL
(
&
pBuf
->
v
)
=
val
;
}
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
...
...
source/libs/function/src/tfunctionInt.c
浏览文件 @
ac7d250a
...
...
@@ -20,7 +20,6 @@
#include "ttypes.h"
#include "function.h"
#include "tbuffer.h"
#include "tcompression.h"
#include "tdatablock.h"
#include "tfunctionInt.h"
...
...
source/libs/function/src/udfd.c
浏览文件 @
ac7d250a
...
...
@@ -460,13 +460,14 @@ void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
#else
snprintf
(
path
,
sizeof
(
path
),
"%s/lib%s.so"
,
tsTempDir
,
pFuncInfo
->
name
);
#endif
TdFilePtr
file
=
taosOpenFile
(
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_READ
|
TD_FILE_TRUNC
|
TD_FILE_AUTO_DEL
);
TdFilePtr
file
=
taosOpenFile
(
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_READ
|
TD_FILE_TRUNC
);
if
(
file
==
NULL
)
{
fnError
(
"udfd write udf shared library: %s failed, error: %d %s"
,
path
,
errno
,
strerror
(
errno
));
msgInfo
->
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_return
;
}
int64_t
count
=
taosWriteFile
(
file
,
pFuncInfo
->
pCode
,
pFuncInfo
->
codeSize
);
if
(
count
!=
pFuncInfo
->
codeSize
)
{
fnError
(
"udfd write udf shared library failed"
);
...
...
source/libs/index/inc/indexUtil.h
浏览文件 @
ac7d250a
...
...
@@ -36,7 +36,6 @@ extern "C" {
#define SERIALIZE_VAR_TO_BUF(buf, var, type) \
do { \
type c = var; \
assert(sizeof(type) == sizeof(c)); \
memcpy((void *)buf, (void *)&c, sizeof(c)); \
buf += sizeof(c); \
} while (0)
...
...
source/libs/index/src/index.c
浏览文件 @
ac7d250a
...
...
@@ -226,7 +226,9 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
indexDebug
(
"w suid:%"
PRIu64
", colName:%s, colType:%d"
,
key
.
suid
,
key
.
colName
,
key
.
colType
);
IndexCache
**
cache
=
taosHashGet
(
index
->
colObj
,
buf
,
sz
);
assert
(
*
cache
!=
NULL
);
ASSERTS
(
*
cache
!=
NULL
,
"index-cache already release"
);
if
(
*
cache
==
NULL
)
return
-
1
;
int
ret
=
idxCachePut
(
*
cache
,
p
,
uid
);
if
(
ret
!=
0
)
{
return
ret
;
...
...
source/libs/index/src/indexComm.c
浏览文件 @
ac7d250a
...
...
@@ -170,7 +170,6 @@ TExeCond tCompare(__compar_fn_t func, int8_t cmptype, void* a, void* b, int8_t d
}
return
tDoCompare
(
func
,
cmptype
,
&
va
,
&
vb
);
}
assert
(
0
);
return
BREAK
;
#endif
}
...
...
@@ -367,7 +366,7 @@ int32_t idxConvertData(void* src, int8_t type, void** dst) {
tlen
=
taosEncodeBinary
(
dst
,
src
,
strlen
(
src
));
break
;
default:
ASSERT
(
0
);
ASSERT
S
(
0
,
"index invalid input type"
);
break
;
}
*
dst
=
(
char
*
)
*
dst
-
tlen
;
...
...
@@ -459,7 +458,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) {
*
dst
=
(
char
*
)
*
dst
-
tlen
;
break
;
default:
ASSERT
(
0
);
ASSERT
S
(
0
,
"index invalid input type"
);
break
;
}
return
tlen
;
...
...
source/libs/index/src/indexFilter.c
浏览文件 @
ac7d250a
...
...
@@ -206,7 +206,9 @@ static FORCE_INLINE int32_t sifGetValueFromNode(SNode *node, char **value) {
static
FORCE_INLINE
int32_t
sifInitJsonParam
(
SNode
*
node
,
SIFParam
*
param
,
SIFCtx
*
ctx
)
{
SOperatorNode
*
nd
=
(
SOperatorNode
*
)
node
;
assert
(
nodeType
(
node
)
==
QUERY_NODE_OPERATOR
);
if
(
nodeType
(
node
)
!=
QUERY_NODE_OPERATOR
)
{
return
-
1
;
}
SColumnNode
*
l
=
(
SColumnNode
*
)
nd
->
pLeft
;
SValueNode
*
r
=
(
SValueNode
*
)
nd
->
pRight
;
...
...
source/libs/index/src/indexFst.c
浏览文件 @
ac7d250a
...
...
@@ -65,10 +65,7 @@ void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes* nodes, bool isFinal) {
taosArrayPush
(
nodes
->
stack
,
&
un
);
}
FstBuilderNode
*
fstUnFinishedNodesPopRoot
(
FstUnFinishedNodes
*
nodes
)
{
assert
(
taosArrayGetSize
(
nodes
->
stack
)
==
1
);
FstBuilderNodeUnfinished
*
un
=
taosArrayPop
(
nodes
->
stack
);
assert
(
un
->
last
==
NULL
);
return
un
->
node
;
}
...
...
@@ -82,7 +79,6 @@ FstBuilderNode* fstUnFinishedNodesPopFreeze(FstUnFinishedNodes* nodes, CompiledA
FstBuilderNode
*
fstUnFinishedNodesPopEmpty
(
FstUnFinishedNodes
*
nodes
)
{
FstBuilderNodeUnfinished
*
un
=
taosArrayPop
(
nodes
->
stack
);
assert
(
un
->
last
==
NULL
);
return
un
->
node
;
}
void
fstUnFinishedNodesSetRootOutput
(
FstUnFinishedNodes
*
nodes
,
Output
out
)
{
...
...
@@ -102,7 +98,8 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output
}
int32_t
sz
=
taosArrayGetSize
(
nodes
->
stack
)
-
1
;
FstBuilderNodeUnfinished
*
un
=
taosArrayGet
(
nodes
->
stack
,
sz
);
assert
(
un
->
last
==
NULL
);
ASSERTS
(
un
->
last
==
NULL
,
"index-fst meet unexpected node"
);
if
(
un
->
last
!=
NULL
)
return
;
// FstLastTransition *trn = taosMemoryMalloc(sizeof(FstLastTransition));
// trn->inp = s->data[s->start];
...
...
@@ -247,7 +244,6 @@ void fstStateCompileForOneTrans(IdxFstFile* w, CompiledAddr addr, FstTransition*
}
void
fstStateCompileForAnyTrans
(
IdxFstFile
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
)
{
int32_t
sz
=
taosArrayGetSize
(
node
->
trans
);
assert
(
sz
<=
256
);
uint8_t
tSize
=
0
;
uint8_t
oSize
=
packSize
(
node
->
finalOutput
);
...
...
@@ -322,7 +318,7 @@ void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode
// set_comm_input
void
fstStateSetCommInput
(
FstState
*
s
,
uint8_t
inp
)
{
assert
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
ASSERT
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
uint8_t
val
;
COMMON_INDEX
(
inp
,
0
b111111
,
val
);
...
...
@@ -331,7 +327,7 @@ void fstStateSetCommInput(FstState* s, uint8_t inp) {
// comm_input
uint8_t
fstStateCommInput
(
FstState
*
s
,
bool
*
null
)
{
assert
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
ASSERT
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
uint8_t
v
=
s
->
val
&
0
b00111111
;
if
(
v
==
0
)
{
*
null
=
true
;
...
...
@@ -344,7 +340,7 @@ uint8_t fstStateCommInput(FstState* s, bool* null) {
// input_len
uint64_t
fstStateInputLen
(
FstState
*
s
)
{
assert
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
ASSERT
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
bool
null
=
false
;
fstStateCommInput
(
s
,
&
null
);
return
null
?
1
:
0
;
...
...
@@ -352,11 +348,11 @@ uint64_t fstStateInputLen(FstState* s) {
// end_addr
uint64_t
fstStateEndAddrForOneTransNext
(
FstState
*
s
,
FstSlice
*
data
)
{
assert
(
s
->
state
==
OneTransNext
);
ASSERT
(
s
->
state
==
OneTransNext
);
return
FST_SLICE_LEN
(
data
)
-
1
-
fstStateInputLen
(
s
);
}
uint64_t
fstStateEndAddrForOneTrans
(
FstState
*
s
,
FstSlice
*
data
,
PackSizes
sizes
)
{
assert
(
s
->
state
==
OneTrans
);
ASSERT
(
s
->
state
==
OneTrans
);
return
FST_SLICE_LEN
(
data
)
-
1
-
fstStateInputLen
(
s
)
-
1
// pack size
-
FST_GET_TRANSITION_PACK_SIZE
(
sizes
)
-
FST_GET_OUTPUT_PACK_SIZE
(
sizes
);
}
...
...
@@ -370,7 +366,7 @@ uint64_t fstStateEndAddrForAnyTrans(FstState* state, uint64_t version, FstSlice*
}
// input
uint8_t
fstStateInput
(
FstState
*
s
,
FstNode
*
node
)
{
assert
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
ASSERT
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
FstSlice
*
slice
=
&
node
->
data
;
bool
null
=
false
;
uint8_t
inp
=
fstStateCommInput
(
s
,
&
null
);
...
...
@@ -378,7 +374,7 @@ uint8_t fstStateInput(FstState* s, FstNode* node) {
return
null
==
false
?
inp
:
data
[
node
->
start
-
1
];
}
uint8_t
fstStateInputForAnyTrans
(
FstState
*
s
,
FstNode
*
node
,
uint64_t
i
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
FstSlice
*
slice
=
&
node
->
data
;
uint64_t
at
=
node
->
start
-
fstStateNtransLen
(
s
)
-
1
// pack size
...
...
@@ -390,7 +386,7 @@ uint8_t fstStateInputForAnyTrans(FstState* s, FstNode* node, uint64_t i) {
// trans_addr
CompiledAddr
fstStateTransAddr
(
FstState
*
s
,
FstNode
*
node
)
{
assert
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
ASSERT
(
s
->
state
==
OneTransNext
||
s
->
state
==
OneTrans
);
FstSlice
*
slice
=
&
node
->
data
;
if
(
s
->
state
==
OneTransNext
)
{
return
(
CompiledAddr
)(
node
->
end
)
-
1
;
...
...
@@ -406,7 +402,7 @@ CompiledAddr fstStateTransAddr(FstState* s, FstNode* node) {
}
}
CompiledAddr
fstStateTransAddrForAnyTrans
(
FstState
*
s
,
FstNode
*
node
,
uint64_t
i
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
FstSlice
*
slice
=
&
node
->
data
;
uint8_t
tSizes
=
FST_GET_TRANSITION_PACK_SIZE
(
node
->
sizes
);
...
...
@@ -418,7 +414,7 @@ CompiledAddr fstStateTransAddrForAnyTrans(FstState* s, FstNode* node, uint64_t i
// sizes
PackSizes
fstStateSizes
(
FstState
*
s
,
FstSlice
*
slice
)
{
assert
(
s
->
state
==
OneTrans
||
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
OneTrans
||
s
->
state
==
AnyTrans
);
uint64_t
i
;
if
(
s
->
state
==
OneTrans
)
{
i
=
FST_SLICE_LEN
(
slice
)
-
1
-
fstStateInputLen
(
s
)
-
1
;
...
...
@@ -431,7 +427,7 @@ PackSizes fstStateSizes(FstState* s, FstSlice* slice) {
}
// Output
Output
fstStateOutput
(
FstState
*
s
,
FstNode
*
node
)
{
assert
(
s
->
state
==
OneTrans
);
ASSERT
(
s
->
state
==
OneTrans
);
uint8_t
oSizes
=
FST_GET_OUTPUT_PACK_SIZE
(
node
->
sizes
);
if
(
oSizes
==
0
)
{
...
...
@@ -445,7 +441,7 @@ Output fstStateOutput(FstState* s, FstNode* node) {
return
unpackUint64
(
data
+
i
,
oSizes
);
}
Output
fstStateOutputForAnyTrans
(
FstState
*
s
,
FstNode
*
node
,
uint64_t
i
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
uint8_t
oSizes
=
FST_GET_OUTPUT_PACK_SIZE
(
node
->
sizes
);
if
(
oSizes
==
0
)
{
...
...
@@ -462,19 +458,19 @@ Output fstStateOutputForAnyTrans(FstState* s, FstNode* node, uint64_t i) {
// anyTrans specify function
void
fstStateSetFinalState
(
FstState
*
s
,
bool
yes
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
if
(
yes
)
{
s
->
val
|=
0
b01000000
;
}
return
;
}
bool
fstStateIsFinalState
(
FstState
*
s
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
return
(
s
->
val
&
0
b01000000
)
==
0
b01000000
;
}
void
fstStateSetStateNtrans
(
FstState
*
s
,
uint8_t
n
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
if
(
n
<=
0
b00111111
)
{
s
->
val
=
(
s
->
val
&
0
b11000000
)
|
n
;
}
...
...
@@ -482,7 +478,7 @@ void fstStateSetStateNtrans(FstState* s, uint8_t n) {
}
// state_ntrans
uint8_t
fstStateStateNtrans
(
FstState
*
s
,
bool
*
null
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
*
null
=
false
;
uint8_t
n
=
s
->
val
&
0
b00111111
;
...
...
@@ -492,16 +488,16 @@ uint8_t fstStateStateNtrans(FstState* s, bool* null) {
return
n
;
}
uint64_t
fstStateTotalTransSize
(
FstState
*
s
,
uint64_t
version
,
PackSizes
sizes
,
uint64_t
nTrans
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
uint64_t
idxSize
=
fstStateTransIndexSize
(
s
,
version
,
nTrans
);
return
nTrans
+
(
nTrans
*
FST_GET_TRANSITION_PACK_SIZE
(
sizes
))
+
idxSize
;
}
uint64_t
fstStateTransIndexSize
(
FstState
*
s
,
uint64_t
version
,
uint64_t
nTrans
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
return
(
version
>=
2
&&
nTrans
>
TRANS_INDEX_THRESHOLD
)
?
256
:
0
;
}
uint64_t
fstStateNtransLen
(
FstState
*
s
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
bool
null
=
false
;
fstStateStateNtrans
(
s
,
&
null
);
return
null
==
true
?
1
:
0
;
...
...
@@ -530,7 +526,7 @@ Output fstStateFinalOutput(FstState* s, uint64_t version, FstSlice* slice, PackS
return
unpackUint64
(
data
+
at
,
(
uint8_t
)
oSizes
);
}
uint64_t
fstStateFindInput
(
FstState
*
s
,
FstNode
*
node
,
uint8_t
b
,
bool
*
null
)
{
assert
(
s
->
state
==
AnyTrans
);
ASSERT
(
s
->
state
==
AnyTrans
);
FstSlice
*
slice
=
&
node
->
data
;
if
(
node
->
version
>=
2
&&
node
->
nTrans
>
TRANS_INDEX_THRESHOLD
)
{
uint64_t
at
=
node
->
start
-
fstStateNtransLen
(
s
)
-
1
// pack size
...
...
@@ -676,17 +672,17 @@ bool fstNodeGetTransitionAddrAt(FstNode* node, uint64_t i, CompiledAddr* res) {
bool
s
=
true
;
FstState
*
st
=
&
node
->
state
;
if
(
st
->
state
==
OneTransNext
)
{
assert
(
i
==
0
);
ASSERT
(
i
==
0
);
fstStateTransAddr
(
st
,
node
);
}
else
if
(
st
->
state
==
OneTrans
)
{
assert
(
i
==
0
);
ASSERT
(
i
==
0
);
fstStateTransAddr
(
st
,
node
);
}
else
if
(
st
->
state
==
AnyTrans
)
{
fstStateTransAddrForAnyTrans
(
st
,
node
,
i
);
}
else
if
(
FST_STATE_EMPTY_FINAL
(
node
))
{
s
=
false
;
}
else
{
assert
(
0
);
ASSERT
(
0
);
}
return
s
;
}
...
...
@@ -722,7 +718,7 @@ bool fstNodeFindInput(FstNode* node, uint8_t b, uint64_t* res) {
bool
fstNodeCompile
(
FstNode
*
node
,
void
*
w
,
CompiledAddr
lastAddr
,
CompiledAddr
addr
,
FstBuilderNode
*
builderNode
)
{
int32_t
sz
=
taosArrayGetSize
(
builderNode
->
trans
);
assert
(
sz
<
256
);
ASSERT
(
sz
<
256
);
if
(
sz
==
0
&&
builderNode
->
isFinal
&&
builderNode
->
finalOutput
==
0
)
{
return
true
;
}
else
if
(
sz
!=
1
||
builderNode
->
isFinal
)
{
...
...
@@ -804,7 +800,7 @@ void fstBuilderInsertOutput(FstBuilder* b, FstSlice bs, Output in) {
uint64_t
prefixLen
=
fstUnFinishedNodesFindCommPrefixAndSetOutput
(
b
->
unfinished
,
bs
,
in
,
&
out
);
if
(
prefixLen
==
FST_SLICE_LEN
(
s
))
{
assert
(
out
==
0
);
ASSERT
(
out
==
0
);
return
;
}
...
...
@@ -848,7 +844,7 @@ void fstBuilderCompileFrom(FstBuilder* b, uint64_t istate) {
addr
=
fstBuilderCompile
(
b
,
bn
);
fstBuilderNodeDestroy
(
bn
);
assert
(
addr
!=
NONE_ADDRESS
);
ASSERT
(
addr
!=
NONE_ADDRESS
);
}
fstUnFinishedNodesTopLastFreeze
(
b
->
unfinished
,
addr
);
return
;
...
...
source/libs/index/src/indexFstDfa.c
浏览文件 @
ac7d250a
...
...
@@ -104,8 +104,9 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet
DfaState
*
t
=
taosArrayGet
(
builder
->
dfa
->
states
,
state
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
t
->
insts
);
i
++
)
{
int32_t
ip
=
*
(
int32_t
*
)
taosArrayGet
(
t
->
insts
,
i
);
bool
succ
=
sparSetAdd
(
cur
,
ip
,
NULL
);
assert
(
succ
==
true
);
bool
succ
=
sparSetAdd
(
cur
,
ip
,
NULL
);
if
(
succ
==
false
)
return
false
;
}
dfaRun
(
builder
->
dfa
,
cur
,
next
,
byte
);
...
...
source/libs/index/src/indexFstFile.c
浏览文件 @
ac7d250a
...
...
@@ -100,7 +100,7 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
do
{
char
key
[
1024
]
=
{
0
};
assert
(
strlen
(
ctx
->
file
.
buf
)
+
1
+
64
<
sizeof
(
key
));
ASSERT
(
strlen
(
ctx
->
file
.
buf
)
+
1
+
64
<
sizeof
(
key
));
idxGenLRUKey
(
key
,
ctx
->
file
.
buf
,
blkId
);
LRUHandle
*
h
=
taosLRUCacheLookup
(
ctx
->
lru
,
key
,
strlen
(
key
));
...
...
@@ -114,7 +114,8 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
if
(
left
<
kBlockSize
)
{
nread
=
TMIN
(
left
,
len
);
int32_t
bytes
=
taosPReadFile
(
ctx
->
file
.
pFile
,
buf
+
total
,
nread
,
offset
);
assert
(
bytes
==
nread
);
ASSERTS
(
bytes
==
nread
,
"index read incomplete data"
);
if
(
bytes
!=
nread
)
break
;
total
+=
bytes
;
return
total
;
...
...
@@ -124,7 +125,8 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of
SDataBlock
*
blk
=
taosMemoryCalloc
(
1
,
cacheMemSize
);
blk
->
blockId
=
blkId
;
blk
->
nread
=
taosPReadFile
(
ctx
->
file
.
pFile
,
blk
->
buf
,
kBlockSize
,
blkId
*
kBlockSize
);
assert
(
blk
->
nread
<=
kBlockSize
);
ASSERTS
(
blk
->
nread
<=
kBlockSize
,
"index read incomplete data"
);
if
(
blk
->
nread
>
kBlockSize
)
break
;
if
(
blk
->
nread
<
kBlockSize
&&
blk
->
nread
<
len
)
{
taosMemoryFree
(
blk
);
...
...
@@ -275,7 +277,10 @@ int idxFileWrite(IdxFstFile* write, uint8_t* buf, uint32_t len) {
// update checksum
IFileCtx
*
ctx
=
write
->
wrt
;
int
nWrite
=
ctx
->
write
(
ctx
,
buf
,
len
);
assert
(
nWrite
==
len
);
ASSERTS
(
nWrite
==
len
,
"index write incomplete data"
);
if
(
nWrite
!=
len
)
{
return
-
1
;
}
write
->
count
+=
len
;
write
->
summer
=
taosCalcChecksum
(
write
->
summer
,
buf
,
len
);
...
...
@@ -302,7 +307,6 @@ int idxFileFlush(IdxFstFile* write) {
}
void
idxFilePackUintIn
(
IdxFstFile
*
writer
,
uint64_t
n
,
uint8_t
nBytes
)
{
assert
(
1
<=
nBytes
&&
nBytes
<=
8
);
uint8_t
*
buf
=
taosMemoryCalloc
(
8
,
sizeof
(
uint8_t
));
for
(
uint8_t
i
=
0
;
i
<
nBytes
;
i
++
)
{
buf
[
i
]
=
(
uint8_t
)
n
;
...
...
source/libs/index/src/indexFstRegister.c
浏览文件 @
ac7d250a
...
...
@@ -57,8 +57,8 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) {
if
(
start
>=
sz
&&
end
>=
sz
)
{
return
;
}
assert
(
start
>=
end
)
;
ASSERTS
(
start
>=
end
,
"index-fst start lower than end"
);
if
(
start
<
end
)
return
;
int32_t
s
=
(
int32_t
)
start
;
int32_t
e
=
(
int32_t
)
end
;
...
...
source/libs/index/src/indexFstUtil.c
浏览文件 @
ac7d250a
...
...
@@ -101,7 +101,6 @@ FstSlice fstSliceDeepCopy(FstSlice* s, int32_t start, int32_t end) {
int32_t
slen
;
uint8_t
*
data
=
fstSliceData
(
s
,
&
slen
);
assert
(
tlen
<=
slen
);
uint8_t
*
buf
=
taosMemoryMalloc
(
sizeof
(
uint8_t
)
*
tlen
);
memcpy
(
buf
,
data
+
start
,
tlen
);
...
...
source/libs/index/src/indexTfile.c
浏览文件 @
ac7d250a
...
...
@@ -122,7 +122,6 @@ TFileCache* tfileCacheCreate(SIndex* idx, const char* path) {
char
buf
[
128
]
=
{
0
};
int32_t
sz
=
idxSerialCacheKey
(
&
key
,
buf
);
assert
(
sz
<
sizeof
(
buf
));
taosHashPut
(
tcache
->
tableCache
,
buf
,
sz
,
&
reader
,
sizeof
(
void
*
));
tfileReaderRef
(
reader
);
}
...
...
@@ -151,9 +150,8 @@ void tfileCacheDestroy(TFileCache* tcache) {
}
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
ICacheKey
*
key
)
{
char
buf
[
128
]
=
{
0
};
int32_t
sz
=
idxSerialCacheKey
(
key
,
buf
);
assert
(
sz
<
sizeof
(
buf
));
char
buf
[
128
]
=
{
0
};
int32_t
sz
=
idxSerialCacheKey
(
key
,
buf
);
TFileReader
**
reader
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
sz
);
if
(
reader
==
NULL
||
*
reader
==
NULL
)
{
return
NULL
;
...
...
@@ -877,7 +875,7 @@ static int tfileWriteFooter(TFileWriter* write) {
int
nwrite
=
write
->
ctx
->
write
(
write
->
ctx
,
buf
,
(
int32_t
)
strlen
(
buf
));
indexInfo
(
"tfile write footer size: %d"
,
write
->
ctx
->
size
(
write
->
ctx
));
assert
(
nwrite
==
sizeof
(
FILE_MAGIC_NUMBER
)
);
ASSERTS
(
nwrite
==
sizeof
(
FILE_MAGIC_NUMBER
),
"index write incomplete data"
);
return
nwrite
;
}
static
int
tfileReaderLoadHeader
(
TFileReader
*
reader
)
{
...
...
@@ -892,7 +890,6 @@ static int tfileReaderLoadHeader(TFileReader* reader) {
}
else
{
indexInfo
(
"actual Read: %d, to read: %d, filename: %s"
,
(
int
)(
nread
),
(
int
)
sizeof
(
buf
),
reader
->
ctx
->
file
.
buf
);
}
// assert(nread == sizeof(buf));
memcpy
(
&
reader
->
header
,
buf
,
sizeof
(
buf
));
return
0
;
...
...
@@ -914,7 +911,10 @@ static int tfileReaderLoadFst(TFileReader* reader) {
indexInfo
(
"nread = %d, and fst offset=%d, fst size: %d, filename: %s, file size: %d, time cost: %"
PRId64
"us"
,
nread
,
reader
->
header
.
fstOffset
,
fstSize
,
ctx
->
file
.
buf
,
size
,
cost
);
// we assuse fst size less than FST_MAX_SIZE
assert
(
nread
>
0
&&
nread
<=
fstSize
);
ASSERTS
(
nread
>
0
&&
nread
<=
fstSize
,
"index read incomplete fst"
);
if
(
nread
<=
0
||
nread
>
fstSize
)
{
return
-
1
;
}
FstSlice
st
=
fstSliceCreate
((
uint8_t
*
)
buf
,
nread
);
reader
->
fst
=
fstCreate
(
&
st
);
...
...
@@ -929,7 +929,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
// add block cache
char
block
[
4096
]
=
{
0
};
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
block
,
sizeof
(
block
),
offset
);
assert
(
nread
>=
sizeof
(
uint32_t
));
ASSERT
(
nread
>=
sizeof
(
uint32_t
));
char
*
p
=
block
;
int32_t
nid
=
*
(
int32_t
*
)
p
;
...
...
source/libs/stream/src/streamMeta.c
浏览文件 @
ac7d250a
...
...
@@ -294,6 +294,7 @@ int32_t streamLoadTasks(SStreamMeta* pMeta) {
tdbTbcClose
(
pCur
);
return
-
1
;
}
pTask
->
taskStatus
=
TASK_STATUS__NORMAL
;
}
tdbFree
(
pKey
);
...
...
source/libs/stream/src/streamState.c
浏览文件 @
ac7d250a
...
...
@@ -107,7 +107,7 @@ static inline int stateKeyCmpr(const void* pKey1, int kLen1, const void* pKey2,
}
SStreamState
*
streamStateOpen
(
char
*
path
,
SStreamTask
*
pTask
,
bool
specPath
,
int32_t
szPage
,
int32_t
pages
)
{
szPage
=
szPage
<
0
?
(
16
*
1024
)
:
szPage
;
szPage
=
szPage
<
0
?
4096
:
szPage
;
pages
=
pages
<
0
?
256
:
pages
;
SStreamState
*
pState
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamState
));
if
(
pState
==
NULL
)
{
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
ac7d250a
...
...
@@ -53,6 +53,18 @@ typedef struct SyncPreSnapshot SyncPreSnapshot;
typedef
struct
SSyncLogBuffer
SSyncLogBuffer
;
typedef
struct
SSyncLogReplMgr
SSyncLogReplMgr
;
#define MAX_CONFIG_INDEX_COUNT 256
typedef
struct
SRaftCfg
{
SSyncCfg
cfg
;
int32_t
batchSize
;
int8_t
isStandBy
;
int8_t
snapshotStrategy
;
SyncIndex
lastConfigIndex
;
int32_t
configIndexCount
;
SyncIndex
configIndexArr
[
MAX_CONFIG_INDEX_COUNT
];
}
SRaftCfg
;
typedef
struct
SRaftId
{
SyncNodeId
addr
;
SyncGroupId
vgId
;
...
...
@@ -93,7 +105,7 @@ typedef struct SPeerState {
typedef
struct
SSyncNode
{
// init by SSyncInfo
SyncGroupId
vgId
;
SRaftCfg
*
pR
aftCfg
;
SRaftCfg
r
aftCfg
;
char
path
[
TSDB_FILENAME_LEN
];
char
raftStorePath
[
TSDB_FILENAME_LEN
*
2
];
char
configPath
[
TSDB_FILENAME_LEN
*
2
];
...
...
@@ -112,6 +124,7 @@ typedef struct SSyncNode {
int32_t
peersNum
;
SNodeInfo
peersNodeInfo
[
TSDB_MAX_REPLICA
];
SEpSet
peersEpset
[
TSDB_MAX_REPLICA
];
SRaftId
peersId
[
TSDB_MAX_REPLICA
];
int32_t
replicaNum
;
...
...
@@ -245,7 +258,6 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
// utils --------------
int32_t
syncNodeSendMsgById
(
const
SRaftId
*
destRaftId
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
);
int32_t
syncNodeSendMsgByInfo
(
const
SNodeInfo
*
nodeInfo
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
);
SyncIndex
syncMinMatchIndex
(
SSyncNode
*
pSyncNode
);
int32_t
syncCacheEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
,
LRUHandle
**
h
);
bool
syncNodeHeartbeatReplyTimeout
(
SSyncNode
*
pSyncNode
);
...
...
source/libs/sync/inc/syncRaftCfg.h
浏览文件 @
ac7d250a
...
...
@@ -22,64 +22,9 @@ extern "C" {
#include "syncInt.h"
#define CONFIG_FILE_LEN 2048
#define MAX_CONFIG_INDEX_COUNT 256
typedef
struct
SRaftCfgIndex
{
TdFilePtr
pFile
;
char
path
[
TSDB_FILENAME_LEN
*
2
];
SyncIndex
configIndexArr
[
MAX_CONFIG_INDEX_COUNT
];
int32_t
configIndexCount
;
}
SRaftCfgIndex
;
SRaftCfgIndex
*
raftCfgIndexOpen
(
const
char
*
path
);
int32_t
raftCfgIndexClose
(
SRaftCfgIndex
*
pRaftCfgIndex
);
int32_t
raftCfgIndexPersist
(
SRaftCfgIndex
*
pRaftCfgIndex
);
int32_t
raftCfgIndexAddConfigIndex
(
SRaftCfgIndex
*
pRaftCfgIndex
,
SyncIndex
configIndex
);
cJSON
*
raftCfgIndex2Json
(
SRaftCfgIndex
*
pRaftCfgIndex
);
char
*
raftCfgIndex2Str
(
SRaftCfgIndex
*
pRaftCfgIndex
);
int32_t
raftCfgIndexFromJson
(
const
cJSON
*
pRoot
,
SRaftCfgIndex
*
pRaftCfgIndex
);
int32_t
raftCfgIndexFromStr
(
const
char
*
s
,
SRaftCfgIndex
*
pRaftCfgIndex
);
int32_t
raftCfgIndexCreateFile
(
const
char
*
path
);
typedef
struct
SRaftCfg
{
SSyncCfg
cfg
;
TdFilePtr
pFile
;
char
path
[
TSDB_FILENAME_LEN
*
2
];
int8_t
isStandBy
;
int32_t
batchSize
;
int8_t
snapshotStrategy
;
SyncIndex
lastConfigIndex
;
SyncIndex
configIndexArr
[
MAX_CONFIG_INDEX_COUNT
];
int32_t
configIndexCount
;
}
SRaftCfg
;
SRaftCfg
*
raftCfgOpen
(
const
char
*
path
);
int32_t
raftCfgClose
(
SRaftCfg
*
pRaftCfg
);
int32_t
raftCfgPersist
(
SRaftCfg
*
pRaftCfg
);
int32_t
raftCfgAddConfigIndex
(
SRaftCfg
*
pRaftCfg
,
SyncIndex
configIndex
);
void
syncCfg2SimpleStr
(
const
SSyncCfg
*
pCfg
,
char
*
str
,
int32_t
bufLen
);
cJSON
*
syncCfg2Json
(
SSyncCfg
*
pSyncCfg
);
int32_t
syncCfgFromJson
(
const
cJSON
*
pRoot
,
SSyncCfg
*
pSyncCfg
);
cJSON
*
raftCfg2Json
(
SRaftCfg
*
pRaftCfg
);
char
*
raftCfg2Str
(
SRaftCfg
*
pRaftCfg
);
int32_t
raftCfgFromJson
(
const
cJSON
*
pRoot
,
SRaftCfg
*
pRaftCfg
);
int32_t
raftCfgFromStr
(
const
char
*
s
,
SRaftCfg
*
pRaftCfg
);
typedef
struct
SRaftCfgMeta
{
int8_t
isStandBy
;
int32_t
batchSize
;
int8_t
snapshotStrategy
;
SyncIndex
lastConfigIndex
;
}
SRaftCfgMeta
;
int32_t
raftCfgCreateFile
(
SSyncCfg
*
pCfg
,
SRaftCfgMeta
meta
,
const
char
*
path
);
int32_t
syncWriteCfgFile
(
SSyncNode
*
pNode
);
int32_t
syncReadCfgFile
(
SSyncNode
*
pNode
);
int32_t
syncAddCfgIndex
(
SSyncNode
*
pNode
,
SyncIndex
cfgIndex
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncUtil.h
浏览文件 @
ac7d250a
...
...
@@ -62,22 +62,19 @@ extern "C" {
// clang-format on
uint64_t
syncUtilAddr2U64
(
const
char
*
host
,
uint16_t
port
);
void
syncUtilU642Addr
(
uint64_t
u64
,
char
*
host
,
int64_t
len
,
uint16_t
*
port
);
void
syncUtilNodeInfo2EpSet
(
const
SNodeInfo
*
pInfo
,
SEpSet
*
pEpSet
);
void
syncUtilRaftId2EpSet
(
const
SRaftId
*
raftId
,
SEpSet
*
pEpSet
);
bool
syncUtilNodeInfo2RaftId
(
const
SNodeInfo
*
pInfo
,
SyncGroupId
vgId
,
SRaftId
*
raftId
);
bool
syncUtilSameId
(
const
SRaftId
*
pId1
,
const
SRaftId
*
pId2
);
bool
syncUtilEmptyId
(
const
SRaftId
*
pId
);
#define CID(pRaftId) (int32_t)(((pRaftId)->addr) >> 32)
#define DID(pRaftId) (int32_t)((pRaftId)->addr)
#define SYNC_ADDR(pInfo) (int64_t)(((pInfo)->clusterId << 32) | (pInfo)->nodeId)
void
syncUtilNodeInfo2EpSet
(
const
SNodeInfo
*
pInfo
,
SEpSet
*
pEpSet
);
bool
syncUtilNodeInfo2RaftId
(
const
SNodeInfo
*
pInfo
,
SyncGroupId
vgId
,
SRaftId
*
raftId
);
bool
syncUtilSameId
(
const
SRaftId
*
pId1
,
const
SRaftId
*
pId2
);
bool
syncUtilEmptyId
(
const
SRaftId
*
pId
);
int32_t
syncUtilElectRandomMS
(
int32_t
min
,
int32_t
max
);
int32_t
syncUtilQuorum
(
int32_t
replicaNum
);
cJSON
*
syncUtilRaftId2Json
(
const
SRaftId
*
p
);
const
char
*
syncStr
(
ESyncState
state
);
char
*
syncUtilPrintBin
(
char
*
ptr
,
uint32_t
len
);
char
*
syncUtilPrintBin2
(
char
*
ptr
,
uint32_t
len
);
void
syncUtilMsgHtoN
(
void
*
msg
);
void
syncUtilMsgNtoH
(
void
*
msg
);
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
);
bool
syncUtilUserRollback
(
tmsg_t
msgType
);
...
...
source/libs/sync/src/syncElection.c
浏览文件 @
ac7d250a
...
...
@@ -94,7 +94,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
voteGrantedUpdate
(
pSyncNode
->
pVotesGranted
,
pSyncNode
);
votesRespondUpdate
(
pSyncNode
->
pVotesRespond
,
pSyncNode
);
pSyncNode
->
quorum
=
syncUtilQuorum
(
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
);
pSyncNode
->
quorum
=
syncUtilQuorum
(
pSyncNode
->
raftCfg
.
cfg
.
replicaNum
);
syncNodeCandidate2Leader
(
pSyncNode
);
pSyncNode
->
pVotesGranted
->
toLeader
=
true
;
...
...
source/libs/sync/src/syncEnv.c
浏览文件 @
ac7d250a
...
...
@@ -115,7 +115,7 @@ void syncHbTimerDataRemove(int64_t rid) { taosRemoveRef(gHbDataRefId, rid); }
SSyncHbTimerData
*
syncHbTimerDataAcquire
(
int64_t
rid
)
{
SSyncHbTimerData
*
pData
=
taosAcquireRef
(
gHbDataRefId
,
rid
);
if
(
pData
==
NULL
)
{
s
Error
(
"failed to acquire hb-timer-data from refId:%"
PRId64
,
rid
);
s
Info
(
"failed to acquire hb-timer-data from refId:%"
PRId64
,
rid
);
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
}
...
...
source/libs/sync/src/syncIndexMgr.c
浏览文件 @
ac7d250a
...
...
@@ -64,10 +64,8 @@ void syncIndexMgrSetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, Sync
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr set index:%"
PRId64
" for %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
index
,
host
,
port
);
sError
(
"vgId:%d, indexmgr set index:%"
PRId64
" for dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
index
,
DID
(
pRaftId
),
CID
(
pRaftId
));
}
SSyncLogReplMgr
*
syncNodeGetLogReplMgr
(
SSyncNode
*
pNode
,
SRaftId
*
pRaftId
)
{
...
...
@@ -77,10 +75,7 @@ SSyncLogReplMgr *syncNodeGetLogReplMgr(SSyncNode *pNode, SRaftId *pRaftId) {
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr get replmgr from %s:%d failed"
,
pNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, indexmgr get replmgr from dnode:%d cluster:%d failed"
,
pNode
->
vgId
,
DID
(
pRaftId
),
CID
(
pRaftId
));
return
NULL
;
}
...
...
@@ -92,10 +87,8 @@ SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId)
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr get index from %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, indexmgr get index from dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
DID
(
pRaftId
),
CID
(
pRaftId
));
return
SYNC_INDEX_INVALID
;
}
...
...
@@ -107,11 +100,8 @@ void syncIndexMgrSetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId,
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr set start-time:%"
PRId64
" for %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
startTime
,
host
,
port
);
sError
(
"vgId:%d, indexmgr set start-time:%"
PRId64
" for dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
startTime
,
DID
(
pRaftId
),
CID
(
pRaftId
));
}
int64_t
syncIndexMgrGetStartTime
(
SSyncIndexMgr
*
pIndexMgr
,
const
SRaftId
*
pRaftId
)
{
...
...
@@ -122,10 +112,8 @@ int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftI
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr get start-time from %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, indexmgr get start-time from dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
DID
(
pRaftId
),
CID
(
pRaftId
));
return
-
1
;
}
...
...
@@ -137,10 +125,8 @@ void syncIndexMgrSetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, i
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr set recv-time:%"
PRId64
" for %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
recvTime
,
host
,
port
);
sError
(
"vgId:%d, indexmgr set recv-time:%"
PRId64
" for dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
recvTime
,
DID
(
pRaftId
),
CID
(
pRaftId
));
}
int64_t
syncIndexMgrGetRecvTime
(
SSyncIndexMgr
*
pIndexMgr
,
const
SRaftId
*
pRaftId
)
{
...
...
@@ -151,10 +137,8 @@ int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr get recv-time from %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, indexmgr get recv-time from dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
DID
(
pRaftId
),
CID
(
pRaftId
));
return
-
1
;
}
...
...
@@ -166,10 +150,8 @@ void syncIndexMgrSetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, SyncT
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr set term:%"
PRId64
" for %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
term
,
host
,
port
);
sError
(
"vgId:%d, indexmgr set term:%"
PRId64
" for dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
term
,
DID
(
pRaftId
),
CID
(
pRaftId
));
}
SyncTerm
syncIndexMgrGetTerm
(
SSyncIndexMgr
*
pIndexMgr
,
const
SRaftId
*
pRaftId
)
{
...
...
@@ -180,9 +162,7 @@ SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId) {
}
}
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
pRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, indexmgr get term from %s:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, indexmgr get term from dnode:%d cluster:%d failed"
,
pIndexMgr
->
pNode
->
vgId
,
DID
(
pRaftId
),
CID
(
pRaftId
));
return
-
1
;
}
source/libs/sync/src/syncMain.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/libs/sync/src/syncPipeline.c
浏览文件 @
ac7d250a
...
...
@@ -652,18 +652,15 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
SRaftId
destId
=
pMsg
->
srcId
;
ASSERT
(
pMgr
->
restored
==
false
);
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
if
(
pMgr
->
endIndex
==
0
)
{
ASSERT
(
pMgr
->
startIndex
==
0
);
ASSERT
(
pMgr
->
matchIndex
==
0
);
if
(
pMsg
->
matchIndex
<
0
)
{
pMgr
->
restored
=
true
;
sInfo
(
"vgId:%d, sync log repl mgr restored. peer:
%s
:%d (%"
PRIx64
"), mgr: rs(%d) [%"
PRId64
" %"
PRId64
sInfo
(
"vgId:%d, sync log repl mgr restored. peer:
dnode
:%d (%"
PRIx64
"), mgr: rs(%d) [%"
PRId64
" %"
PRId64
", %"
PRId64
"), buffer: [%"
PRId64
" %"
PRId64
" %"
PRId64
", %"
PRId64
")"
,
pNode
->
vgId
,
host
,
port
,
destId
.
addr
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pNode
->
vgId
,
DID
(
&
destId
)
,
destId
.
addr
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pBuf
->
startIndex
,
pBuf
->
commitIndex
,
pBuf
->
matchIndex
,
pBuf
->
endIndex
);
return
0
;
}
...
...
@@ -678,21 +675,21 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
if
(
pMsg
->
success
&&
pMsg
->
matchIndex
==
pMsg
->
lastSendIndex
)
{
pMgr
->
matchIndex
=
pMsg
->
matchIndex
;
pMgr
->
restored
=
true
;
sInfo
(
"vgId:%d, sync log repl mgr restored. peer:
%s
:%d (%"
PRIx64
"), mgr: rs(%d) [%"
PRId64
" %"
PRId64
sInfo
(
"vgId:%d, sync log repl mgr restored. peer:
dnode
:%d (%"
PRIx64
"), mgr: rs(%d) [%"
PRId64
" %"
PRId64
", %"
PRId64
"), buffer: [%"
PRId64
" %"
PRId64
" %"
PRId64
", %"
PRId64
")"
,
pNode
->
vgId
,
host
,
port
,
destId
.
addr
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pNode
->
vgId
,
DID
(
&
destId
)
,
destId
.
addr
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pBuf
->
startIndex
,
pBuf
->
commitIndex
,
pBuf
->
matchIndex
,
pBuf
->
endIndex
);
return
0
;
}
if
(
pMsg
->
success
==
false
&&
pMsg
->
matchIndex
>=
pMsg
->
lastSendIndex
)
{
sWarn
(
"vgId:%d, failed to rollback match index. peer:
%s
:%d, match index: %"
PRId64
", last sent: %"
PRId64
,
pNode
->
vgId
,
host
,
port
,
pMsg
->
matchIndex
,
pMsg
->
lastSendIndex
);
sWarn
(
"vgId:%d, failed to rollback match index. peer:
dnode
:%d, match index: %"
PRId64
", last sent: %"
PRId64
,
pNode
->
vgId
,
DID
(
&
destId
)
,
pMsg
->
matchIndex
,
pMsg
->
lastSendIndex
);
if
(
syncNodeStartSnapshot
(
pNode
,
&
destId
)
<
0
)
{
sError
(
"vgId:%d, failed to start snapshot for peer
%s:%d"
,
pNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, failed to start snapshot for peer
dnode:%d"
,
pNode
->
vgId
,
DID
(
&
destId
)
);
return
-
1
;
}
sInfo
(
"vgId:%d, snapshot replication to peer
%s:%d"
,
pNode
->
vgId
,
host
,
port
);
sInfo
(
"vgId:%d, snapshot replication to peer
dnode:%d"
,
pNode
->
vgId
,
DID
(
&
destId
)
);
return
0
;
}
}
...
...
@@ -707,10 +704,10 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
if
(
term
<
0
||
(
term
!=
pMsg
->
lastMatchTerm
&&
(
index
+
1
==
firstVer
||
index
==
firstVer
)))
{
ASSERT
(
term
>=
0
||
terrno
==
TSDB_CODE_WAL_LOG_NOT_EXIST
);
if
(
syncNodeStartSnapshot
(
pNode
,
&
destId
)
<
0
)
{
sError
(
"vgId:%d, failed to start snapshot for peer
%s:%d"
,
pNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, failed to start snapshot for peer
dnode:%d"
,
pNode
->
vgId
,
DID
(
&
destId
)
);
return
-
1
;
}
sInfo
(
"vgId:%d, snapshot replication to peer
%s:%d"
,
pNode
->
vgId
,
host
,
port
);
sInfo
(
"vgId:%d, snapshot replication to peer
dnode:%d"
,
pNode
->
vgId
,
DID
(
&
destId
)
);
return
0
;
}
...
...
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/libs/sync/src/syncRaftStore.c
浏览文件 @
ac7d250a
...
...
@@ -112,13 +112,6 @@ int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) {
cJSON_AddNumberToObject
(
pRoot
,
"vote_for_vgid"
,
pRaftStore
->
voteFor
.
vgId
);
uint64_t
u64
=
pRaftStore
->
voteFor
.
addr
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pRoot
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pRoot
,
"addr_port"
,
port
);
char
*
serialized
=
cJSON_Print
(
pRoot
);
int
len2
=
strlen
(
serialized
);
ASSERT
(
len2
<
len
);
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
ac7d250a
...
...
@@ -107,10 +107,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapsh
pMsg
=
rpcMsg
.
pCont
;
}
else
{
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pDestId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sNError
(
pSyncNode
,
"replicate to %s:%d error, next-index:%"
PRId64
,
host
,
port
,
nextIndex
);
sNError
(
pSyncNode
,
"replicate to dnode:%d error, next-index:%"
PRId64
,
DID
(
pDestId
),
nextIndex
);
return
-
1
;
}
}
...
...
@@ -171,10 +168,7 @@ int32_t syncNodeReplicateOld(SSyncNode* pSyncNode) {
SRaftId
*
pDestId
=
&
(
pSyncNode
->
peersId
[
i
]);
ret
=
syncNodeReplicateOne
(
pSyncNode
,
pDestId
,
true
);
if
(
ret
!=
0
)
{
char
host
[
64
];
int16_t
port
;
syncUtilU642Addr
(
pDestId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sError
(
"vgId:%d, do append entries error for %s:%d"
,
pSyncNode
->
vgId
,
host
,
port
);
sError
(
"vgId:%d, do append entries error for dnode:%d"
,
pSyncNode
->
vgId
,
DID
(
pDestId
));
}
}
...
...
@@ -183,7 +177,6 @@ int32_t syncNodeReplicateOld(SSyncNode* pSyncNode) {
int32_t
syncNodeSendAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntries
*
pMsg
=
pRpcMsg
->
pCont
;
int32_t
ret
=
0
;
pMsg
->
destId
=
*
destRaftId
;
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
pRpcMsg
);
return
0
;
...
...
@@ -229,11 +222,7 @@ int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* dest
if
(
syncNodeNeedSendAppendEntries
(
pSyncNode
,
destRaftId
,
pMsg
))
{
ret
=
syncNodeSendAppendEntries
(
pSyncNode
,
destRaftId
,
pRpcMsg
);
}
else
{
char
logBuf
[
128
];
char
host
[
64
];
int16_t
port
;
syncUtilU642Addr
(
destRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"do not repcate to %s:%d for index:%"
PRId64
,
host
,
port
,
pMsg
->
prevLogIndex
+
1
);
sNTrace
(
pSyncNode
,
"do not repcate to dnode:%d for index:%"
PRId64
,
DID
(
destRaftId
),
pMsg
->
prevLogIndex
+
1
);
rpcFreeCont
(
pRpcMsg
->
pCont
);
}
...
...
source/libs/sync/src/syncTimeout.c
浏览文件 @
ac7d250a
...
...
@@ -24,33 +24,35 @@
#include "syncUtil.h"
static
void
syncNodeCleanConfigIndex
(
SSyncNode
*
ths
)
{
#if 0
int32_t newArrIndex = 0;
SyncIndex newConfigIndexArr[MAX_CONFIG_INDEX_COUNT] = {0};
SSnapshot snapshot = {0};
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
if (snapshot.lastApplyIndex != SYNC_INDEX_INVALID) {
for
(
int32_t
i
=
0
;
i
<
ths
->
pRaftCfg
->
configIndexCount
;
++
i
)
{
if
(
ths
->
pRaftCfg
->
configIndexArr
[
i
]
<
snapshot
.
lastConfigIndex
)
{
for (int32_t i = 0; i < ths->
raftCfg.
configIndexCount; ++i) {
if (ths->
raftCfg.
configIndexArr[i] < snapshot.lastConfigIndex) {
// pass
} else {
// save
newConfigIndexArr
[
newArrIndex
]
=
ths
->
pRaftCfg
->
configIndexArr
[
i
];
newConfigIndexArr[newArrIndex] = ths->
raftCfg.
configIndexArr[i];
++newArrIndex;
}
}
int32_t
oldCnt
=
ths
->
pRaftCfg
->
configIndexCount
;
ths
->
pRaftCfg
->
configIndexCount
=
newArrIndex
;
memcpy
(
ths
->
pRaftCfg
->
configIndexArr
,
newConfigIndexArr
,
sizeof
(
newConfigIndexArr
));
int32_t oldCnt = ths->
raftCfg.
configIndexCount;
ths->
raftCfg.
configIndexCount = newArrIndex;
memcpy(ths->
raftCfg.
configIndexArr, newConfigIndexArr, sizeof(newConfigIndexArr));
int32_t
code
=
raftCfgPersist
(
ths
->
pRaftCfg
);
int32_t code =
syncWriteCfgFile(ths
);
if (code != 0) {
sNFatal(ths, "failed to persist cfg");
} else {
sNTrace
(
ths
,
"clean config index arr, old-cnt:%d, new-cnt:%d"
,
oldCnt
,
ths
->
pRaftCfg
->
configIndexCount
);
sNTrace(ths, "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt, ths->
raftCfg.
configIndexCount);
}
}
#endif
}
static
int32_t
syncNodeTimerRoutine
(
SSyncNode
*
ths
)
{
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/libs/sync/test/syncRaftCfgIndexTest.cpp
浏览文件 @
ac7d250a
...
...
@@ -51,26 +51,26 @@ SSyncCfg* createSyncCfg() {
const
char
*
pFile
=
"./raft_config_index.json"
;
void
test1
()
{
int32_t
code
=
raftCfgIndexCreateFile
(
pFile
);
ASSERT
(
code
==
0
);
//
int32_t code = raftCfgIndexCreateFile(pFile);
//
ASSERT(code == 0);
SRaftCfgIndex
*
pRaftCfgIndex
=
raftCfgIndexOpen
(
pFile
);
//
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
raftCfgIndexClose
(
pRaftCfgIndex
);
//
raftCfgIndexClose(pRaftCfgIndex);
}
void
test2
()
{
SRaftCfgIndex
*
pRaftCfgIndex
=
raftCfgIndexOpen
(
pFile
);
for
(
int
i
=
0
;
i
<
500
;
++
i
)
{
raftCfgIndexAddConfigIndex
(
pRaftCfgIndex
,
i
);
}
raftCfgIndexPersist
(
pRaftCfgIndex
);
raftCfgIndexClose
(
pRaftCfgIndex
);
//
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
//
for (int i = 0; i < 500; ++i) {
//
raftCfgIndexAddConfigIndex(pRaftCfgIndex, i);
//
}
//
raftCfgIndexPersist(pRaftCfgIndex);
//
raftCfgIndexClose(pRaftCfgIndex);
}
void
test3
()
{
SRaftCfgIndex
*
pRaftCfgIndex
=
raftCfgIndexOpen
(
pFile
);
raftCfgIndexClose
(
pRaftCfgIndex
);
//
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
//
raftCfgIndexClose(pRaftCfgIndex);
}
int
main
()
{
...
...
source/libs/sync/test/syncRaftCfgTest.cpp
浏览文件 @
ac7d250a
...
...
@@ -67,12 +67,12 @@ void test3() {
if
(
taosCheckExistFile
(
s
))
{
printf
(
"%s file: %s already exist!
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
}
else
{
SRaftCfgMeta
meta
;
meta
.
isStandBy
=
7
;
meta
.
snapshotStrategy
=
9
;
meta
.
batchSize
=
10
;
meta
.
lastConfigIndex
=
789
;
raftCfgCreateFile
(
pCfg
,
meta
,
s
);
//
SRaftCfgMeta meta;
//
meta.isStandBy = 7;
//
meta.snapshotStrategy = 9;
//
meta.batchSize = 10;
//
meta.lastConfigIndex = 789;
//
raftCfgCreateFile(pCfg, meta, s);
printf
(
"%s create json file: %s
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
}
...
...
@@ -80,37 +80,37 @@ void test3() {
}
void
test4
()
{
SRaftCfg
*
pCfg
=
raftCfgOpen
(
"./test3_raft_cfg.json"
);
assert
(
pCfg
!=
NULL
);
//
SRaftCfg* pCfg = raftCfgOpen("./test3_raft_cfg.json");
//
assert(pCfg != NULL);
int32_t
ret
=
raftCfgClose
(
pCfg
);
assert
(
ret
==
0
);
//
int32_t ret = raftCfgClose(pCfg);
//
assert(ret == 0);
}
void
test5
()
{
SRaftCfg
*
pCfg
=
raftCfgOpen
(
"./test3_raft_cfg.json"
);
assert
(
pCfg
!=
NULL
);
//
SRaftCfg* pCfg = raftCfgOpen("./test3_raft_cfg.json");
//
assert(pCfg != NULL);
pCfg
->
cfg
.
myIndex
=
taosGetTimestampSec
();
pCfg
->
isStandBy
+=
2
;
pCfg
->
snapshotStrategy
+=
3
;
pCfg
->
batchSize
+=
4
;
pCfg
->
lastConfigIndex
+=
1000
;
//
pCfg->cfg.myIndex = taosGetTimestampSec();
//
pCfg->isStandBy += 2;
//
pCfg->snapshotStrategy += 3;
//
pCfg->batchSize += 4;
//
pCfg->lastConfigIndex += 1000;
pCfg
->
configIndexCount
=
5
;
for
(
int
i
=
0
;
i
<
MAX_CONFIG_INDEX_COUNT
;
++
i
)
{
(
pCfg
->
configIndexArr
)[
i
]
=
-
1
;
}
for
(
int
i
=
0
;
i
<
pCfg
->
configIndexCount
;
++
i
)
{
(
pCfg
->
configIndexArr
)[
i
]
=
i
*
100
;
}
//
pCfg->configIndexCount = 5;
//
for (int i = 0; i < MAX_CONFIG_INDEX_COUNT; ++i) {
//
(pCfg->configIndexArr)[i] = -1;
//
}
//
for (int i = 0; i < pCfg->configIndexCount; ++i) {
//
(pCfg->configIndexArr)[i] = i * 100;
//
}
raftCfgPersist
(
pCfg
);
// //
raftCfgPersist(pCfg);
printf
(
"%s update json file: %s myIndex->%d
\n
"
,
(
char
*
)
__FUNCTION__
,
"./test3_raft_cfg.json"
,
pCfg
->
cfg
.
myIndex
);
//
printf("%s update json file: %s myIndex->%d \n", (char*)__FUNCTION__, "./test3_raft_cfg.json", pCfg->cfg.myIndex);
int32_t
ret
=
raftCfgClose
(
pCfg
);
assert
(
ret
==
0
);
//
int32_t ret = raftCfgClose(pCfg);
//
assert(ret == 0);
}
int
main
()
{
...
...
source/libs/sync/test/sync_test_lib/inc/syncTest.h
浏览文件 @
ac7d250a
...
...
@@ -474,6 +474,11 @@ void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg);
void
syncLocalCmdLog
(
const
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdLog2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
);
char
*
syncUtilPrintBin
(
char
*
ptr
,
uint32_t
len
);
char
*
syncUtilPrintBin2
(
char
*
ptr
,
uint32_t
len
);
void
syncUtilU642Addr
(
uint64_t
u64
,
char
*
host
,
int64_t
len
,
uint16_t
*
port
);
uint64_t
syncUtilAddr2U64
(
const
char
*
host
,
uint16_t
port
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/test/sync_test_lib/src/syncBatch.c
浏览文件 @
ac7d250a
...
...
@@ -311,7 +311,7 @@ cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) {
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
//
syncUtilU642Addr(u64, host, sizeof(host), &port);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
...
...
source/libs/sync/test/sync_test_lib/src/syncIO.c
浏览文件 @
ac7d250a
...
...
@@ -73,7 +73,7 @@ int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
int32_t
ret
=
0
;
{
syncUtilMsgNtoH
(
pMsg
->
pCont
);
//
syncUtilMsgNtoH(pMsg->pCont);
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==syncIOSendMsg== %s:%d msgType:%d"
,
pEpSet
->
eps
[
0
].
fqdn
,
pEpSet
->
eps
[
0
].
port
,
...
...
@@ -376,7 +376,7 @@ static void *syncIOConsumerFunc(void *param) {
}
static
void
syncIOProcessRequest
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
syncUtilMsgNtoH
(
pMsg
->
pCont
);
//
syncUtilMsgNtoH(pMsg->pCont);
syncRpcMsgLog2
((
char
*
)
"==syncIOProcessRequest=="
,
pMsg
);
SSyncIO
*
io
=
pParent
;
...
...
@@ -432,9 +432,9 @@ static void syncIOTickQ(void *param, void *tmrId) {
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
SRaftId
srcId
,
destId
;
srcId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
srcId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
srcId
.
vgId
=
-
1
;
destId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
destId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
destId
.
vgId
=
-
1
;
SyncPingReply
*
pMsg
=
syncPingReplyBuild2
(
&
srcId
,
&
destId
,
-
1
,
"syncIOTickQ"
);
...
...
@@ -454,9 +454,9 @@ static void syncIOTickPing(void *param, void *tmrId) {
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
SRaftId
srcId
,
destId
;
srcId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
srcId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
srcId
.
vgId
=
-
1
;
destId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
destId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
destId
.
vgId
=
-
1
;
SyncPing
*
pMsg
=
syncPingBuild2
(
&
srcId
,
&
destId
,
-
1
,
"syncIOTickPing"
);
// SyncPing *pMsg = syncPingBuild3(&srcId, &destId);
...
...
@@ -470,4 +470,68 @@ static void syncIOTickPing(void *param, void *tmrId) {
taosTmrReset
(
syncIOTickPing
,
io
->
pingTimerMS
,
io
,
io
->
timerMgr
,
&
io
->
pingTimer
);
}
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{}
\ No newline at end of file
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{}
void
syncUtilMsgNtoH
(
void
*
msg
)
{
SMsgHead
*
pHead
=
msg
;
pHead
->
contLen
=
ntohl
(
pHead
->
contLen
);
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
}
static
inline
bool
syncUtilCanPrint
(
char
c
)
{
if
(
c
>=
32
&&
c
<=
126
)
{
return
true
;
}
else
{
return
false
;
}
}
char
*
syncUtilPrintBin
(
char
*
ptr
,
uint32_t
len
)
{
int64_t
memLen
=
(
int64_t
)(
len
+
1
);
char
*
s
=
taosMemoryMalloc
(
memLen
);
ASSERT
(
s
!=
NULL
);
memset
(
s
,
0
,
len
+
1
);
memcpy
(
s
,
ptr
,
len
);
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
!
syncUtilCanPrint
(
s
[
i
]))
{
s
[
i
]
=
'.'
;
}
}
return
s
;
}
char
*
syncUtilPrintBin2
(
char
*
ptr
,
uint32_t
len
)
{
uint32_t
len2
=
len
*
4
+
1
;
char
*
s
=
taosMemoryMalloc
(
len2
);
ASSERT
(
s
!=
NULL
);
memset
(
s
,
0
,
len2
);
char
*
p
=
s
;
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
int32_t
n
=
sprintf
(
p
,
"%d,"
,
ptr
[
i
]);
p
+=
n
;
}
return
s
;
}
void
syncUtilU642Addr
(
uint64_t
u64
,
char
*
host
,
int64_t
len
,
uint16_t
*
port
)
{
uint32_t
hostU32
=
(
uint32_t
)((
u64
>>
32
)
&
0x00000000FFFFFFFF
);
struct
in_addr
addr
=
{.
s_addr
=
hostU32
};
taosInetNtoa
(
addr
,
host
,
len
);
*
port
=
(
uint16_t
)((
u64
&
0x00000000FFFF0000
)
>>
16
);
}
uint64_t
syncUtilAddr2U64
(
const
char
*
host
,
uint16_t
port
)
{
uint32_t
hostU32
=
taosGetIpv4FromFqdn
(
host
);
if
(
hostU32
==
(
uint32_t
)
-
1
)
{
sError
(
"failed to resolve ipv4 addr, host:%s"
,
host
);
terrno
=
TSDB_CODE_TSC_INVALID_FQDN
;
return
-
1
;
}
uint64_t
u64
=
(((
uint64_t
)
hostU32
)
<<
32
)
|
(((
uint32_t
)
port
)
<<
16
);
return
u64
;
}
\ No newline at end of file
source/libs/sync/test/sync_test_lib/src/syncIndexMgrDebug.c
浏览文件 @
ac7d250a
...
...
@@ -53,7 +53,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
for
(
int
i
=
0
;
i
<
pSyncIndexMgr
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicas
,
syncUtilRaftId2Json
(
&
(
*
(
pSyncIndexMgr
->
replicas
))[
i
]));
//
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i]));
}
{
...
...
@@ -76,7 +76,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
cJSON_AddItemToObject
(
pRoot
,
"privateTerm"
,
pIndex
);
}
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncIndexMgr
->
pSyncNode
);
//
snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
}
...
...
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
浏览文件 @
ac7d250a
...
...
@@ -23,7 +23,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
if
(
pSyncNode
!=
NULL
)
{
// init by SSyncInfo
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pSyncNode
->
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"SRaftCfg"
,
raftCfg2Json
(
pSyncNode
->
pRaftCfg
));
//
cJSON_AddItemToObject(pRoot, "SRaftCfg", raftCfg2Json(pSyncNode->pRaftCfg));
cJSON_AddStringToObject
(
pRoot
,
"path"
,
pSyncNode
->
path
);
cJSON_AddStringToObject
(
pRoot
,
"raftStorePath"
,
pSyncNode
->
raftStorePath
);
cJSON_AddStringToObject
(
pRoot
,
"configPath"
,
pSyncNode
->
configPath
);
...
...
@@ -44,8 +44,8 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
// init internal
cJSON
*
pMe
=
syncUtilNodeInfo2Json
(
&
pSyncNode
->
myNodeInfo
);
cJSON_AddItemToObject
(
pRoot
,
"myNodeInfo"
,
pMe
);
cJSON
*
pRaftId
=
syncUtilRaftId2Json
(
&
pSyncNode
->
myRaftId
);
cJSON_AddItemToObject
(
pRoot
,
"myRaftId"
,
pRaftId
);
//
cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId);
//
cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId);
cJSON_AddNumberToObject
(
pRoot
,
"peersNum"
,
pSyncNode
->
peersNum
);
cJSON
*
pPeers
=
cJSON_CreateArray
();
...
...
@@ -56,22 +56,22 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
cJSON
*
pPeersId
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"peersId"
,
pPeersId
);
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
cJSON_AddItemToArray
(
pPeersId
,
syncUtilRaftId2Json
(
&
pSyncNode
->
peersId
[
i
]));
//
cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i]));
}
cJSON_AddNumberToObject
(
pRoot
,
"replicaNum"
,
pSyncNode
->
replicaNum
);
cJSON
*
pReplicasId
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicasId"
,
pReplicasId
);
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicasId
,
syncUtilRaftId2Json
(
&
pSyncNode
->
replicasId
[
i
]));
//
cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i]));
}
// raft algorithm
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pFsm
);
cJSON_AddStringToObject
(
pRoot
,
"pFsm"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"quorum"
,
pSyncNode
->
quorum
);
cJSON
*
pLaderCache
=
syncUtilRaftId2Json
(
&
pSyncNode
->
leaderCache
);
cJSON_AddItemToObject
(
pRoot
,
"leaderCache"
,
pLaderCache
);
//
cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache);
//
cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache);
// life cycle
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pSyncNode
->
rid
);
...
...
@@ -200,8 +200,8 @@ inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
"r-num:%d, "
"lcfg:%"
PRId64
", chging:%d, rsto:%d"
,
pSyncNode
->
vgId
,
syncStr
(
pSyncNode
->
state
),
pSyncNode
->
pRaftStore
->
currentTerm
,
pSyncNode
->
commitIndex
,
logBeginIndex
,
logLastIndex
,
snapshot
.
lastApplyIndex
,
pSyncNode
->
pRaftCfg
->
isStandBy
,
pSyncNode
->
replicaNum
,
pSyncNode
->
pRaftCfg
->
lastConfigIndex
,
pSyncNode
->
changing
,
pSyncNode
->
restoreFinish
);
logBeginIndex
,
logLastIndex
,
snapshot
.
lastApplyIndex
,
pSyncNode
->
raftCfg
.
isStandBy
,
pSyncNode
->
replicaNum
,
pSyncNode
->
raftCfg
.
lastConfigIndex
,
pSyncNode
->
changing
,
pSyncNode
->
restoreFinish
);
return
s
;
}
...
...
@@ -243,7 +243,7 @@ int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
int32_t
syncNodePingAll
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
raftCfg
.
cfg
.
replicaNum
;
++
i
)
{
SRaftId
*
destId
=
&
(
pSyncNode
->
replicasId
[
i
]);
SyncPing
*
pMsg
=
syncPingBuild3
(
&
pSyncNode
->
myRaftId
,
destId
,
pSyncNode
->
vgId
);
ret
=
syncNodePing
(
pSyncNode
,
destId
,
pMsg
);
...
...
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
浏览文件 @
ac7d250a
...
...
@@ -181,7 +181,7 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
//
syncUtilU642Addr(u64, host, sizeof(host), &port);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
...
...
@@ -748,7 +748,7 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
lastConfigIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastConfigIndex"
,
u64buf
);
cJSON_AddItemToObject
(
pRoot
,
"lastConfig"
,
syncCfg2Json
((
SSyncCfg
*
)
&
(
pMsg
->
lastConfig
)));
//
cJSON_AddItemToObject(pRoot, "lastConfig", syncCfg2Json((SSyncCfg*)&(pMsg->lastConfig)));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
lastTerm
);
cJSON_AddStringToObject
(
pRoot
,
"lastTerm"
,
u64buf
);
...
...
source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c
浏览文件 @
ac7d250a
...
...
@@ -17,18 +17,19 @@
#include "syncTest.h"
char
*
syncCfg2Str
(
SSyncCfg
*
pSyncCfg
)
{
cJSON
*
pJson
=
syncCfg2Json
(
pSyncCfg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
// cJSON *pJson = syncCfg2Json(pSyncCfg);
// char *serialized = cJSON_Print(pJson);
// cJSON_Delete(pJson);
// return serialized;
return
""
;
}
int32_t
syncCfgFromStr
(
const
char
*
s
,
SSyncCfg
*
pSyncCfg
)
{
cJSON
*
pRoot
=
cJSON_Parse
(
s
);
ASSERT
(
pRoot
!=
NULL
);
int32_t
ret
=
syncCfgFromJson
(
pRoot
,
pSyncCfg
);
ASSERT
(
ret
==
0
);
//
int32_t ret = syncCfgFromJson(pRoot, pSyncCfg);
//
ASSERT(ret == 0);
cJSON_Delete
(
pRoot
);
return
0
;
...
...
source/libs/sync/test/sync_test_lib/src/syncUtilDebug.c
浏览文件 @
ac7d250a
...
...
@@ -29,8 +29,9 @@ cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p) {
}
char
*
syncUtilRaftId2Str
(
const
SRaftId
*
p
)
{
cJSON
*
pJson
=
syncUtilRaftId2Json
(
p
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
// cJSON* pJson = syncUtilRaftId2Json(p);
// char* serialized = cJSON_Print(pJson);
// cJSON_Delete(pJson);
// return serialized;
return
""
;
}
source/libs/sync/test/sync_test_lib/src/syncVoteMgrDebug.c
浏览文件 @
ac7d250a
...
...
@@ -25,7 +25,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
for
(
int32_t
i
=
0
;
i
<
pVotesGranted
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicas
,
syncUtilRaftId2Json
(
&
(
*
(
pVotesGranted
->
replicas
))[
i
]));
//
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i]));
}
int32_t
*
arr
=
(
int32_t
*
)
taosMemoryMalloc
(
sizeof
(
int32_t
)
*
pVotesGranted
->
replicaNum
);
for
(
int32_t
i
=
0
;
i
<
pVotesGranted
->
replicaNum
;
++
i
)
{
...
...
@@ -40,7 +40,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"quorum"
,
pVotesGranted
->
quorum
);
cJSON_AddNumberToObject
(
pRoot
,
"toLeader"
,
pVotesGranted
->
toLeader
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesGranted
->
p
Sync
Node
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesGranted
->
pNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
bool
majority
=
voteGrantedMajority
(
pVotesGranted
);
...
...
@@ -68,7 +68,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
for
(
int32_t
i
=
0
;
i
<
pVotesRespond
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicas
,
syncUtilRaftId2Json
(
&
(
*
(
pVotesRespond
->
replicas
))[
i
]));
//
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i]));
}
int32_t
respondNum
=
0
;
int32_t
*
arr
=
(
int32_t
*
)
taosMemoryMalloc
(
sizeof
(
int32_t
)
*
pVotesRespond
->
replicaNum
);
...
...
@@ -85,7 +85,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pVotesRespond
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesRespond
->
p
Sync
Node
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesRespond
->
pNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
}
...
...
source/libs/transport/src/tmsgcb.c
浏览文件 @
ac7d250a
...
...
@@ -24,7 +24,6 @@ static SMsgCb defaultMsgCb;
void
tmsgSetDefault
(
const
SMsgCb
*
msgcb
)
{
defaultMsgCb
=
*
msgcb
;
}
int32_t
tmsgPutToQueue
(
const
SMsgCb
*
msgcb
,
EQueueType
qtype
,
SRpcMsg
*
pMsg
)
{
ASSERT
(
msgcb
!=
NULL
);
int32_t
code
=
(
*
msgcb
->
putToQueueFp
)(
msgcb
->
mgmt
,
qtype
,
pMsg
);
if
(
code
!=
0
)
{
rpcFreeCont
(
pMsg
->
pCont
);
...
...
@@ -59,3 +58,7 @@ void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg) { (*defaultMsgCb.registerBrokenLin
void
tmsgReleaseHandle
(
SRpcHandleInfo
*
pHandle
,
int8_t
type
)
{
(
*
defaultMsgCb
.
releaseHandleFp
)(
pHandle
,
type
);
}
void
tmsgReportStartup
(
const
char
*
name
,
const
char
*
desc
)
{
(
*
defaultMsgCb
.
reportStartupFp
)(
name
,
desc
);
}
int32_t
tmsgUpdateDnodeInfo
(
int32_t
*
dnodeId
,
int64_t
*
clusterId
,
char
*
fqdn
,
uint16_t
*
port
)
{
return
(
*
defaultMsgCb
.
updateDnodeInfoFp
)(
defaultMsgCb
.
data
,
dnodeId
,
clusterId
,
fqdn
,
port
);
}
source/libs/transport/src/trans.c
浏览文件 @
ac7d250a
...
...
@@ -160,21 +160,12 @@ int rpcSendRecv(void* shandle, SEpSet* pEpSet, SRpcMsg* pMsg, SRpcMsg* pRsp) {
int
rpcSendResponse
(
const
SRpcMsg
*
pMsg
)
{
return
transSendResponse
(
pMsg
);
}
void
rpcRefHandle
(
void
*
handle
,
int8_t
type
)
{
assert
(
type
==
TAOS_CONN_SERVER
||
type
==
TAOS_CONN_CLIENT
);
(
*
taosRefHandle
[
type
])(
handle
);
}
void
rpcRefHandle
(
void
*
handle
,
int8_t
type
)
{
(
*
taosRefHandle
[
type
])(
handle
);
}
void
rpcUnrefHandle
(
void
*
handle
,
int8_t
type
)
{
assert
(
type
==
TAOS_CONN_SERVER
||
type
==
TAOS_CONN_CLIENT
);
(
*
taosUnRefHandle
[
type
])(
handle
);
}
void
rpcUnrefHandle
(
void
*
handle
,
int8_t
type
)
{
(
*
taosUnRefHandle
[
type
])(
handle
);
}
int
rpcRegisterBrokenLinkArg
(
SRpcMsg
*
msg
)
{
return
transRegisterMsg
(
msg
);
}
int
rpcReleaseHandle
(
void
*
handle
,
int8_t
type
)
{
assert
(
type
==
TAOS_CONN_SERVER
||
type
==
TAOS_CONN_CLIENT
);
return
(
*
transReleaseHandle
[
type
])(
handle
);
}
int
rpcReleaseHandle
(
void
*
handle
,
int8_t
type
)
{
return
(
*
transReleaseHandle
[
type
])(
handle
);
}
int
rpcSetDefaultAddr
(
void
*
thandle
,
const
char
*
ip
,
const
char
*
fqdn
)
{
// later
...
...
source/libs/transport/src/transCli.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/libs/transport/src/transComm.c
浏览文件 @
ac7d250a
...
...
@@ -134,7 +134,9 @@ int transDumpFromBuffer(SConnBuffer* connBuf, char** buf) {
if
(
total
>=
HEADSIZE
&&
!
p
->
invalid
)
{
*
buf
=
taosMemoryCalloc
(
1
,
total
);
memcpy
(
*
buf
,
p
->
buf
,
total
);
transResetBuffer
(
connBuf
);
if
(
transResetBuffer
(
connBuf
)
<
0
)
{
return
-
1
;
}
}
else
{
total
=
-
1
;
}
...
...
@@ -154,7 +156,8 @@ int transResetBuffer(SConnBuffer* connBuf) {
p
->
total
=
0
;
p
->
len
=
0
;
}
else
{
assert
(
0
);
ASSERTS
(
0
,
"invalid read from sock buf"
);
return
-
1
;
}
return
0
;
}
...
...
source/libs/transport/src/transSvr.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/os/src/osFile.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/talgo.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/tbuffer.c
已删除
100644 → 0
浏览文件 @
38d1e868
此差异已折叠。
点击以展开。
source/util/src/tcompare.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/tcompression.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/tdigest.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/terror.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/texception.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/tlosertree.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/tpagedbuf.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/trbtree.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/tref.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/ttimer.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
source/util/src/tutil.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
tests/parallel_test/cases.task
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
tests/pytest/auto_crash_gen.py
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
tests/pytest/auto_crash_gen_valgrind.py
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
tests/pytest/auto_crash_gen_valgrind_cluster.py
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
tests/script/tmp/data.sim
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
tests/script/tsim/insert/insert_select.sim
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
tests/system-test/2-query/blockSMA.py
0 → 100644
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
utils/tsim/inc/simInt.h
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
utils/tsim/src/simSystem.c
浏览文件 @
ac7d250a
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录