Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0e690344
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
0e690344
编写于
12月 17, 2021
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor tq
上级
d037b24e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
295 addition
and
283 deletion
+295
-283
include/common/taosmsg.h
include/common/taosmsg.h
+1
-1
include/dnode/vnode/tq/tq.h
include/dnode/vnode/tq/tq.h
+82
-89
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+1
-1
source/dnode/vnode/impl/src/vnodeWrite.c
source/dnode/vnode/impl/src/vnodeWrite.c
+1
-5
source/dnode/vnode/tq/src/tq.c
source/dnode/vnode/tq/src/tq.c
+161
-109
source/dnode/vnode/tq/src/tqMetaStore.c
source/dnode/vnode/tq/src/tqMetaStore.c
+1
-1
source/dnode/vnode/tq/test/tqMetaTest.cpp
source/dnode/vnode/tq/test/tqMetaTest.cpp
+48
-77
未找到文件。
include/common/taosmsg.h
浏览文件 @
0e690344
...
...
@@ -50,7 +50,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" )
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_QUERY
,
"mq-query"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_CONNECT
,
"mq-connect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_DISCONNECT
,
"mq-disconnect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_SET
,
"mq-set
"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_SET
_CUR
,
"mq-set-cur
"
)
// message from client to mnode
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CONNECT
,
"connect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_ACCT
,
"create-acct"
)
...
...
include/dnode/vnode/tq/tq.h
浏览文件 @
0e690344
...
...
@@ -18,84 +18,71 @@
#include "mallocator.h"
#include "os.h"
#include "tlist.h"
#include "tutil.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
Tm
qMsgHead
{
typedef
struct
ST
qMsgHead
{
int32_t
protoVer
;
int32_t
msgType
;
int64_t
cgId
;
int64_t
clientId
;
}
Tm
qMsgHead
;
}
ST
qMsgHead
;
typedef
struct
Tm
qOneAck
{
typedef
struct
ST
qOneAck
{
int64_t
topicId
;
int64_t
consumeOffset
;
}
Tm
qOneAck
;
}
ST
qOneAck
;
typedef
struct
Tm
qAcks
{
typedef
struct
ST
qAcks
{
int32_t
ackNum
;
// should be sorted
Tm
qOneAck
acks
[];
}
Tm
qAcks
;
ST
qOneAck
acks
[];
}
ST
qAcks
;
// TODO: put msgs into common
typedef
struct
TmqConnectReq
{
TmqMsgHead
head
;
TmqAcks
acks
;
}
TmqConnectReq
;
typedef
struct
TmqConnectRsp
{
TmqMsgHead
head
;
int8_t
status
;
}
TmqConnectRsp
;
typedef
struct
TmqDisconnectReq
{
TmqMsgHead
head
;
}
TmqDiscconectReq
;
typedef
struct
TmqDisconnectRsp
{
TmqMsgHead
head
;
int8_t
status
;
}
TmqDisconnectRsp
;
typedef
struct
STqSetCurReq
{
STqMsgHead
head
;
int64_t
topicId
;
int64_t
offset
;
}
STqSetCurReq
;
typedef
struct
STqConsumeReq
{
Tm
qMsgHead
head
;
Tm
qAcks
acks
;
ST
qMsgHead
head
;
ST
qAcks
acks
;
}
STqConsumeReq
;
typedef
struct
Tm
qMsgContent
{
typedef
struct
ST
qMsgContent
{
int64_t
topicId
;
int64_t
msgLen
;
char
msg
[];
}
Tm
qMsgContent
;
}
ST
qMsgContent
;
typedef
struct
STqConsumeRsp
{
Tm
qMsgHead
head
;
ST
qMsgHead
head
;
int64_t
bodySize
;
Tm
qMsgContent
msgs
[];
ST
qMsgContent
msgs
[];
}
STqConsumeRsp
;
typedef
struct
Tm
qSubscribeReq
{
Tm
qMsgHead
head
;
typedef
struct
ST
qSubscribeReq
{
ST
qMsgHead
head
;
int32_t
topicNum
;
int64_t
topic
[];
}
Tm
qSubscribeReq
;
}
ST
qSubscribeReq
;
typedef
struct
tm
qSubscribeRsp
{
Tm
qMsgHead
head
;
typedef
struct
ST
qSubscribeRsp
{
ST
qMsgHead
head
;
int64_t
vgId
;
char
ep
[
TSDB_EP_LEN
];
// TSDB_EP_LEN
}
Tm
qSubscribeRsp
;
}
ST
qSubscribeRsp
;
typedef
struct
Tm
qHeartbeatReq
{
}
Tm
qHeartbeatReq
;
typedef
struct
ST
qHeartbeatReq
{
}
ST
qHeartbeatReq
;
typedef
struct
Tm
qHeartbeatRsp
{
}
Tm
qHeartbeatRsp
;
typedef
struct
ST
qHeartbeatRsp
{
}
ST
qHeartbeatRsp
;
typedef
struct
STqTopicVhandle
{
int64_t
topicId
;
...
...
@@ -113,39 +100,41 @@ typedef struct STqBufferItem {
// executors are identical but not concurrent
// so there must be a copy in each item
void
*
executor
;
int32_t
status
;
int64_t
size
;
void
*
content
;
}
STq
Buffer
Item
;
}
STq
Msg
Item
;
typedef
struct
STq
BufferHandle
{
typedef
struct
STq
Topic
{
// char* topic; //c style, end with '\0'
// int64_t cgId;
// void* ahandle;
int64_t
nextConsumeOffset
;
int64_t
floatingCursor
;
int64_t
topicId
;
int32_t
head
;
int32_t
tail
;
STq
Buffer
Item
buffer
[
TQ_BUFFER_SIZE
];
}
STq
BufferHandle
;
int64_t
nextConsumeOffset
;
int64_t
floatingCursor
;
int64_t
topicId
;
int32_t
head
;
int32_t
tail
;
STq
Msg
Item
buffer
[
TQ_BUFFER_SIZE
];
}
STq
Topic
;
typedef
struct
STqListHandle
{
STq
BufferHandle
bufHandle
;
STq
Topic
topic
;
struct
STqListHandle
*
next
;
}
STqList
Handle
;
}
STqList
;
typedef
struct
STqGroupHandle
{
int64_t
cId
;
int64_t
cgId
;
void
*
ahandle
;
int32_t
topicNum
;
STqListHandle
*
head
;
}
STqGroupHandle
;
typedef
struct
STqGroup
{
int64_t
cId
;
int64_t
cgId
;
void
*
ahandle
;
int32_t
topicNum
;
STqList
*
head
;
SList
*
topicList
;
// SList<STqTopic>
}
STqGroup
;
typedef
struct
STqQueryExec
{
void
*
src
;
STq
Buffer
Item
*
dest
;
void
*
executor
;
void
*
src
;
STq
Msg
Item
*
dest
;
void
*
executor
;
}
STqQueryExec
;
typedef
struct
STqQueryMsg
{
...
...
@@ -209,15 +198,15 @@ typedef void (*FTqDelete)(void*);
#define TQ_DUP_INTXN_REWRITE 0
#define TQ_DUP_INTXN_REJECT 2
static
inline
bool
T
qUpdateAppend
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_UPDATE_APPEND
;
}
static
inline
bool
t
qUpdateAppend
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_UPDATE_APPEND
;
}
static
inline
bool
T
qDupIntxnReject
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_DUP_INTXN_REJECT
;
}
static
inline
bool
t
qDupIntxnReject
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_DUP_INTXN_REJECT
;
}
static
const
int8_t
TQ_CONST_DELETE
=
TQ_ACTION_CONST
;
#define TQ_DELETE_TOKEN (void*)&TQ_CONST_DELETE
typedef
struct
TqMetaHandle
{
typedef
struct
S
TqMetaHandle
{
int64_t
key
;
int64_t
offset
;
int64_t
serializedSize
;
...
...
@@ -225,23 +214,25 @@ typedef struct TqMetaHandle {
void
*
valueInTxn
;
}
STqMetaHandle
;
typedef
struct
TqMetaList
{
STqMetaHandle
handle
;
struct
TqMetaList
*
next
;
// struct TqMetaList* inTxnPrev;
// struct TqMetaList* inTxnNext;
struct
TqMetaList
*
unpersistPrev
;
struct
TqMetaList
*
unpersistNext
;
typedef
struct
S
TqMetaList
{
STqMetaHandle
handle
;
struct
S
TqMetaList
*
next
;
// struct
S
TqMetaList* inTxnPrev;
// struct
S
TqMetaList* inTxnNext;
struct
S
TqMetaList
*
unpersistPrev
;
struct
S
TqMetaList
*
unpersistNext
;
}
STqMetaList
;
typedef
struct
TqMetaStore
{
typedef
struct
S
TqMetaStore
{
STqMetaList
*
bucket
[
TQ_BUCKET_SIZE
];
// a table head
STqMetaList
*
unpersistHead
;
// TODO:temporaral use, to be replaced by unified tfile
int
fileFd
;
// TODO:temporaral use, to be replaced by unified tfile
int
idxFd
;
int
idxFd
;
char
*
dirPath
;
int32_t
tqConfigFlag
;
FTqSerialize
pSerializer
;
...
...
@@ -250,8 +241,8 @@ typedef struct TqMetaStore {
}
STqMetaStore
;
typedef
struct
STQ
{
// the collection of group
handle
// the handle of kvstore
// the collection of group
s
// the handle of
meta
kvstore
char
*
path
;
STqCfg
*
tqConfig
;
STqLogReader
*
tqLogReader
;
...
...
@@ -266,23 +257,25 @@ void tqClose(STQ*);
// void* will be replace by a msg type
int
tqPushMsg
(
STQ
*
,
void
*
msg
,
int64_t
version
);
int
tqCommit
(
STQ
*
);
int
tqSetCursor
(
STQ
*
,
void
*
msg
);
int
tqConsume
(
STQ
*
,
STqConsumeReq
*
);
STqGroupHandle
*
tqGetGroupHandle
(
STQ
*
,
int64_t
cId
);
int
tqSetCursor
(
STQ
*
,
STqSetCurReq
*
pMsg
);
int
tqBufferSetOffset
(
STqTopic
*
,
int64_t
offset
);
STqTopic
*
tqFindTopic
(
STqGroup
*
,
int64_t
topicId
);
STqGroup
*
tqGetGroup
(
STQ
*
,
int64_t
clientId
);
STqGroup
*
tqOpenGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqCloseGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqRegisterContext
(
STqGroup
*
,
void
*
ahandle
);
int
tqSendLaunchQuery
(
STqMsgItem
*
,
int64_t
offset
);
STqGroupHandle
*
tqOpenTCGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqCloseTCGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqMoveOffsetToNext
(
STqGroupHandle
*
);
int
tqResetOffset
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
offset
);
int
tqRegisterContext
(
STqGroupHandle
*
,
void
*
ahandle
);
int
tqLaunchQuery
(
STqGroupHandle
*
);
int
tqSendLaunchQuery
(
STqGroupHandle
*
);
int
tqSerializeGroup
(
const
STqGroup
*
,
STqSerializedHead
**
);
int
tqSerializeGroupHandle
(
const
STqGroupHandle
*
gHandle
,
STqSerializedHead
**
ppHead
);
const
void
*
tqDeserializeGroup
(
const
STqSerializedHead
*
,
STqGroup
**
);
const
void
*
tqDeserializeGroupHandle
(
const
STqSerializedHead
*
pHead
,
STqGroupHandle
**
gHandle
);
static
int
tqQueryExecuting
(
int32_t
status
)
{
return
status
;
}
#ifdef __cplusplus
}
...
...
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
0e690344
...
...
@@ -44,7 +44,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_CONSUME
]
=
dndProcessVnodeQueryMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_CONNECT
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_DISCONNECT
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_SET
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_SET
_CUR
]
=
dndProcessVnodeWriteMsg
;
// msg from client to mnode
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CONNECT
]
=
dndProcessMnodeReadMsg
;
...
...
source/dnode/vnode/impl/src/vnodeWrite.c
浏览文件 @
0e690344
...
...
@@ -16,17 +16,13 @@
#include "vnodeDef.h"
int
vnodeProcessNoWalWMsgs
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
SVnodeReq
*
pVnodeReq
;
switch
(
pMsg
->
msgType
)
{
case
TSDB_MSG_TYPE_MQ_SET
:
case
TSDB_MSG_TYPE_MQ_SET
_CUR
:
if
(
tqSetCursor
(
pVnode
->
pTq
,
pMsg
->
pCont
)
<
0
)
{
// TODO: handle error
}
break
;
}
void
*
pBuf
=
pMsg
->
pCont
;
return
0
;
}
...
...
source/dnode/vnode/tq/src/tq.c
浏览文件 @
0e690344
...
...
@@ -24,21 +24,16 @@
// handle management message
//
int
tqG
etgHandleSSize
(
const
STqGroupHandle
*
gHandle
);
int
tq
BufHandle
SSize
();
int
tq
Buf
ItemSSize
();
int
tqG
roupSSize
(
const
STqGroup
*
pGroup
);
int
tq
Topic
SSize
();
int
tqItemSSize
();
STqGroupHandle
*
tqFindHandle
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
STqGroupHandle
*
gHandle
;
return
NULL
;
}
void
*
tqSerializeListHandle
(
STqListHandle
*
listHandle
,
void
*
ptr
);
void
*
tqSerializeBufHandle
(
STqBufferHandle
*
bufHandle
,
void
*
ptr
);
void
*
tqSerializeBufItem
(
STqBufferItem
*
bufItem
,
void
*
ptr
);
void
*
tqSerializeListHandle
(
STqList
*
listHandle
,
void
*
ptr
);
void
*
tqSerializeTopic
(
STqTopic
*
pTopic
,
void
*
ptr
);
void
*
tqSerializeItem
(
STqMsgItem
*
pItem
,
void
*
ptr
);
const
void
*
tqDeserialize
BufHandle
(
const
void
*
pBytes
,
STqBufferHandle
*
bufHandle
);
const
void
*
tqDeserialize
BufItem
(
const
void
*
pBytes
,
STqBufferItem
*
buf
Item
);
const
void
*
tqDeserialize
Topic
(
const
void
*
pBytes
,
STqTopic
*
pTopic
);
const
void
*
tqDeserialize
Item
(
const
void
*
pBytes
,
STqMsgItem
*
p
Item
);
STQ
*
tqOpen
(
const
char
*
path
,
STqCfg
*
tqConfig
,
STqLogReader
*
tqLogReader
,
SMemAllocatorFactory
*
allocFac
)
{
STQ
*
pTq
=
malloc
(
sizeof
(
STQ
));
...
...
@@ -54,8 +49,7 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemA
if
(
pTq
->
tqMemRef
.
pAllocator
==
NULL
)
{
// TODO
}
pTq
->
tqMeta
=
tqStoreOpen
(
path
,
(
FTqSerialize
)
tqSerializeGroupHandle
,
(
FTqDeserialize
)
tqDeserializeGroupHandle
,
free
,
0
);
pTq
->
tqMeta
=
tqStoreOpen
(
path
,
(
FTqSerialize
)
tqSerializeGroup
,
(
FTqDeserialize
)
tqDeserializeGroup
,
free
,
0
);
if
(
pTq
->
tqMeta
==
NULL
)
{
// TODO: free STQ
return
NULL
;
...
...
@@ -63,14 +57,14 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemA
return
pTq
;
}
static
int
tqProtoCheck
(
Tm
qMsgHead
*
pMsg
)
{
return
pMsg
->
protoVer
==
0
;
}
static
int
tqProtoCheck
(
ST
qMsgHead
*
pMsg
)
{
return
pMsg
->
protoVer
==
0
;
}
static
int
tqAckOneTopic
(
STq
BufferHandle
*
bHandle
,
Tm
qOneAck
*
pAck
,
STqQueryMsg
**
ppQuery
)
{
static
int
tqAckOneTopic
(
STq
Topic
*
pTopic
,
ST
qOneAck
*
pAck
,
STqQueryMsg
**
ppQuery
)
{
// clean old item and move forward
int32_t
consumeOffset
=
pAck
->
consumeOffset
;
int
idx
=
consumeOffset
%
TQ_BUFFER_SIZE
;
ASSERT
(
bHandle
->
buffer
[
idx
].
content
&&
bHandle
->
buffer
[
idx
].
executor
);
tfree
(
bHandle
->
buffer
[
idx
].
content
);
ASSERT
(
pTopic
->
buffer
[
idx
].
content
&&
pTopic
->
buffer
[
idx
].
executor
);
tfree
(
pTopic
->
buffer
[
idx
].
content
);
if
(
1
/* TODO: need to launch new query */
)
{
STqQueryMsg
*
pNewQuery
=
malloc
(
sizeof
(
STqQueryMsg
));
if
(
pNewQuery
==
NULL
)
{
...
...
@@ -78,29 +72,29 @@ static int tqAckOneTopic(STqBufferHandle* bHandle, TmqOneAck* pAck, STqQueryMsg*
return
-
1
;
}
// TODO: lock executor
pNewQuery
->
exec
->
executor
=
bHandle
->
buffer
[
idx
].
executor
;
pNewQuery
->
exec
->
executor
=
pTopic
->
buffer
[
idx
].
executor
;
// TODO: read from wal and assign to src
pNewQuery
->
exec
->
src
=
0
;
pNewQuery
->
exec
->
dest
=
&
bHandle
->
buffer
[
idx
];
pNewQuery
->
exec
->
dest
=
&
pTopic
->
buffer
[
idx
];
pNewQuery
->
next
=
*
ppQuery
;
*
ppQuery
=
pNewQuery
;
}
return
0
;
}
static
int
tqAck
(
STqGroup
Handle
*
gHandle
,
Tm
qAcks
*
pAcks
)
{
static
int
tqAck
(
STqGroup
*
pGroup
,
ST
qAcks
*
pAcks
)
{
int32_t
ackNum
=
pAcks
->
ackNum
;
Tm
qOneAck
*
acks
=
pAcks
->
acks
;
ST
qOneAck
*
acks
=
pAcks
->
acks
;
// double ptr for acks and list
int
i
=
0
;
STqList
Handle
*
node
=
gHandle
->
head
;
int
ackCnt
=
0
;
STqQueryMsg
*
pQuery
=
NULL
;
int
i
=
0
;
STqList
*
node
=
pGroup
->
head
;
int
ackCnt
=
0
;
STqQueryMsg
*
pQuery
=
NULL
;
while
(
i
<
ackNum
&&
node
->
next
)
{
if
(
acks
[
i
].
topicId
==
node
->
next
->
bufHandle
.
topicId
)
{
if
(
acks
[
i
].
topicId
==
node
->
next
->
topic
.
topicId
)
{
ackCnt
++
;
tqAckOneTopic
(
&
node
->
next
->
bufHandle
,
&
acks
[
i
],
&
pQuery
);
}
else
if
(
acks
[
i
].
topicId
<
node
->
next
->
bufHandle
.
topicId
)
{
tqAckOneTopic
(
&
node
->
next
->
topic
,
&
acks
[
i
],
&
pQuery
);
}
else
if
(
acks
[
i
].
topicId
<
node
->
next
->
topic
.
topicId
)
{
i
++
;
}
else
{
node
=
node
->
next
;
...
...
@@ -112,28 +106,29 @@ static int tqAck(STqGroupHandle* gHandle, TmqAcks* pAcks) {
return
ackCnt
;
}
static
int
tqCommit
TCGroup
(
STqGroupHandle
*
handle
)
{
static
int
tqCommit
Group
(
STqGroup
*
pGroup
)
{
// persist modification into disk
return
0
;
}
int
tqCreate
TCGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
,
STqGroupHandle
**
handle
)
{
int
tqCreate
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
,
STqGroup
**
ppGroup
)
{
// create in disk
STqGroup
Handle
*
gHandle
=
(
STqGroupHandle
*
)
malloc
(
sizeof
(
STqGroupHandle
));
if
(
gHandle
==
NULL
)
{
STqGroup
*
pGroup
=
(
STqGroup
*
)
malloc
(
sizeof
(
STqGroup
));
if
(
pGroup
==
NULL
)
{
// TODO
return
-
1
;
}
memset
(
gHandle
,
0
,
sizeof
(
STqGroupHandle
));
*
ppGroup
=
pGroup
;
memset
(
pGroup
,
0
,
sizeof
(
STqGroup
));
return
0
;
}
STqGroup
Handle
*
tqOpenTC
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
STqGroup
Handle
*
gHandle
=
tqHandleGet
(
pTq
->
tqMeta
,
cId
);
if
(
gHandle
==
NULL
)
{
int
code
=
tqCreate
TCGroup
(
pTq
,
topicId
,
cgId
,
cId
,
&
gHandle
);
if
(
code
!=
0
)
{
STqGroup
*
tqOpen
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
STqGroup
*
pGroup
=
tqHandleGet
(
pTq
->
tqMeta
,
cId
);
if
(
pGroup
==
NULL
)
{
int
code
=
tqCreate
Group
(
pTq
,
topicId
,
cgId
,
cId
,
&
pGroup
);
if
(
code
<
0
)
{
// TODO
return
NULL
;
}
...
...
@@ -141,23 +136,26 @@ STqGroupHandle* tqOpenTCGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t c
// create
// open
return
gHandle
;
return
pGroup
;
}
int
tqCloseTCGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
return
0
;
}
int
tqCloseGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
// TODO
return
0
;
}
int
tqDrop
TC
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
int
tqDropGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
// delete from disk
return
0
;
}
static
int
tqFetch
(
STqGroup
Handle
*
gHandle
,
void
**
msg
)
{
STqList
Handle
*
head
=
gHandle
->
head
;
STqList
Handle
*
node
=
head
;
int
totSize
=
0
;
static
int
tqFetch
(
STqGroup
*
pGroup
,
void
**
msg
)
{
STqList
*
head
=
pGroup
->
head
;
STqList
*
node
=
head
;
int
totSize
=
0
;
// TODO: make it a macro
int
sizeLimit
=
4
*
1024
;
Tm
qMsgContent
*
buffer
=
malloc
(
sizeLimit
);
ST
qMsgContent
*
buffer
=
malloc
(
sizeLimit
);
if
(
buffer
==
NULL
)
{
// TODO:memory insufficient
return
-
1
;
...
...
@@ -166,25 +164,25 @@ static int tqFetch(STqGroupHandle* gHandle, void** msg) {
// until all topic iterated or msgs over sizeLimit
while
(
node
->
next
)
{
node
=
node
->
next
;
STq
BufferHandle
*
bufHandle
=
&
node
->
bufHandle
;
int
idx
=
buf
Handle
->
nextConsumeOffset
%
TQ_BUFFER_SIZE
;
if
(
bufHandle
->
buffer
[
idx
].
content
!=
NULL
&&
bufHandle
->
buffer
[
idx
].
offset
==
buf
Handle
->
nextConsumeOffset
)
{
totSize
+=
buf
Handle
->
buffer
[
idx
].
size
;
STq
Topic
*
topicHandle
=
&
node
->
topic
;
int
idx
=
topic
Handle
->
nextConsumeOffset
%
TQ_BUFFER_SIZE
;
if
(
topicHandle
->
buffer
[
idx
].
content
!=
NULL
&&
topicHandle
->
buffer
[
idx
].
offset
==
topic
Handle
->
nextConsumeOffset
)
{
totSize
+=
topic
Handle
->
buffer
[
idx
].
size
;
if
(
totSize
>
sizeLimit
)
{
void
*
ptr
=
realloc
(
buffer
,
totSize
);
if
(
ptr
==
NULL
)
{
totSize
-=
buf
Handle
->
buffer
[
idx
].
size
;
totSize
-=
topic
Handle
->
buffer
[
idx
].
size
;
// TODO:memory insufficient
// return msgs already copied
break
;
}
}
*
((
int64_t
*
)
buffer
)
=
buf
Handle
->
topicId
;
*
((
int64_t
*
)
buffer
)
=
topic
Handle
->
topicId
;
buffer
=
POINTER_SHIFT
(
buffer
,
sizeof
(
int64_t
));
*
((
int64_t
*
)
buffer
)
=
buf
Handle
->
buffer
[
idx
].
size
;
*
((
int64_t
*
)
buffer
)
=
topic
Handle
->
buffer
[
idx
].
size
;
buffer
=
POINTER_SHIFT
(
buffer
,
sizeof
(
int64_t
));
memcpy
(
buffer
,
bufHandle
->
buffer
[
idx
].
content
,
buf
Handle
->
buffer
[
idx
].
size
);
buffer
=
POINTER_SHIFT
(
buffer
,
buf
Handle
->
buffer
[
idx
].
size
);
memcpy
(
buffer
,
topicHandle
->
buffer
[
idx
].
content
,
topic
Handle
->
buffer
[
idx
].
size
);
buffer
=
POINTER_SHIFT
(
buffer
,
topic
Handle
->
buffer
[
idx
].
size
);
if
(
totSize
>
sizeLimit
)
{
break
;
}
...
...
@@ -193,11 +191,19 @@ static int tqFetch(STqGroupHandle* gHandle, void** msg) {
return
totSize
;
}
STqGroup
Handle
*
tqGetGroupHandle
(
STQ
*
pTq
,
int64_t
cId
)
{
return
NULL
;
}
STqGroup
*
tqGetGroup
(
STQ
*
pTq
,
int64_t
clientId
)
{
return
tqHandleGet
(
pTq
->
tqMeta
,
clientId
)
;
}
int
tqLaunchQuery
(
STqGroupHandle
*
gHandle
)
{
return
0
;
}
int
tqSendLaunchQuery
(
STqGroupHandle
*
gHandle
)
{
return
0
;
}
int
tqSendLaunchQuery
(
STqMsgItem
*
bufItem
,
int64_t
offset
)
{
if
(
tqQueryExecuting
(
bufItem
->
status
))
{
return
0
;
}
bufItem
->
status
=
1
;
// load data from wal or buffer pool
// put into exec
// send exec into non blocking queue
// when query finished, put into buffer pool
return
0
;
}
/*int tqMoveOffsetToNext(TqGroupHandle* gHandle) {*/
/*return 0;*/
...
...
@@ -214,23 +220,69 @@ int tqCommit(STQ* pTq) {
return
0
;
}
int
tqSetCursor
(
STQ
*
pTq
,
void
*
msg
)
{
int
tqBufferSetOffset
(
STqTopic
*
pTopic
,
int64_t
offset
)
{
int
code
;
memset
(
pTopic
->
buffer
,
0
,
sizeof
(
pTopic
->
buffer
));
// launch query
for
(
int
i
=
offset
;
i
<
offset
+
TQ_BUFFER_SIZE
;
i
++
)
{
int
pos
=
i
%
TQ_BUFFER_SIZE
;
code
=
tqSendLaunchQuery
(
&
pTopic
->
buffer
[
pos
],
offset
);
if
(
code
<
0
)
{
// TODO: error handling
}
}
// set offset
pTopic
->
nextConsumeOffset
=
offset
;
pTopic
->
floatingCursor
=
offset
;
return
0
;
}
STqTopic
*
tqFindTopic
(
STqGroup
*
pGroup
,
int64_t
topicId
)
{
// TODO
return
NULL
;
}
int
tqSetCursor
(
STQ
*
pTq
,
STqSetCurReq
*
pMsg
)
{
int
code
;
int64_t
clientId
=
pMsg
->
head
.
clientId
;
int64_t
topicId
=
pMsg
->
topicId
;
int64_t
offset
=
pMsg
->
offset
;
STqGroup
*
gHandle
=
tqGetGroup
(
pTq
,
clientId
);
if
(
gHandle
==
NULL
)
{
// client not connect
return
-
1
;
}
STqTopic
*
topicHandle
=
tqFindTopic
(
gHandle
,
topicId
);
if
(
topicHandle
==
NULL
)
{
return
-
1
;
}
if
(
pMsg
->
offset
==
topicHandle
->
nextConsumeOffset
)
{
return
0
;
}
// TODO: check log last version
code
=
tqBufferSetOffset
(
topicHandle
,
offset
);
if
(
code
<
0
)
{
// set error code
return
-
1
;
}
return
0
;
}
int
tqConsume
(
STQ
*
pTq
,
STqConsumeReq
*
pMsg
)
{
if
(
!
tqProtoCheck
((
Tm
qMsgHead
*
)
pMsg
))
{
if
(
!
tqProtoCheck
((
ST
qMsgHead
*
)
pMsg
))
{
// proto version invalid
return
-
1
;
}
int64_t
clientId
=
pMsg
->
head
.
clientId
;
STqGroup
Handle
*
gHandle
=
tqGetGroupHandle
(
pTq
,
clientId
);
if
(
gHandle
==
NULL
)
{
int64_t
clientId
=
pMsg
->
head
.
clientId
;
STqGroup
*
pGroup
=
tqGetGroup
(
pTq
,
clientId
);
if
(
pGroup
==
NULL
)
{
// client not connect
return
-
1
;
}
if
(
pMsg
->
acks
.
ackNum
!=
0
)
{
if
(
tqAck
(
gHandle
,
&
pMsg
->
acks
)
!=
0
)
{
if
(
tqAck
(
pGroup
,
&
pMsg
->
acks
)
!=
0
)
{
// ack not success
return
-
1
;
}
...
...
@@ -238,22 +290,22 @@ int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
STqConsumeRsp
*
pRsp
=
(
STqConsumeRsp
*
)
pMsg
;
if
(
tqFetch
(
gHandle
,
(
void
**
)
&
pRsp
->
msgs
)
<=
0
)
{
if
(
tqFetch
(
pGroup
,
(
void
**
)
&
pRsp
->
msgs
)
<=
0
)
{
// fetch error
return
-
1
;
}
// judge and launch new query
if
(
tqLaunchQuery
(
gHandle
))
{
// launch query error
return
-
1
;
}
/*if (tqSendLaunchQuery(gHandle)) {*/
// launch query error
/*return -1;*/
/*}*/
return
0
;
}
int
tqSerializeGroup
Handle
(
const
STqGroupHandle
*
gHandle
,
STqSerializedHead
**
ppHead
)
{
int
tqSerializeGroup
(
const
STqGroup
*
pGroup
,
STqSerializedHead
**
ppHead
)
{
// calculate size
int
sz
=
tqG
etgHandleSSize
(
gHandle
)
+
sizeof
(
STqSerializedHead
);
int
sz
=
tqG
roupSSize
(
pGroup
)
+
sizeof
(
STqSerializedHead
);
if
(
sz
>
(
*
ppHead
)
->
ssize
)
{
void
*
tmpPtr
=
realloc
(
*
ppHead
,
sz
);
if
(
tmpPtr
==
NULL
)
{
...
...
@@ -266,52 +318,52 @@ int tqSerializeGroupHandle(const STqGroupHandle* gHandle, STqSerializedHead** pp
}
void
*
ptr
=
(
*
ppHead
)
->
content
;
// do serialization
*
(
int64_t
*
)
ptr
=
gHandle
->
cId
;
*
(
int64_t
*
)
ptr
=
pGroup
->
cId
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int64_t
*
)
ptr
=
gHandle
->
cgId
;
*
(
int64_t
*
)
ptr
=
pGroup
->
cgId
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int32_t
*
)
ptr
=
gHandle
->
topicNum
;
*
(
int32_t
*
)
ptr
=
pGroup
->
topicNum
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
if
(
gHandle
->
topicNum
>
0
)
{
tqSerializeListHandle
(
gHandle
->
head
,
ptr
);
if
(
pGroup
->
topicNum
>
0
)
{
tqSerializeListHandle
(
pGroup
->
head
,
ptr
);
}
return
0
;
}
void
*
tqSerializeListHandle
(
STqList
Handle
*
listHandle
,
void
*
ptr
)
{
STqList
Handle
*
node
=
listHandle
;
void
*
tqSerializeListHandle
(
STqList
*
listHandle
,
void
*
ptr
)
{
STqList
*
node
=
listHandle
;
ASSERT
(
node
!=
NULL
);
while
(
node
)
{
ptr
=
tqSerialize
BufHandle
(
&
node
->
bufHandle
,
ptr
);
ptr
=
tqSerialize
Topic
(
&
node
->
topic
,
ptr
);
node
=
node
->
next
;
}
return
ptr
;
}
void
*
tqSerialize
BufHandle
(
STqBufferHandle
*
bufHandle
,
void
*
ptr
)
{
*
(
int64_t
*
)
ptr
=
bufHandle
->
nextConsumeOffset
;
void
*
tqSerialize
Topic
(
STqTopic
*
pTopic
,
void
*
ptr
)
{
*
(
int64_t
*
)
ptr
=
pTopic
->
nextConsumeOffset
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int64_t
*
)
ptr
=
bufHandle
->
topicId
;
*
(
int64_t
*
)
ptr
=
pTopic
->
topicId
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int32_t
*
)
ptr
=
bufHandle
->
head
;
*
(
int32_t
*
)
ptr
=
pTopic
->
head
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
*
(
int32_t
*
)
ptr
=
bufHandle
->
tail
;
*
(
int32_t
*
)
ptr
=
pTopic
->
tail
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
for
(
int
i
=
0
;
i
<
TQ_BUFFER_SIZE
;
i
++
)
{
ptr
=
tqSerialize
BufItem
(
&
bufHandle
->
buffer
[
i
],
ptr
);
ptr
=
tqSerialize
Item
(
&
pTopic
->
buffer
[
i
],
ptr
);
}
return
ptr
;
}
void
*
tqSerialize
BufItem
(
STqBuffer
Item
*
bufItem
,
void
*
ptr
)
{
void
*
tqSerialize
Item
(
STqMsg
Item
*
bufItem
,
void
*
ptr
)
{
// TODO: do we need serialize this?
// mainly for executor
return
ptr
;
}
const
void
*
tqDeserializeGroup
Handle
(
const
STqSerializedHead
*
pHead
,
STqGroupHandle
**
ppGHandle
)
{
STqGroup
Handle
*
gHandle
=
*
ppGHandle
;
const
void
*
ptr
=
pHead
->
content
;
const
void
*
tqDeserializeGroup
(
const
STqSerializedHead
*
pHead
,
STqGroup
**
ppGroup
)
{
STqGroup
*
gHandle
=
*
ppGroup
;
const
void
*
ptr
=
pHead
->
content
;
gHandle
->
cId
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
gHandle
->
cgId
=
*
(
int64_t
*
)
ptr
;
...
...
@@ -320,63 +372,63 @@ const void* tqDeserializeGroupHandle(const STqSerializedHead* pHead, STqGroupHan
gHandle
->
topicNum
=
*
(
int32_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
gHandle
->
head
=
NULL
;
STqList
Handle
*
node
=
gHandle
->
head
;
STqList
*
node
=
gHandle
->
head
;
for
(
int
i
=
0
;
i
<
gHandle
->
topicNum
;
i
++
)
{
if
(
gHandle
->
head
==
NULL
)
{
if
((
node
=
malloc
(
sizeof
(
STqList
Handle
)))
==
NULL
)
{
if
((
node
=
malloc
(
sizeof
(
STqList
)))
==
NULL
)
{
// TODO: error
return
NULL
;
}
node
->
next
=
NULL
;
ptr
=
tqDeserialize
BufHandle
(
ptr
,
&
node
->
bufHandle
);
ptr
=
tqDeserialize
Topic
(
ptr
,
&
node
->
topic
);
gHandle
->
head
=
node
;
}
else
{
node
->
next
=
malloc
(
sizeof
(
STqList
Handle
));
node
->
next
=
malloc
(
sizeof
(
STqList
));
if
(
node
->
next
==
NULL
)
{
// TODO: error
return
NULL
;
}
node
->
next
->
next
=
NULL
;
ptr
=
tqDeserialize
BufHandle
(
ptr
,
&
node
->
next
->
bufHandle
);
ptr
=
tqDeserialize
Topic
(
ptr
,
&
node
->
next
->
topic
);
node
=
node
->
next
;
}
}
return
ptr
;
}
const
void
*
tqDeserialize
BufHandle
(
const
void
*
pBytes
,
STqBufferHandle
*
bufHandle
)
{
const
void
*
tqDeserialize
Topic
(
const
void
*
pBytes
,
STqTopic
*
topic
)
{
const
void
*
ptr
=
pBytes
;
bufHandle
->
nextConsumeOffset
=
*
(
int64_t
*
)
ptr
;
topic
->
nextConsumeOffset
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
bufHandle
->
topicId
=
*
(
int64_t
*
)
ptr
;
topic
->
topicId
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
bufHandle
->
head
=
*
(
int32_t
*
)
ptr
;
topic
->
head
=
*
(
int32_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
bufHandle
->
tail
=
*
(
int32_t
*
)
ptr
;
topic
->
tail
=
*
(
int32_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
for
(
int
i
=
0
;
i
<
TQ_BUFFER_SIZE
;
i
++
)
{
ptr
=
tqDeserialize
BufItem
(
ptr
,
&
bufHandle
->
buffer
[
i
]);
ptr
=
tqDeserialize
Item
(
ptr
,
&
topic
->
buffer
[
i
]);
}
return
ptr
;
}
const
void
*
tqDeserialize
BufItem
(
const
void
*
pBytes
,
STqBuffer
Item
*
bufItem
)
{
return
pBytes
;
}
const
void
*
tqDeserialize
Item
(
const
void
*
pBytes
,
STqMsg
Item
*
bufItem
)
{
return
pBytes
;
}
// TODO: make this a macro
int
tqG
etgHandleSSize
(
const
STqGroupHandle
*
gHandle
)
{
int
tqG
roupSSize
(
const
STqGroup
*
gHandle
)
{
return
sizeof
(
int64_t
)
*
2
// cId + cgId
+
sizeof
(
int32_t
)
// topicNum
+
gHandle
->
topicNum
*
tq
BufHandle
SSize
();
+
gHandle
->
topicNum
*
tq
Topic
SSize
();
}
// TODO: make this a macro
int
tq
BufHandle
SSize
()
{
int
tq
Topic
SSize
()
{
return
sizeof
(
int64_t
)
*
2
// nextConsumeOffset + topicId
+
sizeof
(
int32_t
)
*
2
// head + tail
+
TQ_BUFFER_SIZE
*
tq
Buf
ItemSSize
();
+
TQ_BUFFER_SIZE
*
tqItemSSize
();
}
int
tq
Buf
ItemSSize
()
{
int
tqItemSSize
()
{
// TODO: do this need serialization?
// mainly for executor
return
0
;
...
...
source/dnode/vnode/tq/src/tqMetaStore.c
浏览文件 @
0e690344
...
...
@@ -472,7 +472,7 @@ static inline int32_t tqHandlePutImpl(STqMetaStore* pMeta, int64_t key, void* va
if
(
pNode
->
handle
.
key
==
key
)
{
// TODO: think about thread safety
if
(
pNode
->
handle
.
valueInTxn
)
{
if
(
T
qDupIntxnReject
(
pMeta
->
tqConfigFlag
))
{
if
(
t
qDupIntxnReject
(
pMeta
->
tqConfigFlag
))
{
return
-
2
;
}
if
(
pNode
->
handle
.
valueInTxn
!=
TQ_DELETE_TOKEN
)
{
...
...
source/dnode/vnode/tq/test/tqMetaTest.cpp
浏览文件 @
0e690344
...
...
@@ -10,8 +10,8 @@ struct Foo {
};
int
FooSerializer
(
const
void
*
pObj
,
STqSerializedHead
**
ppHead
)
{
Foo
*
foo
=
(
Foo
*
)
pObj
;
if
((
*
ppHead
)
==
NULL
||
(
*
ppHead
)
->
ssize
<
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
))
{
Foo
*
foo
=
(
Foo
*
)
pObj
;
if
((
*
ppHead
)
==
NULL
||
(
*
ppHead
)
->
ssize
<
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
))
{
*
ppHead
=
(
STqSerializedHead
*
)
realloc
(
*
ppHead
,
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
));
(
*
ppHead
)
->
ssize
=
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
);
}
...
...
@@ -20,36 +20,28 @@ int FooSerializer(const void* pObj, STqSerializedHead** ppHead) {
}
const
void
*
FooDeserializer
(
const
STqSerializedHead
*
pHead
,
void
**
ppObj
)
{
if
(
*
ppObj
==
NULL
)
{
if
(
*
ppObj
==
NULL
)
{
*
ppObj
=
realloc
(
*
ppObj
,
sizeof
(
int32_t
));
}
Foo
*
pFoo
=
*
(
Foo
**
)
ppObj
;
pFoo
->
a
=
*
(
int32_t
*
)
pHead
->
content
;
pFoo
->
a
=
*
(
int32_t
*
)
pHead
->
content
;
return
NULL
;
}
void
FooDeleter
(
void
*
pObj
)
{
free
(
pObj
);
}
void
FooDeleter
(
void
*
pObj
)
{
free
(
pObj
);
}
class
TqMetaUpdateAppendTest
:
public
::
testing
::
Test
{
protected:
void
SetUp
()
override
{
taosRemoveDir
(
pathName
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
}
void
TearDown
()
override
{
tqStoreClose
(
pMeta
);
}
TqMetaStore
*
pMeta
;
const
char
*
pathName
=
"/tmp/tq_test"
;
protected:
void
SetUp
()
override
{
taosRemoveDir
(
pathName
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
}
void
TearDown
()
override
{
tqStoreClose
(
pMeta
);
}
STqMetaStore
*
pMeta
;
const
char
*
pathName
=
"/tmp/tq_test"
;
};
TEST_F
(
TqMetaUpdateAppendTest
,
copyPutTest
)
{
...
...
@@ -57,11 +49,11 @@ TEST_F(TqMetaUpdateAppendTest, copyPutTest) {
foo
.
a
=
3
;
tqHandleCopyPut
(
pMeta
,
1
,
&
foo
,
sizeof
(
Foo
));
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqHandleCommit
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
->
a
,
3
);
}
...
...
@@ -78,10 +70,7 @@ TEST_F(TqMetaUpdateAppendTest, persistTest) {
EXPECT_EQ
(
pBar
==
NULL
,
true
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pBar
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
...
...
@@ -97,7 +86,7 @@ TEST_F(TqMetaUpdateAppendTest, uncommittedTest) {
pFoo
->
a
=
3
;
tqHandleMovePut
(
pMeta
,
1
,
pFoo
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
}
...
...
@@ -106,11 +95,11 @@ TEST_F(TqMetaUpdateAppendTest, abortTest) {
pFoo
->
a
=
3
;
tqHandleMovePut
(
pMeta
,
1
,
pFoo
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqHandleAbort
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
}
...
...
@@ -119,32 +108,29 @@ TEST_F(TqMetaUpdateAppendTest, deleteTest) {
pFoo
->
a
=
3
;
tqHandleMovePut
(
pMeta
,
1
,
pFoo
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqHandleCommit
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
);
EXPECT_EQ
(
pFoo
->
a
,
3
);
tqHandleDel
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
);
EXPECT_EQ
(
pFoo
->
a
,
3
);
tqHandleCommit
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
}
...
...
@@ -162,10 +148,7 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
EXPECT_EQ
(
pFoo1
->
a
,
3
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pFoo1
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
...
...
@@ -177,10 +160,7 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
EXPECT_EQ
(
pFoo1
->
a
,
4
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pFoo1
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
...
...
@@ -190,13 +170,13 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
TEST_F
(
TqMetaUpdateAppendTest
,
multiplePage
)
{
srand
(
0
);
std
::
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
v
.
push_back
(
rand
());
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
...
...
@@ -204,38 +184,34 @@ TEST_F(TqMetaUpdateAppendTest, multiplePage) {
}
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
}
TEST_F
(
TqMetaUpdateAppendTest
,
multipleRewrite
)
{
srand
(
0
);
std
::
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
v
.
push_back
(
rand
());
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
v
[
i
]
=
rand
();
Foo
foo
;
...
...
@@ -243,25 +219,22 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
v
[
i
]
=
rand
();
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
}
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
v
[
i
]
=
rand
();
Foo
foo
;
foo
.
a
=
v
[
i
];
...
...
@@ -269,40 +242,38 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
tqHandleCommit
(
pMeta
,
i
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
}
TEST_F
(
TqMetaUpdateAppendTest
,
dupCommit
)
{
srand
(
0
);
std
::
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
v
.
push_back
(
rand
());
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
int
ret
=
tqHandleCommit
(
pMeta
,
i
);
EXPECT_EQ
(
ret
,
0
);
ret
=
tqHandleCommit
(
pMeta
,
i
);
EXPECT_EQ
(
ret
,
-
1
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
int
ret
=
tqHandleCommit
(
pMeta
,
i
);
EXPECT_EQ
(
ret
,
-
1
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录