Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9e4141fa
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看板
提交
9e4141fa
编写于
1月 12, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add error codes
上级
ba42f8cd
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
55 deletion
+64
-55
include/util/taoserror.h
include/util/taoserror.h
+1
-1
source/libs/tfs/inc/tfsInt.h
source/libs/tfs/inc/tfsInt.h
+13
-14
source/libs/tfs/src/tfsDisk.c
source/libs/tfs/src/tfsDisk.c
+6
-7
source/libs/tfs/src/tfsTier.c
source/libs/tfs/src/tfsTier.c
+43
-32
source/util/src/terror.c
source/util/src/terror.c
+1
-1
未找到文件。
include/util/taoserror.h
浏览文件 @
9e4141fa
...
...
@@ -406,7 +406,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004) //"WAL out of memory")
// tfs
#define TSDB_CODE_FS_
OUT_OF_MEMORY
TAOS_DEF_ERROR_CODE(0, 0x2200) //"tfs out of memory")
#define TSDB_CODE_FS_
APP_ERROR
TAOS_DEF_ERROR_CODE(0, 0x2200) //"tfs out of memory")
#define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201) //"tfs invalid mount config")
#define TSDB_CODE_FS_TOO_MANY_MOUNT TAOS_DEF_ERROR_CODE(0, 0x2202) //"tfs too many mount")
#define TSDB_CODE_FS_DUP_PRIMARY TAOS_DEF_ERROR_CODE(0, 0x2203) //"tfs duplicate primary mount")
...
...
source/libs/tfs/inc/tfsInt.h
浏览文件 @
9e4141fa
...
...
@@ -26,7 +26,7 @@
#include "thash.h"
#include "tlog.h"
extern
int
fsDebugFlag
;
extern
int
32_t
fsDebugFlag
;
// For debug purpose
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", 255, __VA_ARGS__); }}
...
...
@@ -47,8 +47,8 @@ typedef struct {
}
SDiskMeta
;
typedef
struct
SDisk
{
int
level
;
int
id
;
int
32_t
level
;
int
32_t
id
;
char
dir
[
TSDB_FILENAME_LEN
];
SDiskMeta
dmeta
;
}
SDisk
;
...
...
@@ -61,19 +61,19 @@ typedef struct SDisk {
#define DISK_USED_SIZE(pd) ((pd)->dmeta.used)
#define DISK_FREE_SIZE(pd) ((pd)->dmeta.free)
SDisk
*
tfsNewDisk
(
int
level
,
in
t
id
,
const
char
*
dir
);
SDisk
*
tfsFreeDisk
(
SDisk
*
pDisk
);
int
tfsUpdateDiskInfo
(
SDisk
*
pDisk
);
SDisk
*
tfsNewDisk
(
int32_t
level
,
int32_
t
id
,
const
char
*
dir
);
SDisk
*
tfsFreeDisk
(
SDisk
*
pDisk
);
int
32_t
tfsUpdateDiskInfo
(
SDisk
*
pDisk
);
// ttier.c ======================================================
typedef
struct
STier
{
pthread_spinlock_t
lock
;
int
level
;
int
32_t
level
;
int16_t
ndisk
;
// # of disks mounted to this tier
int16_t
nextid
;
// next disk id to allocate
STierMeta
tmeta
;
SDisk
*
disks
[
TSDB_MAX_DISKS_PER_TIER
];
SDisk
*
disks
[
TSDB_MAX_DISKS_PER_TIER
];
}
STier
;
#define TIER_LEVEL(pt) ((pt)->level)
...
...
@@ -83,12 +83,11 @@ typedef struct STier {
#define TIER_AVAIL_DISKS(pt) ((pt)->tmeta.nAvailDisks)
#define DISK_AT_TIER(pt, id) ((pt)->disks[id])
int
tfsInitTier
(
STier
*
pTier
,
int
level
);
void
tfsDestroyTier
(
STier
*
pTier
);
SDisk
*
tfsMountDiskToTier
(
STier
*
pTier
,
SDiskCfg
*
pCfg
);
void
tfsUpdateTierInfo
(
STier
*
pTier
,
STierMeta
*
pTierMeta
);
int
tfsAllocDiskOnTier
(
STier
*
pTier
);
void
tfsGetTierMeta
(
STier
*
pTier
,
STierMeta
*
pTierMeta
);
int32_t
tfsInitTier
(
STier
*
pTier
,
int32_t
level
);
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
);
#ifdef __cplusplus
...
...
source/libs/tfs/src/tfsDisk.c
浏览文件 @
9e4141fa
...
...
@@ -19,7 +19,7 @@
SDisk
*
tfsNewDisk
(
int32_t
level
,
int32_t
id
,
const
char
*
dir
)
{
SDisk
*
pDisk
=
calloc
(
1
,
sizeof
(
SDisk
));
if
(
pDisk
==
NULL
)
{
terrno
=
TSDB_CODE_
FS_
OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
...
...
@@ -34,6 +34,7 @@ SDisk *tfsFreeDisk(SDisk *pDisk) {
if
(
pDisk
!=
NULL
)
{
free
(
pDisk
);
}
return
NULL
;
}
...
...
@@ -44,17 +45,15 @@ int32_t tfsUpdateDiskInfo(SDisk *pDisk) {
}
SysDiskSize
diskSize
=
{
0
};
int32_t
code
=
taosGetDiskSize
(
pDisk
->
dir
,
&
diskSize
);
if
(
code
!=
0
)
{
if
(
taosGetDiskSize
(
pDisk
->
dir
,
&
diskSize
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
fError
(
"failed to update disk information at level %d id %d dir %s since %s"
,
pDisk
->
level
,
pDisk
->
id
,
pDisk
->
dir
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
}
pDisk
->
dmeta
.
size
=
diskSize
.
tsize
;
pDisk
->
dmeta
.
used
=
diskSize
.
used
;
pDisk
->
dmeta
.
free
=
diskSize
.
avail
;
return
code
;
return
0
;
}
source/libs/tfs/src/tfsTier.c
浏览文件 @
9e4141fa
...
...
@@ -16,45 +16,50 @@
#define _DEFAULT_SOURCE
#include "tfsInt.h"
#define tfsLockTier(pTier) pthread_spin_lock(&(
(pTier)->lock)
)
#define tfsUnLockTier(pTier) pthread_spin_unlock(&(
(pTier)->lock)
)
#define tfsLockTier(pTier) pthread_spin_lock(&(
pTier)->lock
)
#define tfsUnLockTier(pTier) pthread_spin_unlock(&(
pTier)->lock
)
// PROTECTED ==========================================
int
tfsInitTier
(
STier
*
pTier
,
int
level
)
{
memset
((
void
*
)
pTier
,
0
,
sizeof
(
*
pTier
));
int32_t
tfsInitTier
(
STier
*
pTier
,
int32_t
level
)
{
if
(
pTier
==
NULL
)
{
terrno
=
TSDB_CODE_INVALID_PARA
;
return
-
1
;
}
memset
(
pTier
,
0
,
sizeof
(
STier
));
int
code
=
pthread_spin_init
(
&
(
pTier
->
lock
)
,
0
);
if
(
code
)
{
int
32_t
code
=
pthread_spin_init
(
&
pTier
->
lock
,
0
);
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
pTier
->
level
=
level
;
return
0
;
}
void
tfsDestroyTier
(
STier
*
pTier
)
{
for
(
int
id
=
0
;
id
<
TSDB_MAX_DISKS_PER_TIER
;
id
++
)
{
if
(
pTier
==
NULL
)
return
;
for
(
int32_t
id
=
0
;
id
<
TSDB_MAX_DISKS_PER_TIER
;
id
++
)
{
DISK_AT_TIER
(
pTier
,
id
)
=
tfsFreeDisk
(
DISK_AT_TIER
(
pTier
,
id
));
}
pTier
->
ndisk
=
0
;
pthread_spin_destroy
(
&
(
pTier
->
lock
));
}
SDisk
*
tfsMountDiskToTier
(
STier
*
pTier
,
SDiskCfg
*
pCfg
)
{
ASSERT
(
pTier
->
level
==
pCfg
->
level
);
int
id
=
0
;
SDisk
*
pDisk
;
if
(
pTier
==
NULL
||
pCfg
==
NULL
||
pTier
->
level
!=
pCfg
->
level
)
{
terrno
=
TSDB_CODE_INVALID_PARA
;
return
-
1
;
}
if
(
TIER_NDISKS
(
pTier
)
>=
TSDB_MAX_DISKS_PER_TIER
)
{
terrno
=
TSDB_CODE_FS_TOO_MANY_MOUNT
;
return
NULL
;
}
int32_t
id
=
0
;
if
(
pTier
->
level
==
0
)
{
if
(
DISK_AT_TIER
(
pTier
,
0
)
!=
NULL
)
{
id
=
pTier
->
ndisk
;
...
...
@@ -73,30 +78,31 @@ SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg) {
id
=
pTier
->
ndisk
;
}
pDisk
=
tfsNewDisk
(
pCfg
->
level
,
id
,
pCfg
->
dir
);
SDisk
*
pDisk
=
tfsNewDisk
(
pCfg
->
level
,
id
,
pCfg
->
dir
);
if
(
pDisk
==
NULL
)
return
NULL
;
DISK_AT_TIER
(
pTier
,
id
)
=
pDisk
;
pTier
->
ndisk
++
;
fInfo
(
"disk %s is mounted to tier level %d id %d"
,
pCfg
->
dir
,
pCfg
->
level
,
id
);
return
DISK_AT_TIER
(
pTier
,
id
);
}
void
tfsUpdateTierInfo
(
STier
*
pTier
,
STierMeta
*
pTierMeta
)
{
STierMeta
tmeta
;
STierMeta
tmeta
=
{
0
}
;
if
(
pTierMeta
==
NULL
)
{
pTierMeta
=
&
tmeta
;
}
memset
(
pTierMeta
,
0
,
sizeof
(
*
p
TierMeta
));
memset
(
pTierMeta
,
0
,
sizeof
(
S
TierMeta
));
tfsLockTier
(
pTier
);
for
(
int
id
=
0
;
id
<
pTier
->
ndisk
;
id
++
)
{
if
(
tfsUpdateDiskInfo
(
DISK_AT_TIER
(
pTier
,
id
))
<
0
)
{
for
(
int
32_t
id
=
0
;
id
<
pTier
->
ndisk
;
id
++
)
{
if
(
tfsUpdateDiskInfo
(
DISK_AT_TIER
(
pTier
,
id
))
!=
0
)
{
continue
;
}
pTierMeta
->
size
+=
DISK_SIZE
(
DISK_AT_TIER
(
pTier
,
id
));
pTierMeta
->
used
+=
DISK_USED_SIZE
(
DISK_AT_TIER
(
pTier
,
id
));
pTierMeta
->
free
+=
DISK_FREE_SIZE
(
DISK_AT_TIER
(
pTier
,
id
));
...
...
@@ -109,22 +115,26 @@ void tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta) {
}
// Round-Robin to allocate disk on a tier
int
tfsAllocDiskOnTier
(
STier
*
pTier
)
{
ASSERT
(
pTier
->
ndisk
>
0
);
int
id
=
TFS_UNDECIDED_ID
;
SDisk
*
pDisk
;
int32_t
tfsAllocDiskOnTier
(
STier
*
pTier
)
{
if
(
pTier
==
NULL
||
pTier
->
ndisk
<=
0
)
{
terrno
=
TSDB_CODE_INVALID_PARA
;
return
-
1
;
}
tfsLockTier
(
pTier
);
if
(
TIER_AVAIL_DISKS
(
pTier
)
<=
0
)
{
tfsUnLockTier
(
pTier
);
return
id
;
return
TFS_UNDECIDED_ID
;
}
id
=
pTier
->
nextid
;
i
nt32_t
i
d
=
pTier
->
nextid
;
while
(
true
)
{
pDisk
=
DISK_AT_TIER
(
pTier
,
id
);
ASSERT
(
pDisk
!=
NULL
);
SDisk
*
pDisk
=
DISK_AT_TIER
(
pTier
,
id
);
if
(
pDisk
==
NULL
)
{
tfsUnLockTier
(
pTier
);
return
TFS_UNDECIDED_ID
;
}
if
(
DISK_FREE_SIZE
(
pDisk
)
<
TFS_MIN_DISK_FREE_SIZE
)
{
id
=
(
id
+
1
)
%
pTier
->
ndisk
;
...
...
@@ -145,7 +155,7 @@ int tfsAllocDiskOnTier(STier *pTier) {
}
void
tfsGetTierMeta
(
STier
*
pTier
,
STierMeta
*
pTierMeta
)
{
ASSERT
(
pTierMeta
!=
NULL
)
;
if
(
pTierMeta
==
NULL
||
pTierMeta
==
NULL
)
return
;
tfsLockTier
(
pTier
);
*
pTierMeta
=
pTier
->
tmeta
;
...
...
@@ -153,10 +163,11 @@ void tfsGetTierMeta(STier *pTier, STierMeta *pTierMeta) {
}
void
tfsPosNextId
(
STier
*
pTier
)
{
ASSERT
(
pTier
->
ndisk
>
0
);
int
nextid
=
0
;
if
(
pTier
==
NULL
||
pTier
->
ndisk
<=
0
)
return
;
int32_t
nextid
=
0
;
for
(
int
id
=
1
;
id
<
pTier
->
ndisk
;
id
++
)
{
for
(
int
32_t
id
=
1
;
id
<
pTier
->
ndisk
;
id
++
)
{
SDisk
*
pLDisk
=
DISK_AT_TIER
(
pTier
,
nextid
);
SDisk
*
pDisk
=
DISK_AT_TIER
(
pTier
,
id
);
if
(
DISK_FREE_SIZE
(
pDisk
)
>
TFS_MIN_DISK_FREE_SIZE
&&
DISK_FREE_SIZE
(
pDisk
)
>
DISK_FREE_SIZE
(
pLDisk
))
{
...
...
source/util/src/terror.c
浏览文件 @
9e4141fa
...
...
@@ -387,7 +387,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_WAL_FILE_CORRUPTED, "WAL file is corrupted
TAOS_DEFINE_ERROR
(
TSDB_CODE_WAL_SIZE_LIMIT
,
"WAL size exceeds limit"
)
// tfs
TAOS_DEFINE_ERROR
(
TSDB_CODE_FS_
OUT_OF_MEMORY
,
"tfs out of memory"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_FS_
APP_ERROR
,
"tfs out of memory"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_FS_INVLD_CFG
,
"tfs invalid mount config"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_FS_TOO_MANY_MOUNT
,
"tfs too many mount"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_FS_DUP_PRIMARY
,
"tfs duplicate primary mount"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录