Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
75cad6e3
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22019
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看板
提交
75cad6e3
编写于
4月 27, 2022
作者:
haoranc
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of github.com:taosdata/TDengine into test/chr/TD-14699
上级
b5246114
eba09ac3
变更
52
显示空白变更内容
内联
并排
Showing
52 changed file
with
793 addition
and
3721 deletion
+793
-3721
include/common/tmsg.h
include/common/tmsg.h
+2
-1
include/common/tmsgdef.h
include/common/tmsgdef.h
+5
-4
include/libs/executor/executor.h
include/libs/executor/executor.h
+1
-0
include/os/osSocket.h
include/os/osSocket.h
+87
-84
include/util/taoserror.h
include/util/taoserror.h
+7
-8
include/util/tarray.h
include/util/tarray.h
+2
-1
include/util/tdef.h
include/util/tdef.h
+1
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+0
-1
source/client/src/tmq.c
source/client/src/tmq.c
+5
-2
source/common/src/tmsg.c
source/common/src/tmsg.c
+5
-0
source/dnode/mgmt/implement/src/dmEps.c
source/dnode/mgmt/implement/src/dmEps.c
+12
-8
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+0
-1
source/dnode/mnode/impl/inc/mndConsumer.h
source/dnode/mnode/impl/inc/mndConsumer.h
+0
-2
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+14
-0
source/dnode/mnode/impl/src/mndConsumer.c
source/dnode/mnode/impl/src/mndConsumer.c
+189
-6
source/dnode/mnode/impl/src/mndDef.c
source/dnode/mnode/impl/src/mndDef.c
+43
-1
source/dnode/mnode/impl/src/mndInfoSchema.c
source/dnode/mnode/impl/src/mndInfoSchema.c
+1
-20
source/dnode/mnode/impl/src/mndPerfSchema.c
source/dnode/mnode/impl/src/mndPerfSchema.c
+11
-2
source/dnode/mnode/impl/src/mndProfile.c
source/dnode/mnode/impl/src/mndProfile.c
+1
-1
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+2
-2
source/dnode/mnode/impl/src/mndTopic.c
source/dnode/mnode/impl/src/mndTopic.c
+1
-1
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+12
-16
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+2
-3
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+1
-2
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+13
-18
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+37
-98
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+0
-1
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+1
-328
source/dnode/vnode/src/tsdb/tsdbCompact.c
source/dnode/vnode/src/tsdb/tsdbCompact.c
+0
-533
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+1
-314
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+1
-266
source/dnode/vnode/src/tsdb/tsdbMain.c
source/dnode/vnode/src/tsdb/tsdbMain.c
+0
-1105
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+1
-621
source/dnode/vnode/src/tsdb/tsdbOpen.c
source/dnode/vnode/src/tsdb/tsdbOpen.c
+89
-0
source/dnode/vnode/src/vnd/vnodeCfg.c
source/dnode/vnode/src/vnd/vnodeCfg.c
+0
-8
source/dnode/vnode/src/vnd/vnodeQuery.c
source/dnode/vnode/src/vnd/vnodeQuery.c
+10
-0
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+1
-1
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-1
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+43
-44
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+85
-20
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+2
-0
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+11
-1
source/os/src/osSocket.c
source/os/src/osSocket.c
+43
-15
source/util/src/tarray.c
source/util/src/tarray.c
+19
-0
source/util/src/terror.c
source/util/src/terror.c
+7
-2
tests/script/general/user/authority.sim
tests/script/general/user/authority.sim
+0
-66
tests/script/general/user/user_create.sim
tests/script/general/user/user_create.sim
+0
-84
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+3
-0
tests/script/tsim/user/pass_alter.sim
tests/script/tsim/user/pass_alter.sim
+9
-11
tests/script/tsim/user/pass_len.sim
tests/script/tsim/user/pass_len.sim
+3
-4
tests/script/tsim/user/user_len.sim
tests/script/tsim/user/user_len.sim
+8
-13
未找到文件。
include/common/tmsg.h
浏览文件 @
75cad6e3
...
@@ -438,6 +438,7 @@ typedef struct {
...
@@ -438,6 +438,7 @@ typedef struct {
int32_t
tSerializeSGetUserAuthRsp
(
void
*
buf
,
int32_t
bufLen
,
SGetUserAuthRsp
*
pRsp
);
int32_t
tSerializeSGetUserAuthRsp
(
void
*
buf
,
int32_t
bufLen
,
SGetUserAuthRsp
*
pRsp
);
int32_t
tDeserializeSGetUserAuthRsp
(
void
*
buf
,
int32_t
bufLen
,
SGetUserAuthRsp
*
pRsp
);
int32_t
tDeserializeSGetUserAuthRsp
(
void
*
buf
,
int32_t
bufLen
,
SGetUserAuthRsp
*
pRsp
);
void
tFreeSGetUserAuthRsp
(
SGetUserAuthRsp
*
pRsp
);
typedef
struct
{
typedef
struct
{
int16_t
colId
;
// column id
int16_t
colId
;
// column id
...
@@ -1332,7 +1333,7 @@ int32_t tDeserializeSCMCreateTopicRsp(void* buf, int32_t bufLen, SCMCreateTopicR
...
@@ -1332,7 +1333,7 @@ int32_t tDeserializeSCMCreateTopicRsp(void* buf, int32_t bufLen, SCMCreateTopicR
typedef
struct
{
typedef
struct
{
int64_t
consumerId
;
int64_t
consumerId
;
}
SMqConsumerLostMsg
;
}
SMqConsumerLostMsg
,
SMqConsumerRecoverMsg
;
typedef
struct
{
typedef
struct
{
int64_t
consumerId
;
int64_t
consumerId
;
...
...
include/common/tmsgdef.h
浏览文件 @
75cad6e3
...
@@ -145,10 +145,11 @@ enum {
...
@@ -145,10 +145,11 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_TOPIC
,
"mnode-alter-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_TOPIC
,
"mnode-alter-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_TOPIC
,
"mnode-drop-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_TOPIC
,
"mnode-drop-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SUBSCRIBE
,
"mnode-subscribe"
,
SCMSubscribeReq
,
SCMSubscribeRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SUBSCRIBE
,
"mnode-subscribe"
,
SCMSubscribeReq
,
SCMSubscribeRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_ASK_EP
,
"mnode-mq-ask-ep"
,
SMqAskEpReq
,
SMqAskEpReq
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_ASK_EP
,
"mnode-mq-ask-ep"
,
SMqAskEpReq
,
SMqAskEpRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_TIMER
,
"mnode-mq-tmr"
,
SMTimerReq
,
SMTimerReq
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_TIMER
,
"mnode-mq-tmr"
,
SMTimerReq
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_CONSUMER_LOST
,
"mnode-mq-consumer-lost"
,
SMTimerReq
,
SMTimerReq
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_CONSUMER_LOST
,
"mnode-mq-consumer-lost"
,
SMqConsumerLostMsg
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_DO_REBALANCE
,
"mnode-mq-do-rebalance"
,
SMqDoRebalanceMsg
,
SMqDoRebalanceMsg
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_CONSUMER_RECOVER
,
"mnode-mq-consumer-recover"
,
SMqConsumerRecoverMsg
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_DO_REBALANCE
,
"mnode-mq-do-rebalance"
,
SMqDoRebalanceMsg
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_COMMIT_OFFSET
,
"mnode-mq-commit-offset"
,
SMqCMCommitOffsetReq
,
SMqCMCommitOffsetRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_COMMIT_OFFSET
,
"mnode-mq-commit-offset"
,
SMqCMCommitOffsetReq
,
SMqCMCommitOffsetRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_STREAM
,
"mnode-create-stream"
,
SCMCreateStreamReq
,
SCMCreateStreamRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_STREAM
,
"mnode-create-stream"
,
SCMCreateStreamReq
,
SCMCreateStreamRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_STREAM
,
"mnode-alter-stream"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_STREAM
,
"mnode-alter-stream"
,
NULL
,
NULL
)
...
...
include/libs/executor/executor.h
浏览文件 @
75cad6e3
...
@@ -32,6 +32,7 @@ typedef struct SReadHandle {
...
@@ -32,6 +32,7 @@ typedef struct SReadHandle {
void
*
reader
;
void
*
reader
;
void
*
meta
;
void
*
meta
;
void
*
config
;
void
*
config
;
void
*
vnode
;
}
SReadHandle
;
}
SReadHandle
;
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
...
...
include/os/osSocket.h
浏览文件 @
75cad6e3
...
@@ -19,53 +19,53 @@
...
@@ -19,53 +19,53 @@
// If the error is in a third-party library, place this header file under the third-party library header file.
// If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section.
// When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC
#ifndef ALLOW_FORBID_FUNC
#define socket
SOCKET_FUNC_TAOS_FORBID
#define socket
SOCKET_FUNC_TAOS_FORBID
#define bind
BIND_FUNC_TAOS_FORBID
#define bind
BIND_FUNC_TAOS_FORBID
#define listen
LISTEN_FUNC_TAOS_FORBID
#define listen
LISTEN_FUNC_TAOS_FORBID
#define accept
ACCEPT_FUNC_TAOS_FORBID
#define accept
ACCEPT_FUNC_TAOS_FORBID
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
#define epoll_ctl
EPOLL_CTL_FUNC_TAOS_FORBID
#define epoll_ctl
EPOLL_CTL_FUNC_TAOS_FORBID
#define epoll_wait
EPOLL_WAIT_FUNC_TAOS_FORBID
#define epoll_wait
EPOLL_WAIT_FUNC_TAOS_FORBID
#define inet_addr
INET_ADDR_FUNC_TAOS_FORBID
#define inet_addr
INET_ADDR_FUNC_TAOS_FORBID
#define inet_ntoa
INET_NTOA_FUNC_TAOS_FORBID
#define inet_ntoa
INET_NTOA_FUNC_TAOS_FORBID
#endif
#endif
#if defined(WINDOWS)
#if defined(WINDOWS)
#if BYTE_ORDER == LITTLE_ENDIAN
#if BYTE_ORDER == LITTLE_ENDIAN
#include <stdlib.h>
#include <stdlib.h>
#define htobe16(x) _byteswap_ushort(x)
#define htobe16(x) _byteswap_ushort(x)
#define htole16(x) (x)
#define htole16(x) (x)
#define be16toh(x) _byteswap_ushort(x)
#define be16toh(x) _byteswap_ushort(x)
#define le16toh(x) (x)
#define le16toh(x) (x)
#define htobe32(x) _byteswap_ulong(x)
#define htobe32(x) _byteswap_ulong(x)
#define htole32(x) (x)
#define htole32(x) (x)
#define be32toh(x) _byteswap_ulong(x)
#define be32toh(x) _byteswap_ulong(x)
#define le32toh(x) (x)
#define le32toh(x) (x)
#define htobe64(x) _byteswap_uint64(x)
#define htobe64(x) _byteswap_uint64(x)
#define htole64(x) (x)
#define htole64(x) (x)
#define be64toh(x) _byteswap_uint64(x)
#define be64toh(x) _byteswap_uint64(x)
#define le64toh(x) (x)
#define le64toh(x) (x)
#else
#else
#error byte order not supported
#error byte order not supported
#endif
#endif
#define __BYTE_ORDER BYTE_ORDER
#define __BYTE_ORDER BYTE_ORDER
#define __BIG_ENDIAN BIG_ENDIAN
#define __BIG_ENDIAN BIG_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#define __PDP_ENDIAN PDP_ENDIAN
#define __PDP_ENDIAN PDP_ENDIAN
#else
#else
#include <netinet/in.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/socket.h>
#if defined(_TD_DARWIN_64)
#if defined(_TD_DARWIN_64)
#include <osEok.h>
#include <osEok.h>
#else
#else
#include <netinet/in.h>
#include <netinet/in.h>
#include <sys/epoll.h>
#include <sys/epoll.h>
#endif
#endif
#endif
#endif
#ifdef __cplusplus
#ifdef __cplusplus
...
@@ -73,24 +73,24 @@ extern "C" {
...
@@ -73,24 +73,24 @@ extern "C" {
#endif
#endif
#if defined(WINDOWS)
#if defined(WINDOWS)
typedef
int
socklen_t
;
typedef
int
socklen_t
;
#define TAOS_EPOLL_WAIT_TIME 100
#define TAOS_EPOLL_WAIT_TIME 100
typedef
SOCKET
eventfd_t
;
typedef
SOCKET
eventfd_t
;
#define eventfd(a, b)
-1
#define eventfd(a, b)
-1
#define EpollClose(pollFd) epoll_close(pollFd)
#define EpollClose(pollFd) epoll_close(pollFd)
#ifndef EPOLLWAKEUP
#ifndef EPOLLWAKEUP
#define EPOLLWAKEUP (1u << 29)
#define EPOLLWAKEUP (1u << 29)
#endif
#endif
#elif defined(_TD_DARWIN_64)
#elif defined(_TD_DARWIN_64)
#define TAOS_EPOLL_WAIT_TIME 500
#define TAOS_EPOLL_WAIT_TIME 500
typedef
int32_t
SOCKET
;
typedef
int32_t
SOCKET
;
typedef
SOCKET
EpollFd
;
typedef
SOCKET
EpollFd
;
#define EpollClose(pollFd)
epoll_close(pollFd)
#define EpollClose(pollFd)
epoll_close(pollFd)
#else
#else
#define TAOS_EPOLL_WAIT_TIME 500
#define TAOS_EPOLL_WAIT_TIME 500
typedef
int32_t
SOCKET
;
typedef
int32_t
SOCKET
;
typedef
SOCKET
EpollFd
;
typedef
SOCKET
EpollFd
;
#define EpollClose(pollFd)
taosCloseSocket(pollFd)
#define EpollClose(pollFd)
taosCloseSocket(pollFd)
#endif
#endif
#if defined(_TD_DARWIN_64)
#if defined(_TD_DARWIN_64)
...
@@ -128,16 +128,17 @@ typedef struct TdSocket {
...
@@ -128,16 +128,17 @@ typedef struct TdSocket {
#endif
#endif
int
refId
;
int
refId
;
SocketFd
fd
;
SocketFd
fd
;
}
*
TdSocketPtr
,
TdSocket
;
}
*
TdSocketPtr
,
TdSocket
;
typedef
struct
TdSocketServer
*
TdSocketServerPtr
;
typedef
struct
TdSocketServer
*
TdSocketServerPtr
;
typedef
struct
TdSocket
*
TdSocketPtr
;
typedef
struct
TdSocket
*
TdSocketPtr
;
typedef
struct
TdEpoll
*
TdEpollPtr
;
typedef
struct
TdEpoll
*
TdEpollPtr
;
int32_t
taosSendto
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
,
unsigned
int
flags
,
const
struct
sockaddr
*
to
,
int
tolen
);
int32_t
taosSendto
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
,
unsigned
int
flags
,
const
struct
sockaddr
*
to
,
int
tolen
);
int32_t
taosWriteSocket
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
);
int32_t
taosWriteSocket
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
);
int32_t
taosReadSocket
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
);
int32_t
taosReadSocket
(
TdSocketPtr
pSocket
,
void
*
msg
,
int
len
);
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
);
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
);
int32_t
taosCloseSocketNoCheck1
(
SocketFd
fd
);
int32_t
taosCloseSocketNoCheck1
(
SocketFd
fd
);
int32_t
taosCloseSocket
(
TdSocketPtr
*
ppSocket
);
int32_t
taosCloseSocket
(
TdSocketPtr
*
ppSocket
);
int32_t
taosCloseSocketServer
(
TdSocketServerPtr
*
ppSocketServer
);
int32_t
taosCloseSocketServer
(
TdSocketServerPtr
*
ppSocketServer
);
...
@@ -156,13 +157,15 @@ int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
...
@@ -156,13 +157,15 @@ int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
int64_t
taosCopyFds
(
TdSocketPtr
pSrcSocket
,
TdSocketPtr
pDestSocket
,
int64_t
len
);
int64_t
taosCopyFds
(
TdSocketPtr
pSrcSocket
,
TdSocketPtr
pDestSocket
,
int64_t
len
);
void
taosWinSocketInit
();
void
taosWinSocketInit
();
int
taosCreateSocketWithTimeOutOpt
(
uint32_t
conn_timeout_sec
);
TdSocketPtr
taosOpenUdpSocket
(
uint32_t
localIp
,
uint16_t
localPort
);
TdSocketPtr
taosOpenUdpSocket
(
uint32_t
localIp
,
uint16_t
localPort
);
TdSocketPtr
taosOpenTcpClientSocket
(
uint32_t
ip
,
uint16_t
port
,
uint32_t
localIp
);
TdSocketPtr
taosOpenTcpClientSocket
(
uint32_t
ip
,
uint16_t
port
,
uint32_t
localIp
);
TdSocketServerPtr
taosOpenTcpServerSocket
(
uint32_t
ip
,
uint16_t
port
);
TdSocketServerPtr
taosOpenTcpServerSocket
(
uint32_t
ip
,
uint16_t
port
);
int32_t
taosKeepTcpAlive
(
TdSocketPtr
pSocket
);
int32_t
taosKeepTcpAlive
(
TdSocketPtr
pSocket
);
TdSocketPtr
taosAcceptTcpConnectSocket
(
TdSocketServerPtr
pServerSocket
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
);
TdSocketPtr
taosAcceptTcpConnectSocket
(
TdSocketServerPtr
pServerSocket
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
);
int32_t
taosGetSocketName
(
TdSocketPtr
pSocket
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
);
int32_t
taosGetSocketName
(
TdSocketPtr
pSocket
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
);
void
taosBlockSIGPIPE
();
void
taosBlockSIGPIPE
();
uint32_t
taosGetIpv4FromFqdn
(
const
char
*
);
uint32_t
taosGetIpv4FromFqdn
(
const
char
*
);
...
...
include/util/taoserror.h
浏览文件 @
75cad6e3
...
@@ -268,14 +268,13 @@ int32_t* taosGetErrno();
...
@@ -268,14 +268,13 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_TOPIC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E1)
#define TSDB_CODE_MND_TOPIC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E1)
#define TSDB_CODE_MND_TOO_MANY_TOPICS TAOS_DEF_ERROR_CODE(0, 0x03E2)
#define TSDB_CODE_MND_TOO_MANY_TOPICS TAOS_DEF_ERROR_CODE(0, 0x03E2)
#define TSDB_CODE_MND_INVALID_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E3)
#define TSDB_CODE_MND_INVALID_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E3)
#define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x03E4)
#define TSDB_CODE_MND_INVALID_TOPIC_QUERY TAOS_DEF_ERROR_CODE(0, 0x03E4)
#define TSDB_CODE_MND_TOPIC_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03E5)
#define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x03E5)
#define TSDB_CODE_MND_NAME_CONFLICT_WITH_STB TAOS_DEF_ERROR_CODE(0, 0x03E6)
#define TSDB_CODE_MND_CONSUMER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E6)
#define TSDB_CODE_MND_CONSUMER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E7)
#define TSDB_CODE_MND_TOPIC_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03E7)
#define TSDB_CODE_MND_UNSUPPORTED_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E8)
#define TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E8)
#define TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E9)
#define TSDB_CODE_MND_OFFSET_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E9)
#define TSDB_CODE_MND_OFFSET_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03EA)
#define TSDB_CODE_MND_CONSUMER_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x03EA)
#define TSDB_CODE_MND_CONSUMER_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x03EB)
// mnode-stream
// mnode-stream
#define TSDB_CODE_MND_STREAM_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F0)
#define TSDB_CODE_MND_STREAM_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F0)
...
...
include/util/tarray.h
浏览文件 @
75cad6e3
...
@@ -205,7 +205,6 @@ SArray* taosArrayDup(const SArray* pSrc);
...
@@ -205,7 +205,6 @@ SArray* taosArrayDup(const SArray* pSrc);
*/
*/
SArray
*
taosArrayDeepCopy
(
const
SArray
*
pSrc
,
FCopy
deepCopy
);
SArray
*
taosArrayDeepCopy
(
const
SArray
*
pSrc
,
FCopy
deepCopy
);
/**
/**
* clear the array (remove all element)
* clear the array (remove all element)
* @param pArray
* @param pArray
...
@@ -272,6 +271,8 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
...
@@ -272,6 +271,8 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
int32_t
taosEncodeArray
(
void
**
buf
,
const
SArray
*
pArray
,
FEncode
encode
);
int32_t
taosEncodeArray
(
void
**
buf
,
const
SArray
*
pArray
,
FEncode
encode
);
void
*
taosDecodeArray
(
const
void
*
buf
,
SArray
**
pArray
,
FDecode
decode
,
int32_t
dataSz
);
void
*
taosDecodeArray
(
const
void
*
buf
,
SArray
**
pArray
,
FDecode
decode
,
int32_t
dataSz
);
char
*
taosShowStrArray
(
const
SArray
*
pArray
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
include/util/tdef.h
浏览文件 @
75cad6e3
...
@@ -131,6 +131,7 @@ extern const int32_t TYPE_BYTES[15];
...
@@ -131,6 +131,7 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_PERFS_TABLE_TOPICS "topics"
#define TSDB_PERFS_TABLE_TOPICS "topics"
#define TSDB_PERFS_TABLE_CONSUMERS "consumers"
#define TSDB_PERFS_TABLE_CONSUMERS "consumers"
#define TSDB_PERFS_TABLE_SUBSCRIPTIONS "subscriptions"
#define TSDB_PERFS_TABLE_SUBSCRIPTIONS "subscriptions"
#define TSDB_PERFS_TABLE_OFFSETS "offsets"
#define TSDB_INDEX_TYPE_SMA "SMA"
#define TSDB_INDEX_TYPE_SMA "SMA"
#define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT"
#define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT"
...
...
source/client/src/clientImpl.c
浏览文件 @
75cad6e3
...
@@ -245,7 +245,6 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
...
@@ -245,7 +245,6 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
ASSERT
(
pSchema
!=
NULL
&&
numOfCols
>
0
);
ASSERT
(
pSchema
!=
NULL
&&
numOfCols
>
0
);
pResInfo
->
numOfCols
=
numOfCols
;
pResInfo
->
numOfCols
=
numOfCols
;
// TODO handle memory leak
if
(
pResInfo
->
fields
!=
NULL
)
{
if
(
pResInfo
->
fields
!=
NULL
)
{
taosMemoryFree
(
pResInfo
->
fields
);
taosMemoryFree
(
pResInfo
->
fields
);
}
}
...
...
source/client/src/tmq.c
浏览文件 @
75cad6e3
...
@@ -666,7 +666,6 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
...
@@ -666,7 +666,6 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
code
=
param
.
rspErr
;
code
=
param
.
rspErr
;
if
(
code
!=
0
)
goto
FAIL
;
if
(
code
!=
0
)
goto
FAIL
;
// TODO: add max retry cnt
while
(
TSDB_CODE_MND_CONSUMER_NOT_READY
==
tmqAskEp
(
tmq
,
false
))
{
while
(
TSDB_CODE_MND_CONSUMER_NOT_READY
==
tmqAskEp
(
tmq
,
false
))
{
tscDebug
(
"not ready, retry"
);
tscDebug
(
"not ready, retry"
);
taosMsleep
(
500
);
taosMsleep
(
500
);
...
@@ -683,7 +682,7 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
...
@@ -683,7 +682,7 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
code
=
0
;
code
=
0
;
FAIL:
FAIL:
if
(
req
.
topicNames
!=
NULL
)
taosArrayDestroyP
(
req
.
topicNames
,
taosMemoryFree
);
if
(
req
.
topicNames
!=
NULL
)
taosArrayDestroyP
(
req
.
topicNames
,
taosMemoryFree
);
if
(
code
!=
0
)
{
if
(
code
!=
0
&&
buf
)
{
taosMemoryFree
(
buf
);
taosMemoryFree
(
buf
);
}
}
return
code
;
return
code
;
...
@@ -1265,6 +1264,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t wait_time) {
...
@@ -1265,6 +1264,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t wait_time) {
return
(
TAOS_RES
*
)
rspObj
;
return
(
TAOS_RES
*
)
rspObj
;
}
}
// in no topic status also need process delayed task
if
(
atomic_load_8
(
&
tmq
->
status
)
==
TMQ_CONSUMER_STATUS__INIT
)
{
if
(
atomic_load_8
(
&
tmq
->
status
)
==
TMQ_CONSUMER_STATUS__INIT
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -1285,6 +1285,9 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t wait_time) {
...
@@ -1285,6 +1285,9 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t wait_time) {
return
NULL
;
return
NULL
;
}
}
tsem_timewait
(
&
tmq
->
rspSem
,
leftTime
*
1000
);
tsem_timewait
(
&
tmq
->
rspSem
,
leftTime
*
1000
);
}
else
{
// use tsem_timewait instead of tsem_wait to avoid unexpected stuck
tsem_timewait
(
&
tmq
->
rspSem
,
500
*
1000
);
}
}
}
}
}
}
...
...
source/common/src/tmsg.c
浏览文件 @
75cad6e3
...
@@ -1302,6 +1302,11 @@ int32_t tDeserializeSGetUserAuthRsp(void *buf, int32_t bufLen, SGetUserAuthRsp *
...
@@ -1302,6 +1302,11 @@ int32_t tDeserializeSGetUserAuthRsp(void *buf, int32_t bufLen, SGetUserAuthRsp *
return
0
;
return
0
;
}
}
void
tFreeSGetUserAuthRsp
(
SGetUserAuthRsp
*
pRsp
)
{
taosHashCleanup
(
pRsp
->
readDbs
);
taosHashCleanup
(
pRsp
->
writeDbs
);
}
int32_t
tSerializeSCreateDropMQSBNodeReq
(
void
*
buf
,
int32_t
bufLen
,
SMCreateQnodeReq
*
pReq
)
{
int32_t
tSerializeSCreateDropMQSBNodeReq
(
void
*
buf
,
int32_t
bufLen
,
SMCreateQnodeReq
*
pReq
)
{
SCoder
encoder
=
{
0
};
SCoder
encoder
=
{
0
};
tCoderInit
(
&
encoder
,
TD_LITTLE_ENDIAN
,
buf
,
bufLen
,
TD_ENCODER
);
tCoderInit
(
&
encoder
,
TD_LITTLE_ENDIAN
,
buf
,
bufLen
,
TD_ENCODER
);
...
...
source/dnode/mgmt/implement/src/dmEps.c
浏览文件 @
75cad6e3
...
@@ -120,7 +120,7 @@ int32_t dmReadEps(SDnode *pDnode) {
...
@@ -120,7 +120,7 @@ int32_t dmReadEps(SDnode *pDnode) {
goto
PRASE_DNODE_OVER
;
goto
PRASE_DNODE_OVER
;
}
}
dnodeEp
.
id
=
d
nodeI
d
->
valueint
;
dnodeEp
.
id
=
d
i
d
->
valueint
;
cJSON
*
dnodeFqdn
=
cJSON_GetObjectItem
(
node
,
"fqdn"
);
cJSON
*
dnodeFqdn
=
cJSON_GetObjectItem
(
node
,
"fqdn"
);
if
(
!
dnodeFqdn
||
dnodeFqdn
->
type
!=
cJSON_String
||
dnodeFqdn
->
valuestring
==
NULL
)
{
if
(
!
dnodeFqdn
||
dnodeFqdn
->
type
!=
cJSON_String
||
dnodeFqdn
->
valuestring
==
NULL
)
{
...
@@ -156,11 +156,6 @@ PRASE_DNODE_OVER:
...
@@ -156,11 +156,6 @@ PRASE_DNODE_OVER:
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
if
(
dmIsEpChanged
(
pDnode
,
pDnode
->
data
.
dnodeId
,
pDnode
->
data
.
localEp
))
{
dError
(
"localEp %s different with %s and need reconfigured"
,
pDnode
->
data
.
localEp
,
file
);
return
-
1
;
}
if
(
taosArrayGetSize
(
pDnode
->
data
.
dnodeEps
)
==
0
)
{
if
(
taosArrayGetSize
(
pDnode
->
data
.
dnodeEps
)
==
0
)
{
SDnodeEp
dnodeEp
=
{
0
};
SDnodeEp
dnodeEp
=
{
0
};
dnodeEp
.
isMnode
=
1
;
dnodeEp
.
isMnode
=
1
;
...
@@ -170,6 +165,11 @@ PRASE_DNODE_OVER:
...
@@ -170,6 +165,11 @@ PRASE_DNODE_OVER:
dmResetEps
(
pDnode
,
pDnode
->
data
.
dnodeEps
);
dmResetEps
(
pDnode
,
pDnode
->
data
.
dnodeEps
);
if
(
dmIsEpChanged
(
pDnode
,
pDnode
->
data
.
dnodeId
,
pDnode
->
data
.
localEp
))
{
dError
(
"localEp %s different with %s and need reconfigured"
,
pDnode
->
data
.
localEp
,
file
);
return
-
1
;
}
terrno
=
code
;
terrno
=
code
;
return
code
;
return
code
;
}
}
...
@@ -291,13 +291,17 @@ static void dmPrintEps(SDnode *pDnode) {
...
@@ -291,13 +291,17 @@ static void dmPrintEps(SDnode *pDnode) {
static
bool
dmIsEpChanged
(
SDnode
*
pDnode
,
int32_t
dnodeId
,
const
char
*
ep
)
{
static
bool
dmIsEpChanged
(
SDnode
*
pDnode
,
int32_t
dnodeId
,
const
char
*
ep
)
{
bool
changed
=
false
;
bool
changed
=
false
;
if
(
dnodeId
==
0
)
return
changed
;
taosRLockLatch
(
&
pDnode
->
data
.
latch
);
taosRLockLatch
(
&
pDnode
->
data
.
latch
);
SDnodeEp
*
pDnodeEp
=
taosHashGet
(
pDnode
->
data
.
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
SDnodeEp
*
pDnodeEp
=
taosHashGet
(
pDnode
->
data
.
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
if
(
pDnodeEp
!=
NULL
)
{
if
(
pDnodeEp
!=
NULL
)
{
char
epstr
[
TSDB_EP_LEN
+
1
];
char
epstr
[
TSDB_EP_LEN
+
1
]
=
{
0
}
;
snprintf
(
epstr
,
TSDB_EP_LEN
,
"%s:%u"
,
pDnodeEp
->
ep
.
fqdn
,
pDnodeEp
->
ep
.
port
);
snprintf
(
epstr
,
TSDB_EP_LEN
,
"%s:%u"
,
pDnodeEp
->
ep
.
fqdn
,
pDnodeEp
->
ep
.
port
);
changed
=
strcmp
(
ep
,
epstr
)
!=
0
;
changed
=
(
strcmp
(
ep
,
epstr
)
!=
0
);
if
(
changed
)
{
dError
(
"dnode:%d, localEp %s different from %s"
,
dnodeId
,
ep
,
epstr
);
}
}
}
taosRUnLockLatch
(
&
pDnode
->
data
.
latch
);
taosRUnLockLatch
(
&
pDnode
->
data
.
latch
);
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
75cad6e3
...
@@ -114,7 +114,6 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
...
@@ -114,7 +114,6 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
pCfg
->
tsdbCfg
.
keep2
=
3650
;
// pCreate->daysToKeep0;
pCfg
->
tsdbCfg
.
keep2
=
3650
;
// pCreate->daysToKeep0;
pCfg
->
tsdbCfg
.
keep0
=
3650
;
// pCreate->daysToKeep2;
pCfg
->
tsdbCfg
.
keep0
=
3650
;
// pCreate->daysToKeep2;
pCfg
->
tsdbCfg
.
keep1
=
3650
;
// pCreate->daysToKeep0;
pCfg
->
tsdbCfg
.
keep1
=
3650
;
// pCreate->daysToKeep0;
pCfg
->
tsdbCfg
.
lruCacheSize
=
pCreate
->
cacheBlockSize
;
pCfg
->
tsdbCfg
.
retentions
=
pCreate
->
pRetensions
;
pCfg
->
tsdbCfg
.
retentions
=
pCreate
->
pRetensions
;
pCfg
->
walCfg
.
vgId
=
pCreate
->
vgId
;
pCfg
->
walCfg
.
vgId
=
pCreate
->
vgId
;
pCfg
->
hashBegin
=
pCreate
->
hashBegin
;
pCfg
->
hashBegin
=
pCreate
->
hashBegin
;
...
...
source/dnode/mnode/impl/inc/mndConsumer.h
浏览文件 @
75cad6e3
...
@@ -23,10 +23,8 @@ extern "C" {
...
@@ -23,10 +23,8 @@ extern "C" {
#endif
#endif
enum
{
enum
{
// MQ_CONSUMER_STATUS__INIT = 1,
MQ_CONSUMER_STATUS__MODIFY
=
1
,
MQ_CONSUMER_STATUS__MODIFY
=
1
,
MQ_CONSUMER_STATUS__MODIFY_IN_REB
,
MQ_CONSUMER_STATUS__MODIFY_IN_REB
,
// MQ_CONSUMER_STATUS__IDLE,
MQ_CONSUMER_STATUS__READY
,
MQ_CONSUMER_STATUS__READY
,
MQ_CONSUMER_STATUS__LOST
,
MQ_CONSUMER_STATUS__LOST
,
MQ_CONSUMER_STATUS__LOST_IN_REB
,
MQ_CONSUMER_STATUS__LOST_IN_REB
,
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
75cad6e3
...
@@ -89,6 +89,7 @@ typedef enum {
...
@@ -89,6 +89,7 @@ typedef enum {
TRN_TYPE_DROP_STREAM
=
1020
,
TRN_TYPE_DROP_STREAM
=
1020
,
TRN_TYPE_ALTER_STREAM
=
1021
,
TRN_TYPE_ALTER_STREAM
=
1021
,
TRN_TYPE_CONSUMER_LOST
=
1022
,
TRN_TYPE_CONSUMER_LOST
=
1022
,
TRN_TYPE_CONSUMER_RECOVER
=
1023
,
TRN_TYPE_BASIC_SCOPE_END
,
TRN_TYPE_BASIC_SCOPE_END
,
TRN_TYPE_GLOBAL_SCOPE
=
2000
,
TRN_TYPE_GLOBAL_SCOPE
=
2000
,
TRN_TYPE_CREATE_DNODE
=
2001
,
TRN_TYPE_CREATE_DNODE
=
2001
,
...
@@ -463,12 +464,14 @@ enum {
...
@@ -463,12 +464,14 @@ enum {
CONSUMER_UPDATE__ADD
,
CONSUMER_UPDATE__ADD
,
CONSUMER_UPDATE__REMOVE
,
CONSUMER_UPDATE__REMOVE
,
CONSUMER_UPDATE__LOST
,
CONSUMER_UPDATE__LOST
,
CONSUMER_UPDATE__RECOVER
,
CONSUMER_UPDATE__MODIFY
,
CONSUMER_UPDATE__MODIFY
,
};
};
typedef
struct
{
typedef
struct
{
int64_t
consumerId
;
int64_t
consumerId
;
char
cgroup
[
TSDB_CGROUP_LEN
];
char
cgroup
[
TSDB_CGROUP_LEN
];
char
appId
[
TSDB_CGROUP_LEN
];
int8_t
updateType
;
// used only for update
int8_t
updateType
;
// used only for update
int32_t
epoch
;
int32_t
epoch
;
int32_t
status
;
int32_t
status
;
...
@@ -479,6 +482,17 @@ typedef struct {
...
@@ -479,6 +482,17 @@ typedef struct {
SArray
*
currentTopics
;
// SArray<char*>
SArray
*
currentTopics
;
// SArray<char*>
SArray
*
rebNewTopics
;
// SArray<char*>
SArray
*
rebNewTopics
;
// SArray<char*>
SArray
*
rebRemovedTopics
;
// SArray<char*>
SArray
*
rebRemovedTopics
;
// SArray<char*>
// subscribed by user
SArray
*
assignedTopics
;
// SArray<char*>
// data for display
int32_t
pid
;
SEpSet
ep
;
int64_t
upTime
;
int64_t
subscribeTime
;
int64_t
rebalanceTime
;
}
SMqConsumerObj
;
}
SMqConsumerObj
;
SMqConsumerObj
*
tNewSMqConsumerObj
(
int64_t
consumerId
,
char
cgroup
[
TSDB_CGROUP_LEN
]);
SMqConsumerObj
*
tNewSMqConsumerObj
(
int64_t
consumerId
,
char
cgroup
[
TSDB_CGROUP_LEN
]);
...
...
source/dnode/mnode/impl/src/mndConsumer.c
浏览文件 @
75cad6e3
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
static
int8_t
mqInRebFlag
=
0
;
static
int8_t
mqInRebFlag
=
0
;
static
const
char
*
mndConsumerStatusName
(
int
status
);
static
int32_t
mndConsumerActionInsert
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
);
static
int32_t
mndConsumerActionInsert
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
);
static
int32_t
mndConsumerActionDelete
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
);
static
int32_t
mndConsumerActionDelete
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
);
static
int32_t
mndConsumerActionUpdate
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
,
SMqConsumerObj
*
pNewConsumer
);
static
int32_t
mndConsumerActionUpdate
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
,
SMqConsumerObj
*
pNewConsumer
);
...
@@ -48,6 +50,7 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg);
...
@@ -48,6 +50,7 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg);
static
int32_t
mndProcessAskEpReq
(
SNodeMsg
*
pMsg
);
static
int32_t
mndProcessAskEpReq
(
SNodeMsg
*
pMsg
);
static
int32_t
mndProcessMqTimerMsg
(
SNodeMsg
*
pMsg
);
static
int32_t
mndProcessMqTimerMsg
(
SNodeMsg
*
pMsg
);
static
int32_t
mndProcessConsumerLostMsg
(
SNodeMsg
*
pMsg
);
static
int32_t
mndProcessConsumerLostMsg
(
SNodeMsg
*
pMsg
);
static
int32_t
mndProcessConsumerRecoverMsg
(
SNodeMsg
*
pMsg
);
int32_t
mndInitConsumer
(
SMnode
*
pMnode
)
{
int32_t
mndInitConsumer
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_CONSUMER
,
SSdbTable
table
=
{.
sdbType
=
SDB_CONSUMER
,
...
@@ -62,6 +65,11 @@ int32_t mndInitConsumer(SMnode *pMnode) {
...
@@ -62,6 +65,11 @@ int32_t mndInitConsumer(SMnode *pMnode) {
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MQ_ASK_EP
,
mndProcessAskEpReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MQ_ASK_EP
,
mndProcessAskEpReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MQ_TIMER
,
mndProcessMqTimerMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MQ_TIMER
,
mndProcessMqTimerMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MQ_CONSUMER_LOST
,
mndProcessConsumerLostMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MQ_CONSUMER_LOST
,
mndProcessConsumerLostMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MQ_CONSUMER_RECOVER
,
mndProcessConsumerRecoverMsg
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_CONSUMERS
,
mndRetrieveConsumer
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_CONSUMERS
,
mndCancelGetNextConsumer
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
}
...
@@ -91,6 +99,30 @@ FAIL:
...
@@ -91,6 +99,30 @@ FAIL:
return
-
1
;
return
-
1
;
}
}
static
int32_t
mndProcessConsumerRecoverMsg
(
SNodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pNode
;
SMqConsumerRecoverMsg
*
pRecoverMsg
=
pMsg
->
rpcMsg
.
pCont
;
SMqConsumerObj
*
pConsumer
=
mndAcquireConsumer
(
pMnode
,
pRecoverMsg
->
consumerId
);
ASSERT
(
pConsumer
);
SMqConsumerObj
*
pConsumerNew
=
tNewSMqConsumerObj
(
pConsumer
->
consumerId
,
pConsumer
->
cgroup
);
pConsumerNew
->
updateType
=
CONSUMER_UPDATE__RECOVER
;
mndReleaseConsumer
(
pMnode
,
pConsumer
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
TRN_TYPE_CONSUMER_RECOVER
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
goto
FAIL
;
if
(
mndSetConsumerCommitLogs
(
pMnode
,
pTrans
,
pConsumerNew
)
!=
0
)
goto
FAIL
;
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
goto
FAIL
;
mndTransDrop
(
pTrans
);
return
0
;
FAIL:
tDeleteSMqConsumerObj
(
pConsumerNew
);
mndTransDrop
(
pTrans
);
return
-
1
;
}
static
SMqRebSubscribe
*
mndGetOrCreateRebSub
(
SHashObj
*
pHash
,
const
char
*
key
)
{
static
SMqRebSubscribe
*
mndGetOrCreateRebSub
(
SHashObj
*
pHash
,
const
char
*
key
)
{
SMqRebSubscribe
*
pRebSub
=
taosHashGet
(
pHash
,
key
,
strlen
(
key
)
+
1
);
SMqRebSubscribe
*
pRebSub
=
taosHashGet
(
pHash
,
key
,
strlen
(
key
)
+
1
);
if
(
pRebSub
==
NULL
)
{
if
(
pRebSub
==
NULL
)
{
...
@@ -216,8 +248,15 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) {
...
@@ -216,8 +248,15 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) {
// 1. check consumer status
// 1. check consumer status
int32_t
status
=
atomic_load_32
(
&
pConsumer
->
status
);
int32_t
status
=
atomic_load_32
(
&
pConsumer
->
status
);
if
(
status
==
MQ_CONSUMER_STATUS__LOST
)
{
if
(
status
==
MQ_CONSUMER_STATUS__LOST_REBD
)
{
// TODO: recover consumer
SMqConsumerRecoverMsg
*
pRecoverMsg
=
rpcMallocCont
(
sizeof
(
SMqConsumerRecoverMsg
));
pRecoverMsg
->
consumerId
=
consumerId
;
SRpcMsg
*
pRpcMsg
=
taosMemoryCalloc
(
1
,
sizeof
(
SRpcMsg
));
pRpcMsg
->
msgType
=
TDMT_MND_MQ_CONSUMER_RECOVER
;
pRpcMsg
->
pCont
=
pRecoverMsg
;
pRpcMsg
->
contLen
=
sizeof
(
SMqConsumerRecoverMsg
);
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
WRITE_QUEUE
,
pRpcMsg
);
}
}
if
(
status
!=
MQ_CONSUMER_STATUS__READY
)
{
if
(
status
!=
MQ_CONSUMER_STATUS__READY
)
{
...
@@ -366,10 +405,14 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
...
@@ -366,10 +405,14 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
if
(
pConsumerOld
==
NULL
)
{
if
(
pConsumerOld
==
NULL
)
{
pConsumerNew
=
tNewSMqConsumerObj
(
consumerId
,
cgroup
);
pConsumerNew
=
tNewSMqConsumerObj
(
consumerId
,
cgroup
);
pConsumerNew
->
updateType
=
CONSUMER_UPDATE__MODIFY
;
pConsumerNew
->
updateType
=
CONSUMER_UPDATE__MODIFY
;
/*pConsumerNew->waitingRebTopics = newSub;*/
pConsumerNew
->
rebNewTopics
=
newSub
;
pConsumerNew
->
rebNewTopics
=
newSub
;
subscribe
.
topicNames
=
NULL
;
subscribe
.
topicNames
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
newTopicNum
;
i
++
)
{
char
*
newTopicCopy
=
strdup
(
taosArrayGetP
(
newSub
,
i
));
taosArrayPush
(
pConsumerNew
->
assignedTopics
,
&
newTopicCopy
);
}
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
TRN_TYPE_SUBSCRIBE
,
&
pMsg
->
rpcMsg
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_RETRY
,
TRN_TYPE_SUBSCRIBE
,
&
pMsg
->
rpcMsg
);
if
(
pTrans
==
NULL
)
goto
SUBSCRIBE_OVER
;
if
(
pTrans
==
NULL
)
goto
SUBSCRIBE_OVER
;
if
(
mndSetConsumerCommitLogs
(
pMnode
,
pTrans
,
pConsumerNew
)
!=
0
)
goto
SUBSCRIBE_OVER
;
if
(
mndSetConsumerCommitLogs
(
pMnode
,
pTrans
,
pConsumerNew
)
!=
0
)
goto
SUBSCRIBE_OVER
;
...
@@ -389,7 +432,11 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
...
@@ -389,7 +432,11 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
goto
SUBSCRIBE_OVER
;
goto
SUBSCRIBE_OVER
;
}
}
pConsumerNew
->
updateType
=
CONSUMER_UPDATE__MODIFY
;
pConsumerNew
->
updateType
=
CONSUMER_UPDATE__MODIFY
;
/*pConsumerOld->waitingRebTopics = newSub;*/
for
(
int32_t
i
=
0
;
i
<
newTopicNum
;
i
++
)
{
char
*
newTopicCopy
=
strdup
(
taosArrayGetP
(
newSub
,
i
));
taosArrayPush
(
pConsumerNew
->
assignedTopics
,
&
newTopicCopy
);
}
int32_t
oldTopicNum
=
0
;
int32_t
oldTopicNum
=
0
;
if
(
pConsumerOld
->
currentTopics
)
{
if
(
pConsumerOld
->
currentTopics
)
{
...
@@ -532,6 +579,7 @@ CM_DECODE_OVER:
...
@@ -532,6 +579,7 @@ CM_DECODE_OVER:
static
int32_t
mndConsumerActionInsert
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
)
{
static
int32_t
mndConsumerActionInsert
(
SSdb
*
pSdb
,
SMqConsumerObj
*
pConsumer
)
{
mTrace
(
"consumer:%"
PRId64
", perform insert action"
,
pConsumer
->
consumerId
);
mTrace
(
"consumer:%"
PRId64
", perform insert action"
,
pConsumer
->
consumerId
);
pConsumer
->
subscribeTime
=
pConsumer
->
upTime
;
return
0
;
return
0
;
}
}
...
@@ -557,17 +605,45 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
...
@@ -557,17 +605,45 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
pOldConsumer
->
rebRemovedTopics
=
pNewConsumer
->
rebRemovedTopics
;
pOldConsumer
->
rebRemovedTopics
=
pNewConsumer
->
rebRemovedTopics
;
pNewConsumer
->
rebRemovedTopics
=
tmp
;
pNewConsumer
->
rebRemovedTopics
=
tmp
;
tmp
=
pOldConsumer
->
assignedTopics
;
pOldConsumer
->
assignedTopics
=
pNewConsumer
->
assignedTopics
;
pNewConsumer
->
assignedTopics
=
tmp
;
pOldConsumer
->
subscribeTime
=
pNewConsumer
->
upTime
;
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__MODIFY
;
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__MODIFY
;
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__LOST
)
{
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__LOST
)
{
ASSERT
(
taosArrayGetSize
(
pOldConsumer
->
rebNewTopics
)
==
0
);
ASSERT
(
taosArrayGetSize
(
pOldConsumer
->
rebRemovedTopics
)
==
0
);
int32_t
sz
=
taosArrayGetSize
(
pOldConsumer
->
currentTopics
);
int32_t
sz
=
taosArrayGetSize
(
pOldConsumer
->
currentTopics
);
pOldConsumer
->
rebRemovedTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
/*pOldConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *));*/
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
strdup
(
taosArrayGetP
(
pOldConsumer
->
currentTopics
,
i
));
char
*
topic
=
strdup
(
taosArrayGetP
(
pOldConsumer
->
currentTopics
,
i
));
taosArrayPush
(
p
New
Consumer
->
rebRemovedTopics
,
&
topic
);
taosArrayPush
(
p
Old
Consumer
->
rebRemovedTopics
,
&
topic
);
}
}
pOldConsumer
->
rebalanceTime
=
pNewConsumer
->
upTime
;
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__LOST
;
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__LOST
;
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__RECOVER
)
{
ASSERT
(
taosArrayGetSize
(
pOldConsumer
->
currentTopics
)
==
0
);
ASSERT
(
taosArrayGetSize
(
pOldConsumer
->
rebNewTopics
)
==
0
);
int32_t
sz
=
taosArrayGetSize
(
pOldConsumer
->
assignedTopics
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
strdup
(
taosArrayGetP
(
pOldConsumer
->
assignedTopics
,
i
));
taosArrayPush
(
pOldConsumer
->
rebNewTopics
,
&
topic
);
}
pOldConsumer
->
rebalanceTime
=
pNewConsumer
->
upTime
;
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__MODIFY
;
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__TOUCH
)
{
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__TOUCH
)
{
atomic_add_fetch_32
(
&
pOldConsumer
->
epoch
,
1
);
atomic_add_fetch_32
(
&
pOldConsumer
->
epoch
,
1
);
pOldConsumer
->
rebalanceTime
=
pNewConsumer
->
upTime
;
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__ADD
)
{
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__ADD
)
{
ASSERT
(
taosArrayGetSize
(
pNewConsumer
->
rebNewTopics
)
==
1
);
ASSERT
(
taosArrayGetSize
(
pNewConsumer
->
rebNewTopics
)
==
1
);
ASSERT
(
taosArrayGetSize
(
pNewConsumer
->
rebRemovedTopics
)
==
0
);
ASSERT
(
taosArrayGetSize
(
pNewConsumer
->
rebRemovedTopics
)
==
0
);
...
@@ -612,6 +688,9 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
...
@@ -612,6 +688,9 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__LOST_IN_REB
;
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__LOST_IN_REB
;
}
}
}
}
pOldConsumer
->
rebalanceTime
=
pNewConsumer
->
upTime
;
atomic_add_fetch_32
(
&
pOldConsumer
->
epoch
,
1
);
atomic_add_fetch_32
(
&
pOldConsumer
->
epoch
,
1
);
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__REMOVE
)
{
}
else
if
(
pNewConsumer
->
updateType
==
CONSUMER_UPDATE__REMOVE
)
{
ASSERT
(
taosArrayGetSize
(
pNewConsumer
->
rebNewTopics
)
==
0
);
ASSERT
(
taosArrayGetSize
(
pNewConsumer
->
rebNewTopics
)
==
0
);
...
@@ -668,6 +747,9 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
...
@@ -668,6 +747,9 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__LOST_IN_REB
;
pOldConsumer
->
status
=
MQ_CONSUMER_STATUS__LOST_IN_REB
;
}
}
}
}
pOldConsumer
->
rebalanceTime
=
pNewConsumer
->
upTime
;
atomic_add_fetch_32
(
&
pOldConsumer
->
epoch
,
1
);
atomic_add_fetch_32
(
&
pOldConsumer
->
epoch
,
1
);
}
}
...
@@ -688,3 +770,104 @@ void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer) {
...
@@ -688,3 +770,104 @@ void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer) {
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbRelease
(
pSdb
,
pConsumer
);
sdbRelease
(
pSdb
,
pConsumer
);
}
}
static
int32_t
mndRetrieveConsumer
(
SNodeMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rowsCapacity
)
{
SMnode
*
pMnode
=
pReq
->
pNode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
SMqConsumerObj
*
pConsumer
=
NULL
;
while
(
numOfRows
<
rowsCapacity
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_CONSUMER
,
pShow
->
pIter
,
(
void
**
)
&
pConsumer
);
if
(
pShow
->
pIter
==
NULL
)
break
;
SColumnInfoData
*
pColInfo
;
int32_t
cols
=
0
;
taosRLockLatch
(
&
pConsumer
->
lock
);
// consumer id
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pConsumer
->
consumerId
,
false
);
// group id
char
groupId
[
TSDB_CGROUP_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tstrncpy
(
varDataVal
(
groupId
),
pConsumer
->
cgroup
,
TSDB_CGROUP_LEN
);
varDataSetLen
(
groupId
,
strlen
(
varDataVal
(
groupId
)));
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
groupId
,
false
);
// app id
char
appId
[
TSDB_CGROUP_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tstrncpy
(
varDataVal
(
appId
),
pConsumer
->
appId
,
TSDB_CGROUP_LEN
);
varDataSetLen
(
appId
,
strlen
(
varDataVal
(
appId
)));
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
appId
,
false
);
// status
char
status
[
20
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tstrncpy
(
varDataVal
(
status
),
mndConsumerStatusName
(
pConsumer
->
status
),
20
);
varDataSetLen
(
status
,
strlen
(
varDataVal
(
status
)));
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
status
,
false
);
// subscribed topics
char
topics
[
TSDB_SHOW_LIST_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
char
*
showStr
=
taosShowStrArray
(
pConsumer
->
assignedTopics
);
tstrncpy
(
varDataVal
(
topics
),
showStr
,
TSDB_SHOW_LIST_LEN
);
taosMemoryFree
(
showStr
);
varDataSetLen
(
topics
,
strlen
(
varDataVal
(
topics
)));
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
topics
,
false
);
// pid
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pConsumer
->
pid
,
true
);
// end point
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pConsumer
->
ep
,
true
);
// up time
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pConsumer
->
upTime
,
false
);
// subscribe time
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pConsumer
->
subscribeTime
,
false
);
// rebalance time
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pConsumer
->
rebalanceTime
,
pConsumer
->
rebalanceTime
==
0
);
taosRUnLockLatch
(
&
pConsumer
->
lock
);
sdbRelease
(
pSdb
,
pConsumer
);
numOfRows
++
;
}
pShow
->
numOfRows
+=
numOfRows
;
return
numOfRows
;
}
static
void
mndCancelGetNextConsumer
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
static
const
char
*
mndConsumerStatusName
(
int
status
)
{
switch
(
status
)
{
case
MQ_CONSUMER_STATUS__READY
:
return
"ready"
;
case
MQ_CONSUMER_STATUS__LOST
:
case
MQ_CONSUMER_STATUS__LOST_REBD
:
case
MQ_CONSUMER_STATUS__LOST_IN_REB
:
return
"lost"
;
case
MQ_CONSUMER_STATUS__MODIFY
:
case
MQ_CONSUMER_STATUS__MODIFY_IN_REB
:
return
"rebalancing"
;
default:
return
"unknown"
;
}
}
source/dnode/mnode/impl/src/mndDef.c
浏览文件 @
75cad6e3
...
@@ -34,15 +34,20 @@ SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_L
...
@@ -34,15 +34,20 @@ SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_L
pConsumer
->
currentTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pConsumer
->
currentTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pConsumer
->
rebNewTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pConsumer
->
rebNewTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pConsumer
->
rebRemovedTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pConsumer
->
rebRemovedTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pConsumer
->
assignedTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
if
(
pConsumer
->
currentTopics
==
NULL
||
pConsumer
->
rebNewTopics
==
NULL
||
pConsumer
->
rebRemovedTopics
==
NULL
)
{
if
(
pConsumer
->
currentTopics
==
NULL
||
pConsumer
->
rebNewTopics
==
NULL
||
pConsumer
->
rebRemovedTopics
==
NULL
||
pConsumer
->
assignedTopics
==
NULL
)
{
taosArrayDestroy
(
pConsumer
->
currentTopics
);
taosArrayDestroy
(
pConsumer
->
currentTopics
);
taosArrayDestroy
(
pConsumer
->
rebNewTopics
);
taosArrayDestroy
(
pConsumer
->
rebNewTopics
);
taosArrayDestroy
(
pConsumer
->
rebRemovedTopics
);
taosArrayDestroy
(
pConsumer
->
rebRemovedTopics
);
taosArrayDestroy
(
pConsumer
->
assignedTopics
);
taosMemoryFree
(
pConsumer
);
taosMemoryFree
(
pConsumer
);
return
NULL
;
return
NULL
;
}
}
pConsumer
->
upTime
=
taosGetTimestampMs
();
return
pConsumer
;
return
pConsumer
;
}
}
...
@@ -56,6 +61,9 @@ void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
...
@@ -56,6 +61,9 @@ void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
if
(
pConsumer
->
rebRemovedTopics
)
{
if
(
pConsumer
->
rebRemovedTopics
)
{
taosArrayDestroyP
(
pConsumer
->
rebRemovedTopics
,
(
FDelete
)
taosMemoryFree
);
taosArrayDestroyP
(
pConsumer
->
rebRemovedTopics
,
(
FDelete
)
taosMemoryFree
);
}
}
if
(
pConsumer
->
assignedTopics
)
{
taosArrayDestroyP
(
pConsumer
->
assignedTopics
,
(
FDelete
)
taosMemoryFree
);
}
}
}
int32_t
tEncodeSMqConsumerObj
(
void
**
buf
,
const
SMqConsumerObj
*
pConsumer
)
{
int32_t
tEncodeSMqConsumerObj
(
void
**
buf
,
const
SMqConsumerObj
*
pConsumer
)
{
...
@@ -67,6 +75,12 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
...
@@ -67,6 +75,12 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumer
->
epoch
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumer
->
epoch
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumer
->
status
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumer
->
status
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumer
->
pid
);
tlen
+=
taosEncodeSEpSet
(
buf
,
&
pConsumer
->
ep
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
upTime
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
subscribeTime
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
rebalanceTime
);
// current topics
// current topics
if
(
pConsumer
->
currentTopics
)
{
if
(
pConsumer
->
currentTopics
)
{
sz
=
taosArrayGetSize
(
pConsumer
->
currentTopics
);
sz
=
taosArrayGetSize
(
pConsumer
->
currentTopics
);
...
@@ -103,6 +117,18 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
...
@@ -103,6 +117,18 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
tlen
+=
taosEncodeFixedI32
(
buf
,
0
);
tlen
+=
taosEncodeFixedI32
(
buf
,
0
);
}
}
// lost topics
if
(
pConsumer
->
assignedTopics
)
{
sz
=
taosArrayGetSize
(
pConsumer
->
assignedTopics
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
assignedTopics
,
i
);
tlen
+=
taosEncodeString
(
buf
,
topic
);
}
}
else
{
tlen
+=
taosEncodeFixedI32
(
buf
,
0
);
}
return
tlen
;
return
tlen
;
}
}
...
@@ -114,6 +140,12 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
...
@@ -114,6 +140,12 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumer
->
epoch
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumer
->
epoch
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumer
->
status
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumer
->
status
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumer
->
pid
);
buf
=
taosDecodeSEpSet
(
buf
,
&
pConsumer
->
ep
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
upTime
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
subscribeTime
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
rebalanceTime
);
// current topics
// current topics
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pConsumer
->
currentTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
pConsumer
->
currentTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
...
@@ -141,6 +173,15 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
...
@@ -141,6 +173,15 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
taosArrayPush
(
pConsumer
->
rebRemovedTopics
,
&
topic
);
taosArrayPush
(
pConsumer
->
rebRemovedTopics
,
&
topic
);
}
}
// reb removed topics
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pConsumer
->
assignedTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
;
buf
=
taosDecodeString
(
buf
,
&
topic
);
taosArrayPush
(
pConsumer
->
assignedTopics
,
&
topic
);
}
return
(
void
*
)
buf
;
return
(
void
*
)
buf
;
}
}
...
@@ -329,6 +370,7 @@ int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEnt
...
@@ -329,6 +370,7 @@ int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEnt
tlen
+=
taosEncodeArray
(
buf
,
pEntry
->
consumers
,
(
FEncode
)
tEncodeSMqSubActionLogEntry
);
tlen
+=
taosEncodeArray
(
buf
,
pEntry
->
consumers
,
(
FEncode
)
tEncodeSMqSubActionLogEntry
);
return
tlen
;
return
tlen
;
}
}
void
*
tDecodeSMqSubActionLogEntry
(
const
void
*
buf
,
SMqSubActionLogEntry
*
pEntry
)
{
void
*
tDecodeSMqSubActionLogEntry
(
const
void
*
buf
,
SMqSubActionLogEntry
*
pEntry
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pEntry
->
epoch
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pEntry
->
epoch
);
buf
=
taosDecodeArray
(
buf
,
&
pEntry
->
consumers
,
(
FDecode
)
tDecodeSMqSubActionLogEntry
,
sizeof
(
SMqSubActionLogEntry
));
buf
=
taosDecodeArray
(
buf
,
&
pEntry
->
consumers
,
(
FDecode
)
tDecodeSMqSubActionLogEntry
,
sizeof
(
SMqSubActionLogEntry
));
...
...
source/dnode/mnode/impl/src/mndInfoSchema.c
浏览文件 @
75cad6e3
...
@@ -142,6 +142,7 @@ static const SInfosTableSchema userTblsSchema[] = {
...
@@ -142,6 +142,7 @@ static const SInfosTableSchema userTblsSchema[] = {
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"ttl"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"ttl"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"table_comment"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"table_comment"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"type"
,
.
bytes
=
20
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
};
};
static
const
SInfosTableSchema
userTblDistSchema
[]
=
{
static
const
SInfosTableSchema
userTblDistSchema
[]
=
{
...
@@ -164,7 +165,6 @@ static const SInfosTableSchema userUsersSchema[] = {
...
@@ -164,7 +165,6 @@ static const SInfosTableSchema userUsersSchema[] = {
{.
name
=
"name"
,
.
bytes
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"name"
,
.
bytes
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"privilege"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"privilege"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"account"
,
.
bytes
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
};
};
static
const
SInfosTableSchema
grantsSchema
[]
=
{
static
const
SInfosTableSchema
grantsSchema
[]
=
{
...
@@ -199,23 +199,6 @@ static const SInfosTableSchema vgroupsSchema[] = {
...
@@ -199,23 +199,6 @@ static const SInfosTableSchema vgroupsSchema[] = {
{.
name
=
"file_size"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"file_size"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
};
};
static
const
SInfosTableSchema
consumerSchema
[]
=
{
{.
name
=
"client_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"group_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"pid"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"status"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
// ep
// up time
// topics
};
static
const
SInfosTableSchema
subscribeSchema
[]
=
{
{.
name
=
"topic_name"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"group_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"client_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
};
static
const
SInfosTableSchema
smaSchema
[]
=
{
static
const
SInfosTableSchema
smaSchema
[]
=
{
{.
name
=
"sma_name"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"sma_name"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
...
@@ -282,8 +265,6 @@ static const SInfosTableMeta infosMeta[] = {
...
@@ -282,8 +265,6 @@ static const SInfosTableMeta infosMeta[] = {
{
TSDB_INS_TABLE_USER_USERS
,
userUsersSchema
,
tListLen
(
userUsersSchema
)},
{
TSDB_INS_TABLE_USER_USERS
,
userUsersSchema
,
tListLen
(
userUsersSchema
)},
{
TSDB_INS_TABLE_LICENCES
,
grantsSchema
,
tListLen
(
grantsSchema
)},
{
TSDB_INS_TABLE_LICENCES
,
grantsSchema
,
tListLen
(
grantsSchema
)},
{
TSDB_INS_TABLE_VGROUPS
,
vgroupsSchema
,
tListLen
(
vgroupsSchema
)},
{
TSDB_INS_TABLE_VGROUPS
,
vgroupsSchema
,
tListLen
(
vgroupsSchema
)},
{
TSDB_INS_TABLE_CONSUMERS
,
consumerSchema
,
tListLen
(
consumerSchema
)},
{
TSDB_INS_TABLE_SUBSCRIBES
,
subscribeSchema
,
tListLen
(
subscribeSchema
)},
{
TSDB_INS_TABLE_TRANS
,
transSchema
,
tListLen
(
transSchema
)},
{
TSDB_INS_TABLE_TRANS
,
transSchema
,
tListLen
(
transSchema
)},
{
TSDB_INS_TABLE_SMAS
,
smaSchema
,
tListLen
(
smaSchema
)},
{
TSDB_INS_TABLE_SMAS
,
smaSchema
,
tListLen
(
smaSchema
)},
{
TSDB_INS_TABLE_CONFIGS
,
configSchema
,
tListLen
(
configSchema
)},
{
TSDB_INS_TABLE_CONFIGS
,
configSchema
,
tListLen
(
configSchema
)},
...
...
source/dnode/mnode/impl/src/mndPerfSchema.c
浏览文件 @
75cad6e3
...
@@ -49,13 +49,15 @@ static const SPerfsTableSchema topicSchema[] = {
...
@@ -49,13 +49,15 @@ static const SPerfsTableSchema topicSchema[] = {
static
const
SPerfsTableSchema
consumerSchema
[]
=
{
static
const
SPerfsTableSchema
consumerSchema
[]
=
{
{.
name
=
"consumer_id"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"consumer_id"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"app_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"group_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"group_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"status"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"app_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"status"
,
.
bytes
=
20
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"topics"
,
.
bytes
=
TSDB_SHOW_LIST_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"topics"
,
.
bytes
=
TSDB_SHOW_LIST_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"pid"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"pid"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"end_point"
,
.
bytes
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"end_point"
,
.
bytes
=
TSDB_EP_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"up_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"up_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"subscribe_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"rebalance_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
};
};
static
const
SPerfsTableSchema
subscriptionSchema
[]
=
{
static
const
SPerfsTableSchema
subscriptionSchema
[]
=
{
...
@@ -63,6 +65,12 @@ static const SPerfsTableSchema subscriptionSchema[] = {
...
@@ -63,6 +65,12 @@ static const SPerfsTableSchema subscriptionSchema[] = {
{.
name
=
"group_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"group_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"consumer_id"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"consumer_id"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
};
static
const
SPerfsTableSchema
offsetSchema
[]
=
{
{.
name
=
"topic_name"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"group_id"
,
.
bytes
=
SYSTABLE_SCH_TABLE_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"committed_offset"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"committed_offset"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"current_offset"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"current_offset"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"skip_log_cnt"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
{.
name
=
"skip_log_cnt"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_BIGINT
},
...
@@ -74,6 +82,7 @@ static const SPerfsTableMeta perfsMeta[] = {
...
@@ -74,6 +82,7 @@ static const SPerfsTableMeta perfsMeta[] = {
{
TSDB_PERFS_TABLE_TOPICS
,
topicSchema
,
tListLen
(
topicSchema
)},
{
TSDB_PERFS_TABLE_TOPICS
,
topicSchema
,
tListLen
(
topicSchema
)},
{
TSDB_PERFS_TABLE_CONSUMERS
,
consumerSchema
,
tListLen
(
consumerSchema
)},
{
TSDB_PERFS_TABLE_CONSUMERS
,
consumerSchema
,
tListLen
(
consumerSchema
)},
{
TSDB_PERFS_TABLE_SUBSCRIPTIONS
,
subscriptionSchema
,
tListLen
(
subscriptionSchema
)},
{
TSDB_PERFS_TABLE_SUBSCRIPTIONS
,
subscriptionSchema
,
tListLen
(
subscriptionSchema
)},
{
TSDB_PERFS_TABLE_OFFSETS
,
offsetSchema
,
tListLen
(
offsetSchema
)},
};
};
// connection/application/
// connection/application/
...
...
source/dnode/mnode/impl/src/mndProfile.c
浏览文件 @
75cad6e3
...
@@ -196,7 +196,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) {
...
@@ -196,7 +196,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) {
goto
CONN_OVER
;
goto
CONN_OVER
;
}
}
if
(
0
!=
strncmp
(
connReq
.
passwd
,
pUser
->
pass
,
TSDB_PASSWORD_LEN
-
1
))
{
if
(
0
!=
strncmp
(
connReq
.
passwd
,
pUser
->
pass
,
TSDB_PASSWORD_LEN
-
1
))
{
mError
(
"user:%s, failed to auth while acquire user
\n
%s
\r\n
%s"
,
pReq
->
user
,
connReq
.
passwd
,
pUser
->
pass
);
mError
(
"user:%s, failed to auth while acquire user
, input:%s saved:
%s"
,
pReq
->
user
,
connReq
.
passwd
,
pUser
->
pass
);
code
=
TSDB_CODE_RPC_AUTH_FAILURE
;
code
=
TSDB_CODE_RPC_AUTH_FAILURE
;
goto
CONN_OVER
;
goto
CONN_OVER
;
}
}
...
...
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
75cad6e3
...
@@ -489,7 +489,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
...
@@ -489,7 +489,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
int32_t
levelNum
=
LIST_LENGTH
(
pPlan
->
pSubplans
);
int32_t
levelNum
=
LIST_LENGTH
(
pPlan
->
pSubplans
);
if
(
levelNum
!=
1
)
{
if
(
levelNum
!=
1
)
{
qDestroyQueryPlan
(
pPlan
);
qDestroyQueryPlan
(
pPlan
);
terrno
=
TSDB_CODE_MND_
UNSUPPORTED_TOPIC
;
terrno
=
TSDB_CODE_MND_
INVALID_TOPIC_QUERY
;
return
-
1
;
return
-
1
;
}
}
...
@@ -498,7 +498,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
...
@@ -498,7 +498,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
int32_t
opNum
=
LIST_LENGTH
(
inner
->
pNodeList
);
int32_t
opNum
=
LIST_LENGTH
(
inner
->
pNodeList
);
if
(
opNum
!=
1
)
{
if
(
opNum
!=
1
)
{
qDestroyQueryPlan
(
pPlan
);
qDestroyQueryPlan
(
pPlan
);
terrno
=
TSDB_CODE_MND_
UNSUPPORTED_TOPIC
;
terrno
=
TSDB_CODE_MND_
INVALID_TOPIC_QUERY
;
return
-
1
;
return
-
1
;
}
}
plan
=
nodesListGetNode
(
inner
->
pNodeList
,
0
);
plan
=
nodesListGetNode
(
inner
->
pNodeList
,
0
);
...
...
source/dnode/mnode/impl/src/mndTopic.c
浏览文件 @
75cad6e3
...
@@ -261,7 +261,7 @@ static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMq
...
@@ -261,7 +261,7 @@ static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMq
static
int32_t
mndCheckCreateTopicReq
(
SCMCreateTopicReq
*
pCreate
)
{
static
int32_t
mndCheckCreateTopicReq
(
SCMCreateTopicReq
*
pCreate
)
{
if
(
pCreate
->
name
[
0
]
==
0
||
pCreate
->
sql
==
NULL
||
pCreate
->
sql
[
0
]
==
0
||
pCreate
->
subscribeDbName
[
0
]
==
0
)
{
if
(
pCreate
->
name
[
0
]
==
0
||
pCreate
->
sql
==
NULL
||
pCreate
->
sql
[
0
]
==
0
||
pCreate
->
subscribeDbName
[
0
]
==
0
)
{
terrno
=
TSDB_CODE_MND_INVALID_TOPIC
_OPTION
;
terrno
=
TSDB_CODE_MND_INVALID_TOPIC
;
return
-
1
;
return
-
1
;
}
}
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
75cad6e3
...
@@ -165,8 +165,9 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
...
@@ -165,8 +165,9 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
int32_t
numOfWriteDbs
=
0
;
int32_t
numOfWriteDbs
=
0
;
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
numOfReadDbs
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
numOfReadDbs
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
numOfWriteDbs
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
numOfWriteDbs
,
_OVER
)
pUser
->
readDbs
=
taosHashInit
(
numOfReadDbs
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
true
);
pUser
->
readDbs
=
taosHashInit
(
numOfReadDbs
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
pUser
->
writeDbs
=
taosHashInit
(
numOfWriteDbs
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
true
);
pUser
->
writeDbs
=
taosHashInit
(
numOfWriteDbs
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
pUser
->
readDbs
==
NULL
||
pUser
->
writeDbs
==
NULL
)
goto
_OVER
;
if
(
pUser
->
readDbs
==
NULL
||
pUser
->
writeDbs
==
NULL
)
goto
_OVER
;
for
(
int32_t
i
=
0
;
i
<
numOfReadDbs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfReadDbs
;
++
i
)
{
...
@@ -340,13 +341,13 @@ _OVER:
...
@@ -340,13 +341,13 @@ _OVER:
return
code
;
return
code
;
}
}
static
int32_t
mnd
Update
User
(
SMnode
*
pMnode
,
SUserObj
*
pOld
,
SUserObj
*
pNew
,
SNodeMsg
*
pReq
)
{
static
int32_t
mnd
Alter
User
(
SMnode
*
pMnode
,
SUserObj
*
pOld
,
SUserObj
*
pNew
,
SNodeMsg
*
pReq
)
{
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_TYPE_ALTER_USER
,
&
pReq
->
rpcMsg
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
TRN_TYPE_ALTER_USER
,
&
pReq
->
rpcMsg
);
if
(
pTrans
==
NULL
)
{
if
(
pTrans
==
NULL
)
{
mError
(
"user:%s, failed to
update
since %s"
,
pOld
->
user
,
terrstr
());
mError
(
"user:%s, failed to
alter
since %s"
,
pOld
->
user
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
mDebug
(
"trans:%d, used to
update
user:%s"
,
pTrans
->
id
,
pOld
->
user
);
mDebug
(
"trans:%d, used to
alter
user:%s"
,
pTrans
->
id
,
pOld
->
user
);
SSdbRaw
*
pRedoRaw
=
mndUserActionEncode
(
pNew
);
SSdbRaw
*
pRedoRaw
=
mndUserActionEncode
(
pNew
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRedoRaw
)
!=
0
)
{
...
@@ -367,7 +368,8 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNo
...
@@ -367,7 +368,8 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNo
}
}
static
SHashObj
*
mndDupDbHash
(
SHashObj
*
pOld
)
{
static
SHashObj
*
mndDupDbHash
(
SHashObj
*
pOld
)
{
SHashObj
*
pNew
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
true
);
SHashObj
*
pNew
=
taosHashInit
(
taosHashGetSize
(
pOld
),
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
...
@@ -378,8 +380,8 @@ static SHashObj *mndDupDbHash(SHashObj *pOld) {
...
@@ -378,8 +380,8 @@ static SHashObj *mndDupDbHash(SHashObj *pOld) {
int32_t
len
=
strlen
(
db
)
+
1
;
int32_t
len
=
strlen
(
db
)
+
1
;
if
(
taosHashPut
(
pNew
,
db
,
len
,
db
,
TSDB_DB_FNAME_LEN
)
!=
0
)
{
if
(
taosHashPut
(
pNew
,
db
,
len
,
db
,
TSDB_DB_FNAME_LEN
)
!=
0
)
{
taosHashCancelIterate
(
pOld
,
db
);
taosHashCancelIterate
(
pOld
,
db
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
taosHashCleanup
(
pNew
);
taosHashCleanup
(
pNew
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
db
=
taosHashIterate
(
pOld
,
db
);
db
=
taosHashIterate
(
pOld
,
db
);
...
@@ -439,7 +441,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
...
@@ -439,7 +441,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_PASSWD
)
{
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_PASSWD
)
{
char
pass
[
TSDB_PASSWORD_LEN
+
1
]
=
{
0
};
char
pass
[
TSDB_PASSWORD_LEN
+
1
]
=
{
0
};
taosEncryptPass_c
((
uint8_t
*
)
alterReq
.
pass
,
strlen
(
alterReq
.
pass
),
pass
);
taosEncryptPass_c
((
uint8_t
*
)
alterReq
.
pass
,
strlen
(
alterReq
.
pass
),
pass
);
memcpy
(
pUser
->
pass
,
pass
,
TSDB_PASSWORD_LEN
);
memcpy
(
newUser
.
pass
,
pass
,
TSDB_PASSWORD_LEN
);
}
else
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_SUPERUSER
)
{
}
else
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_SUPERUSER
)
{
newUser
.
superUser
=
alterReq
.
superUser
;
newUser
.
superUser
=
alterReq
.
superUser
;
}
else
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_ADD_READ_DB
)
{
}
else
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_ADD_READ_DB
)
{
...
@@ -485,7 +487,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
...
@@ -485,7 +487,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
goto
_OVER
;
goto
_OVER
;
}
}
code
=
mnd
Update
User
(
pMnode
,
pUser
,
&
newUser
,
pReq
);
code
=
mnd
Alter
User
(
pMnode
,
pUser
,
&
newUser
,
pReq
);
if
(
code
==
0
)
code
=
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
if
(
code
==
0
)
code
=
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
_OVER:
_OVER:
...
@@ -632,8 +634,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
...
@@ -632,8 +634,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
_OVER:
_OVER:
mndReleaseUser
(
pMnode
,
pUser
);
mndReleaseUser
(
pMnode
,
pUser
);
taosHashCleanup
(
authRsp
.
readDbs
);
tFreeSGetUserAuthRsp
(
&
authRsp
);
taosHashCleanup
(
authRsp
.
writeDbs
);
return
code
;
return
code
;
}
}
...
@@ -670,11 +671,6 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
...
@@ -670,11 +671,6 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pUser
->
createdTime
,
false
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pUser
->
createdTime
,
false
);
cols
++
;
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
);
STR_WITH_MAXSIZE_TO_VARSTR
(
name
,
pUser
->
acct
,
pShow
->
bytes
[
cols
]);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
name
,
false
);
numOfRows
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pUser
);
sdbRelease
(
pSdb
,
pUser
);
}
}
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
75cad6e3
...
@@ -43,7 +43,7 @@
...
@@ -43,7 +43,7 @@
#include "mndUser.h"
#include "mndUser.h"
#include "mndVgroup.h"
#include "mndVgroup.h"
#define MQ_TIMER_MS
3
000
#define MQ_TIMER_MS
2
000
#define TRNAS_TIMER_MS 6000
#define TRNAS_TIMER_MS 6000
static
void
*
mndBuildTimerMsg
(
int32_t
*
pContLen
)
{
static
void
*
mndBuildTimerMsg
(
int32_t
*
pContLen
)
{
...
@@ -418,7 +418,6 @@ int64_t mndGenerateUid(char *name, int32_t len) {
...
@@ -418,7 +418,6 @@ int64_t mndGenerateUid(char *name, int32_t len) {
}
while
(
true
);
}
while
(
true
);
}
}
int32_t
mndGetMonitorInfo
(
SMnode
*
pMnode
,
SMonClusterInfo
*
pClusterInfo
,
SMonVgroupInfo
*
pVgroupInfo
,
int32_t
mndGetMonitorInfo
(
SMnode
*
pMnode
,
SMonClusterInfo
*
pClusterInfo
,
SMonVgroupInfo
*
pVgroupInfo
,
SMonGrantInfo
*
pGrantInfo
)
{
SMonGrantInfo
*
pGrantInfo
)
{
if
(
!
mndIsMaster
(
pMnode
))
return
-
1
;
if
(
!
mndIsMaster
(
pMnode
))
return
-
1
;
...
...
source/dnode/vnode/CMakeLists.txt
浏览文件 @
75cad6e3
...
@@ -27,10 +27,9 @@ target_sources(
...
@@ -27,10 +27,9 @@ target_sources(
"src/tsdb/tsdbTDBImpl.c"
"src/tsdb/tsdbTDBImpl.c"
"src/tsdb/tsdbCommit.c"
"src/tsdb/tsdbCommit.c"
"src/tsdb/tsdbCommit2.c"
"src/tsdb/tsdbCommit2.c"
"src/tsdb/tsdbCompact.c"
"src/tsdb/tsdbFile.c"
"src/tsdb/tsdbFile.c"
"src/tsdb/tsdbFS.c"
"src/tsdb/tsdbFS.c"
"src/tsdb/tsdb
Mai
n.c"
"src/tsdb/tsdb
Ope
n.c"
"src/tsdb/tsdbMemTable.c"
"src/tsdb/tsdbMemTable.c"
"src/tsdb/tsdbRead.c"
"src/tsdb/tsdbRead.c"
"src/tsdb/tsdbReadImpl.c"
"src/tsdb/tsdbReadImpl.c"
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
75cad6e3
...
@@ -68,6 +68,7 @@ void vnodeStop(SVnode *pVnode);
...
@@ -68,6 +68,7 @@ void vnodeStop(SVnode *pVnode);
int64_t
vnodeGetSyncHandle
(
SVnode
*
pVnode
);
int64_t
vnodeGetSyncHandle
(
SVnode
*
pVnode
);
void
vnodeGetSnapshot
(
SVnode
*
pVnode
,
SSnapshot
*
pSnapshot
);
void
vnodeGetSnapshot
(
SVnode
*
pVnode
,
SSnapshot
*
pSnapshot
);
void
vnodeGetInfo
(
SVnode
*
pVnode
,
const
char
**
dbname
,
int32_t
*
vgId
);
// meta
// meta
typedef
struct
SMeta
SMeta
;
// todo: remove
typedef
struct
SMeta
SMeta
;
// todo: remove
...
@@ -76,6 +77,7 @@ typedef struct SMetaEntry SMetaEntry;
...
@@ -76,6 +77,7 @@ typedef struct SMetaEntry SMetaEntry;
void
metaReaderInit
(
SMetaReader
*
pReader
,
SMeta
*
pMeta
,
int32_t
flags
);
void
metaReaderInit
(
SMetaReader
*
pReader
,
SMeta
*
pMeta
,
int32_t
flags
);
void
metaReaderClear
(
SMetaReader
*
pReader
);
void
metaReaderClear
(
SMetaReader
*
pReader
);
int
metaGetTableEntryByUid
(
SMetaReader
*
pReader
,
tb_uid_t
uid
);
int
metaReadNext
(
SMetaReader
*
pReader
);
int
metaReadNext
(
SMetaReader
*
pReader
);
#if 1 // refact APIs below (TODO)
#if 1 // refact APIs below (TODO)
...
@@ -133,10 +135,6 @@ int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *p
...
@@ -133,10 +135,6 @@ int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *p
// need to reposition
// need to reposition
// structs
// structs
struct
SMetaCfg
{
uint64_t
lruSize
;
};
struct
STsdbCfg
{
struct
STsdbCfg
{
int8_t
precision
;
int8_t
precision
;
int8_t
update
;
int8_t
update
;
...
@@ -145,10 +143,9 @@ struct STsdbCfg {
...
@@ -145,10 +143,9 @@ struct STsdbCfg {
int32_t
days
;
int32_t
days
;
int32_t
minRows
;
int32_t
minRows
;
int32_t
maxRows
;
int32_t
maxRows
;
int32_t
keep2
;
int32_t
keep0
;
int32_t
keep0
;
int32_t
keep1
;
int32_t
keep1
;
uint64_t
lruCacheSize
;
int32_t
keep2
;
SArray
*
retentions
;
SArray
*
retentions
;
};
};
...
@@ -160,8 +157,6 @@ struct SVnodeCfg {
...
@@ -160,8 +157,6 @@ struct SVnodeCfg {
int32_t
szCache
;
int32_t
szCache
;
uint64_t
szBuf
;
uint64_t
szBuf
;
bool
isHeap
;
bool
isHeap
;
uint32_t
ttl
;
uint32_t
keep
;
int8_t
streamMode
;
int8_t
streamMode
;
bool
isWeak
;
bool
isWeak
;
STsdbCfg
tsdbCfg
;
STsdbCfg
tsdbCfg
;
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
75cad6e3
...
@@ -46,12 +46,45 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKe
...
@@ -46,12 +46,45 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKe
// tsdbCommit ================
// tsdbCommit ================
#if 1
// tsdbFS ================
typedef
struct
STsdbFS
STsdbFS
;
typedef
struct
SSmaStat
SSmaStat
;
// tsdbSma ================
typedef
struct
SSmaEnv
SSmaEnv
;
typedef
struct
SSmaEnv
SSmaEnv
;
typedef
struct
SSmaEnvs
SSmaEnvs
;
typedef
struct
SSmaEnvs
SSmaEnvs
;
// structs
typedef
struct
{
int
minFid
;
int
midFid
;
int
maxFid
;
TSKEY
minKey
;
}
SRtn
;
struct
SSmaEnvs
{
int16_t
nTSma
;
int16_t
nRSma
;
SSmaEnv
*
pTSmaEnv
;
SSmaEnv
*
pRSmaEnv
;
};
struct
STsdb
{
char
*
path
;
SVnode
*
pVnode
;
bool
repoLocked
;
TdThreadMutex
mutex
;
STsdbCfg
config
;
STsdbMemTable
*
mem
;
STsdbMemTable
*
imem
;
SRtn
rtn
;
STsdbFS
*
fs
;
SSmaEnvs
smaEnvs
;
};
#if 1 // ======================================
typedef
struct
SSmaStat
SSmaStat
;
struct
STable
{
struct
STable
{
uint64_t
tid
;
uint64_t
tid
;
uint64_t
uid
;
uint64_t
uid
;
...
@@ -97,13 +130,6 @@ typedef struct {
...
@@ -97,13 +130,6 @@ typedef struct {
uint8_t
state
;
uint8_t
state
;
}
SDFile
;
}
SDFile
;
struct
SSmaEnvs
{
int16_t
nTSma
;
int16_t
nRSma
;
SSmaEnv
*
pTSmaEnv
;
SSmaEnv
*
pRSmaEnv
;
};
typedef
struct
{
typedef
struct
{
int
fid
;
int
fid
;
int8_t
state
;
// -128~127
int8_t
state
;
// -128~127
...
@@ -112,13 +138,6 @@ typedef struct {
...
@@ -112,13 +138,6 @@ typedef struct {
SDFile
files
[
TSDB_FILE_MAX
];
SDFile
files
[
TSDB_FILE_MAX
];
}
SDFileSet
;
}
SDFileSet
;
typedef
struct
{
int
minFid
;
int
midFid
;
int
maxFid
;
TSKEY
minKey
;
}
SRtn
;
struct
STbData
{
struct
STbData
{
tb_uid_t
uid
;
tb_uid_t
uid
;
TSKEY
keyMin
;
TSKEY
keyMin
;
...
@@ -155,7 +174,7 @@ typedef struct {
...
@@ -155,7 +174,7 @@ typedef struct {
SArray
*
sf
;
// sma data file array v2f1900.index_name_1
SArray
*
sf
;
// sma data file array v2f1900.index_name_1
}
SFSStatus
;
}
SFSStatus
;
typedef
struct
{
struct
STsdbFS
{
TdThreadRwlock
lock
;
TdThreadRwlock
lock
;
SFSStatus
*
cstatus
;
// current status
SFSStatus
*
cstatus
;
// current status
...
@@ -163,23 +182,9 @@ typedef struct {
...
@@ -163,23 +182,9 @@ typedef struct {
SHashObj
*
metaCacheComp
;
// meta cache for compact
SHashObj
*
metaCacheComp
;
// meta cache for compact
bool
intxn
;
bool
intxn
;
SFSStatus
*
nstatus
;
// new status
SFSStatus
*
nstatus
;
// new status
}
STsdbFS
;
struct
STsdb
{
char
*
path
;
SVnode
*
pVnode
;
int32_t
vgId
;
bool
repoLocked
;
TdThreadMutex
mutex
;
STsdbCfg
config
;
STsdbMemTable
*
mem
;
STsdbMemTable
*
imem
;
SRtn
rtn
;
STsdbFS
*
fs
;
SSmaEnvs
smaEnvs
;
};
};
#define REPO_ID(r)
((r)->vgId
)
#define REPO_ID(r)
TD_VID((r)->pVnode
)
#define REPO_CFG(r) (&(r)->config)
#define REPO_CFG(r) (&(r)->config)
#define REPO_FS(r) ((r)->fs)
#define REPO_FS(r) ((r)->fs)
#define REPO_META(r) ((r)->pVnode->pMeta)
#define REPO_META(r) ((r)->pVnode->pMeta)
...
@@ -507,12 +512,6 @@ static FORCE_INLINE void *taosTZfree(void *ptr) {
...
@@ -507,12 +512,6 @@ static FORCE_INLINE void *taosTZfree(void *ptr) {
// tsdbCommit
// tsdbCommit
typedef
struct
{
uint64_t
uid
;
int64_t
offset
;
int64_t
size
;
}
SKVRecord
;
void
tsdbGetRtnSnap
(
STsdb
*
pRepo
,
SRtn
*
pRtn
);
void
tsdbGetRtnSnap
(
STsdb
*
pRepo
,
SRtn
*
pRtn
);
static
FORCE_INLINE
int
TSDB_KEY_FID
(
TSKEY
key
,
int32_t
days
,
int8_t
precision
)
{
static
FORCE_INLINE
int
TSDB_KEY_FID
(
TSKEY
key
,
int32_t
days
,
int8_t
precision
)
{
...
@@ -891,66 +890,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) {
...
@@ -891,66 +890,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) {
return
0
;
return
0
;
}
}
// tsdbSma
// #define TSDB_SMA_TEST // remove after test finished
// struct SSmaEnv {
// TdThreadRwlock lock;
// SDiskID did;
// TDBEnv dbEnv; // TODO: If it's better to put it in smaIndex level?
// char *path; // relative path
// SSmaStat *pStat;
// };
// #define SMA_ENV_LOCK(env) ((env)->lock)
// #define SMA_ENV_DID(env) ((env)->did)
// #define SMA_ENV_ENV(env) ((env)->dbEnv)
// #define SMA_ENV_PATH(env) ((env)->path)
// #define SMA_ENV_STAT(env) ((env)->pStat)
// #define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems)
// void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv);
// void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv);
// #if 0
// int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
// int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
// #endif
// // internal func
// static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
// int32_t len = 0;
// len += taosEncodeFixedI64(pData, tsKey);
// len += taosEncodeFixedI64(pData, groupId);
// return len;
// }
// static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) {
// int code = taosThreadRwlockRdlock(&(pEnv->lock));
// if (code != 0) {
// terrno = TAOS_SYSTEM_ERROR(code);
// return -1;
// }
// return 0;
// }
// static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) {
// int code = taosThreadRwlockWrlock(&(pEnv->lock));
// if (code != 0) {
// terrno = TAOS_SYSTEM_ERROR(code);
// return -1;
// }
// return 0;
// }
// static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
// int code = taosThreadRwlockUnlock(&(pEnv->lock));
// if (code != 0) {
// terrno = TAOS_SYSTEM_ERROR(code);
// return -1;
// }
// return 0;
// }
typedef
struct
SSmaKey
SSmaKey
;
typedef
struct
SSmaKey
SSmaKey
;
struct
SSmaKey
{
struct
SSmaKey
{
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
75cad6e3
...
@@ -75,7 +75,6 @@ int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq*
...
@@ -75,7 +75,6 @@ int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq*
int
metaCreateTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateTbReq
*
pReq
);
int
metaCreateTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateTbReq
*
pReq
);
SSchemaWrapper
*
metaGetTableSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
,
bool
isinline
);
SSchemaWrapper
*
metaGetTableSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
,
bool
isinline
);
STSchema
*
metaGetTbTSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
);
STSchema
*
metaGetTbTSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
);
int
metaGetTableEntryByUid
(
SMetaReader
*
pReader
,
tb_uid_t
uid
);
int
metaGetTableEntryByName
(
SMetaReader
*
pReader
,
const
char
*
name
);
int
metaGetTableEntryByName
(
SMetaReader
*
pReader
,
const
char
*
name
);
int
metaGetTbNum
(
SMeta
*
pMeta
);
int
metaGetTbNum
(
SMeta
*
pMeta
);
SMCtbCursor
*
metaOpenCtbCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
SMCtbCursor
*
metaOpenCtbCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
75cad6e3
...
@@ -88,7 +88,7 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
...
@@ -88,7 +88,7 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
// preprocess req
// preprocess req
pReq
->
uid
=
tGenIdPI64
();
pReq
->
uid
=
tGenIdPI64
();
pReq
->
ctime
=
taosGetTimestamp
Sec
();
pReq
->
ctime
=
taosGetTimestamp
Ms
();
// validate req
// validate req
metaReaderInit
(
&
mr
,
pMeta
,
0
);
metaReaderInit
(
&
mr
,
pMeta
,
0
);
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
75cad6e3
...
@@ -752,334 +752,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
...
@@ -752,334 +752,7 @@ int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf) {
return
0
;
return
0
;
}
}
// // =================== Commit Meta Data
// =================== Commit Time-Series Data
// static int tsdbInitCommitMetaFile(STsdbRepo *pRepo, SMFile* pMf, bool open) {
// STsdbFS * pfs = REPO_FS(pRepo);
// SMFile * pOMFile = pfs->cstatus->pmf;
// SDiskID did;
// // Create/Open a meta file or open the existing file
// if (pOMFile == NULL) {
// // Create a new meta file
// did.level = TFS_PRIMARY_LEVEL;
// did.id = TFS_PRIMARY_ID;
// tsdbInitMFile(pMf, did, REPO_ID(pRepo), FS_TXN_VERSION(REPO_FS(pRepo)));
// if (open && tsdbCreateMFile(pMf, true) < 0) {
// tsdbError("vgId:%d failed to create META file since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// tsdbInfo("vgId:%d meta file %s is created to commit", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMf));
// } else {
// tsdbInitMFileEx(pMf, pOMFile);
// if (open && tsdbOpenMFile(pMf, O_WRONLY) < 0) {
// tsdbError("vgId:%d failed to open META file since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// }
// return 0;
// }
// static int tsdbCommitMeta(STsdbRepo *pRepo) {
// STsdbFS * pfs = REPO_FS(pRepo);
// SMemTable *pMem = pRepo->imem;
// SMFile * pOMFile = pfs->cstatus->pmf;
// SMFile mf;
// SActObj * pAct = NULL;
// SActCont * pCont = NULL;
// SListNode *pNode = NULL;
// ASSERT(pOMFile != NULL || listNEles(pMem->actList) > 0);
// if (listNEles(pMem->actList) <= 0) {
// // no meta data to commit, just keep the old meta file
// tsdbUpdateMFile(pfs, pOMFile);
// if (tsTsdbMetaCompactRatio > 0) {
// if (tsdbInitCommitMetaFile(pRepo, &mf, false) < 0) {
// return -1;
// }
// int ret = tsdbCompactMetaFile(pRepo, pfs, &mf);
// if (ret < 0) tsdbError("compact meta file error");
// return ret;
// }
// return 0;
// } else {
// if (tsdbInitCommitMetaFile(pRepo, &mf, true) < 0) {
// return -1;
// }
// }
// // Loop to write
// while ((pNode = tdListPopHead(pMem->actList)) != NULL) {
// pAct = (SActObj *)pNode->data;
// if (pAct->act == TSDB_UPDATE_META) {
// pCont = (SActCont *)POINTER_SHIFT(pAct, sizeof(SActObj));
// if (tsdbUpdateMetaRecord(pfs, &mf, pAct->uid, (void *)(pCont->cont), pCont->len, false) < 0) {
// tsdbError("vgId:%d failed to update META record, uid %" PRIu64 " since %s", REPO_ID(pRepo), pAct->uid,
// tstrerror(terrno));
// tsdbCloseMFile(&mf);
// (void)tsdbApplyMFileChange(&mf, pOMFile);
// // TODO: need to reload metaCache
// return -1;
// }
// } else if (pAct->act == TSDB_DROP_META) {
// if (tsdbDropMetaRecord(pfs, &mf, pAct->uid) < 0) {
// tsdbError("vgId:%d failed to drop META record, uid %" PRIu64 " since %s", REPO_ID(pRepo), pAct->uid,
// tstrerror(terrno));
// tsdbCloseMFile(&mf);
// tsdbApplyMFileChange(&mf, pOMFile);
// // TODO: need to reload metaCache
// return -1;
// }
// } else {
// ASSERT(false);
// }
// }
// if (tsdbUpdateMFileHeader(&mf) < 0) {
// tsdbError("vgId:%d failed to update META file header since %s, revert it", REPO_ID(pRepo), tstrerror(terrno));
// tsdbApplyMFileChange(&mf, pOMFile);
// // TODO: need to reload metaCache
// return -1;
// }
// TSDB_FILE_FSYNC(&mf);
// tsdbCloseMFile(&mf);
// tsdbUpdateMFile(pfs, &mf);
// if (tsTsdbMetaCompactRatio > 0 && tsdbCompactMetaFile(pRepo, pfs, &mf) < 0) {
// tsdbError("compact meta file error");
// }
// return 0;
// }
// int tsdbEncodeKVRecord(void **buf, SKVRecord *pRecord) {
// int tlen = 0;
// tlen += taosEncodeFixedU64(buf, pRecord->uid);
// tlen += taosEncodeFixedI64(buf, pRecord->offset);
// tlen += taosEncodeFixedI64(buf, pRecord->size);
// return tlen;
// }
// void *tsdbDecodeKVRecord(void *buf, SKVRecord *pRecord) {
// buf = taosDecodeFixedU64(buf, &(pRecord->uid));
// buf = taosDecodeFixedI64(buf, &(pRecord->offset));
// buf = taosDecodeFixedI64(buf, &(pRecord->size));
// return buf;
// }
// static int tsdbUpdateMetaRecord(STsdbFS *pfs, SMFile *pMFile, uint64_t uid, void *cont, int contLen, bool compact) {
// char buf[64] = "\0";
// void * pBuf = buf;
// SKVRecord rInfo;
// int64_t offset;
// // Seek to end of meta file
// offset = tsdbSeekMFile(pMFile, 0, SEEK_END);
// if (offset < 0) {
// return -1;
// }
// rInfo.offset = offset;
// rInfo.uid = uid;
// rInfo.size = contLen;
// int tlen = tsdbEncodeKVRecord((void **)(&pBuf), &rInfo);
// if (tsdbAppendMFile(pMFile, buf, tlen, NULL) < tlen) {
// return -1;
// }
// if (tsdbAppendMFile(pMFile, cont, contLen, NULL) < contLen) {
// return -1;
// }
// tsdbUpdateMFileMagic(pMFile, POINTER_SHIFT(cont, contLen - sizeof(TSCKSUM)));
// SHashObj* cache = compact ? pfs->metaCacheComp : pfs->metaCache;
// pMFile->info.nRecords++;
// SKVRecord *pRecord = taosHashGet(cache, (void *)&uid, sizeof(uid));
// if (pRecord != NULL) {
// pMFile->info.tombSize += (pRecord->size + sizeof(SKVRecord));
// } else {
// pMFile->info.nRecords++;
// }
// taosHashPut(cache, (void *)(&uid), sizeof(uid), (void *)(&rInfo), sizeof(rInfo));
// return 0;
// }
// static int tsdbDropMetaRecord(STsdbFS *pfs, SMFile *pMFile, uint64_t uid) {
// SKVRecord rInfo = {0};
// char buf[128] = "\0";
// SKVRecord *pRecord = taosHashGet(pfs->metaCache, (void *)(&uid), sizeof(uid));
// if (pRecord == NULL) {
// tsdbError("failed to drop META record with key %" PRIu64 " since not find", uid);
// return -1;
// }
// rInfo.offset = -pRecord->offset;
// rInfo.uid = pRecord->uid;
// rInfo.size = pRecord->size;
// void *pBuf = buf;
// tsdbEncodeKVRecord(&pBuf, &rInfo);
// if (tsdbAppendMFile(pMFile, buf, sizeof(SKVRecord), NULL) < 0) {
// return -1;
// }
// pMFile->info.magic = taosCalcChecksum(pMFile->info.magic, (uint8_t *)buf, sizeof(SKVRecord));
// pMFile->info.nDels++;
// pMFile->info.nRecords--;
// pMFile->info.tombSize += (rInfo.size + sizeof(SKVRecord) * 2);
// taosHashRemove(pfs->metaCache, (void *)(&uid), sizeof(uid));
// return 0;
// }
// static int tsdbCompactMetaFile(STsdbRepo *pRepo, STsdbFS *pfs, SMFile *pMFile) {
// float delPercent = (float)(pMFile->info.nDels) / (float)(pMFile->info.nRecords);
// float tombPercent = (float)(pMFile->info.tombSize) / (float)(pMFile->info.size);
// float compactRatio = (float)(tsTsdbMetaCompactRatio)/100;
// if (delPercent < compactRatio && tombPercent < compactRatio) {
// return 0;
// }
// if (tsdbOpenMFile(pMFile, O_RDONLY) < 0) {
// tsdbError("open meta file %s compact fail", pMFile->f.rname);
// return -1;
// }
// tsdbInfo("begin compact tsdb meta file, ratio:%d, nDels:%" PRId64 ",nRecords:%" PRId64 ",tombSize:%" PRId64
// ",size:%" PRId64,
// tsTsdbMetaCompactRatio, pMFile->info.nDels,pMFile->info.nRecords,pMFile->info.tombSize,pMFile->info.size);
// SMFile mf;
// SDiskID did;
// // first create tmp meta file
// did.level = TFS_PRIMARY_LEVEL;
// did.id = TFS_PRIMARY_ID;
// tsdbInitMFile(&mf, did, REPO_ID(pRepo), FS_TXN_VERSION(REPO_FS(pRepo)) + 1);
// if (tsdbCreateMFile(&mf, true) < 0) {
// tsdbError("vgId:%d failed to create META file since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// tsdbInfo("vgId:%d meta file %s is created to compact meta data", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(&mf));
// // second iterator metaCache
// int code = -1;
// int64_t maxBufSize = 1024;
// SKVRecord *pRecord;
// void *pBuf = NULL;
// pBuf = taosMemoryMalloc((size_t)maxBufSize);
// if (pBuf == NULL) {
// goto _err;
// }
// // init Comp
// assert(pfs->metaCacheComp == NULL);
// pfs->metaCacheComp = taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
// if (pfs->metaCacheComp == NULL) {
// goto _err;
// }
// pRecord = taosHashIterate(pfs->metaCache, NULL);
// while (pRecord) {
// if (tsdbSeekMFile(pMFile, pRecord->offset + sizeof(SKVRecord), SEEK_SET) < 0) {
// tsdbError("vgId:%d failed to seek file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile),
// tstrerror(terrno));
// goto _err;
// }
// if (pRecord->size > maxBufSize) {
// maxBufSize = pRecord->size;
// void* tmp = taosMemoryRealloc(pBuf, (size_t)maxBufSize);
// if (tmp == NULL) {
// goto _err;
// }
// pBuf = tmp;
// }
// int nread = (int)tsdbReadMFile(pMFile, pBuf, pRecord->size);
// if (nread < 0) {
// tsdbError("vgId:%d failed to read file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile),
// tstrerror(terrno));
// goto _err;
// }
// if (nread < pRecord->size) {
// tsdbError("vgId:%d failed to read file %s since file corrupted, expected read:%" PRId64 " actual read:%d",
// REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile), pRecord->size, nread);
// goto _err;
// }
// if (tsdbUpdateMetaRecord(pfs, &mf, pRecord->uid, pBuf, (int)pRecord->size, true) < 0) {
// tsdbError("vgId:%d failed to update META record, uid %" PRIu64 " since %s", REPO_ID(pRepo), pRecord->uid,
// tstrerror(terrno));
// goto _err;
// }
// pRecord = taosHashIterate(pfs->metaCache, pRecord);
// }
// code = 0;
// _err:
// if (code == 0) TSDB_FILE_FSYNC(&mf);
// tsdbCloseMFile(&mf);
// tsdbCloseMFile(pMFile);
// if (code == 0) {
// // rename meta.tmp -> meta
// tsdbInfo("vgId:%d meta file rename %s -> %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(&mf),
// TSDB_FILE_FULL_NAME(pMFile)); taosRename(mf.f.aname,pMFile->f.aname); tstrncpy(mf.f.aname, pMFile->f.aname,
// TSDB_FILENAME_LEN); tstrncpy(mf.f.rname, pMFile->f.rname, TSDB_FILENAME_LEN);
// // update current meta file info
// pfs->nstatus->pmf = NULL;
// tsdbUpdateMFile(pfs, &mf);
// taosHashCleanup(pfs->metaCache);
// pfs->metaCache = pfs->metaCacheComp;
// pfs->metaCacheComp = NULL;
// } else {
// // remove meta.tmp file
// taosRemoveFile(mf.f.aname);
// taosHashCleanup(pfs->metaCacheComp);
// pfs->metaCacheComp = NULL;
// }
// taosMemoryFreeClear(pBuf);
// ASSERT(mf.info.nDels == 0);
// ASSERT(mf.info.tombSize == 0);
// tsdbInfo("end compact tsdb meta file,code:%d,nRecords:%" PRId64 ",size:%" PRId64,
// code,mf.info.nRecords,mf.info.size);
// return code;
// }
// // =================== Commit Time-Series Data
// #if 0
// static bool tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey) {
// for (int i = 0; i < nIters; i++) {
// TSKEY nextKey = tsdbNextIterKey((iters + i)->pIter);
// if (nextKey != TSDB_DATA_TIMESTAMP_NULL && (nextKey >= minKey && nextKey <= maxKey)) return true;
// }
// return false;
// }
// #endif
static
int
tsdbCommitToTable
(
SCommitH
*
pCommith
,
int
tid
)
{
static
int
tsdbCommitToTable
(
SCommitH
*
pCommith
,
int
tid
)
{
SCommitIter
*
pIter
=
pCommith
->
iters
+
tid
;
SCommitIter
*
pIter
=
pCommith
->
iters
+
tid
;
TSKEY
nextKey
=
tsdbNextIterKey
(
pIter
->
pIter
);
TSKEY
nextKey
=
tsdbNextIterKey
(
pIter
->
pIter
);
...
...
source/dnode/vnode/src/tsdb/tsdbCompact.c
已删除
100644 → 0
浏览文件 @
b5246114
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if 0
#include "tsdb.h"
typedef struct {
STable * pTable;
SBlockIdx * pBlkIdx;
SBlockIdx bindex;
SBlockInfo *pInfo;
} STableCompactH;
typedef struct {
SRtn rtn;
SFSIter fsIter;
SArray * tbArray; // table array to cache table obj and block indexes
SReadH readh;
SDFileSet wSet;
SArray * aBlkIdx;
SArray * aSupBlk;
SDataCols *pDataCols;
} SCompactH;
#define TSDB_COMPACT_WSET(pComph) (&((pComph)->wSet))
#define TSDB_COMPACT_REPO(pComph) TSDB_READ_REPO(&((pComph)->readh))
#define TSDB_COMPACT_HEAD_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_HEAD)
#define TSDB_COMPACT_DATA_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_DATA)
#define TSDB_COMPACT_LAST_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_LAST)
#define TSDB_COMPACT_SMAD_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_SMAD)
#define TSDB_COMPACT_SMAL_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_SMAL)
#define TSDB_COMPACT_BUF(pComph) TSDB_READ_BUF(&((pComph)->readh))
#define TSDB_COMPACT_COMP_BUF(pComph) TSDB_READ_COMP_BUF(&((pComph)->readh))
static int tsdbAsyncCompact(STsdbRepo *pRepo);
static void tsdbStartCompact(STsdbRepo *pRepo);
static void tsdbEndCompact(STsdbRepo *pRepo, int eno);
static int tsdbCompactMeta(STsdbRepo *pRepo);
static int tsdbCompactTSData(STsdbRepo *pRepo);
static int tsdbCompactFSet(SCompactH *pComph, SDFileSet *pSet);
static bool tsdbShouldCompact(SCompactH *pComph);
static int tsdbInitCompactH(SCompactH *pComph, STsdbRepo *pRepo);
static void tsdbDestroyCompactH(SCompactH *pComph);
static int tsdbInitCompTbArray(SCompactH *pComph);
static void tsdbDestroyCompTbArray(SCompactH *pComph);
static int tsdbCacheFSetIndex(SCompactH *pComph);
static int tsdbCompactFSetInit(SCompactH *pComph, SDFileSet *pSet);
static void tsdbCompactFSetEnd(SCompactH *pComph);
static int tsdbCompactFSetImpl(SCompactH *pComph);
static int tsdbWriteBlockToRightFile(SCompactH *pComph, STable *pTable, SDataCols *pDataCols, void **ppBuf,
void **ppCBuf);
enum { TSDB_NO_COMPACT, TSDB_IN_COMPACT, TSDB_WAITING_COMPACT};
int tsdbCompact(STsdbRepo *pRepo) { return tsdbAsyncCompact(pRepo); }
void *tsdbCompactImpl(STsdbRepo *pRepo) {
// Check if there are files in TSDB FS to compact
if (REPO_FS(pRepo)->cstatus->pmf == NULL) {
tsdbInfo("vgId:%d no file to compact in FS", REPO_ID(pRepo));
return NULL;
}
tsdbStartCompact(pRepo);
if (tsdbCompactMeta(pRepo) < 0) {
tsdbError("vgId:%d failed to compact META data since %s", REPO_ID(pRepo), tstrerror(terrno));
goto _err;
}
if (tsdbCompactTSData(pRepo) < 0) {
tsdbError("vgId:%d failed to compact TS data since %s", REPO_ID(pRepo), tstrerror(terrno));
goto _err;
}
tsdbEndCompact(pRepo, TSDB_CODE_SUCCESS);
return NULL;
_err:
pRepo->code = terrno;
tsdbEndCompact(pRepo, terrno);
return NULL;
}
static int tsdbAsyncCompact(STsdbRepo *pRepo) {
if (pRepo->compactState != TSDB_NO_COMPACT) {
tsdbInfo("vgId:%d not compact tsdb again ", REPO_ID(pRepo));
return 0;
}
pRepo->compactState = TSDB_WAITING_COMPACT;
tsem_wait(&(pRepo->readyToCommit));
return tsdbScheduleCommit(pRepo, COMPACT_REQ);
}
static void tsdbStartCompact(STsdbRepo *pRepo) {
assert(pRepo->compactState != TSDB_IN_COMPACT);
tsdbInfo("vgId:%d start to compact!", REPO_ID(pRepo));
tsdbStartFSTxn(pRepo, 0, 0);
pRepo->code = TSDB_CODE_SUCCESS;
pRepo->compactState = TSDB_IN_COMPACT;
}
static void tsdbEndCompact(STsdbRepo *pRepo, int eno) {
if (eno != TSDB_CODE_SUCCESS) {
tsdbEndFSTxnWithError(REPO_FS(pRepo));
} else {
tsdbEndFSTxn(pRepo);
}
pRepo->compactState = TSDB_NO_COMPACT;
tsdbInfo("vgId:%d compact over, %s", REPO_ID(pRepo), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed");
tsem_post(&(pRepo->readyToCommit));
}
static int tsdbCompactMeta(STsdbRepo *pRepo) {
STsdbFS *pfs = REPO_FS(pRepo);
tsdbUpdateMFile(pfs, pfs->cstatus->pmf);
return 0;
}
static int tsdbCompactTSData(STsdbRepo *pRepo) {
SCompactH compactH;
SDFileSet *pSet = NULL;
tsdbDebug("vgId:%d start to compact TS data", REPO_ID(pRepo));
// If no file, just return 0;
if (taosArrayGetSize(REPO_FS(pRepo)->cstatus->df) <= 0) {
tsdbDebug("vgId:%d no TS data file to compact, compact over", REPO_ID(pRepo));
return 0;
}
if (tsdbInitCompactH(&compactH, pRepo) < 0) {
return -1;
}
while ((pSet = tsdbFSIterNext(&(compactH.fsIter)))) {
// Remove those expired files
if (pSet->fid < compactH.rtn.minFid) {
tsdbInfo("vgId:%d FSET %d on level %d disk id %d expires, remove it", REPO_ID(pRepo), pSet->fid,
TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet));
continue;
}
if (TSDB_FSET_LEVEL(pSet) == TFS_MAX_LEVEL) {
tsdbDebug("vgId:%d FSET %d on level %d, should not compact", REPO_ID(pRepo), pSet->fid, TFS_MAX_LEVEL);
tsdbUpdateDFileSet(REPO_FS(pRepo), pSet);
continue;
}
if (tsdbCompactFSet(&compactH, pSet) < 0) {
tsdbDestroyCompactH(&compactH);
tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno));
return -1;
}
}
tsdbDestroyCompactH(&compactH);
tsdbDebug("vgId:%d compact TS data over", REPO_ID(pRepo));
return 0;
}
static int tsdbCompactFSet(SCompactH *pComph, SDFileSet *pSet) {
STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph);
SDiskID did;
tsdbDebug("vgId:%d start to compact FSET %d on level %d id %d", REPO_ID(pRepo), pSet->fid, TSDB_FSET_LEVEL(pSet),
TSDB_FSET_ID(pSet));
if (tsdbCompactFSetInit(pComph, pSet) < 0) {
return -1;
}
if (!tsdbShouldCompact(pComph)) {
tsdbDebug("vgId:%d no need to compact FSET %d", REPO_ID(pRepo), pSet->fid);
if (tsdbApplyRtnOnFSet(TSDB_COMPACT_REPO(pComph), pSet, &(pComph->rtn)) < 0) {
tsdbCompactFSetEnd(pComph);
return -1;
}
} else {
// Create new fset as compacted fset
if (tfsAllocDisk(pRepo->pTfs, tsdbGetFidLevel(pSet->fid, &(pComph->rtn)), &did) < 0) {
terrno = TSDB_CODE_TDB_NO_AVAIL_DISK;
tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno));
tsdbCompactFSetEnd(pComph);
return -1;
}
tsdbInitDFileSet(TSDB_COMPACT_WSET(pComph), did, REPO_ID(pRepo), TSDB_FSET_FID(pSet),
FS_TXN_VERSION(REPO_FS(pRepo)));
if (tsdbCreateDFileSet(TSDB_COMPACT_WSET(pComph), true) < 0) {
tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno));
tsdbCompactFSetEnd(pComph);
return -1;
}
if (tsdbCompactFSetImpl(pComph) < 0) {
tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph));
tsdbRemoveDFileSet(TSDB_COMPACT_WSET(pComph));
tsdbCompactFSetEnd(pComph);
return -1;
}
tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph));
tsdbUpdateDFileSet(REPO_FS(pRepo), TSDB_COMPACT_WSET(pComph));
tsdbDebug("vgId:%d FSET %d compact over", REPO_ID(pRepo), pSet->fid);
}
tsdbCompactFSetEnd(pComph);
return 0;
}
static bool tsdbShouldCompact(SCompactH *pComph) {
STsdbRepo * pRepo = TSDB_COMPACT_REPO(pComph);
STsdbCfg * pCfg = REPO_CFG(pRepo);
SReadH * pReadh = &(pComph->readh);
STableCompactH *pTh;
SBlock * pBlock;
int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock);
SDFile * pDataF = TSDB_READ_DATA_FILE(pReadh);
SDFile * pLastF = TSDB_READ_LAST_FILE(pReadh);
int tblocks = 0; // total blocks
int nSubBlocks = 0; // # of blocks with sub-blocks
int nSmallBlocks = 0; // # of blocks with rows < defaultRows
int64_t tsize = 0;
for (size_t i = 0; i < taosArrayGetSize(pComph->tbArray); i++) {
pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, i);
if (pTh->pTable == NULL || pTh->pBlkIdx == NULL) continue;
for (size_t bidx = 0; bidx < pTh->pBlkIdx->numOfBlocks; bidx++) {
tblocks++;
pBlock = pTh->pInfo->blocks + bidx;
if (pBlock->numOfRows < defaultRows) {
nSmallBlocks++;
}
if (pBlock->numOfSubBlocks > 1) {
nSubBlocks++;
for (int k = 0; k < pBlock->numOfSubBlocks; k++) {
SBlock *iBlock = ((SBlock *)POINTER_SHIFT(pTh->pInfo, pBlock->offset)) + k;
tsize = tsize + iBlock->len;
}
} else if (pBlock->numOfSubBlocks == 1) {
tsize += pBlock->len;
} else {
ASSERT(0);
}
}
}
return (((nSubBlocks * 1.0 / tblocks) > 0.33) || ((nSmallBlocks * 1.0 / tblocks) > 0.33) ||
(tsize * 1.0 / (pDataF->info.size + pLastF->info.size - 2 * TSDB_FILE_HEAD_SIZE) < 0.85));
}
static int tsdbInitCompactH(SCompactH *pComph, STsdbRepo *pRepo) {
STsdbCfg *pCfg = REPO_CFG(pRepo);
memset(pComph, 0, sizeof(*pComph));
TSDB_FSET_SET_CLOSED(TSDB_COMPACT_WSET(pComph));
tsdbGetRtnSnap(pRepo, &(pComph->rtn));
tsdbFSIterInit(&(pComph->fsIter), REPO_FS(pRepo), TSDB_FS_ITER_FORWARD);
if (tsdbInitReadH(&(pComph->readh), pRepo) < 0) {
return -1;
}
if (tsdbInitCompTbArray(pComph) < 0) {
tsdbDestroyCompactH(pComph);
return -1;
}
pComph->aBlkIdx = taosArrayInit(1024, sizeof(SBlockIdx));
if (pComph->aBlkIdx == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbDestroyCompactH(pComph);
return -1;
}
pComph->aSupBlk = taosArrayInit(1024, sizeof(SBlock));
if (pComph->aSupBlk == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbDestroyCompactH(pComph);
return -1;
}
pComph->pDataCols = tdNewDataCols(0, pCfg->maxRowsPerFileBlock);
if (pComph->pDataCols == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbDestroyCompactH(pComph);
return -1;
}
return 0;
}
static void tsdbDestroyCompactH(SCompactH *pComph) {
pComph->pDataCols = tdFreeDataCols(pComph->pDataCols);
pComph->aSupBlk = taosArrayDestroy(pComph->aSupBlk);
pComph->aBlkIdx = taosArrayDestroy(pComph->aBlkIdx);
tsdbDestroyCompTbArray(pComph);
tsdbDestroyReadH(&(pComph->readh));
tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph));
}
static int tsdbInitCompTbArray(SCompactH *pComph) { // Init pComp->tbArray
STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph);
STsdbMeta *pMeta = pRepo->tsdbMeta;
if (tsdbRLockRepoMeta(pRepo) < 0) return -1;
pComph->tbArray = taosArrayInit(pMeta->maxTables, sizeof(STableCompactH));
if (pComph->tbArray == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbUnlockRepoMeta(pRepo);
return -1;
}
// Note here must start from 0
for (int i = 0; i < pMeta->maxTables; i++) {
STableCompactH ch = {0};
if (pMeta->tables[i] != NULL) {
tsdbRefTable(pMeta->tables[i]);
ch.pTable = pMeta->tables[i];
}
if (taosArrayPush(pComph->tbArray, &ch) == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbUnlockRepoMeta(pRepo);
return -1;
}
}
if (tsdbUnlockRepoMeta(pRepo) < 0) return -1;
return 0;
}
static void tsdbDestroyCompTbArray(SCompactH *pComph) {
STableCompactH *pTh;
if (pComph->tbArray == NULL) return;
for (size_t i = 0; i < taosArrayGetSize(pComph->tbArray); i++) {
pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, i);
if (pTh->pTable) {
tsdbUnRefTable(pTh->pTable);
}
pTh->pInfo = taosTZfree(pTh->pInfo);
}
pComph->tbArray = taosArrayDestroy(pComph->tbArray);
}
static int tsdbCacheFSetIndex(SCompactH *pComph) {
SReadH *pReadH = &(pComph->readh);
if (tsdbLoadBlockIdx(pReadH) < 0) {
return -1;
}
for (int tid = 1; tid < taosArrayGetSize(pComph->tbArray); tid++) {
STableCompactH *pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, tid);
pTh->pBlkIdx = NULL;
if (pTh->pTable == NULL) continue;
if (tsdbSetReadTable(pReadH, pTh->pTable) < 0) {
return -1;
}
if (pReadH->pBlkIdx == NULL) continue;
pTh->bindex = *(pReadH->pBlkIdx);
pTh->pBlkIdx = &(pTh->bindex);
if (tsdbMakeRoom((void **)(&(pTh->pInfo)), pTh->pBlkIdx->len) < 0) {
return -1;
}
if (tsdbLoadBlockInfo(pReadH, (void *)(pTh->pInfo)) < 0) {
return -1;
}
}
return 0;
}
static int tsdbCompactFSetInit(SCompactH *pComph, SDFileSet *pSet) {
taosArrayClear(pComph->aBlkIdx);
taosArrayClear(pComph->aSupBlk);
if (tsdbSetAndOpenReadFSet(&(pComph->readh), pSet) < 0) {
return -1;
}
if (tsdbCacheFSetIndex(pComph) < 0) {
tsdbCloseAndUnsetFSet(&(pComph->readh));
return -1;
}
return 0;
}
static void tsdbCompactFSetEnd(SCompactH *pComph) { tsdbCloseAndUnsetFSet(&(pComph->readh)); }
static int tsdbCompactFSetImpl(SCompactH *pComph) {
STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph);
STsdbCfg * pCfg = REPO_CFG(pRepo);
SReadH * pReadh = &(pComph->readh);
SBlockIdx blkIdx;
void ** ppBuf = &(TSDB_COMPACT_BUF(pComph));
void ** ppCBuf = &(TSDB_COMPACT_COMP_BUF(pComph));
int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock);
taosArrayClear(pComph->aBlkIdx);
for (int tid = 1; tid < taosArrayGetSize(pComph->tbArray); tid++) {
STableCompactH *pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, tid);
STSchema * pSchema;
if (pTh->pTable == NULL || pTh->pBlkIdx == NULL) continue;
pSchema = tsdbGetTableSchemaImpl(pTh->pTable, true, true, -1);
taosArrayClear(pComph->aSupBlk);
if ((tdInitDataCols(pComph->pDataCols, pSchema) < 0) || (tdInitDataCols(pReadh->pDCols[0], pSchema) < 0) ||
(tdInitDataCols(pReadh->pDCols[1], pSchema) < 0)) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
}
tdFreeSchema(pSchema);
// Loop to compact each block data
for (int i = 0; i < pTh->pBlkIdx->numOfBlocks; i++) {
SBlock *pBlock = pTh->pInfo->blocks + i;
// Load the block data
if (tsdbLoadBlockData(pReadh, pBlock, pTh->pInfo) < 0) {
return -1;
}
// Merge pComph->pDataCols and pReadh->pDCols[0] and write data to file
if (pComph->pDataCols->numOfRows == 0 && pBlock->numOfRows >= defaultRows) {
if (tsdbWriteBlockToRightFile(pComph, pTh->pTable, pReadh->pDCols[0], ppBuf, ppCBuf) < 0) {
return -1;
}
} else {
int ridx = 0;
while (true) {
if (pReadh->pDCols[0]->numOfRows - ridx == 0) break;
int rowsToMerge = TMIN(pReadh->pDCols[0]->numOfRows - ridx, defaultRows - pComph->pDataCols->numOfRows);
tdMergeDataCols(pComph->pDataCols, pReadh->pDCols[0], rowsToMerge, &ridx, pCfg->update != TD_ROW_PARTIAL_UPDATE);
if (pComph->pDataCols->numOfRows < defaultRows) {
break;
}
if (tsdbWriteBlockToRightFile(pComph, pTh->pTable, pComph->pDataCols, ppBuf, ppCBuf) < 0) {
return -1;
}
tdResetDataCols(pComph->pDataCols);
}
}
}
if (pComph->pDataCols->numOfRows > 0 &&
tsdbWriteBlockToRightFile(pComph, pTh->pTable, pComph->pDataCols, ppBuf, ppCBuf) < 0) {
return -1;
}
if (tsdbWriteBlockInfoImpl(TSDB_COMPACT_HEAD_FILE(pComph), pTh->pTable, pComph->aSupBlk, NULL, ppBuf, &blkIdx) <
0) {
return -1;
}
if ((blkIdx.numOfBlocks > 0) && (taosArrayPush(pComph->aBlkIdx, (void *)(&blkIdx)) == NULL)) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
}
}
if (tsdbWriteBlockIdx(TSDB_COMPACT_HEAD_FILE(pComph), pComph->aBlkIdx, ppBuf) < 0) {
return -1;
}
return 0;
}
static int tsdbWriteBlockToRightFile(SCompactH *pComph, STable *pTable, SDataCols *pDataCols, void **ppBuf,
void **ppCBuf) {
STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph);
STsdbCfg * pCfg = REPO_CFG(pRepo);
SDFile * pDFile;
bool isLast;
SBlock block;
ASSERT(pDataCols->numOfRows > 0);
if (pDataCols->numOfRows < pCfg->minRowsPerFileBlock) {
pDFile = TSDB_COMPACT_LAST_FILE(pComph);
isLast = true;
} else {
pDFile = TSDB_COMPACT_DATA_FILE(pComph);
isLast = false;
}
if (tsdbWriteBlockImpl(pRepo, pTable, pDFile, pDataCols, &block, isLast, true, ppBuf, ppCBuf) < 0) {
return -1;
}
if (taosArrayPush(pComph->aSupBlk, (void *)(&block)) == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
}
return 0;
}
#endif
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
75cad6e3
...
@@ -246,62 +246,6 @@ void *tsdbFreeFS(STsdbFS *pfs) {
...
@@ -246,62 +246,6 @@ void *tsdbFreeFS(STsdbFS *pfs) {
return
NULL
;
return
NULL
;
}
}
// static int tsdbProcessExpiredFS(STsdb *pRepo) {
// tsdbStartFSTxn(pRepo, 0, 0);
// // if (tsdbCreateMeta(pRepo) < 0) {
// // tsdbError("vgId:%d failed to create meta since %s", REPO_ID(pRepo), tstrerror(terrno));
// // return -1;
// // }
// if (tsdbApplyRtn(pRepo) < 0) {
// tsdbEndFSTxnWithError(REPO_FS(pRepo));
// tsdbError("vgId:%d failed to apply rtn since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// if (tsdbEndFSTxn(pRepo) < 0) {
// tsdbError("vgId:%d failed to end fs txn since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// return 0;
// }
// static int tsdbCreateMeta(STsdb *pRepo) {
// STsdbFS *pfs = REPO_FS(pRepo);
// SMFile * pOMFile = pfs->cstatus->pmf;
// SMFile mf;
// SDiskID did;
// if (pOMFile != NULL) {
// // keep the old meta file
// tsdbUpdateMFile(pfs, pOMFile);
// return 0;
// }
// // Create a new meta file
// did.level = TFS_PRIMARY_LEVEL;
// did.id = TFS_PRIMARY_ID;
// tsdbInitMFile(&mf, did, REPO_ID(pRepo), FS_TXN_VERSION(REPO_FS(pRepo)));
// if (tsdbCreateMFile(&mf, true) < 0) {
// tsdbError("vgId:%d failed to create META file since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// tsdbInfo("vgId:%d meta file %s is created", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(&mf));
// if (tsdbUpdateMFileHeader(&mf) < 0) {
// tsdbError("vgId:%d failed to update META file header since %s, revert it", REPO_ID(pRepo), tstrerror(terrno));
// tsdbApplyMFileChange(&mf, pOMFile);
// return -1;
// }
// TSDB_FILE_FSYNC(&mf);
// tsdbCloseMFile(&mf);
// tsdbUpdateMFile(pfs, &mf);
// return 0;
// }
int
tsdbOpenFS
(
STsdb
*
pRepo
)
{
int
tsdbOpenFS
(
STsdb
*
pRepo
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
char
current
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
current
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
...
@@ -644,7 +588,7 @@ static int tsdbComparFidFSet(const void *arg1, const void *arg2) {
...
@@ -644,7 +588,7 @@ static int tsdbComparFidFSet(const void *arg1, const void *arg2) {
}
}
static
void
tsdbGetTxnFname
(
STsdb
*
pRepo
,
TSDB_TXN_FILE_T
ftype
,
char
fname
[])
{
static
void
tsdbGetTxnFname
(
STsdb
*
pRepo
,
TSDB_TXN_FILE_T
ftype
,
char
fname
[])
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s/vnode/vnode%d/tsdb/%s"
,
tfsGetPrimaryPath
(
REPO_TFS
(
pRepo
)),
pRepo
->
vgId
,
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s/vnode/vnode%d/tsdb/%s"
,
tfsGetPrimaryPath
(
REPO_TFS
(
pRepo
)),
REPO_ID
(
pRepo
)
,
tsdbTxnFname
[
ftype
]);
tsdbTxnFname
[
ftype
]);
}
}
...
@@ -769,142 +713,6 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) {
...
@@ -769,142 +713,6 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) {
return
0
;
return
0
;
}
}
// int tsdbLoadMetaCache(STsdb *pRepo, bool recoverMeta) {
// char tbuf[128];
// STsdbFS * pfs = REPO_FS(pRepo);
// SMFile mf;
// SMFile * pMFile = &mf;
// void * pBuf = NULL;
// SKVRecord rInfo;
// int64_t maxBufSize = 0;
// SMFInfo minfo;
// taosHashClear(pfs->metaCache);
// // No meta file, just return
// if (pfs->cstatus->pmf == NULL) return 0;
// mf = pfs->cstatus->mf;
// // Load cache first
// if (tsdbOpenMFile(pMFile, O_RDONLY) < 0) {
// return -1;
// }
// if (tsdbLoadMFileHeader(pMFile, &minfo) < 0) {
// tsdbCloseMFile(pMFile);
// return -1;
// }
// while (true) {
// int64_t tsize = tsdbReadMFile(pMFile, tbuf, sizeof(SKVRecord));
// if (tsize == 0) break;
// if (tsize < 0) {
// tsdbError("vgId:%d failed to read META file since %s", REPO_ID(pRepo), tstrerror(terrno));
// return -1;
// }
// if (tsize < sizeof(SKVRecord)) {
// tsdbError("vgId:%d failed to read %" PRIzu " bytes from file %s", REPO_ID(pRepo), sizeof(SKVRecord),
// TSDB_FILE_FULL_NAME(pMFile));
// terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
// tsdbCloseMFile(pMFile);
// return -1;
// }
// void *ptr = tsdbDecodeKVRecord(tbuf, &rInfo);
// ASSERT(POINTER_DISTANCE(ptr, tbuf) == sizeof(SKVRecord));
// // ASSERT((rInfo.offset > 0) ? (pStore->info.size == rInfo.offset) : true);
// if (rInfo.offset < 0) {
// taosHashRemove(pfs->metaCache, (void *)(&rInfo.uid), sizeof(rInfo.uid));
// #if 0
// pStore->info.size += sizeof(SKVRecord);
// pStore->info.nRecords--;
// pStore->info.nDels++;
// pStore->info.tombSize += (rInfo.size + sizeof(SKVRecord) * 2);
// #endif
// } else {
// ASSERT(rInfo.offset > 0 && rInfo.size > 0);
// if (taosHashPut(pfs->metaCache, (void *)(&rInfo.uid), sizeof(rInfo.uid), &rInfo, sizeof(rInfo)) < 0) {
// tsdbError("vgId:%d failed to load meta cache from file %s since OOM", REPO_ID(pRepo),
// TSDB_FILE_FULL_NAME(pMFile));
// terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
// tsdbCloseMFile(pMFile);
// return -1;
// }
// maxBufSize = TMAX(maxBufSize, rInfo.size);
// if (tsdbSeekMFile(pMFile, rInfo.size, SEEK_CUR) < 0) {
// tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile),
// tstrerror(terrno));
// tsdbCloseMFile(pMFile);
// return -1;
// }
// #if 0
// pStore->info.size += (sizeof(SKVRecord) + rInfo.size);
// pStore->info.nRecords++;
// #endif
// }
// }
// if (recoverMeta) {
// pBuf = taosMemoryMalloc((size_t)maxBufSize);
// if (pBuf == NULL) {
// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
// tsdbCloseMFile(pMFile);
// return -1;
// }
// SKVRecord *pRecord = taosHashIterate(pfs->metaCache, NULL);
// while (pRecord) {
// if (tsdbSeekMFile(pMFile, pRecord->offset + sizeof(SKVRecord), SEEK_SET) < 0) {
// tsdbError("vgId:%d failed to seek file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile),
// tstrerror(terrno));
// taosMemoryFreeClear(pBuf);
// tsdbCloseMFile(pMFile);
// return -1;
// }
// int nread = (int)tsdbReadMFile(pMFile, pBuf, pRecord->size);
// if (nread < 0) {
// tsdbError("vgId:%d failed to read file %s since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile),
// tstrerror(terrno));
// taosMemoryFreeClear(pBuf);
// tsdbCloseMFile(pMFile);
// return -1;
// }
// if (nread < pRecord->size) {
// tsdbError("vgId:%d failed to read file %s since file corrupted, expected read:%" PRId64 " actual read:%d",
// REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile), pRecord->size, nread);
// terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
// taosMemoryFreeClear(pBuf);
// tsdbCloseMFile(pMFile);
// return -1;
// }
// if (tsdbRestoreTable(pRepo, pBuf, (int)pRecord->size) < 0) {
// tsdbError("vgId:%d failed to restore table, uid %" PRId64 ", since %s" PRIu64, REPO_ID(pRepo), pRecord->uid,
// tstrerror(terrno));
// taosMemoryFreeClear(pBuf);
// tsdbCloseMFile(pMFile);
// return -1;
// }
// pRecord = taosHashIterate(pfs->metaCache, pRecord);
// }
// tsdbOrgMeta(pRepo);
// }
// tsdbCloseMFile(pMFile);
// taosMemoryFreeClear(pBuf);
// return 0;
// }
static
int
tsdbScanRootDir
(
STsdb
*
pRepo
)
{
static
int
tsdbScanRootDir
(
STsdb
*
pRepo
)
{
char
rootDir
[
TSDB_FILENAME_LEN
];
char
rootDir
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
...
@@ -983,127 +791,6 @@ static bool tsdbIsTFileInFS(STsdbFS *pfs, const STfsFile *pf) {
...
@@ -983,127 +791,6 @@ static bool tsdbIsTFileInFS(STsdbFS *pfs, const STfsFile *pf) {
return
false
;
return
false
;
}
}
// static int tsdbRestoreMeta(STsdb *pRepo) {
// char rootDir[TSDB_FILENAME_LEN];
// char bname[TSDB_FILENAME_LEN];
// STfsDir * tdir = NULL;
// const STfsFile *pf = NULL;
// const char * pattern = "^meta(-ver[0-9]+)?$";
// regex_t regex;
// STsdbFS * pfs = REPO_FS(pRepo);
// regcomp(®ex, pattern, REG_EXTENDED);
// tsdbInfo("vgId:%d try to restore meta", REPO_ID(pRepo));
// tsdbGetRootDir(REPO_ID(pRepo), rootDir);
// tdir = tfsOpendir(rootDir);
// if (tdir == NULL) {
// tsdbError("vgId:%d failed to open dir %s since %s", REPO_ID(pRepo), rootDir, tstrerror(terrno));
// regfree(®ex);
// return -1;
// }
// while ((pf = tfsReaddir(tdir))) {
// tfsBasename(pf, bname);
// if (strcmp(bname, "data") == 0) {
// // Skip the data/ directory
// continue;
// }
// if (strcmp(bname, tsdbTxnFname[TSDB_TXN_TEMP_FILE]) == 0) {
// // Skip current.t file
// tsdbInfo("vgId:%d file %s exists, remove it", REPO_ID(pRepo), pf->aname);
// (void)tfsremove(pf);
// continue;
// }
// int code = regexec(®ex, bname, 0, NULL, 0);
// if (code == 0) {
// // Match
// if (pfs->cstatus->pmf != NULL) {
// tsdbError("vgId:%d failed to restore meta since two file exists, file1 %s and file2 %s", REPO_ID(pRepo),
// TSDB_FILE_FULL_NAME(pfs->cstatus->pmf), pf->aname);
// terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
// tfsClosedir(tdir);
// regfree(®ex);
// return -1;
// } else {
// uint32_t _version = 0;
// if (strcmp(bname, "meta") != 0) {
// sscanf(bname, "meta-ver%" PRIu32, &_version);
// pfs->cstatus->meta.version = _version;
// }
// pfs->cstatus->pmf = &(pfs->cstatus->mf);
// pfs->cstatus->pmf->f = *pf;
// TSDB_FILE_SET_CLOSED(pfs->cstatus->pmf);
// if (tsdbOpenMFile(pfs->cstatus->pmf, O_RDONLY) < 0) {
// tsdbError("vgId:%d failed to restore meta since %s", REPO_ID(pRepo), tstrerror(terrno));
// tfsClosedir(tdir);
// regfree(®ex);
// return -1;
// }
// if (tsdbLoadMFileHeader(pfs->cstatus->pmf, &(pfs->cstatus->pmf->info)) < 0) {
// tsdbError("vgId:%d failed to restore meta since %s", REPO_ID(pRepo), tstrerror(terrno));
// tsdbCloseMFile(pfs->cstatus->pmf);
// tfsClosedir(tdir);
// regfree(®ex);
// return -1;
// }
// if (tsdbForceKeepFile) {
// struct stat tfstat;
// // Get real file size
// if (fstat(pfs->cstatus->pmf->fd, &tfstat) < 0) {
// terrno = TAOS_SYSTEM_ERROR(errno);
// tsdbCloseMFile(pfs->cstatus->pmf);
// tfsClosedir(tdir);
// regfree(®ex);
// return -1;
// }
// if (pfs->cstatus->pmf->info.size != tfstat.st_size) {
// int64_t tfsize = pfs->cstatus->pmf->info.size;
// pfs->cstatus->pmf->info.size = tfstat.st_size;
// tsdbInfo("vgId:%d file %s header size is changed from %" PRId64 " to %" PRId64, REPO_ID(pRepo),
// TSDB_FILE_FULL_NAME(pfs->cstatus->pmf), tfsize, pfs->cstatus->pmf->info.size);
// }
// }
// tsdbCloseMFile(pfs->cstatus->pmf);
// }
// } else if (code == REG_NOMATCH) {
// // Not match
// tsdbInfo("vgId:%d invalid file %s exists, remove it", REPO_ID(pRepo), pf->aname);
// tfsremove(pf);
// continue;
// } else {
// // Has other error
// tsdbError("vgId:%d failed to restore meta file while run regexec since %s", REPO_ID(pRepo), strerror(code));
// terrno = TAOS_SYSTEM_ERROR(code);
// tfsClosedir(tdir);
// regfree(®ex);
// return -1;
// }
// }
// if (pfs->cstatus->pmf) {
// tsdbInfo("vgId:%d meta file %s is restored", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pfs->cstatus->pmf));
// } else {
// tsdbInfo("vgId:%d no meta file is restored", REPO_ID(pRepo));
// }
// tfsClosedir(tdir);
// regfree(®ex);
// return 0;
// }
static
int
tsdbRestoreDFileSet
(
STsdb
*
pRepo
)
{
static
int
tsdbRestoreDFileSet
(
STsdb
*
pRepo
)
{
char
dataDir
[
TSDB_FILENAME_LEN
];
char
dataDir
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
75cad6e3
...
@@ -33,271 +33,6 @@ static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo);
...
@@ -33,271 +33,6 @@ static int tsdbEncodeDFInfo(void **buf, SDFInfo *pInfo);
static
void
*
tsdbDecodeDFInfo
(
void
*
buf
,
SDFInfo
*
pInfo
);
static
void
*
tsdbDecodeDFInfo
(
void
*
buf
,
SDFInfo
*
pInfo
);
static
int
tsdbRollBackDFile
(
SDFile
*
pDFile
);
static
int
tsdbRollBackDFile
(
SDFile
*
pDFile
);
#if 0
// ============== SMFile
void tsdbInitMFile(SMFile *pMFile, SDiskID did, int vid, uint32_t ver) {
char fname[TSDB_FILENAME_LEN];
TSDB_FILE_SET_STATE(pMFile, TSDB_FILE_STATE_OK);
memset(&(pMFile->info), 0, sizeof(pMFile->info));
pMFile->info.magic = TSDB_FILE_INIT_MAGIC;
tsdbGetFilename(vid, 0, ver, TSDB_FILE_META, fname);
tfsInitFile(TSDB_FILE_F(pMFile), did.level, did.id, fname);
}
void tsdbInitMFileEx(SMFile *pMFile, const SMFile *pOMFile) {
*pMFile = *pOMFile;
TSDB_FILE_SET_CLOSED(pMFile);
}
int tsdbEncodeSMFile(void **buf, SMFile *pMFile) {
int tlen = 0;
tlen += tsdbEncodeMFInfo(buf, &(pMFile->info));
tlen += tfsEncodeFile(buf, &(pMFile->f));
return tlen;
}
void *tsdbDecodeSMFile(void *buf, SMFile *pMFile) {
buf = tsdbDecodeMFInfo(buf, &(pMFile->info));
buf = tfsDecodeFile(buf, &(pMFile->f));
TSDB_FILE_SET_CLOSED(pMFile);
return buf;
}
int tsdbEncodeSMFileEx(void **buf, SMFile *pMFile) {
int tlen = 0;
tlen += tsdbEncodeMFInfo(buf, &(pMFile->info));
tlen += taosEncodeString(buf, TSDB_FILE_FULL_NAME(pMFile));
return tlen;
}
void *tsdbDecodeSMFileEx(void *buf, SMFile *pMFile) {
char *aname;
buf = tsdbDecodeMFInfo(buf, &(pMFile->info));
buf = taosDecodeString(buf, &aname);
strncpy(TSDB_FILE_FULL_NAME(pMFile), aname, TSDB_FILENAME_LEN);
TSDB_FILE_SET_CLOSED(pMFile);
taosMemoryFreeClear(aname);
return buf;
}
int tsdbApplyMFileChange(SMFile *from, SMFile *to) {
if (from == NULL && to == NULL) return 0;
if (from != NULL) {
if (to == NULL) {
return tsdbRemoveMFile(from);
} else {
if (tfsIsSameFile(TSDB_FILE_F(from), TSDB_FILE_F(to))) {
if (from->info.size > to->info.size) {
tsdbRollBackMFile(to);
}
} else {
return tsdbRemoveMFile(from);
}
}
}
return 0;
}
int tsdbCreateMFile(SMFile *pMFile, bool updateHeader) {
ASSERT(pMFile->info.size == 0 && pMFile->info.magic == TSDB_FILE_INIT_MAGIC);
pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0755);
if (pMFile->fd < 0) {
if (errno == ENOENT) {
// Try to create directory recursively
char *s = strdup(TFILE_REL_NAME(&(pMFile->f)));
if (tfsMkdirRecurAt(dirname(s), TSDB_FILE_LEVEL(pMFile), TSDB_FILE_ID(pMFile)) < 0) {
taosMemoryFreeClear(s);
return -1;
}
taosMemoryFreeClear(s);
pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0755);
if (pMFile->fd < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
} else {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
}
if (!updateHeader) {
return 0;
}
pMFile->info.size += TSDB_FILE_HEAD_SIZE;
if (tsdbUpdateMFileHeader(pMFile) < 0) {
tsdbCloseMFile(pMFile);
tsdbRemoveMFile(pMFile);
return -1;
}
return 0;
}
int tsdbUpdateMFileHeader(SMFile *pMFile) {
char buf[TSDB_FILE_HEAD_SIZE] = "\0";
if (tsdbSeekMFile(pMFile, 0, SEEK_SET) < 0) {
return -1;
}
void *ptr = buf;
tsdbEncodeMFInfo(&ptr, TSDB_FILE_INFO(pMFile));
taosCalcChecksumAppend(0, (uint8_t *)buf, TSDB_FILE_HEAD_SIZE);
if (tsdbWriteMFile(pMFile, buf, TSDB_FILE_HEAD_SIZE) < 0) {
return -1;
}
return 0;
}
int tsdbLoadMFileHeader(SMFile *pMFile, SMFInfo *pInfo) {
char buf[TSDB_FILE_HEAD_SIZE] = "\0";
ASSERT(TSDB_FILE_OPENED(pMFile));
if (tsdbSeekMFile(pMFile, 0, SEEK_SET) < 0) {
return -1;
}
if (tsdbReadMFile(pMFile, buf, TSDB_FILE_HEAD_SIZE) < 0) {
return -1;
}
if (!taosCheckChecksumWhole((uint8_t *)buf, TSDB_FILE_HEAD_SIZE)) {
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
return -1;
}
tsdbDecodeMFInfo(buf, pInfo);
return 0;
}
int tsdbScanAndTryFixMFile(STsdb *pRepo) {
SMFile * pMFile = pRepo->fs->cstatus->pmf;
struct stat mfstat;
SMFile mf;
if (pMFile == NULL) {
// No meta file, no need to scan
return 0;
}
tsdbInitMFileEx(&mf, pMFile);
if (access(TSDB_FILE_FULL_NAME(pMFile), F_OK) != 0) {
tsdbError("vgId:%d meta file %s not exit, report to upper layer to fix it", REPO_ID(pRepo),
TSDB_FILE_FULL_NAME(pMFile));
pRepo->state |= TSDB_STATE_BAD_META;
TSDB_FILE_SET_STATE(pMFile, TSDB_FILE_STATE_BAD);
return 0;
}
if (stat(TSDB_FILE_FULL_NAME(&mf), &mfstat) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
if (pMFile->info.size < mfstat.st_size) {
if (tsdbOpenMFile(&mf, O_WRONLY) < 0) {
return -1;
}
if (taosFtruncate(mf.fd, mf.info.size) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
tsdbCloseMFile(&mf);
return -1;
}
if (tsdbUpdateMFileHeader(&mf) < 0) {
tsdbCloseMFile(&mf);
return -1;
}
tsdbCloseMFile(&mf);
tsdbInfo("vgId:%d file %s is truncated from %" PRId64 " to %" PRId64, REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile),
mfstat.st_size, pMFile->info.size);
} else if (pMFile->info.size > mfstat.st_size) {
tsdbError("vgId:%d meta file %s has wrong size %" PRId64 " expected %" PRId64 ", report to upper layer to fix it",
REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile), mfstat.st_size, pMFile->info.size);
pRepo->state |= TSDB_STATE_BAD_META;
TSDB_FILE_SET_STATE(pMFile, TSDB_FILE_STATE_BAD);
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
return 0;
} else {
tsdbDebug("vgId:%d meta file %s passes the scan", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pMFile));
}
return 0;
}
int tsdbEncodeMFInfo(void **buf, SMFInfo *pInfo) {
int tlen = 0;
tlen += taosEncodeVariantI64(buf, pInfo->size);
tlen += taosEncodeVariantI64(buf, pInfo->tombSize);
tlen += taosEncodeVariantI64(buf, pInfo->nRecords);
tlen += taosEncodeVariantI64(buf, pInfo->nDels);
tlen += taosEncodeFixedU32(buf, pInfo->magic);
return tlen;
}
void *tsdbDecodeMFInfo(void *buf, SMFInfo *pInfo) {
buf = taosDecodeVariantI64(buf, &(pInfo->size));
buf = taosDecodeVariantI64(buf, &(pInfo->tombSize));
buf = taosDecodeVariantI64(buf, &(pInfo->nRecords));
buf = taosDecodeVariantI64(buf, &(pInfo->nDels));
buf = taosDecodeFixedU32(buf, &(pInfo->magic));
return buf;
}
static int tsdbRollBackMFile(SMFile *pMFile) {
SMFile mf;
tsdbInitMFileEx(&mf, pMFile);
if (tsdbOpenMFile(&mf, O_WRONLY) < 0) {
return -1;
}
if (taosFtruncate(TSDB_FILE_FD(&mf), pMFile->info.size) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
tsdbCloseMFile(&mf);
return -1;
}
if (tsdbUpdateMFileHeader(&mf) < 0) {
tsdbCloseMFile(&mf);
return -1;
}
TSDB_FILE_FSYNC(&mf);
tsdbCloseMFile(&mf);
return 0;
}
#endif
// ============== Operations on SDFile
// ============== Operations on SDFile
void
tsdbInitDFile
(
STsdb
*
pRepo
,
SDFile
*
pDFile
,
SDiskID
did
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
)
{
void
tsdbInitDFile
(
STsdb
*
pRepo
,
SDFile
*
pDFile
,
SDiskID
did
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
)
{
char
fname
[
TSDB_FILENAME_LEN
];
char
fname
[
TSDB_FILENAME_LEN
];
...
@@ -310,7 +45,7 @@ void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t
...
@@ -310,7 +45,7 @@ void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t
pDFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pDFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pDFile
->
info
.
fver
=
tsdbGetDFSVersion
(
ftype
);
pDFile
->
info
.
fver
=
tsdbGetDFSVersion
(
ftype
);
tsdbGetFilename
(
pRepo
->
vgId
,
fid
,
ver
,
ftype
,
fname
);
tsdbGetFilename
(
REPO_ID
(
pRepo
)
,
fid
,
ver
,
ftype
,
fname
);
tfsInitFile
(
REPO_TFS
(
pRepo
),
&
(
pDFile
->
f
),
did
,
fname
);
tfsInitFile
(
REPO_TFS
(
pRepo
),
&
(
pDFile
->
f
),
did
,
fname
);
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbMain.c
已删除
100644 → 0
浏览文件 @
b5246114
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tsdb.h"
int
tsdbOpen
(
SVnode
*
pVnode
,
STsdb
**
ppTsdb
)
{
STsdb
*
pTsdb
=
NULL
;
int
slen
=
0
;
*
ppTsdb
=
NULL
;
slen
=
strlen
(
tfsGetPrimaryPath
(
pVnode
->
pTfs
))
+
strlen
(
pVnode
->
path
)
+
strlen
(
VNODE_TSDB_DIR
)
+
3
;
// create handle
pTsdb
=
(
STsdb
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pTsdb
)
+
slen
);
if
(
pTsdb
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pTsdb
->
path
=
(
char
*
)
&
pTsdb
[
1
];
sprintf
(
pTsdb
->
path
,
"%s%s%s%s%s"
,
tfsGetPrimaryPath
(
pVnode
->
pTfs
),
TD_DIRSEP
,
pVnode
->
path
,
TD_DIRSEP
,
VNODE_TSDB_DIR
);
pTsdb
->
pVnode
=
pVnode
;
pTsdb
->
vgId
=
TD_VID
(
pVnode
);
pTsdb
->
repoLocked
=
false
;
tdbMutexInit
(
&
pTsdb
->
mutex
,
NULL
);
pTsdb
->
config
=
pVnode
->
config
.
tsdbCfg
;
pTsdb
->
fs
=
tsdbNewFS
(
&
pTsdb
->
config
);
// create dir (TODO: use tfsMkdir)
taosMkDir
(
pTsdb
->
path
);
// open tsdb
if
(
tsdbOpenFS
(
pTsdb
)
<
0
)
{
goto
_err
;
}
tsdbDebug
(
"vgId: %d tsdb is opened"
,
TD_VID
(
pVnode
));
*
ppTsdb
=
pTsdb
;
return
0
;
_err:
taosMemoryFree
(
pTsdb
);
return
-
1
;
}
int
tsdbClose
(
STsdb
*
pTsdb
)
{
if
(
pTsdb
)
{
tsdbCloseFS
(
pTsdb
);
// tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb));
// tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb));
tsdbFreeFS
(
pTsdb
->
fs
);
// taosMemoryFreeClear(pTsdb->path);
taosMemoryFree
(
pTsdb
);
}
return
0
;
}
int
tsdbLockRepo
(
STsdb
*
pTsdb
)
{
int
code
=
taosThreadMutexLock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to lock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
pTsdb
->
repoLocked
=
true
;
return
0
;
}
int
tsdbUnlockRepo
(
STsdb
*
pTsdb
)
{
ASSERT
(
IS_REPO_LOCKED
(
pTsdb
));
pTsdb
->
repoLocked
=
false
;
int
code
=
taosThreadMutexUnlock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to unlock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
#if 0
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// no test file errors here
#include "taosdef.h"
#include "tsdbint.h"
#include "tthread.h"
#include "ttimer.h"
#define IS_VALID_PRECISION(precision) \
(((precision) >= TSDB_TIME_PRECISION_MILLI) && ((precision) <= TSDB_TIME_PRECISION_NANO))
#define TSDB_DEFAULT_COMPRESSION TWO_STAGE_COMP
#define IS_VALID_COMPRESSION(compression) (((compression) >= NO_COMPRESSION) && ((compression) <= TWO_STAGE_COMP))
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg);
static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH);
static void tsdbFreeRepo(STsdbRepo *pRepo);
static void tsdbStartStream(STsdbRepo *pRepo);
static void tsdbStopStream(STsdbRepo *pRepo);
static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh);
static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh, SBlockIdx *pIdx);
// Function declaration
int32_t tsdbCreateRepo(int repoid) {
char tsdbDir[TSDB_FILENAME_LEN] = "\0";
char dataDir[TSDB_FILENAME_LEN] = "\0";
tsdbGetRootDir(repoid, tsdbDir);
if (tfsMkdir(tsdbDir) < 0) {
goto _err;
}
tsdbGetDataDir(repoid, dataDir);
if (tfsMkdir(dataDir) < 0) {
goto _err;
}
// TODO: need to create current file with nothing in
return 0;
_err:
tsdbError("vgId:%d failed to create TSDB repository since %s", repoid, tstrerror(terrno));
return -1;
}
int32_t tsdbDropRepo(int repoid) {
char tsdbDir[TSDB_FILENAME_LEN] = "\0";
tsdbGetRootDir(repoid, tsdbDir);
return tfsRmdir(tsdbDir);
}
STsdbRepo *tsdbOpenRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) {
STsdbRepo *pRepo;
STsdbCfg config = *pCfg;
terrno = TSDB_CODE_SUCCESS;
// Check and set default configurations
if (tsdbCheckAndSetDefaultCfg(&config) < 0) {
tsdbError("vgId:%d failed to open TSDB repository since %s", config.tsdbId, tstrerror(terrno));
return NULL;
}
// Create new TSDB object
if ((pRepo = tsdbNewRepo(&config, pAppH)) == NULL) {
tsdbError("vgId:%d failed to open TSDB repository while creating TSDB object since %s", config.tsdbId,
tstrerror(terrno));
return NULL;
}
// Open meta
if (tsdbOpenMeta(pRepo) < 0) {
tsdbError("vgId:%d failed to open TSDB repository while opening Meta since %s", config.tsdbId, tstrerror(terrno));
tsdbCloseRepo(pRepo, false);
return NULL;
}
if (tsdbOpenBufPool(pRepo) < 0) {
tsdbError("vgId:%d failed to open TSDB repository while opening buffer pool since %s", config.tsdbId,
tstrerror(terrno));
tsdbCloseRepo(pRepo, false);
return NULL;
}
if (tsdbOpenFS(pRepo) < 0) {
tsdbError("vgId:%d failed to open TSDB repository while opening FS since %s", config.tsdbId, tstrerror(terrno));
tsdbCloseRepo(pRepo, false);
return NULL;
}
// TODO: Restore information from data
if ((!(pRepo->state & TSDB_STATE_BAD_DATA)) && tsdbRestoreInfo(pRepo) < 0) {
tsdbError("vgId:%d failed to open TSDB repository while restore info since %s", config.tsdbId, tstrerror(terrno));
tsdbCloseRepo(pRepo, false);
return NULL;
}
pRepo->mergeBuf = NULL;
tsdbStartStream(pRepo);
tsdbDebug("vgId:%d, TSDB repository opened", REPO_ID(pRepo));
return pRepo;
}
// Note: all working thread and query thread must stopped when calling this function
int tsdbCloseRepo(STsdbRepo *repo, int toCommit) {
if (repo == NULL) return 0;
STsdbRepo *pRepo = repo;
int vgId = REPO_ID(pRepo);
terrno = TSDB_CODE_SUCCESS;
tsdbStopStream(pRepo);
if(pRepo->pthread){
taosDestoryThread(pRepo->pthread);
pRepo->pthread = NULL;
}
if (toCommit) {
tsdbSyncCommit(repo);
}
tsem_wait(&(pRepo->readyToCommit));
tsdbUnRefMemTable(pRepo, pRepo->mem);
tsdbUnRefMemTable(pRepo, pRepo->imem);
pRepo->mem = NULL;
pRepo->imem = NULL;
tsdbCloseFS(pRepo);
tsdbCloseBufPool(pRepo);
tsdbCloseMeta(pRepo);
tsdbFreeRepo(pRepo);
tsdbDebug("vgId:%d repository is closed", vgId);
if (terrno != TSDB_CODE_SUCCESS) {
return -1;
} else {
return 0;
}
}
STsdbCfg *tsdbGetCfg(const STsdbRepo *repo) {
ASSERT(repo != NULL);
return &((STsdbRepo *)repo)->config;
}
int tsdbLockRepo(STsdbRepo *pRepo) {
int code = taosThreadMutexLock(&pRepo->mutex);
if (code != 0) {
tsdbError("vgId:%d failed to lock tsdb since %s", REPO_ID(pRepo), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
pRepo->repoLocked = true;
return 0;
}
int tsdbUnlockRepo(STsdbRepo *pRepo) {
ASSERT(IS_REPO_LOCKED(pRepo));
pRepo->repoLocked = false;
int code = taosThreadMutexUnlock(&pRepo->mutex);
if (code != 0) {
tsdbError("vgId:%d failed to unlock tsdb since %s", REPO_ID(pRepo), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
return 0;
}
int tsdbCheckCommit(STsdbRepo *pRepo) {
ASSERT(pRepo->mem != NULL);
STsdbCfg *pCfg = &(pRepo->config);
STsdbBufBlock *pBufBlock = tsdbGetCurrBufBlock(pRepo);
ASSERT(pBufBlock != NULL);
if ((pRepo->mem->extraBuffList != NULL) ||
((listNEles(pRepo->mem->bufBlockList) >= pCfg->totalBlocks / 3) && (pBufBlock->remain < TSDB_BUFFER_RESERVE))) {
// trigger commit
if (tsdbAsyncCommit(pRepo) < 0) return -1;
}
return 0;
}
STsdbMeta *tsdbGetMeta(STsdbRepo *pRepo) { return pRepo->tsdbMeta; }
STsdbRepoInfo *tsdbGetStatus(STsdbRepo *pRepo) { return NULL; }
int tsdbGetState(STsdbRepo *repo) { return repo->state; }
int8_t tsdbGetCompactState(STsdbRepo *repo) { return (int8_t)(repo->compactState); }
void tsdbReportStat(void *repo, int64_t *totalPoints, int64_t *totalStorage, int64_t *compStorage) {
ASSERT(repo != NULL);
STsdbRepo *pRepo = repo;
*totalPoints = pRepo->stat.pointsWritten;
*totalStorage = pRepo->stat.totalStorage;
*compStorage = pRepo->stat.compStorage;
}
int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) {
// TODO: think about multithread cases
if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return -1;
STsdbCfg * pRCfg = &repo->config;
ASSERT(pRCfg->tsdbId == pCfg->tsdbId);
ASSERT(pRCfg->cacheBlockSize == pCfg->cacheBlockSize);
ASSERT(pRCfg->daysPerFile == pCfg->daysPerFile);
ASSERT(pRCfg->minRowsPerFileBlock == pCfg->minRowsPerFileBlock);
ASSERT(pRCfg->maxRowsPerFileBlock == pCfg->maxRowsPerFileBlock);
ASSERT(pRCfg->precision == pCfg->precision);
bool configChanged = false;
if (pRCfg->compression != pCfg->compression) {
configChanged = true;
}
if (pRCfg->keep != pCfg->keep) {
configChanged = true;
}
if (pRCfg->keep1 != pCfg->keep1) {
configChanged = true;
}
if (pRCfg->keep2 != pCfg->keep2) {
configChanged = true;
}
if (pRCfg->cacheLastRow != pCfg->cacheLastRow) {
configChanged = true;
}
if (pRCfg->totalBlocks != pCfg->totalBlocks) {
configChanged = true;
}
if (!configChanged) {
tsdbError("vgId:%d no config changed", REPO_ID(repo));
}
int code = taosThreadMutexLock(&repo->save_mutex);
if (code != 0) {
tsdbError("vgId:%d failed to lock tsdb save config mutex since %s", REPO_ID(repo), strerror(errno));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
STsdbCfg * pSaveCfg = &repo->save_config;
*pSaveCfg = repo->config;
pSaveCfg->compression = pCfg->compression;
pSaveCfg->keep = pCfg->keep;
pSaveCfg->keep1 = pCfg->keep1;
pSaveCfg->keep2 = pCfg->keep2;
pSaveCfg->cacheLastRow = pCfg->cacheLastRow;
pSaveCfg->totalBlocks = pCfg->totalBlocks;
tsdbInfo("vgId:%d old config: compression(%d), keep(%d,%d,%d), cacheLastRow(%d),totalBlocks(%d)",
REPO_ID(repo),
pRCfg->compression, pRCfg->keep, pRCfg->keep1,pRCfg->keep2,
pRCfg->cacheLastRow, pRCfg->totalBlocks);
tsdbInfo("vgId:%d new config: compression(%d), keep(%d,%d,%d), cacheLastRow(%d),totalBlocks(%d)",
REPO_ID(repo),
pSaveCfg->compression, pSaveCfg->keep,pSaveCfg->keep1, pSaveCfg->keep2,
pSaveCfg->cacheLastRow,pSaveCfg->totalBlocks);
repo->config_changed = true;
taosThreadMutexUnlock(&repo->save_mutex);
// schedule a commit msg and wait for the new config applied
tsdbSyncCommitConfig(repo);
return 0;
#if 0
STsdbRepo *pRepo = (STsdbRepo *)repo;
STsdbCfg config = pRepo->config;
STsdbCfg * pRCfg = &pRepo->config;
if (tsdbCheckAndSetDefaultCfg(pCfg) < 0) return -1;
ASSERT(pRCfg->tsdbId == pCfg->tsdbId);
ASSERT(pRCfg->cacheBlockSize == pCfg->cacheBlockSize);
ASSERT(pRCfg->daysPerFile == pCfg->daysPerFile);
ASSERT(pRCfg->minRowsPerFileBlock == pCfg->minRowsPerFileBlock);
ASSERT(pRCfg->maxRowsPerFileBlock == pCfg->maxRowsPerFileBlock);
ASSERT(pRCfg->precision == pCfg->precision);
bool configChanged = false;
if (pRCfg->compression != pCfg->compression) {
tsdbAlterCompression(pRepo, pCfg->compression);
config.compression = pCfg->compression;
configChanged = true;
}
if (pRCfg->keep != pCfg->keep) {
if (tsdbAlterKeep(pRepo, pCfg->keep) < 0) {
tsdbError("vgId:%d failed to configure repo when alter keep since %s", REPO_ID(pRepo), tstrerror(terrno));
config.keep = pCfg->keep;
return -1;
}
configChanged = true;
}
if (pRCfg->totalBlocks != pCfg->totalBlocks) {
tsdbAlterCacheTotalBlocks(pRepo, pCfg->totalBlocks);
config.totalBlocks = pCfg->totalBlocks;
configChanged = true;
}
if (pRCfg->cacheLastRow != pCfg->cacheLastRow) {
config.cacheLastRow = pCfg->cacheLastRow;
configChanged = true;
}
if (configChanged) {
if (tsdbSaveConfig(pRepo->rootDir, &config) < 0) {
tsdbError("vgId:%d failed to configure repository while save config since %s", REPO_ID(pRepo), tstrerror(terrno));
return -1;
}
}
return 0;
#endif
}
uint32_t tsdbGetFileInfo(STsdbRepo *repo, char *name, uint32_t *index, uint32_t eindex, int64_t *size) {
// TODO
return 0;
#if 0
STsdbRepo *pRepo = (STsdbRepo *)repo;
// STsdbMeta *pMeta = pRepo->tsdbMeta;
STsdbFileH *pFileH = pRepo->tsdbFileH;
uint32_t magic = 0;
char * fname = NULL;
struct stat fState;
tsdbDebug("vgId:%d name:%s index:%d eindex:%d", pRepo->config.tsdbId, name, *index, eindex);
ASSERT(*index <= eindex);
if (name[0] == 0) { // get the file from index or after, but not larger than eindex
int fid = (*index) / TSDB_FILE_TYPE_MAX;
if (pFileH->nFGroups == 0 || fid > pFileH->pFGroup[pFileH->nFGroups - 1].fileId) {
if (*index <= TSDB_META_FILE_INDEX && TSDB_META_FILE_INDEX <= eindex) {
fname = tsdbGetMetaFileName(pRepo->rootDir);
*index = TSDB_META_FILE_INDEX;
magic = TSDB_META_FILE_MAGIC(pRepo->tsdbMeta);
sprintf(name, "tsdb/%s", TSDB_META_FILE_NAME);
} else {
return 0;
}
} else {
SFileGroup *pFGroup =
taosbsearch(&fid, pFileH->pFGroup, pFileH->nFGroups, sizeof(SFileGroup), keyFGroupCompFunc, TD_GE);
if (pFGroup->fileId == fid) {
SFile *pFile = &pFGroup->files[(*index) % TSDB_FILE_TYPE_MAX];
fname = strdup(TSDB_FILE_NAME(pFile));
magic = pFile->info.magic;
char *tfname = strdup(fname);
sprintf(name, "tsdb/%s/%s", TSDB_DATA_DIR_NAME, basename(tfname));
taosMemoryFreeClear(tfname);
} else {
if ((pFGroup->fileId + 1) * TSDB_FILE_TYPE_MAX - 1 < (int)eindex) {
SFile *pFile = &pFGroup->files[0];
fname = strdup(TSDB_FILE_NAME(pFile));
*index = pFGroup->fileId * TSDB_FILE_TYPE_MAX;
magic = pFile->info.magic;
char *tfname = strdup(fname);
sprintf(name, "tsdb/%s/%s", TSDB_DATA_DIR_NAME, basename(tfname));
taosMemoryFreeClear(tfname);
} else {
return 0;
}
}
}
} else { // get the named file at the specified index. If not there, return 0
fname = taosMemoryMalloc(256);
sprintf(fname, "%s/vnode/vnode%d/%s", tfsGetPrimaryPath(pRepo->pTfs), REPO_ID(pRepo), name);
if (access(fname, F_OK) != 0) {
taosMemoryFreeClear(fname);
return 0;
}
if (*index == TSDB_META_FILE_INDEX) { // get meta file
tsdbGetStoreInfo(fname, &magic, size);
} else {
char tfname[TSDB_FILENAME_LEN] = "\0";
sprintf(tfname, "vnode/vnode%d/tsdb/%s/%s", REPO_ID(pRepo), TSDB_DATA_DIR_NAME, basename(name));
tsdbGetFileInfoImpl(tfname, &magic, size);
}
taosMemoryFreeClear(fname);
return magic;
}
if (stat(fname, &fState) < 0) {
taosMemoryFreeClear(fname);
return 0;
}
*size = fState.st_size;
// magic = *size;
taosMemoryFreeClear(fname);
return magic;
#endif
}
void tsdbGetRootDir(int repoid, char dirName[]) {
snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb", repoid);
}
void tsdbGetDataDir(int repoid, char dirName[]) {
snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/data", repoid);
}
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) {
// Check tsdbId
if (pCfg->tsdbId < 0) {
tsdbError("vgId:%d invalid vgroup ID", pCfg->tsdbId);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
// Check precision
if (pCfg->precision == -1) {
pCfg->precision = TSDB_DEFAULT_PRECISION;
} else {
if (!IS_VALID_PRECISION(pCfg->precision)) {
tsdbError("vgId:%d invalid precision configuration %d", pCfg->tsdbId, pCfg->precision);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
}
// Check compression
if (pCfg->compression == -1) {
pCfg->compression = TSDB_DEFAULT_COMPRESSION;
} else {
if (!IS_VALID_COMPRESSION(pCfg->compression)) {
tsdbError("vgId:%d invalid compression configuration %d", pCfg->tsdbId, pCfg->precision);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
}
// Check daysPerFile
if (pCfg->daysPerFile == -1) {
pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
} else {
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) {
tsdbError(
"vgId:%d invalid daysPerFile configuration! daysPerFile %d TSDB_MIN_DAYS_PER_FILE %d TSDB_MAX_DAYS_PER_FILE "
"%d",
pCfg->tsdbId, pCfg->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
}
// Check minRowsPerFileBlock and maxRowsPerFileBlock
if (pCfg->minRowsPerFileBlock == -1) {
pCfg->minRowsPerFileBlock = TSDB_DEFAULT_MINROWS_FBLOCK;
} else {
if (pCfg->minRowsPerFileBlock < TSDB_MIN_MINROWS_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MINROWS_FBLOCK) {
tsdbError(
"vgId:%d invalid minRowsPerFileBlock configuration! minRowsPerFileBlock %d TSDB_MIN_MINROWS_FBLOCK %d "
"TSDB_MAX_MINROWS_FBLOCK %d",
pCfg->tsdbId, pCfg->minRowsPerFileBlock, TSDB_MIN_MINROWS_FBLOCK, TSDB_MAX_MINROWS_FBLOCK);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
}
if (pCfg->maxRowsPerFileBlock == -1) {
pCfg->maxRowsPerFileBlock = TSDB_DEFAULT_MAXROWS_FBLOCK;
} else {
if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAXROWS_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAXROWS_FBLOCK) {
tsdbError(
"vgId:%d invalid maxRowsPerFileBlock configuration! maxRowsPerFileBlock %d TSDB_MIN_MAXROWS_FBLOCK %d "
"TSDB_MAX_MAXROWS_FBLOCK %d",
pCfg->tsdbId, pCfg->maxRowsPerFileBlock, TSDB_MIN_MINROWS_FBLOCK, TSDB_MAX_MINROWS_FBLOCK);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
}
if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) {
tsdbError("vgId:%d invalid configuration! minRowsPerFileBlock %d maxRowsPerFileBlock %d", pCfg->tsdbId,
pCfg->minRowsPerFileBlock, pCfg->maxRowsPerFileBlock);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
// Check keep
if (pCfg->keep == -1) {
pCfg->keep = TSDB_DEFAULT_KEEP;
} else {
if (pCfg->keep < TSDB_MIN_KEEP || pCfg->keep > TSDB_MAX_KEEP) {
tsdbError(
"vgId:%d invalid keep configuration! keep %d TSDB_MIN_KEEP %d "
"TSDB_MAX_KEEP %d",
pCfg->tsdbId, pCfg->keep, TSDB_MIN_KEEP, TSDB_MAX_KEEP);
terrno = TSDB_CODE_TDB_INVALID_CONFIG;
return -1;
}
}
if (pCfg->keep1 == 0) {
pCfg->keep1 = pCfg->keep;
}
if (pCfg->keep2 == 0) {
pCfg->keep2 = pCfg->keep;
}
// update check
if (pCfg->update < TD_ROW_DISCARD_UPDATE || pCfg->update > TD_ROW_PARTIAL_UPDATE)
pCfg->update = TD_ROW_DISCARD_UPDATE;
// update cacheLastRow
if (pCfg->cacheLastRow != 0) {
if (pCfg->cacheLastRow > 3)
pCfg->cacheLastRow = 1;
}
return 0;
}
static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) {
STsdbRepo *pRepo = (STsdbRepo *)taosMemoryCalloc(1, sizeof(*pRepo));
if (pRepo == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return NULL;
}
pRepo->state = TSDB_STATE_OK;
pRepo->code = TSDB_CODE_SUCCESS;
pRepo->compactState = 0;
pRepo->config = *pCfg;
if (pAppH) {
pRepo->appH = *pAppH;
}
pRepo->repoLocked = false;
pRepo->pthread = NULL;
int code = taosThreadMutexInit(&(pRepo->mutex), NULL);
if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code);
tsdbFreeRepo(pRepo);
return NULL;
}
code = taosThreadMutexInit(&(pRepo->save_mutex), NULL);
if (code != 0) {
terrno = TAOS_SYSTEM_ERROR(code);
tsdbFreeRepo(pRepo);
return NULL;
}
pRepo->config_changed = false;
atomic_store_8(&pRepo->hasCachedLastColumn, 0);
code = tsem_init(&(pRepo->readyToCommit), 0, 1);
if (code != 0) {
code = errno;
terrno = TAOS_SYSTEM_ERROR(code);
tsdbFreeRepo(pRepo);
return NULL;
}
pRepo->tsdbMeta = tsdbNewMeta(pCfg);
if (pRepo->tsdbMeta == NULL) {
tsdbError("vgId:%d failed to create meta since %s", REPO_ID(pRepo), tstrerror(terrno));
tsdbFreeRepo(pRepo);
return NULL;
}
pRepo->pPool = tsdbNewBufPool(pCfg);
if (pRepo->pPool == NULL) {
tsdbError("vgId:%d failed to create buffer pool since %s", REPO_ID(pRepo), tstrerror(terrno));
tsdbFreeRepo(pRepo);
return NULL;
}
pRepo->fs = tsdbNewFS(pCfg);
if (pRepo->fs == NULL) {
tsdbError("vgId:%d failed to TSDB file system since %s", REPO_ID(pRepo), tstrerror(terrno));
tsdbFreeRepo(pRepo);
return NULL;
}
return pRepo;
}
static void tsdbFreeRepo(STsdbRepo *pRepo) {
if (pRepo) {
tsdbFreeFS(pRepo->fs);
tsdbFreeBufPool(pRepo->pPool);
tsdbFreeMeta(pRepo->tsdbMeta);
tsdbFreeMergeBuf(pRepo->mergeBuf);
// tsdbFreeMemTable(pRepo->mem);
// tsdbFreeMemTable(pRepo->imem);
tsem_destroy(&(pRepo->readyToCommit));
taosThreadMutexDestroy(&pRepo->mutex);
taosMemoryFree(pRepo);
}
}
static void tsdbStartStream(STsdbRepo *pRepo) {
STsdbMeta *pMeta = pRepo->tsdbMeta;
for (int i = 0; i < pMeta->maxTables; i++) {
STable *pTable = pMeta->tables[i];
if (pTable && pTable->type == TSDB_STREAM_TABLE) {
pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), TABLE_NAME(pTable)->data, pTable->sql,
tsdbGetTableSchemaImpl(pTable, false, false, -1), 0);
}
}
}
static void tsdbStopStream(STsdbRepo *pRepo) {
STsdbMeta *pMeta = pRepo->tsdbMeta;
for (int i = 0; i < pMeta->maxTables; i++) {
STable *pTable = pMeta->tables[i];
if (pTable && pTable->type == TSDB_STREAM_TABLE) {
(*pRepo->appH.cqDropFunc)(pTable->cqhandle);
}
}
}
static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh) {
//tsdbInfo("tsdbRestoreLastColumns of table %s", pTable->name->data);
STSchema *pSchema = tsdbGetTableLatestSchema(pTable);
if (pSchema == NULL) {
tsdbError("tsdbGetTableLatestSchema of table %s fail", pTable->name->data);
return 0;
}
SBlock* pBlock;
int numColumns;
int32_t blockIdx;
SDataStatis* pBlockStatis = NULL;
STSRow* row = NULL;
// restore last column data with last schema
int err = 0;
numColumns = schemaNCols(pSchema);
if (numColumns <= pTable->restoreColumnNum) {
pTable->hasRestoreLastColumn = true;
return 0;
}
if (pTable->lastColSVersion != schemaVersion(pSchema)) {
if (tsdbInitColIdCacheWithSchema(pTable, pSchema) < 0) {
return -1;
}
}
row = taosTMalloc(memRowMaxBytesFromSchema(pSchema));
if (row == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
err = -1;
goto out;
}
memRowSetType(row, SMEM_ROW_DATA);
tdInitDataRow(memRowDataBody(row), pSchema);
// first load block index info
if (tsdbLoadBlockInfo(pReadh, NULL) < 0) {
err = -1;
goto out;
}
pBlockStatis = taosMemoryCalloc(numColumns, sizeof(SDataStatis));
if (pBlockStatis == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
err = -1;
goto out;
}
memset(pBlockStatis, 0, numColumns * sizeof(SDataStatis));
for(int32_t i = 0; i < numColumns; ++i) {
STColumn *pCol = schemaColAt(pSchema, i);
pBlockStatis[i].colId = pCol->colId;
}
// load block from backward
SBlockIdx *pIdx = pReadh->pBlkIdx;
blockIdx = (int32_t)(pIdx->numOfBlocks - 1);
while (numColumns > pTable->restoreColumnNum && blockIdx >= 0) {
bool loadStatisData = false;
pBlock = pReadh->pBlkInfo->blocks + blockIdx;
blockIdx -= 1;
// load block data
if (tsdbLoadBlockData(pReadh, pBlock, NULL) < 0) {
err = -1;
goto out;
}
// file block with sub-blocks has no statistics data
if (pBlock->numOfSubBlocks <= 1) {
if (tsdbLoadBlockStatis(pReadh, pBlock) == TSDB_STATIS_OK) {
tsdbGetBlockStatis(pReadh, pBlockStatis, (int)numColumns, pBlock);
loadStatisData = true;
}
}
for (int16_t i = 0; i < numColumns && numColumns > pTable->restoreColumnNum; ++i) {
STColumn *pCol = schemaColAt(pSchema, i);
// ignore loaded columns
if (pTable->lastCols[i].bytes != 0) {
continue;
}
// ignore block which has no not-null colId column
if (loadStatisData && pBlockStatis[i].numOfNull == pBlock->numOfRows) {
continue;
}
// OK,let's load row from backward to get not-null column
for (int32_t rowId = pBlock->numOfRows - 1; rowId >= 0; rowId--) {
SDataCol *pDataCol = pReadh->pDCols[0]->cols + i;
const void* pColData = tdGetColDataOfRow(pDataCol, rowId);
tdAppendColVal(memRowDataBody(row), pColData, pCol->type, pCol->offset);
//SDataCol *pDataCol = readh.pDCols[0]->cols + j;
void *value = tdGetRowDataOfCol(memRowDataBody(row), (int8_t)pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset);
if (isNull(value, pCol->type)) {
continue;
}
int16_t idx = tsdbGetLastColumnsIndexByColId(pTable, pCol->colId);
if (idx == -1) {
tsdbError("tsdbRestoreLastColumns restore vgId:%d,table:%s cache column %d fail", REPO_ID(pRepo), pTable->name->data, pCol->colId);
continue;
}
// save not-null column
uint16_t bytes = IS_VAR_DATA_TYPE(pCol->type) ? varDataTLen(pColData) : pCol->bytes;
SDataCol *pLastCol = &(pTable->lastCols[idx]);
pLastCol->pData = taosMemoryMalloc(bytes);
pLastCol->bytes = bytes;
pLastCol->colId = pCol->colId;
memcpy(pLastCol->pData, value, bytes);
// save row ts(in column 0)
pDataCol = pReadh->pDCols[0]->cols + 0;
pCol = schemaColAt(pSchema, 0);
tdAppendColVal(memRowDataBody(row), tdGetColDataOfRow(pDataCol, rowId), pCol->type, pCol->offset);
pLastCol->ts = TD_ROW_KEY(row);
pTable->restoreColumnNum += 1;
tsdbDebug("tsdbRestoreLastColumns restore vgId:%d,table:%s cache column %d, %" PRId64, REPO_ID(pRepo), pTable->name->data, pLastCol->colId, pLastCol->ts);
break;
}
}
}
out:
taosTZfree(row);
taosMemoryFreeClear(pBlockStatis);
if (err == 0 && numColumns <= pTable->restoreColumnNum) {
pTable->hasRestoreLastColumn = true;
}
return err;
}
static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh, SBlockIdx *pIdx) {
ASSERT(pTable->lastRow == NULL);
if (tsdbLoadBlockInfo(pReadh, NULL) < 0) {
return -1;
}
SBlock* pBlock = pReadh->pBlkInfo->blocks + pIdx->numOfBlocks - 1;
if (tsdbLoadBlockData(pReadh, pBlock, NULL) < 0) {
return -1;
}
// Get the data in row
STSchema *pSchema = tsdbGetTableSchema(pTable);
pTable->lastRow = taosTMalloc(memRowMaxBytesFromSchema(pSchema));
if (pTable->lastRow == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
}
memRowSetType(pTable->lastRow, SMEM_ROW_DATA);
tdInitDataRow(memRowDataBody(pTable->lastRow), pSchema);
for (int icol = 0; icol < schemaNCols(pSchema); icol++) {
STColumn *pCol = schemaColAt(pSchema, icol);
SDataCol *pDataCol = pReadh->pDCols[0]->cols + icol;
tdAppendColVal(memRowDataBody(pTable->lastRow), tdGetColDataOfRow(pDataCol, pBlock->numOfRows - 1), pCol->type,
pCol->offset);
}
return 0;
}
int tsdbRestoreInfo(STsdbRepo *pRepo) {
SFSIter fsiter;
SReadH readh;
SDFileSet *pSet;
STsdbMeta *pMeta = pRepo->tsdbMeta;
STsdbCfg * pCfg = REPO_CFG(pRepo);
if (tsdbInitReadH(&readh, pRepo) < 0) {
return -1;
}
tsdbFSIterInit(&fsiter, REPO_FS(pRepo), TSDB_FS_ITER_BACKWARD);
if (CACHE_LAST_NULL_COLUMN(pCfg)) {
for (int i = 1; i < pMeta->maxTables; i++) {
STable *pTable = pMeta->tables[i];
if (pTable == NULL) continue;
pTable->restoreColumnNum = 0;
pTable->hasRestoreLastColumn = false;
}
}
while ((pSet = tsdbFSIterNext(&fsiter)) != NULL) {
if (tsdbSetAndOpenReadFSet(&readh, pSet) < 0) {
tsdbDestroyReadH(&readh);
return -1;
}
if (tsdbLoadBlockIdx(&readh) < 0) {
tsdbDestroyReadH(&readh);
return -1;
}
for (int i = 1; i < pMeta->maxTables; i++) {
STable *pTable = pMeta->tables[i];
if (pTable == NULL) continue;
//tsdbInfo("tsdbRestoreInfo restore vgId:%d,table:%s", REPO_ID(pRepo), pTable->name->data);
if (tsdbSetReadTable(&readh, pTable) < 0) {
tsdbDestroyReadH(&readh);
return -1;
}
TSKEY lastKey = tsdbGetTableLastKeyImpl(pTable);
SBlockIdx *pIdx = readh.pBlkIdx;
if (pIdx && lastKey < pIdx->maxKey) {
pTable->lastKey = pIdx->maxKey;
if (CACHE_LAST_ROW(pCfg) && tsdbRestoreLastRow(pRepo, pTable, &readh, pIdx) != 0) {
tsdbDestroyReadH(&readh);
return -1;
}
}
// restore NULL columns
if (pIdx && CACHE_LAST_NULL_COLUMN(pCfg) && !pTable->hasRestoreLastColumn) {
if (tsdbRestoreLastColumns(pRepo, pTable, &readh) != 0) {
tsdbDestroyReadH(&readh);
return -1;
}
}
}
}
tsdbDestroyReadH(&readh);
if (CACHE_LAST_NULL_COLUMN(pCfg)) {
atomic_store_8(&pRepo->hasCachedLastColumn, 1);
}
return 0;
}
int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) {
bool cacheLastRow = false, cacheLastCol = false;
SFSIter fsiter;
SReadH readh;
SDFileSet *pSet;
STsdbMeta *pMeta = pRepo->tsdbMeta;
int tableNum = 0;
int maxTableIdx = 0;
int cacheLastRowTableNum = 0;
int cacheLastColTableNum = 0;
bool need_free_last_row = CACHE_LAST_ROW(oldCfg) && !CACHE_LAST_ROW(&(pRepo->config));
bool need_free_last_col = CACHE_LAST_NULL_COLUMN(oldCfg) && !CACHE_LAST_NULL_COLUMN(&(pRepo->config));
if (CACHE_LAST_ROW(&(pRepo->config)) || CACHE_LAST_NULL_COLUMN(&(pRepo->config))) {
tsdbInfo("tsdbCacheLastData cache last data since cacheLast option changed");
cacheLastRow = !CACHE_LAST_ROW(oldCfg) && CACHE_LAST_ROW(&(pRepo->config));
cacheLastCol = !CACHE_LAST_NULL_COLUMN(oldCfg) && CACHE_LAST_NULL_COLUMN(&(pRepo->config));
}
// calc max table idx and table num
for (int i = 1; i < pMeta->maxTables; i++) {
STable *pTable = pMeta->tables[i];
if (pTable == NULL) continue;
tableNum += 1;
maxTableIdx = i;
if (cacheLastCol) {
pTable->restoreColumnNum = 0;
pTable->hasRestoreLastColumn = false;
}
}
// if close last option,need to free data
if (need_free_last_row || need_free_last_col) {
if (need_free_last_col) {
atomic_store_8(&pRepo->hasCachedLastColumn, 0);
}
tsdbInfo("free cache last data since cacheLast option changed");
for (int i = 1; i <= maxTableIdx; i++) {
STable *pTable = pMeta->tables[i];
if (pTable == NULL) continue;
if (need_free_last_row) {
taosTZfree(pTable->lastRow);
pTable->lastRow = NULL;
}
if (need_free_last_col) {
tsdbFreeLastColumns(pTable);
pTable->hasRestoreLastColumn = false;
}
}
}
if (!cacheLastRow && !cacheLastCol) {
return 0;
}
cacheLastRowTableNum = cacheLastRow ? tableNum : 0;
cacheLastColTableNum = cacheLastCol ? tableNum : 0;
if (tsdbInitReadH(&readh, pRepo) < 0) {
return -1;
}
tsdbFSIterInit(&fsiter, REPO_FS(pRepo), TSDB_FS_ITER_BACKWARD);
while ((pSet = tsdbFSIterNext(&fsiter)) != NULL && (cacheLastRowTableNum > 0 || cacheLastColTableNum > 0)) {
if (tsdbSetAndOpenReadFSet(&readh, pSet) < 0) {
tsdbDestroyReadH(&readh);
return -1;
}
if (tsdbLoadBlockIdx(&readh) < 0) {
tsdbDestroyReadH(&readh);
return -1;
}
for (int i = 1; i <= maxTableIdx; i++) {
STable *pTable = pMeta->tables[i];
if (pTable == NULL) continue;
//tsdbInfo("tsdbRestoreInfo restore vgId:%d,table:%s", REPO_ID(pRepo), pTable->name->data);
if (tsdbSetReadTable(&readh, pTable) < 0) {
tsdbDestroyReadH(&readh);
return -1;
}
SBlockIdx *pIdx = readh.pBlkIdx;
if (pIdx && cacheLastRowTableNum > 0 && pTable->lastRow == NULL) {
pTable->lastKey = pIdx->maxKey;
if (tsdbRestoreLastRow(pRepo, pTable, &readh, pIdx) != 0) {
tsdbDestroyReadH(&readh);
return -1;
}
cacheLastRowTableNum -= 1;
}
// restore NULL columns
if (pIdx && cacheLastColTableNum > 0 && !pTable->hasRestoreLastColumn) {
if (tsdbRestoreLastColumns(pRepo, pTable, &readh) != 0) {
tsdbDestroyReadH(&readh);
return -1;
}
if (pTable->hasRestoreLastColumn) {
cacheLastColTableNum -= 1;
}
}
}
}
tsdbDestroyReadH(&readh);
if (cacheLastCol) {
atomic_store_8(&pRepo->hasCachedLastColumn, 1);
}
return 0;
}
#endif
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
75cad6e3
...
@@ -285,21 +285,6 @@ static STbData *tsdbNewTbData(tb_uid_t uid) {
...
@@ -285,21 +285,6 @@ static STbData *tsdbNewTbData(tb_uid_t uid) {
pTbData
->
keyMax
=
TSKEY_MIN
;
pTbData
->
keyMax
=
TSKEY_MIN
;
pTbData
->
nrows
=
0
;
pTbData
->
nrows
=
0
;
// uint8_t skipListCreateFlags;
// if (pCfg->update == TD_ROW_DISCARD_UPDATE)
// skipListCreateFlags = SL_DISCARD_DUP_KEY;
// else
// skipListCreateFlags = SL_UPDATE_DUP_KEY;
// pTableData->pData =
// tSkipListCreate(TSDB_DATA_SKIPLIST_LEVEL, TSDB_DATA_TYPE_TIMESTAMP, TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP],
// tkeyComparFn, skipListCreateFlags, tsdbGetTsTupleKey);
// if (pTableData->pData == NULL) {
// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
// taosMemoryFree(pTableData);
// return NULL;
// }
pTbData
->
pData
=
tSkipListCreate
(
5
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
tkeyComparFn
,
SL_DISCARD_DUP_KEY
,
pTbData
->
pData
=
tSkipListCreate
(
5
,
TSDB_DATA_TYPE_TIMESTAMP
,
sizeof
(
int64_t
),
tkeyComparFn
,
SL_DISCARD_DUP_KEY
,
tsdbGetTsTupleKey
);
tsdbGetTsTupleKey
);
if
(
pTbData
->
pData
==
NULL
)
{
if
(
pTbData
->
pData
==
NULL
)
{
...
@@ -351,608 +336,3 @@ static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema *
...
@@ -351,608 +336,3 @@ static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema *
return
0
;
return
0
;
}
}
\ No newline at end of file
/* ------------------------ REFACTORING ------------------------ */
#if 0
int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitReq *pMsg) {
SMemAllocator *pMA = pMemTable->pMA;
STbData * pTbData = (STbData *)TD_MA_MALLOC(pMA, sizeof(*pTbData));
if (pTbData == NULL) {
// TODO
}
TD_SLIST_PUSH(&(pMemTable->list), pTbData);
return 0;
}
#include "tdataformat.h"
#include "tfunctional.h"
#include "tsdbRowMergeBuf.h"
#include "tsdbint.h"
#include "tskiplist.h"
#define TSDB_DATA_SKIPLIST_LEVEL 5
#define TSDB_MAX_INSERT_BATCH 512
typedef struct {
int32_t totalLen;
int32_t len;
STSRow* row;
} SSubmitBlkIter;
typedef struct {
int32_t totalLen;
int32_t len;
void * pMsg;
} SSubmitMsgIter;
static SMemTable * tsdbNewMemTable(STsdbRepo *pRepo);
static void tsdbFreeMemTable(SMemTable *pMemTable);
static STableData* tsdbNewTableData(STsdbCfg *pCfg, STable *pTable);
static void tsdbFreeTableData(STableData *pTableData);
static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables);
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow* row);
static int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter);
static STSRow* tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter);
static int tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, int32_t *affectedrows);
static int tsdbInitSubmitMsgIter(SSubmitReq *pMsg, SSubmitMsgIter *pIter);
static int tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock);
static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable);
static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, STSRow* row);
static FORCE_INLINE int tsdbCheckRowRange(STsdbRepo *pRepo, STable *pTable, STSRow* row, TSKEY minKey, TSKEY maxKey,
TSKEY now);
// ---------------- INTERNAL FUNCTIONS ----------------
int tsdbRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
if (pMemTable == NULL) return 0;
int ref = T_REF_INC(pMemTable);
tsdbDebug("vgId:%d ref memtable %p ref %d", REPO_ID(pRepo), pMemTable, ref);
return 0;
}
// Need to lock the repository
int tsdbUnRefMemTable(STsdbRepo *pRepo, SMemTable *pMemTable) {
if (pMemTable == NULL) return 0;
int ref = T_REF_DEC(pMemTable);
tsdbDebug("vgId:%d unref memtable %p ref %d", REPO_ID(pRepo), pMemTable, ref);
if (ref == 0) {
STsdbBufPool *pBufPool = pRepo->pPool;
SListNode *pNode = NULL;
bool addNew = false;
if (tsdbLockRepo(pRepo) < 0) return -1;
while ((pNode = tdListPopHead(pMemTable->bufBlockList)) != NULL) {
if (pBufPool->nRecycleBlocks > 0) {
tsdbRecycleBufferBlock(pBufPool, pNode, false);
pBufPool->nRecycleBlocks -= 1;
} else {
if(pBufPool->nElasticBlocks > 0 && listNEles(pBufPool->bufBlockList) > 2) {
tsdbRecycleBufferBlock(pBufPool, pNode, true);
} else {
tdListAppendNode(pBufPool->bufBlockList, pNode);
addNew = true;
}
}
}
if (addNew) {
int code = taosThreadCondSignal(&pBufPool->poolNotEmpty);
if (code != 0) {
if (tsdbUnlockRepo(pRepo) < 0) return -1;
tsdbError("vgId:%d failed to signal pool not empty since %s", REPO_ID(pRepo), strerror(code));
terrno = TAOS_SYSTEM_ERROR(code);
return -1;
}
}
if (tsdbUnlockRepo(pRepo) < 0) return -1;
for (int i = 0; i < pMemTable->maxTables; i++) {
if (pMemTable->tData[i] != NULL) {
tsdbFreeTableData(pMemTable->tData[i]);
}
}
tdListDiscard(pMemTable->actList);
tdListDiscard(pMemTable->bufBlockList);
tsdbFreeMemTable(pMemTable);
}
return 0;
}
int tsdbTakeMemSnapshot(STsdbRepo *pRepo, SMemSnapshot *pSnapshot, SArray *pATable) {
memset(pSnapshot, 0, sizeof(*pSnapshot));
if (tsdbLockRepo(pRepo) < 0) return -1;
pSnapshot->omem = pRepo->mem;
pSnapshot->imem = pRepo->imem;
tsdbRefMemTable(pRepo, pRepo->mem);
tsdbRefMemTable(pRepo, pRepo->imem);
if (tsdbUnlockRepo(pRepo) < 0) return -1;
if (pSnapshot->omem) {
taosRLockLatch(&(pSnapshot->omem->latch));
pSnapshot->mem = &(pSnapshot->mtable);
pSnapshot->mem->tData = (STableData **)taosMemoryCalloc(pSnapshot->omem->maxTables, sizeof(STableData *));
if (pSnapshot->mem->tData == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
taosRUnLockLatch(&(pSnapshot->omem->latch));
tsdbUnRefMemTable(pRepo, pSnapshot->omem);
tsdbUnRefMemTable(pRepo, pSnapshot->imem);
pSnapshot->mem = NULL;
pSnapshot->imem = NULL;
pSnapshot->omem = NULL;
return -1;
}
pSnapshot->mem->keyFirst = pSnapshot->omem->keyFirst;
pSnapshot->mem->keyLast = pSnapshot->omem->keyLast;
pSnapshot->mem->numOfRows = pSnapshot->omem->numOfRows;
pSnapshot->mem->maxTables = pSnapshot->omem->maxTables;
for (size_t i = 0; i < taosArrayGetSize(pATable); i++) {
STable * pTable = *(STable **)taosArrayGet(pATable, i);
int32_t tid = TABLE_TID(pTable);
STableData *pTableData = (tid < pSnapshot->omem->maxTables) ? pSnapshot->omem->tData[tid] : NULL;
if ((pTableData == NULL) || (TABLE_UID(pTable) != pTableData->uid)) continue;
pSnapshot->mem->tData[tid] = pTableData;
T_REF_INC(pTableData);
}
taosRUnLockLatch(&(pSnapshot->omem->latch));
}
tsdbDebug("vgId:%d take memory snapshot, pMem %p pIMem %p", REPO_ID(pRepo), pSnapshot->omem, pSnapshot->imem);
return 0;
}
void tsdbUnTakeMemSnapShot(STsdbRepo *pRepo, SMemSnapshot *pSnapshot) {
tsdbDebug("vgId:%d untake memory snapshot, pMem %p pIMem %p", REPO_ID(pRepo), pSnapshot->omem, pSnapshot->imem);
if (pSnapshot->mem) {
ASSERT(pSnapshot->omem != NULL);
for (size_t i = 0; i < pSnapshot->mem->maxTables; i++) {
STableData *pTableData = pSnapshot->mem->tData[i];
if (pTableData) {
tsdbFreeTableData(pTableData);
}
}
taosMemoryFreeClear(pSnapshot->mem->tData);
tsdbUnRefMemTable(pRepo, pSnapshot->omem);
}
tsdbUnRefMemTable(pRepo, pSnapshot->imem);
pSnapshot->mem = NULL;
pSnapshot->imem = NULL;
pSnapshot->omem = NULL;
}
int tsdbSyncCommitConfig(STsdbRepo* pRepo) {
ASSERT(pRepo->config_changed == true);
tsem_wait(&(pRepo->readyToCommit));
if (pRepo->code != TSDB_CODE_SUCCESS) {
tsdbWarn("vgId:%d try to commit config when TSDB not in good state: %s", REPO_ID(pRepo), tstrerror(terrno));
}
if (tsdbLockRepo(pRepo) < 0) return -1;
tsdbScheduleCommit(pRepo, COMMIT_CONFIG_REQ);
if (tsdbUnlockRepo(pRepo) < 0) return -1;
tsem_wait(&(pRepo->readyToCommit));
tsem_post(&(pRepo->readyToCommit));
if (pRepo->code != TSDB_CODE_SUCCESS) {
terrno = pRepo->code;
return -1;
}
terrno = TSDB_CODE_SUCCESS;
return 0;
}
/**
* This is an important function to load data or try to load data from memory skiplist iterator.
*
* This function load memory data until:
* 1. iterator ends
* 2. data key exceeds maxKey
* 3. rowsIncreased = rowsInserted - rowsDeleteSucceed >= maxRowsToRead
* 4. operations in pCols not exceeds its max capacity if pCols is given
*
* The function tries to procceed AS MUCH AS POSSIBLE.
*/
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) {
ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0);
if (pIter == NULL) return 0;
STSchema * pSchema = NULL;
TSKEY rowKey = 0;
TSKEY fKey = 0;
bool isRowDel = false;
int filterIter = 0;
STSRow* row = NULL;
SMergeInfo mInfo;
if (pMergeInfo == NULL) pMergeInfo = &mInfo;
memset(pMergeInfo, 0, sizeof(*pMergeInfo));
pMergeInfo->keyFirst = INT64_MAX;
pMergeInfo->keyLast = INT64_MIN;
if (pCols) tdResetDataCols(pCols);
row = tsdbNextIterRow(pIter);
if (row == NULL || TD_ROW_KEY(row) > maxKey) {
rowKey = INT64_MAX;
isRowDel = false;
} else {
rowKey = TD_ROW_KEY(row);
isRowDel = memRowDeleted(row);
}
if (filterIter >= nFilterKeys) {
fKey = INT64_MAX;
} else {
fKey = tdGetKey(filterKeys[filterIter]);
}
while (true) {
if (fKey == INT64_MAX && rowKey == INT64_MAX) break;
if (fKey < rowKey) {
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey);
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey);
filterIter++;
if (filterIter >= nFilterKeys) {
fKey = INT64_MAX;
} else {
fKey = tdGetKey(filterKeys[filterIter]);
}
} else if (fKey > rowKey) {
if (isRowDel) {
pMergeInfo->rowsDeleteFailed++;
} else {
if (pMergeInfo->rowsInserted - pMergeInfo->rowsDeleteSucceed >= maxRowsToRead) break;
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
pMergeInfo->rowsInserted++;
pMergeInfo->nOperations++;
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey);
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey);
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row);
}
tSkipListIterNext(pIter);
row = tsdbNextIterRow(pIter);
if (row == NULL || TD_ROW_KEY(row) > maxKey) {
rowKey = INT64_MAX;
isRowDel = false;
} else {
rowKey = TD_ROW_KEY(row);
isRowDel = memRowDeleted(row);
}
} else {
if (isRowDel) {
ASSERT(!keepDup);
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
pMergeInfo->rowsDeleteSucceed++;
pMergeInfo->nOperations++;
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row);
} else {
if (keepDup) {
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
pMergeInfo->rowsUpdated++;
pMergeInfo->nOperations++;
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey);
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey);
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row);
} else {
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey);
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, fKey);
}
}
tSkipListIterNext(pIter);
row = tsdbNextIterRow(pIter);
if (row == NULL || TD_ROW_KEY(row) > maxKey) {
rowKey = INT64_MAX;
isRowDel = false;
} else {
rowKey = TD_ROW_KEY(row);
isRowDel = memRowDeleted(row);
}
filterIter++;
if (filterIter >= nFilterKeys) {
fKey = INT64_MAX;
} else {
fKey = tdGetKey(filterKeys[filterIter]);
}
}
}
return 0;
}
// ---------------- LOCAL FUNCTIONS ----------------
static FORCE_INLINE int tsdbCheckRowRange(STsdbRepo *pRepo, STable *pTable, STSRow* row, TSKEY minKey, TSKEY maxKey,
TSKEY now) {
TSKEY rowKey = TD_ROW_KEY(row);
if (rowKey < minKey || rowKey > maxKey) {
tsdbError("vgId:%d table %s tid %d uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
" maxKey %" PRId64 " row key %" PRId64,
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), now, minKey, maxKey,
rowKey);
terrno = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
return -1;
}
return 0;
}
//row1 has higher priority
static STSRow* tsdbInsertDupKeyMerge(STSRow* row1, STSRow* row2, STsdbRepo* pRepo,
STSchema **ppSchema1, STSchema **ppSchema2,
STable* pTable, int32_t* pPoints, STSRow** pLastRow) {
//for compatiblity, duplicate key inserted when update=0 should be also calculated as affected rows!
if(row1 == NULL && row2 == NULL && pRepo->config.update == TD_ROW_DISCARD_UPDATE) {
(*pPoints)++;
return NULL;
}
tsdbTrace("vgId:%d a row is %s table %s tid %d uid %" PRIu64 " key %" PRIu64, REPO_ID(pRepo),
"updated in", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable),
TD_ROW_KEY(row1));
if(row2 == NULL || pRepo->config.update != TD_ROW_PARTIAL_UPDATE) {
void* pMem = tsdbAllocBytes(pRepo, TD_ROW_LEN(row1));
if(pMem == NULL) return NULL;
memRowCpy(pMem, row1);
(*pPoints)++;
*pLastRow = pMem;
return pMem;
}
STSchema *pSchema1 = *ppSchema1;
STSchema *pSchema2 = *ppSchema2;
SMergeBuf * pBuf = &pRepo->mergeBuf;
int dv1 = memRowVersion(row1);
int dv2 = memRowVersion(row2);
if(pSchema1 == NULL || schemaVersion(pSchema1) != dv1) {
if(pSchema2 != NULL && schemaVersion(pSchema2) == dv1) {
*ppSchema1 = pSchema2;
} else {
*ppSchema1 = tsdbGetTableSchemaImpl(pTable, false, false, memRowVersion(row1), (int8_t)memRowType(row1));
}
pSchema1 = *ppSchema1;
}
if(pSchema2 == NULL || schemaVersion(pSchema2) != dv2) {
if(schemaVersion(pSchema1) == dv2) {
pSchema2 = pSchema1;
} else {
*ppSchema2 = tsdbGetTableSchemaImpl(pTable, false, false, memRowVersion(row2), (int8_t)memRowType(row2));
pSchema2 = *ppSchema2;
}
}
STSRow* tmp = tsdbMergeTwoRows(pBuf, row1, row2, pSchema1, pSchema2);
void* pMem = tsdbAllocBytes(pRepo, TD_ROW_LEN(tmp));
if(pMem == NULL) return NULL;
memRowCpy(pMem, tmp);
(*pPoints)++;
*pLastRow = pMem;
return pMem;
}
static void* tsdbInsertDupKeyMergePacked(void** args) {
return tsdbInsertDupKeyMerge(args[0], args[1], args[2], (STSchema**)&args[3], (STSchema**)&args[4], args[5], args[6], args[7]);
}
static void tsdbSetupSkipListHookFns(SSkipList* pSkipList, STsdbRepo *pRepo, STable *pTable, int32_t* pPoints, STSRow** pLastRow) {
if(pSkipList->insertHandleFn == NULL) {
tGenericSavedFunc *dupHandleSavedFunc = genericSavedFuncInit((GenericVaFunc)&tsdbInsertDupKeyMergePacked, 9);
dupHandleSavedFunc->args[2] = pRepo;
dupHandleSavedFunc->args[3] = NULL;
dupHandleSavedFunc->args[4] = NULL;
dupHandleSavedFunc->args[5] = pTable;
pSkipList->insertHandleFn = dupHandleSavedFunc;
}
pSkipList->insertHandleFn->args[6] = pPoints;
pSkipList->insertHandleFn->args[7] = pLastRow;
}
static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable) {
ASSERT(pTable != NULL);
STSchema *pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1, -1);
int sversion = schemaVersion(pSchema);
if (pBlock->sversion == sversion) {
return 0;
} else {
if (TABLE_TYPE(pTable) == TSDB_STREAM_TABLE) { // stream table is not allowed to change schema
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
return -1;
}
}
if (pBlock->sversion > sversion) { // may need to update table schema
if (pBlock->schemaLen > 0) {
tsdbDebug(
"vgId:%d table %s tid %d uid %" PRIu64 " schema version %d is out of data, client version %d, update...",
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), sversion, pBlock->sversion);
ASSERT(pBlock->schemaLen % sizeof(STColumn) == 0);
int numOfCols = pBlock->schemaLen / sizeof(STColumn);
STColumn *pTCol = (STColumn *)pBlock->data;
STSchemaBuilder schemaBuilder = {0};
if (tdInitTSchemaBuilder(&schemaBuilder, pBlock->sversion) < 0) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbError("vgId:%d failed to update schema of table %s since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
tstrerror(terrno));
return -1;
}
for (int i = 0; i < numOfCols; i++) {
if (tdAddColToSchema(&schemaBuilder, pTCol[i].type, htons(pTCol[i].colId), htons(pTCol[i].bytes)) < 0) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tsdbError("vgId:%d failed to update schema of table %s since %s", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable),
tstrerror(terrno));
tdDestroyTSchemaBuilder(&schemaBuilder);
return -1;
}
}
STSchema *pNSchema = tdGetSchemaFromBuilder(&schemaBuilder);
if (pNSchema == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
tdDestroyTSchemaBuilder(&schemaBuilder);
return -1;
}
tdDestroyTSchemaBuilder(&schemaBuilder);
tsdbUpdateTableSchema(pRepo, pTable, pNSchema, true);
} else {
tsdbDebug(
"vgId:%d table %s tid %d uid %" PRIu64 " schema version %d is out of data, client version %d, reconfigure...",
REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), sversion, pBlock->sversion);
terrno = TSDB_CODE_TDB_TABLE_RECONFIGURE;
return -1;
}
} else {
ASSERT(pBlock->sversion >= 0);
if (tsdbGetTableSchemaImpl(pTable, false, false, pBlock->sversion, -1) == NULL) {
tsdbError("vgId:%d invalid submit schema version %d to table %s tid %d from client", REPO_ID(pRepo),
pBlock->sversion, TABLE_CHAR_NAME(pTable), TABLE_TID(pTable));
terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION;
return -1;
}
}
return 0;
}
static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, STSRow* row) {
tsdbDebug("vgId:%d updateTableLatestColumn, %s row version:%d", REPO_ID(pRepo), pTable->name->data,
memRowVersion(row));
STSchema* pSchema = tsdbGetTableLatestSchema(pTable);
if (tsdbUpdateLastColSchema(pTable, pSchema) < 0) {
return;
}
pSchema = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row), (int8_t)memRowType(row));
if (pSchema == NULL) {
return;
}
SDataCol *pLatestCols = pTable->lastCols;
int32_t kvIdx = 0;
for (int16_t j = 0; j < schemaNCols(pSchema); j++) {
STColumn *pTCol = schemaColAt(pSchema, j);
// ignore not exist colId
int16_t idx = tsdbGetLastColumnsIndexByColId(pTable, pTCol->colId);
if (idx == -1) {
continue;
}
void *value = NULL;
value = tdGetMemRowDataOfColEx(row, pTCol->colId, (int8_t)pTCol->type,
TD_DATA_ROW_HEAD_SIZE + pSchema->columns[j].offset, &kvIdx);
if ((value == NULL) || isNull(value, pTCol->type)) {
continue;
}
// lock
TSDB_WLOCK_TABLE(pTable);
SDataCol *pDataCol = &(pLatestCols[idx]);
if (pDataCol->pData == NULL) {
pDataCol->pData = taosMemoryMalloc(pTCol->bytes);
pDataCol->bytes = pTCol->bytes;
} else if (pDataCol->bytes < pTCol->bytes) {
pDataCol->pData = taosMemoryRealloc(pDataCol->pData, pTCol->bytes);
pDataCol->bytes = pTCol->bytes;
}
// the actual value size
uint16_t bytes = IS_VAR_DATA_TYPE(pTCol->type) ? varDataTLen(value) : pTCol->bytes;
// the actual data size CANNOT larger than column size
assert(pTCol->bytes >= bytes);
memcpy(pDataCol->pData, value, bytes);
//tsdbInfo("updateTableLatestColumn vgId:%d cache column %d for %d,%s", REPO_ID(pRepo), j, pDataCol->bytes, (char*)pDataCol->pData);
pDataCol->ts = TD_ROW_KEY(row);
// unlock
TSDB_WUNLOCK_TABLE(pTable);
}
}
static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, STSRow* row) {
STsdbCfg *pCfg = &pRepo->config;
// if cacheLastRow config has been reset, free the lastRow
if (!pCfg->cacheLastRow && pTable->lastRow != NULL) {
STSRow* cachedLastRow = pTable->lastRow;
TSDB_WLOCK_TABLE(pTable);
pTable->lastRow = NULL;
TSDB_WUNLOCK_TABLE(pTable);
taosTZfree(cachedLastRow);
}
if (tsdbGetTableLastKeyImpl(pTable) <= TD_ROW_KEY(row)) {
if (CACHE_LAST_ROW(pCfg) || pTable->lastRow != NULL) {
STSRow* nrow = pTable->lastRow;
if (taosTSizeof(nrow) < TD_ROW_LEN(row)) {
STSRow* orow = nrow;
nrow = taosTMalloc(TD_ROW_LEN(row));
if (nrow == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
}
memRowCpy(nrow, row);
TSDB_WLOCK_TABLE(pTable);
pTable->lastKey = TD_ROW_KEY(row);
pTable->lastRow = nrow;
TSDB_WUNLOCK_TABLE(pTable);
taosTZfree(orow);
} else {
TSDB_WLOCK_TABLE(pTable);
pTable->lastKey = TD_ROW_KEY(row);
memRowCpy(nrow, row);
TSDB_WUNLOCK_TABLE(pTable);
}
} else {
pTable->lastKey = TD_ROW_KEY(row);
}
if (CACHE_LAST_NULL_COLUMN(pCfg)) {
updateTableLatestColumn(pRepo, pTable, row);
}
}
pTable->cacheLastConfigVersion = pRepo->cacheLastConfigVersion;
return 0;
}
#endif
\ No newline at end of file
source/dnode/vnode/src/tsdb/tsdbOpen.c
0 → 100644
浏览文件 @
75cad6e3
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tsdb.h"
int
tsdbOpen
(
SVnode
*
pVnode
,
STsdb
**
ppTsdb
)
{
STsdb
*
pTsdb
=
NULL
;
int
slen
=
0
;
*
ppTsdb
=
NULL
;
slen
=
strlen
(
tfsGetPrimaryPath
(
pVnode
->
pTfs
))
+
strlen
(
pVnode
->
path
)
+
strlen
(
VNODE_TSDB_DIR
)
+
3
;
// create handle
pTsdb
=
(
STsdb
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pTsdb
)
+
slen
);
if
(
pTsdb
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pTsdb
->
path
=
(
char
*
)
&
pTsdb
[
1
];
sprintf
(
pTsdb
->
path
,
"%s%s%s%s%s"
,
tfsGetPrimaryPath
(
pVnode
->
pTfs
),
TD_DIRSEP
,
pVnode
->
path
,
TD_DIRSEP
,
VNODE_TSDB_DIR
);
pTsdb
->
pVnode
=
pVnode
;
pTsdb
->
repoLocked
=
false
;
tdbMutexInit
(
&
pTsdb
->
mutex
,
NULL
);
pTsdb
->
config
=
pVnode
->
config
.
tsdbCfg
;
pTsdb
->
fs
=
tsdbNewFS
(
&
pTsdb
->
config
);
// create dir (TODO: use tfsMkdir)
taosMkDir
(
pTsdb
->
path
);
// open tsdb
if
(
tsdbOpenFS
(
pTsdb
)
<
0
)
{
goto
_err
;
}
tsdbDebug
(
"vgId: %d tsdb is opened"
,
TD_VID
(
pVnode
));
*
ppTsdb
=
pTsdb
;
return
0
;
_err:
taosMemoryFree
(
pTsdb
);
return
-
1
;
}
int
tsdbClose
(
STsdb
*
pTsdb
)
{
if
(
pTsdb
)
{
tsdbCloseFS
(
pTsdb
);
tsdbFreeFS
(
pTsdb
->
fs
);
taosMemoryFree
(
pTsdb
);
}
return
0
;
}
int
tsdbLockRepo
(
STsdb
*
pTsdb
)
{
int
code
=
taosThreadMutexLock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to lock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
pTsdb
->
repoLocked
=
true
;
return
0
;
}
int
tsdbUnlockRepo
(
STsdb
*
pTsdb
)
{
ASSERT
(
IS_REPO_LOCKED
(
pTsdb
));
pTsdb
->
repoLocked
=
false
;
int
code
=
taosThreadMutexUnlock
(
&
pTsdb
->
mutex
);
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to unlock tsdb since %s"
,
REPO_ID
(
pTsdb
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
\ No newline at end of file
source/dnode/vnode/src/vnd/vnodeCfg.c
浏览文件 @
75cad6e3
...
@@ -23,8 +23,6 @@ const SVnodeCfg vnodeCfgDefault = {
...
@@ -23,8 +23,6 @@ const SVnodeCfg vnodeCfgDefault = {
.
szCache
=
256
,
.
szCache
=
256
,
.
szBuf
=
96
*
1024
*
1024
,
.
szBuf
=
96
*
1024
*
1024
,
.
isHeap
=
false
,
.
isHeap
=
false
,
.
ttl
=
0
,
.
keep
=
0
,
.
streamMode
=
0
,
.
streamMode
=
0
,
.
isWeak
=
0
,
.
isWeak
=
0
,
.
tsdbCfg
=
{.
precision
=
TSDB_TIME_PRECISION_MILLI
,
.
tsdbCfg
=
{.
precision
=
TSDB_TIME_PRECISION_MILLI
,
...
@@ -58,8 +56,6 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
...
@@ -58,8 +56,6 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
if
(
tjsonAddIntegerToObject
(
pJson
,
"szCache"
,
pCfg
->
szCache
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"szCache"
,
pCfg
->
szCache
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"szBuf"
,
pCfg
->
szBuf
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"szBuf"
,
pCfg
->
szBuf
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isHeap"
,
pCfg
->
isHeap
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isHeap"
,
pCfg
->
isHeap
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"ttl"
,
pCfg
->
ttl
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep"
,
pCfg
->
keep
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
...
@@ -72,7 +68,6 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
...
@@ -72,7 +68,6 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"lruCacheSize"
,
pCfg
->
tsdbCfg
.
lruCacheSize
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
if
(
tjsonAddIntegerToObject
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
...
@@ -109,8 +104,6 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
...
@@ -109,8 +104,6 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
if
(
tjsonGetNumberValue
(
pJson
,
"szCache"
,
pCfg
->
szCache
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"szCache"
,
pCfg
->
szCache
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"szBuf"
,
pCfg
->
szBuf
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"szBuf"
,
pCfg
->
szBuf
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isHeap"
,
pCfg
->
isHeap
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isHeap"
,
pCfg
->
isHeap
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"ttl"
,
pCfg
->
ttl
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep"
,
pCfg
->
keep
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"streamMode"
,
pCfg
->
streamMode
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
)
<
0
)
return
-
1
;
...
@@ -123,7 +116,6 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
...
@@ -123,7 +116,6 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
if
(
tjsonGetNumberValue
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"lruCacheSize"
,
pCfg
->
tsdbCfg
.
lruCacheSize
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
if
(
tjsonGetNumberValue
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
)
<
0
)
return
-
1
;
...
...
source/dnode/vnode/src/vnd/vnodeQuery.c
浏览文件 @
75cad6e3
...
@@ -138,3 +138,13 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
...
@@ -138,3 +138,13 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
pLoad
->
numOfBatchInsertSuccessReqs
=
4
;
pLoad
->
numOfBatchInsertSuccessReqs
=
4
;
return
0
;
return
0
;
}
}
void
vnodeGetInfo
(
SVnode
*
pVnode
,
const
char
**
dbname
,
int32_t
*
vgId
)
{
if
(
dbname
)
{
*
dbname
=
pVnode
->
config
.
dbname
;
}
if
(
vgId
)
{
*
vgId
=
TD_VID
(
pVnode
);
}
}
\ No newline at end of file
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
75cad6e3
...
@@ -142,7 +142,7 @@ _err:
...
@@ -142,7 +142,7 @@ _err:
int
vnodeProcessQueryMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
int
vnodeProcessQueryMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
vTrace
(
"message in vnode query queue is processing"
);
vTrace
(
"message in vnode query queue is processing"
);
SReadHandle
handle
=
{.
reader
=
pVnode
->
pTsdb
,
.
meta
=
pVnode
->
pMeta
,
.
config
=
&
pVnode
->
config
};
SReadHandle
handle
=
{.
reader
=
pVnode
->
pTsdb
,
.
meta
=
pVnode
->
pMeta
,
.
config
=
&
pVnode
->
config
,
.
vnode
=
pVnode
};
switch
(
pMsg
->
msgType
)
{
switch
(
pMsg
->
msgType
)
{
case
TDMT_VND_QUERY
:
case
TDMT_VND_QUERY
:
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
75cad6e3
...
@@ -380,7 +380,7 @@ typedef struct SStreamBlockScanInfo {
...
@@ -380,7 +380,7 @@ typedef struct SStreamBlockScanInfo {
typedef
struct
SSysTableScanInfo
{
typedef
struct
SSysTableScanInfo
{
union
{
union
{
void
*
pTransporter
;
void
*
pTransporter
;
void
*
readHandle
;
SReadHandle
readHandle
;
};
};
SRetrieveMetaTableRsp
*
pRsp
;
SRetrieveMetaTableRsp
*
pRsp
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
75cad6e3
...
@@ -3738,7 +3738,32 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf
...
@@ -3738,7 +3738,32 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
// TODO if only one or two columns required, how to extract data?
// NOTE: sources columns are more than the destination SSDatablock columns.
static
void
relocateColumnData
(
SSDataBlock
*
pBlock
,
const
SArray
*
pColMatchInfo
,
SArray
*
pCols
)
{
size_t
numOfSrcCols
=
taosArrayGetSize
(
pCols
);
ASSERT
(
numOfSrcCols
>=
pBlock
->
info
.
numOfCols
);
int32_t
i
=
0
,
j
=
0
;
while
(
i
<
numOfSrcCols
&&
j
<
taosArrayGetSize
(
pColMatchInfo
))
{
SColumnInfoData
*
p
=
taosArrayGet
(
pCols
,
i
);
SColMatchInfo
*
pmInfo
=
taosArrayGet
(
pColMatchInfo
,
j
);
if
(
!
pmInfo
->
output
)
{
j
++
;
continue
;
}
if
(
p
->
info
.
colId
==
pmInfo
->
colId
)
{
taosArraySet
(
pBlock
->
pDataBlock
,
pmInfo
->
targetSlotId
,
p
);
i
++
;
j
++
;
}
else
if
(
p
->
info
.
colId
<
pmInfo
->
colId
)
{
i
++
;
}
else
{
ASSERT
(
0
);
}
}
}
int32_t
setSDataBlockFromFetchRsp
(
SSDataBlock
*
pRes
,
SLoadRemoteDataInfo
*
pLoadInfo
,
int32_t
numOfRows
,
char
*
pData
,
int32_t
setSDataBlockFromFetchRsp
(
SSDataBlock
*
pRes
,
SLoadRemoteDataInfo
*
pLoadInfo
,
int32_t
numOfRows
,
char
*
pData
,
int32_t
compLen
,
int32_t
numOfOutput
,
int64_t
startTs
,
uint64_t
*
total
,
int32_t
compLen
,
int32_t
numOfOutput
,
int64_t
startTs
,
uint64_t
*
total
,
SArray
*
pColList
)
{
SArray
*
pColList
)
{
...
@@ -3756,7 +3781,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
...
@@ -3756,7 +3781,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
char
*
pStart
=
pData
+
sizeof
(
int32_t
)
*
numOfOutput
;
char
*
pStart
=
pData
+
sizeof
(
int32_t
)
*
numOfOutput
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
colLen
[
i
]
=
htonl
(
colLen
[
i
]);
colLen
[
i
]
=
htonl
(
colLen
[
i
]);
ASSERT
(
colLen
[
i
]
>
0
);
ASSERT
(
colLen
[
i
]
>
=
0
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pRes
->
pDataBlock
,
i
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pRes
->
pDataBlock
,
i
);
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
...
@@ -3766,13 +3791,18 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
...
@@ -3766,13 +3791,18 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
memcpy
(
pColInfoData
->
varmeta
.
offset
,
pStart
,
sizeof
(
int32_t
)
*
numOfRows
);
memcpy
(
pColInfoData
->
varmeta
.
offset
,
pStart
,
sizeof
(
int32_t
)
*
numOfRows
);
pStart
+=
sizeof
(
int32_t
)
*
numOfRows
;
pStart
+=
sizeof
(
int32_t
)
*
numOfRows
;
if
(
colLen
[
i
]
>
0
)
{
pColInfoData
->
pData
=
taosMemoryMalloc
(
colLen
[
i
]);
pColInfoData
->
pData
=
taosMemoryMalloc
(
colLen
[
i
]);
}
}
else
{
}
else
{
memcpy
(
pColInfoData
->
nullbitmap
,
pStart
,
BitmapLen
(
numOfRows
));
memcpy
(
pColInfoData
->
nullbitmap
,
pStart
,
BitmapLen
(
numOfRows
));
pStart
+=
BitmapLen
(
numOfRows
);
pStart
+=
BitmapLen
(
numOfRows
);
}
}
if
(
colLen
[
i
]
>
0
)
{
memcpy
(
pColInfoData
->
pData
,
pStart
,
colLen
[
i
]);
memcpy
(
pColInfoData
->
pData
,
pStart
,
colLen
[
i
]);
}
//TODO setting this flag to true temporarily so aggregate function on stable will
//TODO setting this flag to true temporarily so aggregate function on stable will
//examine NULL value for non-primary key column
//examine NULL value for non-primary key column
pColInfoData
->
hasNull
=
true
;
pColInfoData
->
hasNull
=
true
;
...
@@ -3785,6 +3815,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
...
@@ -3785,6 +3815,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
int32_t
numOfCols
=
htonl
(
*
(
int32_t
*
)
pStart
);
int32_t
numOfCols
=
htonl
(
*
(
int32_t
*
)
pStart
);
pStart
+=
sizeof
(
int32_t
);
pStart
+=
sizeof
(
int32_t
);
// todo refactor:extract method
SSysTableSchema
*
pSchema
=
(
SSysTableSchema
*
)
pStart
;
SSysTableSchema
*
pSchema
=
(
SSysTableSchema
*
)
pStart
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SSysTableSchema
*
p
=
(
SSysTableSchema
*
)
pStart
;
SSysTableSchema
*
p
=
(
SSysTableSchema
*
)
pStart
;
...
@@ -3839,19 +3870,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
...
@@ -3839,19 +3870,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
}
}
// data from mnode
// data from mnode
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
relocateColumnData
(
pRes
,
pColList
,
block
.
pDataBlock
);
SColumnInfoData
*
pSrc
=
taosArrayGet
(
block
.
pDataBlock
,
i
);
for
(
int32_t
j
=
0
;
j
<
numOfOutput
;
++
j
)
{
int16_t
colIndex
=
*
(
int16_t
*
)
taosArrayGet
(
pColList
,
j
);
if
(
colIndex
-
1
==
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pRes
->
pDataBlock
,
j
);
colDataAssign
(
pColInfoData
,
pSrc
,
numOfRows
);
break
;
}
}
}
}
}
pRes
->
info
.
rows
=
numOfRows
;
pRes
->
info
.
rows
=
numOfRows
;
...
@@ -6423,7 +6442,6 @@ static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SRead
...
@@ -6423,7 +6442,6 @@ static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SRead
static
int32_t
doCreateTableGroup
(
void
*
metaHandle
,
int32_t
tableType
,
uint64_t
tableUid
,
STableGroupInfo
*
pGroupInfo
,
static
int32_t
doCreateTableGroup
(
void
*
metaHandle
,
int32_t
tableType
,
uint64_t
tableUid
,
STableGroupInfo
*
pGroupInfo
,
uint64_t
queryId
,
uint64_t
taskId
);
uint64_t
queryId
,
uint64_t
taskId
);
static
SArray
*
extractTableIdList
(
const
STableGroupInfo
*
pTableGroupInfo
);
static
SArray
*
extractTableIdList
(
const
STableGroupInfo
*
pTableGroupInfo
);
static
SArray
*
extractScanColumnId
(
SNodeList
*
pNodeList
);
static
SArray
*
extractColumnInfo
(
SNodeList
*
pNodeList
);
static
SArray
*
extractColumnInfo
(
SNodeList
*
pNodeList
);
static
SArray
*
extractColMatchInfo
(
SNodeList
*
pNodeList
,
SDataBlockDescNode
*
pOutputNodeList
,
int32_t
*
numOfOutputCols
);
static
SArray
*
extractColMatchInfo
(
SNodeList
*
pNodeList
,
SDataBlockDescNode
*
pOutputNodeList
,
int32_t
*
numOfOutputCols
);
...
@@ -6494,10 +6512,11 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
...
@@ -6494,10 +6512,11 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
SScanPhysiNode
*
pScanNode
=
&
pSysScanPhyNode
->
scan
;
SScanPhysiNode
*
pScanNode
=
&
pSysScanPhyNode
->
scan
;
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pScanNode
->
node
.
pOutputDataBlockDesc
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pScanNode
->
node
.
pOutputDataBlockDesc
);
SArray
*
colList
=
extractScanColumnId
(
pScanNode
->
pScanCols
);
int32_t
numOfOutputCols
=
0
;
SArray
*
colList
=
extractColMatchInfo
(
pScanNode
->
pScanCols
,
pScanNode
->
node
.
pOutputDataBlockDesc
,
&
numOfOutputCols
);
SOperatorInfo
*
pOperator
=
createSysTableScanOperatorInfo
(
SOperatorInfo
*
pOperator
=
createSysTableScanOperatorInfo
(
pHandle
->
meta
,
pResBlock
,
&
pScanNode
->
tableName
,
pScanNode
->
node
.
pConditions
,
pSysScanPhyNode
->
mgmtEpSet
,
pHandle
,
pResBlock
,
&
pScanNode
->
tableName
,
pScanNode
->
node
.
pConditions
,
pSysScanPhyNode
->
mgmtEpSet
,
colList
,
pTaskInfo
,
pSysScanPhyNode
->
showRewrite
,
pSysScanPhyNode
->
accountId
);
colList
,
pTaskInfo
,
pSysScanPhyNode
->
showRewrite
,
pSysScanPhyNode
->
accountId
);
return
pOperator
;
return
pOperator
;
}
else
{
}
else
{
...
@@ -6658,28 +6677,6 @@ static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableS
...
@@ -6658,28 +6677,6 @@ static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableS
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SArray
*
extractScanColumnId
(
SNodeList
*
pNodeList
)
{
size_t
numOfCols
=
LIST_LENGTH
(
pNodeList
);
SArray
*
pList
=
taosArrayInit
(
numOfCols
,
sizeof
(
int16_t
));
if
(
pList
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
j
=
0
;
j
<
numOfCols
;
++
j
)
{
STargetNode
*
pNode
=
(
STargetNode
*
)
nodesListGetNode
(
pNodeList
,
j
);
if
(
pNode
->
slotId
==
i
)
{
SColumnNode
*
pColNode
=
(
SColumnNode
*
)
pNode
->
pExpr
;
taosArrayPush
(
pList
,
&
pColNode
->
colId
);
break
;
}
}
}
return
pList
;
}
SArray
*
extractColumnInfo
(
SNodeList
*
pNodeList
)
{
SArray
*
extractColumnInfo
(
SNodeList
*
pNodeList
)
{
size_t
numOfCols
=
LIST_LENGTH
(
pNodeList
);
size_t
numOfCols
=
LIST_LENGTH
(
pNodeList
);
SArray
*
pList
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumn
));
SArray
*
pList
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumn
));
...
@@ -6815,9 +6812,9 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
...
@@ -6815,9 +6812,9 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
SColumnNode
*
pColNode
=
(
SColumnNode
*
)
pNode
->
pExpr
;
SColumnNode
*
pColNode
=
(
SColumnNode
*
)
pNode
->
pExpr
;
SColMatchInfo
c
=
{
0
};
SColMatchInfo
c
=
{
0
};
c
.
output
=
true
;
c
.
colId
=
pColNode
->
colId
;
c
.
colId
=
pColNode
->
colId
;
c
.
targetSlotId
=
pNode
->
slotId
;
c
.
targetSlotId
=
pNode
->
slotId
;
c
.
output
=
true
;
taosArrayPush
(
pList
,
&
c
);
taosArrayPush
(
pList
,
&
c
);
}
}
...
@@ -6825,8 +6822,10 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
...
@@ -6825,8 +6822,10 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
int32_t
num
=
LIST_LENGTH
(
pOutputNodeList
->
pSlots
);
int32_t
num
=
LIST_LENGTH
(
pOutputNodeList
->
pSlots
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SSlotDescNode
*
pNode
=
(
SSlotDescNode
*
)
nodesListGetNode
(
pOutputNodeList
->
pSlots
,
i
);
SSlotDescNode
*
pNode
=
(
SSlotDescNode
*
)
nodesListGetNode
(
pOutputNodeList
->
pSlots
,
i
);
// todo: add reserve flag check
// todo: add reserve flag check
if
(
pNode
->
slotId
>=
numOfCols
)
{
// it is a column reserved for the arithmetic expression calculation
// it is a column reserved for the arithmetic expression calculation
if
(
pNode
->
slotId
>=
numOfCols
)
{
(
*
numOfOutputCols
)
+=
1
;
(
*
numOfOutputCols
)
+=
1
;
continue
;
continue
;
}
}
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
75cad6e3
...
@@ -811,7 +811,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
...
@@ -811,7 +811,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
const
char
*
name
=
tNameGetTableName
(
&
pInfo
->
name
);
const
char
*
name
=
tNameGetTableName
(
&
pInfo
->
name
);
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_USER_TABLES
,
TSDB_TABLE_FNAME_LEN
)
==
0
)
{
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_USER_TABLES
,
TSDB_TABLE_FNAME_LEN
)
==
0
)
{
if
(
pInfo
->
pCur
==
NULL
)
{
if
(
pInfo
->
pCur
==
NULL
)
{
pInfo
->
pCur
=
metaOpenTbCursor
(
pInfo
->
readHandle
);
pInfo
->
pCur
=
metaOpenTbCursor
(
pInfo
->
readHandle
.
meta
);
}
}
blockDataCleanup
(
pInfo
->
pRes
);
blockDataCleanup
(
pInfo
->
pRes
);
...
@@ -819,32 +819,97 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
...
@@ -819,32 +819,97 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
int32_t
tableNameSlotId
=
1
;
int32_t
tableNameSlotId
=
1
;
SColumnInfoData
*
pTableNameCol
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
tableNameSlotId
);
SColumnInfoData
*
pTableNameCol
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
tableNameSlotId
);
char
*
tb
=
NULL
;
int32_t
numOfRows
=
0
;
int32_t
numOfRows
=
0
;
const
char
*
db
=
NULL
;
int32_t
vgId
=
0
;
vnodeGetInfo
(
pInfo
->
readHandle
.
vnode
,
&
db
,
&
vgId
);
SName
sn
=
{
0
};
char
dbname
[
TSDB_DB_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
sn
,
db
,
T_NAME_ACCT
|
T_NAME_DB
);
tNameGetDbName
(
&
sn
,
varDataVal
(
dbname
));
varDataSetLen
(
dbname
,
strlen
(
varDataVal
(
dbname
)));
char
n
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
char
n
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
while
(
metaTbCursorNext
(
pInfo
->
pCur
)
==
0
)
{
while
(
metaTbCursorNext
(
pInfo
->
pCur
)
==
0
)
{
STR_TO_VARSTR
(
n
,
pInfo
->
pCur
->
mr
.
me
.
name
);
STR_TO_VARSTR
(
n
,
pInfo
->
pCur
->
mr
.
me
.
name
);
colDataAppend
(
pTableNameCol
,
numOfRows
,
n
,
false
);
colDataAppend
(
pTableNameCol
,
numOfRows
,
n
,
false
);
numOfRows
+=
1
;
if
(
numOfRows
>=
pInfo
->
capacity
)
{
break
;
}
for
(
int32_t
i
=
0
;
i
<
pInfo
->
pRes
->
info
.
numOfCols
;
++
i
)
{
int32_t
tableType
=
pInfo
->
pCur
->
mr
.
me
.
type
;
if
(
i
==
tableNameSlotId
)
{
continue
;
}
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
i
);
// database name
int64_t
tmp
=
0
;
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
0
);
char
t
[
10
]
=
{
0
};
colDataAppend
(
pColInfoData
,
numOfRows
,
dbname
,
false
);
STR_TO_VARSTR
(
t
,
"_"
);
// TODO
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
// vgId
colDataAppend
(
pColInfoData
,
numOfRows
,
t
,
false
);
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
6
);
}
else
{
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
vgId
,
false
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
tmp
,
false
);
// table comment
// todo: set the correct comment
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
8
);
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
char
str
[
256
]
=
{
0
};
if
(
tableType
==
TSDB_CHILD_TABLE
)
{
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
pInfo
->
readHandle
.
meta
,
0
);
metaGetTableEntryByUid
(
&
mr
,
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
suid
);
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr
.
me
.
stbEntry
.
schema
.
nCols
,
false
);
// create time
int64_t
ts
=
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
ctime
;
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
ts
,
false
);
// super table name
STR_TO_VARSTR
(
str
,
mr
.
me
.
name
);
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
4
);
colDataAppend
(
pColInfoData
,
numOfRows
,
str
,
false
);
metaReaderClear
(
&
mr
);
// uid
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
uid
,
false
);
// ttl
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
ttlDays
,
false
);
STR_TO_VARSTR
(
str
,
"CHILD_TABLE"
);
}
else
if
(
tableType
==
TSDB_NORMAL_TABLE
)
{
// create time
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
ctime
,
false
);
// number of columns
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
schema
.
nCols
,
false
);
// super table name
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
4
);
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
// uid
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
uid
,
false
);
// ttl
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
ttlDays
,
false
);
STR_TO_VARSTR
(
str
,
"NORMAL_TABLE"
);
}
}
pColInfoData
=
taosArrayGet
(
pInfo
->
pRes
->
pDataBlock
,
9
);
colDataAppend
(
pColInfoData
,
numOfRows
,
str
,
false
);
if
(
++
numOfRows
>=
pInfo
->
capacity
)
{
break
;
}
}
}
}
...
@@ -923,7 +988,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
...
@@ -923,7 +988,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
}
}
}
}
SOperatorInfo
*
createSysTableScanOperatorInfo
(
void
*
pSysTableR
eadHandle
,
SSDataBlock
*
pResBlock
,
const
SName
*
pName
,
SOperatorInfo
*
createSysTableScanOperatorInfo
(
void
*
r
eadHandle
,
SSDataBlock
*
pResBlock
,
const
SName
*
pName
,
SNode
*
pCondition
,
SEpSet
epset
,
SArray
*
colList
,
SNode
*
pCondition
,
SEpSet
epset
,
SArray
*
colList
,
SExecTaskInfo
*
pTaskInfo
,
bool
showRewrite
,
int32_t
accountId
)
{
SExecTaskInfo
*
pTaskInfo
,
bool
showRewrite
,
int32_t
accountId
)
{
SSysTableScanInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SSysTableScanInfo
));
SSysTableScanInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SSysTableScanInfo
));
...
@@ -945,7 +1010,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB
...
@@ -945,7 +1010,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB
tNameAssign
(
&
pInfo
->
name
,
pName
);
tNameAssign
(
&
pInfo
->
name
,
pName
);
const
char
*
name
=
tNameGetTableName
(
&
pInfo
->
name
);
const
char
*
name
=
tNameGetTableName
(
&
pInfo
->
name
);
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_USER_TABLES
,
TSDB_TABLE_FNAME_LEN
)
==
0
)
{
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_USER_TABLES
,
TSDB_TABLE_FNAME_LEN
)
==
0
)
{
pInfo
->
readHandle
=
pSysTableR
eadHandle
;
pInfo
->
readHandle
=
*
(
SReadHandle
*
)
r
eadHandle
;
blockDataEnsureCapacity
(
pInfo
->
pRes
,
pInfo
->
capacity
);
blockDataEnsureCapacity
(
pInfo
->
pRes
,
pInfo
->
capacity
);
}
else
{
}
else
{
tsem_init
(
&
pInfo
->
ready
,
0
,
0
);
tsem_init
(
&
pInfo
->
ready
,
0
,
0
);
...
...
source/libs/transport/inc/transComm.h
浏览文件 @
75cad6e3
...
@@ -21,6 +21,7 @@ extern "C" {
...
@@ -21,6 +21,7 @@ extern "C" {
#include <uv.h>
#include <uv.h>
#include "lz4.h"
#include "lz4.h"
#include "os.h"
#include "os.h"
#include "osSocket.h"
#include "rpcCache.h"
#include "rpcCache.h"
#include "rpcHead.h"
#include "rpcHead.h"
#include "rpcLog.h"
#include "rpcLog.h"
...
@@ -105,6 +106,7 @@ typedef void* queue[2];
...
@@ -105,6 +106,7 @@ typedef void* queue[2];
#define TRANS_RETRY_COUNT_LIMIT 10 // retry count limit
#define TRANS_RETRY_COUNT_LIMIT 10 // retry count limit
#define TRANS_RETRY_INTERVAL 5 // ms retry interval
#define TRANS_RETRY_INTERVAL 5 // ms retry interval
#define TRANS_CONN_TIMEOUT 3 // connect timeout
typedef
struct
{
typedef
struct
{
SRpcInfo
*
pRpc
;
// associated SRpcInfo
SRpcInfo
*
pRpc
;
// associated SRpcInfo
...
...
source/libs/transport/src/transCli.c
浏览文件 @
75cad6e3
...
@@ -103,6 +103,10 @@ static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle o
...
@@ -103,6 +103,10 @@ static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle o
static
void
cliDestroy
(
uv_handle_t
*
handle
);
static
void
cliDestroy
(
uv_handle_t
*
handle
);
static
void
cliSend
(
SCliConn
*
pConn
);
static
void
cliSend
(
SCliConn
*
pConn
);
/*
* set TCP connection timeout per-socket level
*/
static
int
cliCreateSocket
();
// process data read from server, add decompress etc later
// process data read from server, add decompress etc later
static
void
cliHandleResp
(
SCliConn
*
conn
);
static
void
cliHandleResp
(
SCliConn
*
conn
);
// handle except about conn
// handle except about conn
...
@@ -729,9 +733,15 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
...
@@ -729,9 +733,15 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
if
(
ret
)
{
if
(
ret
)
{
tError
(
"%s cli conn %p failed to set conn option, errmsg %s"
,
pTransInst
->
label
,
conn
,
uv_err_name
(
ret
));
tError
(
"%s cli conn %p failed to set conn option, errmsg %s"
,
pTransInst
->
label
,
conn
,
uv_err_name
(
ret
));
}
}
int
fd
=
taosCreateSocketWithTimeOutOpt
(
TRANS_CONN_TIMEOUT
);
if
(
fd
==
-
1
)
{
tTrace
(
"%s cli conn %p failed to create socket"
,
pTransInst
->
label
,
conn
);
cliHandleExcept
(
conn
);
return
;
}
uv_tcp_open
((
uv_tcp_t
*
)
conn
->
stream
,
fd
);
struct
sockaddr_in
addr
;
struct
sockaddr_in
addr
;
addr
.
sin_family
=
AF_INET
;
addr
.
sin_family
=
AF_INET
;
addr
.
sin_addr
.
s_addr
=
taosGetIpv4FromFqdn
(
conn
->
ip
);
addr
.
sin_addr
.
s_addr
=
taosGetIpv4FromFqdn
(
conn
->
ip
);
addr
.
sin_port
=
(
uint16_t
)
htons
((
uint16_t
)
conn
->
port
);
addr
.
sin_port
=
(
uint16_t
)
htons
((
uint16_t
)
conn
->
port
);
...
...
source/os/src/osSocket.c
浏览文件 @
75cad6e3
...
@@ -37,20 +37,24 @@
...
@@ -37,20 +37,24 @@
#include <unistd.h>
#include <unistd.h>
#if defined(DARWIN)
#if defined(DARWIN)
#include <dispatch/dispatch.h>
#include <dispatch/dispatch.h>
#include "osEok.h"
#include "osEok.h"
#else
#else
#include <sys/epoll.h>
#include <sys/epoll.h>
#endif
#endif
#endif
#endif
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
typedef
struct
TdSocketServer
{
typedef
struct
TdSocketServer
{
#if SOCKET_WITH_LOCK
#if SOCKET_WITH_LOCK
TdThreadRwlock
rwlock
;
TdThreadRwlock
rwlock
;
#endif
#endif
int
refId
;
int
refId
;
SocketFd
fd
;
SocketFd
fd
;
}
*
TdSocketServerPtr
,
TdSocketServer
;
}
*
TdSocketServerPtr
,
TdSocketServer
;
typedef
struct
TdEpoll
{
typedef
struct
TdEpoll
{
#if SOCKET_WITH_LOCK
#if SOCKET_WITH_LOCK
...
@@ -58,7 +62,7 @@ typedef struct TdEpoll {
...
@@ -58,7 +62,7 @@ typedef struct TdEpoll {
#endif
#endif
int
refId
;
int
refId
;
EpollFd
fd
;
EpollFd
fd
;
}
*
TdEpollPtr
,
TdEpoll
;
}
*
TdEpollPtr
,
TdEpoll
;
int32_t
taosSendto
(
TdSocketPtr
pSocket
,
void
*
buf
,
int
len
,
unsigned
int
flags
,
const
struct
sockaddr
*
dest_addr
,
int32_t
taosSendto
(
TdSocketPtr
pSocket
,
void
*
buf
,
int
len
,
unsigned
int
flags
,
const
struct
sockaddr
*
dest_addr
,
int
addrlen
)
{
int
addrlen
)
{
...
@@ -94,7 +98,8 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) {
...
@@ -94,7 +98,8 @@ int32_t taosReadSocket(TdSocketPtr pSocket, void *buf, int len) {
#endif
#endif
}
}
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
)
{
int32_t
taosReadFromSocket
(
TdSocketPtr
pSocket
,
void
*
buf
,
int32_t
len
,
int32_t
flags
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
)
{
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
if
(
pSocket
==
NULL
||
pSocket
->
fd
<
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -318,7 +323,7 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *buf, int32_t nbytes) {
...
@@ -318,7 +323,7 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *buf, int32_t nbytes) {
return
-
1
;
return
-
1
;
}
}
int32_t
nleft
,
nwritten
;
int32_t
nleft
,
nwritten
;
char
*
ptr
=
(
char
*
)
buf
;
char
*
ptr
=
(
char
*
)
buf
;
nleft
=
nbytes
;
nleft
=
nbytes
;
...
@@ -347,7 +352,7 @@ int32_t taosReadMsg(TdSocketPtr pSocket, void *buf, int32_t nbytes) {
...
@@ -347,7 +352,7 @@ int32_t taosReadMsg(TdSocketPtr pSocket, void *buf, int32_t nbytes) {
return
-
1
;
return
-
1
;
}
}
int32_t
nleft
,
nread
;
int32_t
nleft
,
nread
;
char
*
ptr
=
(
char
*
)
buf
;
char
*
ptr
=
(
char
*
)
buf
;
nleft
=
nbytes
;
nleft
=
nbytes
;
...
@@ -689,8 +694,7 @@ TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
...
@@ -689,8 +694,7 @@ TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
return
(
TdSocketServerPtr
)
pSocket
;
return
(
TdSocketServerPtr
)
pSocket
;
}
}
TdSocketPtr
taosAcceptTcpConnectSocket
(
TdSocketServerPtr
pServerSocket
,
struct
sockaddr
*
destAddr
,
TdSocketPtr
taosAcceptTcpConnectSocket
(
TdSocketServerPtr
pServerSocket
,
struct
sockaddr
*
destAddr
,
int
*
addrLen
)
{
int
*
addrLen
)
{
if
(
pServerSocket
==
NULL
||
pServerSocket
->
fd
<
0
)
{
if
(
pServerSocket
==
NULL
||
pServerSocket
->
fd
<
0
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -771,7 +775,7 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) {
...
@@ -771,7 +775,7 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) {
int32_t
ret
=
getaddrinfo
(
fqdn
,
NULL
,
&
hints
,
&
result
);
int32_t
ret
=
getaddrinfo
(
fqdn
,
NULL
,
&
hints
,
&
result
);
if
(
result
)
{
if
(
result
)
{
struct
sockaddr
*
sa
=
result
->
ai_addr
;
struct
sockaddr
*
sa
=
result
->
ai_addr
;
struct
sockaddr_in
*
si
=
(
struct
sockaddr_in
*
)
sa
;
struct
sockaddr_in
*
si
=
(
struct
sockaddr_in
*
)
sa
;
struct
in_addr
ia
=
si
->
sin_addr
;
struct
in_addr
ia
=
si
->
sin_addr
;
uint32_t
ip
=
ia
.
s_addr
;
uint32_t
ip
=
ia
.
s_addr
;
...
@@ -887,7 +891,6 @@ int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *a
...
@@ -887,7 +891,6 @@ int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *a
return
getsockname
(
pSocket
->
fd
,
destAddr
,
addrLen
);
return
getsockname
(
pSocket
->
fd
,
destAddr
,
addrLen
);
}
}
TdEpollPtr
taosCreateEpoll
(
int32_t
size
)
{
TdEpollPtr
taosCreateEpoll
(
int32_t
size
)
{
EpollFd
fd
=
-
1
;
EpollFd
fd
=
-
1
;
#ifdef WINDOWS
#ifdef WINDOWS
...
@@ -939,3 +942,28 @@ int32_t taosCloseEpoll(TdEpollPtr *ppEpoll) {
...
@@ -939,3 +942,28 @@ int32_t taosCloseEpoll(TdEpollPtr *ppEpoll) {
taosMemoryFree
(
*
ppEpoll
);
taosMemoryFree
(
*
ppEpoll
);
return
code
;
return
code
;
}
}
/*
* Set TCP connection timeout per-socket level.
* ref [https://github.com/libuv/help/issues/54]
*/
int
taosCreateSocketWithTimeOutOpt
(
uint32_t
conn_timeout_sec
)
{
#if defined(WINDOWS)
SOCKET
fd
;
#else
int
fd
;
#endif
if
((
fd
=
socket
(
PF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
))
==
INVALID_SOCKET
)
{
return
-
1
;
}
#if defined(WINDOWS)
if
(
0
!=
setsockopt
(
fd
,
IPPROTO_TCP
,
TCP_MAXRT
,
(
char
*
)
&
conn_timeout_sec
,
sizeof
(
conn_timeout_sec
)))
{
return
-
1
;
}
#else // Linux like systems
uint32_t
conn_timeout_ms
=
conn_timeout_sec
*
1000
;
if
(
0
!=
setsockopt
(
fd
,
IPPROTO_TCP
,
TCP_USER_TIMEOUT
,
(
char
*
)
&
conn_timeout_ms
,
sizeof
(
conn_timeout_ms
)))
{
return
-
1
;
}
#endif
return
(
int
)
fd
;
}
source/util/src/tarray.c
浏览文件 @
75cad6e3
...
@@ -482,3 +482,22 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
...
@@ -482,3 +482,22 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
taosArrayGetSize
(
pArray
)
>
8
?
taosArrayQuickSort
(
pArray
,
fn
,
param
)
:
taosArrayInsertSort
(
pArray
,
fn
,
param
);
taosArrayGetSize
(
pArray
)
>
8
?
taosArrayQuickSort
(
pArray
,
fn
,
param
)
:
taosArrayInsertSort
(
pArray
,
fn
,
param
);
}
}
// TODO(yihaoDeng) add order array<type>
// TODO(yihaoDeng) add order array<type>
//
char
*
taosShowStrArray
(
const
SArray
*
pArray
)
{
int32_t
sz
=
pArray
->
size
;
int32_t
tlen
=
0
;
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
tlen
+=
strlen
(
taosArrayGetP
(
pArray
,
i
))
+
1
;
}
char
*
res
=
taosMemoryCalloc
(
1
,
tlen
);
char
*
buf
=
res
;
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
str
=
taosArrayGetP
(
pArray
,
i
);
int32_t
len
=
strlen
(
str
);
memcpy
(
buf
,
str
,
len
);
buf
+=
len
;
if
(
i
!=
sz
-
1
)
*
buf
=
','
;
}
return
res
;
}
source/util/src/terror.c
浏览文件 @
75cad6e3
...
@@ -271,9 +271,14 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_INVALID_STAGE, "Invalid stage to kill
...
@@ -271,9 +271,14 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_INVALID_STAGE, "Invalid stage to kill
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_CANT_PARALLEL
,
"Invalid stage to kill"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_CANT_PARALLEL
,
"Invalid stage to kill"
)
// mnode-mq
// mnode-mq
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_UNSUPPORTED_TOPIC
,
"Topic with aggregation is unsupported"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOPIC_ALREADY_EXIST
,
"Topic already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_CONSUMER_NOT_READY
,
"Consumer waiting for rebalance"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOPIC_NOT_EXIST
,
"Topic not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOO_MANY_TOPICS
,
"Too many Topics"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TOPIC
,
"Invalid topic"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TOPIC_QUERY
,
"Topic with invalid query"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_TOPIC_OPTION
,
"Topic with invalid option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_CONSUMER_NOT_EXIST
,
"Consumer not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_CONSUMER_NOT_EXIST
,
"Consumer not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_CONSUMER_NOT_READY
,
"Consumer waiting for rebalance"
)
// mnode-sma
// mnode-sma
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_SMA_ALREADY_EXIST
,
"SMA already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_SMA_ALREADY_EXIST
,
"SMA already exists"
)
...
...
tests/script/general/user/authority.sim
已删除
100644 → 0
浏览文件 @
b5246114
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect
sleep 2000
print ============= step1
sql create user read pass 'taosdata'
sql create user write pass 'taosdata'
sql show users
if $rows != 5 then
return -1
endi
print ============= step2
sql close
sql connect read
sleep 2000
sql create database dread
sql show databases
if $rows != 1 then
return -1
endi
print ============= step3
sql close
sql connect write
sleep 2000
sql create database dwrite
sql show databases
if $rows != 2 then
return -1
endi
print ============ step4
sql close
sql connect
sleep 2000
sql show databases
if $row != 2 then
return -1
endi
print ============ step5
sql close
sql connect read
sleep 2000
sql drop database dread
sql drop database dwrite
sql close
sql connect
sql show databases
if $rows != 0 then
return -1
endi
sql close
sql connect
sleep 2000
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
tests/script/general/user/user_create.sim
已删除
100644 → 0
浏览文件 @
b5246114
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
sql connect
print =============== step1
sql show users
if $rows != 3 then
return -1
endi
sql create user read PASS 'pass123'
sql create user read PASS 'pass123' -x step1
return -1
step1:
sql show users
if $rows != 4 then
return -1
endi
sql alter user read PASS 'taosdata'
print =============== step2
sql close
sql connect read
sleep 2000
sql alter user read PASS 'taosdata'
print =============== step3
sql drop user read -x step31
return -1
step31:
sql drop user _root -x step32
return -1
step32:
sql drop user monitor -x step33
return -1
step33:
print =============== step4
sql close
sql connect
sleep 2000
sql alter user read privilege read
sql show users
print $data1_read
if $data1_read != readable then
return -1
endi
sql_error alter user read privilege super
sql show users
print $data1_read
if $data1_read != readable then
return -1
endi
sql alter user read privilege write
sql show users
print $data1_read
if $data1_read != writable then
return -1
endi
sql alter user read privilege 1 -x step43
return -1
step43:
sql drop user _root -x step41
return -1
step41:
sql drop user monitor -x step42
return -1
step42:
sql drop user read
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
tests/script/jenkins/basic.txt
浏览文件 @
75cad6e3
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
# ---- user
# ---- user
./test.sh -f tsim/user/basic1.sim
./test.sh -f tsim/user/basic1.sim
./test.sh -f tsim/user/pass_alter.sim
./test.sh -f tsim/user/pass_len.sim
./test.sh -f tsim/user/user_len.sim
# ---- db
# ---- db
./test.sh -f tsim/db/create_all_options.sim
./test.sh -f tsim/db/create_all_options.sim
...
...
tests/script/
general
/user/pass_alter.sim
→
tests/script/
tsim
/user/pass_alter.sim
浏览文件 @
75cad6e3
system sh/stop_dnodes.sh
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect
sql connect
print ============= step1
print ============= step1
...
@@ -13,7 +11,7 @@ sql alter user read pass 'taosdata'
...
@@ -13,7 +11,7 @@ sql alter user read pass 'taosdata'
sql alter user write pass 'taosdata'
sql alter user write pass 'taosdata'
sql show users
sql show users
if $rows !=
5
then
if $rows !=
3
then
return -1
return -1
endi
endi
...
@@ -27,11 +25,11 @@ sql alter user write pass 'taosdata1' -x step2
...
@@ -27,11 +25,11 @@ sql alter user write pass 'taosdata1' -x step2
return -1
return -1
step2:
step2:
sql_error create user read pass 'taosdata1'
sql_error create user read
1
pass 'taosdata1'
sql_error create user write pass 'taosdata1'
sql_error create user write
1
pass 'taosdata1'
sql show users
sql show users
if $rows !=
5
then
if $rows !=
3
then
return -1
return -1
endi
endi
...
@@ -41,27 +39,27 @@ sleep 2500
...
@@ -41,27 +39,27 @@ sleep 2500
print user write login
print user write login
sql connect write
sql connect write
sql_error create user read pass 'taosdata1'
sql_error create user read
2
pass 'taosdata1'
sql_error create user write pass 'taosdata1'
sql_error create user write
2
pass 'taosdata1'
sql alter user write pass 'taosdata'
sql alter user write pass 'taosdata'
sql alter user read pass 'taosdata' -x step3
sql alter user read pass 'taosdata' -x step3
return -1
return -1
step3:
step3:
sql show users
sql show users
if $rows !=
5
then
if $rows !=
3
then
return -1
return -1
endi
endi
print ============= step4
print ============= step4
sql close
sql close
sleep 2500
sleep 2500
print
root write
login
print
user root
login
sql connect
sql connect
sql create user oroot pass 'taosdata'
sql create user oroot pass 'taosdata'
sql show users
sql show users
if $rows !=
6
then
if $rows !=
4
then
return -1
return -1
endi
endi
...
...
tests/script/
general
/user/pass_len.sim
→
tests/script/
tsim
/user/pass_len.sim
浏览文件 @
75cad6e3
system sh/stop_dnodes.sh
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode1 -s start
sql connect
sql connect
...
@@ -50,15 +48,16 @@ step3:
...
@@ -50,15 +48,16 @@ step3:
sql create user $user PASS 'abc0123456789'
sql create user $user PASS 'abc0123456789'
sql show users
sql show users
if $rows !=
3
then
if $rows !=
4
then
return -1
return -1
endi
endi
print =============== step4
print =============== step4
$i = 3
$i = 3
$user = $userPrefix . $i
$user = $userPrefix . $i
sql create user $user PASS 'abcd012345678901234567891234567890' -x step4
sql create user $user PASS 'abcd012345678901234567891234567890
abcd012345678901234567891234567890abcd012345678901234567891234567890abcd012345678901234567891234567890123
' -x step4
return -1
return -1
step4:
step4:
sql show users
sql show users
if $rows != 4 then
if $rows != 4 then
...
...
tests/script/
general
/user/user_len.sim
→
tests/script/
tsim
/user/user_len.sim
浏览文件 @
75cad6e3
system sh/stop_dnodes.sh
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect
sql connect
$i = 0
$i = 0
...
@@ -24,7 +19,7 @@ sql create user PASS '123' -x step1
...
@@ -24,7 +19,7 @@ sql create user PASS '123' -x step1
step1:
step1:
sql show users
sql show users
if $rows !=
3
then
if $rows !=
1
then
return -1
return -1
endi
endi
...
@@ -33,13 +28,13 @@ sql drop user a -x step2
...
@@ -33,13 +28,13 @@ sql drop user a -x step2
step2:
step2:
sql create user a PASS '123'
sql create user a PASS '123'
sql show users
sql show users
if $rows !=
4
then
if $rows !=
2
then
return -1
return -1
endi
endi
sql drop user a
sql drop user a
sql show users
sql show users
if $rows !=
3
then
if $rows !=
1
then
return -1
return -1
endi
endi
...
@@ -49,13 +44,13 @@ step3:
...
@@ -49,13 +44,13 @@ step3:
sql create user abc01234567890123456789 PASS '123'
sql create user abc01234567890123456789 PASS '123'
sql show users
sql show users
if $rows !=
4
then
if $rows !=
2
then
return -1
return -1
endi
endi
sql drop user abc01234567890123456789
sql drop user abc01234567890123456789
sql show users
sql show users
if $rows !=
3
then
if $rows !=
1
then
return -1
return -1
endi
endi
...
@@ -64,7 +59,7 @@ sql create user abcd0123456789012345678901234567890111 PASS '123' -x step4
...
@@ -64,7 +59,7 @@ sql create user abcd0123456789012345678901234567890111 PASS '123' -x step4
return -1
return -1
step4:
step4:
sql show users
sql show users
if $rows !=
3
then
if $rows !=
1
then
return -1
return -1
endi
endi
...
@@ -77,13 +72,13 @@ step61:
...
@@ -77,13 +72,13 @@ step61:
sql create user a123 PASS '123'
sql create user a123 PASS '123'
sql show users
sql show users
if $rows !=
4
then
if $rows !=
2
then
return -1
return -1
endi
endi
sql drop user a123
sql drop user a123
sql show users
sql show users
if $rows !=
3
then
if $rows !=
1
then
return -1
return -1
endi
endi
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录