提交 68f3de61 编写于 作者: S Shengliang Guan

remove tfile

上级 7eec493a
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#ifndef _TD_CONFIG_H_ #ifndef _TD_CONFIG_H_
#define _TD_CONFIG_H_ #define _TD_CONFIG_H_
#include "os.h"
#include "tarray.h" #include "tarray.h"
#ifdef __cplusplus #ifdef __cplusplus
...@@ -54,11 +53,11 @@ typedef struct SConfigItem { ...@@ -54,11 +53,11 @@ typedef struct SConfigItem {
bool tsc; bool tsc;
char *name; char *name;
union { union {
bool bval; bool bval;
float fval; float fval;
int32_t i32; int32_t i32;
int64_t i64; int64_t i64;
char *str; char *str;
}; };
union { union {
int64_t imin; int64_t imin;
...@@ -80,7 +79,7 @@ typedef struct SConfig SConfig; ...@@ -80,7 +79,7 @@ typedef struct SConfig SConfig;
SConfig *cfgInit(); SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg); void cfgCleanup(SConfig *pCfg);
int32_t cfgGetSize(SConfig *pCfg); int32_t cfgGetSize(SConfig *pCfg);
......
此差异已折叠。
/*
* 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 _TD_UTIL_FILE_H
#define _TD_UTIL_FILE_H
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
// init taos file module
int32_t tfInit();
// clean up taos file module
void tfCleanup();
// the same syntax as UNIX standard open/close/read/write
// but FD is int64_t and will never be reused
// int64_t tfOpenRead(const char *pathname);
// int64_t tfOpenReadWrite(const char *pathname);
// int64_t tfOpenCreateWrite(const char *pathname);
// int64_t tfOpenCreateWriteAppend(const char *pathname);
// int64_t tfClose(int64_t tfd);
// int64_t tfWrite(int64_t tfd, void *buf, int64_t count);
// int64_t tfRead(int64_t tfd, void *buf, int64_t count);
// int64_t tfPread(int64_t tfd, void *buf, int64_t count, int64_t offset);
// int32_t tfFsync(int64_t tfd);
// bool tfValid(int64_t tfd);
// int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence);
// int32_t tfFtruncate(int64_t tfd, int64_t length);
// void * tfMmapReadOnly(int64_t tfd, int64_t length);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_FILE_H*/
...@@ -16,9 +16,11 @@ ...@@ -16,9 +16,11 @@
#ifndef _TD_INDEX_INT_H_ #ifndef _TD_INDEX_INT_H_
#define _TD_INDEX_INT_H_ #define _TD_INDEX_INT_H_
#include "os.h"
#include "index.h" #include "index.h"
#include "index_fst.h"
#include "taos.h" #include "taos.h"
#include "tarray.h"
#include "tchecksum.h" #include "tchecksum.h"
#include "thash.h" #include "thash.h"
#include "tlog.h" #include "tlog.h"
......
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
#ifndef __INDEX_CACHE_H__ #ifndef __INDEX_CACHE_H__
#define __INDEX_CACHE_H__ #define __INDEX_CACHE_H__
#include "index.h"
#include "indexInt.h" #include "indexInt.h"
#include "tlockfree.h"
#include "tskiplist.h" #include "tskiplist.h"
// ----------------- key structure in skiplist --------------------- // ----------------- key structure in skiplist ---------------------
/* A data row, the format is like below /* A data row, the format is like below
......
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_node.h"
#include "index_fst_automation.h" #include "index_fst_automation.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
#include "index_fst_registry.h" #include "index_fst_registry.h"
#include "index_fst_util.h" #include "index_fst_util.h"
#include "tarray.h"
#define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) #define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_util.h" #include "index_fst_util.h"
typedef struct AutomationCtx AutomationCtx; typedef struct AutomationCtx AutomationCtx;
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#ifndef __INDEX_FST_COUNTING_WRITER_H__ #ifndef __INDEX_FST_COUNTING_WRITER_H__
#define __INDEX_FST_COUNTING_WRITER_H__ #define __INDEX_FST_COUNTING_WRITER_H__
#include "indexInt.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tfile.h"
//#define USE_MMAP 1 //#define USE_MMAP 1
#define DefaultMem 1024 * 1024 #define DefaultMem 1024 * 1024
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
#include "index_fst_util.h" #include "index_fst_util.h"
......
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_node.h" #include "index_fst_node.h"
#include "index_fst_util.h" #include "index_fst_util.h"
#include "tarray.h"
typedef struct FstRegistryCell { typedef struct FstRegistryCell {
CompiledAddr addr; CompiledAddr addr;
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
extern "C" { extern "C" {
#endif #endif
#include "indexInt.h"
#include "index_fst_common.h" #include "index_fst_common.h"
#include "tarray.h"
typedef uint64_t FstType; typedef uint64_t FstType;
typedef uint64_t CompiledAddr; typedef uint64_t CompiledAddr;
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#ifndef __INDEX_TFILE_H__ #ifndef __INDEX_TFILE_H__
#define __INDEX_TFILE_H__ #define __INDEX_TFILE_H__
#include "index.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst.h" #include "index_fst.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef __INDEX_UTIL_H__ #ifndef __INDEX_UTIL_H__
#define __INDEX_UTIL_H__ #define __INDEX_UTIL_H__
#include "tarray.h" #include "indexInt.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst_util.h" #include "index_fst_util.h"
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "os.h"
#include "index_fst_registry.h" #include "index_fst_registry.h"
uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) {
......
...@@ -49,7 +49,6 @@ class FstWriter { ...@@ -49,7 +49,6 @@ class FstWriter {
class FstReadMemory { class FstReadMemory {
public: public:
FstReadMemory(size_t size, const std::string& fileName = "/tmp/tindex.tindex") { FstReadMemory(size_t size, const std::string& fileName = "/tmp/tindex.tindex") {
tfInit();
_wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024); _wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024);
_w = fstCountingWriterCreate(_wc); _w = fstCountingWriterCreate(_wc);
_size = size; _size = size;
...@@ -116,7 +115,6 @@ class FstReadMemory { ...@@ -116,7 +115,6 @@ class FstReadMemory {
fstDestroy(_fst); fstDestroy(_fst);
fstSliceDestroy(&_s); fstSliceDestroy(&_s);
writerCtxDestroy(_wc, false); writerCtxDestroy(_wc, false);
tfCleanup();
} }
private: private:
...@@ -170,7 +168,6 @@ void Performance_fstReadRecords(FstReadMemory* m) { ...@@ -170,7 +168,6 @@ void Performance_fstReadRecords(FstReadMemory* m) {
} }
void checkMillonWriteAndReadOfFst() { void checkMillonWriteAndReadOfFst() {
tfInit();
FstWriter* fw = new FstWriter; FstWriter* fw = new FstWriter;
Performance_fstWriteRecords(fw); Performance_fstWriteRecords(fw);
delete fw; delete fw;
...@@ -181,11 +178,9 @@ void checkMillonWriteAndReadOfFst() { ...@@ -181,11 +178,9 @@ void checkMillonWriteAndReadOfFst() {
} }
Performance_fstReadRecords(fr); Performance_fstReadRecords(fr);
tfCleanup();
delete fr; delete fr;
} }
void checkFstLongTerm() { void checkFstLongTerm() {
tfInit();
FstWriter* fw = new FstWriter; FstWriter* fw = new FstWriter;
// Performance_fstWriteRecords(fw); // Performance_fstWriteRecords(fw);
...@@ -235,12 +230,10 @@ void checkFstLongTerm() { ...@@ -235,12 +230,10 @@ void checkFstLongTerm() {
// for (int i = 0; i < result.size(); i++) { // for (int i = 0; i < result.size(); i++) {
// assert(result[i] == i); // check result // assert(result[i] == i); // check result
//} //}
tfCleanup();
// free(ctx); // free(ctx);
// delete m; // delete m;
} }
void checkFstCheckIterator() { void checkFstCheckIterator() {
tfInit();
FstWriter* fw = new FstWriter; FstWriter* fw = new FstWriter;
int64_t s = taosGetTimestampUs(); int64_t s = taosGetTimestampUs();
int count = 2; int count = 2;
...@@ -275,7 +268,6 @@ void checkFstCheckIterator() { ...@@ -275,7 +268,6 @@ void checkFstCheckIterator() {
free(ctx); free(ctx);
delete m; delete m;
tfCleanup();
} }
void fst_get(Fst* fst) { void fst_get(Fst* fst) {
...@@ -294,8 +286,6 @@ void fst_get(Fst* fst) { ...@@ -294,8 +286,6 @@ void fst_get(Fst* fst) {
#define NUM_OF_THREAD 10 #define NUM_OF_THREAD 10
void validateTFile(char* arg) { void validateTFile(char* arg) {
tfInit();
std::thread threads[NUM_OF_THREAD]; std::thread threads[NUM_OF_THREAD];
// std::vector<std::thread> threads; // std::vector<std::thread> threads;
TFileReader* reader = tfileReaderOpen(arg, 0, 20000000, "tag1"); TFileReader* reader = tfileReaderOpen(arg, 0, 20000000, "tag1");
...@@ -309,12 +299,9 @@ void validateTFile(char* arg) { ...@@ -309,12 +299,9 @@ void validateTFile(char* arg) {
// wait join // wait join
threads[i].join(); threads[i].join();
} }
tfCleanup();
} }
void iterTFileReader(char* path, char* ver) { void iterTFileReader(char* path, char* ver) {
tfInit();
int version = atoi(ver); int version = atoi(ver);
TFileReader* reader = tfileReaderOpen(path, 0, version, "tag1"); TFileReader* reader = tfileReaderOpen(path, 0, version, "tag1");
Iterate* iter = tfileIteratorCreate(reader); Iterate* iter = tfileIteratorCreate(reader);
...@@ -331,7 +318,6 @@ void iterTFileReader(char* path, char* ver) { ...@@ -331,7 +318,6 @@ void iterTFileReader(char* path, char* ver) {
printf("total size: %d\n term count: %d\n", count, termCount); printf("total size: %d\n term count: %d\n", count, termCount);
tfileIteratorDestroy(iter); tfileIteratorDestroy(iter);
tfCleanup();
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
......
...@@ -24,8 +24,6 @@ static char tindex[PATH_MAX] = {0}; ...@@ -24,8 +24,6 @@ static char tindex[PATH_MAX] = {0};
static char tindexDir[PATH_MAX] = {0}; static char tindexDir[PATH_MAX] = {0};
static void EnvInit() { static void EnvInit() {
tfInit();
std::string path = dir; std::string path = dir;
taosRemoveDir(path.c_str()); taosRemoveDir(path.c_str());
taosMkDir(path.c_str()); taosMkDir(path.c_str());
...@@ -136,7 +134,6 @@ class FstReadMemory { ...@@ -136,7 +134,6 @@ class FstReadMemory {
fstDestroy(_fst); fstDestroy(_fst);
fstSliceDestroy(&_s); fstSliceDestroy(&_s);
writerCtxDestroy(_wc, false); writerCtxDestroy(_wc, false);
// tfCleanup();
} }
private: private:
......
...@@ -420,7 +420,6 @@ class IndexTFileEnv : public ::testing::Test { ...@@ -420,7 +420,6 @@ class IndexTFileEnv : public ::testing::Test {
virtual void SetUp() { virtual void SetUp() {
taosRemoveDir(dir.c_str()); taosRemoveDir(dir.c_str());
taosMkDir(dir.c_str()); taosMkDir(dir.c_str());
tfInit();
fObj = new TFileObj(dir, colName); fObj = new TFileObj(dir, colName);
} }
...@@ -428,7 +427,6 @@ class IndexTFileEnv : public ::testing::Test { ...@@ -428,7 +427,6 @@ class IndexTFileEnv : public ::testing::Test {
// indexClose(index); // indexClose(index);
// indexeptsDestroy(opts); // indexeptsDestroy(opts);
delete fObj; delete fObj;
tfCleanup();
// tfileWriterDestroy(twrite); // tfileWriterDestroy(twrite);
} }
TFileObj* fObj; TFileObj* fObj;
...@@ -800,13 +798,10 @@ class IndexObj { ...@@ -800,13 +798,10 @@ class IndexObj {
class IndexEnv2 : public ::testing::Test { class IndexEnv2 : public ::testing::Test {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
tfInit();
index = new IndexObj(); index = new IndexObj();
//
} }
virtual void TearDown() { virtual void TearDown() {
delete index; delete index;
tfCleanup();
} }
IndexObj* index; IndexObj* index;
}; };
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "tcompare.h" #include "tcompare.h"
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tfile.h"
#include "tref.h" #include "tref.h"
#include "walInt.h" #include "walInt.h"
...@@ -40,15 +39,9 @@ int32_t walInit() { ...@@ -40,15 +39,9 @@ int32_t walInit() {
int8_t old = atomic_val_compare_exchange_8(&tsWal.inited, 0, 1); int8_t old = atomic_val_compare_exchange_8(&tsWal.inited, 0, 1);
if (old == 1) return 0; if (old == 1) return 0;
int code = tfInit();
if (code != 0) {
wError("failed to init tfile since %s", tstrerror(code));
atomic_store_8(&tsWal.inited, 0);
return code;
}
tsWal.refSetId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj); tsWal.refSetId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj);
code = walCreateThread(); int32_t code = walCreateThread();
if (code != 0) { if (code != 0) {
wError("failed to init wal module since %s", tstrerror(code)); wError("failed to init wal module since %s", tstrerror(code));
atomic_store_8(&tsWal.inited, 0); atomic_store_8(&tsWal.inited, 0);
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tfile.h"
#include "walInt.h" #include "walInt.h"
#include "taoserror.h" #include "taoserror.h"
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tfile.h"
#include "tref.h" #include "tref.h"
#include "walInt.h" #include "walInt.h"
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "os.h" #include "os.h"
#include "taoserror.h" #include "taoserror.h"
#include "tchecksum.h" #include "tchecksum.h"
#include "tfile.h"
#include "walInt.h" #include "walInt.h"
int32_t walCommit(SWal *pWal, int64_t ver) { int32_t walCommit(SWal *pWal, int64_t ver) {
......
...@@ -16,14 +16,12 @@ ...@@ -16,14 +16,12 @@
#define _GNU_SOURCE #define _GNU_SOURCE
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "tcompare.h" #include "tcompare.h"
#include "regex.h" #include "regex.h"
#include "tdef.h"
#include "thash.h" #include "thash.h"
#include "types.h"
#include "tlog.h" #include "tlog.h"
#include "tdef.h" #include "types.h"
#include "taos.h"
int32_t setChkInBytes1(const void *pLeft, const void *pRight) { int32_t setChkInBytes1(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0; return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
...@@ -57,16 +55,14 @@ int32_t setChkNotInBytes8(const void *pLeft, const void *pRight) { ...@@ -57,16 +55,14 @@ int32_t setChkNotInBytes8(const void *pLeft, const void *pRight) {
return NULL == taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0; return NULL == taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0;
} }
int32_t compareChkInString(const void *pLeft, const void *pRight) {
int32_t compareChkInString(const void *pLeft, const void* pRight) {
return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0; return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0;
} }
int32_t compareChkNotInString(const void *pLeft, const void* pRight) { int32_t compareChkNotInString(const void *pLeft, const void *pRight) {
return NULL == taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0; return NULL == taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0;
} }
int32_t compareInt8Val(const void *pLeft, const void *pRight) { int32_t compareInt8Val(const void *pLeft, const void *pRight) {
int8_t left = GET_INT8_VAL(pLeft), right = GET_INT8_VAL(pRight); int8_t left = GET_INT8_VAL(pLeft), right = GET_INT8_VAL(pRight);
if (left > right) return 1; if (left > right) return 1;
...@@ -74,9 +70,7 @@ int32_t compareInt8Val(const void *pLeft, const void *pRight) { ...@@ -74,9 +70,7 @@ int32_t compareInt8Val(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareInt8ValDesc(const void *pLeft, const void *pRight) { int32_t compareInt8ValDesc(const void *pLeft, const void *pRight) { return compareInt8Val(pRight, pLeft); }
return compareInt8Val(pRight, pLeft);
}
int32_t compareInt16Val(const void *pLeft, const void *pRight) { int32_t compareInt16Val(const void *pLeft, const void *pRight) {
int16_t left = GET_INT16_VAL(pLeft), right = GET_INT16_VAL(pRight); int16_t left = GET_INT16_VAL(pLeft), right = GET_INT16_VAL(pRight);
...@@ -85,9 +79,7 @@ int32_t compareInt16Val(const void *pLeft, const void *pRight) { ...@@ -85,9 +79,7 @@ int32_t compareInt16Val(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareInt16ValDesc(const void* pLeft, const void* pRight) { int32_t compareInt16ValDesc(const void *pLeft, const void *pRight) { return compareInt16Val(pRight, pLeft); }
return compareInt16Val(pRight, pLeft);
}
int32_t compareInt32Val(const void *pLeft, const void *pRight) { int32_t compareInt32Val(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft), right = GET_INT32_VAL(pRight); int32_t left = GET_INT32_VAL(pLeft), right = GET_INT32_VAL(pRight);
...@@ -96,9 +88,7 @@ int32_t compareInt32Val(const void *pLeft, const void *pRight) { ...@@ -96,9 +88,7 @@ int32_t compareInt32Val(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareInt32ValDesc(const void* pLeft, const void* pRight) { int32_t compareInt32ValDesc(const void *pLeft, const void *pRight) { return compareInt32Val(pRight, pLeft); }
return compareInt32Val(pRight, pLeft);
}
int32_t compareInt64Val(const void *pLeft, const void *pRight) { int32_t compareInt64Val(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft), right = GET_INT64_VAL(pRight); int64_t left = GET_INT64_VAL(pLeft), right = GET_INT64_VAL(pRight);
...@@ -107,9 +97,7 @@ int32_t compareInt64Val(const void *pLeft, const void *pRight) { ...@@ -107,9 +97,7 @@ int32_t compareInt64Val(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareInt64ValDesc(const void* pLeft, const void* pRight) { int32_t compareInt64ValDesc(const void *pLeft, const void *pRight) { return compareInt64Val(pRight, pLeft); }
return compareInt64Val(pRight, pLeft);
}
int32_t compareUint32Val(const void *pLeft, const void *pRight) { int32_t compareUint32Val(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft), right = GET_UINT32_VAL(pRight); uint32_t left = GET_UINT32_VAL(pLeft), right = GET_UINT32_VAL(pRight);
...@@ -118,9 +106,7 @@ int32_t compareUint32Val(const void *pLeft, const void *pRight) { ...@@ -118,9 +106,7 @@ int32_t compareUint32Val(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareUint32ValDesc(const void* pLeft, const void* pRight) { int32_t compareUint32ValDesc(const void *pLeft, const void *pRight) { return compareUint32Val(pRight, pLeft); }
return compareUint32Val(pRight, pLeft);
}
int32_t compareUint64Val(const void *pLeft, const void *pRight) { int32_t compareUint64Val(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft), right = GET_UINT64_VAL(pRight); uint64_t left = GET_UINT64_VAL(pLeft), right = GET_UINT64_VAL(pRight);
...@@ -129,9 +115,7 @@ int32_t compareUint64Val(const void *pLeft, const void *pRight) { ...@@ -129,9 +115,7 @@ int32_t compareUint64Val(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareUint64ValDesc(const void* pLeft, const void* pRight) { int32_t compareUint64ValDesc(const void *pLeft, const void *pRight) { return compareUint64Val(pRight, pLeft); }
return compareUint64Val(pRight, pLeft);
}
int32_t compareUint16Val(const void *pLeft, const void *pRight) { int32_t compareUint16Val(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft), right = GET_UINT16_VAL(pRight); uint16_t left = GET_UINT16_VAL(pLeft), right = GET_UINT16_VAL(pRight);
...@@ -140,20 +124,16 @@ int32_t compareUint16Val(const void *pLeft, const void *pRight) { ...@@ -140,20 +124,16 @@ int32_t compareUint16Val(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareUint16ValDesc(const void* pLeft, const void* pRight) { int32_t compareUint16ValDesc(const void *pLeft, const void *pRight) { return compareUint16Val(pRight, pLeft); }
return compareUint16Val(pRight, pLeft);
}
int32_t compareUint8Val(const void* pLeft, const void* pRight) { int32_t compareUint8Val(const void *pLeft, const void *pRight) {
uint8_t left = GET_UINT8_VAL(pLeft), right = GET_UINT8_VAL(pRight); uint8_t left = GET_UINT8_VAL(pLeft), right = GET_UINT8_VAL(pRight);
if (left > right) return 1; if (left > right) return 1;
if (left < right) return -1; if (left < right) return -1;
return 0; return 0;
} }
int32_t compareUint8ValDesc(const void* pLeft, const void* pRight) { int32_t compareUint8ValDesc(const void *pLeft, const void *pRight) { return compareUint8Val(pRight, pLeft); }
return compareUint8Val(pRight, pLeft);
}
int32_t compareFloatVal(const void *pLeft, const void *pRight) { int32_t compareFloatVal(const void *pLeft, const void *pRight) {
float p1 = GET_FLOAT_VAL(pLeft); float p1 = GET_FLOAT_VAL(pLeft);
...@@ -173,12 +153,10 @@ int32_t compareFloatVal(const void *pLeft, const void *pRight) { ...@@ -173,12 +153,10 @@ int32_t compareFloatVal(const void *pLeft, const void *pRight) {
if (FLT_EQUAL(p1, p2)) { if (FLT_EQUAL(p1, p2)) {
return 0; return 0;
} }
return FLT_GREATER(p1, p2) ? 1: -1; return FLT_GREATER(p1, p2) ? 1 : -1;
} }
int32_t compareFloatValDesc(const void* pLeft, const void* pRight) { int32_t compareFloatValDesc(const void *pLeft, const void *pRight) { return compareFloatVal(pRight, pLeft); }
return compareFloatVal(pRight, pLeft);
}
int32_t compareDoubleVal(const void *pLeft, const void *pRight) { int32_t compareDoubleVal(const void *pLeft, const void *pRight) {
double p1 = GET_DOUBLE_VAL(pLeft); double p1 = GET_DOUBLE_VAL(pLeft);
...@@ -198,30 +176,28 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight) { ...@@ -198,30 +176,28 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight) {
if (FLT_EQUAL(p1, p2)) { if (FLT_EQUAL(p1, p2)) {
return 0; return 0;
} }
return FLT_GREATER(p1, p2) ? 1: -1; return FLT_GREATER(p1, p2) ? 1 : -1;
} }
int32_t compareDoubleValDesc(const void* pLeft, const void* pRight) { int32_t compareDoubleValDesc(const void *pLeft, const void *pRight) { return compareDoubleVal(pRight, pLeft); }
return compareDoubleVal(pRight, pLeft);
}
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) { int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) {
int32_t len1 = varDataLen(pLeft); int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight); int32_t len2 = varDataLen(pRight);
if (len1 != len2) { if (len1 != len2) {
return len1 > len2? 1:-1; return len1 > len2 ? 1 : -1;
} else { } else {
int32_t ret = strncmp(varDataVal(pLeft), varDataVal(pRight), len1); int32_t ret = strncmp(varDataVal(pLeft), varDataVal(pRight), len1);
if (ret == 0) { if (ret == 0) {
return 0; return 0;
} else { } else {
return ret > 0 ? 1:-1; return ret > 0 ? 1 : -1;
} }
} }
} }
int32_t compareLenPrefixedStrDesc(const void* pLeft, const void* pRight) { int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight) {
return compareLenPrefixedStr(pRight, pLeft); return compareLenPrefixedStr(pRight, pLeft);
} }
...@@ -230,9 +206,9 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) { ...@@ -230,9 +206,9 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
int32_t len2 = varDataLen(pRight); int32_t len2 = varDataLen(pRight);
if (len1 != len2) { if (len1 != len2) {
return len1 > len2? 1:-1; return len1 > len2 ? 1 : -1;
} else { } else {
int32_t ret = memcmp((wchar_t*) pLeft, (wchar_t*) pRight, len1); int32_t ret = memcmp((wchar_t *)pLeft, (wchar_t *)pRight, len1);
if (ret == 0) { if (ret == 0) {
return 0; return 0;
} else { } else {
...@@ -241,7 +217,7 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) { ...@@ -241,7 +217,7 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
} }
} }
int32_t compareLenPrefixedWStrDesc(const void* pLeft, const void* pRight) { int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) {
return compareLenPrefixedWStr(pRight, pLeft); return compareLenPrefixedWStr(pRight, pLeft);
} }
...@@ -301,10 +277,13 @@ int32_t patternMatch(const char *patterStr, const char *str, size_t size, const ...@@ -301,10 +277,13 @@ int32_t patternMatch(const char *patterStr, const char *str, size_t size, const
} }
c1 = str[j++]; c1 = str[j++];
++o; ++o;
if (j <= size) { if (j <= size) {
if (c == '\\' && patterStr[i] == '_' && c1 == '_') { i++; continue; } if (c == '\\' && patterStr[i] == '_' && c1 == '_') {
i++;
continue;
}
if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) { if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) {
continue; continue;
} }
...@@ -364,21 +343,19 @@ int32_t WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t siz ...@@ -364,21 +343,19 @@ int32_t WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t siz
return TSDB_PATTERN_NOMATCH; return TSDB_PATTERN_NOMATCH;
} }
return (str[j] == 0 || j >= size) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH; return (str[j] == 0 || j >= size) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH;
} }
int32_t compareStrRegexCompMatch(const void* pLeft, const void* pRight) { int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight) { return compareStrRegexComp(pLeft, pRight); }
return compareStrRegexComp(pLeft, pRight);
}
int32_t compareStrRegexCompNMatch(const void* pLeft, const void* pRight) { int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight) {
return compareStrRegexComp(pLeft, pRight) ? 0 : 1; return compareStrRegexComp(pLeft, pRight) ? 0 : 1;
} }
int32_t compareStrRegexComp(const void* pLeft, const void* pRight) { int32_t compareStrRegexComp(const void *pLeft, const void *pRight) {
size_t sz = varDataLen(pRight); size_t sz = varDataLen(pRight);
char *pattern = malloc(sz + 1); char *pattern = malloc(sz + 1);
memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight));
pattern[sz] = 0; pattern[sz] = 0;
...@@ -413,15 +390,14 @@ int32_t compareStrRegexComp(const void* pLeft, const void* pRight) { ...@@ -413,15 +390,14 @@ int32_t compareStrRegexComp(const void* pLeft, const void* pRight) {
return result; return result;
} }
int32_t taosArrayCompareString(const void* a, const void* b) { int32_t taosArrayCompareString(const void *a, const void *b) {
const char* x = *(const char**)a; const char *x = *(const char **)a;
const char* y = *(const char**)b; const char *y = *(const char **)b;
return compareLenPrefixedStr(x, y); return compareLenPrefixedStr(x, y);
} }
int32_t compareStrPatternMatch(const void *pLeft, const void *pRight) {
int32_t compareStrPatternMatch(const void* pLeft, const void* pRight) {
SPatternCompareInfo pInfo = {'%', '_'}; SPatternCompareInfo pInfo = {'%', '_'};
assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN); assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN);
...@@ -429,7 +405,7 @@ int32_t compareStrPatternMatch(const void* pLeft, const void* pRight) { ...@@ -429,7 +405,7 @@ int32_t compareStrPatternMatch(const void* pLeft, const void* pRight) {
memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight));
size_t sz = varDataLen(pLeft); size_t sz = varDataLen(pLeft);
char *buf = malloc(sz + 1); char *buf = malloc(sz + 1);
memcpy(buf, varDataVal(pLeft), sz); memcpy(buf, varDataVal(pLeft), sz);
buf[sz] = 0; buf[sz] = 0;
...@@ -439,11 +415,11 @@ int32_t compareStrPatternMatch(const void* pLeft, const void* pRight) { ...@@ -439,11 +415,11 @@ int32_t compareStrPatternMatch(const void* pLeft, const void* pRight) {
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
} }
int32_t compareStrPatternNotMatch(const void* pLeft, const void* pRight) { int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight) {
return compareStrPatternMatch(pLeft, pRight) ? 0 : 1; return compareStrPatternMatch(pLeft, pRight) ? 0 : 1;
} }
int32_t compareWStrPatternMatch(const void* pLeft, const void* pRight) { int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight) {
SPatternCompareInfo pInfo = {'%', '_'}; SPatternCompareInfo pInfo = {'%', '_'};
assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE); assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE);
...@@ -451,17 +427,16 @@ int32_t compareWStrPatternMatch(const void* pLeft, const void* pRight) { ...@@ -451,17 +427,16 @@ int32_t compareWStrPatternMatch(const void* pLeft, const void* pRight) {
wchar_t *pattern = calloc(varDataLen(pRight) + 1, sizeof(wchar_t)); wchar_t *pattern = calloc(varDataLen(pRight) + 1, sizeof(wchar_t));
memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight));
int32_t ret = WCSPatternMatch(pattern, varDataVal(pLeft), varDataLen(pLeft)/TSDB_NCHAR_SIZE, &pInfo); int32_t ret = WCSPatternMatch(pattern, varDataVal(pLeft), varDataLen(pLeft) / TSDB_NCHAR_SIZE, &pInfo);
free(pattern); free(pattern);
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
} }
int32_t compareWStrPatternNotMatch(const void* pLeft, const void* pRight) { int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight) {
return compareWStrPatternMatch(pLeft, pRight) ? 0 : 1; return compareWStrPatternMatch(pLeft, pRight) ? 0 : 1;
} }
__compar_fn_t getComparFunc(int32_t type, int32_t optr) { __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
__compar_fn_t comparFn = NULL; __compar_fn_t comparFn = NULL;
...@@ -513,13 +488,25 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -513,13 +488,25 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: comparFn = compareInt8Val; break; case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_SMALLINT: comparFn = compareInt16Val; break; comparFn = compareInt8Val;
case TSDB_DATA_TYPE_INT: comparFn = compareInt32Val; break; break;
case TSDB_DATA_TYPE_SMALLINT:
comparFn = compareInt16Val;
break;
case TSDB_DATA_TYPE_INT:
comparFn = compareInt32Val;
break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP: comparFn = compareInt64Val; break; case TSDB_DATA_TYPE_TIMESTAMP:
case TSDB_DATA_TYPE_FLOAT: comparFn = compareFloatVal; break; comparFn = compareInt64Val;
case TSDB_DATA_TYPE_DOUBLE: comparFn = compareDoubleVal; break; break;
case TSDB_DATA_TYPE_FLOAT:
comparFn = compareFloatVal;
break;
case TSDB_DATA_TYPE_DOUBLE:
comparFn = compareDoubleVal;
break;
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (optr == OP_TYPE_MATCH) { if (optr == OP_TYPE_MATCH) {
comparFn = compareStrRegexCompMatch; comparFn = compareStrRegexCompMatch;
...@@ -559,10 +546,18 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -559,10 +546,18 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
break; break;
} }
case TSDB_DATA_TYPE_UTINYINT: comparFn = compareUint8Val; break; case TSDB_DATA_TYPE_UTINYINT:
case TSDB_DATA_TYPE_USMALLINT: comparFn = compareUint16Val;break; comparFn = compareUint8Val;
case TSDB_DATA_TYPE_UINT: comparFn = compareUint32Val;break; break;
case TSDB_DATA_TYPE_UBIGINT: comparFn = compareUint64Val;break; case TSDB_DATA_TYPE_USMALLINT:
comparFn = compareUint16Val;
break;
case TSDB_DATA_TYPE_UINT:
comparFn = compareUint32Val;
break;
case TSDB_DATA_TYPE_UBIGINT:
comparFn = compareUint64Val;
break;
default: default:
comparFn = compareInt32Val; comparFn = compareInt32Val;
...@@ -572,99 +567,106 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -572,99 +567,106 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
return comparFn; return comparFn;
} }
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) { __compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) {
__compar_fn_t comparFn = NULL; __compar_fn_t comparFn = NULL;
switch (keyType) { switch (keyType) {
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
comparFn = (order == TSDB_ORDER_ASC)? compareInt8Val:compareInt8ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareInt8Val : compareInt8ValDesc;
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
comparFn = (order == TSDB_ORDER_ASC)? compareInt16Val:compareInt16ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareInt16Val : compareInt16ValDesc;
break; break;
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
comparFn = (order == TSDB_ORDER_ASC)? compareInt32Val:compareInt32ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc;
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
comparFn = (order == TSDB_ORDER_ASC)? compareInt64Val:compareInt64ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareInt64Val : compareInt64ValDesc;
break; break;
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
comparFn = (order == TSDB_ORDER_ASC)? compareFloatVal:compareFloatValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareFloatVal : compareFloatValDesc;
break; break;
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
comparFn = (order == TSDB_ORDER_ASC)? compareDoubleVal:compareDoubleValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareDoubleVal : compareDoubleValDesc;
break; break;
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint8Val:compareUint8ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareUint8Val : compareUint8ValDesc;
break; break;
case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_USMALLINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint16Val:compareUint16ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareUint16Val : compareUint16ValDesc;
break; break;
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint32Val:compareUint32ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareUint32Val : compareUint32ValDesc;
break; break;
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
comparFn = (order == TSDB_ORDER_ASC)? compareUint64Val:compareUint64ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareUint64Val : compareUint64ValDesc;
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
comparFn = (order == TSDB_ORDER_ASC)? compareLenPrefixedStr:compareLenPrefixedStrDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareLenPrefixedStr : compareLenPrefixedStrDesc;
break; break;
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
comparFn = (order == TSDB_ORDER_ASC)? compareLenPrefixedWStr:compareLenPrefixedWStrDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareLenPrefixedWStr : compareLenPrefixedWStrDesc;
break; break;
default: default:
comparFn = (order == TSDB_ORDER_ASC)? compareInt32Val:compareInt32ValDesc; comparFn = (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc;
break; break;
} }
return comparFn; return comparFn;
} }
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) { int32_t doCompare(const char *f1, const char *f2, int32_t type, size_t size) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_INT: DEFAULT_COMP(GET_INT32_VAL(f1), GET_INT32_VAL(f2)); case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_DOUBLE: DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(f1), GET_DOUBLE_VAL(f2)); DEFAULT_COMP(GET_INT32_VAL(f1), GET_INT32_VAL(f2));
case TSDB_DATA_TYPE_FLOAT: DEFAULT_FLOAT_COMP(GET_FLOAT_VAL(f1), GET_FLOAT_VAL(f2)); case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_BIGINT: DEFAULT_COMP(GET_INT64_VAL(f1), GET_INT64_VAL(f2)); DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(f1), GET_DOUBLE_VAL(f2));
case TSDB_DATA_TYPE_SMALLINT: DEFAULT_COMP(GET_INT16_VAL(f1), GET_INT16_VAL(f2)); case TSDB_DATA_TYPE_FLOAT:
DEFAULT_FLOAT_COMP(GET_FLOAT_VAL(f1), GET_FLOAT_VAL(f2));
case TSDB_DATA_TYPE_BIGINT:
DEFAULT_COMP(GET_INT64_VAL(f1), GET_INT64_VAL(f2));
case TSDB_DATA_TYPE_SMALLINT:
DEFAULT_COMP(GET_INT16_VAL(f1), GET_INT16_VAL(f2));
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_BOOL: DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2)); case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_UTINYINT: DEFAULT_COMP(GET_UINT8_VAL(f1), GET_UINT8_VAL(f2)); DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2));
case TSDB_DATA_TYPE_USMALLINT: DEFAULT_COMP(GET_UINT16_VAL(f1), GET_UINT16_VAL(f2)); case TSDB_DATA_TYPE_UTINYINT:
case TSDB_DATA_TYPE_UINT: DEFAULT_COMP(GET_UINT32_VAL(f1), GET_UINT32_VAL(f2)); DEFAULT_COMP(GET_UINT8_VAL(f1), GET_UINT8_VAL(f2));
case TSDB_DATA_TYPE_UBIGINT: DEFAULT_COMP(GET_UINT64_VAL(f1), GET_UINT64_VAL(f2)); case TSDB_DATA_TYPE_USMALLINT:
DEFAULT_COMP(GET_UINT16_VAL(f1), GET_UINT16_VAL(f2));
case TSDB_DATA_TYPE_UINT:
DEFAULT_COMP(GET_UINT32_VAL(f1), GET_UINT32_VAL(f2));
case TSDB_DATA_TYPE_UBIGINT:
DEFAULT_COMP(GET_UINT64_VAL(f1), GET_UINT64_VAL(f2));
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
tstr* t1 = (tstr*) f1; tstr *t1 = (tstr *)f1;
tstr* t2 = (tstr*) f2; tstr *t2 = (tstr *)f2;
if (t1->len != t2->len) { if (t1->len != t2->len) {
return t1->len > t2->len? 1:-1; return t1->len > t2->len ? 1 : -1;
} }
int32_t ret = memcmp((wchar_t*) t1, (wchar_t*) t2, t2->len); int32_t ret = memcmp((wchar_t *)t1, (wchar_t *)t2, t2->len);
if (ret == 0) { if (ret == 0) {
return ret; return ret;
} }
return (ret < 0) ? -1 : 1; return (ret < 0) ? -1 : 1;
} }
default: { // todo refactor default: { // todo refactor
tstr* t1 = (tstr*) f1; tstr *t1 = (tstr *)f1;
tstr* t2 = (tstr*) f2; tstr *t2 = (tstr *)f2;
if (t1->len != t2->len) { if (t1->len != t2->len) {
return t1->len > t2->len? 1:-1; return t1->len > t2->len ? 1 : -1;
} else { } else {
int32_t ret = strncmp(t1->data, t2->data, t1->len); int32_t ret = strncmp(t1->data, t2->data, t1->len);
if (ret == 0) { if (ret == 0) {
return 0; return 0;
} else { } else {
return ret < 0? -1:1; return ret < 0 ? -1 : 1;
} }
} }
} }
} }
} }
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include "tconfig.h" #include "tconfig.h"
#include "taoserror.h" #include "taoserror.h"
#include "thash.h" #include "thash.h"
#include "tutil.h"
#include "tlog.h" #include "tlog.h"
#include "tutil.h"
#define CFG_NAME_PRINT_LEN 24 #define CFG_NAME_PRINT_LEN 24
#define CFG_SRC_PRINT_LEN 12 #define CFG_SRC_PRINT_LEN 12
......
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "taoserror.h"
#include "tref.h"
#include "tutil.h"
#include "tlog.h"
static int32_t tsFileRsetId = -1;
static int8_t tfInited = 0;
// static void tfCloseFile(void *p) { taosCloseFile((TdFilePtr)(uintptr_t)p); }
int32_t tfInit() {
// int8_t old = atomic_val_compare_exchange_8(&tfInited, 0, 1);
// if (old == 1) return 0;
// tsFileRsetId = taosOpenRef(2000, tfCloseFile);
// if (tsFileRsetId > 0) {
// return 0;
// } else {
// atomic_store_8(&tfInited, 0);
// return -1;
// }
}
void tfCleanup() {
// atomic_store_8(&tfInited, 0);
// if (tsFileRsetId >= 0) taosCloseRef(tsFileRsetId);
// tsFileRsetId = -1;
}
// static int64_t tfOpenImp(TdFilePtr pFile) {
// if (pFile == NULL) {
// terrno = TAOS_SYSTEM_ERROR(errno);
// return -1;
// }
// void * p = (void *)(int64_t)pFile;
// int64_t rid = taosAddRef(tsFileRsetId, p);
// if (rid < 0) taosCloseFile(&pFile);
// return rid;
// }
// int64_t tfOpenRead(const char *pathname, int32_t flags) {
// int32_t pFile = taosOpenFile(pathname, TD_FILE_READ);
// return tfOpenImp(fd);
// }
// int64_t tfOpenReadWrite(const char *pathname, int32_t flags) {
// int32_t pFile = taosOpenFile(pathname, TD_FILE_READ | TD_FILE_WRITE);
// return tfOpenImp(fd);
// }
// int64_t tfOpenCreateWrite(const char *pathname, int32_t flags, mode_t mode) {
// int32_t pFile = taosOpenFile(pathname, TD_FILE_CTEATE | TD_FILE_WRITE);
// return tfOpenImp(fd);
// }
// int64_t tfOpenCreateWriteAppend(const char *pathname, int32_t flags, mode_t mode) {
// int32_t pFile = taosOpenFile(pathname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
// return tfOpenImp(fd);
// }
// int64_t tfClose(int64_t tfd) { return taosRemoveRef(tsFileRsetId, tfd); }
// int64_t tfWrite(int64_t tfd, void *buf, int64_t count) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return -1;
// int32_t pFile = (TdFilePtr)(uintptr_t)p;
// int64_t ret = taosWriteFile(pFile, buf, count);
// if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno);
// taosReleaseRef(tsFileRsetId, tfd);
// return ret;
// }
// int64_t tfRead(int64_t tfd, void *buf, int64_t count) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return -1;
// int32_t pFile = (TdFilePtr)(uintptr_t)p;
// int64_t ret = taosReadFile(pFile, buf, count);
// if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno);
// taosReleaseRef(tsFileRsetId, tfd);
// return ret;
// }
// int64_t tfPread(int64_t tfd, void *buf, int64_t count, int32_t offset) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return -1;
// int32_t pFile = (TdFilePtr)(uintptr_t)p;
// int64_t ret = pread(fd, buf, count, offset);
// if (ret < 0) terrno = TAOS_SYSTEM_ERROR(errno);
// taosReleaseRef(tsFileRsetId, tfd);
// return ret;
// }
// int32_t tfFsync(int64_t tfd) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return -1;
// int32_t pFile = (TdFilePtr)(uintptr_t)p;
// int32_t code = taosFsyncFile(pFile);
// taosReleaseRef(tsFileRsetId, tfd);
// return code;
// }
// bool tfValid(int64_t tfd) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return false;
// taosReleaseRef(tsFileRsetId, tfd);
// return true;
// }
// int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return -1;
// int32_t pFile = (TdFilePtr)(uintptr_t)p;
// int64_t ret = taosLSeekFile(fd, offset, whence);
// taosReleaseRef(tsFileRsetId, tfd);
// return ret;
// }
// int32_t tfFtruncate(int64_t tfd, int64_t length) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return -1;
// int32_t pFile = (TdFilePtr)(uintptr_t)p;
// int32_t code = taosFtruncateFile(fd, length);
// taosReleaseRef(tsFileRsetId, tfd);
// return code;
// }
// void *tfMmapReadOnly(int64_t tfd, int64_t length) {
// void *p = taosAcquireRef(tsFileRsetId, tfd);
// if (p == NULL) return NULL;
// int32_t pFile = (TdFilePtr)(uintptr_t)p;
// void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0);
// taosReleaseRef(tsFileRsetId, tfd);
// return ptr;
// }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册