index_cache.h 2.2 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
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 __INDEX_CACHE_H__
#define __INDEX_CACHE_H__

#include "index.h"
dengyihao's avatar
dengyihao 已提交
19
#include "indexInt.h"
dengyihao's avatar
dengyihao 已提交
20
#include "tlockfree.h"
dengyihao's avatar
dengyihao 已提交
21
#include "tskiplist.h"
dengyihao's avatar
dengyihao 已提交
22
// ----------------- key structure in skiplist ---------------------
dengyihao's avatar
dengyihao 已提交
23

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

#ifdef __cplusplus
extern "C" {
#endif

32 33 34 35
typedef struct MemTable {
  T_REF_DECLARE()
  SSkipList* mem;
} 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

dengyihao's avatar
dengyihao 已提交
46
  pthread_mutex_t mtx;
dengyihao's avatar
dengyihao 已提交
47
  pthread_cond_t  finished;
dengyihao's avatar
dengyihao 已提交
48 49
} IndexCache;

dengyihao's avatar
dengyihao 已提交
50
#define CACHE_VERSION(cache) atomic_load_32(&cache->version)
51 52 53 54 55 56 57 58 59
typedef struct CacheTerm {
  // key
  char*   colVal;
  int32_t version;
  // value
  uint64_t           uid;
  int8_t             colType;
  SIndexOperOnColumn operaType;
} CacheTerm;
60
//
dengyihao's avatar
dengyihao 已提交
61

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

dengyihao's avatar
dengyihao 已提交
64
void indexCacheDestroy(void* cache);
dengyihao's avatar
dengyihao 已提交
65

dengyihao's avatar
dengyihao 已提交
66 67 68
Iterate* indexCacheIteratorCreate(IndexCache* cache);
void     indexCacheIteratorDestroy(Iterate* iiter);

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

71
// int indexCacheGet(void *cache, uint64_t *rst);
dengyihao's avatar
dengyihao 已提交
72 73 74 75
int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s);

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

77
void indexCacheDebug(IndexCache* cache);
dengyihao's avatar
dengyihao 已提交
78

dengyihao's avatar
dengyihao 已提交
79
void indexCacheDestroyImm(IndexCache* cache);
dengyihao's avatar
dengyihao 已提交
80 81 82 83 84
#ifdef __cplusplus
}
#endif

#endif