Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5a5b4bf5
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5a5b4bf5
编写于
3月 24, 2022
作者:
A
Alex Duan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TS-238]<feature>(tsdb): the flow of delete was passed
上级
eeba8d02
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
175 addition
and
76 deletion
+175
-76
src/dnode/src/dnodeVWrite.c
src/dnode/src/dnodeVWrite.c
+6
-4
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-1
src/inc/tsdb.h
src/inc/tsdb.h
+1
-1
src/inc/vnode.h
src/inc/vnode.h
+1
-1
src/tsdb/inc/tsdbCommit.h
src/tsdb/inc/tsdbCommit.h
+4
-1
src/tsdb/inc/tsdbCommitQueue.h
src/tsdb/inc/tsdbCommitQueue.h
+2
-2
src/tsdb/inc/tsdbMemTable.h
src/tsdb/inc/tsdbMemTable.h
+4
-2
src/tsdb/inc/tsdbTruncate.h
src/tsdb/inc/tsdbTruncate.h
+9
-0
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+51
-8
src/tsdb/src/tsdbCommitQueue.c
src/tsdb/src/tsdbCommitQueue.c
+7
-5
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+2
-2
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+62
-31
src/tsdb/src/tsdbTruncate.c
src/tsdb/src/tsdbTruncate.c
+13
-8
src/tsdb/tests/tsdbTests.cpp
src/tsdb/tests/tsdbTests.cpp
+1
-1
src/vnode/src/vnodeMain.c
src/vnode/src/vnodeMain.c
+8
-8
src/vnode/src/vnodeWrite.c
src/vnode/src/vnodeWrite.c
+3
-1
未找到文件。
src/dnode/src/dnodeVWrite.c
浏览文件 @
5a5b4bf5
...
...
@@ -164,12 +164,14 @@ void dnodeFreeVWriteQueue(void *pWqueue) {
void
*
waitingResultThread
(
void
*
param
)
{
SVWriteMsg
*
pWrite
=
(
SVWriteMsg
*
)
param
;
int32_t
ret
=
sem_wait
(
pWrite
->
rspRet
.
psem
_rsp
);
int32_t
ret
=
sem_wait
(
pWrite
->
rspRet
.
psem
);
if
(
ret
==
0
)
{
// success
}
sem_destroy
(
pWrite
->
rspRet
.
psem_rsp
);
sem_destroy
(
pWrite
->
rspRet
.
psem
);
tfree
(
pWrite
->
rspRet
.
psem
);
// wait ok
SRpcMsg
rpcRsp
=
{
.
handle
=
pWrite
->
rpcMsg
.
handle
,
...
...
@@ -194,7 +196,7 @@ void dnodeSendRpcVWriteRsp(void *pVnode, void *wparam, int32_t code) {
if
(
count
<=
1
)
return
;
if
(
pWrite
->
rspRet
.
psem
_rsp
==
0
)
{
if
(
pWrite
->
rspRet
.
psem
==
0
)
{
SRpcMsg
rpcRsp
=
{
.
handle
=
pWrite
->
rpcMsg
.
handle
,
.
pCont
=
pWrite
->
rspRet
.
rsp
,
...
...
@@ -208,7 +210,7 @@ void dnodeSendRpcVWriteRsp(void *pVnode, void *wparam, int32_t code) {
// need async to wait result in another thread
pthread_t
*
thread
=
taosCreateThread
(
waitingResultThread
,
pWrite
);
// add to wait thread manager
vnodeAddWait
(
pVnode
,
thread
,
pWrite
->
rspRet
.
psem
_rsp
,
pWrite
);
vnodeAddWait
(
pVnode
,
thread
,
pWrite
->
rspRet
.
psem
,
pWrite
);
}
}
...
...
src/inc/taosmsg.h
浏览文件 @
5a5b4bf5
...
...
@@ -1005,7 +1005,7 @@ typedef struct {
#define CMD_DELETE_DATA 0x00000001
typedef
struct
SControlData
{
uint32_t
command
;
// see define CMD_???
uint32_t
command
;
// see define CMD_???
STimeWindow
win
;
}
SControlData
;
...
...
src/inc/tsdb.h
浏览文件 @
5a5b4bf5
...
...
@@ -160,7 +160,7 @@ typedef struct {
*
* @return the number of points inserted, -1 for failure and the error number is set
*/
int32_t
tsdbInsertData
(
STsdbRepo
*
repo
,
SSubmitMsg
*
pMsg
,
SShellSubmitRspMsg
*
pRsp
,
sem_t
*
pSem
);
int32_t
tsdbInsertData
(
STsdbRepo
*
repo
,
SSubmitMsg
*
pMsg
,
SShellSubmitRspMsg
*
pRsp
,
tsem_t
**
p
pSem
);
// -- FOR QUERY TIME SERIES DATA
...
...
src/inc/vnode.h
浏览文件 @
5a5b4bf5
...
...
@@ -32,7 +32,7 @@ typedef struct {
int32_t
len
;
void
*
rsp
;
void
*
qhandle
;
// used by query and retrieve msg
sem_t
*
psem_rsp
;
// if it is not zero, need wait result with async
tsem_t
*
psem
;
// if it is not zero, need wait result with async
}
SRspRet
;
typedef
struct
{
...
...
src/tsdb/inc/tsdbCommit.h
浏览文件 @
5a5b4bf5
...
...
@@ -34,7 +34,7 @@ typedef struct {
void
tsdbGetRtnSnap
(
STsdbRepo
*
pRepo
,
SRtn
*
pRtn
);
int
tsdbEncodeKVRecord
(
void
**
buf
,
SKVRecord
*
pRecord
);
void
*
tsdbDecodeKVRecord
(
void
*
buf
,
SKVRecord
*
pRecord
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
,
bool
end
);
int
tsdbApplyRtnOnFSet
(
STsdbRepo
*
pRepo
,
SDFileSet
*
pSet
,
SRtn
*
pRtn
);
int
tsdbWriteBlockInfoImpl
(
SDFile
*
pHeadf
,
STable
*
pTable
,
SArray
*
pSupA
,
SArray
*
pSubA
,
void
**
ppBuf
,
SBlockIdx
*
pIdx
);
int
tsdbWriteBlockIdx
(
SDFile
*
pHeadf
,
SArray
*
pIdxA
,
void
**
ppBuf
);
...
...
@@ -42,6 +42,9 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDFil
SBlock
*
pBlock
,
bool
isLast
,
bool
isSuper
,
void
**
ppBuf
,
void
**
ppCBuf
,
void
**
ppExBuf
);
int
tsdbApplyRtn
(
STsdbRepo
*
pRepo
);
// commit control command
int
tsdbCommitControl
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
);
static
FORCE_INLINE
int
tsdbGetFidLevel
(
int
fid
,
SRtn
*
pRtn
)
{
if
(
fid
>=
pRtn
->
maxFid
)
{
return
0
;
...
...
src/tsdb/inc/tsdbCommitQueue.h
浏览文件 @
5a5b4bf5
...
...
@@ -18,9 +18,9 @@
typedef
enum
{
COMMIT_REQ
,
COMMIT_BOTH_REQ
,
COMPACT_REQ
,
TRUNCATE_TBL_REQ
,
DELETE_TBL_REQ
,
CONTROL_REQ
,
COMMIT_CONFIG_REQ
,
}
TSDB_REQ_T
;
...
...
src/tsdb/inc/tsdbMemTable.h
浏览文件 @
5a5b4bf5
...
...
@@ -16,6 +16,7 @@
#ifndef _TD_TSDB_MEMTABLE_H_
#define _TD_TSDB_MEMTABLE_H_
#include "tsdbTruncate.h"
typedef
struct
{
int
rowsInserted
;
int
rowsUpdated
;
...
...
@@ -65,11 +66,12 @@ int tsdbUnRefMemTable(STsdbRepo* pRepo, SMemTable* pMemTable);
int
tsdbTakeMemSnapshot
(
STsdbRepo
*
pRepo
,
SMemSnapshot
*
pSnapshot
,
SArray
*
pATable
);
void
tsdbUnTakeMemSnapShot
(
STsdbRepo
*
pRepo
,
SMemSnapshot
*
pSnapshot
);
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
);
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
);
// if pCtrlData is NULL, force must be true
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
);
int
tsdbSyncCommitConfig
(
STsdbRepo
*
pRepo
);
int
tsdbLoadDataFromCache
(
STable
*
pTable
,
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
SDataCols
*
pCols
,
TKEY
*
filterKeys
,
int
nFilterKeys
,
bool
keepDup
,
SMergeInfo
*
pMergeInfo
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
,
bool
end
);
static
FORCE_INLINE
SMemRow
tsdbNextIterRow
(
SSkipListIterator
*
pIter
)
{
if
(
pIter
==
NULL
)
return
NULL
;
...
...
src/tsdb/inc/tsdbTruncate.h
浏览文件 @
5a5b4bf5
...
...
@@ -18,6 +18,15 @@
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
{
SControlData
ctlData
;
// addition info
uint64_t
uid
;
// table unique id
int32_t
tid
;
// table id
tsem_t
*
pSem
;
bool
memNull
;
// pRepo->mem is NULL, this is true
SShellSubmitRspMsg
*
pRsp
;
}
SControlDataInfo
;
void
*
tsdbTruncateImpl
(
STsdbRepo
*
pRepo
,
void
*
param
);
void
*
tsdbDeleteImpl
(
STsdbRepo
*
pRepo
,
void
*
param
);
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
5a5b4bf5
...
...
@@ -58,7 +58,7 @@ static int tsdbDropMetaRecord(STsdbFS *pfs, SMFile *pMFile, uint64_t uid);
static
int
tsdbCompactMetaFile
(
STsdbRepo
*
pRepo
,
STsdbFS
*
pfs
,
SMFile
*
pMFile
);
static
int
tsdbCommitTSData
(
STsdbRepo
*
pRepo
);
static
void
tsdbStartCommit
(
STsdbRepo
*
pRepo
);
static
void
tsdbEndCommit
(
STsdbRepo
*
pRepo
,
int
eno
);
static
void
tsdbEndCommit
(
STsdbRepo
*
pRepo
,
int
eno
,
bool
end
);
static
int
tsdbCommitToFile
(
SCommitH
*
pCommith
,
SDFileSet
*
pSet
,
int
fid
);
static
int
tsdbCreateCommitIters
(
SCommitH
*
pCommith
);
static
void
tsdbDestroyCommitIters
(
SCommitH
*
pCommith
);
...
...
@@ -85,14 +85,14 @@ static bool tsdbCanAddSubBlock(SCommitH *pCommith, SBlock *pBlock, SMergeInfo *p
static
void
tsdbLoadAndMergeFromCache
(
SDataCols
*
pDataCols
,
int
*
iter
,
SCommitIter
*
pCommitIter
,
SDataCols
*
pTarget
,
TSKEY
maxKey
,
int
maxRows
,
int8_t
update
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
)
{
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
,
bool
end
)
{
if
(
pRepo
->
imem
==
NULL
)
{
return
NULL
;
}
tsdbStartCommit
(
pRepo
);
if
(
tsShortcutFlag
&
TSDB_SHORTCUT_RB_TSDB_COMMIT
)
{
tsdbEndCommit
(
pRepo
,
terrno
);
tsdbEndCommit
(
pRepo
,
terrno
,
end
);
return
NULL
;
}
...
...
@@ -108,14 +108,14 @@ void *tsdbCommitData(STsdbRepo *pRepo) {
goto
_err
;
}
tsdbEndCommit
(
pRepo
,
TSDB_CODE_SUCCESS
);
tsdbEndCommit
(
pRepo
,
TSDB_CODE_SUCCESS
,
end
);
return
NULL
;
_err:
ASSERT
(
terrno
!=
TSDB_CODE_SUCCESS
);
pRepo
->
code
=
terrno
;
tsdbEndCommit
(
pRepo
,
terrno
);
tsdbEndCommit
(
pRepo
,
terrno
,
end
);
return
NULL
;
}
...
...
@@ -688,7 +688,7 @@ static void tsdbStartCommit(STsdbRepo *pRepo) {
pRepo
->
code
=
TSDB_CODE_SUCCESS
;
}
static
void
tsdbEndCommit
(
STsdbRepo
*
pRepo
,
int
eno
)
{
static
void
tsdbEndCommit
(
STsdbRepo
*
pRepo
,
int
eno
,
bool
end
)
{
if
(
eno
!=
TSDB_CODE_SUCCESS
)
{
tsdbEndFSTxnWithError
(
REPO_FS
(
pRepo
));
}
else
{
...
...
@@ -697,14 +697,21 @@ static void tsdbEndCommit(STsdbRepo *pRepo, int eno) {
tsdbInfo
(
"vgId:%d commit over, %s"
,
REPO_ID
(
pRepo
),
(
eno
==
TSDB_CODE_SUCCESS
)
?
"succeed"
:
"failed"
);
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_OVER
,
eno
);
// notify
if
(
end
&&
pRepo
->
appH
.
notifyStatus
)
{
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_OVER
,
eno
);
}
SMemTable
*
pIMem
=
pRepo
->
imem
;
(
void
)
tsdbLockRepo
(
pRepo
);
pRepo
->
imem
=
NULL
;
(
void
)
tsdbUnlockRepo
(
pRepo
);
tsdbUnRefMemTable
(
pRepo
,
pIMem
);
tsem_post
(
&
(
pRepo
->
readyToCommit
));
// release readyToCommit allow next commit
if
(
end
)
{
tsem_post
(
&
(
pRepo
->
readyToCommit
));
}
}
#if 0
...
...
@@ -1772,3 +1779,39 @@ int tsdbApplyRtn(STsdbRepo *pRepo) {
return
0
;
}
int
tsdbControlDelete
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
)
{
int
ret
=
TSDB_CODE_SUCCESS
;
if
(
pCtlDataInfo
->
pRsp
)
{
pCtlDataInfo
->
pRsp
->
affectedRows
=
htonl
(
23
);
pCtlDataInfo
->
pRsp
->
code
=
ret
;
}
return
ret
;
}
// do control task
int
tsdbCommitControl
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
)
{
int
ret
=
TSDB_CODE_SUCCESS
;
// do command
if
(
pCtlDataInfo
->
ctlData
.
command
==
CMD_DELETE_DATA
)
{
// delete data
ret
=
tsdbControlDelete
(
pRepo
,
pCtlDataInfo
);
}
// notify response thread to response result to client
if
(
pCtlDataInfo
->
pSem
)
{
tsem_post
(
pCtlDataInfo
->
pSem
);
}
// deal wal
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_OVER
,
ret
);
// release commitSep for next commit
tsem_post
(
&
pRepo
->
readyToCommit
);
return
ret
;
}
\ No newline at end of file
src/tsdb/src/tsdbCommitQueue.c
浏览文件 @
5a5b4bf5
...
...
@@ -189,13 +189,15 @@ static void *tsdbLoopCommit(void *arg) {
param
=
((
SReq
*
)
pNode
->
data
)
->
param
;
if
(
req
==
COMMIT_REQ
)
{
tsdbCommitData
(
pRepo
);
tsdbCommitData
(
pRepo
,
true
);
}
else
if
(
req
==
COMPACT_REQ
)
{
tsdbCompactImpl
(
pRepo
);
}
else
if
(
req
==
TRUNCATE_TBL_REQ
)
{
tsdbTruncateImpl
(
pRepo
,
param
);
}
else
if
(
req
==
DELETE_TBL_REQ
)
{
tsdbDeleteImpl
(
pRepo
,
param
);
}
else
if
(
req
==
COMMIT_BOTH_REQ
)
{
SControlDataInfo
*
pCtlDataInfo
=
(
SControlDataInfo
*
)
param
;
if
(
!
pCtlDataInfo
->
memNull
)
{
tsdbCommitData
(
pRepo
,
false
);
}
tsdbCommitControl
(
pRepo
,
param
);
}
else
if
(
req
==
COMMIT_CONFIG_REQ
)
{
ASSERT
(
pRepo
->
config_changed
);
tsdbApplyRepoConfig
(
pRepo
);
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
5a5b4bf5
...
...
@@ -188,7 +188,7 @@ int tsdbUnlockRepo(STsdbRepo *pRepo) {
int
tsdbCheckWal
(
STsdbRepo
*
pRepo
,
uint32_t
walSize
)
{
// MB
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
if
((
walSize
>
tsdbWalFlushSize
)
&&
(
walSize
>
(
pCfg
->
totalBlocks
/
2
*
pCfg
->
cacheBlockSize
)))
{
if
(
tsdbAsyncCommit
(
pRepo
)
<
0
)
return
-
1
;
if
(
tsdbAsyncCommit
(
pRepo
,
NULL
)
<
0
)
return
-
1
;
}
return
0
;
}
...
...
@@ -202,7 +202,7 @@ int tsdbCheckCommit(STsdbRepo *pRepo) {
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
;
if
(
tsdbAsyncCommit
(
pRepo
,
NULL
)
<
0
)
return
-
1
;
}
return
0
;
}
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
5a5b4bf5
...
...
@@ -49,12 +49,12 @@ static int tsdbInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIte
static
int
tsdbGetSubmitMsgNext
(
SSubmitMsgIter
*
pIter
,
SSubmitBlk
**
pPBlock
);
static
int
tsdbCheckTableSchema
(
STsdbRepo
*
pRepo
,
SSubmitBlk
*
pBlock
,
STable
*
pTable
);
static
int
tsdbUpdateTableLatestInfo
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SMemRow
row
);
static
int32_t
tsdbInsertControlData
(
STsdbRepo
*
pRepo
,
SSubmitBlk
*
pBlock
,
SShellSubmitRspMsg
*
pRsp
,
sem_t
*
pSem
);
static
int32_t
tsdbInsertControlData
(
STsdbRepo
*
pRepo
,
SSubmitBlk
*
pBlock
,
SShellSubmitRspMsg
*
pRsp
,
tsem_t
*
*
pSem
);
static
FORCE_INLINE
int
tsdbCheckRowRange
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SMemRow
row
,
TSKEY
minKey
,
TSKEY
maxKey
,
TSKEY
now
);
int32_t
tsdbInsertData
(
STsdbRepo
*
repo
,
SSubmitMsg
*
pMsg
,
SShellSubmitRspMsg
*
pRsp
,
sem_t
*
pSem
)
{
int32_t
tsdbInsertData
(
STsdbRepo
*
repo
,
SSubmitMsg
*
pMsg
,
SShellSubmitRspMsg
*
pRsp
,
tsem_t
**
p
pSem
)
{
STsdbRepo
*
pRepo
=
repo
;
SSubmitMsgIter
msgIter
=
{
0
};
SSubmitBlk
*
pBlock
=
NULL
;
...
...
@@ -74,7 +74,7 @@ int32_t tsdbInsertData(STsdbRepo *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pR
if
(
pBlock
==
NULL
)
break
;
if
(
IS_CONTROL_BLOCK
(
pBlock
))
{
// COMMAND DATA BLOCK
ret
=
tsdbInsertControlData
(
pRepo
,
pBlock
,
pRsp
,
pSem
);
ret
=
tsdbInsertControlData
(
pRepo
,
pBlock
,
pRsp
,
p
p
Sem
);
// all control msg is one SSubmitMsg, so need return
return
ret
;
}
else
{
...
...
@@ -317,11 +317,12 @@ int tsdbSyncCommitConfig(STsdbRepo* pRepo) {
return
0
;
}
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
)
{
int
tsdbAsyncCommit
(
STsdbRepo
*
pRepo
,
SControlDataInfo
*
pCtlDataInfo
)
{
tsem_wait
(
&
(
pRepo
->
readyToCommit
));
ASSERT
(
pRepo
->
imem
==
NULL
);
if
(
pRepo
->
mem
==
NULL
)
{
if
(
pRepo
->
mem
==
NULL
&&
pCtlDataInfo
==
NULL
)
{
tsem_post
(
&
(
pRepo
->
readyToCommit
));
return
0
;
}
...
...
@@ -332,11 +333,33 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) {
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_START
,
TSDB_CODE_SUCCESS
);
if
(
tsdbLockRepo
(
pRepo
)
<
0
)
return
-
1
;
pRepo
->
imem
=
pRepo
->
mem
;
pRepo
->
mem
=
NULL
;
if
(
tsdbScheduleCommit
(
pRepo
,
NULL
,
COMMIT_REQ
)
<
0
)
{
tsem_post
(
&
(
pRepo
->
readyToCommit
));
bool
post
=
false
;
if
(
pRepo
->
mem
)
{
// has data in mem
pRepo
->
imem
=
pRepo
->
mem
;
pRepo
->
mem
=
NULL
;
if
(
pCtlDataInfo
==
NULL
)
{
if
(
tsdbScheduleCommit
(
pRepo
,
NULL
,
COMMIT_REQ
)
<
0
)
post
=
true
;
}
else
{
pCtlDataInfo
->
memNull
=
false
;
if
(
tsdbScheduleCommit
(
pRepo
,
pCtlDataInfo
,
COMMIT_BOTH_REQ
)
<
0
)
post
=
true
;
}
}
else
{
// no data in mem
if
(
pCtlDataInfo
)
{
pCtlDataInfo
->
memNull
=
true
;
if
(
tsdbScheduleCommit
(
pRepo
,
pCtlDataInfo
,
COMMIT_BOTH_REQ
)
<
0
)
post
=
true
;
}
}
// need post
if
(
post
)
tsem_post
(
&
(
pRepo
->
readyToCommit
));
if
(
tsdbUnlockRepo
(
pRepo
)
<
0
)
return
-
1
;
return
0
;
...
...
@@ -345,7 +368,7 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) {
int
tsdbSyncCommit
(
STsdbRepo
*
repo
)
{
STsdbRepo
*
pRepo
=
repo
;
tsdbAsyncCommit
(
pRepo
);
tsdbAsyncCommit
(
pRepo
,
NULL
);
tsem_wait
(
&
(
pRepo
->
readyToCommit
));
tsem_post
(
&
(
pRepo
->
readyToCommit
));
...
...
@@ -1096,38 +1119,46 @@ static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SMemRow r
return
0
;
}
// Delete Data
int32_t
tsdbInsertDeleteData
(
STsdbRepo
*
pRepo
,
SControlData
*
pCtlData
,
SShellSubmitRspMsg
*
pRsp
,
sem_t
*
pSem
)
{
pRsp
->
affectedRows
=
htonl
(
99
);
// INIT SEM
int32_t
ret
=
sem_init
(
pSem
,
0
,
0
);
if
(
ret
!=
0
)
{
return
TAOS_SYSTEM_ERROR
(
ret
);
}
// CREATE DELETE MEMTABLE
// FORCE COMMIT ALL MEM AND IMEM
return
0
;
}
// Control Data
int32_t
tsdbInsertControlData
(
STsdbRepo
*
pRepo
,
SSubmitBlk
*
pBlock
,
SShellSubmitRspMsg
*
pRsp
,
sem_t
*
pSem
)
{
int32_t
tsdbInsertControlData
(
STsdbRepo
*
pRepo
,
SSubmitBlk
*
pBlock
,
SShellSubmitRspMsg
*
pRsp
,
tsem_t
**
p
pSem
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
assert
(
pBlock
->
dataLen
==
sizeof
(
SControlData
));
SControlData
*
pCtlData
=
(
SControlData
*
)
pBlock
->
data
;
// INIT SEM FOR ASYNC WAIT COMMIT RESULT
if
(
ppSem
)
{
*
ppSem
=
(
tsem_t
*
)
tmalloc
(
sizeof
(
tsem_t
));
ret
=
tsem_init
(
*
ppSem
,
0
,
0
);
if
(
ret
!=
0
)
{
return
TAOS_SYSTEM_ERROR
(
ret
);
}
}
// anti-serialize
pCtlData
->
command
=
htonl
(
pCtlData
->
command
);
pCtlData
->
win
.
skey
=
htobe64
(
pCtlData
->
win
.
skey
);
pCtlData
->
win
.
ekey
=
htobe64
(
pCtlData
->
win
.
ekey
);
// server data set
SControlDataInfo
*
pNew
=
(
SControlDataInfo
*
)
tmalloc
(
sizeof
(
SControlDataInfo
));
memset
(
pNew
,
0
,
sizeof
(
SControlDataInfo
));
pNew
->
ctlData
=
*
pCtlData
;
pNew
->
uid
=
pBlock
->
uid
;
pNew
->
tid
=
pBlock
->
tid
;
pNew
->
pRsp
=
pRsp
;
if
(
ppSem
)
pNew
->
pSem
=
*
ppSem
;
if
(
pCtlData
->
command
==
CMD_DELETE_DATA
)
{
ret
=
tsdbInsertDeleteData
(
pRepo
,
pCtlData
,
pRsp
,
pSem
);
// malloc new to pass commit thread
ret
=
tsdbAsyncCommit
(
pRepo
,
pNew
);
}
// if async post failed , must set wait event ppSem NULL
if
(
ret
!=
TSDB_CODE_SUCCESS
&&
ppSem
)
{
tsem_destroy
(
*
ppSem
);
*
ppSem
=
NULL
;
}
return
ret
;
}
\ No newline at end of file
src/tsdb/src/tsdbTruncate.c
浏览文件 @
5a5b4bf5
...
...
@@ -45,13 +45,14 @@ typedef struct {
#define TSDB_TRUNCATE_COMP_BUF(pTruncateH) TSDB_READ_COMP_BUF(&((pTruncateH)->readh))
#define TSDB_TRUNCATE_EXBUF(pTruncateH) TSDB_READ_EXBUF(&((pTruncateH)->readh))
/*
static int tsdbAsyncTruncate(STsdbRepo *pRepo, void *param, TSDB_REQ_T type);
static void tsdbStartTruncate(STsdbRepo *pRepo);
static void tsdbEndTruncate(STsdbRepo *pRepo, int eno);
static int tsdbTruncateMeta(STsdbRepo *pRepo);
static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param, TSDB_REQ_T type);
static
int
tsdbTruncateFSet
(
STruncateH
*
pTruncateH
,
SDFileSet
*
pSet
);
static
int
tsdbDeleteFSet
(
STruncateH
*
pTruncateH
,
SDFileSet
*
pSet
);
//
static int tsdbTruncateFSet(STruncateH *pTruncateH, SDFileSet *pSet);
//
static int tsdbDeleteFSet(STruncateH *pTruncateH, SDFileSet *pSet);
static int tsdbInitTruncateH(STruncateH *pTruncateH, STsdbRepo *pRepo);
static void tsdbDestroyTruncateH(STruncateH *pTruncateH);
static int tsdbInitTruncateTblArray(STruncateH *pTruncateH);
...
...
@@ -65,7 +66,7 @@ static int tsdbDeleteFSetImpl(STruncateH *pTruncateH);
static bool tsdbBlockInterleaved(STruncateH *pTruncateH, SBlock *pBlock);
static int tsdbWriteBlockToRightFile(STruncateH *pTruncateH, STable *pTable, SDataCols *pDCols, void **ppBuf,
void **ppCBuf, void **ppExBuf);
static
void
*
tsdbTruncateImplCommon
(
STsdbRepo
*
pRepo
,
void
*
param
,
TSDB_REQ_T
type
);
//
static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T type);
enum {
TSDB_NO_TRUNCATE,
...
...
@@ -73,18 +74,19 @@ enum {
TSDB_WAITING_TRUNCATE,
};
int
tsdbTruncateTbl
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
return
tsdbAsyncTruncate
(
pRepo
,
param
,
TRUNCATE_TB
L_REQ
);
}
int
tsdbDeleteData
(
STsdbRepo
*
pRepo
,
void
*
param
)
{
return
tsdbAsyncTruncate
(
pRepo
,
param
,
DELETE_TB
L_REQ
);
}
int tsdbTruncateTbl(STsdbRepo *pRepo, void *param) { return tsdbAsyncTruncate(pRepo, param,
CONTRO
L_REQ); }
int tsdbDeleteData(STsdbRepo *pRepo, void *param) { return tsdbAsyncTruncate(pRepo, param,
CONTRO
L_REQ); }
void *tsdbTruncateImpl(STsdbRepo *pRepo, void *param) {
tsdbTruncateImplCommon
(
pRepo
,
param
,
TRUNCATE_TBL_REQ
);
//
tsdbTruncateImplCommon(pRepo, param, TRUNCATE_TBL_REQ);
return NULL;
}
void *tsdbDeleteImpl(STsdbRepo *pRepo, void *param) {
tsdbTruncateImplCommon
(
pRepo
,
param
,
DELETE_TBL_REQ
);
//
tsdbTruncateImplCommon(pRepo, param, DELETE_TBL_REQ);
return NULL;
}
static void *tsdbTruncateImplCommon(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
ASSERT(param != NULL);
int32_t code = 0;
...
...
@@ -233,6 +235,7 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
continue;
}
#endif
if (truncateH.type == TRUNCATE_TBL_REQ) {
if (tsdbTruncateFSet(&truncateH, pSet) < 0) {
tsdbDestroyTruncateH(&truncateH);
...
...
@@ -248,6 +251,7 @@ static int tsdbTruncateTSData(STsdbRepo *pRepo, void *param, TSDB_REQ_T type) {
} else {
ASSERT(false);
}
}
tsdbDestroyTruncateH(&truncateH);
...
...
@@ -739,4 +743,5 @@ static int tsdbWriteBlockToRightFile(STruncateH *pTruncateH, STable *pTable, SDa
// }
// return 0;
// }
\ No newline at end of file
// }
*/
\ No newline at end of file
src/tsdb/tests/tsdbTests.cpp
浏览文件 @
5a5b4bf5
...
...
@@ -79,7 +79,7 @@ static int insertData(SInsertInfo *pInfo) {
pMsg
->
length
=
htonl
(
pMsg
->
length
);
pMsg
->
numOfBlocks
=
htonl
(
pMsg
->
numOfBlocks
);
if
(
tsdbInsertData
(
pInfo
->
pRepo
,
pMsg
,
NULL
)
<
0
)
{
if
(
tsdbInsertData
(
pInfo
->
pRepo
,
pMsg
,
NULL
,
NULL
)
<
0
)
{
tfree
(
pMsg
);
return
-
1
;
}
...
...
src/vnode/src/vnodeMain.c
浏览文件 @
5a5b4bf5
...
...
@@ -144,9 +144,9 @@ int32_t vnodeTruncateTbl(STruncateTblMsg *pMsg) {
param
->
nSpan
=
1
;
param
->
span
[
0
].
skey
=
1634701320001
;
param
->
span
[
0
].
ekey
=
1634701320001
;
if
(
tsdbTruncateTbl
(((
SVnodeObj
*
)
pVnode
)
->
tsdb
,
param
)
<
0
)
{
tfree
(
param
);
}
//
if (tsdbTruncateTbl(((SVnodeObj *)pVnode)->tsdb, param) < 0) {
//
tfree(param);
//
}
vnodeRelease
(
pVnode
);
}
else
{
vInfo
(
"vgId:%d, vnode not exist, can't truncate table %s in it"
,
vgId
,
pMsg
->
tableFname
);
...
...
@@ -167,9 +167,9 @@ int32_t vnodeDeleteData(SDeleteDataMsg *pMsg) {
param
->
nSpan
=
1
;
param
->
span
[
0
].
skey
=
1634701320001
;
param
->
span
[
0
].
ekey
=
1634701320001
;
if
(
tsdbDeleteData
(((
SVnodeObj
*
)
pVnode
)
->
tsdb
,
param
)
<
0
)
{
tfree
(
param
);
}
//
if (tsdbDeleteData(((SVnodeObj *)pVnode)->tsdb, param) < 0) {
//
tfree(param);
//
}
vnodeRelease
(
pVnode
);
}
else
{
vInfo
(
"vgId:%d, vnode not exist, can't truncate table %s in it"
,
vgId
,
pMsg
->
tableFname
);
...
...
@@ -481,7 +481,7 @@ void freeWaitThread(SVnodeObj* pVnode) {
if
(
loop
==
LOOP_CNT
)
tsem_post
(
pWaitThread
->
psem
);
taosMsleep
(
50
);
loop
-=
1
;
loop
-=
1
;
if
(
loop
==
0
)
break
;
}
...
...
@@ -671,7 +671,7 @@ void vnodeAddWait(void* vparam, pthread_t* pthread, sem_t* psem, void* param) {
pWaitThread
->
psem
=
psem
;
pWaitThread
->
param
=
param
;
int32_t
crc
=
crc32c_sf
(
0
,
(
crc_stream
)
p
WaitThread
,
sizeof
(
void
*
));
int32_t
crc
=
crc32c_sf
(
0
,
(
crc_stream
)
p
aram
,
sizeof
(
void
*
));
taosWriteQitem
(
pVnode
->
tqueue
,
crc
,
pWaitThread
);
}
...
...
src/vnode/src/vnodeWrite.c
浏览文件 @
5a5b4bf5
...
...
@@ -163,13 +163,15 @@ static int32_t vnodeProcessSubmitMsg(SVnodeObj *pVnode, void *pCont, SRspRet *pR
// save insert result into item
SShellSubmitRspMsg
*
pRsp
=
NULL
;
tsem_t
**
ppsem
=
NULL
;
if
(
pRet
)
{
pRet
->
len
=
sizeof
(
SShellSubmitRspMsg
);
pRet
->
rsp
=
rpcMallocCont
(
pRet
->
len
);
pRsp
=
pRet
->
rsp
;
ppsem
=
&
pRet
->
psem
;
}
if
(
tsdbInsertData
(
pVnode
->
tsdb
,
pCont
,
pRsp
,
p
Ret
->
psem_rsp
)
<
0
)
{
if
(
tsdbInsertData
(
pVnode
->
tsdb
,
pCont
,
pRsp
,
p
psem
)
<
0
)
{
code
=
terrno
;
}
else
{
if
(
pRsp
!=
NULL
)
atomic_fetch_add_64
(
&
tsSubmitReqSucNum
,
1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录