Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1a139a07
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
提交
1a139a07
编写于
6月 15, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-353
上级
f09d73cf
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
155 addition
and
123 deletion
+155
-123
src/inc/taoserror.h
src/inc/taoserror.h
+1
-0
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+4
-2
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+0
-5
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+0
-31
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+142
-85
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+8
-0
未找到文件。
src/inc/taoserror.h
浏览文件 @
1a139a07
...
@@ -191,6 +191,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE, 0, 0x060B, "tsdb times
...
@@ -191,6 +191,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE, 0, 0x060B, "tsdb times
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP
,
0
,
0x060C
,
"tsdb submit message is messed up"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP
,
0
,
0x060C
,
"tsdb submit message is messed up"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_ACTION
,
0
,
0x060D
,
"tsdb invalid action"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_ACTION
,
0
,
0x060D
,
"tsdb invalid action"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_CREATE_TB_MSG
,
0
,
0x060E
,
"tsdb invalid create table message"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_CREATE_TB_MSG
,
0
,
0x060E
,
"tsdb invalid create table message"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM
,
0
,
0x060F
,
"tsdb no table data in memory skiplist"
)
// query
// query
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_INVALID_QHANDLE
,
0
,
0x0700
,
"query invalid handle"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_INVALID_QHANDLE
,
0
,
0x0700
,
"query invalid handle"
)
...
...
src/tsdb/inc/tsdbMain.h
浏览文件 @
1a139a07
...
@@ -295,6 +295,8 @@ int tsdbUpdateTable(STsdbMeta* pMeta, STable* pTable, STableCfg* pCfg);
...
@@ -295,6 +295,8 @@ int tsdbUpdateTable(STsdbMeta* pMeta, STable* pTable, STableCfg* pCfg);
int
tsdbWLockRepoMeta
(
STsdbRepo
*
pRepo
);
int
tsdbWLockRepoMeta
(
STsdbRepo
*
pRepo
);
int
tsdbRLockRepoMeta
(
STsdbRepo
*
pRepo
);
int
tsdbRLockRepoMeta
(
STsdbRepo
*
pRepo
);
int
tsdbUnlockRepoMeta
(
STsdbRepo
*
pRepo
);
int
tsdbUnlockRepoMeta
(
STsdbRepo
*
pRepo
);
void
tsdbRefTable
(
STable
*
pTable
);
void
tsdbUnRefTable
(
STable
*
pTable
);
// ------------------ tsdbBuffer.c
// ------------------ tsdbBuffer.c
STsdbBufPool
*
tsdbNewBufPool
();
STsdbBufPool
*
tsdbNewBufPool
();
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
1a139a07
...
@@ -325,11 +325,6 @@ int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, SFile *pFile)
...
@@ -325,11 +325,6 @@ int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, SFile *pFile)
return
0
;
return
0
;
}
}
void
tsdbGetKeyRangeOfFileId
(
int32_t
daysPerFile
,
int8_t
precision
,
int32_t
fileId
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
)
{
*
minKey
=
fileId
*
daysPerFile
*
tsMsPerDay
[
precision
];
*
maxKey
=
*
minKey
+
daysPerFile
*
tsMsPerDay
[
precision
]
-
1
;
}
SFileGroup
*
tsdbSearchFGroup
(
STsdbFileH
*
pFileH
,
int
fid
)
{
SFileGroup
*
tsdbSearchFGroup
(
STsdbFileH
*
pFileH
,
int
fid
)
{
if
(
pFileH
->
numOfFGroups
==
0
||
fid
<
pFileH
->
fGroup
[
0
].
fileId
||
fid
>
pFileH
->
fGroup
[
pFileH
->
numOfFGroups
-
1
].
fileId
)
if
(
pFileH
->
numOfFGroups
==
0
||
fid
<
pFileH
->
fGroup
[
0
].
fileId
||
fid
>
pFileH
->
fGroup
[
pFileH
->
numOfFGroups
-
1
].
fileId
)
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
1a139a07
...
@@ -844,35 +844,4 @@ TSKEY tsdbGetTableLastKey(TSDB_REPO_T *repo, uint64_t uid) {
...
@@ -844,35 +844,4 @@ TSKEY tsdbGetTableLastKey(TSDB_REPO_T *repo, uint64_t uid) {
return TSDB_GET_TABLE_LAST_KEY(pTable);
return TSDB_GET_TABLE_LAST_KEY(pTable);
}
}
/**
* Return the next iterator key.
*
* @return the next key if iter has
* -1 if iter not
*/
static TSKEY tsdbNextIterKey(SSkipListIterator *pIter) {
if (pIter == NULL) return -1;
SSkipListNode *node = tSkipListIterGet(pIter);
if (node == NULL) return -1;
SDataRow row = SL_GET_NODE_DATA(node);
return dataRowKey(row);
}
static int tsdbHasDataToCommit(SSkipListIterator **iters, int nIters, TSKEY minKey, TSKEY maxKey) {
TSKEY nextKey;
for (int i = 0; i < nIters; i++) {
SSkipListIterator *pIter = iters[i];
nextKey = tsdbNextIterKey(pIter);
if (nextKey > 0 && (nextKey >= minKey && nextKey <= maxKey)) return 1;
}
return 0;
}
#endif
#endif
\ No newline at end of file
src/tsdb/src/tsdbMemTable.c
浏览文件 @
1a139a07
...
@@ -18,6 +18,11 @@
...
@@ -18,6 +18,11 @@
#define TSDB_DATA_SKIPLIST_LEVEL 5
#define TSDB_DATA_SKIPLIST_LEVEL 5
typedef
struct
{
STable
*
pTable
;
SSkipListIterator
*
pIter
;
}
SCommitIter
;
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
);
static
FORCE_INLINE
STsdbBufBlock
*
tsdbGetCurrBufBlock
(
STsdbRepo
*
pRepo
);
static
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
);
static
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
);
...
@@ -337,9 +342,12 @@ static void tsdbFreeTableData(STableData *pTableData) {
...
@@ -337,9 +342,12 @@ static void tsdbFreeTableData(STableData *pTableData) {
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
)
{
return
dataRowTuple
(
data
);
}
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
)
{
return
dataRowTuple
(
data
);
}
static
void
*
tsdbCommitData
(
void
*
arg
)
{
static
void
*
tsdbCommitData
(
void
*
arg
)
{
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
arg
;
STsdbRepo
*
pRepo
=
(
STsdbRepo
*
)
arg
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
SMemTable
*
pMem
=
pRepo
->
imem
;
SMemTable
*
pMem
=
pRepo
->
imem
;
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
SDataCols
*
pDataCols
=
NULL
;
SCommitIter
*
iters
=
NULL
;
ASSERT
(
pRepo
->
commit
==
1
);
ASSERT
(
pRepo
->
commit
==
1
);
ASSERT
(
pMem
!=
NULL
);
ASSERT
(
pMem
!=
NULL
);
...
@@ -347,69 +355,84 @@ static void *tsdbCommitData(void *arg) {
...
@@ -347,69 +355,84 @@ static void *tsdbCommitData(void *arg) {
pMem
->
keyFirst
,
pMem
->
keyLast
,
pMem
->
numOfRows
);
pMem
->
keyFirst
,
pMem
->
keyLast
,
pMem
->
numOfRows
);
// Create the iterator to read from cache
// Create the iterator to read from cache
SSkipListIterator
**
iters
=
tsdbCreateTableIters
(
pRepo
);
iters
=
tsdbCreateTableIters
(
pRepo
);
if
(
iters
==
NULL
)
{
if
(
iters
==
NULL
)
{
tsdbError
(
"vgId:%d failed to create table iterators since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to create commit iterator since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
// TODO: deal with the error here
goto
_exit
;
return
NULL
;
}
}
if
(
tsdbInitWriteHelper
(
&
whelper
,
pRepo
)
<
0
)
{
if
(
tsdbInitWriteHelper
(
&
whelper
,
pRepo
)
<
0
)
{
tsdbError
(
"vgId:%d failed to init write helper since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to init write helper since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
));
// TODO
goto
_exit
;
goto
_exit
;
}
}
if
((
pDataCols
=
tdNewDataCols
(
pMe
ta
->
maxRowBytes
,
pMeta
->
maxCols
,
pCfg
->
maxRowsPerFileBlock
))
==
NULL
)
{
if
((
pDataCols
=
tdNewDataCols
(
pMe
m
->
maxRowBytes
,
pMem
->
maxCols
,
pCfg
->
maxRowsPerFileBlock
))
==
NULL
)
{
t
sdbError
(
"vgId:%d failed to init data cols with maxRowBytes %d maxCols %d since %s"
,
REPO_ID
(
pRepo
),
t
errno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
pMeta
->
maxRowBytes
,
pMeta
->
maxCols
,
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to init data cols with maxRowBytes %d maxCols %d maxRowsPerFileBlock %d since %s"
,
// TODO
REPO_ID
(
pRepo
),
pMeta
->
maxRowBytes
,
pMeta
->
maxCols
,
pCfg
->
maxRowsPerFileBlock
,
tstrerror
(
terrno
));
goto
_exit
;
goto
_exit
;
}
}
int
sfid
=
tsdbGetKeyFileId
(
pCache
->
im
em
->
keyFirst
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
sfid
=
TSDB_KEY_FILEID
(
pM
em
->
keyFirst
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
efid
=
tsdbGetKeyFileId
(
pCache
->
im
em
->
keyLast
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int
efid
=
TSDB_KEY_FILEID
(
pM
em
->
keyLast
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
// Loop to commit to each file
// Loop to commit to each file
for
(
int
fid
=
sfid
;
fid
<=
efid
;
fid
++
)
{
for
(
int
fid
=
sfid
;
fid
<=
efid
;
fid
++
)
{
if
(
tsdbCommitToFile
(
pRepo
,
fid
,
iters
,
&
whelper
,
pDataCols
)
<
0
)
{
if
(
tsdbCommitToFile
(
pRepo
,
fid
,
iters
,
&
whelper
,
pDataCols
)
<
0
)
{
ASSERT
(
false
);
tsdbError
(
"vgId:%d failed to commit to file %d since %s"
,
REPO_ID
(
pRepo
),
fid
,
tstrerror
(
terrno
)
);
goto
_exit
;
goto
_exit
;
}
}
}
}
// Do retention actions
//
TODO:
Do retention actions
tsdbFitRetention
(
pRepo
);
tsdbFitRetention
(
pRepo
);
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_OVER
);
// TODO: Commit action meta data
_exit:
_exit:
tdFreeDataCols
(
pDataCols
);
tdFreeDataCols
(
pDataCols
);
tsdbDestroyTableIters
(
iters
,
pCfg
->
maxTables
);
tsdbDestroyTableIters
(
iters
,
pCfg
->
maxTables
);
tsdbDestroyHelper
(
&
whelper
);
tsdbDestroyHelper
(
&
whelper
);
tsdbEndCommit
(
pRepo
);
tsdbPrint
(
"vgId:%d commit over"
,
pRepo
->
config
.
tsdbId
);
return
NULL
;
}
tsdbLockRepo
(
arg
);
static
void
tsdbEndCommit
(
STsdbRepo
*
pRepo
)
{
tdListMove
(
pCache
->
imem
->
list
,
pCache
->
pool
.
memPool
);
ASSERT
(
pRepo
->
commit
==
1
);
tsdbAdjustCacheBlocks
(
pCache
);
tsdbLockRepo
(
pRepo
);
tdListFree
(
pCache
->
imem
->
list
);
free
(
pCache
->
imem
);
pCache
->
imem
=
NULL
;
pRepo
->
commit
=
0
;
pRepo
->
commit
=
0
;
for
(
int
i
=
1
;
i
<
pCfg
->
maxTables
;
i
++
)
{
tsdbUnlockRepo
(
pRepo
);
STable
*
pTable
=
pMeta
->
tables
[
i
];
if
(
pRepo
->
appH
.
notifyStatus
)
pRepo
->
appH
.
notifyStatus
(
pRepo
->
appH
.
appH
,
TSDB_STATUS_COMMIT_OVER
);
if
(
pTable
&&
pTable
->
imem
)
{
}
tsdbFreeMemTable
(
pTable
->
imem
);
pTable
->
imem
=
NULL
;
static
TSKEY
tsdbNextIterKey
(
SCommitIter
*
pIter
)
{
}
if
(
pIter
==
NULL
)
return
-
1
;
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
->
pIter
);
if
(
node
==
NULL
)
return
-
1
;
SDataRow
row
=
SL_GET_NODE_DATA
(
node
);
return
dataRowKey
(
row
);
}
static
int
tsdbHasDataToCommit
(
SCommitIter
*
iters
,
int
nIters
,
TSKEY
minKey
,
TSKEY
maxKey
)
{
for
(
int
i
=
0
;
i
<
nIters
;
i
++
)
{
TSKEY
nextKey
=
tsdbNextIterKey
(
iters
+
i
);
if
(
nextKey
>
0
&&
(
nextKey
>=
minKey
&&
nextKey
<=
maxKey
))
return
1
;
}
}
tsdbUnLockRepo
(
arg
)
;
return
0
;
tsdbPrint
(
"vgId:%d, commit over...."
,
pRepo
->
config
.
tsdbId
);
}
return
NULL
;
static
void
tsdbGetKeyRangeOfFileId
(
int32_t
daysPerFile
,
int8_t
precision
,
int32_t
fileId
,
TSKEY
*
minKey
,
TSKEY
*
maxKey
)
{
*
minKey
=
fileId
*
daysPerFile
*
tsMsPerDay
[
precision
];
*
maxKey
=
*
minKey
+
daysPerFile
*
tsMsPerDay
[
precision
]
-
1
;
}
}
static
int
tsdbCommitToFile
(
STsdbRepo
*
pRepo
,
int
fid
,
SSkipListIterator
**
iters
,
SRWHelper
*
pHelper
,
static
int
tsdbCommitToFile
(
STsdbRepo
*
pRepo
,
int
fid
,
SCommitIter
*
iters
,
SRWHelper
*
pHelper
,
SDataCols
*
pDataCols
)
{
SDataCols
*
pDataCols
)
{
char
*
dataDir
=
NULL
;
char
dataDir
[
128
]
=
{
0
};
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
...
@@ -420,38 +443,46 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
...
@@ -420,38 +443,46 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
// Check if there are data to commit to this file
// Check if there are data to commit to this file
int
hasDataToCommit
=
tsdbHasDataToCommit
(
iters
,
pCfg
->
maxTables
,
minKey
,
maxKey
);
int
hasDataToCommit
=
tsdbHasDataToCommit
(
iters
,
pCfg
->
maxTables
,
minKey
,
maxKey
);
if
(
!
hasDataToCommit
)
return
0
;
// No data to commit, just return
if
(
!
hasDataToCommit
)
{
tsdbTrace
(
"vgId:%d no data to commit to file %d"
,
REPO_ID
(
pRepo
),
fid
);
return
0
;
}
// Create and open files for commit
// Create and open files for commit
tsdbGetDataDirName
(
pRepo
,
dataDir
);
dataDir
=
tsdbGetDataDirName
(
pRepo
->
rootDir
);
if
(
dataDir
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
if
((
pGroup
=
tsdbCreateFGroup
(
pFileH
,
dataDir
,
fid
,
pCfg
->
maxTables
))
==
NULL
)
{
if
((
pGroup
=
tsdbCreateFGroup
(
pFileH
,
dataDir
,
fid
,
pCfg
->
maxTables
))
==
NULL
)
{
tsdbError
(
"vgId:%d
, failed to create file group %d"
,
pRepo
->
config
.
tsdbId
,
fid
);
tsdbError
(
"vgId:%d
failed to create file group %d since %s"
,
REPO_ID
(
pRepo
),
fid
,
tstrerror
(
terrno
)
);
goto
_err
;
goto
_err
;
}
}
free
(
dataDir
);
// Open files for write/read
// Open files for write/read
if
(
tsdbSetAndOpenHelperFile
(
pHelper
,
pGroup
)
<
0
)
{
if
(
tsdbSetAndOpenHelperFile
(
pHelper
,
pGroup
)
<
0
)
{
tsdbError
(
"vgId:%d
, failed to set helper file"
,
pRepo
->
config
.
tsdbId
);
tsdbError
(
"vgId:%d
failed to set helper file since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
)
);
goto
_err
;
goto
_err
;
}
}
// Loop to commit data in each table
// Loop to commit data in each table
for
(
int
tid
=
1
;
tid
<
pCfg
->
maxTables
;
tid
++
)
{
for
(
int
tid
=
1
;
tid
<
pCfg
->
maxTables
;
tid
++
)
{
STable
*
pTable
=
pMeta
->
tables
[
tid
];
SCommitIter
*
pIter
=
iters
+
tid
;
if
(
pTable
==
NULL
)
continue
;
if
(
pIter
->
pTable
==
NULL
)
continue
;
SSkipListIterator
*
pIter
=
iters
[
tid
];
// Set the helper and the buffer dataCols object to help to write this table
tsdbSetHelperTable
(
pHelper
,
pTable
,
pRepo
);
tsdbSetHelperTable
(
pHelper
,
pTable
,
pRepo
);
tdInitDataCols
(
pDataCols
,
tsdbGetTableSchema
(
pMeta
,
pTable
));
// Loop to write the data in the cache to files. If no data to write, just break the loop
if
(
pIter
->
pIter
!=
NULL
)
{
tdInitDataCols
(
pDataCols
,
tsdbGetTableSchema
(
pIter
->
pTable
));
int
maxRowsToRead
=
pCfg
->
maxRowsPerFileBlock
*
4
/
5
;
int
maxRowsToRead
=
pCfg
->
maxRowsPerFileBlock
*
4
/
5
;
int
nLoop
=
0
;
int
nLoop
=
0
;
while
(
true
)
{
while
(
true
)
{
int
rowsRead
=
tsdbReadRowsFromCache
(
pMeta
,
pTable
,
pIter
,
maxKey
,
maxRowsToRead
,
pDataCols
);
int
rowsRead
=
tsdbReadRowsFromCache
(
pMeta
,
pIter
->
pTable
,
pIter
->
pIter
,
maxKey
,
maxRowsToRead
,
pDataCols
);
assert
(
rowsRead
>=
0
);
ASSERT
(
rowsRead
>=
0
);
if
(
pDataCols
->
numOfRows
==
0
)
break
;
if
(
pDataCols
->
numOfRows
==
0
)
break
;
nLoop
++
;
nLoop
++
;
...
@@ -460,7 +491,12 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
...
@@ -460,7 +491,12 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
int
rowsWritten
=
tsdbWriteDataBlock
(
pHelper
,
pDataCols
);
int
rowsWritten
=
tsdbWriteDataBlock
(
pHelper
,
pDataCols
);
ASSERT
(
rowsWritten
!=
0
);
ASSERT
(
rowsWritten
!=
0
);
if
(
rowsWritten
<
0
)
goto
_err
;
if
(
rowsWritten
<
0
)
{
tsdbError
(
"vgId:%d failed to write data block to table %s tid %d uid %"
PRIu64
" since %s"
,
REPO_ID
(
pRepo
),
TABLE_CHAR_NAME
(
pIter
->
pTable
),
TABLE_TID
(
pIter
->
pTable
),
TABLE_UID
(
pIter
->
pTable
),
tstrerror
(
terrno
));
goto
_err
;
}
ASSERT
(
rowsWritten
<=
pDataCols
->
numOfRows
);
ASSERT
(
rowsWritten
<=
pDataCols
->
numOfRows
);
tdPopDataColsPoints
(
pDataCols
,
rowsWritten
);
tdPopDataColsPoints
(
pDataCols
,
rowsWritten
);
...
@@ -468,22 +504,23 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
...
@@ -468,22 +504,23 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
}
}
ASSERT
(
pDataCols
->
numOfRows
==
0
);
ASSERT
(
pDataCols
->
numOfRows
==
0
);
}
// Move the last block to the new .l file if neccessary
// Move the last block to the new .l file if neccessary
if
(
tsdbMoveLastBlockIfNeccessary
(
pHelper
)
<
0
)
{
if
(
tsdbMoveLastBlockIfNeccessary
(
pHelper
)
<
0
)
{
tsdbError
(
"vgId:%d, failed to move last block
"
,
pRepo
->
config
.
tsdbId
);
tsdbError
(
"vgId:%d, failed to move last block
, since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
)
);
goto
_err
;
goto
_err
;
}
}
// Write the SCompBlock part
// Write the SCompBlock part
if
(
tsdbWriteCompInfo
(
pHelper
)
<
0
)
{
if
(
tsdbWriteCompInfo
(
pHelper
)
<
0
)
{
tsdbError
(
"vgId:%d, failed to write compInfo part
"
,
pRepo
->
config
.
tsdbId
);
tsdbError
(
"vgId:%d, failed to write compInfo part
since %s"
,
REPO_ID
(
pRepo
),
tstrerror
(
terrno
)
);
goto
_err
;
goto
_err
;
}
}
}
}
if
(
tsdbWriteCompIdx
(
pHelper
)
<
0
)
{
if
(
tsdbWriteCompIdx
(
pHelper
)
<
0
)
{
tsdbError
(
"vgId:%d
, failed to write compIdx part"
,
pRepo
->
config
.
tsdbId
);
tsdbError
(
"vgId:%d
failed to write compIdx part to file %d since %s"
,
REPO_ID
(
pRepo
),
fid
,
tstrerror
(
terrno
)
);
goto
_err
;
goto
_err
;
}
}
...
@@ -496,43 +533,63 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
...
@@ -496,43 +533,63 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters
return
0
;
return
0
;
_err:
_err:
ASSERT
(
false
);
//
ASSERT(false);
tsdbCloseHelperFile
(
pHelper
,
1
);
tsdbCloseHelperFile
(
pHelper
,
1
);
return
-
1
;
return
-
1
;
}
}
static
SSkipListIterator
**
tsdbCreateTableIters
(
STsdbRepo
*
pRepo
)
{
static
SCommitIter
*
tsdbCreateTableIters
(
STsdbRepo
*
pRepo
)
{
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
SMemTable
*
pMem
=
pRepo
->
imem
;
STsdbMeta
*
pMeta
=
pRepo
->
tsdbMeta
;
S
SkipListIterator
**
iters
=
(
SSkipListIterator
**
)
calloc
(
pCfg
->
maxTables
,
sizeof
(
SSkipListIterator
*
));
S
CommitIter
*
iters
=
(
SCommitIter
*
)
calloc
(
pCfg
->
maxTables
,
sizeof
(
SCommitIter
));
if
(
iters
==
NULL
)
{
if
(
iters
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
for
(
int
tid
=
1
;
tid
<
maxTables
;
tid
++
)
{
if
(
tsdbRLockRepoMeta
(
pRepo
)
<
0
)
goto
_err
;
STable
*
pTable
=
pMeta
->
tables
[
tid
];
if
(
pTable
==
NULL
||
pTable
->
imem
==
NULL
||
pTable
->
imem
->
numOfRows
==
0
)
continue
;
iters
[
tid
]
=
tSkipListCreateIter
(
pTable
->
imem
->
pData
);
// reference all tables
if
(
iters
[
tid
]
==
NULL
)
goto
_err
;
for
(
int
i
=
0
;
i
<
pCfg
->
maxTables
;
i
++
)
{
if
(
pMeta
->
tables
[
i
]
!=
NULL
)
{
tsdbRefTable
(
pMeta
->
tables
[
i
]);
iters
[
i
].
pTable
=
pMeta
->
tables
[
i
];
}
}
if
(
tsdbUnlockRepoMeta
(
pRepo
)
<
0
)
goto
_err
;
for
(
int
i
=
0
;
i
<
pCfg
->
maxTables
;
i
++
)
{
if
((
iters
[
i
].
pTable
!=
NULL
)
&&
(
pMem
->
tData
[
i
]
!=
NULL
)
&&
(
TALBE_UID
(
iters
[
i
].
pTable
)
==
pMem
->
tData
[
i
]
->
uid
))
{
if
((
iters
[
i
].
pIter
=
tSkipListCreateIter
(
pMem
->
tData
[
i
]
->
pData
))
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
}
if
(
!
tSkipListIterNext
(
iters
[
tid
]))
goto
_err
;
if
(
!
tSkipListIterNext
(
iters
[
i
].
pIter
))
{
terrno
=
TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM
;
goto
_err
;
}
}
}
}
return
iters
;
return
iters
;
_err:
_err:
tsdbDestroyTableIters
(
iters
,
maxTables
);
tsdbDestroyTableIters
(
iters
,
pCfg
->
maxTables
);
return
NULL
;
return
NULL
;
}
}
static
void
tsdbDestroyTableIters
(
S
SkipListIterator
*
*
iters
,
int
maxTables
)
{
static
void
tsdbDestroyTableIters
(
S
CommitIter
*
iters
,
int
maxTables
)
{
if
(
iters
==
NULL
)
return
;
if
(
iters
==
NULL
)
return
;
for
(
int
tid
=
1
;
tid
<
maxTables
;
tid
++
)
{
for
(
int
i
=
1
;
i
<
maxTables
;
i
++
)
{
if
(
iters
[
tid
]
==
NULL
)
continue
;
if
(
iters
[
i
].
pTable
!=
NULL
)
{
tSkipListDestroyIter
(
iters
[
tid
]);
tsdbUnRefTable
(
iters
[
i
].
pTable
);
tSkipListDestroyIter
(
iters
[
i
].
pIter
);
}
}
}
free
(
iters
);
free
(
iters
);
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
1a139a07
...
@@ -516,6 +516,14 @@ int tsdbUnlockRepoMeta(STsdbRepo *pRepo) {
...
@@ -516,6 +516,14 @@ int tsdbUnlockRepoMeta(STsdbRepo *pRepo) {
return
0
;
return
0
;
}
}
void
tsdbRefTable
(
STable
*
pTable
)
{
T_REF_INC
(
pTable
);
}
void
tsdbUnRefTable
(
STable
*
pTable
)
{
if
(
T_REF_DEC
(
pTable
)
==
0
)
{
tsdbFreeTable
(
pTable
);
}
}
// ------------------ LOCAL FUNCTIONS ------------------
// ------------------ LOCAL FUNCTIONS ------------------
static
int
tsdbCompareSchemaVersion
(
const
void
*
key1
,
const
void
*
key2
)
{
static
int
tsdbCompareSchemaVersion
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
int16_t
*
)
key1
<
schemaVersion
(
*
(
STSchema
**
)
key2
))
{
if
(
*
(
int16_t
*
)
key1
<
schemaVersion
(
*
(
STSchema
**
)
key2
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录