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 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
#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__); }}
S
Shengliang Guan 已提交
36 37
#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("TFS ", fsDebugFlag, __VA_ARGS__); }}
#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("TFS ", fsDebugFlag, __VA_ARGS__); }}
H
refact  
Hongze Cheng 已提交
38

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

S
Shengliang Guan 已提交
46
typedef struct {
H
Hongze Cheng 已提交
47
  pthread_spinlock_t lock;
S
Shengliang Guan 已提交
48
  int32_t            level;
S
Shengliang Guan 已提交
49 50 51 52 53 54 55 56 57 58 59 60
  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 已提交
61 62 63 64 65 66
  SDiskIter iter;
  SDiskID   did;
  char      dirname[TSDB_FILENAME_LEN];
  STfsFile  tfile;
  DIR      *dir;
  STfs     *pTfs;
S
Shengliang Guan 已提交
67 68 69 70
} STfsDir;

typedef struct STfs {
  pthread_spinlock_t lock;
71
  SDiskSize          size;
S
Shengliang Guan 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  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);

#define tfsLockTier(pTier) pthread_spin_lock(&(pTier)->lock)
#define tfsUnLockTier(pTier) pthread_spin_unlock(&(pTier)->lock)

#define tfsLock(pTfs) pthread_spin_lock(&(pTfs)->lock)
#define tfsUnLock(pTfs) pthread_spin_unlock(&(pTfs)->lock)

S
Shengliang Guan 已提交
94 95 96
#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 已提交
97

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

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

104
#endif /*_TD_TFS_INT_H_*/