tsdbUtil.h 3.1 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
// SDelBlock ----------
H
Hongze Cheng 已提交
26

H
Hongze Cheng 已提交
27
#define DEL_RECORD_NUM_ELEM 5
H
Hongze Cheng 已提交
28
typedef union {
H
Hongze Cheng 已提交
29
  int64_t aData[DEL_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
30 31 32 33 34 35 36 37
  struct {
    int64_t suid;
    int64_t uid;
    int64_t version;
    int64_t skey;
    int64_t ekey;
  };
} SDelRecord;
H
Hongze Cheng 已提交
38

H
Hongze Cheng 已提交
39
typedef union {
H
Hongze Cheng 已提交
40
  TARRAY2(int64_t) dataArr[DEL_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
41
  struct {
H
Hongze Cheng 已提交
42 43 44 45 46
    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 已提交
47 48
  };
} SDelBlock;
H
Hongze Cheng 已提交
49

H
Hongze Cheng 已提交
50
typedef struct SDelBlk {
H
Hongze Cheng 已提交
51
  int32_t   numRec;
H
Hongze Cheng 已提交
52
  int32_t   size[DEL_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
53 54 55 56
  TABLEID   minTid;
  TABLEID   maxTid;
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
57
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
58 59
} SDelBlk;

H
Hongze Cheng 已提交
60
#define DEL_BLOCK_SIZE(db) TARRAY2_SIZE((db)->suid)
H
Hongze Cheng 已提交
61 62 63 64 65 66 67

int32_t tDelBlockInit(SDelBlock *delBlock);
int32_t tDelBlockFree(SDelBlock *delBlock);
int32_t tDelBlockClear(SDelBlock *delBlock);
int32_t tDelBlockPut(SDelBlock *delBlock, const SDelRecord *delRecord);

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

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

H
Hongze Cheng 已提交
99
typedef struct SStatisBlk {
H
Hongze Cheng 已提交
100
  int32_t   numRec;
H
Hongze Cheng 已提交
101
  int32_t   size[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
102 103
  TABLEID   minTbid;
  TABLEID   maxTbid;
H
Hongze Cheng 已提交
104 105
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
106
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
107
} SStatisBlk;
H
Hongze Cheng 已提交
108 109 110 111 112 113 114 115 116 117 118

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

int32_t tStatisBlockInit(STbStatisBlock *statisBlock);
int32_t tStatisBlockFree(STbStatisBlock *statisBlock);
int32_t tStatisBlockClear(STbStatisBlock *statisBlock);
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, const STbStatisRecord *statisRecord);

// 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 已提交
119 120 121 122 123 124

#ifdef __cplusplus
}
#endif

#endif /*_TSDB_UTIL_H*/