Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7087e442
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看板
提交
7087e442
编写于
1月 12, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor changes
上级
9e4141fa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
80 deletion
+80
-80
include/libs/tfs/tfs.h
include/libs/tfs/tfs.h
+27
-27
source/libs/tfs/inc/tfsInt.h
source/libs/tfs/inc/tfsInt.h
+4
-4
source/libs/tfs/src/tfs.c
source/libs/tfs/src/tfs.c
+49
-49
未找到文件。
include/libs/tfs/tfs.h
浏览文件 @
7087e442
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef
TD_TFS_H
#define
TD_TFS_H
#ifndef
_TD_TFS_H_
#define
_TD_TFS_H_
#include "tglobal.h"
...
...
@@ -23,8 +23,8 @@ extern "C" {
#endif
typedef
struct
{
int
level
;
int
id
;
int
32_t
level
;
int
32_t
id
;
}
SDiskID
;
#define TFS_UNDECIDED_LEVEL -1
...
...
@@ -48,21 +48,21 @@ typedef struct {
int16_t
nAvailDisks
;
// # of Available disks
}
STierMeta
;
int
tfsInit
(
SDiskCfg
*
pDiskCfg
,
in
t
ndisk
);
void
tfsCleanup
();
void
tfsUpdateInfo
(
SFSMeta
*
pFSMeta
,
STierMeta
*
tierMetas
,
int8_t
numLevels
);
void
tfsGetMeta
(
SFSMeta
*
pMeta
);
void
tfsAllocDisk
(
int
expLevel
,
int
*
level
,
in
t
*
id
);
int
32_t
tfsInit
(
SDiskCfg
*
pDiskCfg
,
int32_
t
ndisk
);
void
tfsCleanup
();
void
tfsUpdateInfo
(
SFSMeta
*
pFSMeta
,
STierMeta
*
tierMetas
,
int8_t
numLevels
);
void
tfsGetMeta
(
SFSMeta
*
pMeta
);
void
tfsAllocDisk
(
int32_t
expLevel
,
int32_t
*
level
,
int32_
t
*
id
);
const
char
*
TFS_PRIMARY_PATH
();
const
char
*
TFS_DISK_PATH
(
int
level
,
in
t
id
);
const
char
*
TFS_DISK_PATH
(
int
32_t
level
,
int32_
t
id
);
// TFILE APIs ====================================
typedef
struct
{
int
level
;
int
id
;
char
rname
[
TSDB_FILENAME_LEN
];
// REL name
char
aname
[
TSDB_FILENAME_LEN
];
// ABS name
int
32_t
level
;
int
32_t
id
;
char
rname
[
TSDB_FILENAME_LEN
];
// REL name
char
aname
[
TSDB_FILENAME_LEN
];
// ABS name
}
TFILE
;
#define TFILE_LEVEL(pf) ((pf)->level)
...
...
@@ -76,23 +76,23 @@ typedef struct {
#define tfscopy(sf, df) taosCopyFile(TFILE_NAME(sf), TFILE_NAME(df))
#define tfsrename(sf, df) taosRename(TFILE_NAME(sf), TFILE_NAME(df))
void
tfsInitFile
(
TFILE
*
pf
,
int
level
,
in
t
id
,
const
char
*
bname
);
bool
tfsIsSameFile
(
const
TFILE
*
pf1
,
const
TFILE
*
pf2
);
int
tfsEncodeFile
(
void
**
buf
,
TFILE
*
pf
);
void
*
tfsDecodeFile
(
void
*
buf
,
TFILE
*
pf
);
void
tfsbasename
(
const
TFILE
*
pf
,
char
*
dest
);
void
tfsdirname
(
const
TFILE
*
pf
,
char
*
dest
);
void
tfsInitFile
(
TFILE
*
pf
,
int32_t
level
,
int32_
t
id
,
const
char
*
bname
);
bool
tfsIsSameFile
(
const
TFILE
*
pf1
,
const
TFILE
*
pf2
);
int
32_t
tfsEncodeFile
(
void
**
buf
,
TFILE
*
pf
);
void
*
tfsDecodeFile
(
void
*
buf
,
TFILE
*
pf
);
void
tfsbasename
(
const
TFILE
*
pf
,
char
*
dest
);
void
tfsdirname
(
const
TFILE
*
pf
,
char
*
dest
);
// DIR APIs ====================================
int
tfsMkdirAt
(
const
char
*
rname
,
int
level
,
in
t
id
);
int
tfsMkdirRecurAt
(
const
char
*
rname
,
int
level
,
in
t
id
);
int
tfsMkdir
(
const
char
*
rname
);
int
tfsRmdir
(
const
char
*
rname
);
int
tfsRename
(
char
*
orname
,
char
*
nrname
);
int
32_t
tfsMkdirAt
(
const
char
*
rname
,
int32_t
level
,
int32_
t
id
);
int
32_t
tfsMkdirRecurAt
(
const
char
*
rname
,
int32_t
level
,
int32_
t
id
);
int
32_t
tfsMkdir
(
const
char
*
rname
);
int
32_t
tfsRmdir
(
const
char
*
rname
);
int
32_t
tfsRename
(
char
*
orname
,
char
*
nrname
);
typedef
struct
TDIR
TDIR
;
TDIR
*
tfsOpendir
(
const
char
*
rname
);
TDIR
*
tfsOpendir
(
const
char
*
rname
);
const
TFILE
*
tfsReaddir
(
TDIR
*
tdir
);
void
tfsClosedir
(
TDIR
*
tdir
);
...
...
@@ -100,4 +100,4 @@ void tfsClosedir(TDIR *tdir);
}
#endif
#endif
#endif
/*_TD_TFS_H_*/
source/libs/tfs/inc/tfsInt.h
浏览文件 @
7087e442
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef
TD_TFSINT_H
#define
TD_TFSINT_H
#ifndef
_TD_TFSINT_H_
#define
_TD_TFSINT_H_
#include "os.h"
...
...
@@ -88,10 +88,10 @@ void tfsDestroyTier(STier *pTier);
SDisk
*
tfsMountDiskToTier
(
STier
*
pTier
,
SDiskCfg
*
pCfg
);
void
tfsUpdateTierInfo
(
STier
*
pTier
,
STierMeta
*
pTierMeta
);
int32_t
tfsAllocDiskOnTier
(
STier
*
pTier
);
void
tfsPosNextId
(
STier
*
pTier
);
void
tfsPosNextId
(
STier
*
pTier
);
#ifdef __cplusplus
}
#endif
#endif
#endif
/*_TD_TFSINT_H_*/
source/libs/tfs/src/tfs.c
浏览文件 @
7087e442
...
...
@@ -21,9 +21,9 @@
typedef
struct
{
pthread_spinlock_t
lock
;
SFSMeta
meta
;
int
nlevel
;
int
32_t
nlevel
;
STier
tiers
[
TSDB_MAX_TIERS
];
SHashObj
*
map
;
// name to did map
SHashObj
*
map
;
// name to did map
}
SFS
;
typedef
struct
{
...
...
@@ -47,21 +47,21 @@ static SFS tfs = {0};
static
SFS
*
pfs
=
&
tfs
;
// STATIC DECLARATION
static
int
tfsMount
(
SDiskCfg
*
pCfg
);
static
int
tfsCheck
();
static
int
tfsCheckAndFormatCfg
(
SDiskCfg
*
pCfg
);
static
int
tfsFormatDir
(
char
*
idir
,
char
*
odir
);
static
SDisk
*
tfsGetDiskByID
(
SDiskID
did
);
static
SDisk
*
tfsGetDiskByName
(
const
char
*
dir
);
static
int
tfsOpendirImpl
(
TDIR
*
tdir
);
static
void
tfsInitDiskIter
(
SDiskIter
*
pIter
);
static
SDisk
*
tfsNextDisk
(
SDiskIter
*
pIter
);
static
int
32_t
tfsMount
(
SDiskCfg
*
pCfg
);
static
int
32_t
tfsCheck
();
static
int
32_t
tfsCheckAndFormatCfg
(
SDiskCfg
*
pCfg
);
static
int
32_t
tfsFormatDir
(
char
*
idir
,
char
*
odir
);
static
SDisk
*
tfsGetDiskByID
(
SDiskID
did
);
static
SDisk
*
tfsGetDiskByName
(
const
char
*
dir
);
static
int
32_t
tfsOpendirImpl
(
TDIR
*
tdir
);
static
void
tfsInitDiskIter
(
SDiskIter
*
pIter
);
static
SDisk
*
tfsNextDisk
(
SDiskIter
*
pIter
);
// FS APIs ====================================
int
tfsInit
(
SDiskCfg
*
pDiskCfg
,
in
t
ndisk
)
{
int
32_t
tfsInit
(
SDiskCfg
*
pDiskCfg
,
int32_
t
ndisk
)
{
ASSERT
(
ndisk
>
0
);
for
(
int
level
=
0
;
level
<
TSDB_MAX_TIERS
;
level
++
)
{
for
(
int
32_t
level
=
0
;
level
<
TSDB_MAX_TIERS
;
level
++
)
{
if
(
tfsInitTier
(
TFS_TIER_AT
(
level
),
level
)
<
0
)
{
while
(
true
)
{
level
--
;
...
...
@@ -84,7 +84,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
return
-
1
;
}
for
(
int
idisk
=
0
;
idisk
<
ndisk
;
idisk
++
)
{
for
(
int
32_t
idisk
=
0
;
idisk
<
ndisk
;
idisk
++
)
{
if
(
tfsMount
(
pDiskCfg
+
idisk
)
<
0
)
{
tfsCleanup
();
return
-
1
;
...
...
@@ -97,7 +97,7 @@ int tfsInit(SDiskCfg *pDiskCfg, int ndisk) {
}
tfsUpdateInfo
(
NULL
,
NULL
,
0
);
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
for
(
int
32_t
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
tfsPosNextId
(
TFS_TIER_AT
(
level
));
}
...
...
@@ -109,7 +109,7 @@ void tfsCleanup() {
pfs
->
map
=
NULL
;
pthread_spin_destroy
(
&
(
pfs
->
lock
));
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
for
(
int
32_t
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
tfsDestroyTier
(
TFS_TIER_AT
(
level
));
}
}
...
...
@@ -124,7 +124,7 @@ void tfsUpdateInfo(SFSMeta *pFSMeta, STierMeta *tierMetas, int8_t numTiers) {
memset
(
pFSMeta
,
0
,
sizeof
(
*
pFSMeta
));
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
for
(
int
32_t
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
STierMeta
*
pTierMeta
=
&
tierMeta
;
if
(
tierMetas
&&
level
<
numTiers
)
{
pTierMeta
=
tierMetas
+
level
;
...
...
@@ -152,7 +152,7 @@ void tfsGetMeta(SFSMeta *pMeta) {
/* Allocate an existing available tier level
*/
void
tfsAllocDisk
(
int
expLevel
,
int
*
level
,
in
t
*
id
)
{
void
tfsAllocDisk
(
int
32_t
expLevel
,
int32_t
*
level
,
int32_
t
*
id
)
{
ASSERT
(
expLevel
>=
0
);
*
level
=
expLevel
;
...
...
@@ -177,10 +177,10 @@ void tfsAllocDisk(int expLevel, int *level, int *id) {
}
const
char
*
TFS_PRIMARY_PATH
()
{
return
DISK_DIR
(
TFS_PRIMARY_DISK
());
}
const
char
*
TFS_DISK_PATH
(
int
level
,
in
t
id
)
{
return
DISK_DIR
(
TFS_DISK_AT
(
level
,
id
));
}
const
char
*
TFS_DISK_PATH
(
int
32_t
level
,
int32_
t
id
)
{
return
DISK_DIR
(
TFS_DISK_AT
(
level
,
id
));
}
// TFILE APIs ====================================
void
tfsInitFile
(
TFILE
*
pf
,
int
level
,
in
t
id
,
const
char
*
bname
)
{
void
tfsInitFile
(
TFILE
*
pf
,
int
32_t
level
,
int32_
t
id
,
const
char
*
bname
)
{
ASSERT
(
TFS_IS_VALID_DISK
(
level
,
id
));
SDisk
*
pDisk
=
TFS_DISK_AT
(
level
,
id
);
...
...
@@ -203,8 +203,8 @@ bool tfsIsSameFile(const TFILE *pf1, const TFILE *pf2) {
return
true
;
}
int
tfsEncodeFile
(
void
**
buf
,
TFILE
*
pf
)
{
int
tlen
=
0
;
int
32_t
tfsEncodeFile
(
void
**
buf
,
TFILE
*
pf
)
{
int
32_t
tlen
=
0
;
tlen
+=
taosEncodeVariantI32
(
buf
,
pf
->
level
);
tlen
+=
taosEncodeVariantI32
(
buf
,
pf
->
id
);
...
...
@@ -215,7 +215,7 @@ int tfsEncodeFile(void **buf, TFILE *pf) {
void
*
tfsDecodeFile
(
void
*
buf
,
TFILE
*
pf
)
{
int32_t
level
,
id
;
char
*
rname
;
char
*
rname
;
buf
=
taosDecodeVariantI32
(
buf
,
&
(
level
));
buf
=
taosDecodeVariantI32
(
buf
,
&
(
id
));
...
...
@@ -242,7 +242,7 @@ void tfsdirname(const TFILE *pf, char *dest) {
}
// DIR APIs ====================================
int
tfsMkdirAt
(
const
char
*
rname
,
int
level
,
in
t
id
)
{
int
32_t
tfsMkdirAt
(
const
char
*
rname
,
int32_t
level
,
int32_
t
id
)
{
SDisk
*
pDisk
=
TFS_DISK_AT
(
level
,
id
);
char
aname
[
TMPNAME_LEN
];
...
...
@@ -255,7 +255,7 @@ int tfsMkdirAt(const char *rname, int level, int id) {
return
0
;
}
int
tfsMkdirRecurAt
(
const
char
*
rname
,
int
level
,
in
t
id
)
{
int
32_t
tfsMkdirRecurAt
(
const
char
*
rname
,
int32_t
level
,
int32_
t
id
)
{
if
(
tfsMkdirAt
(
rname
,
level
,
id
)
<
0
)
{
if
(
errno
==
ENOENT
)
{
// Try to create upper
...
...
@@ -288,10 +288,10 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) {
return
0
;
}
int
tfsMkdir
(
const
char
*
rname
)
{
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
int
32_t
tfsMkdir
(
const
char
*
rname
)
{
for
(
int
32_t
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
STier
*
pTier
=
TFS_TIER_AT
(
level
);
for
(
int
id
=
0
;
id
<
TIER_NDISKS
(
pTier
);
id
++
)
{
for
(
int
32_t
id
=
0
;
id
<
TIER_NDISKS
(
pTier
);
id
++
)
{
if
(
tfsMkdirAt
(
rname
,
level
,
id
)
<
0
)
{
return
-
1
;
}
...
...
@@ -301,12 +301,12 @@ int tfsMkdir(const char *rname) {
return
0
;
}
int
tfsRmdir
(
const
char
*
rname
)
{
int
32_t
tfsRmdir
(
const
char
*
rname
)
{
char
aname
[
TMPNAME_LEN
]
=
"
\0
"
;
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
for
(
int
32_t
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
STier
*
pTier
=
TFS_TIER_AT
(
level
);
for
(
int
id
=
0
;
id
<
TIER_NDISKS
(
pTier
);
id
++
)
{
for
(
int
32_t
id
=
0
;
id
<
TIER_NDISKS
(
pTier
);
id
++
)
{
SDisk
*
pDisk
=
DISK_AT_TIER
(
pTier
,
id
);
snprintf
(
aname
,
TMPNAME_LEN
,
"%s/%s"
,
DISK_DIR
(
pDisk
),
rname
);
...
...
@@ -318,13 +318,13 @@ int tfsRmdir(const char *rname) {
return
0
;
}
int
tfsRename
(
char
*
orname
,
char
*
nrname
)
{
int
32_t
tfsRename
(
char
*
orname
,
char
*
nrname
)
{
char
oaname
[
TMPNAME_LEN
]
=
"
\0
"
;
char
naname
[
TMPNAME_LEN
]
=
"
\0
"
;
for
(
int
level
=
0
;
level
<
pfs
->
nlevel
;
level
++
)
{
for
(
int
32_t
level
=
0
;
level
<
pfs
->
nlevel
;
level
++
)
{
STier
*
pTier
=
TFS_TIER_AT
(
level
);
for
(
int
id
=
0
;
id
<
TIER_NDISKS
(
pTier
);
id
++
)
{
for
(
int
32_t
id
=
0
;
id
<
TIER_NDISKS
(
pTier
);
id
++
)
{
SDisk
*
pDisk
=
DISK_AT_TIER
(
pTier
,
id
);
snprintf
(
oaname
,
TMPNAME_LEN
,
"%s/%s"
,
DISK_DIR
(
pDisk
),
orname
);
...
...
@@ -339,11 +339,11 @@ int tfsRename(char *orname, char *nrname) {
struct
TDIR
{
SDiskIter
iter
;
int
level
;
int
id
;
int
32_t
level
;
int
32_t
id
;
char
dirname
[
TSDB_FILENAME_LEN
];
TFILE
tfile
;
DIR
*
dir
;
DIR
*
dir
;
};
TDIR
*
tfsOpendir
(
const
char
*
rname
)
{
...
...
@@ -402,9 +402,9 @@ void tfsClosedir(TDIR *tdir) {
}
// private
static
int
tfsMount
(
SDiskCfg
*
pCfg
)
{
static
int
32_t
tfsMount
(
SDiskCfg
*
pCfg
)
{
SDiskID
did
;
SDisk
*
pDisk
=
NULL
;
SDisk
*
pDisk
=
NULL
;
if
(
tfsCheckAndFormatCfg
(
pCfg
)
<
0
)
return
-
1
;
...
...
@@ -422,7 +422,7 @@ static int tfsMount(SDiskCfg *pCfg) {
return
0
;
}
static
int
tfsCheckAndFormatCfg
(
SDiskCfg
*
pCfg
)
{
static
int
32_t
tfsCheckAndFormatCfg
(
SDiskCfg
*
pCfg
)
{
char
dirName
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
struct
stat
pstat
;
...
...
@@ -481,10 +481,10 @@ static int tfsCheckAndFormatCfg(SDiskCfg *pCfg) {
return
0
;
}
static
int
tfsFormatDir
(
char
*
idir
,
char
*
odir
)
{
static
int
32_t
tfsFormatDir
(
char
*
idir
,
char
*
odir
)
{
wordexp_t
wep
=
{
0
};
int
code
=
wordexp
(
idir
,
&
wep
,
0
);
int
32_t
code
=
wordexp
(
idir
,
&
wep
,
0
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
...
...
@@ -502,14 +502,14 @@ static int tfsFormatDir(char *idir, char *odir) {
return
0
;
}
static
int
tfsCheck
()
{
static
int
32_t
tfsCheck
()
{
if
(
TFS_PRIMARY_DISK
()
==
NULL
)
{
fError
(
"no primary disk is set"
);
terrno
=
TSDB_CODE_FS_NO_PRIMARY_DISK
;
return
-
1
;
}
for
(
int
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
for
(
int
32_t
level
=
0
;
level
<
TFS_NLEVEL
();
level
++
)
{
if
(
TIER_NDISKS
(
TFS_TIER_AT
(
level
))
==
0
)
{
fError
(
"no disk at level %d"
,
level
);
terrno
=
TSDB_CODE_FS_NO_MOUNT_AT_TIER
;
...
...
@@ -523,8 +523,8 @@ static int tfsCheck() {
static
SDisk
*
tfsGetDiskByID
(
SDiskID
did
)
{
return
TFS_DISK_AT
(
did
.
level
,
did
.
id
);
}
static
SDisk
*
tfsGetDiskByName
(
const
char
*
dir
)
{
SDiskID
did
;
SDisk
*
pDisk
=
NULL
;
void
*
pr
=
NULL
;
SDisk
*
pDisk
=
NULL
;
void
*
pr
=
NULL
;
pr
=
taosHashGet
(
pfs
->
map
,
(
void
*
)
dir
,
strnlen
(
dir
,
TSDB_FILENAME_LEN
));
if
(
pr
==
NULL
)
return
NULL
;
...
...
@@ -536,7 +536,7 @@ static SDisk *tfsGetDiskByName(const char *dir) {
return
pDisk
;
}
static
int
tfsOpendirImpl
(
TDIR
*
tdir
)
{
static
int
32_t
tfsOpendirImpl
(
TDIR
*
tdir
)
{
SDisk
*
pDisk
=
NULL
;
char
adir
[
TMPNAME_LEN
*
2
]
=
"
\0
"
;
...
...
@@ -567,8 +567,8 @@ static SDisk *tfsNextDisk(SDiskIter *pIter) {
if
(
pDisk
==
NULL
)
return
NULL
;
int
level
=
DISK_LEVEL
(
pDisk
);
int
id
=
DISK_ID
(
pDisk
);
int
32_t
level
=
DISK_LEVEL
(
pDisk
);
int
32_t
id
=
DISK_ID
(
pDisk
);
id
++
;
if
(
id
<
TIER_NDISKS
(
TFS_TIER_AT
(
level
)))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录