mgmtSdb.h 3.8 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/*
 * 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 _sdbint_header_
#define _sdbint_header_

#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "hashint.h"
#include "hashstr.h"
#include "sdb.h"
#include "tchecksum.h"
#include "tlog.h"
#include "trpc.h"
#include "tutil.h"

#define sdbError(...)                            \
  if (sdbDebugFlag & DEBUG_ERROR) {              \
    tprintf("ERROR MND-SDB ", 255, __VA_ARGS__); \
  }
#define sdbWarn(...)                                      \
  if (sdbDebugFlag & DEBUG_WARN) {                        \
    tprintf("WARN  MND-SDB ", sdbDebugFlag, __VA_ARGS__); \
  }
#define sdbTrace(...)                               \
  if (sdbDebugFlag & DEBUG_TRACE) {                 \
    tprintf("MND-SDB ", sdbDebugFlag, __VA_ARGS__); \
  }
#define sdbPrint(...) \
  { tprintf("MND-SDB ", 255, __VA_ARGS__); }

S
slguan 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#define mpeerError(...)                            \
  if (sdbDebugFlag & DEBUG_ERROR) {              \
    tprintf("ERROR MND-MPEER ", 255, __VA_ARGS__); \
  }
#define mpeerWarn(...)                                      \
  if (sdbDebugFlag & DEBUG_WARN) {                        \
    tprintf("WARN  MND-MPEER ", sdbDebugFlag, __VA_ARGS__); \
  }
#define mpeerTrace(...)                               \
  if (sdbDebugFlag & DEBUG_TRACE) {                 \
    tprintf("MND-MPEER ", sdbDebugFlag, __VA_ARGS__); \
  }
#define mpeerPrint(...) \
  { tprintf("MND-MPEER ", 255, __VA_ARGS__); }

H
hzcheng 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#define sdbLError(...) taosLogError(__VA_ARGS__) sdbError(__VA_ARGS__)
#define sdbLWarn(...) taosLogWarn(__VA_ARGS__) sdbWarn(__VA_ARGS__)
#define sdbLPrint(...) taosLogPrint(__VA_ARGS__) sdbPrint(__VA_ARGS__)

#define SDB_MAX_PEERS 4
#define SDB_DELIMITER 0xFFF00F00
#define SDB_ENDCOMMIT 0xAFFFAAAF

typedef struct {
  uint64_t swVersion;
  int16_t  sdbFileVersion;
  char     reserved[6];
  TSCKSUM  checkSum;
} SSdbHeader;

typedef struct {
  char type;
  // short  rowSize;
  char *row;
} SSdbUpdate;

S
slguan 已提交
87
typedef struct _SSdbTable {
H
hzcheng 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  SSdbHeader header;
  int        maxRows;
  int        dbId;
  int32_t    maxRowSize;
  char       name[TSDB_DB_NAME_LEN];
  char       fn[128];
  int        keyType;
  uint32_t   autoIndex;
  int64_t    numOfRows;
  int64_t    id;
  int64_t    size;
  void *     iHandle;
  int        fd;
  void *(*appTool)(char, void *, char *, int, int *);
  pthread_mutex_t mutex;
  SSdbUpdate *    update;
  int             numOfUpdates;
  int             updatePos;
} SSdbTable;

typedef struct {
  int64_t id;
  int64_t offset;
  int     rowSize;
  void *  row;
} SRowMeta;

typedef struct {
  int32_t delimiter;
  int32_t rowSize;
  int64_t id;
  char    data[];
} SRowHead;

typedef struct {
S
slguan 已提交
123
  uint8_t  dbId;
H
hzcheng 已提交
124 125 126 127 128 129 130 131 132 133 134
  char     type;
  uint64_t version;
  short    dataLen;
  char     data[];
} SForwardMsg;

extern SSdbTable *tableList[];
extern int        sdbMaxPeers;
extern int        sdbNumOfTables;
extern int64_t    sdbVersion;

S
slguan 已提交
135
int sdbForwardDbReqToPeer(SSdbTable *pTable, char type, char *data, int dataLen);
S
slguan 已提交
136
int mpeerRetrieveRows(int fd, SSdbTable *pTable, uint64_t version);
H
hzcheng 已提交
137 138 139
void sdbResetTable(SSdbTable *pTable);
extern const int16_t sdbFileVersion;

S
#1177  
slguan 已提交
140

H
hzcheng 已提交
141
#endif