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
29 30 31 32 33 34
#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
refact  
Hongze Cheng 已提交
35

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

S
Shengliang Guan 已提交
43
typedef struct {
wafwerar's avatar
wafwerar 已提交
44
  TdThreadSpinlock lock;
S
Shengliang Guan 已提交
45
  int32_t            level;
S
Shengliang Guan 已提交
46 47 48 49 50 51 52 53 54 55 56 57
  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;
} STfsTier;

typedef struct {
  STfsDisk *pDisk;
} SDiskIter;

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

typedef struct STfs {
wafwerar's avatar
wafwerar 已提交
67
  TdThreadSpinlock lock;
68
  SDiskSize          size;
S
Shengliang Guan 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  int32_t            nlevel;
  STfsTier           tiers[TFS_MAX_TIERS];
  SHashObj          *hash;  // name to did map
} 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);

wafwerar's avatar
wafwerar 已提交
85 86
#define tfsLockTier(pTier) taosThreadSpinLock(&(pTier)->lock)
#define tfsUnLockTier(pTier) taosThreadSpinUnlock(&(pTier)->lock)
S
Shengliang Guan 已提交
87

wafwerar's avatar
wafwerar 已提交
88 89
#define tfsLock(pTfs) taosThreadSpinLock(&(pTfs)->lock)
#define tfsUnLock(pTfs) taosThreadSpinUnlock(&(pTfs)->lock)
S
Shengliang Guan 已提交
90

S
Shengliang Guan 已提交
91 92 93
#define TFS_TIER_AT(pTfs, level) (&(pTfs)->tiers[level])
#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 已提交
94

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

H
refact  
Hongze Cheng 已提交
97 98 99 100
#ifdef __cplusplus
}
#endif

101
#endif /*_TD_TFS_INT_H_*/