catalogInt.h 5.7 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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_CATALOG_INT_H_
#define _TD_CATALOG_INT_H_

#ifdef __cplusplus
extern "C" {
#endif

H
Haojun Liao 已提交
23
#include "catalog.h"
D
dapan1121 已提交
24 25
#include "common.h"
#include "tlog.h"
H
Haojun Liao 已提交
26

D
dapan1121 已提交
27 28 29 30
#define CTG_DEFAULT_CACHE_CLUSTER_NUMBER 6
#define CTG_DEFAULT_CACHE_VGROUP_NUMBER 100
#define CTG_DEFAULT_CACHE_DB_NUMBER 20
#define CTG_DEFAULT_CACHE_TABLEMETA_NUMBER 100000
D
dapan1121 已提交
31 32

#define CTG_DEFAULT_INVALID_VERSION (-1)
D
dapan 已提交
33

D
dapan1121 已提交
34 35 36 37 38
enum {
  CTG_READ = 1,
  CTG_WRITE,
};

D
dapan1121 已提交
39 40
typedef struct SVgroupListCache {
  int32_t vgroupVersion;
D
dapan1121 已提交
41
  SHashObj *cache;        // key:vgId, value:SVgroupInfo
D
dapan1121 已提交
42 43 44 45 46
} SVgroupListCache;

typedef struct SDBVgroupCache {
  SHashObj *cache;      //key:dbname, value:SDBVgroupInfo
} SDBVgroupCache;
D
dapan1121 已提交
47

D
dapan1121 已提交
48
typedef struct STableMetaCache {
D
dapan1121 已提交
49
  SRWLatch  stableLock;
D
dapan1121 已提交
50 51
  SHashObj *cache;           //key:fulltablename, value:STableMeta
  SHashObj *stableCache;     //key:suid, value:STableMeta*
D
dapan1121 已提交
52 53 54
} STableMetaCache;

typedef struct SCatalog {
D
dapan1121 已提交
55 56
  SDBVgroupCache   dbCache;
  STableMetaCache  tableCache;
H
Haojun Liao 已提交
57 58
} SCatalog;

D
dapan1121 已提交
59 60
typedef struct SCatalogMgmt {
  void       *pMsgSender;   // used to send messsage to mnode to fetch necessary metadata
D
dapan 已提交
61
  SHashObj   *pCluster;     // items cached for each cluster, the hash key is the cluster-id got from mgmt node
D
dapan1121 已提交
62
  SCatalogCfg cfg;
D
dapan1121 已提交
63 64
} SCatalogMgmt;

D
dapan1121 已提交
65
typedef uint32_t (*tableNameHashFp)(const char *, uint32_t);
D
dapan 已提交
66

D
dapan1121 已提交
67 68 69 70 71 72 73 74
#define CTG_IS_STABLE(isSTable) (1 == (isSTable))
#define CTG_IS_NOT_STABLE(isSTable) (0 == (isSTable))
#define CTG_IS_UNKNOWN_STABLE(isSTable) ((isSTable) < 0)
#define CTG_SET_STABLE(isSTable, tbType) do { (isSTable) = ((tbType) == TSDB_SUPER_TABLE) ? 1 : ((tbType) > TSDB_SUPER_TABLE ? 0 : -1); } while (0)
#define CTG_TBTYPE_MATCH(isSTable, tbType) (CTG_IS_UNKNOWN_STABLE(isSTable) || (CTG_IS_STABLE(isSTable) && (tbType) == TSDB_SUPER_TABLE) || (CTG_IS_NOT_STABLE(isSTable) && (tbType) != TSDB_SUPER_TABLE))

#define CTG_TABLE_NOT_EXIST(code) (code == TSDB_CODE_TDB_INVALID_TABLE_ID) 

D
dapan1121 已提交
75 76 77 78 79 80 81
#define ctgFatal(...)  do { if (ctgDebugFlag & DEBUG_FATAL) { taosPrintLog("CTG FATAL ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define ctgError(...)  do { if (ctgDebugFlag & DEBUG_ERROR) { taosPrintLog("CTG ERROR ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define ctgWarn(...)   do { if (ctgDebugFlag & DEBUG_WARN)  { taosPrintLog("CTG WARN ", ctgDebugFlag, __VA_ARGS__); }}  while(0)
#define ctgInfo(...)   do { if (ctgDebugFlag & DEBUG_INFO)  { taosPrintLog("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define ctgDebug(...)  do { if (ctgDebugFlag & DEBUG_DEBUG) { taosPrintLog("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define ctgTrace(...)  do { if (ctgDebugFlag & DEBUG_TRACE) { taosPrintLog("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define ctgDebugL(...) do { if (ctgDebugFlag & DEBUG_DEBUG) { taosPrintLongString("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
D
dapan 已提交
82

D
dapan1121 已提交
83 84 85 86
#define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define CTG_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
D
dapan 已提交
87

D
dapan1121 已提交
88 89
#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000

D
dapan1121 已提交
90 91
#define CTG_LOCK(type, _lock) do {   \
  if (CTG_READ == (type)) {          \
D
dapan1121 已提交
92 93
    assert(atomic_load_32((_lock)) >= 0);  \
    ctgDebug("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
D
dapan1121 已提交
94
    taosRLockLatch(_lock);           \
D
dapan1121 已提交
95 96
    ctgDebug("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
    assert(atomic_load_32((_lock)) > 0);  \
D
dapan1121 已提交
97
  } else {                                                \
D
dapan1121 已提交
98 99
    assert(atomic_load_32((_lock)) >= 0);  \
    ctgDebug("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__);  \
D
dapan1121 已提交
100
    taosWLockLatch(_lock);                                \
D
dapan1121 已提交
101 102
    ctgDebug("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__);  \
    assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY);  \
D
dapan1121 已提交
103 104 105 106 107
  }                                                       \
} while (0)

#define CTG_UNLOCK(type, _lock) do {                       \
  if (CTG_READ == (type)) {                                \
D
dapan1121 已提交
108 109
    assert(atomic_load_32((_lock)) > 0);  \
    ctgDebug("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
D
dapan1121 已提交
110
    taosRUnLockLatch(_lock);                              \
D
dapan1121 已提交
111 112
    ctgDebug("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
    assert(atomic_load_32((_lock)) >= 0);  \
D
dapan1121 已提交
113
  } else {                                                \
D
dapan1121 已提交
114 115
    assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY);  \
    ctgDebug("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
D
dapan1121 已提交
116
    taosWUnLockLatch(_lock);                              \
D
dapan1121 已提交
117 118
    ctgDebug("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
    assert(atomic_load_32((_lock)) >= 0);  \
D
dapan1121 已提交
119 120 121 122
  }                                                       \
} while (0)


H
Hongze Cheng 已提交
123 124 125 126
#ifdef __cplusplus
}
#endif

D
dapan 已提交
127
#endif /*_TD_CATALOG_INT_H_*/