tsdbUtil.h 4.8 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
  int32_t   numRec;
H
Hongze Cheng 已提交
51 52 53
  int32_t   size[TOMB_RECORD_ELEM_NUM];
  TABLEID   minTbid;
  TABLEID   maxTbid;
H
Hongze Cheng 已提交
54 55
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
56
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
57
} STombBlk;
H
Hongze Cheng 已提交
58

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

H
Hongze Cheng 已提交
61 62 63 64
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 已提交
65
int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record);
H
Hongze Cheng 已提交
66
int32_t tTombRecordCompare(const STombRecord *record1, const STombRecord *record2);
H
Hongze Cheng 已提交
67

H
Hongze Cheng 已提交
68
// STbStatisRecord ----------
H
Hongze Cheng 已提交
69
#define STATIS_RECORD_NUM_ELEM 7
H
Hongze Cheng 已提交
70
typedef union {
H
Hongze Cheng 已提交
71
  int64_t dataArr[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
72 73 74 75 76 77 78 79 80 81 82 83
  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 已提交
84
  TARRAY2(int64_t) dataArr[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
85 86 87 88 89 90 91
  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 已提交
92
    TARRAY2(int64_t) count[1];
H
Hongze Cheng 已提交
93 94 95
  };
} STbStatisBlock;

H
Hongze Cheng 已提交
96
typedef struct {
H
Hongze Cheng 已提交
97
  int32_t   numRec;
H
Hongze Cheng 已提交
98
  int32_t   size[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
99 100
  TABLEID   minTbid;
  TABLEID   maxTbid;
H
Hongze Cheng 已提交
101 102
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
103
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
104
} SStatisBlk;
H
Hongze Cheng 已提交
105 106 107 108

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

int32_t tStatisBlockInit(STbStatisBlock *statisBlock);
H
Hongze Cheng 已提交
109
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock);
H
Hongze Cheng 已提交
110
int32_t tStatisBlockClear(STbStatisBlock *statisBlock);
H
Hongze Cheng 已提交
111
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, const STbStatisRecord *record);
H
Hongze Cheng 已提交
112 113 114 115 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
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 {
  TABLEID   minTbid;
  TABLEID   maxTbid;
H
Hongze Cheng 已提交
166 167
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
168 169 170 171 172 173 174 175 176 177
  SFDataPtr dp[1];
} SBrinBlk;

#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 已提交
178 179 180 181

// 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 已提交
182 183 184 185 186 187

#ifdef __cplusplus
}
#endif

#endif /*_TSDB_UTIL_H*/