Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
713c20c4
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
713c20c4
编写于
12月 10, 2021
作者:
L
Liu Jicong
提交者:
GitHub
12月 10, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9028 from taosdata/feature/tq
make tfinit called once
上级
defd4325
03a54b5a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
115 addition
and
72 deletion
+115
-72
include/libs/wal/wal.h
include/libs/wal/wal.h
+10
-16
include/util/tarray.h
include/util/tarray.h
+7
-0
source/libs/wal/inc/walInt.h
source/libs/wal/inc/walInt.h
+5
-5
source/libs/wal/src/walIndex.c
source/libs/wal/src/walIndex.c
+20
-14
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+14
-8
source/libs/wal/src/walRead.c
source/libs/wal/src/walRead.c
+2
-2
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+41
-20
source/libs/wal/test/walMetaTest.cpp
source/libs/wal/test/walMetaTest.cpp
+0
-7
source/util/src/tarray.c
source/util/src/tarray.c
+10
-0
source/util/src/tfile.c
source/util/src/tfile.c
+6
-0
未找到文件。
include/libs/wal/wal.h
浏览文件 @
713c20c4
...
...
@@ -91,7 +91,8 @@ typedef struct SWal {
int32_t
fsyncPeriod
;
// millisecond
int32_t
rollPeriod
;
// second
int64_t
segSize
;
int64_t
rtSize
;
int64_t
retentionSize
;
int32_t
retentionPeriod
;
EWalType
level
;
//total size
int64_t
totSize
;
...
...
@@ -99,31 +100,24 @@ typedef struct SWal {
int32_t
fsyncSeq
;
//reference
int64_t
refId
;
//current tfd
int64_t
curLogTfd
;
int64_t
curIdxTfd
;
//write tfd
int64_t
writeLogTfd
;
int64_t
writeIdxTfd
;
//read tfd
int64_t
readLogTfd
;
int64_t
readIdxTfd
;
//current version
int64_t
curVersion
;
//current file version
//int64_t curFileFirstVersion;
//int64_t curFileLastVersion;
//wal lifecycle
int64_t
firstVersion
;
int64_t
snapshotVersion
;
int64_t
commitVersion
;
int64_t
lastVersion
;
//last file
//int64_t lastFileName;
//roll status
int64_t
lastRollSeq
;
//int64_t lastFileWriteSize;
//file set
int32_t
fileCursor
;
int32_t
writeCur
;
int32_t
readCur
;
SArray
*
fileInfoSet
;
//ctl
int32_t
curStatus
;
...
...
include/util/tarray.h
浏览文件 @
713c20c4
...
...
@@ -146,6 +146,13 @@ void* taosArrayInsert(SArray* pArray, size_t index, void* pData);
*/
void
taosArraySet
(
SArray
*
pArray
,
size_t
index
,
void
*
pData
);
/**
* remove some data entry from front
* @param pArray
* @param cnt
*/
void
taosArrayPopFrontBatch
(
SArray
*
pArray
,
size_t
cnt
);
/**
* remove data entry of the given index
* @param pArray
...
...
source/libs/wal/inc/walInt.h
浏览文件 @
713c20c4
...
...
@@ -49,26 +49,26 @@ static inline int64_t walGetLastFileFirstVer(SWal* pWal) {
}
static
inline
int64_t
walGetCurFileFirstVer
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
fileCurso
r
);
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCu
r
);
return
pInfo
->
firstVer
;
}
static
inline
int64_t
walGetCurFileLastVer
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
fileCurso
r
);
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCu
r
);
return
pInfo
->
firstVer
;
}
static
inline
int64_t
walGetCurFileOffset
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
fileCurso
r
);
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCu
r
);
return
pInfo
->
fileSize
;
}
static
inline
bool
walCurFileClosed
(
SWal
*
pWal
)
{
return
taosArrayGetSize
(
pWal
->
fileInfoSet
)
!=
pWal
->
fileCurso
r
;
return
taosArrayGetSize
(
pWal
->
fileInfoSet
)
!=
pWal
->
writeCu
r
;
}
static
inline
WalFileInfo
*
walGetCurFileInfo
(
SWal
*
pWal
)
{
return
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
fileCurso
r
);
return
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCu
r
);
}
static
inline
int
walBuildLogName
(
SWal
*
pWal
,
int64_t
fileFirstVer
,
char
*
buf
)
{
...
...
source/libs/wal/src/walIndex.c
浏览文件 @
713c20c4
...
...
@@ -23,25 +23,25 @@
static
int
walSeekFilePos
(
SWal
*
pWal
,
int64_t
ver
)
{
int
code
=
0
;
int64_t
idxTfd
=
pWal
->
cur
IdxTfd
;
int64_t
logTfd
=
pWal
->
cur
LogTfd
;
int64_t
idxTfd
=
pWal
->
write
IdxTfd
;
int64_t
logTfd
=
pWal
->
write
LogTfd
;
//seek position
int64_t
offset
=
(
ver
-
walGetCurFileFirstVer
(
pWal
))
*
WAL_IDX_ENTRY_SIZE
;
code
=
tfLseek
(
idxTfd
,
offset
,
SEEK_SET
);
if
(
code
!=
0
)
{
return
-
1
;
}
int64_t
readBuf
[
2
];
code
=
tfRead
(
idxTfd
,
readBuf
,
sizeof
(
readBuf
));
if
(
code
!=
0
)
{
return
-
1
;
}
//TODO:deserialize
ASSERT
(
readBuf
[
0
]
==
ver
);
code
=
tfLseek
(
logTfd
,
readBuf
[
1
],
SEEK_CUR
);
if
(
code
!=
0
)
{
return
-
1
;
}
/*pWal->curLogOffset = readBuf[1];*/
pWal
->
curVersion
=
ver
;
...
...
@@ -52,11 +52,11 @@ static int walChangeFile(SWal *pWal, int64_t ver) {
int
code
=
0
;
int64_t
idxTfd
,
logTfd
;
char
fnameStr
[
WAL_FILE_LEN
];
code
=
tfClose
(
pWal
->
cur
LogTfd
);
code
=
tfClose
(
pWal
->
write
LogTfd
);
if
(
code
!=
0
)
{
//TODO
}
code
=
tfClose
(
pWal
->
cur
IdxTfd
);
code
=
tfClose
(
pWal
->
write
IdxTfd
);
if
(
code
!=
0
)
{
//TODO
}
...
...
@@ -81,14 +81,14 @@ static int walChangeFile(SWal *pWal, int64_t ver) {
logTfd
=
tfOpenReadWrite
(
fnameStr
);
}
pWal
->
cur
LogTfd
=
logTfd
;
pWal
->
cur
IdxTfd
=
idxTfd
;
pWal
->
write
LogTfd
=
logTfd
;
pWal
->
write
IdxTfd
=
idxTfd
;
return
code
;
}
int
walSeekVer
(
SWal
*
pWal
,
int64_t
ver
)
{
i
f
((
!
(
pWal
->
curStatus
&
WAL_CUR_FAILED
))
&&
ver
==
pWal
->
curVersion
)
{
i
nt
code
;
if
((
!
(
pWal
->
curStatus
&
WAL_CUR_FAILED
))
&&
ver
==
pWal
->
curVersion
)
{
return
0
;
}
if
(
ver
>
pWal
->
lastVersion
)
{
...
...
@@ -103,9 +103,15 @@ int walSeekVer(SWal *pWal, int64_t ver) {
//TODO: seek snapshotted log, invalid in some cases
}
if
(
ver
<
walGetCurFileFirstVer
(
pWal
)
||
(
ver
>
walGetCurFileLastVer
(
pWal
)))
{
walChangeFile
(
pWal
,
ver
);
code
=
walChangeFile
(
pWal
,
ver
);
if
(
code
!=
0
)
{
return
-
1
;
}
}
walSeekFilePos
(
pWal
,
ver
);
code
=
walSeekFilePos
(
pWal
,
ver
);
if
(
code
!=
0
)
{
return
-
1
;
}
return
0
;
}
source/libs/wal/src/walMgmt.c
浏览文件 @
713c20c4
...
...
@@ -48,9 +48,15 @@ int32_t walInit() {
int8_t
old
=
atomic_val_compare_exchange_8
(
&
tsWal
.
inited
,
0
,
1
);
if
(
old
==
1
)
return
0
;
int
code
=
tfInit
();
if
(
code
!=
0
)
{
wError
(
"failed to init tfile since %s"
,
tstrerror
(
code
));
atomic_store_8
(
&
tsWal
.
inited
,
0
);
return
code
;
}
tsWal
.
refSetId
=
taosOpenRef
(
TSDB_MIN_VNODES
,
walFreeObj
);
int
code
=
walCreateThread
();
code
=
walCreateThread
();
if
(
code
!=
0
)
{
wError
(
"failed to init wal module since %s"
,
tstrerror
(
code
));
atomic_store_8
(
&
tsWal
.
inited
,
0
);
...
...
@@ -74,8 +80,8 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
}
pWal
->
cur
LogTfd
=
-
1
;
pWal
->
cur
IdxTfd
=
-
1
;
pWal
->
write
LogTfd
=
-
1
;
pWal
->
write
IdxTfd
=
-
1
;
//set config
pWal
->
vgId
=
pCfg
->
vgId
;
...
...
@@ -138,8 +144,8 @@ void walClose(SWal *pWal) {
if
(
pWal
==
NULL
)
return
;
pthread_mutex_lock
(
&
pWal
->
mutex
);
tfClose
(
pWal
->
cur
LogTfd
);
tfClose
(
pWal
->
cur
IdxTfd
);
tfClose
(
pWal
->
write
LogTfd
);
tfClose
(
pWal
->
write
IdxTfd
);
/*taosArrayDestroy(pWal->fileInfoSet);*/
/*pWal->fileInfoSet = NULL;*/
pthread_mutex_unlock
(
&
pWal
->
mutex
);
...
...
@@ -165,8 +171,8 @@ static void walFreeObj(void *wal) {
SWal
*
pWal
=
wal
;
wDebug
(
"vgId:%d, wal:%p is freed"
,
pWal
->
vgId
,
pWal
);
tfClose
(
pWal
->
cur
LogTfd
);
tfClose
(
pWal
->
cur
IdxTfd
);
tfClose
(
pWal
->
write
LogTfd
);
tfClose
(
pWal
->
write
IdxTfd
);
taosArrayDestroy
(
pWal
->
fileInfoSet
);
pWal
->
fileInfoSet
=
NULL
;
taosArrayDestroy
(
pWal
->
fileInfoSet
);
...
...
@@ -197,7 +203,7 @@ static void walFsyncAll() {
while
(
pWal
)
{
if
(
walNeedFsync
(
pWal
))
{
wTrace
(
"vgId:%d, do fsync, level:%d seq:%d rseq:%d"
,
pWal
->
vgId
,
pWal
->
level
,
pWal
->
fsyncSeq
,
atomic_load_32
(
&
tsWal
.
seq
));
int32_t
code
=
tfFsync
(
pWal
->
cur
LogTfd
);
int32_t
code
=
tfFsync
(
pWal
->
write
LogTfd
);
if
(
code
!=
0
)
{
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to fsync since %s"
,
pWal
->
vgId
,
walGetLastFileFirstVer
(
pWal
),
strerror
(
code
));
}
...
...
source/libs/wal/src/walRead.c
浏览文件 @
713c20c4
...
...
@@ -42,7 +42,7 @@ int32_t walRead(SWal *pWal, SWalHead **ppHead, int64_t ver) {
}
*
ppHead
=
ptr
;
}
if
(
tfRead
(
pWal
->
cur
LogTfd
,
*
ppHead
,
sizeof
(
SWalHead
))
!=
sizeof
(
SWalHead
))
{
if
(
tfRead
(
pWal
->
write
LogTfd
,
*
ppHead
,
sizeof
(
SWalHead
))
!=
sizeof
(
SWalHead
))
{
return
-
1
;
}
//TODO: endian compatibility processing after read
...
...
@@ -55,7 +55,7 @@ int32_t walRead(SWal *pWal, SWalHead **ppHead, int64_t ver) {
*
ppHead
=
NULL
;
return
-
1
;
}
if
(
tfRead
(
pWal
->
cur
LogTfd
,
(
*
ppHead
)
->
cont
,
(
*
ppHead
)
->
len
)
!=
(
*
ppHead
)
->
len
)
{
if
(
tfRead
(
pWal
->
write
LogTfd
,
(
*
ppHead
)
->
cont
,
(
*
ppHead
)
->
len
)
!=
(
*
ppHead
)
->
len
)
{
return
-
1
;
}
//TODO: endian compatibility processing after read
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
713c20c4
...
...
@@ -44,18 +44,39 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
int32_t
walTakeSnapshot
(
SWal
*
pWal
,
int64_t
ver
)
{
pWal
->
snapshotVersion
=
ver
;
int
ts
=
taosGetTimestampSec
();
int
deleteCnt
=
0
;
int64_t
newTotSize
=
pWal
->
totSize
;
WalFileInfo
tmp
;
tmp
.
firstVer
=
ver
;
//mark files safe to delete
WalFileInfo
*
pInfo
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmp
,
compareWalFileInfo
,
TD_LE
);
//iterate files, until the searched result
//if totSize > rtSize, delete
//if createTs > retentionTs, delete
for
(
WalFileInfo
*
iter
=
pWal
->
fileInfoSet
->
pData
;
iter
<
pInfo
;
iter
++
)
{
if
(
pWal
->
totSize
>
pWal
->
retentionSize
||
iter
->
closeTs
+
pWal
->
retentionPeriod
>
ts
)
{
//delete according to file size or close time
deleteCnt
++
;
newTotSize
-=
iter
->
fileSize
;
}
}
char
fnameStr
[
WAL_FILE_LEN
];
//remove file
for
(
int
i
=
0
;
i
<
deleteCnt
;
i
++
)
{
WalFileInfo
*
pInfo
=
taosArrayGet
(
pWal
->
fileInfoSet
,
i
);
walBuildLogName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
remove
(
fnameStr
);
walBuildIdxName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
remove
(
fnameStr
);
}
//save snapshot ver, commit ver
//make new array, remove files
taosArrayPopFrontBatch
(
pWal
->
fileInfoSet
,
deleteCnt
);
pWal
->
totSize
=
newTotSize
;
return
0
;
}
...
...
@@ -153,14 +174,14 @@ void walRemoveAllOldFiles(void *handle) {
int
walRoll
(
SWal
*
pWal
)
{
int
code
=
0
;
if
(
pWal
->
cur
IdxTfd
!=
-
1
)
{
code
=
tfClose
(
pWal
->
cur
IdxTfd
);
if
(
pWal
->
write
IdxTfd
!=
-
1
)
{
code
=
tfClose
(
pWal
->
write
IdxTfd
);
if
(
code
!=
0
)
{
return
-
1
;
}
}
if
(
pWal
->
cur
LogTfd
!=
-
1
)
{
code
=
tfClose
(
pWal
->
cur
LogTfd
);
if
(
pWal
->
write
LogTfd
!=
-
1
)
{
code
=
tfClose
(
pWal
->
write
LogTfd
);
if
(
code
!=
0
)
{
return
-
1
;
}
...
...
@@ -188,8 +209,8 @@ int walRoll(SWal *pWal) {
}
//switch file
pWal
->
cur
IdxTfd
=
idxTfd
;
pWal
->
cur
LogTfd
=
logTfd
;
pWal
->
write
IdxTfd
=
idxTfd
;
pWal
->
write
LogTfd
=
logTfd
;
//change status
pWal
->
curStatus
=
WAL_CUR_FILE_WRITABLE
&
WAL_CUR_POS_WRITABLE
;
...
...
@@ -215,8 +236,8 @@ int walChangeFileToLast(SWal *pWal) {
return
-
1
;
}
//switch file
pWal
->
cur
IdxTfd
=
idxTfd
;
pWal
->
cur
LogTfd
=
logTfd
;
pWal
->
write
IdxTfd
=
idxTfd
;
pWal
->
write
LogTfd
=
logTfd
;
//change status
pWal
->
curVersion
=
fileFirstVer
;
pWal
->
curStatus
=
WAL_CUR_FILE_WRITABLE
;
...
...
@@ -226,15 +247,14 @@ int walChangeFileToLast(SWal *pWal) {
static
int
walWriteIndex
(
SWal
*
pWal
,
int64_t
ver
,
int64_t
offset
)
{
int
code
=
0
;
//get index file
if
(
!
tfValid
(
pWal
->
cur
IdxTfd
))
{
if
(
!
tfValid
(
pWal
->
write
IdxTfd
))
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
WalFileInfo
*
pInfo
=
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
fileCursor
);
wError
(
"vgId:%d, file:%"
PRId64
".idx, failed to open since %s"
,
pWal
->
vgId
,
pInfo
->
firstVer
,
strerror
(
errno
));
wError
(
"vgId:%d, file:%"
PRId64
".idx, failed to open since %s"
,
pWal
->
vgId
,
walGetLastFileFirstVer
(
pWal
),
strerror
(
errno
));
return
code
;
}
int64_t
writeBuf
[
2
]
=
{
ver
,
offset
};
int
size
=
tfWrite
(
pWal
->
cur
IdxTfd
,
writeBuf
,
sizeof
(
writeBuf
));
int
size
=
tfWrite
(
pWal
->
write
IdxTfd
,
writeBuf
,
sizeof
(
writeBuf
));
if
(
size
!=
sizeof
(
writeBuf
))
{
return
-
1
;
}
...
...
@@ -278,13 +298,13 @@ int64_t walWrite(SWal *pWal, int64_t index, uint8_t msgType, const void *body, i
pthread_mutex_lock
(
&
pWal
->
mutex
);
if
(
tfWrite
(
pWal
->
cur
LogTfd
,
&
pWal
->
head
,
sizeof
(
SWalHead
))
!=
sizeof
(
SWalHead
))
{
if
(
tfWrite
(
pWal
->
write
LogTfd
,
&
pWal
->
head
,
sizeof
(
SWalHead
))
!=
sizeof
(
SWalHead
))
{
//ftruncate
code
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
vgId
,
walGetLastFileFirstVer
(
pWal
),
strerror
(
errno
));
}
if
(
tfWrite
(
pWal
->
cur
LogTfd
,
&
body
,
bodyLen
)
!=
bodyLen
)
{
if
(
tfWrite
(
pWal
->
write
LogTfd
,
&
body
,
bodyLen
)
!=
bodyLen
)
{
//ftruncate
code
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
vgId
,
walGetLastFileFirstVer
(
pWal
),
strerror
(
errno
));
...
...
@@ -296,6 +316,7 @@ int64_t walWrite(SWal *pWal, int64_t index, uint8_t msgType, const void *body, i
//set status
pWal
->
lastVersion
=
index
;
pWal
->
totSize
+=
sizeof
(
SWalHead
)
+
bodyLen
;
walGetCurFileInfo
(
pWal
)
->
lastVer
=
index
;
walGetCurFileInfo
(
pWal
)
->
fileSize
+=
sizeof
(
SWalHead
)
+
bodyLen
;
...
...
@@ -305,11 +326,11 @@ int64_t walWrite(SWal *pWal, int64_t index, uint8_t msgType, const void *body, i
}
void
walFsync
(
SWal
*
pWal
,
bool
forceFsync
)
{
if
(
pWal
==
NULL
||
!
tfValid
(
pWal
->
cur
LogTfd
))
return
;
if
(
pWal
==
NULL
||
!
tfValid
(
pWal
->
write
LogTfd
))
return
;
if
(
forceFsync
||
(
pWal
->
level
==
TAOS_WAL_FSYNC
&&
pWal
->
fsyncPeriod
==
0
))
{
wTrace
(
"vgId:%d, fileId:%"
PRId64
".log, do fsync"
,
pWal
->
vgId
,
walGetCurFileFirstVer
(
pWal
));
if
(
tfFsync
(
pWal
->
cur
LogTfd
)
<
0
)
{
if
(
tfFsync
(
pWal
->
write
LogTfd
)
<
0
)
{
wError
(
"vgId:%d, file:%"
PRId64
".log, fsync failed since %s"
,
pWal
->
vgId
,
walGetCurFileFirstVer
(
pWal
),
strerror
(
errno
));
}
}
...
...
@@ -408,10 +429,10 @@ static int64_t walGetOffset(SWal* pWal, int64_t ver) {
}
static
void
walFtruncate
(
SWal
*
pWal
,
int64_t
ver
)
{
int64_t
tfd
=
pWal
->
cur
LogTfd
;
int64_t
tfd
=
pWal
->
write
LogTfd
;
tfFtruncate
(
tfd
,
ver
);
tfFsync
(
tfd
);
tfd
=
pWal
->
cur
IdxTfd
;
tfd
=
pWal
->
write
IdxTfd
;
tfFtruncate
(
tfd
,
ver
*
WAL_IDX_ENTRY_SIZE
);
tfFsync
(
tfd
);
}
...
...
source/libs/wal/test/walMetaTest.cpp
浏览文件 @
713c20c4
...
...
@@ -3,7 +3,6 @@
#include <iostream>
#include <queue>
#include "tfile.h"
#include "walInt.h"
class
WalCleanEnv
:
public
::
testing
::
Test
{
...
...
@@ -11,13 +10,10 @@ class WalCleanEnv : public ::testing::Test {
static
void
SetUpTestCase
()
{
int
code
=
walInit
();
ASSERT
(
code
==
0
);
code
=
tfInit
();
ASSERT
(
code
==
0
);
}
static
void
TearDownTestCase
()
{
walCleanUp
();
tfCleanup
();
}
void
SetUp
()
override
{
...
...
@@ -45,13 +41,10 @@ class WalKeepEnv : public ::testing::Test {
static
void
SetUpTestCase
()
{
int
code
=
walInit
();
ASSERT
(
code
==
0
);
code
=
tfInit
();
ASSERT
(
code
==
0
);
}
static
void
TearDownTestCase
()
{
walCleanUp
();
tfCleanup
();
}
void
SetUp
()
override
{
...
...
source/util/src/tarray.c
浏览文件 @
713c20c4
...
...
@@ -237,6 +237,16 @@ void taosArraySet(SArray* pArray, size_t index, void* pData) {
memcpy
(
TARRAY_GET_ELEM
(
pArray
,
index
),
pData
,
pArray
->
elemSize
);
}
void
taosArrayPopFrontBatch
(
SArray
*
pArray
,
size_t
cnt
)
{
assert
(
cnt
<=
pArray
->
size
);
pArray
->
size
=
pArray
->
size
-
cnt
;
if
(
pArray
->
size
==
0
)
{
pArray
->
size
=
0
;
return
;
}
memmove
(
pArray
->
pData
,
(
char
*
)
pArray
->
pData
+
cnt
*
pArray
->
elemSize
,
pArray
->
size
);
}
void
taosArrayRemove
(
SArray
*
pArray
,
size_t
index
)
{
assert
(
index
<
pArray
->
size
);
...
...
source/util/src/tfile.c
浏览文件 @
713c20c4
...
...
@@ -22,20 +22,26 @@
static
int32_t
tsFileRsetId
=
-
1
;
static
int8_t
tfInited
=
0
;
static
void
tfCloseFile
(
void
*
p
)
{
taosCloseFile
((
int32_t
)(
uintptr_t
)
p
);
}
int32_t
tfInit
()
{
int8_t
old
=
atomic_val_compare_exchange_8
(
&
tfInited
,
0
,
1
);
if
(
old
==
1
)
return
0
;
tsFileRsetId
=
taosOpenRef
(
2000
,
tfCloseFile
);
if
(
tsFileRsetId
>
0
)
{
return
0
;
}
else
{
atomic_store_8
(
&
tfInited
,
0
);
return
-
1
;
}
}
void
tfCleanup
()
{
atomic_store_8
(
&
tfInited
,
0
);
if
(
tsFileRsetId
>=
0
)
taosCloseRef
(
tsFileRsetId
);
tsFileRsetId
=
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录