tsdbFile.h 2.2 KB
Newer Older
H
more  
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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
more  
Hongze Cheng 已提交
15 16 17
#if !defined(_TD_TSDB_FILE_H_)
#define _TD_TSDB_FILE_H_

H
more  
hzcheng 已提交
18
#include <stdint.h>
H
hzcheng 已提交
19 20

#include "taosdef.h"
H
TD-34  
hzcheng 已提交
21
#include "tglobalcfg.h"
H
more  
Hongze Cheng 已提交
22

H
more  
hzcheng 已提交
23 24 25 26
#ifdef __cplusplus
extern "C" {
#endif

H
TD-34  
hzcheng 已提交
27 28 29
#define tsdbGetKeyFileId(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
#define tsdbGetMaxNumOfFiles(keep, daysPerFile) ((keep) / (daysPerFile) + 3)

H
Hongze Cheng 已提交
30
typedef enum {
H
TD-34  
hzcheng 已提交
31 32 33 34
  TSDB_FILE_TYPE_HEAD = 0,  // .head file type
  TSDB_FILE_TYPE_DATA,      // .data file type
  TSDB_FILE_TYPE_LAST,      // .last file type
  TSDB_FILE_TYPE_MAX
H
more  
Hongze Cheng 已提交
35 36
} TSDB_FILE_TYPE;

H
more  
hzcheng 已提交
37
extern const char *tsdbFileSuffix[];
H
Hongze Cheng 已提交
38

H
more  
Hongze Cheng 已提交
39
typedef struct {
H
hzcheng 已提交
40 41
  int64_t size;
  int64_t tombSize;
H
more  
Hongze Cheng 已提交
42 43 44
} SFileInfo;

typedef struct {
H
TD-34  
hzcheng 已提交
45 46 47 48
  int8_t  type;
  char    fname[128];
  int64_t size;      // total size of the file
  int64_t tombSize;  // unused file size
H
hzcheng 已提交
49
} SFile;
H
more  
Hongze Cheng 已提交
50

H
hzcheng 已提交
51 52
typedef struct {
  int32_t fileId;
H
TD-34  
hzcheng 已提交
53
  SFile   files[TSDB_FILE_TYPE_MAX];
H
hzcheng 已提交
54 55 56 57 58 59 60 61
} SFileGroup;

// TSDB file handle
typedef struct {
  int32_t    daysPerFile;
  int32_t    keep;
  int32_t    minRowPerFBlock;
  int32_t    maxRowsPerFBlock;
H
TD-34  
hzcheng 已提交
62
  int32_t    maxTables;
H
hzcheng 已提交
63 64
  SFileGroup fGroup[];
} STsdbFileH;
H
more  
Hongze Cheng 已提交
65

H
TD-34  
hzcheng 已提交
66
#define IS_VALID_TSDB_FILE_TYPE(type) ((type) >= TSDB_FILE_TYPE_HEAD && (type) < TSDB_FILE_TYPE_MAX)
H
hzcheng 已提交
67

H
hzcheng 已提交
68
STsdbFileH *tsdbInitFile(char *dataDir, int32_t daysPerFile, int32_t keep, int32_t minRowsPerFBlock,
H
TD-34  
hzcheng 已提交
69 70 71 72
                         int32_t maxRowsPerFBlock, int32_t maxTables);

void  tsdbCloseFile(STsdbFileH *pFileH);
int   tsdbCreateFileGroup(char *dataDir, int fileId, SFileGroup *pFGroup, int maxTables);
H
TD-34  
hzcheng 已提交
73
void  tsdbGetKeyRangeOfFileId(int32_t daysPerFile, int8_t precision, int32_t fileId, TSKEY *minKey, TSKEY *maxKey);
H
more  
hzcheng 已提交
74 75 76 77
#ifdef __cplusplus
}
#endif

H
more  
Hongze Cheng 已提交
78
#endif  // _TD_TSDB_FILE_H_