refactor code
This commit is contained in:
parent
88ba5faec9
commit
c1a2366d67
|
@ -73,6 +73,7 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
|||
#ifdef USE_INVERTED_INDEX
|
||||
// sIdx->cache = (void*)indexCacheCreate(sIdx);
|
||||
sIdx->tindex = indexTFileCreate(path);
|
||||
if (sIdx->tindex == NULL) { goto END; }
|
||||
sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
sIdx->cVersion = 1;
|
||||
sIdx->path = calloc(1, strlen(path) + 1);
|
||||
|
@ -83,6 +84,8 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
|||
|
||||
return 0;
|
||||
#endif
|
||||
END:
|
||||
if (sIdx != NULL) { indexClose(sIdx); }
|
||||
|
||||
*index = NULL;
|
||||
return -1;
|
||||
|
|
|
@ -72,12 +72,14 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
|
|||
if (readOnly == false) {
|
||||
// ctx->file.fd = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
ctx->file.fd = tfOpenCreateWriteAppend(path);
|
||||
|
||||
struct stat fstat;
|
||||
stat(path, &fstat);
|
||||
ctx->file.size = fstat.st_size;
|
||||
} else {
|
||||
// ctx->file.fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
ctx->file.fd = tfOpenRead(path);
|
||||
|
||||
struct stat fstat;
|
||||
stat(path, &fstat);
|
||||
ctx->file.size = fstat.st_size;
|
||||
|
|
|
@ -66,12 +66,14 @@ TFileCache* tfileCacheCreate(const char* path) {
|
|||
int32_t colId, version;
|
||||
for (size_t i = 0; i < taosArrayGetSize(files); i++) {
|
||||
char* file = taosArrayGetP(files, i);
|
||||
|
||||
// refactor later, use colname and version info
|
||||
char colName[256] = {0};
|
||||
if (0 != tfileParseFileName(file, &suid, colName, (int*)&version)) {
|
||||
indexInfo("try parse invalid file: %s, skip it", file);
|
||||
continue;
|
||||
}
|
||||
// use version info later
|
||||
|
||||
char fullName[256] = {0};
|
||||
sprintf(fullName, "%s/%s", path, file);
|
||||
|
||||
|
@ -204,7 +206,7 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SArray* resul
|
|||
TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const char* colName, uint8_t colType) {
|
||||
char fullname[256] = {0};
|
||||
tfileGenFileFullName(fullname, path, suid, colName, version);
|
||||
indexInfo("open write file name %s", fullname);
|
||||
// indexInfo("open write file name %s", fullname);
|
||||
WriterCtx* wcx = writerCtxCreate(TFile, fullname, false, 1024 * 1024 * 64);
|
||||
if (wcx == NULL) { return NULL; }
|
||||
|
||||
|
@ -221,7 +223,7 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const c
|
|||
tfileGenFileFullName(fullname, path, suid, colName, version);
|
||||
|
||||
WriterCtx* wc = writerCtxCreate(TFile, fullname, true, 1024 * 1024 * 1024);
|
||||
indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size);
|
||||
// indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size);
|
||||
if (wc == NULL) { return NULL; }
|
||||
|
||||
TFileReader* reader = tfileReaderCreate(wc);
|
||||
|
@ -356,6 +358,7 @@ IndexTFile* indexTFileCreate(const char* path) {
|
|||
return tfile;
|
||||
}
|
||||
void indexTFileDestroy(IndexTFile* tfile) {
|
||||
if (tfile == NULL) { return; }
|
||||
tfileCacheDestroy(tfile->cache);
|
||||
free(tfile);
|
||||
}
|
||||
|
|
|
@ -823,7 +823,7 @@ TEST_F(IndexEnv2, testIndex_TrigeFlush) {
|
|||
// r
|
||||
std::cout << "failed to init" << std::endl;
|
||||
}
|
||||
int numOfTable = 2 * 10000;
|
||||
int numOfTable = 100 * 10000;
|
||||
index->WriteMillonData("tag1", "Hello Wolrd", numOfTable);
|
||||
int target = index->SearchOne("tag1", "Hello Wolrd");
|
||||
std::cout << "Get Index: " << target << std::endl;
|
||||
|
@ -847,8 +847,8 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) {
|
|||
}
|
||||
index->PutOne("tag1", "Hello");
|
||||
index->PutOne("tag2", "Test");
|
||||
index->WriteMultiMillonData("tag1", "Hello", 5 * 10000);
|
||||
index->WriteMultiMillonData("tag2", "Test", 5 * 10000);
|
||||
index->WriteMultiMillonData("tag1", "Hello", 50 * 10000);
|
||||
index->WriteMultiMillonData("tag2", "Test", 50 * 10000);
|
||||
std::thread threads[NUM_OF_THREAD];
|
||||
|
||||
for (int i = 0; i < NUM_OF_THREAD; i++) {
|
||||
|
|
Loading…
Reference in New Issue