indexCache.h 2.3 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
1
/*
dengyihao's avatar
dengyihao 已提交
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com> *
dengyihao's avatar
dengyihao 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 * 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 __INDEX_CACHE_H__
#define __INDEX_CACHE_H__

dengyihao's avatar
dengyihao 已提交
17
#include "indexInt.h"
dengyihao's avatar
dengyihao 已提交
18
#include "indexUtil.h"
dengyihao's avatar
dengyihao 已提交
19
#include "tskiplist.h"
S
Shengliang Guan 已提交
20

dengyihao's avatar
dengyihao 已提交
21
// ----------------- key structure in skiplist ---------------------
dengyihao's avatar
dengyihao 已提交
22

dengyihao's avatar
dengyihao 已提交
23 24
/* A data row, the format is like below
 * content: |<---colVal---->|<-- version--->|<-- uid--->|<-- colType --->|<--operaType--->|
dengyihao's avatar
dengyihao 已提交
25 26 27 28 29 30
 */

#ifdef __cplusplus
extern "C" {
#endif

31 32 33
typedef struct MemTable {
  T_REF_DECLARE()
  SSkipList* mem;
dengyihao's avatar
dengyihao 已提交
34
  void*      pCache;
35
} MemTable;
dengyihao's avatar
dengyihao 已提交
36
typedef struct IndexCache {
37
  T_REF_DECLARE()
38 39 40 41
  MemTable *mem, *imm;
  SIndex*   index;
  char*     colName;
  int32_t   version;
dengyihao's avatar
dengyihao 已提交
42
  int64_t   occupiedMem;
43
  int8_t    type;
dengyihao's avatar
dengyihao 已提交
44
  uint64_t  suid;
dengyihao's avatar
dengyihao 已提交
45

wafwerar's avatar
wafwerar 已提交
46 47
  TdThreadMutex mtx;
  TdThreadCond  finished;
dengyihao's avatar
dengyihao 已提交
48 49
} IndexCache;

dengyihao's avatar
dengyihao 已提交
50
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
dengyihao's avatar
dengyihao 已提交
51

52 53 54 55 56
typedef struct CacheTerm {
  // key
  char*   colVal;
  int32_t version;
  // value
dengyihao's avatar
dengyihao 已提交
57 58 59
  uint64_t uid;
  int8_t   colType;

60 61
  SIndexOperOnColumn operaType;
} CacheTerm;
62
//
dengyihao's avatar
dengyihao 已提交
63

dengyihao's avatar
dengyihao 已提交
64
IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type);
dengyihao's avatar
dengyihao 已提交
65

dengyihao's avatar
dengyihao 已提交
66
void indexCacheForceToMerge(void* cache);
dengyihao's avatar
dengyihao 已提交
67
void indexCacheDestroy(void* cache);
dengyihao's avatar
dengyihao 已提交
68 69
void indexCacheBroadcast(void* cache);
void indexCacheWait(void* cache);
dengyihao's avatar
dengyihao 已提交
70

dengyihao's avatar
dengyihao 已提交
71 72 73
Iterate* indexCacheIteratorCreate(IndexCache* cache);
void     indexCacheIteratorDestroy(Iterate* iiter);

dengyihao's avatar
dengyihao 已提交
74
int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid);
dengyihao's avatar
dengyihao 已提交
75

76
// int indexCacheGet(void *cache, uint64_t *rst);
dengyihao's avatar
dengyihao 已提交
77
int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* tr, STermValueType* s);
dengyihao's avatar
dengyihao 已提交
78 79 80

void indexCacheRef(IndexCache* cache);
void indexCacheUnRef(IndexCache* cache);
dengyihao's avatar
dengyihao 已提交
81

82
void indexCacheDebug(IndexCache* cache);
dengyihao's avatar
dengyihao 已提交
83

dengyihao's avatar
dengyihao 已提交
84
void indexCacheDestroyImm(IndexCache* cache);
dengyihao's avatar
dengyihao 已提交
85 86 87 88 89
#ifdef __cplusplus
}
#endif

#endif