tsdbint.h 3.7 KB
Newer Older
H
refact  
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 _TD_TSDB_INT_H_
#define _TD_TSDB_INT_H_

H
Hongze Cheng 已提交
19
#if 0
H
refact  
Hongze Cheng 已提交
20 21 22 23 24 25 26 27 28
// // TODO: remove the include
// #include <errno.h>
// #include <fcntl.h>
// #include <limits.h>
// #include <inttypes.h>
// #include <sys/stat.h>
// #include <sys/types.h>
// #include <semaphore.h>
// #include <dirent.h>
H
refact  
Hongze Cheng 已提交
29

H
Haojun Liao 已提交
30
#include "hash.h"
H
refact  
Hongze Cheng 已提交
31 32
#include "os.h"
#include "taosdef.h"
H
refact  
Hongze Cheng 已提交
33
#include "taoserror.h"
H
Haojun Liao 已提交
34
#include "tarray.h"
H
refact  
Hongze Cheng 已提交
35
#include "tchecksum.h"
H
Hongze Cheng 已提交
36
#include "tcoding.h"
H
Haojun Liao 已提交
37 38
#include "tcompression.h"
#include "tdataformat.h"
H
refact  
Hongze Cheng 已提交
39
#include "tfs.h"
H
Haojun Liao 已提交
40 41 42 43
#include "tlist.h"
#include "tlockfree.h"
#include "tlog.h"
#include "tskiplist.h"
H
Hongze Cheng 已提交
44
#include "tsocket.h"
H
refact  
Hongze Cheng 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

#include "tsdb.h"

#ifdef __cplusplus
extern "C" {
#endif

// Log
#include "tsdbLog.h"
// Meta
#include "tsdbMeta.h"
// Buffer
#include "tsdbBuffer.h"
// MemTable
#include "tsdbMemTable.h"
// File
#include "tsdbFile.h"
// FS
#include "tsdbFS.h"
// ReadImpl
#include "tsdbReadImpl.h"
// Commit
#include "tsdbCommit.h"
H
Hongze Cheng 已提交
68 69
// Compact
#include "tsdbCompact.h"
H
refact  
Hongze Cheng 已提交
70 71
// Commit Queue
#include "tsdbCommitQueue.h"
72 73

#include "tsdbRowMergeBuf.h"
H
refact  
Hongze Cheng 已提交
74 75
// Main definitions
struct STsdbRepo {
H
Hongze Cheng 已提交
76
  uint8_t state;
H
refact  
Hongze Cheng 已提交
77 78

  STsdbCfg        config;
L
lichuang 已提交
79 80 81 82

  STsdbCfg        save_config;    // save apply config
  bool            config_changed; // config changed flag
  pthread_mutex_t save_mutex;     // protect save config
83 84
  
  uint8_t         hasCachedLastColumn;
L
lichuang 已提交
85

H
refact  
Hongze Cheng 已提交
86 87 88 89 90 91 92
  STsdbAppH       appH;
  STsdbStat       stat;
  STsdbMeta*      tsdbMeta;
  STsdbBufPool*   pPool;
  SMemTable*      mem;
  SMemTable*      imem;
  STsdbFS*        fs;
93
  SRtn            rtn;
94
  tsem_t          readyToCommit;
H
refact  
Hongze Cheng 已提交
95 96 97
  pthread_mutex_t mutex;
  bool            repoLocked;
  int32_t         code;  // Commit code
Y
yihaoDeng 已提交
98

99
  SMergeBuf       mergeBuf;  //used when update=2
100
  int8_t          compactState;  // compact state: inCompact/noCompact/waitingCompact?
A
AlexDuan 已提交
101
  pthread_t*      pthread;
H
refact  
Hongze Cheng 已提交
102 103 104 105
};

#define REPO_ID(r) (r)->config.tsdbId
#define REPO_CFG(r) (&((r)->config))
H
Hongze Cheng 已提交
106
#define REPO_FS(r) ((r)->fs)
H
refact  
Hongze Cheng 已提交
107 108 109
#define IS_REPO_LOCKED(r) (r)->repoLocked
#define TSDB_SUBMIT_MSG_HEAD_SIZE sizeof(SSubmitMsg)

H
Hongze Cheng 已提交
110 111 112 113
int        tsdbLockRepo(STsdbRepo* pRepo);
int        tsdbUnlockRepo(STsdbRepo* pRepo);
STsdbMeta* tsdbGetMeta(STsdbRepo* pRepo);
int        tsdbCheckCommit(STsdbRepo* pRepo);
H
Hongze Cheng 已提交
114
int        tsdbRestoreInfo(STsdbRepo* pRepo);
115
int        tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg);
116 117
void       tsdbGetRootDir(int repoid, char dirName[]);
void       tsdbGetDataDir(int repoid, char dirName[]);
H
refact  
Hongze Cheng 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131

static FORCE_INLINE STsdbBufBlock* tsdbGetCurrBufBlock(STsdbRepo* pRepo) {
  ASSERT(pRepo != NULL);
  if (pRepo->mem == NULL) return NULL;

  SListNode* pNode = listTail(pRepo->mem->bufBlockList);
  if (pNode == NULL) return NULL;

  STsdbBufBlock* pBufBlock = NULL;
  tdListNodeGetData(pRepo->mem->bufBlockList, pNode, (void*)(&pBufBlock));

  return pBufBlock;
}

H
Hongze Cheng 已提交
132 133 134 135 136 137 138 139 140 141 142 143
static FORCE_INLINE int tsdbGetNextMaxTables(int tid) {
  ASSERT(tid >= 1 && tid <= TSDB_MAX_TABLES);
  int maxTables = TSDB_INIT_NTABLES;
  while (true) {
    maxTables = MIN(maxTables, TSDB_MAX_TABLES);
    if (tid <= maxTables) break;
    maxTables *= 2;
  }

  return maxTables + 1;
}

H
refact  
Hongze Cheng 已提交
144 145 146 147
#ifdef __cplusplus
}
#endif

H
Hongze Cheng 已提交
148
#endif
149
#endif /* _TD_TSDB_INT_H_ */