Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
ab64511b
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ab64511b
编写于
6月 16, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-353
上级
32dcbfe5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
92 addition
and
97 deletion
+92
-97
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+12
-3
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+80
-94
未找到文件。
src/tsdb/inc/tsdbMain.h
浏览文件 @
ab64511b
...
...
@@ -111,7 +111,13 @@ typedef struct {
}
SMemTable
;
// ------------------ tsdbFile.c
typedef
enum
{
TSDB_FILE_TYPE_HEAD
=
0
,
TSDB_FILE_TYPE_DATA
,
TSDB_FILE_TYPE_LAST
,
TSDB_FILE_TYPE_MAX
}
TSDB_FILE_TYPE
;
typedef
enum
{
TSDB_FILE_TYPE_HEAD
=
0
,
TSDB_FILE_TYPE_DATA
,
TSDB_FILE_TYPE_LAST
,
TSDB_FILE_TYPE_NHEAD
,
TSDB_FILE_TYPE_NLAST
}
TSDB_FILE_TYPE
;
typedef
struct
{
uint32_t
offset
;
...
...
@@ -123,8 +129,9 @@ typedef struct {
}
STsdbFileInfo
;
typedef
struct
{
char
*
fname
;
int
fd
;
char
*
fname
;
int
fd
;
STsdbFileInfo
info
;
}
SFile
;
...
...
@@ -136,6 +143,8 @@ typedef struct {
}
SFileGroup
;
typedef
struct
{
pthread_rwlock_t
fhlock
;
int
maxFGroups
;
int
nFGroups
;
SFileGroup
*
pFGroup
;
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
ab64511b
...
...
@@ -29,13 +29,7 @@
#include "tutil.h"
#include "ttime.h"
const
char
*
tsdbFileSuffix
[]
=
{
".head"
,
".data"
,
".last"
,
".h"
,
".l"
};
const
char
*
tsdbFileSuffix
[]
=
{
".head"
,
".data"
,
".last"
,
".h"
,
".l"
};
// ---------------- INTERNAL FUNCTIONS ----------------
STsdbFileH
*
tsdbNewFileH
(
STsdbCfg
*
pCfg
)
{
...
...
@@ -45,6 +39,13 @@ STsdbFileH *tsdbNewFileH(STsdbCfg *pCfg) {
goto
_err
;
}
int
code
=
pthread_rwlock_init
(
&
(
pFileH
->
fhlock
));
if
(
code
!=
0
)
{
tsdbError
(
"vgId:%d failed to init file handle lock since %s"
,
pCfg
->
tsdbId
,
strerror
(
code
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
goto
_err
;
}
pFileH
->
maxFGroups
=
TSDB_MAX_FILE
(
pCfg
->
keep
,
pCfg
->
daysPerFile
);
pFileH
->
pFGroup
=
(
SFileGroup
*
)
calloc
(
pFileH
->
maxFGroups
,
sizeof
(
SFileGroup
));
...
...
@@ -62,6 +63,7 @@ _err:
void
tsdbFreeFileH
(
STsdbFileH
*
pFileH
)
{
if
(
pFileH
)
{
pthread_rwlock_destroy
(
&
pFileH
->
fhlock
);
tfree
(
pFileH
->
pFGroup
);
free
(
pFileH
);
}
...
...
@@ -74,7 +76,9 @@ int *tsdbOpenFileH(STsdbRepo *pRepo) {
DIR
*
dir
=
NULL
;
int
fid
=
0
;
tsdbGetDataDirName
(
pRepo
->
rootDir
);
STsdbFileH
pFileH
=
pRepo
->
tsdbFileH
;
tDataDir
=
tsdbGetDataDirName
(
pRepo
->
rootDir
);
if
(
tDataDir
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
...
...
@@ -91,9 +95,15 @@ int *tsdbOpenFileH(STsdbRepo *pRepo) {
while
((
dp
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strncmp
(
dp
->
d_name
,
"."
,
1
)
==
0
||
strncmp
(
dp
->
d_name
,
".."
,
2
)
==
0
)
continue
;
sscanf
(
dp
->
d_name
,
"f%d"
,
&
fid
);
// if (tsdbOpenFGroup(pFileH, dataDir, fid) < 0) {
// break;
// }
SFileGroup
fileGroup
=
{
0
};
if
(
tsdbSearchFGroup
(
pFileH
,
fid
,
TD_EQ
)
!=
NULL
)
continue
;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<=
TSDB_FILE_TYPE_LAST
;
type
++
)
{
}
for
(
int
type
=
TSDB_FILE_TYPE_NHEAD
;
type
<=
TSDB_FILE_TYPE_NLAST
;
type
++
)
{
}
}
tfree
(
tDataDir
);
...
...
@@ -106,10 +116,12 @@ _err:
return
-
1
;
}
void
tsdbCloseFileH
(
STsdbFileH
*
pFileH
)
{
if
(
pFileH
)
{
tfree
(
pFileH
->
fGroup
);
free
(
pFileH
);
void
tsdbCloseFileH
(
STsdbRepo
*
pRepo
)
{
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
for
(
int
i
=
0
;
i
<
pFileH
->
nFGroups
;
i
++
)
{
// TODO
}
}
...
...
@@ -146,7 +158,7 @@ _err:
int
tsdbRemoveFileGroup
(
STsdbFileH
*
pFileH
,
int
fid
)
{
SFileGroup
*
pGroup
=
bsearch
((
void
*
)
&
fid
,
(
void
*
)(
pFileH
->
fGroup
),
pFileH
->
numOfFGroups
,
sizeof
(
SFileGroup
),
compFGroupKey
);
bsearch
((
void
*
)
&
fid
,
(
void
*
)(
pFileH
->
fGroup
),
pFileH
->
numOfFGroups
,
sizeof
(
SFileGroup
),
keyFGroupCompFunc
);
if
(
pGroup
==
NULL
)
return
-
1
;
// Remove from disk
...
...
@@ -198,7 +210,7 @@ void tsdbSeekFileGroupIter(SFileGroupIter *pIter, int fid) {
}
int
flags
=
(
pIter
->
direction
==
TSDB_FGROUP_ITER_FORWARD
)
?
TD_GE
:
TD_LE
;
void
*
ptr
=
taosbsearch
(
&
fid
,
pIter
->
base
,
pIter
->
numOfFGroups
,
sizeof
(
SFileGroup
),
compFGroupKey
,
flags
);
void
*
ptr
=
taosbsearch
(
&
fid
,
pIter
->
base
,
pIter
->
numOfFGroups
,
sizeof
(
SFileGroup
),
keyFGroupCompFunc
,
flags
);
if
(
ptr
==
NULL
)
{
pIter
->
pFileGroup
=
NULL
;
}
else
{
...
...
@@ -226,81 +238,38 @@ SFileGroup *tsdbGetFileGroupNext(SFileGroupIter *pIter) {
return
ret
;
}
int
tsdbCopyBlockDataInFile
(
SFile
*
pOutFile
,
SFile
*
pInFile
,
SCompInfo
*
pCompInfo
,
int
idx
,
int
isLast
,
SDataCols
*
pCols
)
{
SCompBlock
*
pSuperBlock
=
TSDB_COMPBLOCK_AT
(
pCompInfo
,
idx
);
SCompBlock
*
pStartBlock
=
NULL
;
SCompBlock
*
pBlock
=
NULL
;
int
numOfBlocks
=
pSuperBlock
->
numOfSubBlocks
;
if
(
numOfBlocks
==
1
)
pStartBlock
=
pSuperBlock
;
else
pStartBlock
=
TSDB_COMPBLOCK_AT
(
pCompInfo
,
pSuperBlock
->
offset
);
int
maxNumOfCols
=
0
;
pBlock
=
pStartBlock
;
for
(
int
i
=
0
;
i
<
numOfBlocks
;
i
++
)
{
if
(
pBlock
->
numOfCols
>
maxNumOfCols
)
maxNumOfCols
=
pBlock
->
numOfCols
;
pBlock
++
;
}
SCompData
*
pCompData
=
(
SCompData
*
)
malloc
(
sizeof
(
SCompData
)
+
sizeof
(
SCompCol
)
*
maxNumOfCols
);
if
(
pCompData
==
NULL
)
return
-
1
;
// Load data from the block
// if (tsdbLoadDataBlock(pOutFile, pStartBlock, numOfBlocks, pCols, pCompData));
// Write data block to the file
{
// TODO
}
char
*
tsdbGetFileName
(
char
*
dataDir
,
int
fileId
,
int
type
)
{
int
tlen
=
strlen
(
dataDir
)
+
strlen
(
tsdbFileSuffix
[
type
])
+
24
;
if
(
pCompData
)
free
(
pCompData
);
return
0
;
}
int
compFGroupKey
(
const
void
*
key
,
const
void
*
fgroup
)
{
int
fid
=
*
(
int
*
)
key
;
SFileGroup
*
pFGroup
=
(
SFileGroup
*
)
fgroup
;
if
(
fid
==
pFGroup
->
fileId
)
{
return
0
;
}
else
{
return
fid
>
pFGroup
->
fileId
?
1
:-
1
;
char
*
fname
=
(
char
*
)
malloc
(
tlen
);
if
(
fname
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
}
int
tsdbGetFileName
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
char
*
fname
)
{
if
(
dataDir
==
NULL
||
fname
==
NULL
)
return
-
1
;
sprintf
(
fname
,
"%s/f%d%s"
,
dataDir
,
fileId
,
suffix
);
sprintf
(
fname
,
"%s/v%df%d%s"
,
dataDir
,
fileId
,
tsdbFileSuffix
[
type
]);
return
0
;
}
int
tsdbOpenFile
(
SFile
*
pFile
,
int
oflag
)
{
// TODO: change the function
if
(
TSDB_IS_FILE_OPENED
(
pFile
))
return
-
1
;
int
tsdbOpenFile
(
SFile
*
pFile
,
int
oflag
)
{
ASSERT
(
!
TSDB_IS_FILE_OPENED
(
pFile
))
;
pFile
->
fd
=
open
(
pFile
->
fname
,
oflag
,
0755
);
if
(
pFile
->
fd
<
0
)
return
-
1
;
if
(
pFile
->
fd
<
0
)
{
tsdbError
(
"failed to open file %s since %s"
,
pFile
->
fname
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
return
0
;
}
int
tsdbCloseFile
(
SFile
*
pFile
)
{
int
ret
=
close
(
pFile
->
fd
);
pFile
->
fd
=
-
1
;
return
ret
;
}
SFileGroup
*
tsdbOpenFilesForCommit
(
STsdbFileH
*
pFileH
,
int
fid
)
{
SFileGroup
*
pGroup
=
tsdbSearchFGroup
(
pFileH
,
fid
);
if
(
pGroup
==
NULL
)
return
NULL
;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
tsdbOpenFile
(
&
(
pGroup
->
files
[
type
]),
O_RDWR
);
void
tsdbCloseFile
(
SFile
*
pFile
)
{
if
(
TSDB_IS_FILE_OPENED
(
pFile
))
{
close
(
pFile
->
fd
);
pFile
->
fd
=
-
1
;
}
return
pGroup
;
}
int
tsdbCreateFile
(
char
*
dataDir
,
int
fileId
,
const
char
*
suffix
,
SFile
*
pFile
)
{
...
...
@@ -331,11 +300,9 @@ int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, SFile *pFile)
return
0
;
}
SFileGroup
*
tsdbSearchFGroup
(
STsdbFileH
*
pFileH
,
int
fid
)
{
if
(
pFileH
->
numOfFGroups
==
0
||
fid
<
pFileH
->
fGroup
[
0
].
fileId
||
fid
>
pFileH
->
fGroup
[
pFileH
->
numOfFGroups
-
1
].
fileId
)
return
NULL
;
void
*
ptr
=
bsearch
((
void
*
)
&
fid
,
(
void
*
)(
pFileH
->
fGroup
),
pFileH
->
numOfFGroups
,
sizeof
(
SFileGroup
),
compFGroupKey
);
SFileGroup
*
tsdbSearchFGroup
(
STsdbFileH
*
pFileH
,
int
fid
,
int
flags
)
{
void
*
ptr
=
taosbsearch
((
void
*
)(
&
fid
),
(
void
*
)(
pFileH
->
pFGroup
),
pFileH
->
nFGroups
,
sizeof
(
SFileGroup
),
keyFGroupCompFunc
);
if
(
ptr
==
NULL
)
return
NULL
;
return
(
SFileGroup
*
)
ptr
;
}
...
...
@@ -362,20 +329,39 @@ static int tsdbInitFile(char *dataDir, int fid, const char *suffix, SFile *pFile
return
0
;
}
static
int
tsdbOpenFGroup
(
STsdbFileH
*
pFileH
,
char
*
dataDir
,
int
fid
)
{
if
(
tsdbSearchFGroup
(
pFileH
,
fid
)
!=
NULL
)
return
0
;
//
static int tsdbOpenFGroup(STsdbFileH *pFileH, char *dataDir, int fid) {
//
if (tsdbSearchFGroup(pFileH, fid) != NULL) return 0;
SFileGroup
fGroup
=
{
0
};
fGroup
.
fileId
=
fid
;
//
SFileGroup fGroup = {0};
//
fGroup.fileId = fid;
for
(
int
type
=
TSDB_FILE_TYPE_HEAD
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
if
(
tsdbInitFile
(
dataDir
,
fid
,
tsdbFileSuffix
[
type
],
&
fGroup
.
files
[
type
])
<
0
)
return
-
1
;
// for (int type = TSDB_FILE_TYPE_HEAD; type < TSDB_FILE_TYPE_MAX; type++) {
// if (tsdbInitFile(dataDir, fid, tsdbFileSuffix[type], &fGroup.files[type]) < 0) return -1;
// }
// pFileH->fGroup[pFileH->numOfFGroups++] = fGroup;
// qsort((void *)(pFileH->fGroup), pFileH->numOfFGroups, sizeof(SFileGroup), compFGroup);
// return 0;
// }
static
int
compFGroup
(
const
void
*
arg1
,
const
void
*
arg2
)
{
int
val1
=
((
SFileGroup
*
)
arg1
)
->
fileId
;
int
val2
=
((
SFileGroup
*
)
arg2
)
->
fileId
;
if
(
val1
<
val2
)
{
return
-
1
;
}
else
if
(
val1
>
val2
)
{
return
1
;
}
else
{
return
0
;
}
pFileH
->
fGroup
[
pFileH
->
numOfFGroups
++
]
=
fGroup
;
qsort
((
void
*
)(
pFileH
->
fGroup
),
pFileH
->
numOfFGroups
,
sizeof
(
SFileGroup
),
compFGroup
);
return
0
;
}
static
int
compFGroup
(
const
void
*
arg1
,
const
void
*
arg2
)
{
return
((
SFileGroup
*
)
arg1
)
->
fileId
-
((
SFileGroup
*
)
arg2
)
->
fileId
;
static
int
keyFGroupCompFunc
(
const
void
*
key
,
const
void
*
fgroup
)
{
int
fid
=
*
(
int
*
)
key
;
SFileGroup
*
pFGroup
=
(
SFileGroup
*
)
fgroup
;
if
(
fid
==
pFGroup
->
fileId
)
{
return
0
;
}
else
{
return
fid
>
pFGroup
->
fileId
?
1
:
-
1
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录