tfsInt.h 2.7 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 27
#include "tfs.h"
#include "tglobal.h"
#include "thash.h"
#include "tlog.h"
H
refact  
Hongze Cheng 已提交
28

S
Shengliang Guan 已提交
29
extern int32_t fsDebugFlag;
H
Hongze Cheng 已提交
30

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

H
Hongze Cheng 已提交
39 40 41
// Global Definitions
#define TFS_MIN_DISK_FREE_SIZE 50 * 1024 * 1024

H
Hongze Cheng 已提交
42
typedef struct SDisk {
S
Shengliang Guan 已提交
43 44
  int32_t   level;
  int32_t   id;
45 46
  char     *path;
  SDiskSize size;
H
Hongze Cheng 已提交
47 48
} SDisk;

H
Hongze Cheng 已提交
49
typedef struct STier {
H
Hongze Cheng 已提交
50
  pthread_spinlock_t lock;
S
Shengliang Guan 已提交
51
  int32_t            level;
52 53 54
  int16_t            nextid;       // next disk id to allocate
  int16_t            ndisk;        // # of disks mounted to this tier
  int16_t            nAvailDisks;  // # of Available disks
S
Shengliang Guan 已提交
55
  SDisk             *disks[TSDB_MAX_DISKS_PER_TIER];
56
  SDiskSize          size;
H
Hongze Cheng 已提交
57
} STier;
H
refact  
Hongze Cheng 已提交
58

H
Hongze Cheng 已提交
59 60 61 62
#define TIER_LEVEL(pt) ((pt)->level)
#define TIER_NDISKS(pt) ((pt)->ndisk)
#define TIER_SIZE(pt) ((pt)->tmeta.size)
#define TIER_FREE_SIZE(pt) ((pt)->tmeta.free)
63

H
Hongze Cheng 已提交
64
#define DISK_AT_TIER(pt, id) ((pt)->disks[id])
65 66 67 68 69
#define DISK_DIR(pd) ((pd)->path)

SDisk  *tfsNewDisk(int32_t level, int32_t id, const char *dir);
SDisk  *tfsFreeDisk(SDisk *pDisk);
int32_t tfsUpdateDiskSize(SDisk *pDisk);
H
refact  
Hongze Cheng 已提交
70

S
Shengliang Guan 已提交
71 72 73
int32_t tfsInitTier(STier *pTier, int32_t level);
void    tfsDestroyTier(STier *pTier);
SDisk  *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg);
74
void    tfsUpdateTierSize(STier *pTier);
S
Shengliang Guan 已提交
75
int32_t tfsAllocDiskOnTier(STier *pTier);
S
Shengliang Guan 已提交
76
void    tfsPosNextId(STier *pTier);
H
refact  
Hongze Cheng 已提交
77

H
refact  
Hongze Cheng 已提交
78 79 80 81
#ifdef __cplusplus
}
#endif

82
#endif /*_TD_TFS_INT_H_*/