index_tfile.c 2.5 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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/>.
 */

#include "index_tfile.h"
dengyihao's avatar
dengyihao 已提交
17
#include "index_fst.h"
dengyihao's avatar
dengyihao 已提交
18
#include "index_util.h"
dengyihao's avatar
dengyihao 已提交
19

dengyihao's avatar
dengyihao 已提交
20 21 22


static void tfileSerialCacheKey(TFileCacheKey *key, char *buf) {
dengyihao's avatar
dengyihao 已提交
23 24 25 26 27 28 29
  SERIALIZE_MEM_TO_BUF(buf, key, suid);
  SERIALIZE_VAR_TO_BUF(buf, '_', char); 
  SERIALIZE_MEM_TO_BUF(buf, key, colType);
  SERIALIZE_VAR_TO_BUF(buf, '_', char); 
  SERIALIZE_MEM_TO_BUF(buf, key, version);
  SERIALIZE_VAR_TO_BUF(buf, '_', char); 
  SERIALIZE_STR_MEM_TO_BUF(buf, key, colName, key->nColName);
dengyihao's avatar
dengyihao 已提交
30 31 32 33 34 35 36 37 38 39 40 41
}

TFileCache *tfileCacheCreate() {
  TFileCache *tcache = calloc(1, sizeof(TFileCache)); 
  if (tcache == NULL) { return NULL; }
  
  tcache->tableCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); 
  tcache->capacity   = 64;
  return tcache;
}
void tfileCacheDestroy(TFileCache *tcache) {
  
dengyihao's avatar
dengyihao 已提交
42 43
  free(tcache);    
   
dengyihao's avatar
dengyihao 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
}

TFileReader *tfileCacheGet(TFileCache *tcache, TFileCacheKey *key) {
  char buf[128] = {0}; 
  tfileSerialCacheKey(key, buf);
  TFileReader *reader = taosHashGet(tcache->tableCache, buf, strlen(buf)); 
  return reader; 
}
void tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader) {
  char buf[128] = {0};
  tfileSerialCacheKey(key, buf);
  taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void *));     
  return;
} 




dengyihao's avatar
dengyihao 已提交
62 63 64 65 66 67 68
IndexTFile *indexTFileCreate() {
  IndexTFile *tfile = calloc(1, sizeof(IndexTFile));   
  return tfile;
}
void IndexTFileDestroy(IndexTFile *tfile) {
  free(tfile); 
}
dengyihao's avatar
dengyihao 已提交
69 70


dengyihao's avatar
dengyihao 已提交
71 72
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result) {
  IndexTFile *ptfile = (IndexTFile *)tfile;
dengyihao's avatar
dengyihao 已提交
73
     
dengyihao's avatar
dengyihao 已提交
74 75
  return 0;
}
dengyihao's avatar
dengyihao 已提交
76 77 78 79 80 81 82 83 84 85 86
int indexTFilePut(void *tfile, SIndexTerm *term,  uint64_t uid) {
  TFileWriterOpt wOpt = {.suid    = term->suid,
                         .colType = term->colType,
                         .colName = term->colName,
                         .nColName= term->nColName,
                         .version = 1}; 

  
   
  return 0; 
}
dengyihao's avatar
dengyihao 已提交
87 88 89