Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e329a159
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
e329a159
编写于
11月 20, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
fde6ef66
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
456 addition
and
293 deletion
+456
-293
src/inc/tfs.h
src/inc/tfs.h
+11
-10
src/tfs/inc/tfcntl.h
src/tfs/inc/tfcntl.h
+28
-0
src/tfs/inc/tfslog.h
src/tfs/inc/tfslog.h
+6
-6
src/tfs/inc/tfstypes.h
src/tfs/inc/tfstypes.h
+28
-0
src/tfs/src/tfcntl.c
src/tfs/src/tfcntl.c
+118
-0
src/tfs/src/tfs.c
src/tfs/src/tfs.c
+9
-0
src/tfs/src/ttier.c
src/tfs/src/ttier.c
+2
-0
src/tsdb/src/tsdbFile.c
src/tsdb/src/tsdbFile.c
+254
-277
未找到文件。
src/inc/tfs.h
浏览文件 @
e329a159
...
...
@@ -22,16 +22,7 @@
extern
"C"
{
#endif
typedef
struct
{
int
level
;
int
id
;
}
SDiskID
;
typedef
struct
{
SDiskID
did
;
char
fname
[
TSDB_FILENAME_LEN
];
}
STfsFile
;
// tfs.c
int
tfsInit
(
SDiskCfg
*
pDiskCfg
,
int
ndisk
);
void
tfsDestroy
();
int
tfsUpdateInfo
();
...
...
@@ -40,6 +31,16 @@ int tfsCreateDir(char *dirname);
int
tfsRemoveDir
(
char
*
dirname
);
int
tfsRename
(
char
*
oldpath
,
char
*
newpath
);
// tfcntl.c
typedef
struct
TFSFILE
TFSFILE
;
typedef
struct
TFSDIR
TFSDIR
;
TFSDIR
*
tfsOpenDir
(
char
*
dir
);
void
tfsCloseDir
(
TFSDIR
*
tdir
);
const
TFSFILE
*
tfsReadDir
(
TFSDIR
*
tdir
);
const
char
*
tfsGetDiskName
(
int
level
,
int
id
);
#ifdef __cplusplus
}
#endif
...
...
src/tfs/inc/tfcntl.h
0 → 100644
浏览文件 @
e329a159
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TD_TFCNTL_H
#define TD_TFCNTL_H
#ifdef __cplusplus
extern
"C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
src/tfs/inc/tfslog.h
浏览文件 @
e329a159
...
...
@@ -20,12 +20,12 @@
extern
"C"
{
#endif
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("FS FATAL ", 255, __VA_ARGS__); }}
#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("FS ERROR ", 255, __VA_ARGS__); }}
#define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("FS WARN ", 255, __VA_ARGS__); }}
#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("FS ", 255, __VA_ARGS__); }}
#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }}
#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }}
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("
T
FS FATAL ", 255, __VA_ARGS__); }}
#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("
T
FS ERROR ", 255, __VA_ARGS__); }}
#define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("
T
FS WARN ", 255, __VA_ARGS__); }}
#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("
T
FS ", 255, __VA_ARGS__); }}
#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("
T
FS ", cqDebugFlag, __VA_ARGS__); }}
#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("
T
FS ", cqDebugFlag, __VA_ARGS__); }}
#ifdef __cplusplus
}
...
...
src/tfs/inc/tfstypes.h
0 → 100644
浏览文件 @
e329a159
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TD_TFCNTL_H
#define TD_TFCNTL_H
#ifdef __cplusplus
extern
"C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
src/tfs/src/tfcntl.c
0 → 100644
浏览文件 @
e329a159
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "taoserror.h"
#include "tdisk.h"
#include "tfs.h"
struct
TFSFILE
{
int
level
;
int
id
;
char
name
[
TSDB_FILENAME_LEN
];
};
struct
TFSDIR
{
int
level
;
int
id
;
char
name
[
TSDB_FILENAME_LEN
];
TFSFILE
tfsfile
;
DIR
*
dir
;
};
TFSDIR
*
tfsOpenDir
(
char
*
dir
)
{
TFSDIR
*
tdir
=
(
TFSDIR
*
)
calloc
(
1
,
sizeof
(
*
tdir
));
if
(
tdir
==
NULL
)
{
terrno
=
TSDB_CODE_FS_OUT_OF_MEMORY
;
return
NULL
;
}
if
(
tfsOpenDirImpl
(
tdir
)
<
0
)
{
tfsCloseDir
(
tdir
);
return
NULL
;
}
return
tdir
;
}
void
tfsCloseDir
(
TFSDIR
*
tdir
)
{
if
(
tdir
)
{
if
(
tdir
->
dir
!=
NULL
)
{
closedir
(
tdir
->
dir
);
tdir
->
dir
=
NULL
;
}
free
(
tdir
);
}
}
const
TFSFILE
*
tfsReadDir
(
TFSDIR
*
tdir
)
{
if
(
tdir
->
dir
==
NULL
)
return
NULL
;
while
(
true
)
{
struct
dirent
*
dp
=
readdir
(
tdir
->
dir
);
if
(
dp
!=
NULL
)
{
tdir
->
tfsfile
.
level
=
tdir
->
level
;
tdir
->
tfsfile
.
id
=
tdir
->
id
;
snprintf
(
tdir
->
tfsfile
.
name
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
tdir
->
name
,
dp
->
d_name
);
return
&
(
tdir
->
tfsfile
);
}
closedir
(
tdir
->
dir
);
// Move to next
if
(
tdir
->
id
<
tfsNDisksAt
(
tdir
->
level
)
-
1
)
{
tdir
->
id
++
;
}
else
{
tdir
->
level
++
;
tdir
->
id
=
0
;
}
if
(
tfsOpenDirImpl
(
tdir
)
<
0
)
{
return
NULL
;
}
if
(
tdir
->
dir
==
NULL
)
return
NULL
;
}
}
static
int
tfsOpenDirImpl
(
TFSDIR
*
tdir
)
{
char
dirName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
while
(
tdir
->
level
<
tfsMaxLevel
())
{
while
(
tdir
->
id
<
tfsNDisksAt
(
tdir
->
level
))
{
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
tfsGetDiskDir
(
tdir
->
level
,
tdir
->
id
),
tdir
->
name
);
tdir
->
dir
=
opendir
(
dirName
);
if
(
tdir
->
dir
==
NULL
)
{
if
(
errno
==
ENOENT
)
{
tdir
->
id
++
;
}
else
{
fError
(
"failed to open dir %s since %s"
,
dirName
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
}
else
{
return
0
;
}
}
tdir
->
id
=
0
;
tdir
->
level
++
;
}
ASSERT
(
tdir
->
dir
==
NULL
);
return
0
;
}
\ No newline at end of file
src/tfs/src/tfs.c
浏览文件 @
e329a159
...
...
@@ -23,6 +23,11 @@
#define TSDB_MAX_TIER 3
typedef
struct
{
int
level
;
int
id
;
}
SDiskID
;
typedef
struct
{
uint64_t
tsize
;
uint64_t
avail
;
...
...
@@ -166,6 +171,10 @@ int tfsRename(char *oldpath, char *newpath) {
return
0
;
}
const
char
*
tfsGetDiskName
(
int
level
,
int
id
)
{
return
DISK_AT
(
level
,
id
)
->
dir
;
}
static
int
tfsMount
(
SDiskCfg
*
pCfg
)
{
SDiskID
did
;
...
...
src/tfs/src/ttier.c
浏览文件 @
e329a159
...
...
@@ -56,6 +56,8 @@ SDisk *tdMountToTier(STier *pTier, SDiskCfg *pCfg) {
if
(
pTier
->
disks
[
id
]
==
NULL
)
return
-
1
;
pTier
->
ndisk
++
;
fDebug
(
"disk %s is mounted at level %d id %d"
,
pCfg
->
dir
,
pCfg
->
level
,
id
);
return
id
;
}
...
...
src/tsdb/src/tsdbFile.c
浏览文件 @
e329a159
...
...
@@ -16,22 +16,15 @@
#define TAOS_RANDOM_FILE_FAIL_TEST
#include <regex.h>
#include "os.h"
#include "tglobal.h"
#include "talgo.h"
#include "tchecksum.h"
#include "tsdbMain.h"
#include "tutil.h"
#include "tfs.h"
const
char
*
tsdbFileSuffix
[]
=
{
".head"
,
".data"
,
".last"
,
".stat"
,
".h"
,
".d"
,
".l"
,
".s"
};
static
void
tsdbDestroyFile
(
SFile
*
pFile
);
static
int
compFGroup
(
const
void
*
arg1
,
const
void
*
arg2
);
static
int
keyFGroupCompFunc
(
const
void
*
key
,
const
void
*
fgroup
);
static
int
tsdbLoadFilesFromDisk
(
STsdbRepo
*
pRepo
,
SDisk
*
pDisk
);
static
SHashObj
*
tsdbGetAllFids
(
STsdbRepo
*
pRepo
,
char
*
dirName
);
static
int
tsdbRestoreFileGroup
(
STsdbRepo
*
pRepo
,
SDisk
*
pDisk
,
int
fid
,
SFileGroup
*
pFileGroup
);
static
int
tsdbGetFidLevel
(
int
fid
,
SFidGroup
*
pFidGroup
);
static
int
tsdbCreateVnodeDataDir
(
char
*
baseDir
,
int
vid
);
const
char
*
tsdbFileSuffix
[]
=
{
".head"
,
".data"
,
".last"
,
".stat"
,
".h"
,
".d"
,
".l"
,
".s"
};
// ---------------- INTERNAL FUNCTIONS ----------------
STsdbFileH
*
tsdbNewFileH
(
STsdbCfg
*
pCfg
)
{
...
...
@@ -75,22 +68,6 @@ int tsdbOpenFileH(STsdbRepo *pRepo) {
ASSERT
(
pRepo
!=
NULL
&&
pRepo
->
tsdbFileH
!=
NULL
);
char
dataDir
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
for
(
int
level
=
0
;
level
<
tsDnodeTier
->
nTiers
;
level
++
)
{
STier
*
pTier
=
tsDnodeTier
->
tiers
+
level
;
for
(
int
did
=
0
;
did
<
pTier
->
nDisks
;
did
++
)
{
SDisk
*
pDisk
=
pTier
->
disks
[
did
];
tdGetTsdbDataDir
(
pDisk
->
dir
,
REPO_ID
(
pRepo
),
dataDir
);
if
(
access
(
dataDir
,
F_OK
)
!=
0
)
{
// Skip those disks without data
continue
;
}
tsdbLoadFilesFromDisk
(
pRepo
,
pDisk
);
}
}
return
0
;
}
...
...
@@ -521,254 +498,254 @@ static int keyFGroupCompFunc(const void *key, const void *fgroup) {
}
}
static
int
tsdbLoadFilesFromDisk
(
STsdbRepo
*
pRepo
,
SDisk
*
pDisk
)
{
char
tsdbDataDir
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
tsdbRootDir
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
fname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
SHashObj
*
pFids
=
NULL
;
SHashMutableIterator
*
pIter
=
NULL
;
STsdbFileH
*
pFileH
=
pRepo
->
tsdbFileH
;
SFileGroup
fgroup
=
{
0
};
STsdbCfg
*
pCfg
=
&
(
pRepo
->
config
);
SFidGroup
fidGroup
=
{
0
};
int
mfid
=
0
;
tdGetTsdbRootDir
(
pDisk
->
dir
,
REPO_ID
(
pRepo
),
tsdbRootDir
);
tdGetTsdbDataDir
(
pDisk
->
dir
,
REPO_ID
(
pRepo
),
tsdbDataDir
);
pFids
=
tsdbGetAllFids
(
pRepo
,
tsdbDataDir
);
if
(
pFids
==
NULL
)
{
goto
_err
;
}
pIter
=
taosHashCreateIter
(
pFids
);
if
(
pIter
==
NULL
)
{
goto
_err
;
}
tsdbGetFidGroup
(
pCfg
,
&
fidGroup
);
mfid
=
fidGroup
.
minFid
;
while
(
taosHashIterNext
(
pIter
))
{
int32_t
fid
=
*
(
int32_t
*
)
taosHashIterGet
(
pIter
);
if
(
fid
<
mfid
)
{
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
fid
,
type
,
fname
);
(
void
)
remove
(
fname
);
}
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
fid
,
TSDB_FILE_TYPE_NHEAD
,
fname
);
(
void
)
remove
(
fname
);
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
fid
,
TSDB_FILE_TYPE_NLAST
,
fname
);
(
void
)
remove
(
fname
);
continue
;
}
tsdbRestoreFileGroup
(
pRepo
,
pDisk
,
fid
,
&
fgroup
);
pFileH
->
pFGroup
[
pFileH
->
nFGroups
++
]
=
fgroup
;
qsort
((
void
*
)(
pFileH
->
pFGroup
),
pFileH
->
nFGroups
,
sizeof
(
fgroup
),
compFGroup
);
// TODO
pDisk
->
dmeta
.
nfiles
++
;
}
taosHashDestroyIter
(
pIter
);
taosHashCleanup
(
pFids
);
return
0
;
_err:
taosHashDestroyIter
(
pIter
);
taosHashCleanup
(
pFids
);
return
-
1
;
}
static
int
tsdbRestoreFileGroup
(
STsdbRepo
*
pRepo
,
SDisk
*
pDisk
,
int
fid
,
SFileGroup
*
pFileGroup
)
{
char
tsdbRootDir
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
nheadF
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
nlastF
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
bool
newHeadExists
=
false
;
bool
newLastExists
=
false
;
uint32_t
version
=
0
;
terrno
=
TSDB_CODE_SUCCESS
;
memset
((
void
*
)
pFileGroup
,
0
,
sizeof
(
*
pFileGroup
));
pFileGroup
->
fileId
=
fid
;
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
SFile
*
pFile
=
pFileGroup
->
files
+
type
;
pFile
->
fd
=
-
1
;
}
tdGetTsdbRootDir
(
pDisk
->
dir
,
REPO_ID
(
pRepo
),
tsdbRootDir
);
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
SFile
*
pFile
=
pFileGroup
->
files
+
type
;
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
fid
,
TSDB_FILE_TYPE_HEAD
,
pFile
->
fname
);
if
(
access
(
pFile
->
fname
,
F_OK
)
!=
0
)
{
memset
(
&
(
pFile
->
info
),
0
,
sizeof
(
pFile
->
info
));
pFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pFileGroup
->
state
=
1
;
terrno
=
TSDB_CODE_TDB_FILE_CORRUPTED
;
}
}
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
fid
,
TSDB_FILE_TYPE_NHEAD
,
nheadF
);
tsdbGetDataFileName
(
tsdbRootDir
,
REPO_ID
(
pRepo
),
fid
,
TSDB_FILE_TYPE_NLAST
,
nlastF
);
if
(
access
(
nheadF
,
F_OK
)
==
0
)
{
newHeadExists
=
true
;
}
if
(
access
(
nlastF
,
F_OK
)
==
0
)
{
newLastExists
=
true
;
}
if
(
newHeadExists
)
{
(
void
)
remove
(
nheadF
);
(
void
)
remove
(
nlastF
);
}
else
{
if
(
newLastExists
)
{
(
void
)
rename
(
nlastF
,
pFileGroup
->
files
[
TSDB_FILE_TYPE_LAST
].
fname
);
}
}
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
{
return
-
1
;
}
for
(
int
type
=
0
;
type
<
TSDB_FILE_TYPE_MAX
;
type
++
)
{
SFile
*
pFile
=
pFileGroup
->
files
+
type
;
if
(
tsdbOpenFile
(
pFile
,
O_RDONLY
)
<
0
)
{
memset
(
&
(
pFile
->
info
),
0
,
sizeof
(
pFile
->
info
));
pFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pFileGroup
->
state
=
1
;
terrno
=
TSDB_CODE_TDB_FILE_CORRUPTED
;
continue
;
}
if
(
tsdbLoadFileHeader
(
pFile
,
&
version
)
<
0
)
{
memset
(
&
(
pFile
->
info
),
0
,
sizeof
(
pFile
->
info
));
pFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pFileGroup
->
state
=
1
;
terrno
=
TSDB_CODE_TDB_FILE_CORRUPTED
;
tsdbCloseFile
(
pFile
);
continue
;
}
if
(
version
!=
TSDB_FILE_VERSION
)
{
tsdbError
(
"vgId:%d file %s version %u is not the same as program version %u which may cause problem"
,
REPO_ID
(
pRepo
),
pFile
->
fname
,
version
,
TSDB_FILE_VERSION
);
}
tsdbCloseFile
(
pFile
);
}
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
{
return
-
1
;
}
else
{
return
0
;
}
}
static
SHashObj
*
tsdbGetAllFids
(
STsdbRepo
*
pRepo
,
char
*
dirName
)
{
DIR
*
dir
=
NULL
;
regex_t
regex
=
{
0
};
int
code
=
0
;
int32_t
vid
,
fid
;
SHashObj
*
pHash
=
NULL
;
code
=
regcomp
(
&
regex
,
"^v[0-9]+f[0-9]+
\\
.(head|data|last|h|d|l)$"
,
REG_EXTENDED
);
if
(
code
!=
0
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
}
dir
=
opendir
(
dirName
);
if
(
dir
==
NULL
)
{
tsdbError
(
"vgId:%d failed to open directory %s since %s"
,
REPO_ID
(
pRepo
),
dirName
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
goto
_err
;
}
pHash
=
taosHashInit
(
1024
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
false
,
HASH_NO_LOCK
);
if
(
pHash
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
goto
_err
;
}
struct
dirent
*
dp
=
NULL
;
while
((
dp
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
dp
->
d_name
,
"."
)
==
0
||
strcmp
(
dp
->
d_name
,
".."
)
==
0
)
continue
;
code
=
regexec
(
&
regex
,
dp
->
d_name
,
0
,
NULL
,
0
);
if
(
code
==
0
)
{
sscanf
(
dp
->
d_name
,
"v%df%d"
,
&
vid
,
&
fid
);
if
(
vid
!=
REPO_ID
(
pRepo
))
{
tsdbError
(
"vgId:%d invalid file %s exists, ignore it"
,
REPO_ID
(
pRepo
),
dp
->
d_name
);
continue
;
}
taosHashPut
(
pHash
,
(
void
*
)(
&
fid
),
sizeof
(
fid
),
(
void
*
)(
&
fid
),
sizeof
(
fid
));
}
else
if
(
code
==
REG_NOMATCH
)
{
tsdbError
(
"vgId:%d invalid file %s exists, ignore it"
,
REPO_ID
(
pRepo
),
dp
->
d_name
);
continue
;
}
else
{
goto
_err
;
}
}
closedir
(
dir
);
regfree
(
&
regex
);
return
pHash
;
_err:
taosHashCleanup
(
pHash
);
if
(
dir
!=
NULL
)
closedir
(
dir
);
regfree
(
&
regex
);
return
NULL
;
}
static
int
tsdbGetFidLevel
(
int
fid
,
SFidGroup
*
pFidGroup
)
{
if
(
fid
>=
pFidGroup
->
maxFid
)
{
return
0
;
}
else
if
(
fid
>=
pFidGroup
->
midFid
&&
fid
<
pFidGroup
->
maxFid
)
{
return
1
;
}
else
{
return
2
;
}
}
static
int
tsdbCreateVnodeDataDir
(
char
*
baseDir
,
int
vid
)
{
char
dirName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
tsdbRootDir
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
tdGetVnodeRootDir
(
baseDir
,
dirName
);
if
(
taosMkDir
(
dirName
,
0755
)
<
0
&&
errno
!=
EEXIST
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
tdGetVnodeDir
(
baseDir
,
vid
,
dirName
);
if
(
taosMkDir
(
dirName
,
0755
)
<
0
&&
errno
!=
EEXIST
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
tdGetTsdbRootDir
(
baseDir
,
vid
,
tsdbRootDir
);
if
(
taosMkDir
(
tsdbRootDir
,
0755
)
<
0
&&
errno
!=
EEXIST
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
tdGetTsdbDataDir
(
baseDir
,
vid
,
dirName
);
if
(
taosMkDir
(
dirName
,
0755
)
<
0
&&
errno
!=
EEXIST
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
return
0
;
}
\ No newline at end of file
// static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk) {
// char tsdbDataDir[TSDB_FILENAME_LEN] = "\0";
// char tsdbRootDir[TSDB_FILENAME_LEN] = "\0";
// char fname[TSDB_FILENAME_LEN] = "\0";
// SHashObj * pFids = NULL;
// SHashMutableIterator *pIter = NULL;
// STsdbFileH * pFileH = pRepo->tsdbFileH;
// SFileGroup fgroup = {0};
// STsdbCfg * pCfg = &(pRepo->config);
// SFidGroup fidGroup = {0};
// int mfid = 0;
// tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir);
// tdGetTsdbDataDir(pDisk->dir, REPO_ID(pRepo), tsdbDataDir);
// pFids = tsdbGetAllFids(pRepo, tsdbDataDir);
// if (pFids == NULL) {
// goto _err;
// }
// pIter = taosHashCreateIter(pFids);
// if (pIter == NULL) {
// goto _err;
// }
// tsdbGetFidGroup(pCfg, &fidGroup);
// mfid = fidGroup.minFid;
// while (taosHashIterNext(pIter)) {
// int32_t fid = *(int32_t *)taosHashIterGet(pIter);
// if (fid < mfid) {
// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, type, fname);
// (void)remove(fname);
// }
// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NHEAD, fname);
// (void)remove(fname);
// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NLAST, fname);
// (void)remove(fname);
// continue;
// }
// tsdbRestoreFileGroup(pRepo, pDisk, fid, &fgroup);
// pFileH->pFGroup[pFileH->nFGroups++] = fgroup;
// qsort((void *)(pFileH->pFGroup), pFileH->nFGroups, sizeof(fgroup), compFGroup);
// // TODO
// pDisk->dmeta.nfiles++;
// }
// taosHashDestroyIter(pIter);
// taosHashCleanup(pFids);
// return 0;
// _err:
// taosHashDestroyIter(pIter);
// taosHashCleanup(pFids);
// return -1;
// }
// static int tsdbRestoreFileGroup(STsdbRepo *pRepo, SDisk *pDisk, int fid, SFileGroup *pFileGroup) {
// char tsdbRootDir[TSDB_FILENAME_LEN] = "\0";
// char nheadF[TSDB_FILENAME_LEN] = "\0";
// char nlastF[TSDB_FILENAME_LEN] = "\0";
// bool newHeadExists = false;
// bool newLastExists = false;
// uint32_t version = 0;
// terrno = TSDB_CODE_SUCCESS;
// memset((void *)pFileGroup, 0, sizeof(*pFileGroup));
// pFileGroup->fileId = fid;
// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
// SFile *pFile = pFileGroup->files + type;
// pFile->fd = -1;
// }
// tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir);
// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
// SFile *pFile = pFileGroup->files + type;
// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_HEAD, pFile->fname);
// if (access(pFile->fname, F_OK) != 0) {
// memset(&(pFile->info), 0, sizeof(pFile->info));
// pFile->info.magic = TSDB_FILE_INIT_MAGIC;
// pFileGroup->state = 1;
// terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
// }
// }
// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NHEAD, nheadF);
// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NLAST, nlastF);
// if (access(nheadF, F_OK) == 0) {
// newHeadExists = true;
// }
// if (access(nlastF, F_OK) == 0) {
// newLastExists = true;
// }
// if (newHeadExists) {
// (void)remove(nheadF);
// (void)remove(nlastF);
// } else {
// if (newLastExists) {
// (void)rename(nlastF, pFileGroup->files[TSDB_FILE_TYPE_LAST].fname);
// }
// }
// if (terrno != TSDB_CODE_SUCCESS) {
// return -1;
// }
// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) {
// SFile *pFile = pFileGroup->files + type;
// if (tsdbOpenFile(pFile, O_RDONLY) < 0) {
// memset(&(pFile->info), 0, sizeof(pFile->info));
// pFile->info.magic = TSDB_FILE_INIT_MAGIC;
// pFileGroup->state = 1;
// terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
// continue;
// }
// if (tsdbLoadFileHeader(pFile, &version) < 0) {
// memset(&(pFile->info), 0, sizeof(pFile->info));
// pFile->info.magic = TSDB_FILE_INIT_MAGIC;
// pFileGroup->state = 1;
// terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
// tsdbCloseFile(pFile);
// continue;
// }
// if (version != TSDB_FILE_VERSION) {
// tsdbError("vgId:%d file %s version %u is not the same as program version %u which may cause problem",
// REPO_ID(pRepo), pFile->fname, version, TSDB_FILE_VERSION);
// }
// tsdbCloseFile(pFile);
// }
// if (terrno != TSDB_CODE_SUCCESS) {
// return -1;
// } else {
// return 0;
// }
// }
// static SHashObj *tsdbGetAllFids(STsdbRepo *pRepo, char *dirName) {
// DIR * dir = NULL;
// regex_t regex = {0};
// int code = 0;
// int32_t vid, fid;
// SHashObj *pHash = NULL;
// code = regcomp(®ex, "^v[0-9]+f[0-9]+\\.(head|data|last|h|d|l)$", REG_EXTENDED);
// if (code != 0) {
// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
// goto _err;
// }
// dir = opendir(dirName);
// if (dir == NULL) {
// tsdbError("vgId:%d failed to open directory %s since %s", REPO_ID(pRepo), dirName, strerror(errno));
// terrno = TAOS_SYSTEM_ERROR(errno);
// goto _err;
// }
// pHash = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
// if (pHash == NULL) {
// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
// goto _err;
// }
// struct dirent *dp = NULL;
// while ((dp = readdir(dir)) != NULL) {
// if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) continue;
// code = regexec(®ex, dp->d_name, 0, NULL, 0);
// if (code == 0) {
// sscanf(dp->d_name, "v%df%d", &vid, &fid);
// if (vid != REPO_ID(pRepo)) {
// tsdbError("vgId:%d invalid file %s exists, ignore it", REPO_ID(pRepo), dp->d_name);
// continue;
// }
// taosHashPut(pHash, (void *)(&fid), sizeof(fid), (void *)(&fid), sizeof(fid));
// } else if (code == REG_NOMATCH) {
// tsdbError("vgId:%d invalid file %s exists, ignore it", REPO_ID(pRepo), dp->d_name);
// continue;
// } else {
// goto _err;
// }
// }
// closedir(dir);
// regfree(®ex);
// return pHash;
// _err:
// taosHashCleanup(pHash);
// if (dir != NULL) closedir(dir);
// regfree(®ex);
// return NULL;
// }
// static int tsdbGetFidLevel(int fid, SFidGroup *pFidGroup) {
// if (fid >= pFidGroup->maxFid) {
// return 0;
// } else if (fid >= pFidGroup->midFid && fid < pFidGroup->maxFid) {
// return 1;
// } else {
// return 2;
// }
// }
// static int tsdbCreateVnodeDataDir(char *baseDir, int vid) {
// char dirName[TSDB_FILENAME_LEN] = "\0";
// char tsdbRootDir[TSDB_FILENAME_LEN] = "\0";
// tdGetVnodeRootDir(baseDir, dirName);
// if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno);
// return -1;
// }
// tdGetVnodeDir(baseDir, vid, dirName);
// if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno);
// return -1;
// }
// tdGetTsdbRootDir(baseDir, vid, tsdbRootDir);
// if (taosMkDir(tsdbRootDir, 0755) < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno);
// return -1;
// }
// tdGetTsdbDataDir(baseDir, vid, dirName);
// if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) {
// terrno = TAOS_SYSTEM_ERROR(errno);
// return -1;
// }
// return 0;
// }
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录