Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1132a7f7
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
1132a7f7
编写于
9月 02, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact code
上级
3286ab2a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
193 addition
and
198 deletion
+193
-198
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+7
-7
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+14
-14
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+84
-84
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+19
-19
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
+24
-27
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+12
-14
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
+26
-26
source/dnode/vnode/src/tsdb/tsdbRetention.c
source/dnode/vnode/src/tsdb/tsdbRetention.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
+6
-6
未找到文件。
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
1132a7f7
...
...
@@ -50,7 +50,7 @@ typedef struct SBlockData SBlockData;
typedef
struct
SDelFile
SDelFile
;
typedef
struct
SHeadFile
SHeadFile
;
typedef
struct
SDataFile
SDataFile
;
typedef
struct
S
LastFile
SLa
stFile
;
typedef
struct
S
SstFile
SS
stFile
;
typedef
struct
SSmaFile
SSmaFile
;
typedef
struct
SDFileSet
SDFileSet
;
typedef
struct
SDataFWriter
SDataFWriter
;
...
...
@@ -219,7 +219,7 @@ bool tsdbDelFileIsSame(SDelFile *pDelFile1, SDelFile *pDelFile2);
int32_t
tsdbDFileRollback
(
STsdb
*
pTsdb
,
SDFileSet
*
pSet
,
EDataFileT
ftype
);
int32_t
tPutHeadFile
(
uint8_t
*
p
,
SHeadFile
*
pHeadFile
);
int32_t
tPutDataFile
(
uint8_t
*
p
,
SDataFile
*
pDataFile
);
int32_t
tPut
LastFile
(
uint8_t
*
p
,
SLastFile
*
pLa
stFile
);
int32_t
tPut
SstFile
(
uint8_t
*
p
,
SSstFile
*
pS
stFile
);
int32_t
tPutSmaFile
(
uint8_t
*
p
,
SSmaFile
*
pSmaFile
);
int32_t
tPutDelFile
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
int32_t
tGetDelFile
(
uint8_t
*
p
,
SDelFile
*
pDelFile
);
...
...
@@ -228,7 +228,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet);
void
tsdbHeadFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SHeadFile
*
pHeadF
,
char
fname
[]);
void
tsdbDataFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SDataFile
*
pDataF
,
char
fname
[]);
void
tsdb
LastFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SLastFile
*
pLa
stF
,
char
fname
[]);
void
tsdb
SstFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SSstFile
*
pS
stF
,
char
fname
[]);
void
tsdbSmaFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SSmaFile
*
pSmaF
,
char
fname
[]);
// SDelFile
void
tsdbDelFileName
(
STsdb
*
pTsdb
,
SDelFile
*
pFile
,
char
fname
[]);
...
...
@@ -541,7 +541,7 @@ struct SDataFile {
int64_t
size
;
};
struct
S
La
stFile
{
struct
S
S
stFile
{
volatile
int32_t
nRef
;
int64_t
commitID
;
...
...
@@ -562,8 +562,8 @@ struct SDFileSet {
SHeadFile
*
pHeadF
;
SDataFile
*
pDataF
;
SSmaFile
*
pSmaF
;
uint8_t
n
La
stF
;
S
LastFile
*
aLa
stF
[
TSDB_MAX_LAST_FILE
];
uint8_t
n
S
stF
;
S
SstFile
*
aS
stF
[
TSDB_MAX_LAST_FILE
];
};
struct
SRowIter
{
...
...
@@ -598,7 +598,7 @@ struct SDataFWriter {
SHeadFile
fHead
;
SDataFile
fData
;
SSmaFile
fSma
;
S
LastFile
fLa
st
[
TSDB_MAX_LAST_FILE
];
S
SstFile
fS
st
[
TSDB_MAX_LAST_FILE
];
uint8_t
*
aBuf
[
4
];
};
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
1132a7f7
...
...
@@ -431,9 +431,9 @@ static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) {
pCommitter
->
toLastOnly
=
0
;
SDataFReader
*
pReader
=
pCommitter
->
dReader
.
pReader
;
if
(
pReader
)
{
if
(
pReader
->
pSet
->
n
La
stF
>=
pCommitter
->
maxLast
)
{
if
(
pReader
->
pSet
->
n
S
stF
>=
pCommitter
->
maxLast
)
{
int8_t
iIter
=
0
;
for
(
int32_t
iLast
=
0
;
iLast
<
pReader
->
pSet
->
n
La
stF
;
iLast
++
)
{
for
(
int32_t
iLast
=
0
;
iLast
<
pReader
->
pSet
->
n
S
stF
;
iLast
++
)
{
pIter
=
&
pCommitter
->
aDataIter
[
iIter
];
pIter
->
type
=
LAST_DATA_ITER
;
pIter
->
iLast
=
iLast
;
...
...
@@ -457,9 +457,9 @@ static int32_t tsdbOpenCommitIter(SCommitter *pCommitter) {
iIter
++
;
}
}
else
{
for
(
int32_t
iLast
=
0
;
iLast
<
pReader
->
pSet
->
n
La
stF
;
iLast
++
)
{
S
LastFile
*
pLastFile
=
pReader
->
pSet
->
aLa
stF
[
iLast
];
if
(
p
LastFile
->
size
>
pLa
stFile
->
offset
)
{
for
(
int32_t
iLast
=
0
;
iLast
<
pReader
->
pSet
->
n
S
stF
;
iLast
++
)
{
S
SstFile
*
pSstFile
=
pReader
->
pSet
->
aS
stF
[
iLast
];
if
(
p
SstFile
->
size
>
pS
stFile
->
offset
)
{
pCommitter
->
toLastOnly
=
1
;
break
;
}
...
...
@@ -515,29 +515,29 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) {
SHeadFile
fHead
=
{.
commitID
=
pCommitter
->
commitID
};
SDataFile
fData
=
{.
commitID
=
pCommitter
->
commitID
};
SSmaFile
fSma
=
{.
commitID
=
pCommitter
->
commitID
};
S
LastFile
fLa
st
=
{.
commitID
=
pCommitter
->
commitID
};
S
SstFile
fS
st
=
{.
commitID
=
pCommitter
->
commitID
};
SDFileSet
wSet
=
{.
fid
=
pCommitter
->
commitFid
,
.
pHeadF
=
&
fHead
,
.
pDataF
=
&
fData
,
.
pSmaF
=
&
fSma
};
if
(
pRSet
)
{
ASSERT
(
pRSet
->
n
La
stF
<=
pCommitter
->
maxLast
);
ASSERT
(
pRSet
->
n
S
stF
<=
pCommitter
->
maxLast
);
fData
=
*
pRSet
->
pDataF
;
fSma
=
*
pRSet
->
pSmaF
;
wSet
.
diskId
=
pRSet
->
diskId
;
if
(
pRSet
->
n
La
stF
<
pCommitter
->
maxLast
)
{
for
(
int32_t
iLast
=
0
;
iLast
<
pRSet
->
n
La
stF
;
iLast
++
)
{
wSet
.
a
LastF
[
iLast
]
=
pRSet
->
aLa
stF
[
iLast
];
if
(
pRSet
->
n
S
stF
<
pCommitter
->
maxLast
)
{
for
(
int32_t
iLast
=
0
;
iLast
<
pRSet
->
n
S
stF
;
iLast
++
)
{
wSet
.
a
SstF
[
iLast
]
=
pRSet
->
aS
stF
[
iLast
];
}
wSet
.
n
LastF
=
pRSet
->
nLa
stF
+
1
;
wSet
.
n
SstF
=
pRSet
->
nS
stF
+
1
;
}
else
{
wSet
.
n
La
stF
=
1
;
wSet
.
n
S
stF
=
1
;
}
}
else
{
SDiskID
did
=
{
0
};
tfsAllocDisk
(
pTsdb
->
pVnode
->
pTfs
,
0
,
&
did
);
tfsMkdirRecurAt
(
pTsdb
->
pVnode
->
pTfs
,
pTsdb
->
path
,
did
);
wSet
.
diskId
=
did
;
wSet
.
n
La
stF
=
1
;
wSet
.
n
S
stF
=
1
;
}
wSet
.
a
LastF
[
wSet
.
nLastF
-
1
]
=
&
fLa
st
;
wSet
.
a
SstF
[
wSet
.
nSstF
-
1
]
=
&
fS
st
;
code
=
tsdbDataFWriterOpen
(
&
pCommitter
->
dWriter
.
pWriter
,
pTsdb
,
&
wSet
);
if
(
code
)
goto
_err
;
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
1132a7f7
...
...
@@ -255,8 +255,8 @@ void tsdbFSDestroy(STsdbFS *pFS) {
taosMemoryFree
(
pSet
->
pHeadF
);
taosMemoryFree
(
pSet
->
pDataF
);
taosMemoryFree
(
pSet
->
pSmaF
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
taosMemoryFree
(
pSet
->
a
La
stF
[
iLast
]);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
taosMemoryFree
(
pSet
->
a
S
stF
[
iLast
]);
}
}
...
...
@@ -312,12 +312,12 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
}
// last ===========
tsdb
LastFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aLa
stF
[
0
],
fname
);
tsdb
SstFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aS
stF
[
0
],
fname
);
if
(
taosStatFile
(
fname
,
&
size
,
NULL
))
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
if
(
size
!=
pSet
->
a
La
stF
[
0
]
->
size
)
{
if
(
size
!=
pSet
->
a
S
stF
[
0
]
->
size
)
{
code
=
TSDB_CODE_FILE_CORRUPTED
;
goto
_err
;
}
...
...
@@ -509,8 +509,8 @@ int32_t tsdbFSClose(STsdb *pTsdb) {
taosMemoryFree
(
pSet
->
pDataF
);
// last
ASSERT
(
pSet
->
a
La
stF
[
0
]
->
nRef
==
1
);
taosMemoryFree
(
pSet
->
a
La
stF
[
0
]);
ASSERT
(
pSet
->
a
S
stF
[
0
]
->
nRef
==
1
);
taosMemoryFree
(
pSet
->
a
S
stF
[
0
]);
// sma
ASSERT
(
pSet
->
pSmaF
->
nRef
==
1
);
...
...
@@ -571,13 +571,13 @@ int32_t tsdbFSCopy(STsdb *pTsdb, STsdbFS *pFS) {
*
fSet
.
pSmaF
=
*
pSet
->
pSmaF
;
// last
for
(
fSet
.
n
LastF
=
0
;
fSet
.
nLastF
<
pSet
->
nLastF
;
fSet
.
nLa
stF
++
)
{
fSet
.
a
LastF
[
fSet
.
nLastF
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
fSet
.
a
LastF
[
fSet
.
nLa
stF
]
==
NULL
)
{
for
(
fSet
.
n
SstF
=
0
;
fSet
.
nSstF
<
pSet
->
nSstF
;
fSet
.
nS
stF
++
)
{
fSet
.
a
SstF
[
fSet
.
nSstF
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
fSet
.
a
SstF
[
fSet
.
nS
stF
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
*
fSet
.
a
LastF
[
fSet
.
nLastF
]
=
*
pSet
->
aLastF
[
fSet
.
nLa
stF
];
*
fSet
.
a
SstF
[
fSet
.
nSstF
]
=
*
pSet
->
aSstF
[
fSet
.
nS
stF
];
}
if
(
taosArrayPush
(
pFS
->
aDFileSet
,
&
fSet
)
==
NULL
)
{
...
...
@@ -631,27 +631,27 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
*
pDFileSet
->
pDataF
=
*
pSet
->
pDataF
;
*
pDFileSet
->
pSmaF
=
*
pSet
->
pSmaF
;
// last
if
(
pSet
->
n
LastF
>
pDFileSet
->
nLa
stF
)
{
ASSERT
(
pSet
->
n
LastF
==
pDFileSet
->
nLa
stF
+
1
);
if
(
pSet
->
n
SstF
>
pDFileSet
->
nS
stF
)
{
ASSERT
(
pSet
->
n
SstF
==
pDFileSet
->
nS
stF
+
1
);
pDFileSet
->
a
LastF
[
pDFileSet
->
nLastF
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
pDFileSet
->
a
LastF
[
pDFileSet
->
nLa
stF
]
==
NULL
)
{
pDFileSet
->
a
SstF
[
pDFileSet
->
nSstF
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
pDFileSet
->
a
SstF
[
pDFileSet
->
nS
stF
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
*
pDFileSet
->
a
LastF
[
pDFileSet
->
nLastF
]
=
*
pSet
->
aLastF
[
pSet
->
nLa
stF
-
1
];
pDFileSet
->
n
La
stF
++
;
}
else
if
(
pSet
->
n
LastF
<
pDFileSet
->
nLa
stF
)
{
ASSERT
(
pSet
->
n
La
stF
==
1
);
for
(
int32_t
iLast
=
1
;
iLast
<
pDFileSet
->
n
La
stF
;
iLast
++
)
{
taosMemoryFree
(
pDFileSet
->
a
La
stF
[
iLast
]);
*
pDFileSet
->
a
SstF
[
pDFileSet
->
nSstF
]
=
*
pSet
->
aSstF
[
pSet
->
nS
stF
-
1
];
pDFileSet
->
n
S
stF
++
;
}
else
if
(
pSet
->
n
SstF
<
pDFileSet
->
nS
stF
)
{
ASSERT
(
pSet
->
n
S
stF
==
1
);
for
(
int32_t
iLast
=
1
;
iLast
<
pDFileSet
->
n
S
stF
;
iLast
++
)
{
taosMemoryFree
(
pDFileSet
->
a
S
stF
[
iLast
]);
}
*
pDFileSet
->
a
LastF
[
0
]
=
*
pSet
->
aLa
stF
[
0
];
pDFileSet
->
n
La
stF
=
1
;
*
pDFileSet
->
a
SstF
[
0
]
=
*
pSet
->
aS
stF
[
0
];
pDFileSet
->
n
S
stF
=
1
;
}
else
{
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
*
pDFileSet
->
a
LastF
[
iLast
]
=
*
pSet
->
aLa
stF
[
iLast
];
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
*
pDFileSet
->
a
SstF
[
iLast
]
=
*
pSet
->
aS
stF
[
iLast
];
}
}
...
...
@@ -659,8 +659,8 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
}
}
ASSERT
(
pSet
->
n
La
stF
==
1
);
SDFileSet
fSet
=
{.
diskId
=
pSet
->
diskId
,
.
fid
=
pSet
->
fid
,
.
n
La
stF
=
1
};
ASSERT
(
pSet
->
n
S
stF
==
1
);
SDFileSet
fSet
=
{.
diskId
=
pSet
->
diskId
,
.
fid
=
pSet
->
fid
,
.
n
S
stF
=
1
};
// head
fSet
.
pHeadF
=
(
SHeadFile
*
)
taosMemoryMalloc
(
sizeof
(
SHeadFile
));
...
...
@@ -687,12 +687,12 @@ int32_t tsdbFSUpsertFSet(STsdbFS *pFS, SDFileSet *pSet) {
*
fSet
.
pSmaF
=
*
pSet
->
pSmaF
;
// last
fSet
.
a
LastF
[
0
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
fSet
.
a
La
stF
[
0
]
==
NULL
)
{
fSet
.
a
SstF
[
0
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
fSet
.
a
S
stF
[
0
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
*
fSet
.
a
LastF
[
0
]
=
*
pSet
->
aLa
stF
[
0
];
*
fSet
.
a
SstF
[
0
]
=
*
pSet
->
aS
stF
[
0
];
if
(
taosArrayInsert
(
pFS
->
aDFileSet
,
idx
,
&
fSet
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -862,74 +862,74 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
// last
if
(
sameDisk
)
{
if
(
pSetNew
->
n
LastF
>
pSetOld
->
nLa
stF
)
{
ASSERT
(
pSetNew
->
n
LastF
=
pSetOld
->
nLa
stF
+
1
);
pSetOld
->
a
LastF
[
pSetOld
->
nLastF
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
pSetOld
->
a
LastF
[
pSetOld
->
nLa
stF
]
==
NULL
)
{
if
(
pSetNew
->
n
SstF
>
pSetOld
->
nS
stF
)
{
ASSERT
(
pSetNew
->
n
SstF
=
pSetOld
->
nS
stF
+
1
);
pSetOld
->
a
SstF
[
pSetOld
->
nSstF
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
pSetOld
->
a
SstF
[
pSetOld
->
nS
stF
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
*
pSetOld
->
a
LastF
[
pSetOld
->
nLastF
]
=
*
pSetNew
->
aLastF
[
pSetOld
->
nLa
stF
];
pSetOld
->
a
LastF
[
pSetOld
->
nLa
stF
]
->
nRef
=
1
;
pSetOld
->
n
La
stF
++
;
}
else
if
(
pSetNew
->
n
LastF
<
pSetOld
->
nLa
stF
)
{
ASSERT
(
pSetNew
->
n
La
stF
==
1
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSetOld
->
n
La
stF
;
iLast
++
)
{
S
LastFile
*
pLastFile
=
pSetOld
->
aLa
stF
[
iLast
];
nRef
=
atomic_sub_fetch_32
(
&
p
La
stFile
->
nRef
,
1
);
*
pSetOld
->
a
SstF
[
pSetOld
->
nSstF
]
=
*
pSetNew
->
aSstF
[
pSetOld
->
nS
stF
];
pSetOld
->
a
SstF
[
pSetOld
->
nS
stF
]
->
nRef
=
1
;
pSetOld
->
n
S
stF
++
;
}
else
if
(
pSetNew
->
n
SstF
<
pSetOld
->
nS
stF
)
{
ASSERT
(
pSetNew
->
n
S
stF
==
1
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSetOld
->
n
S
stF
;
iLast
++
)
{
S
SstFile
*
pSstFile
=
pSetOld
->
aS
stF
[
iLast
];
nRef
=
atomic_sub_fetch_32
(
&
p
S
stFile
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdb
LastFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pLa
stFile
,
fname
);
tsdb
SstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pS
stFile
,
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
p
La
stFile
);
taosMemoryFree
(
p
S
stFile
);
}
pSetOld
->
a
La
stF
[
iLast
]
=
NULL
;
pSetOld
->
a
S
stF
[
iLast
]
=
NULL
;
}
pSetOld
->
n
La
stF
=
1
;
pSetOld
->
a
LastF
[
0
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
pSetOld
->
a
La
stF
[
0
]
==
NULL
)
{
pSetOld
->
n
S
stF
=
1
;
pSetOld
->
a
SstF
[
0
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
pSetOld
->
a
S
stF
[
0
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
*
pSetOld
->
a
LastF
[
0
]
=
*
pSetNew
->
aLa
stF
[
0
];
pSetOld
->
a
La
stF
[
0
]
->
nRef
=
1
;
*
pSetOld
->
a
SstF
[
0
]
=
*
pSetNew
->
aS
stF
[
0
];
pSetOld
->
a
S
stF
[
0
]
->
nRef
=
1
;
}
else
{
for
(
int32_t
iLast
=
0
;
iLast
<
pSetOld
->
n
La
stF
;
iLast
++
)
{
S
LastFile
*
pLastFile
=
pSetOld
->
aLa
stF
[
iLast
];
nRef
=
atomic_sub_fetch_32
(
&
p
La
stFile
->
nRef
,
1
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSetOld
->
n
S
stF
;
iLast
++
)
{
S
SstFile
*
pSstFile
=
pSetOld
->
aS
stF
[
iLast
];
nRef
=
atomic_sub_fetch_32
(
&
p
S
stFile
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdb
LastFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pLa
stFile
,
fname
);
tsdb
SstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pS
stFile
,
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
p
La
stFile
);
taosMemoryFree
(
p
S
stFile
);
}
pSetOld
->
a
LastF
[
iLast
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
pSetOld
->
a
La
stF
[
iLast
]
==
NULL
)
{
pSetOld
->
a
SstF
[
iLast
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
pSetOld
->
a
S
stF
[
iLast
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
*
pSetOld
->
a
LastF
[
iLast
]
=
*
pSetNew
->
aLa
stF
[
iLast
];
pSetOld
->
a
La
stF
[
iLast
]
->
nRef
=
1
;
*
pSetOld
->
a
SstF
[
iLast
]
=
*
pSetNew
->
aS
stF
[
iLast
];
pSetOld
->
a
S
stF
[
iLast
]
->
nRef
=
1
;
}
}
}
else
{
ASSERT
(
pSetOld
->
n
LastF
==
pSetNew
->
nLa
stF
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSetOld
->
n
La
stF
;
iLast
++
)
{
S
LastFile
*
pLastFile
=
pSetOld
->
aLa
stF
[
iLast
];
nRef
=
atomic_sub_fetch_32
(
&
p
La
stFile
->
nRef
,
1
);
ASSERT
(
pSetOld
->
n
SstF
==
pSetNew
->
nS
stF
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSetOld
->
n
S
stF
;
iLast
++
)
{
S
SstFile
*
pSstFile
=
pSetOld
->
aS
stF
[
iLast
];
nRef
=
atomic_sub_fetch_32
(
&
p
S
stFile
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdb
LastFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pLa
stFile
,
fname
);
tsdb
SstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pS
stFile
,
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
p
La
stFile
);
taosMemoryFree
(
p
S
stFile
);
}
pSetOld
->
a
LastF
[
iLast
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
pSetOld
->
a
La
stF
[
iLast
]
==
NULL
)
{
pSetOld
->
a
SstF
[
iLast
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
pSetOld
->
a
S
stF
[
iLast
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
*
pSetOld
->
a
LastF
[
iLast
]
=
*
pSetNew
->
aLa
stF
[
iLast
];
pSetOld
->
a
La
stF
[
iLast
]
->
nRef
=
1
;
*
pSetOld
->
a
SstF
[
iLast
]
=
*
pSetNew
->
aS
stF
[
iLast
];
pSetOld
->
a
S
stF
[
iLast
]
->
nRef
=
1
;
}
}
...
...
@@ -963,12 +963,12 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
taosMemoryFree
(
pSetOld
->
pSmaF
);
}
for
(
int8_t
iLast
=
0
;
iLast
<
pSetOld
->
n
La
stF
;
iLast
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSetOld
->
a
La
stF
[
iLast
]
->
nRef
,
1
);
for
(
int8_t
iLast
=
0
;
iLast
<
pSetOld
->
n
S
stF
;
iLast
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSetOld
->
a
S
stF
[
iLast
]
->
nRef
,
1
);
if
(
nRef
==
0
)
{
tsdb
LastFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pSetOld
->
aLa
stF
[
iLast
],
fname
);
tsdb
SstFileName
(
pTsdb
,
pSetOld
->
diskId
,
pSetOld
->
fid
,
pSetOld
->
aS
stF
[
iLast
],
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
pSetOld
->
a
La
stF
[
iLast
]);
taosMemoryFree
(
pSetOld
->
a
S
stF
[
iLast
]);
}
}
...
...
@@ -976,7 +976,7 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
continue
;
_add_new:
fSet
=
(
SDFileSet
){.
diskId
=
pSetNew
->
diskId
,
.
fid
=
pSetNew
->
fid
,
.
n
La
stF
=
1
};
fSet
=
(
SDFileSet
){.
diskId
=
pSetNew
->
diskId
,
.
fid
=
pSetNew
->
fid
,
.
n
S
stF
=
1
};
// head
fSet
.
pHeadF
=
(
SHeadFile
*
)
taosMemoryMalloc
(
sizeof
(
SHeadFile
));
...
...
@@ -1006,14 +1006,14 @@ int32_t tsdbFSCommit2(STsdb *pTsdb, STsdbFS *pFSNew) {
fSet
.
pSmaF
->
nRef
=
1
;
// last
ASSERT
(
pSetNew
->
n
La
stF
==
1
);
fSet
.
a
LastF
[
0
]
=
(
SLastFile
*
)
taosMemoryMalloc
(
sizeof
(
SLa
stFile
));
if
(
fSet
.
a
La
stF
[
0
]
==
NULL
)
{
ASSERT
(
pSetNew
->
n
S
stF
==
1
);
fSet
.
a
SstF
[
0
]
=
(
SSstFile
*
)
taosMemoryMalloc
(
sizeof
(
SS
stFile
));
if
(
fSet
.
a
S
stF
[
0
]
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
*
fSet
.
a
LastF
[
0
]
=
*
pSetNew
->
aLa
stF
[
0
];
fSet
.
a
La
stF
[
0
]
->
nRef
=
1
;
*
fSet
.
a
SstF
[
0
]
=
*
pSetNew
->
aS
stF
[
0
];
fSet
.
a
S
stF
[
0
]
->
nRef
=
1
;
if
(
taosArrayInsert
(
pTsdb
->
fs
.
aDFileSet
,
iOld
,
&
fSet
)
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -1061,8 +1061,8 @@ int32_t tsdbFSRef(STsdb *pTsdb, STsdbFS *pFS) {
nRef
=
atomic_fetch_add_32
(
&
pSet
->
pSmaF
->
nRef
,
1
);
ASSERT
(
nRef
>
0
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
nRef
=
atomic_fetch_add_32
(
&
pSet
->
a
La
stF
[
iLast
]
->
nRef
,
1
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
nRef
=
atomic_fetch_add_32
(
&
pSet
->
a
S
stF
[
iLast
]
->
nRef
,
1
);
ASSERT
(
nRef
>
0
);
}
...
...
@@ -1121,13 +1121,13 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) {
}
// last
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSet
->
a
La
stF
[
iLast
]
->
nRef
,
1
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
nRef
=
atomic_sub_fetch_32
(
&
pSet
->
a
S
stF
[
iLast
]
->
nRef
,
1
);
ASSERT
(
nRef
>=
0
);
if
(
nRef
==
0
)
{
tsdb
LastFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aLa
stF
[
iLast
],
fname
);
tsdb
SstFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aS
stF
[
iLast
],
fname
);
taosRemoveFile
(
fname
);
taosMemoryFree
(
pSet
->
a
La
stF
[
iLast
]);
taosMemoryFree
(
pSet
->
a
S
stF
[
iLast
]);
/* code */
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
1132a7f7
...
...
@@ -53,22 +53,22 @@ static int32_t tGetDataFile(uint8_t *p, SDataFile *pDataFile) {
return
n
;
}
int32_t
tPut
LastFile
(
uint8_t
*
p
,
SLastFile
*
pLa
stFile
)
{
int32_t
tPut
SstFile
(
uint8_t
*
p
,
SSstFile
*
pS
stFile
)
{
int32_t
n
=
0
;
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
La
stFile
->
commitID
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
La
stFile
->
size
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
La
stFile
->
offset
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
S
stFile
->
commitID
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
S
stFile
->
size
);
n
+=
tPutI64v
(
p
?
p
+
n
:
p
,
p
S
stFile
->
offset
);
return
n
;
}
static
int32_t
tGet
LastFile
(
uint8_t
*
p
,
SLastFile
*
pLa
stFile
)
{
static
int32_t
tGet
SstFile
(
uint8_t
*
p
,
SSstFile
*
pS
stFile
)
{
int32_t
n
=
0
;
n
+=
tGetI64v
(
p
+
n
,
&
p
La
stFile
->
commitID
);
n
+=
tGetI64v
(
p
+
n
,
&
p
La
stFile
->
size
);
n
+=
tGetI64v
(
p
+
n
,
&
p
La
stFile
->
offset
);
n
+=
tGetI64v
(
p
+
n
,
&
p
S
stFile
->
commitID
);
n
+=
tGetI64v
(
p
+
n
,
&
p
S
stFile
->
size
);
n
+=
tGetI64v
(
p
+
n
,
&
p
S
stFile
->
offset
);
return
n
;
}
...
...
@@ -102,9 +102,9 @@ void tsdbDataFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SDataFile *pDataF,
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
fid
,
pDataF
->
commitID
,
".data"
);
}
void
tsdb
LastFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SLastFile
*
pLa
stF
,
char
fname
[])
{
void
tsdb
SstFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SSstFile
*
pS
stF
,
char
fname
[])
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
-
1
,
"%s%s%s%sv%df%dver%"
PRId64
"%s"
,
tfsGetDiskPath
(
pTsdb
->
pVnode
->
pTfs
,
did
),
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
fid
,
p
LastF
->
commitID
,
".la
st"
);
TD_DIRSEP
,
pTsdb
->
path
,
TD_DIRSEP
,
TD_VID
(
pTsdb
->
pVnode
),
fid
,
p
SstF
->
commitID
,
".s
st"
);
}
void
tsdbSmaFileName
(
STsdb
*
pTsdb
,
SDiskID
did
,
int32_t
fid
,
SSmaFile
*
pSmaF
,
char
fname
[])
{
...
...
@@ -195,9 +195,9 @@ int32_t tPutDFileSet(uint8_t *p, SDFileSet *pSet) {
n
+=
tPutSmaFile
(
p
?
p
+
n
:
p
,
pSet
->
pSmaF
);
// last
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
pSet
->
n
La
stF
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
n
+=
tPut
LastFile
(
p
?
p
+
n
:
p
,
pSet
->
aLa
stF
[
iLast
]);
n
+=
tPutU8
(
p
?
p
+
n
:
p
,
pSet
->
n
S
stF
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
n
+=
tPut
SstFile
(
p
?
p
+
n
:
p
,
pSet
->
aS
stF
[
iLast
]);
}
return
n
;
...
...
@@ -235,14 +235,14 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) {
n
+=
tGetSmaFile
(
p
+
n
,
pSet
->
pSmaF
);
// last
n
+=
tGetU8
(
p
+
n
,
&
pSet
->
n
La
stF
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
pSet
->
a
LastF
[
iLast
]
=
(
SLastFile
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SLa
stFile
));
if
(
pSet
->
a
La
stF
[
iLast
]
==
NULL
)
{
n
+=
tGetU8
(
p
+
n
,
&
pSet
->
n
S
stF
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
pSet
->
a
SstF
[
iLast
]
=
(
SSstFile
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SS
stFile
));
if
(
pSet
->
a
S
stF
[
iLast
]
==
NULL
)
{
return
-
1
;
}
pSet
->
a
La
stF
[
iLast
]
->
nRef
=
1
;
n
+=
tGet
LastFile
(
p
+
n
,
pSet
->
aLa
stF
[
iLast
]);
pSet
->
a
S
stF
[
iLast
]
->
nRef
=
1
;
n
+=
tGet
SstFile
(
p
+
n
,
pSet
->
aS
stF
[
iLast
]);
}
return
n
;
...
...
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
浏览文件 @
1132a7f7
...
...
@@ -99,12 +99,12 @@ void tLDataIterClose(SLDataIter *pIter) {
extern
int32_t
tsdbReadLastBlockEx
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SBlockL
*
pBlockL
,
SBlockData
*
pBlockData
);
void
tLDataIterNextBlock
(
SLDataIter
*
pIter
)
{
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
pIter
->
iBlockL
+=
step
;
int32_t
index
=
-
1
;
size_t
size
=
taosArrayGetSize
(
pIter
->
aBlockL
);
for
(
int32_t
i
=
pIter
->
iBlockL
;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
size_t
size
=
taosArrayGetSize
(
pIter
->
aBlockL
);
for
(
int32_t
i
=
pIter
->
iBlockL
;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
SBlockL
*
p
=
taosArrayGet
(
pIter
->
aBlockL
,
i
);
if
((
!
pIter
->
backward
)
&&
p
->
minUid
>
pIter
->
uid
)
{
break
;
...
...
@@ -122,15 +122,15 @@ void tLDataIterNextBlock(SLDataIter *pIter) {
if
(
index
==
-
1
)
{
pIter
->
pBlockL
=
NULL
;
}
else
{
}
else
{
pIter
->
pBlockL
=
(
SBlockL
*
)
taosArrayGet
(
pIter
->
aBlockL
,
pIter
->
iBlockL
);
}
}
static
void
findNextValidRow
(
SLDataIter
*
pIter
)
{
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
static
void
findNextValidRow
(
SLDataIter
*
pIter
)
{
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
bool
hasVal
=
false
;
bool
hasVal
=
false
;
int32_t
i
=
pIter
->
iRow
;
for
(;
i
<
pIter
->
bData
.
nRow
&&
i
>=
0
;
i
+=
step
)
{
if
(
pIter
->
bData
.
aUid
!=
NULL
)
{
...
...
@@ -150,7 +150,7 @@ static void findNextValidRow(SLDataIter* pIter) {
}
int64_t
ts
=
pIter
->
bData
.
aTSKEY
[
i
];
if
(
!
pIter
->
backward
)
{
// asc
if
(
!
pIter
->
backward
)
{
// asc
if
(
ts
>
pIter
->
timeWindow
.
ekey
)
{
// no more data
break
;
}
else
if
(
ts
<
pIter
->
timeWindow
.
skey
)
{
...
...
@@ -186,12 +186,12 @@ static void findNextValidRow(SLDataIter* pIter) {
break
;
}
pIter
->
iRow
=
(
hasVal
)
?
i
:
-
1
;
pIter
->
iRow
=
(
hasVal
)
?
i
:
-
1
;
}
bool
tLDataIterNextRow
(
SLDataIter
*
pIter
)
{
int32_t
code
=
0
;
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
// no qualified last file block in current file, no need to fetch row
if
(
pIter
->
pBlockL
==
NULL
)
{
...
...
@@ -206,12 +206,12 @@ bool tLDataIterNextRow(SLDataIter *pIter) {
goto
_exit
;
}
pIter
->
iRow
=
(
pIter
->
backward
)
?
pIter
->
bData
.
nRow
:
-
1
;
pIter
->
iRow
=
(
pIter
->
backward
)
?
pIter
->
bData
.
nRow
:
-
1
;
}
pIter
->
iRow
+=
step
;
while
(
1
)
{
while
(
1
)
{
findNextValidRow
(
pIter
);
if
(
pIter
->
iRow
>=
pIter
->
bData
.
nRow
||
pIter
->
iRow
<
0
)
{
...
...
@@ -237,16 +237,14 @@ bool tLDataIterNextRow(SLDataIter *pIter) {
pIter
->
rInfo
.
row
=
tsdbRowFromBlockData
(
&
pIter
->
bData
,
pIter
->
iRow
);
_exit:
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
}
return
(
code
==
TSDB_CODE_SUCCESS
)
&&
(
pIter
->
pBlockL
!=
NULL
);
}
SRowInfo
*
tLDataIterGet
(
SLDataIter
*
pIter
)
{
return
&
pIter
->
rInfo
;
}
SRowInfo
*
tLDataIterGet
(
SLDataIter
*
pIter
)
{
return
&
pIter
->
rInfo
;
}
// SMergeTree =================================================
static
FORCE_INLINE
int32_t
tLDataIterCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
...
...
@@ -271,16 +269,17 @@ static FORCE_INLINE int32_t tLDataIterCmprFn(const void *p1, const void *p2) {
}
}
void
tMergeTreeOpen
(
SMergeTree
*
pMTree
,
int8_t
backward
,
SDataFReader
*
pFReader
,
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
)
{
void
tMergeTreeOpen
(
SMergeTree
*
pMTree
,
int8_t
backward
,
SDataFReader
*
pFReader
,
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
)
{
pMTree
->
backward
=
backward
;
pMTree
->
pIter
=
NULL
;
pMTree
->
pIterList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
tRBTreeCreate
(
&
pMTree
->
rbt
,
tLDataIterCmprFn
);
struct
SLDataIter
*
pIterList
[
TSDB_DEFAULT_LAST_FILE
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pFReader
->
pSet
->
nLastF
;
++
i
)
{
// open all last file
/*int32_t code = */
tLDataIterOpen
(
&
pIterList
[
i
],
pFReader
,
i
,
pMTree
->
backward
,
uid
,
pTimeWindow
,
pVerRange
);
struct
SLDataIter
*
pIterList
[
TSDB_DEFAULT_LAST_FILE
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pFReader
->
pSet
->
nSstF
;
++
i
)
{
// open all last file
/*int32_t code = */
tLDataIterOpen
(
&
pIterList
[
i
],
pFReader
,
i
,
pMTree
->
backward
,
uid
,
pTimeWindow
,
pVerRange
);
bool
hasVal
=
tLDataIterNextRow
(
pIterList
[
i
]);
if
(
hasVal
)
{
taosArrayPush
(
pMTree
->
pIterList
,
&
pIterList
[
i
]);
...
...
@@ -293,7 +292,7 @@ void tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader* pFReader,
void
tMergeTreeAddIter
(
SMergeTree
*
pMTree
,
SLDataIter
*
pIter
)
{
tRBTreePut
(
&
pMTree
->
rbt
,
(
SRBTreeNode
*
)
pIter
);
}
bool
tMergeTreeNext
(
SMergeTree
*
pMTree
)
{
bool
tMergeTreeNext
(
SMergeTree
*
pMTree
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
pMTree
->
pIter
)
{
SLDataIter
*
pIter
=
pMTree
->
pIter
;
...
...
@@ -326,14 +325,12 @@ bool tMergeTreeNext(SMergeTree* pMTree) {
return
pMTree
->
pIter
!=
NULL
;
}
TSDBROW
tMergeTreeGetRow
(
SMergeTree
*
pMTree
)
{
return
pMTree
->
pIter
->
rInfo
.
row
;
}
TSDBROW
tMergeTreeGetRow
(
SMergeTree
*
pMTree
)
{
return
pMTree
->
pIter
->
rInfo
.
row
;
}
void
tMergeTreeClose
(
SMergeTree
*
pMTree
)
{
void
tMergeTreeClose
(
SMergeTree
*
pMTree
)
{
size_t
size
=
taosArrayGetSize
(
pMTree
->
pIterList
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SLDataIter
*
pIter
=
taosArrayGetP
(
pMTree
->
pIterList
,
i
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SLDataIter
*
pIter
=
taosArrayGetP
(
pMTree
->
pIterList
,
i
);
tLDataIterClose
(
pIter
);
}
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
1132a7f7
...
...
@@ -176,10 +176,10 @@ static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pR
static
void
setComposedBlockFlag
(
STsdbReader
*
pReader
,
bool
composed
);
static
bool
hasBeenDropped
(
const
SArray
*
pDelList
,
int32_t
*
index
,
TSDBKEY
*
pKey
,
int32_t
order
);
static
int32_t
doMergeMemTableMultiRows
(
TSDBROW
*
pRow
,
uint64_t
uid
,
SIterInfo
*
pIter
,
SArray
*
pDelList
,
STSRow
**
pTSRow
,
STsdbReader
*
pReader
,
bool
*
freeTSRow
);
static
int32_t
doMergeMemIMemRows
(
TSDBROW
*
pRow
,
TSDBROW
*
piRow
,
STableBlockScanInfo
*
pBlockScanInfo
,
STsdbReader
*
pReader
,
STSRow
**
pTSRow
);
static
int32_t
doMergeMemTableMultiRows
(
TSDBROW
*
pRow
,
uint64_t
uid
,
SIterInfo
*
pIter
,
SArray
*
pDelList
,
STSRow
**
pTSRow
,
STsdbReader
*
pReader
,
bool
*
freeTSRow
);
static
int32_t
doMergeMemIMemRows
(
TSDBROW
*
pRow
,
TSDBROW
*
piRow
,
STableBlockScanInfo
*
pBlockScanInfo
,
STsdbReader
*
pReader
,
STSRow
**
pTSRow
);
static
int32_t
mergeRowsInFileBlocks
(
SBlockData
*
pBlockData
,
STableBlockScanInfo
*
pBlockScanInfo
,
int64_t
key
,
STsdbReader
*
pReader
);
...
...
@@ -617,7 +617,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
}
}
pBlockNum
->
numOfLastFiles
=
pReader
->
pFileReader
->
pSet
->
n
La
stF
;
pBlockNum
->
numOfLastFiles
=
pReader
->
pFileReader
->
pSet
->
n
S
stF
;
int32_t
total
=
pBlockNum
->
numOfLastFiles
+
pBlockNum
->
numOfBlocks
;
double
el
=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
...
...
@@ -1374,7 +1374,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
static
int32_t
doMergeFileBlockAndLastBlock
(
SLastBlockReader
*
pLastBlockReader
,
STsdbReader
*
pReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
SBlockData
*
pBlockData
,
bool
mergeBlockData
)
{
int64_t
tsLastBlock
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
int64_t
tsLastBlock
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
STSRow
*
pTSRow
=
NULL
;
SRowMerger
merge
=
{
0
};
...
...
@@ -1860,9 +1860,7 @@ static int64_t getCurrentKeyInLastBlock(SLastBlockReader* pLastBlockReader) {
return
key
.
ts
;
}
static
bool
hasDataInLastBlock
(
SLastBlockReader
*
pLastBlockReader
)
{
return
pLastBlockReader
->
mergeTree
.
pIter
!=
NULL
;
}
static
bool
hasDataInLastBlock
(
SLastBlockReader
*
pLastBlockReader
)
{
return
pLastBlockReader
->
mergeTree
.
pIter
!=
NULL
;
}
int32_t
mergeRowsInFileBlocks
(
SBlockData
*
pBlockData
,
STableBlockScanInfo
*
pBlockScanInfo
,
int64_t
key
,
STsdbReader
*
pReader
)
{
...
...
@@ -1958,7 +1956,6 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
}
}
bool
hasBlockLData
=
hasDataInLastBlock
(
pLastBlockReader
);
// no data in last block and block, no need to proceed.
...
...
@@ -2185,7 +2182,7 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum) {
return
code
;
}
if
(
taosArrayGetSize
(
pIndexList
)
>
0
||
pReader
->
pFileReader
->
pSet
->
n
La
stF
>
0
)
{
if
(
taosArrayGetSize
(
pIndexList
)
>
0
||
pReader
->
pFileReader
->
pSet
->
n
S
stF
>
0
)
{
code
=
doLoadFileBlock
(
pReader
,
pIndexList
,
pBlockNum
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosArrayDestroy
(
pIndexList
);
...
...
@@ -2296,7 +2293,7 @@ static int32_t doLoadLastBlockSequentially(STsdbReader* pReader) {
while
(
1
)
{
// load the last data block of current table
STableBlockScanInfo
*
pScanInfo
=
pStatus
->
pTableIter
;
bool
hasVal
=
initLastBlockReader
(
pLastBlockReader
,
pScanInfo
->
uid
,
pReader
->
pFileReader
);
bool
hasVal
=
initLastBlockReader
(
pLastBlockReader
,
pScanInfo
->
uid
,
pReader
->
pFileReader
);
if
(
!
hasVal
)
{
bool
hasNexTable
=
moveToNextTable
(
pOrderedCheckInfo
,
pStatus
);
if
(
!
hasNexTable
)
{
...
...
@@ -2946,7 +2943,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
}
int32_t
doMergeMemIMemRows
(
TSDBROW
*
pRow
,
TSDBROW
*
piRow
,
STableBlockScanInfo
*
pBlockScanInfo
,
STsdbReader
*
pReader
,
STSRow
**
pTSRow
)
{
STSRow
**
pTSRow
)
{
SRowMerger
merge
=
{
0
};
TSDBKEY
k
=
TSDBROW_KEY
(
pRow
);
...
...
@@ -3020,7 +3017,8 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR
}
if
(
pBlockScanInfo
->
iter
.
hasVal
&&
pRow
!=
NULL
)
{
return
doMergeMemTableMultiRows
(
pRow
,
pBlockScanInfo
->
uid
,
&
pBlockScanInfo
->
iter
,
pDelList
,
pTSRow
,
pReader
,
freeTSRow
);
return
doMergeMemTableMultiRows
(
pRow
,
pBlockScanInfo
->
uid
,
&
pBlockScanInfo
->
iter
,
pDelList
,
pTSRow
,
pReader
,
freeTSRow
);
}
if
(
pBlockScanInfo
->
iiter
.
hasVal
&&
piRow
!=
NULL
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbReaderWriter.c
浏览文件 @
1132a7f7
...
...
@@ -434,8 +434,8 @@ int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pS
}
// last
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
tsdb
LastFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aLa
stF
[
iLast
],
fname
);
for
(
int32_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
tsdb
SstFileName
(
pTsdb
,
pSet
->
diskId
,
pSet
->
fid
,
pSet
->
aS
stF
[
iLast
],
fname
);
pReader
->
aLastFD
[
iLast
]
=
taosOpenFile
(
fname
,
TD_FILE_READ
);
if
(
pReader
->
aLastFD
[
iLast
]
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -475,7 +475,7 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) {
}
// last
for
(
int32_t
iLast
=
0
;
iLast
<
(
*
ppReader
)
->
pSet
->
n
La
stF
;
iLast
++
)
{
for
(
int32_t
iLast
=
0
;
iLast
<
(
*
ppReader
)
->
pSet
->
n
S
stF
;
iLast
++
)
{
if
(
taosCloseFile
(
&
(
*
ppReader
)
->
aLastFD
[
iLast
])
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
...
...
@@ -561,8 +561,8 @@ _err:
int32_t
tsdbReadBlockL
(
SDataFReader
*
pReader
,
int32_t
iLast
,
SArray
*
aBlockL
)
{
int32_t
code
=
0
;
int64_t
offset
=
pReader
->
pSet
->
a
La
stF
[
iLast
]
->
offset
;
int64_t
size
=
pReader
->
pSet
->
a
La
stF
[
iLast
]
->
size
-
offset
;
int64_t
offset
=
pReader
->
pSet
->
a
S
stF
[
iLast
]
->
offset
;
int64_t
size
=
pReader
->
pSet
->
a
S
stF
[
iLast
]
->
size
-
offset
;
int64_t
n
;
uint32_t
delimiter
;
...
...
@@ -947,14 +947,14 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
.
pHeadF
=
&
pWriter
->
fHead
,
.
pDataF
=
&
pWriter
->
fData
,
.
pSmaF
=
&
pWriter
->
fSma
,
.
n
LastF
=
pSet
->
nLa
stF
//
.
n
SstF
=
pSet
->
nS
stF
//
};
pWriter
->
fHead
=
*
pSet
->
pHeadF
;
pWriter
->
fData
=
*
pSet
->
pDataF
;
pWriter
->
fSma
=
*
pSet
->
pSmaF
;
for
(
int8_t
iLast
=
0
;
iLast
<
pSet
->
n
La
stF
;
iLast
++
)
{
pWriter
->
wSet
.
a
LastF
[
iLast
]
=
&
pWriter
->
fLa
st
[
iLast
];
pWriter
->
f
Last
[
iLast
]
=
*
pSet
->
aLa
stF
[
iLast
];
for
(
int8_t
iLast
=
0
;
iLast
<
pSet
->
n
S
stF
;
iLast
++
)
{
pWriter
->
wSet
.
a
SstF
[
iLast
]
=
&
pWriter
->
fS
st
[
iLast
];
pWriter
->
f
Sst
[
iLast
]
=
*
pSet
->
aS
stF
[
iLast
];
}
// head
...
...
@@ -1037,9 +1037,9 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
}
// last
ASSERT
(
pWriter
->
f
Last
[
pSet
->
nLa
stF
-
1
].
size
==
0
);
ASSERT
(
pWriter
->
f
Sst
[
pSet
->
nS
stF
-
1
].
size
==
0
);
flag
=
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
;
tsdb
LastFileName
(
pTsdb
,
pWriter
->
wSet
.
diskId
,
pWriter
->
wSet
.
fid
,
&
pWriter
->
fLast
[
pSet
->
nLa
stF
-
1
],
fname
);
tsdb
SstFileName
(
pTsdb
,
pWriter
->
wSet
.
diskId
,
pWriter
->
wSet
.
fid
,
&
pWriter
->
fSst
[
pSet
->
nS
stF
-
1
],
fname
);
pWriter
->
pLastFD
=
taosOpenFile
(
fname
,
flag
);
if
(
pWriter
->
pLastFD
==
NULL
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
@@ -1050,7 +1050,7 @@ int32_t tsdbDataFWriterOpen(SDataFWriter **ppWriter, STsdb *pTsdb, SDFileSet *pS
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
pWriter
->
f
Last
[
pWriter
->
wSet
.
nLa
stF
-
1
].
size
+=
TSDB_FHDR_SIZE
;
pWriter
->
f
Sst
[
pWriter
->
wSet
.
nS
stF
-
1
].
size
+=
TSDB_FHDR_SIZE
;
*
ppWriter
=
pWriter
;
return
code
;
...
...
@@ -1181,7 +1181,7 @@ int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter) {
// last ==============
memset
(
hdr
,
0
,
TSDB_FHDR_SIZE
);
tPut
LastFile
(
hdr
,
&
pWriter
->
fLast
[
pWriter
->
wSet
.
nLa
stF
-
1
]);
tPut
SstFile
(
hdr
,
&
pWriter
->
fSst
[
pWriter
->
wSet
.
nS
stF
-
1
]);
taosCalcChecksumAppend
(
0
,
hdr
,
TSDB_FHDR_SIZE
);
n
=
taosLSeekFile
(
pWriter
->
pLastFD
,
0
,
SEEK_SET
);
...
...
@@ -1302,14 +1302,14 @@ _err:
}
int32_t
tsdbWriteBlockL
(
SDataFWriter
*
pWriter
,
SArray
*
aBlockL
)
{
int32_t
code
=
0
;
S
LastFile
*
pLastFile
=
&
pWriter
->
fLast
[
pWriter
->
wSet
.
nLa
stF
-
1
];
int64_t
size
;
int64_t
n
;
int32_t
code
=
0
;
S
SstFile
*
pSstFile
=
&
pWriter
->
fSst
[
pWriter
->
wSet
.
nS
stF
-
1
];
int64_t
size
;
int64_t
n
;
// check
if
(
taosArrayGetSize
(
aBlockL
)
==
0
)
{
p
LastFile
->
offset
=
pLa
stFile
->
size
;
p
SstFile
->
offset
=
pS
stFile
->
size
;
goto
_exit
;
}
...
...
@@ -1342,12 +1342,12 @@ int32_t tsdbWriteBlockL(SDataFWriter *pWriter, SArray *aBlockL) {
}
// update
p
LastFile
->
offset
=
pLa
stFile
->
size
;
p
La
stFile
->
size
+=
size
;
p
SstFile
->
offset
=
pS
stFile
->
size
;
p
S
stFile
->
size
+=
size
;
_exit:
tsdbTrace
(
"vgId:%d tsdb write blockl, loffset:%"
PRId64
" size:%"
PRId64
,
TD_VID
(
pWriter
->
pTsdb
->
pVnode
),
p
La
stFile
->
offset
,
size
);
p
S
stFile
->
offset
,
size
);
return
code
;
_err:
...
...
@@ -1431,7 +1431,7 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlock
ASSERT
(
pBlockData
->
nRow
>
0
);
pBlkInfo
->
offset
=
toLast
?
pWriter
->
f
Last
[
pWriter
->
wSet
.
nLa
stF
-
1
].
size
:
pWriter
->
fData
.
size
;
pBlkInfo
->
offset
=
toLast
?
pWriter
->
f
Sst
[
pWriter
->
wSet
.
nS
stF
-
1
].
size
:
pWriter
->
fData
.
size
;
pBlkInfo
->
szBlock
=
0
;
pBlkInfo
->
szKey
=
0
;
...
...
@@ -1475,7 +1475,7 @@ int32_t tsdbWriteBlockData(SDataFWriter *pWriter, SBlockData *pBlockData, SBlock
// update info
if
(
toLast
)
{
pWriter
->
f
Last
[
pWriter
->
wSet
.
nLa
stF
-
1
].
size
+=
pBlkInfo
->
szBlock
;
pWriter
->
f
Sst
[
pWriter
->
wSet
.
nS
stF
-
1
].
size
+=
pBlkInfo
->
szBlock
;
}
else
{
pWriter
->
fData
.
size
+=
pBlkInfo
->
szBlock
;
}
...
...
@@ -1555,8 +1555,8 @@ int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo) {
taosCloseFile
(
&
PInFD
);
// last
tsdb
LastFileName
(
pTsdb
,
pSetFrom
->
diskId
,
pSetFrom
->
fid
,
pSetFrom
->
aLa
stF
[
0
],
fNameFrom
);
tsdb
LastFileName
(
pTsdb
,
pSetTo
->
diskId
,
pSetTo
->
fid
,
pSetTo
->
aLa
stF
[
0
],
fNameTo
);
tsdb
SstFileName
(
pTsdb
,
pSetFrom
->
diskId
,
pSetFrom
->
fid
,
pSetFrom
->
aS
stF
[
0
],
fNameFrom
);
tsdb
SstFileName
(
pTsdb
,
pSetTo
->
diskId
,
pSetTo
->
fid
,
pSetTo
->
aS
stF
[
0
],
fNameTo
);
pOutFD
=
taosOpenFile
(
fNameTo
,
TD_FILE_WRITE
|
TD_FILE_CREATE
|
TD_FILE_TRUNC
);
if
(
pOutFD
==
NULL
)
{
...
...
@@ -1570,7 +1570,7 @@ int32_t tsdbDFileSetCopy(STsdb *pTsdb, SDFileSet *pSetFrom, SDFileSet *pSetTo) {
goto
_err
;
}
n
=
taosFSendFile
(
pOutFD
,
PInFD
,
0
,
pSetFrom
->
a
La
stF
[
0
]
->
size
);
n
=
taosFSendFile
(
pOutFD
,
PInFD
,
0
,
pSetFrom
->
a
S
stF
[
0
]
->
size
);
if
(
n
<
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
...
...
source/dnode/vnode/src/tsdb/tsdbRetention.c
浏览文件 @
1132a7f7
...
...
@@ -60,7 +60,7 @@ int32_t tsdbDoRetention(STsdb *pTsdb, int64_t now) {
if
(
expLevel
<
0
)
{
taosMemoryFree
(
pSet
->
pHeadF
);
taosMemoryFree
(
pSet
->
pDataF
);
taosMemoryFree
(
pSet
->
a
La
stF
[
0
]);
taosMemoryFree
(
pSet
->
a
S
stF
[
0
]);
taosMemoryFree
(
pSet
->
pSmaF
);
taosArrayRemove
(
fs
.
aDFileSet
,
iSet
);
iSet
--
;
...
...
source/dnode/vnode/src/tsdb/tsdbSnapshot.c
浏览文件 @
1132a7f7
...
...
@@ -931,25 +931,25 @@ static int32_t tsdbSnapWriteData(STsdbSnapWriter* pWriter, uint8_t* pData, uint3
// write
SHeadFile
fHead
;
SDataFile
fData
;
S
LastFile
fLast
;
S
SstFile
fLast
;
SSmaFile
fSma
;
SDFileSet
wSet
=
{.
pHeadF
=
&
fHead
,
.
pDataF
=
&
fData
,
.
a
La
stF
[
0
]
=
&
fLast
,
.
pSmaF
=
&
fSma
};
SDFileSet
wSet
=
{.
pHeadF
=
&
fHead
,
.
pDataF
=
&
fData
,
.
a
S
stF
[
0
]
=
&
fLast
,
.
pSmaF
=
&
fSma
};
if
(
pSet
)
{
wSet
.
diskId
=
pSet
->
diskId
;
wSet
.
fid
=
fid
;
wSet
.
n
La
stF
=
1
;
wSet
.
n
S
stF
=
1
;
fHead
=
(
SHeadFile
){.
commitID
=
pWriter
->
commitID
,
.
offset
=
0
,
.
size
=
0
};
fData
=
*
pSet
->
pDataF
;
fLast
=
(
S
La
stFile
){.
commitID
=
pWriter
->
commitID
,
.
size
=
0
};
fLast
=
(
S
S
stFile
){.
commitID
=
pWriter
->
commitID
,
.
size
=
0
};
fSma
=
*
pSet
->
pSmaF
;
}
else
{
wSet
.
diskId
=
(
SDiskID
){.
level
=
0
,
.
id
=
0
};
wSet
.
fid
=
fid
;
wSet
.
n
La
stF
=
1
;
wSet
.
n
S
stF
=
1
;
fHead
=
(
SHeadFile
){.
commitID
=
pWriter
->
commitID
,
.
offset
=
0
,
.
size
=
0
};
fData
=
(
SDataFile
){.
commitID
=
pWriter
->
commitID
,
.
size
=
0
};
fLast
=
(
S
La
stFile
){.
commitID
=
pWriter
->
commitID
,
.
size
=
0
,
.
offset
=
0
};
fLast
=
(
S
S
stFile
){.
commitID
=
pWriter
->
commitID
,
.
size
=
0
,
.
offset
=
0
};
fSma
=
(
SSmaFile
){.
commitID
=
pWriter
->
commitID
,
.
size
=
0
};
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录