tfsint.h 3.2 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/>.
 */

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

H
Hongze Cheng 已提交
19 20
#include "tlog.h"
#include "tglobal.h"
H
Hongze Cheng 已提交
21
#include "tfs.h"
H
Hongze Cheng 已提交
22
#include "tcoding.h"
H
Hongze Cheng 已提交
23

H
refact  
Hongze Cheng 已提交
24 25 26 27
#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
28 29
extern int fsDebugFlag;

H
refact  
Hongze Cheng 已提交
30
// For debug purpose
H
Hongze Cheng 已提交
31 32 33 34 35 36
#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 已提交
37

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

H
Hongze Cheng 已提交
41 42 43
// tdisk.c ======================================================
typedef struct {
  int64_t size;
44
  int64_t used;
H
Hongze Cheng 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
  int64_t free;
} SDiskMeta;

typedef struct SDisk {
  int       level;
  int       id;
  char      dir[TSDB_FILENAME_LEN];
  SDiskMeta dmeta;
} SDisk;

#define DISK_LEVEL(pd) ((pd)->level)
#define DISK_ID(pd) ((pd)->id)
#define DISK_DIR(pd) ((pd)->dir)
#define DISK_META(pd) ((pd)->dmeta)
#define DISK_SIZE(pd) ((pd)->dmeta.size)
60
#define DISK_USED_SIZE(pd) ((pd)->dmeta.used)
H
Hongze Cheng 已提交
61 62 63 64
#define DISK_FREE_SIZE(pd) ((pd)->dmeta.free)

SDisk *tfsNewDisk(int level, int id, const char *dir);
SDisk *tfsFreeDisk(SDisk *pDisk);
H
Hongze Cheng 已提交
65
int    tfsUpdateDiskInfo(SDisk *pDisk);
H
Hongze Cheng 已提交
66 67 68 69

// ttier.c ======================================================
typedef struct {
  int64_t size;
70
  int64_t used;
H
Hongze Cheng 已提交
71
  int64_t free;
H
Hongze Cheng 已提交
72
  int16_t nAvailDisks;  // # of Available disks
H
Hongze Cheng 已提交
73
} STierMeta;
H
Hongze Cheng 已提交
74
typedef struct STier {
H
Hongze Cheng 已提交
75 76 77 78 79 80
  pthread_spinlock_t lock;
  int                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];
H
Hongze Cheng 已提交
81
} STier;
H
refact  
Hongze Cheng 已提交
82

H
Hongze Cheng 已提交
83 84 85 86
#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)
H
Hongze Cheng 已提交
87
#define TIER_AVAIL_DISKS(pt) ((pt)->tmeta.nAvailDisks)
H
Hongze Cheng 已提交
88
#define DISK_AT_TIER(pt, id) ((pt)->disks[id])
H
refact  
Hongze Cheng 已提交
89

H
Hongze Cheng 已提交
90
int    tfsInitTier(STier *pTier, int level);
H
refact  
Hongze Cheng 已提交
91 92
void   tfsDestroyTier(STier *pTier);
SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg);
H
Hongze Cheng 已提交
93 94 95 96
void   tfsUpdateTierInfo(STier *pTier, STierMeta *pTierMeta);
int    tfsAllocDiskOnTier(STier *pTier);
void   tfsGetTierMeta(STier *pTier, STierMeta *pTierMeta);
void   tfsPosNextId(STier *pTier);
H
refact  
Hongze Cheng 已提交
97

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

102
#endif