tfsInt.h 3.3 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

16 17
#ifndef _TD_TFS_INT_H_
#define _TD_TFS_INT_H_
H
refact  
Hongze Cheng 已提交
18

S
Shengliang Guan 已提交
19 20
#include "os.h"

S
Shengliang Guan 已提交
21
#include "taosdef.h"
S
Shengliang Guan 已提交
22
#include "taoserror.h"
H
Hongze Cheng 已提交
23
#include "tcoding.h"
S
Shengliang Guan 已提交
24 25 26
#include "tfs.h"
#include "thash.h"
#include "tlog.h"
H
refact  
Hongze Cheng 已提交
27

H
refact  
Hongze Cheng 已提交
28
// For debug purpose
H
Hongze Cheng 已提交
29
// clang-format off
30 31 32 33 34 35
#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("TFS ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
#define fWarn(...)  { if (fsDebugFlag & DEBUG_WARN)  { taosPrintLog("TFS WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
#define fInfo(...)  { if (fsDebugFlag & DEBUG_INFO)  { taosPrintLog("TFS ", DEBUG_INFO, 255, __VA_ARGS__); }}
#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("TFS ", DEBUG_DEBUG, fsDebugFlag, __VA_ARGS__); }}
#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("TFS ", DEBUG_TRACE, fsDebugFlag, __VA_ARGS__); }}
H
Hongze Cheng 已提交
36
// clang-format on
H
refact  
Hongze Cheng 已提交
37

S
Shengliang Guan 已提交
38
typedef struct {
S
Shengliang Guan 已提交
39 40
  int32_t   level;
  int32_t   id;
41 42
  char     *path;
  SDiskSize size;
S
Shengliang Guan 已提交
43
} STfsDisk;
H
Hongze Cheng 已提交
44

S
Shengliang Guan 已提交
45
typedef struct {
wafwerar's avatar
wafwerar 已提交
46
  TdThreadSpinlock lock;
H
Hongze Cheng 已提交
47 48 49 50 51 52
  int32_t          level;
  int32_t          nextid;       // next disk id to allocate
  int32_t          ndisk;        // # of disks mounted to this tier
  int32_t          nAvailDisks;  // # of Available disks
  STfsDisk        *disks[TFS_MAX_DISKS_PER_TIER];
  SDiskSize        size;
S
Shengliang Guan 已提交
53 54 55 56 57 58 59
} STfsTier;

typedef struct {
  STfsDisk *pDisk;
} SDiskIter;

typedef struct STfsDir {
S
Shengliang Guan 已提交
60 61
  SDiskIter iter;
  SDiskID   did;
C
Cary Xu 已提交
62
  char      dirName[TSDB_FILENAME_LEN];
S
Shengliang Guan 已提交
63
  STfsFile  tfile;
wafwerar's avatar
wafwerar 已提交
64
  TdDirPtr  pDir;
S
Shengliang Guan 已提交
65
  STfs     *pTfs;
S
Shengliang Guan 已提交
66 67 68
} STfsDir;

typedef struct STfs {
wafwerar's avatar
wafwerar 已提交
69
  TdThreadSpinlock lock;
H
Hongze Cheng 已提交
70 71 72 73
  SDiskSize        size;
  int32_t          nlevel;
  STfsTier         tiers[TFS_MAX_TIERS];
  SHashObj        *hash;  // name to did map
S
Shengliang Guan 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86
} STfs;

STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *dir);
STfsDisk *tfsFreeDisk(STfsDisk *pDisk);
int32_t   tfsUpdateDiskSize(STfsDisk *pDisk);

int32_t   tfsInitTier(STfsTier *pTier, int32_t level);
void      tfsDestroyTier(STfsTier *pTier);
STfsDisk *tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg);
void      tfsUpdateTierSize(STfsTier *pTier);
int32_t   tfsAllocDiskOnTier(STfsTier *pTier);
void      tfsPosNextId(STfsTier *pTier);

H
Hongze Cheng 已提交
87
#define tfsLockTier(pTier)   taosThreadSpinLock(&(pTier)->lock)
wafwerar's avatar
wafwerar 已提交
88
#define tfsUnLockTier(pTier) taosThreadSpinUnlock(&(pTier)->lock)
S
Shengliang Guan 已提交
89

H
Hongze Cheng 已提交
90
#define tfsLock(pTfs)   taosThreadSpinLock(&(pTfs)->lock)
wafwerar's avatar
wafwerar 已提交
91
#define tfsUnLock(pTfs) taosThreadSpinUnlock(&(pTfs)->lock)
S
Shengliang Guan 已提交
92

S
Shengliang Guan 已提交
93
#define TFS_TIER_AT(pTfs, level) (&(pTfs)->tiers[level])
H
Hongze Cheng 已提交
94 95
#define TFS_DISK_AT(pTfs, did)   ((pTfs)->tiers[(did).level].disks[(did).id])
#define TFS_PRIMARY_DISK(pTfs)   ((pTfs)->tiers[0].disks[0])
H
refact  
Hongze Cheng 已提交
96

S
Shengliang Guan 已提交
97
#define TMPNAME_LEN (TSDB_FILENAME_LEN * 2 + 32)
98

H
refact  
Hongze Cheng 已提交
99 100 101 102
#ifdef __cplusplus
}
#endif

103
#endif /*_TD_TFS_INT_H_*/