tsdbFile2.h 2.2 KB
Newer Older
H
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
Hongze Cheng 已提交
16 17
#include "tsdbDef.h"

H
Hongze Cheng 已提交
18 19 20 21 22 23 24
#ifndef _TSDB_FILE_H
#define _TSDB_FILE_H

#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
25 26
typedef struct STFile    STFile;
typedef struct STFileObj STFileObj;
H
Hongze Cheng 已提交
27

H
Hongze Cheng 已提交
28
typedef enum {
H
Hongze Cheng 已提交
29 30 31 32 33
  TSDB_FTYPE_HEAD = 0,                   // .head
  TSDB_FTYPE_DATA,                       // .data
  TSDB_FTYPE_SMA,                        // .sma
  TSDB_FTYPE_TOMB,                       // .tomb
  TSDB_FTYPE_STT = TSDB_FTYPE_TOMB + 2,  // .stt
H
Hongze Cheng 已提交
34
} tsdb_ftype_t;
H
Hongze Cheng 已提交
35

H
Hongze Cheng 已提交
36
enum {
H
Hongze Cheng 已提交
37 38
  TSDB_FSTATE_LIVE = 1,
  TSDB_FSTATE_DEAD,
H
Hongze Cheng 已提交
39 40
};

H
Hongze Cheng 已提交
41
#define TSDB_FTYPE_MIN TSDB_FTYPE_HEAD
H
Hongze Cheng 已提交
42 43
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)

H
Hongze Cheng 已提交
44
// STFile
H
Hongze Cheng 已提交
45 46
int32_t tsdbTFileToJson(const STFile *f, cJSON *json);
int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f);
H
Hongze Cheng 已提交
47
int32_t tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]);
H
Hongze Cheng 已提交
48 49
bool    tsdbIsSameTFile(const STFile *f1, const STFile *f2);
bool    tsdbIsTFileChanged(const STFile *f1, const STFile *f2);
H
Hongze Cheng 已提交
50

H
Hongze Cheng 已提交
51
// STFileObj
H
Hongze Cheng 已提交
52
int32_t tsdbTFileObjInit(STsdb *pTsdb, const STFile *f, STFileObj **fobj);
H
Hongze Cheng 已提交
53 54
int32_t tsdbTFileObjRef(STFileObj *fobj);
int32_t tsdbTFileObjUnref(STFileObj *fobj);
H
Hongze Cheng 已提交
55
int32_t tsdbTFileObjRemove(STFileObj *fobj);
H
Hongze Cheng 已提交
56
int32_t tsdbTFileObjCmpr(const STFileObj **fobj1, const STFileObj **fobj2);
H
Hongze Cheng 已提交
57

H
Hongze Cheng 已提交
58
struct STFile {
H
Hongze Cheng 已提交
59
  tsdb_ftype_t type;
H
Hongze Cheng 已提交
60
  SDiskID      did;  // disk id
H
Hongze Cheng 已提交
61 62
  int32_t      fid;  // file id
  int64_t      cid;  // commit id
H
Hongze Cheng 已提交
63
  int64_t      size;
H
Hongze Cheng 已提交
64 65
  union {
    struct {
H
Hongze Cheng 已提交
66
      int32_t level;
H
Hongze Cheng 已提交
67
    } stt[1];
H
Hongze Cheng 已提交
68 69
  };
};
H
Hongze Cheng 已提交
70

H
Hongze Cheng 已提交
71
struct STFileObj {
H
Hongze Cheng 已提交
72
  TdThreadMutex mutex;
H
Hongze Cheng 已提交
73
  STFile        f[1];
H
Hongze Cheng 已提交
74 75 76
  int32_t       state;
  int32_t       ref;
  char          fname[TSDB_FILENAME_LEN];
H
Hongze Cheng 已提交
77 78
};

H
Hongze Cheng 已提交
79 80 81 82 83
#ifdef __cplusplus
}
#endif

#endif /*_TSDB_FILE_H*/