tsdbUtil.h 3.2 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) aData[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   nRow;
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 68 69

int32_t tDelBlockInit(SDelBlock *delBlock);
int32_t tDelBlockFree(SDelBlock *delBlock);
int32_t tDelBlockClear(SDelBlock *delBlock);
int32_t tDelBlockPut(SDelBlock *delBlock, const SDelRecord *delRecord);
int32_t tDelBlockEncode(SDelBlock *delBlock, void *buf, int32_t size);
int32_t tDelBlockDecode(const void *buf, SDelBlock *delBlock);

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

typedef union {
H
Hongze Cheng 已提交
87
  TARRAY2(int64_t) aData[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  struct {
    TARRAY2(int64_t) suid[1];
    TARRAY2(int64_t) uid[1];
    TARRAY2(int64_t) firstKey[1];
    TARRAY2(int64_t) firstVer[1];
    TARRAY2(int64_t) lastKey[1];
    TARRAY2(int64_t) lastVer[1];
    TARRAY2(int64_t) minVer[1];
    TARRAY2(int64_t) maxVer[1];
    TARRAY2(int64_t) aCount[1];
  };
} STbStatisBlock;

typedef struct STbStatisBlk {
  int32_t   numRec;
H
Hongze Cheng 已提交
103
  int32_t   size[STATIS_RECORD_NUM_ELEM];
H
Hongze Cheng 已提交
104 105 106 107
  TABLEID   minTid;
  TABLEID   maxTid;
  int64_t   minVer;
  int64_t   maxVer;
H
Hongze Cheng 已提交
108
  SFDataPtr dp[1];
H
Hongze Cheng 已提交
109 110 111 112 113 114 115 116 117 118 119 120
} STbStatisBlk;

#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 已提交
121 122 123 124 125 126

#ifdef __cplusplus
}
#endif

#endif /*_TSDB_UTIL_H*/