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
/*
 * 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__

dengyihao's avatar
dengyihao 已提交
18
#include "indexInt.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 34
typedef struct MemTable {
  T_REF_DECLARE()
  SSkipList* mem;
} MemTable;
dengyihao's avatar
dengyihao 已提交
35
typedef struct IndexCache {
36
  T_REF_DECLARE()
37 38 39 40
  MemTable *mem, *imm;
  SIndex*   index;
  char*     colName;
  int32_t   version;
dengyihao's avatar
dengyihao 已提交
41
  int64_t   occupiedMem;
42
  int8_t    type;
dengyihao's avatar
dengyihao 已提交
43
  uint64_t  suid;
dengyihao's avatar
dengyihao 已提交
44

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

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

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

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

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

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

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

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

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

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

#endif