tsdbUtil.h 5.0 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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/>.
 */

#ifndef _TSDB_UTIL_H
#define _TSDB_UTIL_H

H
Hongze Cheng 已提交
19
#include "tsdbDef.h"
H
Hongze Cheng 已提交
20

H
Hongze Cheng 已提交
21 22 23 24
#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
25 26
// STombRecord ----------
#define TOMB_RECORD_ELEM_NUM 5
H
Hongze Cheng 已提交
27
typedef union {
H
Hongze Cheng 已提交
28
  int64_t dataArr[TOMB_RECORD_ELEM_NUM];
H
Hongze Cheng 已提交
29 30 31 32 33 34 35
  struct {
    int64_t suid;
    int64_t uid;
    int64_t version;
    int64_t skey;
    int64_t ekey;
  };
H
Hongze Cheng 已提交
36
} STombRecord;
H
Hongze Cheng 已提交
37

H
Hongze Cheng 已提交
38
typedef union {
H
Hongze Cheng 已提交
39
  TARRAY2(int64_t) dataArr[TOMB_RECORD_ELEM_NUM];
H
Hongze Cheng 已提交
40
  struct {
H
Hongze Cheng 已提交
41 42 43 44 45
    TARRAY2(int64_t) suid[1];
    TARRAY2(int64_t) uid[1];
    TARRAY2(int64_t) version[1];
    TARRAY2(int64_t) skey[1];
    TARRAY2(int64_t) ekey[1];
H
Hongze Cheng 已提交
46
  };
H
Hongze Cheng 已提交
47
} STombBlock;
H
Hongze Cheng 已提交
48

H
Hongze Cheng 已提交
49
typedef struct {
H
Hongze Cheng 已提交
50
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
51 52
  TABLEID   minTbid;
  TABLEID   maxTbid;
H
Hongze Cheng 已提交
53 54
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
55 56 57 58
  int32_t   numRec;
  int32_t   size[TOMB_RECORD_ELEM_NUM];
  int8_t    cmprAlg;
  int8_t    rsvd[7];
H
Hongze Cheng 已提交
59
} STombBlk;
H
Hongze Cheng 已提交
60

H
Hongze Cheng 已提交
61
#define TOMB_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)
H
Hongze Cheng 已提交
62

H
Hongze Cheng 已提交
63 64 65 66
int32_t tTombBlockInit(STombBlock *tombBlock);
int32_t tTombBlockDestroy(STombBlock *tombBlock);
int32_t tTombBlockClear(STombBlock *tombBlock);
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record);
H
Hongze Cheng 已提交
67
int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record);
H
Hongze Cheng 已提交
68
int32_t tTombRecordCompare(const STombRecord *record1, const STombRecord *record2);
H
Hongze Cheng 已提交
69

H
Hongze Cheng 已提交
70
// STbStatisRecord ----------
H
Hongze Cheng 已提交
71
#define STATIS_RECORD_NUM_ELEM 7
H
Hongze Cheng 已提交
72
typedef union {
H
Hongze Cheng 已提交
73
  int64_t dataArr[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
74 75 76 77 78 79 80 81 82 83 84 85
  struct {
    int64_t suid;
    int64_t uid;
    int64_t firstKey;
    int64_t lastKey;
    int64_t minVer;
    int64_t maxVer;
    int64_t count;
  };
} STbStatisRecord;

typedef union {
H
Hongze Cheng 已提交
86
  TARRAY2(int64_t) dataArr[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
87 88 89 90 91 92 93
  struct {
    TARRAY2(int64_t) suid[1];
    TARRAY2(int64_t) uid[1];
    TARRAY2(int64_t) firstKey[1];
    TARRAY2(int64_t) lastKey[1];
    TARRAY2(int64_t) minVer[1];
    TARRAY2(int64_t) maxVer[1];
H
Hongze Cheng 已提交
94
    TARRAY2(int64_t) count[1];
H
Hongze Cheng 已提交
95 96 97
  };
} STbStatisBlock;

H
Hongze Cheng 已提交
98
typedef struct {
H
Hongze Cheng 已提交
99
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
100 101
  TABLEID   minTbid;
  TABLEID   maxTbid;
H
Hongze Cheng 已提交
102 103
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
104 105 106 107
  int32_t   numRec;
  int32_t   size[STATIS_RECORD_NUM_ELEM];
  int8_t    cmprAlg;
  int8_t    rsvd[7];
H
Hongze Cheng 已提交
108
} SStatisBlk;
H
Hongze Cheng 已提交
109 110 111 112

#define STATIS_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)

int32_t tStatisBlockInit(STbStatisBlock *statisBlock);
H
Hongze Cheng 已提交
113
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock);
H
Hongze Cheng 已提交
114
int32_t tStatisBlockClear(STbStatisBlock *statisBlock);
H
Hongze Cheng 已提交
115
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, const STbStatisRecord *record);
H
Hongze Cheng 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record);

// SBrinRecord ----------
typedef union {
  struct {
    int64_t dataArr1[10];
    int32_t dataArr2[5];
  };
  struct {
    int64_t suid;
    int64_t uid;
    int64_t firstKey;
    int64_t firstKeyVer;
    int64_t lastKey;
    int64_t lastKeyVer;
    int64_t minVer;
    int64_t maxVer;
    int64_t blockOffset;
    int64_t smaOffset;
    int32_t blockSize;
    int32_t blockKeySize;
    int32_t smaSize;
    int32_t numRow;
    int32_t count;
  };
} SBrinRecord;

typedef union {
  struct {
    TARRAY2(int64_t) dataArr1[10];
    TARRAY2(int32_t) dataArr2[5];
  };
  struct {
    TARRAY2(int64_t) suid[1];
    TARRAY2(int64_t) uid[1];
    TARRAY2(int64_t) firstKey[1];
    TARRAY2(int64_t) firstKeyVer[1];
    TARRAY2(int64_t) lastKey[1];
    TARRAY2(int64_t) lastKeyVer[1];
    TARRAY2(int64_t) minVer[1];
    TARRAY2(int64_t) maxVer[1];
    TARRAY2(int64_t) blockOffset[1];
    TARRAY2(int64_t) smaOffset[1];
    TARRAY2(int32_t) blockSize[1];
    TARRAY2(int32_t) blockKeySize[1];
    TARRAY2(int32_t) smaSize[1];
    TARRAY2(int32_t) numRow[1];
    TARRAY2(int32_t) count[1];
  };
} SBrinBlock;

typedef struct {
H
Hongze Cheng 已提交
168
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
169 170
  TABLEID   minTbid;
  TABLEID   maxTbid;
H
Hongze Cheng 已提交
171 172
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
173 174 175 176
  int32_t   numRec;
  int32_t   size[15];
  int8_t    cmprAlg;
  int8_t    rsvd[7];
H
Hongze Cheng 已提交
177 178
} SBrinBlk;

H
Hongze Cheng 已提交
179 180
typedef TARRAY2(SBrinBlk) TBrinBlkArray;

H
Hongze Cheng 已提交
181 182 183 184 185 186 187
#define BRIN_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)

int32_t tBrinBlockInit(SBrinBlock *brinBlock);
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock);
int32_t tBrinBlockClear(SBrinBlock *brinBlock);
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record);
int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record);
H
Hongze Cheng 已提交
188 189 190 191

// other apis
int32_t tsdbUpdateSkmTb(STsdb *pTsdb, const TABLEID *tbid, SSkmInfo *pSkmTb);
int32_t tsdbUpdateSkmRow(STsdb *pTsdb, const TABLEID *tbid, int32_t sver, SSkmInfo *pSkmRow);
H
Hongze Cheng 已提交
192 193 194 195 196 197

#ifdef __cplusplus
}
#endif

#endif /*_TSDB_UTIL_H*/