commit
e54eef75b9
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
* 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_TCOMPARE_H_
|
|
||||||
#define _TD_TCOMPARE_H_
|
|
||||||
|
|
||||||
#include "compare.h"
|
|
||||||
#include "ttypes.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int32_t compareStrPatternMatch(const void* pLeft, const void* pRight);
|
|
||||||
int32_t compareStrPatternNotMatch(const void* pLeft, const void* pRight);
|
|
||||||
|
|
||||||
int32_t compareWStrPatternMatch(const void* pLeft, const void* pRight);
|
|
||||||
int32_t compareWStrPatternNotMatch(const void* pLeft, const void* pRight);
|
|
||||||
|
|
||||||
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
|
|
||||||
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
|
|
||||||
int32_t doCompare(const char* a, const char* b, int32_t type, size_t size);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_TCOMPARE_H_*/
|
|
|
@ -20,7 +20,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tcfg.h"
|
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "encode.h"
|
#include "tencode.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
|
|
@ -15,11 +15,6 @@ typedef uint8_t TDRowValT;
|
||||||
typedef uint16_t col_id_t;
|
typedef uint16_t col_id_t;
|
||||||
typedef int8_t col_type_t;
|
typedef int8_t col_type_t;
|
||||||
|
|
||||||
typedef struct tstr {
|
|
||||||
VarDataLenT len;
|
|
||||||
char data[];
|
|
||||||
} tstr;
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
VarDataLenT len;
|
VarDataLenT len;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#define _TD_DNODE_H_
|
#define _TD_DNODE_H_
|
||||||
|
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tcfg.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_TFS_H_
|
#ifndef _TD_TFS_H_
|
||||||
#define _TD_TFS_H_
|
#define _TD_TFS_H_
|
||||||
|
|
||||||
#include "tcfg.h"
|
#include "tdef.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -1,125 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 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_EXCEPTION_H
|
|
||||||
#define _TD_UTIL_EXCEPTION_H
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* cleanup actions
|
|
||||||
*/
|
|
||||||
typedef struct SCleanupAction {
|
|
||||||
bool failOnly;
|
|
||||||
uint8_t wrapper;
|
|
||||||
uint16_t reserved;
|
|
||||||
void* func;
|
|
||||||
union {
|
|
||||||
void* Ptr;
|
|
||||||
bool Bool;
|
|
||||||
char Char;
|
|
||||||
int8_t Int8;
|
|
||||||
uint8_t Uint8;
|
|
||||||
int16_t Int16;
|
|
||||||
uint16_t Uint16;
|
|
||||||
int Int;
|
|
||||||
unsigned int Uint;
|
|
||||||
int32_t Int32;
|
|
||||||
uint32_t Uint32;
|
|
||||||
int64_t Int64;
|
|
||||||
uint64_t Uint64;
|
|
||||||
float Float;
|
|
||||||
double Double;
|
|
||||||
} arg1, arg2;
|
|
||||||
} SCleanupAction;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* exception hander registration
|
|
||||||
*/
|
|
||||||
typedef struct SExceptionNode {
|
|
||||||
struct SExceptionNode* prev;
|
|
||||||
jmp_buf jb;
|
|
||||||
int32_t code;
|
|
||||||
int32_t maxCleanupAction;
|
|
||||||
int32_t numCleanupAction;
|
|
||||||
SCleanupAction* cleanupActions;
|
|
||||||
} SExceptionNode;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// functions & macros for auto-cleanup
|
|
||||||
|
|
||||||
void cleanupPush_void_ptr_ptr ( bool failOnly, void* func, void* arg1, void* arg2 );
|
|
||||||
void cleanupPush_void_ptr_bool ( bool failOnly, void* func, void* arg1, bool arg2 );
|
|
||||||
void cleanupPush_void_ptr ( bool failOnly, void* func, void* arg );
|
|
||||||
void cleanupPush_int_int ( bool failOnly, void* func, int arg );
|
|
||||||
void cleanupPush_void ( bool failOnly, void* func );
|
|
||||||
void cleanupPush_int_ptr ( bool failOnly, void* func, void* arg );
|
|
||||||
|
|
||||||
int32_t cleanupGetActionCount();
|
|
||||||
void cleanupExecuteTo( int32_t anchor, bool failed );
|
|
||||||
void cleanupExecute( SExceptionNode* node, bool failed );
|
|
||||||
bool cleanupExceedLimit();
|
|
||||||
|
|
||||||
#define CLEANUP_PUSH_VOID_PTR_PTR( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_ptr( (failOnly), (void*)(func), (void*)(arg1), (void*)(arg2) )
|
|
||||||
#define CLEANUP_PUSH_VOID_PTR_BOOL( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_bool( (failOnly), (void*)(func), (void*)(arg1), (bool)(arg2) )
|
|
||||||
#define CLEANUP_PUSH_VOID_PTR( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (void*)(arg) )
|
|
||||||
#define CLEANUP_PUSH_INT_INT( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (int)(arg) )
|
|
||||||
#define CLEANUP_PUSH_VOID( failOnly, func ) cleanupPush_void( (failOnly), (void*)(func) )
|
|
||||||
#define CLEANUP_PUSH_INT_PTR( failOnly, func, arg ) cleanupPush_int_ptr( (failOnly), (void*)(func), (void*)(arg) )
|
|
||||||
#define CLEANUP_PUSH_FREE( failOnly, arg ) cleanupPush_void_ptr( (failOnly), free, (void*)(arg) )
|
|
||||||
#define CLEANUP_PUSH_CLOSE( failOnly, arg ) cleanupPush_int_int( (failOnly), close, (int)(arg) )
|
|
||||||
#define CLEANUP_PUSH_FCLOSE( failOnly, arg ) cleanupPush_int_ptr( (failOnly), fclose, (void*)(arg) )
|
|
||||||
|
|
||||||
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
|
|
||||||
#define CLEANUP_EXECUTE_TO( anchor, failed ) cleanupExecuteTo( (anchor), (failed) )
|
|
||||||
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// functions & macros for exception handling
|
|
||||||
|
|
||||||
void exceptionPushNode( SExceptionNode* node );
|
|
||||||
int32_t exceptionPopNode();
|
|
||||||
void exceptionThrow( int32_t code );
|
|
||||||
|
|
||||||
#define TRY(maxCleanupActions) do { \
|
|
||||||
SExceptionNode exceptionNode = { 0 }; \
|
|
||||||
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
|
|
||||||
exceptionNode.maxCleanupAction = (maxCleanupActions) > 0 ? (maxCleanupActions) : 1; \
|
|
||||||
exceptionNode.cleanupActions = cleanupActions; \
|
|
||||||
exceptionPushNode( &exceptionNode ); \
|
|
||||||
int caughtException = setjmp( exceptionNode.jb ); \
|
|
||||||
if( caughtException == 0 )
|
|
||||||
|
|
||||||
#define CATCH( code ) int32_t code = exceptionPopNode(); \
|
|
||||||
if( caughtException == 1 )
|
|
||||||
|
|
||||||
#define FINALLY( code ) int32_t code = exceptionPopNode();
|
|
||||||
|
|
||||||
#define END_TRY } while( 0 );
|
|
||||||
|
|
||||||
#define THROW( x ) exceptionThrow( (x) )
|
|
||||||
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
|
|
||||||
#define CLEANUP_EXECUTE() cleanupExecute( &exceptionNode, CAUGHT_EXCEPTION() )
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_UTIL_EXCEPTION_H*/
|
|
|
@ -13,16 +13,18 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_TALGO_H
|
#ifndef _TD_UTIL_TALGO_H_
|
||||||
#define _TD_UTIL_TALGO_H
|
#define _TD_UTIL_TALGO_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __COMPAR_FN_T
|
#ifndef __COMPAR_FN_T
|
||||||
# define __COMPAR_FN_T
|
#define __COMPAR_FN_T
|
||||||
typedef int (*__compar_fn_t) (const void *, const void *);
|
typedef int32_t (*__compar_fn_t)(const void *, const void *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TD_EQ 0x1
|
#define TD_EQ 0x1
|
||||||
|
@ -45,7 +47,7 @@ typedef void (*__ext_swap_fn_t)(void *p1, void *p2, const void *param);
|
||||||
* @param param
|
* @param param
|
||||||
* @param comparFn
|
* @param comparFn
|
||||||
*/
|
*/
|
||||||
void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ext_compar_fn_t comparFn);
|
void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* binary search, with range support
|
* binary search, with range support
|
||||||
|
@ -58,7 +60,7 @@ void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ex
|
||||||
* @param flags
|
* @param flags
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, __compar_fn_t fn, int flags);
|
void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t fn, int32_t flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adjust heap
|
* adjust heap
|
||||||
|
@ -74,7 +76,8 @@ void *taosbsearch(const void *key, const void *base, size_t nmemb, size_t size,
|
||||||
* @param maxroot: if heap is max root heap
|
* @param maxroot: if heap is max root heap
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot);
|
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar,
|
||||||
|
__ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sort heap to make sure it is a max/min root heap
|
* sort heap to make sure it is a max/min root heap
|
||||||
|
@ -89,10 +92,11 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
|
||||||
* @param maxroot: if heap is max root heap
|
* @param maxroot: if heap is max root heap
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot);
|
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar,
|
||||||
|
const void *parswap, __ext_swap_fn_t swap, bool maxroot);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif /*_TD_UTIL_TALGO_H*/
|
|
||||||
|
#endif /*_TD_UTIL_TALGO_H_*/
|
||||||
|
|
|
@ -13,15 +13,13 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_TAOS_ERROR_H_
|
#ifndef _TD_UTIL_ERROR_H_
|
||||||
#define _TD_UTIL_TAOS_ERROR_H_
|
#define _TD_UTIL_ERROR_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
|
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
|
||||||
|
|
||||||
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
|
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
|
||||||
|
@ -469,4 +467,4 @@ int32_t* taosGetErrno();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_TAOS_ERROR_H_*/
|
#endif /*_TD_UTIL_ERROR_H_*/
|
||||||
|
|
|
@ -13,16 +13,15 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_ARRAY_H
|
#ifndef _TD_UTIL_ARRAY_H_
|
||||||
#define _TD_UTIL_ARRAY_H
|
#define _TD_UTIL_ARRAY_H_
|
||||||
|
|
||||||
|
#include "talgo.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "talgo.h"
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define TARRAY(TYPE) \
|
#define TARRAY(TYPE) \
|
||||||
struct { \
|
struct { \
|
||||||
|
@ -31,15 +30,15 @@ extern "C" {
|
||||||
struct TYPE* td_array_data_; \
|
struct TYPE* td_array_data_; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_
|
#define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_
|
||||||
#define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_
|
#define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_
|
||||||
#define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx)
|
#define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TARRAY_MIN_SIZE 8
|
#define TARRAY_MIN_SIZE 8
|
||||||
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
|
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
|
||||||
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
|
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
|
||||||
#define TARRAY_GET_START(array) ((array)->pData)
|
#define TARRAY_GET_START(array) ((array)->pData)
|
||||||
|
|
||||||
typedef struct SArray {
|
typedef struct SArray {
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -70,7 +69,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize);
|
||||||
* @param nEles
|
* @param nEles
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void* taosArrayAddBatch(SArray* pArray, const void* pData, int nEles);
|
void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -238,7 +237,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn);
|
||||||
* @param compar
|
* @param compar
|
||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags);
|
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search the array, return index of the element
|
* search the array, return index of the element
|
||||||
|
@ -246,14 +245,14 @@ void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t compa
|
||||||
* @param compar
|
* @param compar
|
||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags);
|
int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search the array
|
* search the array
|
||||||
* @param pArray
|
* @param pArray
|
||||||
* @param key
|
* @param key
|
||||||
*/
|
*/
|
||||||
char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int flags);
|
char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int32_t flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sort the pointer data in the array
|
* sort the pointer data in the array
|
||||||
|
@ -269,4 +268,4 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_ARRAY_H*/
|
#endif /*_TD_UTIL_ARRAY_H_*/
|
||||||
|
|
|
@ -13,15 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_INT_H_
|
#ifndef _TD_UTIL_BASE64_H_
|
||||||
#define _TD_UTIL_INT_H_
|
#define _TD_UTIL_BASE64_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen);
|
||||||
|
char *base64_encode(const uint8_t *value, int32_t vlen);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_INT_H_*/
|
#endif /*_TD_UTIL_BASE64_H_*/
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_BUFFER_H
|
#ifndef _TD_UTIL_BUFFER_H_
|
||||||
#define _TD_UTIL_BUFFER_H
|
#define _TD_UTIL_BUFFER_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ extern "C" {
|
||||||
// usage example
|
// usage example
|
||||||
/*
|
/*
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "exception.h"
|
#include "texception.h"
|
||||||
|
|
||||||
int main( int argc, char** argv ) {
|
int32_t main( int32_t argc, char** argv ) {
|
||||||
SBufferWriter bw = tbufInitWriter( NULL, false );
|
SBufferWriter bw = tbufInitWriter( NULL, false );
|
||||||
|
|
||||||
TRY( 1 ) {
|
TRY( 1 ) {
|
||||||
|
@ -39,7 +39,7 @@ int main( int argc, char** argv ) {
|
||||||
// reserve space for the interger count
|
// reserve space for the interger count
|
||||||
size_t pos = tbufReserve( &bw, sizeof(int32_t) );
|
size_t pos = tbufReserve( &bw, sizeof(int32_t) );
|
||||||
// write 5 integers to the buffer
|
// write 5 integers to the buffer
|
||||||
for( int i = 0; i < 5; i++) {
|
for( int32_t i = 0; i < 5; i++) {
|
||||||
tbufWriteInt32( &bw, i );
|
tbufWriteInt32( &bw, i );
|
||||||
}
|
}
|
||||||
// write the integer count to buffer at reserved position
|
// write the integer count to buffer at reserved position
|
||||||
|
@ -55,7 +55,7 @@ int main( int argc, char** argv ) {
|
||||||
SBufferReader br = tbufInitReader( data, size, false );
|
SBufferReader br = tbufInitReader( data, size, false );
|
||||||
// read & print out all integers
|
// read & print out all integers
|
||||||
int32_t count = tbufReadInt32( &br );
|
int32_t count = tbufReadInt32( &br );
|
||||||
for( int i = 0; i < count; i++ ) {
|
for( int32_t i = 0; i < count; i++ ) {
|
||||||
printf( "%d\n", tbufReadInt32(&br) );
|
printf( "%d\n", tbufReadInt32(&br) );
|
||||||
}
|
}
|
||||||
// read & print out a string
|
// read & print out a string
|
||||||
|
@ -87,12 +87,10 @@ typedef struct SBufferWriter {
|
||||||
void* (*allocator)(void*, size_t);
|
void* (*allocator)(void*, size_t);
|
||||||
} SBufferWriter;
|
} SBufferWriter;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// common functions & macros for both reader & writer
|
// common functions & macros for both reader & writer
|
||||||
|
|
||||||
#define tbufTell(buf) ((buf)->pos)
|
#define tbufTell(buf) ((buf)->pos)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */
|
/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */
|
||||||
// *Allocator*, function to allocate memory, will use 'realloc' if NULL
|
// *Allocator*, function to allocate memory, will use 'realloc' if NULL
|
||||||
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically
|
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically
|
||||||
|
@ -167,4 +165,4 @@ double tbufReadDouble(SBufferReader* buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_BUFFER_H*/
|
#endif /*_TD_UTIL_BUFFER_H_*/
|
||||||
|
|
|
@ -13,27 +13,25 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_CACHE_H
|
#ifndef _TD_UTIL_CACHE_H_
|
||||||
#define _TD_UTIL_CACHE_H
|
#define _TD_UTIL_CACHE_H_
|
||||||
|
|
||||||
|
#include "thash.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tlockfree.h"
|
|
||||||
#include "thash.h"
|
|
||||||
|
|
||||||
#if defined(_TD_ARM_32)
|
#if defined(_TD_ARM_32)
|
||||||
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT
|
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_INT
|
||||||
#define TSDB_CACHE_PTR_TYPE int32_t
|
#define TSDB_CACHE_PTR_TYPE int32_t
|
||||||
#else
|
#else
|
||||||
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT
|
#define TSDB_CACHE_PTR_KEY TSDB_DATA_TYPE_BIGINT
|
||||||
#define TSDB_CACHE_PTR_TYPE int64_t
|
#define TSDB_CACHE_PTR_TYPE int64_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (*__cache_free_fn_t)(void*);
|
typedef void (*__cache_free_fn_t)(void *);
|
||||||
typedef void (*__cache_trav_fn_t)(void*, void*);
|
typedef void (*__cache_trav_fn_t)(void *, void *);
|
||||||
|
|
||||||
typedef struct SCacheStatis {
|
typedef struct SCacheStatis {
|
||||||
int64_t missCount;
|
int64_t missCount;
|
||||||
|
@ -45,17 +43,17 @@ typedef struct SCacheStatis {
|
||||||
struct STrashElem;
|
struct STrashElem;
|
||||||
|
|
||||||
typedef struct SCacheDataNode {
|
typedef struct SCacheDataNode {
|
||||||
uint64_t addedTime; // the added time when this element is added or updated into cache
|
uint64_t addedTime; // the added time when this element is added or updated into cache
|
||||||
uint64_t lifespan; // life duration when this element should be remove from cache
|
uint64_t lifespan; // life duration when this element should be remove from cache
|
||||||
uint64_t expireTime; // expire time
|
uint64_t expireTime; // expire time
|
||||||
uint64_t signature;
|
uint64_t signature;
|
||||||
struct STrashElem *pTNodeHeader; // point to trash node head
|
struct STrashElem *pTNodeHeader; // point to trash node head
|
||||||
uint16_t keySize: 15; // max key size: 32kb
|
uint16_t keySize : 15; // max key size: 32kb
|
||||||
bool inTrashcan: 1;// denote if it is in trash or not
|
bool inTrashcan : 1; // denote if it is in trash or not
|
||||||
uint32_t size; // allocated size for current SCacheDataNode
|
uint32_t size; // allocated size for current SCacheDataNode
|
||||||
T_REF_DECLARE()
|
T_REF_DECLARE()
|
||||||
char *key;
|
char *key;
|
||||||
char data[];
|
char data[];
|
||||||
} SCacheDataNode;
|
} SCacheDataNode;
|
||||||
|
|
||||||
typedef struct STrashElem {
|
typedef struct STrashElem {
|
||||||
|
@ -73,22 +71,22 @@ typedef struct STrashElem {
|
||||||
* when the node in pTrash does not be referenced, it will be release at the expired expiredTime
|
* when the node in pTrash does not be referenced, it will be release at the expired expiredTime
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t totalSize; // total allocated buffer in this hash table, SCacheObj is not included.
|
int64_t totalSize; // total allocated buffer in this hash table, SCacheObj is not included.
|
||||||
int64_t refreshTime;
|
int64_t refreshTime;
|
||||||
STrashElem * pTrash;
|
STrashElem *pTrash;
|
||||||
char* name;
|
char *name;
|
||||||
SCacheStatis statistics;
|
SCacheStatis statistics;
|
||||||
SHashObj * pHashTable;
|
SHashObj *pHashTable;
|
||||||
__cache_free_fn_t freeFp;
|
__cache_free_fn_t freeFp;
|
||||||
uint32_t numOfElemsInTrash; // number of element in trash
|
uint32_t numOfElemsInTrash; // number of element in trash
|
||||||
uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
|
uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
|
||||||
pthread_t refreshWorker;
|
pthread_t refreshWorker;
|
||||||
bool extendLifespan; // auto extend life span when one item is accessed.
|
bool extendLifespan; // auto extend life span when one item is accessed.
|
||||||
int64_t checkTick; // tick used to record the check times of the refresh threads
|
int64_t checkTick; // tick used to record the check times of the refresh threads
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
pthread_rwlock_t lock;
|
pthread_rwlock_t lock;
|
||||||
#else
|
#else
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
#endif
|
#endif
|
||||||
} SCacheObj;
|
} SCacheObj;
|
||||||
|
|
||||||
|
@ -101,7 +99,8 @@ typedef struct {
|
||||||
* @param fn free resource callback function
|
* @param fn free resource callback function
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char *cacheName);
|
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn,
|
||||||
|
const char *cacheName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add data into cache
|
* add data into cache
|
||||||
|
@ -113,7 +112,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
|
||||||
* @param keepTime survival time in second
|
* @param keepTime survival time in second
|
||||||
* @return cached element
|
* @return cached element
|
||||||
*/
|
*/
|
||||||
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize, int durationMS);
|
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize,
|
||||||
|
int32_t durationMS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get data from cache
|
* get data from cache
|
||||||
|
@ -177,7 +177,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj);
|
||||||
* @param fp
|
* @param fp
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void* param1);
|
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void *param1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stop background refresh worker thread
|
* stop background refresh worker thread
|
||||||
|
@ -188,4 +188,4 @@ void taosStopCacheRefreshWorker();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_CACHE_H*/
|
#endif /*_TD_UTIL_CACHE_H_*/
|
||||||
|
|
|
@ -13,24 +13,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_CHECKSUM_H
|
#ifndef _TD_UTIL_CHECKSUM_H_
|
||||||
#define _TD_UTIL_CHECKSUM_H
|
#define _TD_UTIL_CHECKSUM_H_
|
||||||
|
|
||||||
|
#include "tcrc32c.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tcrc32c.h"
|
|
||||||
#include "tutil.h"
|
|
||||||
|
|
||||||
typedef uint32_t TSCKSUM;
|
typedef uint32_t TSCKSUM;
|
||||||
|
|
||||||
static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) {
|
static FORCE_INLINE TSCKSUM taosCalcChecksum(TSCKSUM csi, const uint8_t *stream, uint32_t ssize) {
|
||||||
return (*crc32c)(csi, stream, (size_t)ssize);
|
return (*crc32c)(csi, stream, (size_t)ssize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) {
|
static FORCE_INLINE int32_t taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uint32_t ssize) {
|
||||||
if (ssize < sizeof(TSCKSUM)) return -1;
|
if (ssize < sizeof(TSCKSUM)) return -1;
|
||||||
|
|
||||||
*((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM)));
|
*((TSCKSUM *)(stream + ssize - sizeof(TSCKSUM))) = (*crc32c)(csi, stream, (size_t)(ssize - sizeof(TSCKSUM)));
|
||||||
|
@ -38,11 +36,11 @@ static FORCE_INLINE int taosCalcChecksumAppend(TSCKSUM csi, uint8_t *stream, uin
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) {
|
static FORCE_INLINE int32_t taosCheckChecksum(const uint8_t *stream, uint32_t ssize, TSCKSUM checksum) {
|
||||||
return (checksum != (*crc32c)(0, stream, (size_t)ssize));
|
return (checksum != (*crc32c)(0, stream, (size_t)ssize));
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) {
|
static FORCE_INLINE int32_t taosCheckChecksumWhole(const uint8_t *stream, uint32_t ssize) {
|
||||||
if (ssize < sizeof(TSCKSUM)) return 0;
|
if (ssize < sizeof(TSCKSUM)) return 0;
|
||||||
|
|
||||||
#if (_WIN64)
|
#if (_WIN64)
|
||||||
|
@ -56,4 +54,4 @@ static FORCE_INLINE int taosCheckChecksumWhole(const uint8_t *stream, uint32_t s
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_CHECKSUM_H*/
|
#endif /*_TD_UTIL_CHECKSUM_H_*/
|
||||||
|
|
|
@ -12,29 +12,30 @@
|
||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
#ifndef _TD_UTIL_CODING_H
|
|
||||||
#define _TD_UTIL_CODING_H
|
#ifndef _TD_UTIL_CODING_H_
|
||||||
|
#define _TD_UTIL_CODING_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
#define ENCODE_LIMIT (((uint8_t)1) << 7)
|
||||||
|
|
||||||
#define ENCODE_LIMIT (((uint8_t)1) << 7)
|
|
||||||
#define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode
|
#define ZIGZAGE(T, v) ((u##T)((v) >> (sizeof(T) * 8 - 1))) ^ (((u##T)(v)) << 1) // zigzag encode
|
||||||
#define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode
|
#define ZIGZAGD(T, v) ((v) >> 1) ^ -((T)((v)&1)) // zigzag decode
|
||||||
|
|
||||||
/* ------------------------ LEGACY CODES ------------------------ */
|
/* ------------------------ LEGACY CODES ------------------------ */
|
||||||
#if 1
|
#if 1
|
||||||
// ---- Fixed U8
|
// ---- Fixed U8
|
||||||
static FORCE_INLINE int taosEncodeFixedU8(void **buf, uint8_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedU8(void **buf, uint8_t value) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
((uint8_t *)(*buf))[0] = value;
|
((uint8_t *)(*buf))[0] = value;
|
||||||
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)sizeof(value);
|
return (int32_t)sizeof(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
|
static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
|
||||||
|
@ -43,12 +44,12 @@ static FORCE_INLINE void *taosDecodeFixedU8(const void *buf, uint8_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Fixed I8
|
// ---- Fixed I8
|
||||||
static FORCE_INLINE int taosEncodeFixedI8(void **buf, int8_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedI8(void **buf, int8_t value) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
((int8_t *)(*buf))[0] = value;
|
((int8_t *)(*buf))[0] = value;
|
||||||
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
||||||
}
|
}
|
||||||
return (int)sizeof(value);
|
return (int32_t)sizeof(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
|
static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
|
||||||
|
@ -57,7 +58,7 @@ static FORCE_INLINE void *taosDecodeFixedI8(const void *buf, int8_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Fixed U16
|
// ---- Fixed U16
|
||||||
static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedU16(void **buf, uint16_t value) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
if (IS_LITTLE_ENDIAN()) {
|
if (IS_LITTLE_ENDIAN()) {
|
||||||
memcpy(*buf, &value, sizeof(value));
|
memcpy(*buf, &value, sizeof(value));
|
||||||
|
@ -68,7 +69,7 @@ static FORCE_INLINE int taosEncodeFixedU16(void **buf, uint16_t value) {
|
||||||
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)sizeof(value);
|
return (int32_t)sizeof(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
|
static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
|
||||||
|
@ -83,7 +84,7 @@ static FORCE_INLINE void *taosDecodeFixedU16(const void *buf, uint16_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Fixed I16
|
// ---- Fixed I16
|
||||||
static FORCE_INLINE int taosEncodeFixedI16(void **buf, int16_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedI16(void **buf, int16_t value) {
|
||||||
return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value));
|
return taosEncodeFixedU16(buf, ZIGZAGE(int16_t, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ static FORCE_INLINE void *taosDecodeFixedI16(const void *buf, int16_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Fixed U32
|
// ---- Fixed U32
|
||||||
static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedU32(void **buf, uint32_t value) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
if (IS_LITTLE_ENDIAN()) {
|
if (IS_LITTLE_ENDIAN()) {
|
||||||
memcpy(*buf, &value, sizeof(value));
|
memcpy(*buf, &value, sizeof(value));
|
||||||
|
@ -108,7 +109,7 @@ static FORCE_INLINE int taosEncodeFixedU32(void **buf, uint32_t value) {
|
||||||
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)sizeof(value);
|
return (int32_t)sizeof(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
|
static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
|
||||||
|
@ -125,7 +126,7 @@ static FORCE_INLINE void *taosDecodeFixedU32(const void *buf, uint32_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Fixed I32
|
// ---- Fixed I32
|
||||||
static FORCE_INLINE int taosEncodeFixedI32(void **buf, int32_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedI32(void **buf, int32_t value) {
|
||||||
return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value));
|
return taosEncodeFixedU32(buf, ZIGZAGE(int32_t, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ static FORCE_INLINE void *taosDecodeFixedI32(const void *buf, int32_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Fixed U64
|
// ---- Fixed U64
|
||||||
static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedU64(void **buf, uint64_t value) {
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
if (IS_LITTLE_ENDIAN()) {
|
if (IS_LITTLE_ENDIAN()) {
|
||||||
memcpy(*buf, &value, sizeof(value));
|
memcpy(*buf, &value, sizeof(value));
|
||||||
|
@ -155,7 +156,7 @@ static FORCE_INLINE int taosEncodeFixedU64(void **buf, uint64_t value) {
|
||||||
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
*buf = POINTER_SHIFT(*buf, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)sizeof(value);
|
return (int32_t)sizeof(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
|
static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
|
||||||
|
@ -176,7 +177,7 @@ static FORCE_INLINE void *taosDecodeFixedU64(const void *buf, uint64_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Fixed I64
|
// ---- Fixed I64
|
||||||
static FORCE_INLINE int taosEncodeFixedI64(void **buf, int64_t value) {
|
static FORCE_INLINE int32_t taosEncodeFixedI64(void **buf, int64_t value) {
|
||||||
return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value));
|
return taosEncodeFixedU64(buf, ZIGZAGE(int64_t, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +189,8 @@ static FORCE_INLINE void *taosDecodeFixedI64(const void *buf, int64_t *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Variant U16
|
// ---- Variant U16
|
||||||
static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) {
|
static FORCE_INLINE int32_t taosEncodeVariantU16(void **buf, uint16_t value) {
|
||||||
int i = 0;
|
int32_t i = 0;
|
||||||
while (value >= ENCODE_LIMIT) {
|
while (value >= ENCODE_LIMIT) {
|
||||||
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
|
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
|
||||||
value >>= 7;
|
value >>= 7;
|
||||||
|
@ -206,7 +207,7 @@ static FORCE_INLINE int taosEncodeVariantU16(void **buf, uint16_t value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) {
|
static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value) {
|
||||||
int i = 0;
|
int32_t i = 0;
|
||||||
uint16_t tval = 0;
|
uint16_t tval = 0;
|
||||||
*value = 0;
|
*value = 0;
|
||||||
while (i < 3) {
|
while (i < 3) {
|
||||||
|
@ -224,7 +225,7 @@ static FORCE_INLINE void *taosDecodeVariantU16(const void *buf, uint16_t *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Variant I16
|
// ---- Variant I16
|
||||||
static FORCE_INLINE int taosEncodeVariantI16(void **buf, int16_t value) {
|
static FORCE_INLINE int32_t taosEncodeVariantI16(void **buf, int16_t value) {
|
||||||
return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value));
|
return taosEncodeVariantU16(buf, ZIGZAGE(int16_t, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,8 +237,8 @@ static FORCE_INLINE void *taosDecodeVariantI16(const void *buf, int16_t *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Variant U32
|
// ---- Variant U32
|
||||||
static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) {
|
static FORCE_INLINE int32_t taosEncodeVariantU32(void **buf, uint32_t value) {
|
||||||
int i = 0;
|
int32_t i = 0;
|
||||||
while (value >= ENCODE_LIMIT) {
|
while (value >= ENCODE_LIMIT) {
|
||||||
if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT);
|
if (buf != NULL) ((uint8_t *)(*buf))[i] = (value | ENCODE_LIMIT);
|
||||||
value >>= 7;
|
value >>= 7;
|
||||||
|
@ -254,7 +255,7 @@ static FORCE_INLINE int taosEncodeVariantU32(void **buf, uint32_t value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) {
|
static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value) {
|
||||||
int i = 0;
|
int32_t i = 0;
|
||||||
uint32_t tval = 0;
|
uint32_t tval = 0;
|
||||||
*value = 0;
|
*value = 0;
|
||||||
while (i < 5) {
|
while (i < 5) {
|
||||||
|
@ -272,7 +273,7 @@ static FORCE_INLINE void *taosDecodeVariantU32(const void *buf, uint32_t *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Variant I32
|
// ---- Variant I32
|
||||||
static FORCE_INLINE int taosEncodeVariantI32(void **buf, int32_t value) {
|
static FORCE_INLINE int32_t taosEncodeVariantI32(void **buf, int32_t value) {
|
||||||
return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value));
|
return taosEncodeVariantU32(buf, ZIGZAGE(int32_t, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,8 +285,8 @@ static FORCE_INLINE void *taosDecodeVariantI32(const void *buf, int32_t *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Variant U64
|
// ---- Variant U64
|
||||||
static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) {
|
static FORCE_INLINE int32_t taosEncodeVariantU64(void **buf, uint64_t value) {
|
||||||
int i = 0;
|
int32_t i = 0;
|
||||||
while (value >= ENCODE_LIMIT) {
|
while (value >= ENCODE_LIMIT) {
|
||||||
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
|
if (buf != NULL) ((uint8_t *)(*buf))[i] = (uint8_t)(value | ENCODE_LIMIT);
|
||||||
value >>= 7;
|
value >>= 7;
|
||||||
|
@ -302,7 +303,7 @@ static FORCE_INLINE int taosEncodeVariantU64(void **buf, uint64_t value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) {
|
static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value) {
|
||||||
int i = 0;
|
int32_t i = 0;
|
||||||
uint64_t tval = 0;
|
uint64_t tval = 0;
|
||||||
*value = 0;
|
*value = 0;
|
||||||
while (i < 10) {
|
while (i < 10) {
|
||||||
|
@ -320,7 +321,7 @@ static FORCE_INLINE void *taosDecodeVariantU64(const void *buf, uint64_t *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Variant I64
|
// ---- Variant I64
|
||||||
static FORCE_INLINE int taosEncodeVariantI64(void **buf, int64_t value) {
|
static FORCE_INLINE int32_t taosEncodeVariantI64(void **buf, int64_t value) {
|
||||||
return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value));
|
return taosEncodeVariantU64(buf, ZIGZAGE(int64_t, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,16 +333,16 @@ static FORCE_INLINE void *taosDecodeVariantI64(const void *buf, int64_t *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- string
|
// ---- string
|
||||||
static FORCE_INLINE int taosEncodeString(void **buf, const char *value) {
|
static FORCE_INLINE int32_t taosEncodeString(void **buf, const char *value) {
|
||||||
int tlen = 0;
|
int32_t tlen = 0;
|
||||||
size_t size = strlen(value);
|
size_t size = strlen(value);
|
||||||
|
|
||||||
tlen += taosEncodeVariantU64(buf, size);
|
tlen += taosEncodeVariantU64(buf, size);
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
memcpy(*buf, value, size);
|
memcpy(*buf, value, size);
|
||||||
*buf = POINTER_SHIFT(*buf, size);
|
*buf = POINTER_SHIFT(*buf, size);
|
||||||
}
|
}
|
||||||
tlen += (int)size;
|
tlen += (int32_t)size;
|
||||||
|
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
@ -372,14 +373,14 @@ static FORCE_INLINE void *taosDecodeStringTo(const void *buf, char *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- binary
|
// ---- binary
|
||||||
static FORCE_INLINE int taosEncodeBinary(void **buf, const void *value, int32_t valueLen) {
|
static FORCE_INLINE int32_t taosEncodeBinary(void **buf, const void *value, int32_t valueLen) {
|
||||||
int tlen = 0;
|
int32_t tlen = 0;
|
||||||
|
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
memcpy(*buf, value, valueLen);
|
memcpy(*buf, value, valueLen);
|
||||||
*buf = POINTER_SHIFT(*buf, valueLen);
|
*buf = POINTER_SHIFT(*buf, valueLen);
|
||||||
}
|
}
|
||||||
tlen += (int)valueLen;
|
tlen += (int32_t)valueLen;
|
||||||
|
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
@ -403,4 +404,4 @@ static FORCE_INLINE void *taosDecodeBinaryTo(const void *buf, void *value, int32
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_CODING_H*/
|
#endif /*_TD_UTIL_CODING_H_*/
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
#define _TD_UTIL_COMPARE_H_
|
#define _TD_UTIL_COMPARE_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "taos.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define TSDB_PATTERN_MATCH 0
|
#define TSDB_PATTERN_MATCH 0
|
||||||
#define TSDB_PATTERN_NOMATCH 1
|
#define TSDB_PATTERN_NOMATCH 1
|
||||||
#define TSDB_PATTERN_NOWILDCARDMATCH 2
|
#define TSDB_PATTERN_NOWILDCARDMATCH 2
|
||||||
|
@ -99,7 +99,15 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight);
|
||||||
int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight);
|
int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight);
|
||||||
int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight);
|
int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight);
|
||||||
|
|
||||||
|
int32_t compareStrPatternMatch(const void *pLeft, const void *pRight);
|
||||||
|
int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
|
||||||
|
|
||||||
|
int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight);
|
||||||
|
int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight);
|
||||||
|
|
||||||
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
|
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
|
||||||
|
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
|
||||||
|
int32_t doCompare(const char *a, const char *b, int32_t type, size_t size);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
|
@ -13,22 +13,23 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_COMPRESSION_H
|
#ifndef _TD_UTIL_COMPRESSION_H_
|
||||||
#define _TD_UTIL_COMPRESSION_H
|
#define _TD_UTIL_COMPRESSION_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "taos.h"
|
||||||
|
#include "tutil.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "taos.h"
|
|
||||||
#include "tutil.h"
|
|
||||||
|
|
||||||
#define COMP_OVERFLOW_BYTES 2
|
#define COMP_OVERFLOW_BYTES 2
|
||||||
#define BITS_PER_BYTE 8
|
#define BITS_PER_BYTE 8
|
||||||
// Masks
|
// Masks
|
||||||
#define INT64MASK(_x) ((((uint64_t)1) << _x) - 1)
|
#define INT64MASK(_x) ((((uint64_t)1) << _x) - 1)
|
||||||
#define INT32MASK(_x) (((uint32_t)1 << _x) - 1)
|
#define INT32MASK(_x) (((uint32_t)1 << _x) - 1)
|
||||||
#define INT8MASK(_x) (((uint8_t)1 << _x) - 1)
|
#define INT8MASK(_x) (((uint8_t)1 << _x) - 1)
|
||||||
// Compression algorithm
|
// Compression algorithm
|
||||||
#define NO_COMPRESSION 0
|
#define NO_COMPRESSION 0
|
||||||
#define ONE_STAGE_COMP 1
|
#define ONE_STAGE_COMP 1
|
||||||
|
@ -41,48 +42,51 @@ extern "C" {
|
||||||
//
|
//
|
||||||
|
|
||||||
// compression data mode save first byte lower 1 bit
|
// compression data mode save first byte lower 1 bit
|
||||||
#define MODE_NOCOMPRESS 0 // original data
|
#define MODE_NOCOMPRESS 0 // original data
|
||||||
#define MODE_COMPRESS 1 // compatible old compress
|
#define MODE_COMPRESS 1 // compatible old compress
|
||||||
|
|
||||||
// compression algorithm save first byte higher 7 bit
|
// compression algorithm save first byte higher 7 bit
|
||||||
#define ALGO_SZ_LOSSY 1 // SZ compress
|
#define ALGO_SZ_LOSSY 1 // SZ compress
|
||||||
|
|
||||||
#define HEAD_MODE(x) x%2
|
#define HEAD_MODE(x) x % 2
|
||||||
#define HEAD_ALGO(x) x/2
|
#define HEAD_ALGO(x) x / 2
|
||||||
|
|
||||||
extern int tsCompressINTImp(const char *const input, const int nelements, char *const output, const char type);
|
extern int32_t tsCompressINTImp(const char *const input, const int32_t nelements, char *const output, const char type);
|
||||||
extern int tsDecompressINTImp(const char *const input, const int nelements, char *const output, const char type);
|
extern int32_t tsDecompressINTImp(const char *const input, const int32_t nelements, char *const output,
|
||||||
extern int tsCompressBoolImp(const char *const input, const int nelements, char *const output);
|
const char type);
|
||||||
extern int tsDecompressBoolImp(const char *const input, const int nelements, char *const output);
|
extern int32_t tsCompressBoolImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
extern int tsCompressStringImp(const char *const input, int inputSize, char *const output, int outputSize);
|
extern int32_t tsDecompressBoolImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
extern int tsDecompressStringImp(const char *const input, int compressedSize, char *const output, int outputSize);
|
extern int32_t tsCompressStringImp(const char *const input, int32_t inputSize, char *const output, int32_t outputSize);
|
||||||
extern int tsCompressTimestampImp(const char *const input, const int nelements, char *const output);
|
extern int32_t tsDecompressStringImp(const char *const input, int32_t compressedSize, char *const output,
|
||||||
extern int tsDecompressTimestampImp(const char *const input, const int nelements, char *const output);
|
int32_t outputSize);
|
||||||
extern int tsCompressDoubleImp(const char *const input, const int nelements, char *const output);
|
extern int32_t tsCompressTimestampImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
extern int tsDecompressDoubleImp(const char *const input, const int nelements, char *const output);
|
extern int32_t tsDecompressTimestampImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
extern int tsCompressFloatImp(const char *const input, const int nelements, char *const output);
|
extern int32_t tsCompressDoubleImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
extern int tsDecompressFloatImp(const char *const input, const int nelements, char *const output);
|
extern int32_t tsDecompressDoubleImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
|
extern int32_t tsCompressFloatImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
|
extern int32_t tsDecompressFloatImp(const char *const input, const int32_t nelements, char *const output);
|
||||||
// lossy
|
// lossy
|
||||||
extern int tsCompressFloatLossyImp(const char * input, const int nelements, char *const output);
|
extern int32_t tsCompressFloatLossyImp(const char *input, const int32_t nelements, char *const output);
|
||||||
extern int tsDecompressFloatLossyImp(const char * input, int compressedSize, const int nelements, char *const output);
|
extern int32_t tsDecompressFloatLossyImp(const char *input, int32_t compressedSize, const int32_t nelements,
|
||||||
extern int tsCompressDoubleLossyImp(const char * input, const int nelements, char *const output);
|
char *const output);
|
||||||
extern int tsDecompressDoubleLossyImp(const char * input, int compressedSize, const int nelements, char *const output);
|
extern int32_t tsCompressDoubleLossyImp(const char *input, const int32_t nelements, char *const output);
|
||||||
|
extern int32_t tsDecompressDoubleLossyImp(const char *input, int32_t compressedSize, const int32_t nelements,
|
||||||
|
char *const output);
|
||||||
|
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
extern bool lossyFloat;
|
extern bool lossyFloat;
|
||||||
extern bool lossyDouble;
|
extern bool lossyDouble;
|
||||||
// init call
|
int32_t tsCompressInit();
|
||||||
int tsCompressInit();
|
void tsCompressExit();
|
||||||
// exit call
|
|
||||||
void tsCompressExit();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressTinyint(const char *const input, int inputSize, const int nelements, char *const output, int outputSize, char algorithm,
|
static FORCE_INLINE int32_t tsCompressTinyint(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_TINYINT);
|
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_TINYINT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_TINYINT);
|
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_TINYINT);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -90,8 +94,9 @@ static FORCE_INLINE int tsCompressTinyint(const char *const input, int inputSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressTinyint(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressTinyint(const char *const input, int32_t compressedSize,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
const int32_t nelements, char *const output, int32_t outputSize,
|
||||||
|
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_TINYINT);
|
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_TINYINT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
|
@ -103,12 +108,13 @@ static FORCE_INLINE int tsDecompressTinyint(const char *const input, int compres
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressSmallint(const char *const input, int inputSize, const int nelements, char *const output, int outputSize, char algorithm,
|
static FORCE_INLINE int32_t tsCompressSmallint(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_SMALLINT);
|
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_SMALLINT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_SMALLINT);
|
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_SMALLINT);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -116,8 +122,9 @@ static FORCE_INLINE int tsCompressSmallint(const char *const input, int inputSiz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressSmallint(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressSmallint(const char *const input, int32_t compressedSize,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
const int32_t nelements, char *const output, int32_t outputSize,
|
||||||
|
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_SMALLINT);
|
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_SMALLINT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
|
@ -129,12 +136,13 @@ static FORCE_INLINE int tsDecompressSmallint(const char *const input, int compre
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressInt(const char *const input, int inputSize, const int nelements, char *const output, int outputSize, char algorithm,
|
static FORCE_INLINE int32_t tsCompressInt(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
|
int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_INT);
|
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_INT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_INT);
|
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_INT);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -142,8 +150,9 @@ static FORCE_INLINE int tsCompressInt(const char *const input, int inputSize, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressInt(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressInt(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
|
int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_INT);
|
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_INT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
|
@ -155,12 +164,13 @@ static FORCE_INLINE int tsDecompressInt(const char *const input, int compressedS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressBigint(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
static FORCE_INLINE int32_t tsCompressBigint(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
|
int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_BIGINT);
|
return tsCompressINTImp(input, nelements, output, TSDB_DATA_TYPE_BIGINT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_BIGINT);
|
int32_t len = tsCompressINTImp(input, nelements, buffer, TSDB_DATA_TYPE_BIGINT);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -168,8 +178,9 @@ static FORCE_INLINE int tsCompressBigint(const char *const input, int inputSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressBigint(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressBigint(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_BIGINT);
|
return tsDecompressINTImp(input, nelements, output, TSDB_DATA_TYPE_BIGINT);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
|
@ -181,12 +192,13 @@ static FORCE_INLINE int tsDecompressBigint(const char *const input, int compress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressBool(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
static FORCE_INLINE int32_t tsCompressBool(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
|
int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressBoolImp(input, nelements, output);
|
return tsCompressBoolImp(input, nelements, output);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressBoolImp(input, nelements, buffer);
|
int32_t len = tsCompressBoolImp(input, nelements, buffer);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -194,8 +206,9 @@ static FORCE_INLINE int tsCompressBool(const char *const input, int inputSize, c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressBool(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressBool(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
|
int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsDecompressBoolImp(input, nelements, output);
|
return tsDecompressBoolImp(input, nelements, output);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
|
@ -207,29 +220,32 @@ static FORCE_INLINE int tsDecompressBool(const char *const input, int compressed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressString(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
static FORCE_INLINE int32_t tsCompressString(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
|
int32_t bufferSize) {
|
||||||
return tsCompressStringImp(input, inputSize, output, outputSize);
|
return tsCompressStringImp(input, inputSize, output, outputSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressString(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressString(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
return tsDecompressStringImp(input, compressedSize, output, outputSize);
|
return tsDecompressStringImp(input, compressedSize, output, outputSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressFloat(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
static FORCE_INLINE int32_t tsCompressFloat(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
|
int32_t bufferSize) {
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
// lossy mode
|
// lossy mode
|
||||||
if(lossyFloat) {
|
if (lossyFloat) {
|
||||||
return tsCompressFloatLossyImp(input, nelements, output);
|
return tsCompressFloatLossyImp(input, nelements, output);
|
||||||
// lossless mode
|
// lossless mode
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressFloatImp(input, nelements, output);
|
return tsCompressFloatImp(input, nelements, output);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressFloatImp(input, nelements, buffer);
|
int32_t len = tsCompressFloatImp(input, nelements, buffer);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -240,10 +256,11 @@ static FORCE_INLINE int tsCompressFloat(const char *const input, int inputSize,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressFloat(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressFloat(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
if(HEAD_ALGO(input[0]) == ALGO_SZ_LOSSY){
|
if (HEAD_ALGO(input[0]) == ALGO_SZ_LOSSY) {
|
||||||
// decompress lossy
|
// decompress lossy
|
||||||
return tsDecompressFloatLossyImp(input, compressedSize, nelements, output);
|
return tsDecompressFloatLossyImp(input, compressedSize, nelements, output);
|
||||||
} else {
|
} else {
|
||||||
|
@ -263,11 +280,11 @@ static FORCE_INLINE int tsDecompressFloat(const char *const input, int compresse
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tsCompressDouble(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
static FORCE_INLINE int tsCompressDouble(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
char *const output, int32_t outputSize, char algorithm, char *const buffer,
|
||||||
char algorithm, char *const buffer, int bufferSize) {
|
int32_t bufferSize) {
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
if(lossyDouble){
|
if (lossyDouble) {
|
||||||
// lossy mode
|
// lossy mode
|
||||||
return tsCompressDoubleLossyImp(input, nelements, output);
|
return tsCompressDoubleLossyImp(input, nelements, output);
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,7 +293,7 @@ static FORCE_INLINE int tsCompressDouble(const char *const input, int inputSize,
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressDoubleImp(input, nelements, output);
|
return tsCompressDoubleImp(input, nelements, output);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressDoubleImp(input, nelements, buffer);
|
int32_t len = tsCompressDoubleImp(input, nelements, buffer);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -287,14 +304,15 @@ static FORCE_INLINE int tsCompressDouble(const char *const input, int inputSize,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressDouble(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressDouble(const char *const input, int32_t compressedSize, const int32_t nelements,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
#ifdef TD_TSZ
|
char *const buffer, int32_t bufferSize) {
|
||||||
if(HEAD_ALGO(input[0]) == ALGO_SZ_LOSSY){
|
#ifdef TD_TSZ
|
||||||
|
if (HEAD_ALGO(input[0]) == ALGO_SZ_LOSSY) {
|
||||||
// decompress lossy
|
// decompress lossy
|
||||||
return tsDecompressDoubleLossyImp(input, compressedSize, nelements, output);
|
return tsDecompressDoubleLossyImp(input, compressedSize, nelements, output);
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
// decompress lossless
|
// decompress lossless
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsDecompressDoubleImp(input, nelements, output);
|
return tsDecompressDoubleImp(input, nelements, output);
|
||||||
|
@ -314,34 +332,39 @@ static FORCE_INLINE int tsDecompressDouble(const char *const input, int compress
|
||||||
//
|
//
|
||||||
// lossy float double
|
// lossy float double
|
||||||
//
|
//
|
||||||
static FORCE_INLINE int tsCompressFloatLossy(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
static FORCE_INLINE int32_t tsCompressFloatLossy(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
return tsCompressFloatLossyImp(input, nelements, output);
|
return tsCompressFloatLossyImp(input, nelements, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressFloatLossy(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressFloatLossy(const char *const input, int32_t compressedSize,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize){
|
const int32_t nelements, char *const output, int32_t outputSize,
|
||||||
|
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||||
return tsDecompressFloatLossyImp(input, compressedSize, nelements, output);
|
return tsDecompressFloatLossyImp(input, compressedSize, nelements, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressDoubleLossy(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
static FORCE_INLINE int32_t tsCompressDoubleLossy(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char algorithm, char *const buffer, int bufferSize){
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
return tsCompressDoubleLossyImp(input, nelements, output);
|
return tsCompressDoubleLossyImp(input, nelements, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressDoubleLossy(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressDoubleLossy(const char *const input, int32_t compressedSize,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize){
|
const int32_t nelements, char *const output, int32_t outputSize,
|
||||||
|
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||||
return tsDecompressDoubleLossyImp(input, compressedSize, nelements, output);
|
return tsDecompressDoubleLossyImp(input, compressedSize, nelements, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static FORCE_INLINE int tsCompressTimestamp(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
|
static FORCE_INLINE int32_t tsCompressTimestamp(const char *const input, int32_t inputSize, const int32_t nelements,
|
||||||
char algorithm, char *const buffer, int bufferSize) {
|
char *const output, int32_t outputSize, char algorithm,
|
||||||
|
char *const buffer, int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsCompressTimestampImp(input, nelements, output);
|
return tsCompressTimestampImp(input, nelements, output);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
int len = tsCompressTimestampImp(input, nelements, buffer);
|
int32_t len = tsCompressTimestampImp(input, nelements, buffer);
|
||||||
return tsCompressStringImp(buffer, len, output, outputSize);
|
return tsCompressStringImp(buffer, len, output, outputSize);
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
|
@ -349,8 +372,9 @@ static FORCE_INLINE int tsCompressTimestamp(const char *const input, int inputSi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsDecompressTimestamp(const char *const input, int compressedSize, const int nelements, char *const output,
|
static FORCE_INLINE int32_t tsDecompressTimestamp(const char *const input, int32_t compressedSize,
|
||||||
int outputSize, char algorithm, char *const buffer, int bufferSize) {
|
const int32_t nelements, char *const output, int32_t outputSize,
|
||||||
|
char algorithm, char *const buffer, int32_t bufferSize) {
|
||||||
if (algorithm == ONE_STAGE_COMP) {
|
if (algorithm == ONE_STAGE_COMP) {
|
||||||
return tsDecompressTimestampImp(input, nelements, output);
|
return tsDecompressTimestampImp(input, nelements, output);
|
||||||
} else if (algorithm == TWO_STAGE_COMP) {
|
} else if (algorithm == TWO_STAGE_COMP) {
|
||||||
|
@ -366,4 +390,4 @@ static FORCE_INLINE int tsDecompressTimestamp(const char *const input, int compr
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_COMPRESSION_H*/
|
#endif /*_TD_UTIL_COMPRESSION_H_*/
|
|
@ -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 {
|
||||||
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;
|
||||||
|
@ -76,16 +75,17 @@ typedef struct {
|
||||||
const char *value;
|
const char *value;
|
||||||
} SConfigPair;
|
} SConfigPair;
|
||||||
|
|
||||||
typedef struct SConfig SConfig;
|
typedef struct SConfig {
|
||||||
|
ECfgSrcType stype;
|
||||||
|
SArray *array;
|
||||||
|
} 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);
|
||||||
SConfigItem *cfgIterate(SConfig *pCfg, SConfigItem *pIter);
|
|
||||||
void cfgCancelIterate(SConfig *pCfg, SConfigItem *pIter);
|
|
||||||
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name);
|
SConfigItem *cfgGetItem(SConfig *pCfg, const char *name);
|
||||||
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype);
|
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype);
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,10 @@
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_CRC32_H
|
#ifndef _TD_UTIL_CRC32_H_
|
||||||
#define _TD_UTIL_CRC32_H
|
#define _TD_UTIL_CRC32_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -39,4 +41,4 @@ void taosResolveCRC();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_CRC32_H*/
|
#endif /*_TD_UTIL_CRC32_H_*/
|
||||||
|
|
|
@ -13,10 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// clang-format off
|
#ifndef _TD_UTIL_DEF_H_
|
||||||
|
#define _TD_UTIL_DEF_H_
|
||||||
#ifndef _TD_UTIL_DEF_H
|
|
||||||
#define _TD_UTIL_DEF_H
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -26,89 +24,91 @@ extern "C" {
|
||||||
|
|
||||||
#define TSDB__packed
|
#define TSDB__packed
|
||||||
|
|
||||||
#define TSKEY int64_t
|
#define TSKEY int64_t
|
||||||
#define TSKEY_MIN INT64_MIN
|
#define TSKEY_MIN INT64_MIN
|
||||||
#define TSKEY_MAX (INT64_MAX - 1)
|
#define TSKEY_MAX (INT64_MAX - 1)
|
||||||
#define TSKEY_INITIAL_VAL TSKEY_MIN
|
#define TSKEY_INITIAL_VAL TSKEY_MIN
|
||||||
|
|
||||||
// Bytes for each type.
|
// Bytes for each type.
|
||||||
extern const int32_t TYPE_BYTES[15];
|
extern const int32_t TYPE_BYTES[15];
|
||||||
|
|
||||||
// TODO: replace and remove code below
|
// TODO: replace and remove code below
|
||||||
#define CHAR_BYTES sizeof(char)
|
#define CHAR_BYTES sizeof(char)
|
||||||
#define SHORT_BYTES sizeof(int16_t)
|
#define SHORT_BYTES sizeof(int16_t)
|
||||||
#define INT_BYTES sizeof(int32_t)
|
#define INT_BYTES sizeof(int32_t)
|
||||||
#define LONG_BYTES sizeof(int64_t)
|
#define LONG_BYTES sizeof(int64_t)
|
||||||
#define FLOAT_BYTES sizeof(float)
|
#define FLOAT_BYTES sizeof(float)
|
||||||
#define DOUBLE_BYTES sizeof(double)
|
#define DOUBLE_BYTES sizeof(double)
|
||||||
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
|
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
|
||||||
#define TSDB_KEYSIZE sizeof(TSKEY)
|
#define TSDB_KEYSIZE sizeof(TSKEY)
|
||||||
#define TSDB_NCHAR_SIZE sizeof(int32_t)
|
#define TSDB_NCHAR_SIZE sizeof(int32_t)
|
||||||
|
|
||||||
// NULL definition
|
// NULL definition
|
||||||
#define TSDB_DATA_BOOL_NULL 0x02
|
#define TSDB_DATA_BOOL_NULL 0x02
|
||||||
#define TSDB_DATA_TINYINT_NULL 0x80
|
#define TSDB_DATA_TINYINT_NULL 0x80
|
||||||
#define TSDB_DATA_SMALLINT_NULL 0x8000
|
#define TSDB_DATA_SMALLINT_NULL 0x8000
|
||||||
#define TSDB_DATA_INT_NULL 0x80000000L
|
#define TSDB_DATA_INT_NULL 0x80000000L
|
||||||
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
|
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
|
||||||
#define TSDB_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
|
#define TSDB_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
|
||||||
|
|
||||||
#define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
|
#define TSDB_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
|
||||||
#define TSDB_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN
|
#define TSDB_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN
|
||||||
#define TSDB_DATA_NCHAR_NULL 0xFFFFFFFF
|
#define TSDB_DATA_NCHAR_NULL 0xFFFFFFFF
|
||||||
#define TSDB_DATA_BINARY_NULL 0xFF
|
#define TSDB_DATA_BINARY_NULL 0xFF
|
||||||
|
|
||||||
#define TSDB_DATA_UTINYINT_NULL 0xFF
|
#define TSDB_DATA_UTINYINT_NULL 0xFF
|
||||||
#define TSDB_DATA_USMALLINT_NULL 0xFFFF
|
#define TSDB_DATA_USMALLINT_NULL 0xFFFF
|
||||||
#define TSDB_DATA_UINT_NULL 0xFFFFFFFF
|
#define TSDB_DATA_UINT_NULL 0xFFFFFFFF
|
||||||
#define TSDB_DATA_UBIGINT_NULL 0xFFFFFFFFFFFFFFFFL
|
#define TSDB_DATA_UBIGINT_NULL 0xFFFFFFFFFFFFFFFFL
|
||||||
|
|
||||||
#define TSDB_DATA_NULL_STR "NULL"
|
#define TSDB_DATA_NULL_STR "NULL"
|
||||||
#define TSDB_DATA_NULL_STR_L "null"
|
#define TSDB_DATA_NULL_STR_L "null"
|
||||||
|
|
||||||
#define TSDB_NETTEST_USER "nettestinternal"
|
#define TSDB_NETTEST_USER "nettestinternal"
|
||||||
#define TSDB_DEFAULT_USER "root"
|
#define TSDB_DEFAULT_USER "root"
|
||||||
#ifdef _TD_POWER_
|
#ifdef _TD_POWER_
|
||||||
#define TSDB_DEFAULT_PASS "powerdb"
|
#define TSDB_DEFAULT_PASS "powerdb"
|
||||||
#elif (_TD_TQ_ == true)
|
#elif (_TD_TQ_ == true)
|
||||||
#define TSDB_DEFAULT_PASS "tqueue"
|
#define TSDB_DEFAULT_PASS "tqueue"
|
||||||
#elif (_TD_PRO_ == true)
|
#elif (_TD_PRO_ == true)
|
||||||
#define TSDB_DEFAULT_PASS "prodb"
|
#define TSDB_DEFAULT_PASS "prodb"
|
||||||
#else
|
#else
|
||||||
#define TSDB_DEFAULT_PASS "taosdata"
|
#define TSDB_DEFAULT_PASS "taosdata"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SHELL_MAX_PASSWORD_LEN 20
|
#define SHELL_MAX_PASSWORD_LEN 20
|
||||||
|
|
||||||
#define TSDB_TRUE 1
|
#define TSDB_TRUE 1
|
||||||
#define TSDB_FALSE 0
|
#define TSDB_FALSE 0
|
||||||
#define TSDB_OK 0
|
#define TSDB_OK 0
|
||||||
#define TSDB_ERR -1
|
#define TSDB_ERR -1
|
||||||
|
|
||||||
#define TS_PATH_DELIMITER "."
|
#define TS_PATH_DELIMITER "."
|
||||||
#define TS_ESCAPE_CHAR '`'
|
#define TS_ESCAPE_CHAR '`'
|
||||||
|
|
||||||
#define TSDB_TIME_PRECISION_MILLI 0
|
#define TSDB_TIME_PRECISION_MILLI 0
|
||||||
#define TSDB_TIME_PRECISION_MICRO 1
|
#define TSDB_TIME_PRECISION_MICRO 1
|
||||||
#define TSDB_TIME_PRECISION_NANO 2
|
#define TSDB_TIME_PRECISION_NANO 2
|
||||||
|
|
||||||
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
|
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
|
||||||
#define TSDB_TIME_PRECISION_MICRO_STR "us"
|
#define TSDB_TIME_PRECISION_MICRO_STR "us"
|
||||||
#define TSDB_TIME_PRECISION_NANO_STR "ns"
|
#define TSDB_TIME_PRECISION_NANO_STR "ns"
|
||||||
|
|
||||||
#define TSDB_TICK_PER_SECOND(precision) ((int64_t)((precision)==TSDB_TIME_PRECISION_MILLI ? 1e3L : ((precision)==TSDB_TIME_PRECISION_MICRO ? 1e6L : 1e9L)))
|
#define TSDB_TICK_PER_SECOND(precision) \
|
||||||
|
((int64_t)((precision) == TSDB_TIME_PRECISION_MILLI ? 1e3L \
|
||||||
|
: ((precision) == TSDB_TIME_PRECISION_MICRO ? 1e6L : 1e9L)))
|
||||||
|
|
||||||
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
|
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
|
||||||
#define T_APPEND_MEMBER(dst, ptr, type, member) \
|
#define T_APPEND_MEMBER(dst, ptr, type, member) \
|
||||||
do {\
|
do { \
|
||||||
memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member));\
|
memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member)); \
|
||||||
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member));\
|
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member)); \
|
||||||
} while(0)
|
} while (0)
|
||||||
#define T_READ_MEMBER(src, type, target) \
|
#define T_READ_MEMBER(src, type, target) \
|
||||||
do { \
|
do { \
|
||||||
(target) = *(type *)(src); \
|
(target) = *(type *)(src); \
|
||||||
(src) = (void *)((char *)src + sizeof(type));\
|
(src) = (void *)((char *)src + sizeof(type)); \
|
||||||
} while(0)
|
} while (0)
|
||||||
|
|
||||||
typedef enum EOperatorType {
|
typedef enum EOperatorType {
|
||||||
// arithmetic operator
|
// arithmetic operator
|
||||||
|
@ -149,116 +149,114 @@ typedef enum EOperatorType {
|
||||||
OP_TYPE_JSON_CONTAINS
|
OP_TYPE_JSON_CONTAINS
|
||||||
} EOperatorType;
|
} EOperatorType;
|
||||||
|
|
||||||
|
|
||||||
typedef enum ELogicConditionType {
|
typedef enum ELogicConditionType {
|
||||||
LOGIC_COND_TYPE_AND,
|
LOGIC_COND_TYPE_AND,
|
||||||
LOGIC_COND_TYPE_OR,
|
LOGIC_COND_TYPE_OR,
|
||||||
LOGIC_COND_TYPE_NOT,
|
LOGIC_COND_TYPE_NOT,
|
||||||
} ELogicConditionType;
|
} ELogicConditionType;
|
||||||
|
|
||||||
|
#define FUNCTION_CEIL 4500
|
||||||
|
#define FUNCTION_FLOOR 4501
|
||||||
|
#define FUNCTION_ABS 4502
|
||||||
|
#define FUNCTION_ROUND 4503
|
||||||
|
|
||||||
#define FUNCTION_CEIL 4500
|
#define FUNCTION_LENGTH 4800
|
||||||
#define FUNCTION_FLOOR 4501
|
#define FUNCTION_CONCAT 4801
|
||||||
#define FUNCTION_ABS 4502
|
#define FUNCTION_LTRIM 4802
|
||||||
#define FUNCTION_ROUND 4503
|
#define FUNCTION_RTRIM 4803
|
||||||
|
|
||||||
#define FUNCTION_LENGTH 4800
|
#define TSDB_NAME_DELIMITER_LEN 1
|
||||||
#define FUNCTION_CONCAT 4801
|
|
||||||
#define FUNCTION_LTRIM 4802
|
|
||||||
#define FUNCTION_RTRIM 4803
|
|
||||||
|
|
||||||
#define TSDB_NAME_DELIMITER_LEN 1
|
#define TSDB_UNI_LEN 24
|
||||||
|
#define TSDB_USER_LEN TSDB_UNI_LEN
|
||||||
#define TSDB_UNI_LEN 24
|
|
||||||
#define TSDB_USER_LEN TSDB_UNI_LEN
|
|
||||||
|
|
||||||
// ACCOUNT is a 32 bit positive integer
|
// ACCOUNT is a 32 bit positive integer
|
||||||
// this is the length of its string representation, including the terminator zero
|
// this is the length of its string representation, including the terminator zero
|
||||||
#define TSDB_ACCT_ID_LEN 11
|
#define TSDB_ACCT_ID_LEN 11
|
||||||
|
|
||||||
#define TSDB_MAX_COLUMNS 4096
|
#define TSDB_MAX_COLUMNS 4096
|
||||||
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
#define TSDB_MIN_COLUMNS 2 // PRIMARY COLUMN(timestamp) + other columns
|
||||||
|
|
||||||
#define TSDB_NODE_NAME_LEN 64
|
#define TSDB_NODE_NAME_LEN 64
|
||||||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
||||||
#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string
|
#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string
|
||||||
#define TSDB_DB_NAME_LEN 65
|
#define TSDB_DB_NAME_LEN 65
|
||||||
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||||
|
|
||||||
#define TSDB_FUNC_NAME_LEN 65
|
#define TSDB_FUNC_NAME_LEN 65
|
||||||
#define TSDB_FUNC_COMMENT_LEN 4096
|
#define TSDB_FUNC_COMMENT_LEN 4096
|
||||||
#define TSDB_FUNC_CODE_LEN (65535 - 512)
|
#define TSDB_FUNC_CODE_LEN (65535 - 512)
|
||||||
#define TSDB_FUNC_BUF_SIZE 512
|
#define TSDB_FUNC_BUF_SIZE 512
|
||||||
#define TSDB_FUNC_TYPE_SCALAR 1
|
#define TSDB_FUNC_TYPE_SCALAR 1
|
||||||
#define TSDB_FUNC_TYPE_AGGREGATE 2
|
#define TSDB_FUNC_TYPE_AGGREGATE 2
|
||||||
#define TSDB_FUNC_MAX_RETRIEVE 1024
|
#define TSDB_FUNC_MAX_RETRIEVE 1024
|
||||||
|
|
||||||
#define TSDB_TYPE_STR_MAX_LEN 32
|
#define TSDB_TYPE_STR_MAX_LEN 32
|
||||||
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||||
#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN
|
#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN
|
||||||
#define TSDB_CONSUMER_GROUP_LEN 192
|
#define TSDB_CONSUMER_GROUP_LEN 192
|
||||||
#define TSDB_SUBSCRIBE_KEY_LEN (TSDB_CONSUMER_GROUP_LEN + TSDB_TOPIC_FNAME_LEN + 2)
|
#define TSDB_SUBSCRIBE_KEY_LEN (TSDB_CONSUMER_GROUP_LEN + TSDB_TOPIC_FNAME_LEN + 2)
|
||||||
#define TSDB_PARTITION_KEY_LEN (TSDB_CONSUMER_GROUP_LEN + TSDB_TOPIC_FNAME_LEN + 2)
|
#define TSDB_PARTITION_KEY_LEN (TSDB_CONSUMER_GROUP_LEN + TSDB_TOPIC_FNAME_LEN + 2)
|
||||||
#define TSDB_COL_NAME_LEN 65
|
#define TSDB_COL_NAME_LEN 65
|
||||||
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
|
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
|
||||||
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
||||||
#define TSDB_MAX_SQL_SHOW_LEN 1024
|
#define TSDB_MAX_SQL_SHOW_LEN 1024
|
||||||
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024u) // sql length should be less than 1mb
|
#define TSDB_MAX_ALLOWED_SQL_LEN (1 * 1024 * 1024u) // sql length should be less than 1mb
|
||||||
|
|
||||||
#define TSDB_APP_NAME_LEN TSDB_UNI_LEN
|
#define TSDB_APP_NAME_LEN TSDB_UNI_LEN
|
||||||
#define TSDB_STB_COMMENT_LEN 1024
|
#define TSDB_STB_COMMENT_LEN 1024
|
||||||
/**
|
/**
|
||||||
* In some scenarios uint16_t (0~65535) is used to store the row len.
|
* In some scenarios uint16_t (0~65535) is used to store the row len.
|
||||||
* - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header.
|
* - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header.
|
||||||
* - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus
|
* - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus
|
||||||
* the final value is 65531-(4096-1)*4 = 49151.
|
* the final value is 65531-(4096-1)*4 = 49151.
|
||||||
*/
|
*/
|
||||||
#define TSDB_MAX_BYTES_PER_ROW 49151
|
#define TSDB_MAX_BYTES_PER_ROW 49151
|
||||||
#define TSDB_MAX_TAGS_LEN 16384
|
#define TSDB_MAX_TAGS_LEN 16384
|
||||||
#define TSDB_MAX_TAGS 128
|
#define TSDB_MAX_TAGS 128
|
||||||
#define TSDB_MAX_TAG_CONDITIONS 1024
|
#define TSDB_MAX_TAG_CONDITIONS 1024
|
||||||
|
|
||||||
#define TSDB_AUTH_LEN 16
|
#define TSDB_AUTH_LEN 16
|
||||||
#define TSDB_PASSWORD_LEN 32
|
#define TSDB_PASSWORD_LEN 32
|
||||||
#define TSDB_USET_PASSWORD_LEN 129
|
#define TSDB_USET_PASSWORD_LEN 129
|
||||||
#define TSDB_VERSION_LEN 12
|
#define TSDB_VERSION_LEN 12
|
||||||
#define TSDB_LABEL_LEN 8
|
#define TSDB_LABEL_LEN 8
|
||||||
|
|
||||||
#define TSDB_CLUSTER_ID_LEN 40
|
#define TSDB_CLUSTER_ID_LEN 40
|
||||||
#define TSDB_FQDN_LEN 128
|
#define TSDB_FQDN_LEN 128
|
||||||
#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6)
|
#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6)
|
||||||
#define TSDB_IPv4ADDR_LEN 16
|
#define TSDB_IPv4ADDR_LEN 16
|
||||||
#define TSDB_FILENAME_LEN 128
|
#define TSDB_FILENAME_LEN 128
|
||||||
#define TSDB_SHOW_SQL_LEN 512
|
#define TSDB_SHOW_SQL_LEN 512
|
||||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||||
|
|
||||||
#define TSDB_TRANS_STAGE_LEN 12
|
#define TSDB_TRANS_STAGE_LEN 12
|
||||||
#define TSDB_TRANS_TYPE_LEN 16
|
#define TSDB_TRANS_TYPE_LEN 16
|
||||||
#define TSDB_TRANS_ERROR_LEN 64
|
#define TSDB_TRANS_ERROR_LEN 64
|
||||||
|
|
||||||
#define TSDB_STEP_NAME_LEN 32
|
#define TSDB_STEP_NAME_LEN 32
|
||||||
#define TSDB_STEP_DESC_LEN 128
|
#define TSDB_STEP_DESC_LEN 128
|
||||||
|
|
||||||
#define TSDB_ERROR_MSG_LEN 1024
|
#define TSDB_ERROR_MSG_LEN 1024
|
||||||
#define TSDB_DNODE_CONFIG_LEN 128
|
#define TSDB_DNODE_CONFIG_LEN 128
|
||||||
#define TSDB_DNODE_VALUE_LEN 256
|
#define TSDB_DNODE_VALUE_LEN 256
|
||||||
|
|
||||||
#define TSDB_MQTT_HOSTNAME_LEN 64
|
#define TSDB_MQTT_HOSTNAME_LEN 64
|
||||||
#define TSDB_MQTT_PORT_LEN 8
|
#define TSDB_MQTT_PORT_LEN 8
|
||||||
#define TSDB_MQTT_USER_LEN 24
|
#define TSDB_MQTT_USER_LEN 24
|
||||||
#define TSDB_MQTT_PASS_LEN 24
|
#define TSDB_MQTT_PASS_LEN 24
|
||||||
#define TSDB_MQTT_TOPIC_LEN 64
|
#define TSDB_MQTT_TOPIC_LEN 64
|
||||||
#define TSDB_MQTT_CLIENT_ID_LEN 32
|
#define TSDB_MQTT_CLIENT_ID_LEN 32
|
||||||
|
|
||||||
#define TSDB_DB_TYPE_DEFAULT 0
|
#define TSDB_DB_TYPE_DEFAULT 0
|
||||||
#define TSDB_DB_TYPE_TOPIC 1
|
#define TSDB_DB_TYPE_TOPIC 1
|
||||||
|
|
||||||
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE
|
#define TSDB_DEFAULT_PKT_SIZE 65480 // same as RPC_MAX_UDP_SIZE
|
||||||
|
|
||||||
#define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE
|
#define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE
|
||||||
#define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value
|
#define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value
|
||||||
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
|
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
|
||||||
#define TSDB_CQ_SQL_SIZE 1024
|
#define TSDB_CQ_SQL_SIZE 1024
|
||||||
#define TSDB_MIN_VNODES 16
|
#define TSDB_MIN_VNODES 16
|
||||||
#define TSDB_MAX_VNODES 512
|
#define TSDB_MAX_VNODES 512
|
||||||
|
@ -266,150 +264,154 @@ typedef enum ELogicConditionType {
|
||||||
#define TSDB_MAX_VNODES_PER_DB 4096
|
#define TSDB_MAX_VNODES_PER_DB 4096
|
||||||
#define TSDB_DEFAULT_VN_PER_DB 2
|
#define TSDB_DEFAULT_VN_PER_DB 2
|
||||||
|
|
||||||
#define TSDB_DNODE_ROLE_ANY 0
|
#define TSDB_DNODE_ROLE_ANY 0
|
||||||
#define TSDB_DNODE_ROLE_MGMT 1
|
#define TSDB_DNODE_ROLE_MGMT 1
|
||||||
#define TSDB_DNODE_ROLE_VNODE 2
|
#define TSDB_DNODE_ROLE_VNODE 2
|
||||||
|
|
||||||
#define TSDB_MAX_REPLICA 5
|
#define TSDB_MAX_REPLICA 5
|
||||||
|
|
||||||
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
||||||
#define TSDB_UD_COLUMN_INDEX (-1000)
|
#define TSDB_UD_COLUMN_INDEX (-1000)
|
||||||
#define TSDB_RES_COL_ID (-5000)
|
#define TSDB_RES_COL_ID (-5000)
|
||||||
|
|
||||||
#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta
|
#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta
|
||||||
|
|
||||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
|
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
|
||||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode
|
#define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode
|
||||||
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
|
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
|
||||||
|
|
||||||
#define TSDB_MIN_TOTAL_BLOCKS 3
|
#define TSDB_MIN_TOTAL_BLOCKS 3
|
||||||
#define TSDB_MAX_TOTAL_BLOCKS 10000
|
#define TSDB_MAX_TOTAL_BLOCKS 10000
|
||||||
#define TSDB_DEFAULT_TOTAL_BLOCKS 6
|
#define TSDB_DEFAULT_TOTAL_BLOCKS 6
|
||||||
|
|
||||||
#define TSDB_MIN_DAYS_PER_FILE 1
|
#define TSDB_MIN_DAYS_PER_FILE 1
|
||||||
#define TSDB_MAX_DAYS_PER_FILE 3650
|
#define TSDB_MAX_DAYS_PER_FILE 3650
|
||||||
#define TSDB_DEFAULT_DAYS_PER_FILE 10
|
#define TSDB_DEFAULT_DAYS_PER_FILE 10
|
||||||
|
|
||||||
#define TSDB_MIN_KEEP 1 // data in db to be reserved.
|
#define TSDB_MIN_KEEP 1 // data in db to be reserved.
|
||||||
#define TSDB_MAX_KEEP 365000 // data in db to be reserved.
|
#define TSDB_MAX_KEEP 365000 // data in db to be reserved.
|
||||||
#define TSDB_DEFAULT_KEEP 3650 // ten years
|
#define TSDB_DEFAULT_KEEP 3650 // ten years
|
||||||
|
|
||||||
#define TSDB_MIN_MIN_ROW_FBLOCK 10
|
#define TSDB_MIN_MIN_ROW_FBLOCK 10
|
||||||
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
|
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
|
||||||
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
|
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
|
||||||
|
|
||||||
#define TSDB_MIN_MAX_ROW_FBLOCK 200
|
#define TSDB_MIN_MAX_ROW_FBLOCK 200
|
||||||
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
|
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
|
||||||
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
|
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
|
||||||
|
|
||||||
#define TSDB_MIN_COMMIT_TIME 30
|
#define TSDB_MIN_COMMIT_TIME 30
|
||||||
#define TSDB_MAX_COMMIT_TIME 40960
|
#define TSDB_MAX_COMMIT_TIME 40960
|
||||||
#define TSDB_DEFAULT_COMMIT_TIME 3600
|
#define TSDB_DEFAULT_COMMIT_TIME 3600
|
||||||
|
|
||||||
#define TSDB_MIN_FSYNC_PERIOD 0
|
#define TSDB_MIN_FSYNC_PERIOD 0
|
||||||
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
|
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
|
||||||
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
|
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
|
||||||
|
|
||||||
#define TSDB_MIN_WAL_LEVEL 0
|
#define TSDB_MIN_WAL_LEVEL 0
|
||||||
#define TSDB_MAX_WAL_LEVEL 2
|
#define TSDB_MAX_WAL_LEVEL 2
|
||||||
#define TSDB_DEFAULT_WAL_LEVEL 1
|
#define TSDB_DEFAULT_WAL_LEVEL 1
|
||||||
|
|
||||||
#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI
|
#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI
|
||||||
#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO
|
#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO
|
||||||
#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI
|
#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI
|
||||||
|
|
||||||
#define TSDB_MIN_COMP_LEVEL 0
|
#define TSDB_MIN_COMP_LEVEL 0
|
||||||
#define TSDB_MAX_COMP_LEVEL 2
|
#define TSDB_MAX_COMP_LEVEL 2
|
||||||
#define TSDB_DEFAULT_COMP_LEVEL 2
|
#define TSDB_DEFAULT_COMP_LEVEL 2
|
||||||
|
|
||||||
#define TSDB_MIN_DB_REPLICA_OPTION 1
|
#define TSDB_MIN_DB_REPLICA_OPTION 1
|
||||||
#define TSDB_MAX_DB_REPLICA_OPTION 3
|
#define TSDB_MAX_DB_REPLICA_OPTION 3
|
||||||
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
|
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
|
||||||
|
|
||||||
#define TSDB_MIN_DB_QUORUM_OPTION 1
|
#define TSDB_MIN_DB_QUORUM_OPTION 1
|
||||||
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
||||||
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
||||||
|
|
||||||
#define TSDB_MIN_DB_UPDATE 0
|
#define TSDB_MIN_DB_UPDATE 0
|
||||||
#define TSDB_MAX_DB_UPDATE 2
|
#define TSDB_MAX_DB_UPDATE 2
|
||||||
#define TSDB_DEFAULT_DB_UPDATE_OPTION 0
|
#define TSDB_DEFAULT_DB_UPDATE_OPTION 0
|
||||||
|
|
||||||
#define TSDB_MIN_DB_CACHE_LAST_ROW 0
|
#define TSDB_MIN_DB_CACHE_LAST_ROW 0
|
||||||
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
|
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
|
||||||
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
|
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
|
||||||
|
|
||||||
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
||||||
#define TSDB_MAX_UNION_CLAUSE 5
|
#define TSDB_MAX_UNION_CLAUSE 5
|
||||||
|
|
||||||
#define TSDB_MAX_FIELD_LEN 16384
|
#define TSDB_MAX_FIELD_LEN 16384
|
||||||
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
|
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
|
||||||
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
|
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
|
||||||
#define PRIMARYKEY_TIMESTAMP_COL_ID 1
|
#define PRIMARYKEY_TIMESTAMP_COL_ID 1
|
||||||
#define COL_REACH_END(colId, maxColId) ((colId) > (maxColId))
|
#define COL_REACH_END(colId, maxColId) ((colId) > (maxColId))
|
||||||
|
|
||||||
#define TSDB_MAX_RPC_THREADS 5
|
#define TSDB_MAX_RPC_THREADS 5
|
||||||
|
|
||||||
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
|
|
||||||
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
|
|
||||||
|
|
||||||
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
|
|
||||||
|
|
||||||
|
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
|
||||||
|
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
|
||||||
|
|
||||||
|
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. ordinary sub query for select * from super_table
|
* 1. ordinary sub query for select * from super_table
|
||||||
* 2. all sqlobj generated by createSubqueryObj with this flag
|
* 2. all sqlobj generated by createSubqueryObj with this flag
|
||||||
*/
|
*/
|
||||||
#define TSDB_QUERY_TYPE_SUBQUERY 0x02u
|
#define TSDB_QUERY_TYPE_SUBQUERY 0x02u
|
||||||
#define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x04u // two-stage subquery for super table
|
#define TSDB_QUERY_TYPE_STABLE_SUBQUERY 0x04u // two-stage subquery for super table
|
||||||
|
|
||||||
#define TSDB_QUERY_TYPE_TABLE_QUERY 0x08u // query ordinary table; below only apply to client side
|
#define TSDB_QUERY_TYPE_TABLE_QUERY 0x08u // query ordinary table; below only apply to client side
|
||||||
#define TSDB_QUERY_TYPE_STABLE_QUERY 0x10u // query on super table
|
#define TSDB_QUERY_TYPE_STABLE_QUERY 0x10u // query on super table
|
||||||
#define TSDB_QUERY_TYPE_JOIN_QUERY 0x20u // join query
|
#define TSDB_QUERY_TYPE_JOIN_QUERY 0x20u // join query
|
||||||
#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40u // select *,columns... query
|
#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40u // select *,columns... query
|
||||||
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80u // join sub query at the second stage
|
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80u // join sub query at the second stage
|
||||||
|
|
||||||
#define TSDB_QUERY_TYPE_TAG_FILTER_QUERY 0x400u
|
#define TSDB_QUERY_TYPE_TAG_FILTER_QUERY 0x400u
|
||||||
#define TSDB_QUERY_TYPE_INSERT 0x100u // insert type
|
#define TSDB_QUERY_TYPE_INSERT 0x100u // insert type
|
||||||
#define TSDB_QUERY_TYPE_MULTITABLE_QUERY 0x200u
|
#define TSDB_QUERY_TYPE_MULTITABLE_QUERY 0x200u
|
||||||
#define TSDB_QUERY_TYPE_FILE_INSERT 0x400u // insert data from file
|
#define TSDB_QUERY_TYPE_FILE_INSERT 0x400u // insert data from file
|
||||||
#define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type
|
#define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type
|
||||||
#define TSDB_QUERY_TYPE_NEST_SUBQUERY 0x1000u // nested sub query
|
#define TSDB_QUERY_TYPE_NEST_SUBQUERY 0x1000u // nested sub query
|
||||||
|
|
||||||
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
|
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
|
||||||
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
|
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
|
||||||
#define TSDB_QUERY_CLEAR_TYPE(x, _type) ((x) &= (~_type))
|
#define TSDB_QUERY_CLEAR_TYPE(x, _type) ((x) &= (~_type))
|
||||||
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
|
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
|
||||||
|
|
||||||
#define TSDB_ORDER_ASC 1
|
#define TSDB_ORDER_ASC 1
|
||||||
#define TSDB_ORDER_DESC 2
|
#define TSDB_ORDER_DESC 2
|
||||||
|
|
||||||
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
|
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
|
||||||
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5
|
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5
|
||||||
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10
|
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10
|
||||||
#define TSDB_DEFAULT_ACCOUNTS_HASH_SIZE 10
|
#define TSDB_DEFAULT_ACCOUNTS_HASH_SIZE 10
|
||||||
#define TSDB_DEFAULT_USERS_HASH_SIZE 20
|
#define TSDB_DEFAULT_USERS_HASH_SIZE 20
|
||||||
#define TSDB_DEFAULT_DBS_HASH_SIZE 100
|
#define TSDB_DEFAULT_DBS_HASH_SIZE 100
|
||||||
#define TSDB_DEFAULT_VGROUPS_HASH_SIZE 100
|
#define TSDB_DEFAULT_VGROUPS_HASH_SIZE 100
|
||||||
#define TSDB_DEFAULT_STABLES_HASH_SIZE 100
|
#define TSDB_DEFAULT_STABLES_HASH_SIZE 100
|
||||||
#define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000
|
#define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000
|
||||||
|
|
||||||
#define TSDB_MAX_WAL_SIZE (1024*1024*3)
|
#define TSDB_MAX_WAL_SIZE (1024 * 1024 * 3)
|
||||||
|
|
||||||
#define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P
|
#define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P
|
||||||
|
|
||||||
#define TFS_MAX_TIERS 3
|
#define TFS_MAX_TIERS 3
|
||||||
#define TFS_MAX_DISKS_PER_TIER 16
|
#define TFS_MAX_DISKS_PER_TIER 16
|
||||||
#define TFS_MAX_DISKS (TFS_MAX_TIERS * TFS_MAX_DISKS_PER_TIER)
|
#define TFS_MAX_DISKS (TFS_MAX_TIERS * TFS_MAX_DISKS_PER_TIER)
|
||||||
#define TFS_MIN_LEVEL 0
|
#define TFS_MIN_LEVEL 0
|
||||||
#define TFS_MAX_LEVEL (TFS_MAX_TIERS - 1)
|
#define TFS_MAX_LEVEL (TFS_MAX_TIERS - 1)
|
||||||
#define TFS_PRIMARY_LEVEL 0
|
#define TFS_PRIMARY_LEVEL 0
|
||||||
#define TFS_PRIMARY_ID 0
|
#define TFS_PRIMARY_ID 0
|
||||||
#define TFS_MIN_DISK_FREE_SIZE 50 * 1024 * 1024
|
#define TFS_MIN_DISK_FREE_SIZE 50 * 1024 * 1024
|
||||||
|
|
||||||
enum { TRANS_STAT_INIT = 0, TRANS_STAT_EXECUTING, TRANS_STAT_EXECUTED, TRANS_STAT_ROLLBACKING, TRANS_STAT_ROLLBACKED };
|
enum { TRANS_STAT_INIT = 0, TRANS_STAT_EXECUTING, TRANS_STAT_EXECUTED, TRANS_STAT_ROLLBACKING, TRANS_STAT_ROLLBACKED };
|
||||||
enum { TRANS_OPER_INIT = 0, TRANS_OPER_EXECUTE, TRANS_OPER_ROLLBACK };
|
enum { TRANS_OPER_INIT = 0, TRANS_OPER_EXECUTE, TRANS_OPER_ROLLBACK };
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char dir[TSDB_FILENAME_LEN];
|
||||||
|
int32_t level;
|
||||||
|
int32_t primary;
|
||||||
|
} SDiskCfg;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,23 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_COMMON_CFG_H_
|
#ifndef _TD_UTIL_DES_H
|
||||||
#define _TD_COMMON_CFG_H_
|
#define _TD_UTIL_DES_H
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tdef.h"
|
char *taosDesEncode(int64_t key, char *src, int32_t len);
|
||||||
|
char *taosDesDecode(int64_t key, char *src, int32_t len);
|
||||||
typedef struct {
|
|
||||||
char dir[TSDB_FILENAME_LEN];
|
|
||||||
int level;
|
|
||||||
int primary;
|
|
||||||
} SDiskCfg;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_COMMON_CFG_H_*/
|
#endif /*_TD_UTIL_DES_H*/
|
|
@ -16,8 +16,8 @@
|
||||||
#ifndef _TD_UTIL_ENCODE_H_
|
#ifndef _TD_UTIL_ENCODE_H_
|
||||||
#define _TD_UTIL_ENCODE_H_
|
#define _TD_UTIL_ENCODE_H_
|
||||||
|
|
||||||
#include "freelist.h"
|
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
|
#include "tfreelist.h"
|
||||||
#include "tmacro.h"
|
#include "tmacro.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -71,62 +71,62 @@ typedef struct {
|
||||||
TD_SLIST(SCoderNode) stack;
|
TD_SLIST(SCoderNode) stack;
|
||||||
} SCoder;
|
} SCoder;
|
||||||
|
|
||||||
#define TD_CODER_POS(CODER) ((CODER)->pos)
|
#define TD_CODER_POS(CODER) ((CODER)->pos)
|
||||||
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
|
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
|
||||||
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
|
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
|
||||||
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
|
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
|
||||||
#define TCODER_MALLOC(SIZE, CODER) TFL_MALLOC(SIZE, &((CODER)->fl))
|
#define TCODER_MALLOC(SIZE, CODER) TFL_MALLOC(SIZE, &((CODER)->fl))
|
||||||
|
|
||||||
void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type);
|
void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type);
|
||||||
void tCoderClear(SCoder* pCoder);
|
void tCoderClear(SCoder* pCoder);
|
||||||
|
|
||||||
/* ------------------------ ENCODE ------------------------ */
|
/* ------------------------ ENCODE ------------------------ */
|
||||||
int tStartEncode(SCoder* pEncoder);
|
int32_t tStartEncode(SCoder* pEncoder);
|
||||||
void tEndEncode(SCoder* pEncoder);
|
void tEndEncode(SCoder* pEncoder);
|
||||||
static int tEncodeU8(SCoder* pEncoder, uint8_t val);
|
static int32_t tEncodeU8(SCoder* pEncoder, uint8_t val);
|
||||||
static int tEncodeI8(SCoder* pEncoder, int8_t val);
|
static int32_t tEncodeI8(SCoder* pEncoder, int8_t val);
|
||||||
static int tEncodeU16(SCoder* pEncoder, uint16_t val);
|
static int32_t tEncodeU16(SCoder* pEncoder, uint16_t val);
|
||||||
static int tEncodeI16(SCoder* pEncoder, int16_t val);
|
static int32_t tEncodeI16(SCoder* pEncoder, int16_t val);
|
||||||
static int tEncodeU32(SCoder* pEncoder, uint32_t val);
|
static int32_t tEncodeU32(SCoder* pEncoder, uint32_t val);
|
||||||
static int tEncodeI32(SCoder* pEncoder, int32_t val);
|
static int32_t tEncodeI32(SCoder* pEncoder, int32_t val);
|
||||||
static int tEncodeU64(SCoder* pEncoder, uint64_t val);
|
static int32_t tEncodeU64(SCoder* pEncoder, uint64_t val);
|
||||||
static int tEncodeI64(SCoder* pEncoder, int64_t val);
|
static int32_t tEncodeI64(SCoder* pEncoder, int64_t val);
|
||||||
static int tEncodeU16v(SCoder* pEncoder, uint16_t val);
|
static int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val);
|
||||||
static int tEncodeI16v(SCoder* pEncoder, int16_t val);
|
static int32_t tEncodeI16v(SCoder* pEncoder, int16_t val);
|
||||||
static int tEncodeU32v(SCoder* pEncoder, uint32_t val);
|
static int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val);
|
||||||
static int tEncodeI32v(SCoder* pEncoder, int32_t val);
|
static int32_t tEncodeI32v(SCoder* pEncoder, int32_t val);
|
||||||
static int tEncodeU64v(SCoder* pEncoder, uint64_t val);
|
static int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val);
|
||||||
static int tEncodeI64v(SCoder* pEncoder, int64_t val);
|
static int32_t tEncodeI64v(SCoder* pEncoder, int64_t val);
|
||||||
static int tEncodeFloat(SCoder* pEncoder, float val);
|
static int32_t tEncodeFloat(SCoder* pEncoder, float val);
|
||||||
static int tEncodeDouble(SCoder* pEncoder, double val);
|
static int32_t tEncodeDouble(SCoder* pEncoder, double val);
|
||||||
static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len);
|
static int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len);
|
||||||
static int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len);
|
static int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len);
|
||||||
static int tEncodeCStr(SCoder* pEncoder, const char* val);
|
static int32_t tEncodeCStr(SCoder* pEncoder, const char* val);
|
||||||
|
|
||||||
/* ------------------------ DECODE ------------------------ */
|
/* ------------------------ DECODE ------------------------ */
|
||||||
int tStartDecode(SCoder* pDecoder);
|
int32_t tStartDecode(SCoder* pDecoder);
|
||||||
void tEndDecode(SCoder* pDecoder);
|
void tEndDecode(SCoder* pDecoder);
|
||||||
static bool tDecodeIsEnd(SCoder* pCoder);
|
static bool tDecodeIsEnd(SCoder* pCoder);
|
||||||
static int tDecodeU8(SCoder* pDecoder, uint8_t* val);
|
static int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val);
|
||||||
static int tDecodeI8(SCoder* pDecoder, int8_t* val);
|
static int32_t tDecodeI8(SCoder* pDecoder, int8_t* val);
|
||||||
static int tDecodeU16(SCoder* pDecoder, uint16_t* val);
|
static int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val);
|
||||||
static int tDecodeI16(SCoder* pDecoder, int16_t* val);
|
static int32_t tDecodeI16(SCoder* pDecoder, int16_t* val);
|
||||||
static int tDecodeU32(SCoder* pDecoder, uint32_t* val);
|
static int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val);
|
||||||
static int tDecodeI32(SCoder* pDecoder, int32_t* val);
|
static int32_t tDecodeI32(SCoder* pDecoder, int32_t* val);
|
||||||
static int tDecodeU64(SCoder* pDecoder, uint64_t* val);
|
static int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val);
|
||||||
static int tDecodeI64(SCoder* pDecoder, int64_t* val);
|
static int32_t tDecodeI64(SCoder* pDecoder, int64_t* val);
|
||||||
static int tDecodeU16v(SCoder* pDecoder, uint16_t* val);
|
static int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val);
|
||||||
static int tDecodeI16v(SCoder* pDecoder, int16_t* val);
|
static int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val);
|
||||||
static int tDecodeU32v(SCoder* pDecoder, uint32_t* val);
|
static int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val);
|
||||||
static int tDecodeI32v(SCoder* pDecoder, int32_t* val);
|
static int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val);
|
||||||
static int tDecodeU64v(SCoder* pDecoder, uint64_t* val);
|
static int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val);
|
||||||
static int tDecodeI64v(SCoder* pDecoder, int64_t* val);
|
static int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val);
|
||||||
static int tDecodeFloat(SCoder* pDecoder, float* val);
|
static int32_t tDecodeFloat(SCoder* pDecoder, float* val);
|
||||||
static int tDecodeDouble(SCoder* pDecoder, double* val);
|
static int32_t tDecodeDouble(SCoder* pDecoder, double* val);
|
||||||
static int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len);
|
static int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len);
|
||||||
static int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len);
|
static int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len);
|
||||||
static int tDecodeCStr(SCoder* pDecoder, const char** val);
|
static int32_t tDecodeCStr(SCoder* pDecoder, const char** val);
|
||||||
static int tDecodeCStrTo(SCoder* pDecoder, char* val);
|
static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val);
|
||||||
|
|
||||||
/* ------------------------ IMPL ------------------------ */
|
/* ------------------------ IMPL ------------------------ */
|
||||||
#define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \
|
#define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \
|
||||||
|
@ -190,7 +190,7 @@ static int tDecodeCStrTo(SCoder* pDecoder, char* val);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// 8
|
// 8
|
||||||
static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) {
|
static FORCE_INLINE int32_t tEncodeU8(SCoder* pEncoder, uint8_t val) {
|
||||||
if (pEncoder->data) {
|
if (pEncoder->data) {
|
||||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
||||||
tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val);
|
tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val);
|
||||||
|
@ -199,7 +199,7 @@ static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) {
|
static FORCE_INLINE int32_t tEncodeI8(SCoder* pEncoder, int8_t val) {
|
||||||
if (pEncoder->data) {
|
if (pEncoder->data) {
|
||||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
||||||
tPut(int8_t, TD_CODER_CURRENT(pEncoder), val);
|
tPut(int8_t, TD_CODER_CURRENT(pEncoder), val);
|
||||||
|
@ -209,31 +209,31 @@ static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 16
|
// 16
|
||||||
static FORCE_INLINE int tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); }
|
static FORCE_INLINE int32_t tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); }
|
||||||
static FORCE_INLINE int tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); }
|
static FORCE_INLINE int32_t tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); }
|
||||||
// 32
|
// 32
|
||||||
static FORCE_INLINE int tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); }
|
static FORCE_INLINE int32_t tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); }
|
||||||
static FORCE_INLINE int tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); }
|
static FORCE_INLINE int32_t tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); }
|
||||||
// 64
|
// 64
|
||||||
static FORCE_INLINE int tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); }
|
static FORCE_INLINE int32_t tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); }
|
||||||
static FORCE_INLINE int tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); }
|
static FORCE_INLINE int32_t tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); }
|
||||||
// 16v
|
// 16v
|
||||||
static FORCE_INLINE int tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
static FORCE_INLINE int32_t tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||||
static FORCE_INLINE int tEncodeI16v(SCoder* pEncoder, int16_t val) {
|
static FORCE_INLINE int32_t tEncodeI16v(SCoder* pEncoder, int16_t val) {
|
||||||
return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val));
|
return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val));
|
||||||
}
|
}
|
||||||
// 32v
|
// 32v
|
||||||
static FORCE_INLINE int tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
static FORCE_INLINE int32_t tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||||
static FORCE_INLINE int tEncodeI32v(SCoder* pEncoder, int32_t val) {
|
static FORCE_INLINE int32_t tEncodeI32v(SCoder* pEncoder, int32_t val) {
|
||||||
return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val));
|
return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val));
|
||||||
}
|
}
|
||||||
// 64v
|
// 64v
|
||||||
static FORCE_INLINE int tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
static FORCE_INLINE int32_t tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||||
static FORCE_INLINE int tEncodeI64v(SCoder* pEncoder, int64_t val) {
|
static FORCE_INLINE int32_t tEncodeI64v(SCoder* pEncoder, int64_t val) {
|
||||||
return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val));
|
return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) {
|
static FORCE_INLINE int32_t tEncodeFloat(SCoder* pEncoder, float val) {
|
||||||
union {
|
union {
|
||||||
uint32_t ui;
|
uint32_t ui;
|
||||||
float f;
|
float f;
|
||||||
|
@ -242,7 +242,7 @@ static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) {
|
||||||
return tEncodeU32(pEncoder, v.ui);
|
return tEncodeU32(pEncoder, v.ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) {
|
static FORCE_INLINE int32_t tEncodeDouble(SCoder* pEncoder, double val) {
|
||||||
union {
|
union {
|
||||||
uint64_t ui;
|
uint64_t ui;
|
||||||
double d;
|
double d;
|
||||||
|
@ -251,7 +251,7 @@ static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) {
|
||||||
return tEncodeU64(pEncoder, v.ui);
|
return tEncodeU64(pEncoder, v.ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) {
|
static FORCE_INLINE int32_t tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) {
|
||||||
if (tEncodeU64v(pEncoder, len) < 0) return -1;
|
if (tEncodeU64v(pEncoder, len) < 0) return -1;
|
||||||
if (pEncoder->data) {
|
if (pEncoder->data) {
|
||||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1;
|
||||||
|
@ -262,24 +262,24 @@ static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) {
|
static FORCE_INLINE int32_t tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) {
|
||||||
return tEncodeBinary(pEncoder, (void*)val, len + 1);
|
return tEncodeBinary(pEncoder, (void*)val, len + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) {
|
static FORCE_INLINE int32_t tEncodeCStr(SCoder* pEncoder, const char* val) {
|
||||||
return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val));
|
return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------ FOR DECODER ------------------------ */
|
/* ------------------------ FOR DECODER ------------------------ */
|
||||||
// 8
|
// 8
|
||||||
static FORCE_INLINE int tDecodeU8(SCoder* pDecoder, uint8_t* val) {
|
static FORCE_INLINE int32_t tDecodeU8(SCoder* pDecoder, uint8_t* val) {
|
||||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
||||||
tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val);
|
tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val);
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) {
|
static FORCE_INLINE int32_t tDecodeI8(SCoder* pDecoder, int8_t* val) {
|
||||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
||||||
tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val);
|
tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val);
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
||||||
|
@ -287,21 +287,27 @@ static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 16
|
// 16
|
||||||
static FORCE_INLINE int tDecodeU16(SCoder* pDecoder, uint16_t* val) { TD_DECODE_MACRO(pDecoder, val, uint16_t, 16); }
|
static FORCE_INLINE int32_t tDecodeU16(SCoder* pDecoder, uint16_t* val) {
|
||||||
static FORCE_INLINE int tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); }
|
TD_DECODE_MACRO(pDecoder, val, uint16_t, 16);
|
||||||
|
}
|
||||||
|
static FORCE_INLINE int32_t tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); }
|
||||||
// 32
|
// 32
|
||||||
static FORCE_INLINE int tDecodeU32(SCoder* pDecoder, uint32_t* val) { TD_DECODE_MACRO(pDecoder, val, uint32_t, 32); }
|
static FORCE_INLINE int32_t tDecodeU32(SCoder* pDecoder, uint32_t* val) {
|
||||||
static FORCE_INLINE int tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); }
|
TD_DECODE_MACRO(pDecoder, val, uint32_t, 32);
|
||||||
|
}
|
||||||
|
static FORCE_INLINE int32_t tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); }
|
||||||
// 64
|
// 64
|
||||||
static FORCE_INLINE int tDecodeU64(SCoder* pDecoder, uint64_t* val) { TD_DECODE_MACRO(pDecoder, val, uint64_t, 64); }
|
static FORCE_INLINE int32_t tDecodeU64(SCoder* pDecoder, uint64_t* val) {
|
||||||
static FORCE_INLINE int tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); }
|
TD_DECODE_MACRO(pDecoder, val, uint64_t, 64);
|
||||||
|
}
|
||||||
|
static FORCE_INLINE int32_t tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); }
|
||||||
|
|
||||||
// 16v
|
// 16v
|
||||||
static FORCE_INLINE int tDecodeU16v(SCoder* pDecoder, uint16_t* val) {
|
static FORCE_INLINE int32_t tDecodeU16v(SCoder* pDecoder, uint16_t* val) {
|
||||||
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t);
|
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) {
|
static FORCE_INLINE int32_t tDecodeI16v(SCoder* pDecoder, int16_t* val) {
|
||||||
uint16_t tval;
|
uint16_t tval;
|
||||||
if (tDecodeU16v(pDecoder, &tval) < 0) {
|
if (tDecodeU16v(pDecoder, &tval) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -311,11 +317,11 @@ static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32v
|
// 32v
|
||||||
static FORCE_INLINE int tDecodeU32v(SCoder* pDecoder, uint32_t* val) {
|
static FORCE_INLINE int32_t tDecodeU32v(SCoder* pDecoder, uint32_t* val) {
|
||||||
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t);
|
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) {
|
static FORCE_INLINE int32_t tDecodeI32v(SCoder* pDecoder, int32_t* val) {
|
||||||
uint32_t tval;
|
uint32_t tval;
|
||||||
if (tDecodeU32v(pDecoder, &tval) < 0) {
|
if (tDecodeU32v(pDecoder, &tval) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -325,11 +331,11 @@ static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 64v
|
// 64v
|
||||||
static FORCE_INLINE int tDecodeU64v(SCoder* pDecoder, uint64_t* val) {
|
static FORCE_INLINE int32_t tDecodeU64v(SCoder* pDecoder, uint64_t* val) {
|
||||||
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t);
|
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) {
|
static FORCE_INLINE int32_t tDecodeI64v(SCoder* pDecoder, int64_t* val) {
|
||||||
uint64_t tval;
|
uint64_t tval;
|
||||||
if (tDecodeU64v(pDecoder, &tval) < 0) {
|
if (tDecodeU64v(pDecoder, &tval) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -338,7 +344,7 @@ static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) {
|
static FORCE_INLINE int32_t tDecodeFloat(SCoder* pDecoder, float* val) {
|
||||||
union {
|
union {
|
||||||
uint32_t ui;
|
uint32_t ui;
|
||||||
float f;
|
float f;
|
||||||
|
@ -352,7 +358,7 @@ static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) {
|
static FORCE_INLINE int32_t tDecodeDouble(SCoder* pDecoder, double* val) {
|
||||||
union {
|
union {
|
||||||
uint64_t ui;
|
uint64_t ui;
|
||||||
double d;
|
double d;
|
||||||
|
@ -366,7 +372,7 @@ static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) {
|
static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) {
|
||||||
if (tDecodeU64v(pDecoder, len) < 0) return -1;
|
if (tDecodeU64v(pDecoder, len) < 0) return -1;
|
||||||
|
|
||||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
|
||||||
|
@ -376,18 +382,18 @@ static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) {
|
static FORCE_INLINE int32_t tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) {
|
||||||
if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1;
|
if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1;
|
||||||
(*len) -= 1;
|
(*len) -= 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeCStr(SCoder* pDecoder, const char** val) {
|
static FORCE_INLINE int32_t tDecodeCStr(SCoder* pDecoder, const char** val) {
|
||||||
uint64_t len;
|
uint64_t len;
|
||||||
return tDecodeCStrAndLen(pDecoder, val, &len);
|
return tDecodeCStrAndLen(pDecoder, val, &len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tDecodeCStrTo(SCoder* pDecoder, char* val) {
|
static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) {
|
||||||
const char* pStr;
|
const char* pStr;
|
||||||
uint64_t len;
|
uint64_t len;
|
||||||
if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1;
|
if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1;
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 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_EXCEPTION_H_
|
||||||
|
#define _TD_UTIL_EXCEPTION_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cleanup actions
|
||||||
|
*/
|
||||||
|
typedef struct SCleanupAction {
|
||||||
|
bool failOnly;
|
||||||
|
uint8_t wrapper;
|
||||||
|
uint16_t reserved;
|
||||||
|
void* func;
|
||||||
|
union {
|
||||||
|
void* Ptr;
|
||||||
|
bool Bool;
|
||||||
|
char Char;
|
||||||
|
int8_t Int8;
|
||||||
|
uint8_t Uint8;
|
||||||
|
int16_t Int16;
|
||||||
|
uint16_t Uint16;
|
||||||
|
int32_t Int;
|
||||||
|
uint32_t Uint;
|
||||||
|
int32_t Int32;
|
||||||
|
uint32_t Uint32;
|
||||||
|
int64_t Int64;
|
||||||
|
uint64_t Uint64;
|
||||||
|
float Float;
|
||||||
|
double Double;
|
||||||
|
} arg1, arg2;
|
||||||
|
} SCleanupAction;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* exception hander registration
|
||||||
|
*/
|
||||||
|
typedef struct SExceptionNode {
|
||||||
|
struct SExceptionNode* prev;
|
||||||
|
jmp_buf jb;
|
||||||
|
int32_t code;
|
||||||
|
int32_t maxCleanupAction;
|
||||||
|
int32_t numCleanupAction;
|
||||||
|
SCleanupAction* cleanupActions;
|
||||||
|
} SExceptionNode;
|
||||||
|
|
||||||
|
// functions & macros for auto-cleanup
|
||||||
|
|
||||||
|
void cleanupPush_void_ptr_ptr(bool failOnly, void* func, void* arg1, void* arg2);
|
||||||
|
void cleanupPush_void_ptr_bool(bool failOnly, void* func, void* arg1, bool arg2);
|
||||||
|
void cleanupPush_void_ptr(bool failOnly, void* func, void* arg);
|
||||||
|
void cleanupPush_int_int(bool failOnly, void* func, int32_t arg);
|
||||||
|
void cleanupPush_void(bool failOnly, void* func);
|
||||||
|
void cleanupPush_int_ptr(bool failOnly, void* func, void* arg);
|
||||||
|
|
||||||
|
int32_t cleanupGetActionCount();
|
||||||
|
void cleanupExecuteTo(int32_t anchor, bool failed);
|
||||||
|
void cleanupExecute(SExceptionNode* node, bool failed);
|
||||||
|
bool cleanupExceedLimit();
|
||||||
|
|
||||||
|
#define CLEANUP_PUSH_VOID_PTR_PTR(failOnly, func, arg1, arg2) \
|
||||||
|
cleanupPush_void_ptr_ptr((failOnly), (void*)(func), (void*)(arg1), (void*)(arg2))
|
||||||
|
#define CLEANUP_PUSH_VOID_PTR_BOOL(failOnly, func, arg1, arg2) \
|
||||||
|
cleanupPush_void_ptr_bool((failOnly), (void*)(func), (void*)(arg1), (bool)(arg2))
|
||||||
|
#define CLEANUP_PUSH_VOID_PTR(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (void*)(arg))
|
||||||
|
#define CLEANUP_PUSH_INT_INT(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (int32_t)(arg))
|
||||||
|
#define CLEANUP_PUSH_VOID(failOnly, func) cleanupPush_void((failOnly), (void*)(func))
|
||||||
|
#define CLEANUP_PUSH_INT_PTR(failOnly, func, arg) cleanupPush_int_ptr((failOnly), (void*)(func), (void*)(arg))
|
||||||
|
#define CLEANUP_PUSH_FREE(failOnly, arg) cleanupPush_void_ptr((failOnly), free, (void*)(arg))
|
||||||
|
#define CLEANUP_PUSH_CLOSE(failOnly, arg) cleanupPush_int_int((failOnly), close, (int32_t)(arg))
|
||||||
|
#define CLEANUP_PUSH_FCLOSE(failOnly, arg) cleanupPush_int_ptr((failOnly), fclose, (void*)(arg))
|
||||||
|
|
||||||
|
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
|
||||||
|
#define CLEANUP_EXECUTE_TO(anchor, failed) cleanupExecuteTo((anchor), (failed))
|
||||||
|
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
|
||||||
|
|
||||||
|
// functions & macros for exception handling
|
||||||
|
|
||||||
|
void exceptionPushNode(SExceptionNode* node);
|
||||||
|
int32_t exceptionPopNode();
|
||||||
|
void exceptionThrow(int32_t code);
|
||||||
|
|
||||||
|
#define TRY(maxCleanupActions) \
|
||||||
|
do { \
|
||||||
|
SExceptionNode exceptionNode = {0}; \
|
||||||
|
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
|
||||||
|
exceptionNode.maxCleanupAction = (maxCleanupActions) > 0 ? (maxCleanupActions) : 1; \
|
||||||
|
exceptionNode.cleanupActions = cleanupActions; \
|
||||||
|
exceptionPushNode(&exceptionNode); \
|
||||||
|
int32_t caughtException = setjmp(exceptionNode.jb); \
|
||||||
|
if (caughtException == 0)
|
||||||
|
|
||||||
|
#define CATCH(code) \
|
||||||
|
int32_t code = exceptionPopNode(); \
|
||||||
|
if (caughtException == 1)
|
||||||
|
|
||||||
|
#define FINALLY(code) int32_t code = exceptionPopNode();
|
||||||
|
|
||||||
|
#define END_TRY \
|
||||||
|
} \
|
||||||
|
while (0) \
|
||||||
|
;
|
||||||
|
|
||||||
|
#define THROW(x) exceptionThrow((x))
|
||||||
|
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
|
||||||
|
#define CLEANUP_EXECUTE() cleanupExecute(&exceptionNode, CAUGHT_EXCEPTION())
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_UTIL_EXCEPTION_H_*/
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* 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,7 +16,6 @@
|
||||||
#ifndef _TD_UTIL_FREELIST_H_
|
#ifndef _TD_UTIL_FREELIST_H_
|
||||||
#define _TD_UTIL_FREELIST_H_
|
#define _TD_UTIL_FREELIST_H_
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
|
@ -12,45 +12,45 @@
|
||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
#ifndef _TD_UTIL_FUNCTIONAL_H
|
#ifndef _TD_UTIL_FUNCTIONAL_H_
|
||||||
#define _TD_UTIL_FUNCTIONAL_H
|
#define _TD_UTIL_FUNCTIONAL_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
// TODO: hard to use, trying to rewrite it using va_list
|
||||||
|
|
||||||
//TODO: hard to use, trying to rewrite it using va_list
|
|
||||||
|
|
||||||
typedef void* (*GenericVaFunc)(void* args[]);
|
typedef void* (*GenericVaFunc)(void* args[]);
|
||||||
typedef int32_t (*I32VaFunc) (void* args[]);
|
typedef int32_t (*I32VaFunc)(void* args[]);
|
||||||
typedef void (*VoidVaFunc) (void* args[]);
|
typedef void (*VoidVaFunc)(void* args[]);
|
||||||
|
|
||||||
typedef struct GenericSavedFunc {
|
typedef struct GenericSavedFunc {
|
||||||
GenericVaFunc func;
|
GenericVaFunc func;
|
||||||
void * args[];
|
void* args[];
|
||||||
} tGenericSavedFunc;
|
} tGenericSavedFunc;
|
||||||
|
|
||||||
typedef struct I32SavedFunc {
|
typedef struct I32SavedFunc {
|
||||||
I32VaFunc func;
|
I32VaFunc func;
|
||||||
void * args[];
|
void* args[];
|
||||||
} tI32SavedFunc;
|
} tI32SavedFunc;
|
||||||
|
|
||||||
typedef struct VoidSavedFunc {
|
typedef struct VoidSavedFunc {
|
||||||
VoidVaFunc func;
|
VoidVaFunc func;
|
||||||
void * args[];
|
void* args[];
|
||||||
} tVoidSavedFunc;
|
} tVoidSavedFunc;
|
||||||
|
|
||||||
tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int numOfArgs);
|
tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int32_t numOfArgs);
|
||||||
tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int numOfArgs);
|
tI32SavedFunc* i32SavedFuncInit(I32VaFunc func, int32_t numOfArgs);
|
||||||
tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int numOfArgs);
|
tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int32_t numOfArgs);
|
||||||
void* genericInvoke(tGenericSavedFunc* const pSavedFunc);
|
void* genericInvoke(tGenericSavedFunc* const pSavedFunc);
|
||||||
int32_t i32Invoke(tI32SavedFunc* const pSavedFunc);
|
int32_t i32Invoke(tI32SavedFunc* const pSavedFunc);
|
||||||
void voidInvoke(tVoidSavedFunc* const pSavedFunc);
|
void voidInvoke(tVoidSavedFunc* const pSavedFunc);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_FUNCTIONAL_H*/
|
#endif /*_TD_UTIL_FUNCTIONAL_H_*/
|
||||||
|
|
|
@ -13,22 +13,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_HASH_H
|
#ifndef _TD_UTIL_HASH_H_
|
||||||
#define TDENGINE_HASH_H
|
#define _TD_UTIL_HASH_H_
|
||||||
|
|
||||||
|
#include "tarray.h"
|
||||||
|
#include "tlockfree.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tarray.h"
|
|
||||||
#include "tlockfree.h"
|
|
||||||
|
|
||||||
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
|
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
|
||||||
typedef int32_t (*_equal_fn_t)(const void*, const void*, size_t len);
|
typedef int32_t (*_equal_fn_t)(const void *, const void *, size_t len);
|
||||||
typedef void (*_hash_before_fn_t)(void *);
|
typedef void (*_hash_before_fn_t)(void *);
|
||||||
typedef void (*_hash_free_fn_t)(void *);
|
typedef void (*_hash_free_fn_t)(void *);
|
||||||
|
|
||||||
#define HASH_MAX_CAPACITY (1024 * 1024 * 16)
|
#define HASH_MAX_CAPACITY (1024 * 1024 * 16)
|
||||||
#define HASH_DEFAULT_LOAD_FACTOR (0.75)
|
#define HASH_DEFAULT_LOAD_FACTOR (0.75)
|
||||||
|
|
||||||
#define HASH_INDEX(v, c) ((v) & ((c)-1))
|
#define HASH_INDEX(v, c) ((v) & ((c)-1))
|
||||||
|
@ -59,43 +59,43 @@ _equal_fn_t taosGetDefaultEqualFunction(int32_t type);
|
||||||
|
|
||||||
typedef struct SHashNode {
|
typedef struct SHashNode {
|
||||||
struct SHashNode *next;
|
struct SHashNode *next;
|
||||||
uint32_t hashVal; // the hash value of key
|
uint32_t hashVal; // the hash value of key
|
||||||
uint32_t dataLen; // length of data
|
uint32_t dataLen; // length of data
|
||||||
uint32_t keyLen; // length of the key
|
uint32_t keyLen; // length of the key
|
||||||
uint16_t count; // reference count
|
uint16_t count; // reference count
|
||||||
int8_t removed; // flag to indicate removed
|
int8_t removed; // flag to indicate removed
|
||||||
char data[];
|
char data[];
|
||||||
} SHashNode;
|
} SHashNode;
|
||||||
|
|
||||||
#define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->dataLen)
|
#define GET_HASH_NODE_KEY(_n) ((char *)(_n) + sizeof(SHashNode) + (_n)->dataLen)
|
||||||
#define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode))
|
#define GET_HASH_NODE_DATA(_n) ((char *)(_n) + sizeof(SHashNode))
|
||||||
#define GET_HASH_PNODE(_n) ((SHashNode *)((char*)(_n) - sizeof(SHashNode)))
|
#define GET_HASH_PNODE(_n) ((SHashNode *)((char *)(_n) - sizeof(SHashNode)))
|
||||||
|
|
||||||
typedef enum SHashLockTypeE {
|
typedef enum SHashLockTypeE {
|
||||||
HASH_NO_LOCK = 0,
|
HASH_NO_LOCK = 0,
|
||||||
HASH_ENTRY_LOCK = 1,
|
HASH_ENTRY_LOCK = 1,
|
||||||
} SHashLockTypeE;
|
} SHashLockTypeE;
|
||||||
|
|
||||||
typedef struct SHashEntry {
|
typedef struct SHashEntry {
|
||||||
int32_t num; // number of elements in current entry
|
int32_t num; // number of elements in current entry
|
||||||
SRWLatch latch; // entry latch
|
SRWLatch latch; // entry latch
|
||||||
SHashNode *next;
|
SHashNode *next;
|
||||||
} SHashEntry;
|
} SHashEntry;
|
||||||
|
|
||||||
typedef struct SHashObj {
|
typedef struct SHashObj {
|
||||||
SHashEntry **hashList;
|
SHashEntry **hashList;
|
||||||
uint32_t capacity; // number of slots
|
uint32_t capacity; // number of slots
|
||||||
uint32_t size; // number of elements in hash table
|
uint32_t size; // number of elements in hash table
|
||||||
|
|
||||||
_hash_fn_t hashFp; // hash function
|
_hash_fn_t hashFp; // hash function
|
||||||
_hash_free_fn_t freeFp; // hash node free callback function
|
_hash_free_fn_t freeFp; // hash node free callback function
|
||||||
_equal_fn_t equalFp; // equal function
|
_equal_fn_t equalFp; // equal function
|
||||||
_hash_before_fn_t callbackFp; // function invoked before return the value to caller
|
_hash_before_fn_t callbackFp; // function invoked before return the value to caller
|
||||||
|
|
||||||
SRWLatch lock; // read-write spin lock
|
SRWLatch lock; // read-write spin lock
|
||||||
SHashLockTypeE type; // lock type
|
SHashLockTypeE type; // lock type
|
||||||
bool enableUpdate; // enable update
|
bool enableUpdate; // enable update
|
||||||
SArray *pMemBlock; // memory block allocated for SHashEntry
|
SArray *pMemBlock; // memory block allocated for SHashEntry
|
||||||
} SHashObj;
|
} SHashObj;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,7 +128,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
|
||||||
|
|
||||||
int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded);
|
int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the payload data with the specified key
|
* return the payload data with the specified key
|
||||||
*
|
*
|
||||||
|
@ -147,7 +146,7 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
|
||||||
* @param destBuf
|
* @param destBuf
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* destBuf);
|
void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone the result to interval allocated buffer
|
* Clone the result to interval allocated buffer
|
||||||
|
@ -157,7 +156,7 @@ void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void*
|
||||||
* @param destBuf
|
* @param destBuf
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz);
|
void *taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void **d, size_t *sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove item with the specified key
|
* remove item with the specified key
|
||||||
|
@ -206,15 +205,14 @@ void *taosHashIterate(SHashObj *pHashObj, void *p);
|
||||||
* @param pHashObj
|
* @param pHashObj
|
||||||
* @param p
|
* @param p
|
||||||
*/
|
*/
|
||||||
void taosHashCancelIterate(SHashObj *pHashObj, void *p);
|
void taosHashCancelIterate(SHashObj *pHashObj, void *p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the corresponding key information for a given data in hash table
|
* Get the corresponding key information for a given data in hash table
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
|
int32_t taosHashGetKey(void *data, void **key, size_t *keyLen);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the corresponding key information for a given data in hash table, using memcpy
|
* Get the corresponding key information for a given data in hash table, using memcpy
|
||||||
|
@ -222,13 +220,13 @@ int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
|
||||||
* @param dst
|
* @param dst
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static FORCE_INLINE int32_t taosHashCopyKey(void *data, void* dst) {
|
static FORCE_INLINE int32_t taosHashCopyKey(void *data, void *dst) {
|
||||||
if (NULL == data || NULL == dst) {
|
if (NULL == data || NULL == dst) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashNode * node = GET_HASH_PNODE(data);
|
SHashNode *node = GET_HASH_PNODE(data);
|
||||||
void* key = GET_HASH_NODE_KEY(node);
|
void *key = GET_HASH_NODE_KEY(node);
|
||||||
memcpy(dst, key, node->keyLen);
|
memcpy(dst, key, node->keyLen);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -249,7 +247,7 @@ int32_t taosHashGetDataLen(void *data);
|
||||||
* @param keyLen
|
* @param keyLen
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void* taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen);
|
void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* release the prevous acquired obj
|
* release the prevous acquired obj
|
||||||
|
@ -262,9 +260,8 @@ void taosHashRelease(SHashObj *pHashObj, void *p);
|
||||||
|
|
||||||
void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp);
|
void taosHashSetEqualFp(SHashObj *pHashObj, _equal_fn_t fp);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TDENGINE_HASH_H
|
#endif // _TD_UTIL_HASH_H_
|
||||||
|
|
|
@ -12,19 +12,20 @@
|
||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
#ifndef TDENGINE_HEAP_H
|
|
||||||
#define TDENGINE_HEAP_H
|
#ifndef _TD_UTIL_HEAP_H_
|
||||||
|
#define _TD_UTIL_HEAP_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
struct HeapNode;
|
struct HeapNode;
|
||||||
|
|
||||||
/* Return non-zero if a < b. */
|
/* Return non-zero if a < b. */
|
||||||
typedef int (*HeapCompareFn)(const struct HeapNode* a, const struct HeapNode* b);
|
typedef int32_t (*HeapCompareFn)(const struct HeapNode* a, const struct HeapNode* b);
|
||||||
|
|
||||||
typedef struct HeapNode {
|
typedef struct HeapNode {
|
||||||
struct HeapNode* left;
|
struct HeapNode* left;
|
||||||
|
@ -38,15 +39,14 @@ typedef struct HeapNode {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
HeapNode* min;
|
HeapNode* min;
|
||||||
size_t nelts;
|
size_t nelts;
|
||||||
HeapCompareFn compFn;
|
HeapCompareFn compFn;
|
||||||
} Heap;
|
} Heap;
|
||||||
|
|
||||||
|
|
||||||
Heap* heapCreate(HeapCompareFn fn);
|
Heap* heapCreate(HeapCompareFn fn);
|
||||||
|
|
||||||
void heapDestroy(Heap *heap);
|
void heapDestroy(Heap* heap);
|
||||||
|
|
||||||
HeapNode* heapMin(const Heap* heap);
|
HeapNode* heapMin(const Heap* heap);
|
||||||
|
|
||||||
|
@ -56,10 +56,10 @@ void heapRemove(Heap* heap, struct HeapNode* node);
|
||||||
|
|
||||||
void heapDequeue(Heap* heap);
|
void heapDequeue(Heap* heap);
|
||||||
|
|
||||||
size_t heapSize(Heap *heap);
|
size_t heapSize(Heap* heap);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TDENGINE_HASH_H
|
#endif /*_TD_UTIL_HEAP_H_*/
|
||||||
|
|
|
@ -13,31 +13,34 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_IDPOOL_H
|
#ifndef _TD_UTIL_IDPOOL_H_
|
||||||
#define _TD_UTIL_IDPOOL_H
|
#define _TD_UTIL_IDPOOL_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *taosInitIdPool(int maxId);
|
typedef struct {
|
||||||
|
int32_t maxId;
|
||||||
|
int32_t numOfFree;
|
||||||
|
int32_t freeSlot;
|
||||||
|
bool *freeList;
|
||||||
|
pthread_mutex_t mutex;
|
||||||
|
} id_pool_t;
|
||||||
|
|
||||||
int taosUpdateIdPool(void *handle, int maxId);
|
void *taosInitIdPool(int32_t maxId);
|
||||||
|
int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId);
|
||||||
int taosIdPoolMaxSize(void *handle);
|
int32_t taosIdPoolMaxSize(id_pool_t *handle);
|
||||||
|
int32_t taosAllocateId(id_pool_t *handle);
|
||||||
int taosAllocateId(void *handle);
|
void taosFreeId(id_pool_t *handle, int32_t id);
|
||||||
|
void taosIdPoolCleanUp(id_pool_t *handle);
|
||||||
void taosFreeId(void *handle, int id);
|
int32_t taosIdPoolNumOfUsed(id_pool_t *handle);
|
||||||
|
bool taosIdPoolMarkStatus(id_pool_t *handle, int32_t id);
|
||||||
void taosIdPoolCleanUp(void *handle);
|
|
||||||
|
|
||||||
int taosIdPoolNumOfUsed(void *handle);
|
|
||||||
|
|
||||||
bool taosIdPoolMarkStatus(void *handle, int id);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_IDPOOL_H*/
|
#endif /*_TD_UTIL_IDPOOL_H_*/
|
||||||
|
|
|
@ -16,18 +16,18 @@
|
||||||
#ifndef _TD_UTIL_JSON_H_
|
#ifndef _TD_UTIL_JSON_H_
|
||||||
#define _TD_UTIL_JSON_H_
|
#define _TD_UTIL_JSON_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
typedef void SJson;
|
typedef void SJson;
|
||||||
|
|
||||||
SJson* tjsonCreateObject();
|
SJson* tjsonCreateObject();
|
||||||
void tjsonDelete(SJson* pJson);
|
void tjsonDelete(SJson* pJson);
|
||||||
|
|
||||||
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName);
|
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName);
|
||||||
int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number);
|
int32_t tjsonAddIntegerToObject(SJson* pJson, const char* pName, const uint64_t number);
|
||||||
int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number);
|
int32_t tjsonAddDoubleToObject(SJson* pJson, const char* pName, const double number);
|
||||||
int32_t tjsonAddBoolToObject(SJson* pJson, const char* pName, const bool boolean);
|
int32_t tjsonAddBoolToObject(SJson* pJson, const char* pName, const bool boolean);
|
||||||
|
@ -35,7 +35,7 @@ int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal
|
||||||
int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
|
int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
|
||||||
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
|
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
|
||||||
|
|
||||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
|
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
|
||||||
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
|
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
|
||||||
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
|
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
|
||||||
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
|
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
|
||||||
|
@ -48,7 +48,7 @@ int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal);
|
||||||
int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal);
|
int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal);
|
||||||
|
|
||||||
int32_t tjsonGetArraySize(const SJson* pJson);
|
int32_t tjsonGetArraySize(const SJson* pJson);
|
||||||
SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index);
|
SJson* tjsonGetArrayItem(const SJson* pJson, int32_t index);
|
||||||
|
|
||||||
typedef int32_t (*FToJson)(const void* pObj, SJson* pJson);
|
typedef int32_t (*FToJson)(const void* pObj, SJson* pJson);
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
* 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_KEY_H
|
|
||||||
#define _TD_UTIL_KEY_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned char *base64_decode(const char *value, int inlen, int *outlen);
|
|
||||||
char * base64_encode(const unsigned char *value, int vlen);
|
|
||||||
char * taosDesEncode(int64_t key, char *src, int len);
|
|
||||||
char * taosDesDecode(int64_t key, char *src, int len);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_UTIL_KEY_H*/
|
|
|
@ -12,8 +12,11 @@
|
||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
#ifndef _TD_UTIL_LIST_H
|
|
||||||
#define _TD_UTIL_LIST_H
|
#ifndef _TD_UTIL_LIST_H_
|
||||||
|
#define _TD_UTIL_LIST_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -28,12 +31,12 @@ extern "C" {
|
||||||
#define TD_SLIST(TYPE) \
|
#define TD_SLIST(TYPE) \
|
||||||
struct { \
|
struct { \
|
||||||
struct TYPE *sl_head_; \
|
struct TYPE *sl_head_; \
|
||||||
int sl_neles_; \
|
int32_t sl_neles_; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
|
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
|
||||||
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
|
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
|
||||||
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
|
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
|
||||||
#define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) ((sln)->field.sl_next_)
|
#define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) ((sln)->field.sl_next_)
|
||||||
|
|
||||||
#define TD_SLIST_INIT(sl) \
|
#define TD_SLIST_INIT(sl) \
|
||||||
|
@ -79,16 +82,16 @@ extern "C" {
|
||||||
struct { \
|
struct { \
|
||||||
struct TYPE *dl_head_; \
|
struct TYPE *dl_head_; \
|
||||||
struct TYPE *dl_tail_; \
|
struct TYPE *dl_tail_; \
|
||||||
int dl_neles_; \
|
int32_t dl_neles_; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
|
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
|
||||||
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
|
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
|
||||||
#define TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) ((dln)->field.dl_prev_)
|
#define TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) ((dln)->field.dl_prev_)
|
||||||
#define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) ((dln)->field.dl_next_)
|
#define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) ((dln)->field.dl_next_)
|
||||||
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
|
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
|
||||||
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
|
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
|
||||||
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
|
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
|
||||||
|
|
||||||
#define TD_DLIST_INIT(dl) \
|
#define TD_DLIST_INIT(dl) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -200,29 +203,29 @@ typedef struct SListNode {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TD_DLIST(SListNode);
|
TD_DLIST(SListNode);
|
||||||
int eleSize;
|
int32_t eleSize;
|
||||||
} SList;
|
} SList;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SListNode * next;
|
SListNode *next;
|
||||||
TD_LIST_DIRECTION_T direction;
|
TD_LIST_DIRECTION_T direction;
|
||||||
} SListIter;
|
} SListIter;
|
||||||
|
|
||||||
#define listHead(l) TD_DLIST_HEAD(l)
|
#define listHead(l) TD_DLIST_HEAD(l)
|
||||||
#define listTail(l) TD_DLIST_TAIL(l)
|
#define listTail(l) TD_DLIST_TAIL(l)
|
||||||
#define listNEles(l) TD_DLIST_NELES(l)
|
#define listNEles(l) TD_DLIST_NELES(l)
|
||||||
#define listEleSize(l) ((l)->eleSize)
|
#define listEleSize(l) ((l)->eleSize)
|
||||||
#define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
|
#define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
|
||||||
#define listNodeFree(n) free(n)
|
#define listNodeFree(n) free(n)
|
||||||
|
|
||||||
void tdListInit(SList *list, int eleSize);
|
void tdListInit(SList *list, int32_t eleSize);
|
||||||
void tdListEmpty(SList *list);
|
void tdListEmpty(SList *list);
|
||||||
SList * tdListNew(int eleSize);
|
SList *tdListNew(int32_t eleSize);
|
||||||
void * tdListFree(SList *list);
|
void *tdListFree(SList *list);
|
||||||
void tdListPrependNode(SList *list, SListNode *node);
|
void tdListPrependNode(SList *list, SListNode *node);
|
||||||
void tdListAppendNode(SList *list, SListNode *node);
|
void tdListAppendNode(SList *list, SListNode *node);
|
||||||
int tdListPrepend(SList *list, void *data);
|
int32_t tdListPrepend(SList *list, void *data);
|
||||||
int tdListAppend(SList *list, void *data);
|
int32_t tdListAppend(SList *list, void *data);
|
||||||
SListNode *tdListPopHead(SList *list);
|
SListNode *tdListPopHead(SList *list);
|
||||||
SListNode *tdListPopTail(SList *list);
|
SListNode *tdListPopTail(SList *list);
|
||||||
SListNode *tdListGetHead(SList *list);
|
SListNode *tdListGetHead(SList *list);
|
||||||
|
@ -239,4 +242,4 @@ SListNode *tdListNext(SListIter *pIter);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_LIST_H*/
|
#endif /*_TD_UTIL_LIST_H_*/
|
|
@ -12,8 +12,9 @@
|
||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
#ifndef _TD_UTIL_LOCK_FREE_H
|
|
||||||
#define _TD_UTIL_LOCK_FREE_H
|
#ifndef _TD_UTIL_LOCK_FREE_H_
|
||||||
|
#define _TD_UTIL_LOCK_FREE_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// reference counting
|
// reference counting
|
||||||
typedef void (*_ref_fn_t)(const void* pObj);
|
typedef void (*_ref_fn_t)(const void *pObj);
|
||||||
|
|
||||||
#define T_REF_DECLARE() \
|
#define T_REF_DECLARE() \
|
||||||
struct { \
|
struct { \
|
||||||
|
@ -67,8 +68,6 @@ typedef void (*_ref_fn_t)(const void* pObj);
|
||||||
|
|
||||||
#define T_REF_VAL_GET(x) (x)->_ref.val
|
#define T_REF_VAL_GET(x) (x)->_ref.val
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// single writer multiple reader lock
|
// single writer multiple reader lock
|
||||||
typedef volatile int32_t SRWLatch;
|
typedef volatile int32_t SRWLatch;
|
||||||
|
|
||||||
|
@ -78,35 +77,33 @@ void taosWUnLockLatch(SRWLatch *pLatch);
|
||||||
void taosRLockLatch(SRWLatch *pLatch);
|
void taosRLockLatch(SRWLatch *pLatch);
|
||||||
void taosRUnLockLatch(SRWLatch *pLatch);
|
void taosRUnLockLatch(SRWLatch *pLatch);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// copy on read
|
// copy on read
|
||||||
#define taosCorBeginRead(x) for (uint32_t i_ = 1; 1; ++i_) { \
|
#define taosCorBeginRead(x) \
|
||||||
|
for (uint32_t i_ = 1; 1; ++i_) { \
|
||||||
int32_t old_ = atomic_add_fetch_32((x), 0); \
|
int32_t old_ = atomic_add_fetch_32((x), 0); \
|
||||||
if (old_ & 0x00000001) { \
|
if (old_ & 0x00000001) { \
|
||||||
if (i_ % 1000 == 0) { \
|
if (i_ % 1000 == 0) { \
|
||||||
sched_yield(); \
|
sched_yield(); \
|
||||||
} \
|
} \
|
||||||
continue; \
|
continue; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define taosCorEndRead(x) \
|
#define taosCorEndRead(x) \
|
||||||
if (atomic_add_fetch_32((x), 0) == old_) { \
|
if (atomic_add_fetch_32((x), 0) == old_) { \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define taosCorBeginWrite(x) taosCorBeginRead(x) \
|
#define taosCorBeginWrite(x) \
|
||||||
if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { \
|
taosCorBeginRead(x) if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { continue; }
|
||||||
continue; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define taosCorEndWrite(x) atomic_add_fetch_32((x), 1); \
|
#define taosCorEndWrite(x) \
|
||||||
break; \
|
atomic_add_fetch_32((x), 1); \
|
||||||
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_LOCK_FREE_H*/
|
#endif /*_TD_UTIL_LOCK_FREE_H_*/
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_LOG_H
|
#ifndef _TD_UTIL_LOG_H_
|
||||||
#define _TD_UTIL_LOG_H
|
#define _TD_UTIL_LOG_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -84,4 +84,4 @@ extern int8_t tscEmbeddedInUtil;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_LOG_H*/
|
#endif /*_TD_UTIL_LOG_H_*/
|
||||||
|
|
|
@ -13,14 +13,16 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_LOSERTREE_H
|
#ifndef _TD_UTIL_LOSERTREE_H_
|
||||||
#define _TD_UTIL_LOSERTREE_H
|
#define _TD_UTIL_LOSERTREE_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef int (*__merge_compare_fn_t)(const void *, const void *, void *param);
|
typedef int32_t (*__merge_compare_fn_t)(const void *, const void *, void *param);
|
||||||
|
|
||||||
typedef struct STreeNode {
|
typedef struct STreeNode {
|
||||||
int32_t index;
|
int32_t index;
|
||||||
|
@ -31,16 +33,17 @@ typedef struct SMultiwayMergeTreeInfo {
|
||||||
int32_t numOfSources;
|
int32_t numOfSources;
|
||||||
int32_t totalSources;
|
int32_t totalSources;
|
||||||
__merge_compare_fn_t comparFn;
|
__merge_compare_fn_t comparFn;
|
||||||
void * param;
|
void *param;
|
||||||
struct STreeNode *pNode;
|
struct STreeNode *pNode;
|
||||||
} SMultiwayMergeTreeInfo;
|
} SMultiwayMergeTreeInfo;
|
||||||
|
|
||||||
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
|
#define tMergeTreeGetChosenIndex(t_) ((t_)->pNode[0].index)
|
||||||
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
|
#define tMergeTreeGetAdjustIndex(t_) (tMergeTreeGetChosenIndex(t_) + (t_)->numOfSources)
|
||||||
|
|
||||||
int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param, __merge_compare_fn_t compareFn);
|
int32_t tMergeTreeCreate(SMultiwayMergeTreeInfo **pTree, uint32_t numOfEntries, void *param,
|
||||||
|
__merge_compare_fn_t compareFn);
|
||||||
|
|
||||||
void tMergeTreeDestroy(SMultiwayMergeTreeInfo* pTree);
|
void tMergeTreeDestroy(SMultiwayMergeTreeInfo *pTree);
|
||||||
|
|
||||||
void tMergeTreeAdjust(SMultiwayMergeTreeInfo *pTree, int32_t idx);
|
void tMergeTreeAdjust(SMultiwayMergeTreeInfo *pTree, int32_t idx);
|
||||||
|
|
||||||
|
@ -52,4 +55,4 @@ void tMergeTreePrint(const SMultiwayMergeTreeInfo *pTree);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_LOSERTREE_H*/
|
#endif /*_TD_UTIL_LOSERTREE_H_*/
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
// Module init/clear MACRO definitions
|
// Module init/clear MACRO definitions
|
||||||
#define TD_MOD_UNINITIALIZED 0
|
#define TD_MOD_UNINITIALIZED 0
|
||||||
#define TD_MOD_INITIALIZED 1
|
#define TD_MOD_INITIALIZED 1
|
||||||
|
|
||||||
typedef int8_t td_mode_flag_t;
|
typedef int8_t td_mode_flag_t;
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MALLOCATOR_H_
|
#ifndef _TD_UTIL_MALLOCATOR_H_
|
||||||
#define _TD_MALLOCATOR_H_
|
#define _TD_UTIL_MALLOCATOR_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -29,10 +29,10 @@ extern "C" {
|
||||||
void (*free_)(struct TYPE *, void *ptr); \
|
void (*free_)(struct TYPE *, void *ptr); \
|
||||||
}
|
}
|
||||||
#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_
|
#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_
|
||||||
#define TD_MA_FREE_FUNC(TMA) (TMA)->free_
|
#define TD_MA_FREE_FUNC(TMA) (TMA)->free_
|
||||||
|
|
||||||
#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE))
|
#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE))
|
||||||
#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR))
|
#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR))
|
||||||
|
|
||||||
typedef struct SMemAllocator {
|
typedef struct SMemAllocator {
|
||||||
void *impl;
|
void *impl;
|
||||||
|
@ -40,7 +40,7 @@ typedef struct SMemAllocator {
|
||||||
} SMemAllocator;
|
} SMemAllocator;
|
||||||
|
|
||||||
#define tMalloc(pMA, SIZE) TD_MA_MALLOC(PMA, SIZE)
|
#define tMalloc(pMA, SIZE) TD_MA_MALLOC(PMA, SIZE)
|
||||||
#define tFree(pMA, PTR) TD_MA_FREE(PMA, PTR)
|
#define tFree(pMA, PTR) TD_MA_FREE(PMA, PTR)
|
||||||
|
|
||||||
typedef struct SMemAllocatorFactory {
|
typedef struct SMemAllocatorFactory {
|
||||||
void *impl;
|
void *impl;
|
||||||
|
@ -52,4 +52,4 @@ typedef struct SMemAllocatorFactory {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MALLOCATOR_H_*/
|
#endif /*_TD_UTIL_MALLOCATOR_H_*/
|
|
@ -25,6 +25,12 @@
|
||||||
#ifndef _TD_UTIL_MD5_H
|
#ifndef _TD_UTIL_MD5_H
|
||||||
#define _TD_UTIL_MD5_H
|
#define _TD_UTIL_MD5_H
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t i[2]; /* number of _bits_ handled mod 2^64 */
|
uint32_t i[2]; /* number of _bits_ handled mod 2^64 */
|
||||||
uint32_t buf[4]; /* scratch buffer */
|
uint32_t buf[4]; /* scratch buffer */
|
||||||
|
@ -33,7 +39,11 @@ typedef struct {
|
||||||
} T_MD5_CTX;
|
} T_MD5_CTX;
|
||||||
|
|
||||||
void tMD5Init(T_MD5_CTX *mdContext);
|
void tMD5Init(T_MD5_CTX *mdContext);
|
||||||
void tMD5Update(T_MD5_CTX *mdContext, uint8_t *inBuf, unsigned int inLen);
|
void tMD5Update(T_MD5_CTX *mdContext, uint8_t *inBuf, uint32_t inLen);
|
||||||
void tMD5Final(T_MD5_CTX *mdContext);
|
void tMD5Final(T_MD5_CTX *mdContext);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_MD5_H*/
|
#endif /*_TD_UTIL_MD5_H*/
|
||||||
|
|
|
@ -12,25 +12,24 @@
|
||||||
* 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/>.
|
||||||
*/
|
*/
|
||||||
#ifndef _TD_UTIL_MEMPOOL_H
|
#ifndef _TD_UTIL_MEMPOOL_H_
|
||||||
#define _TD_UTIL_MEMPOOL_H
|
#define _TD_UTIL_MEMPOOL_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define mpool_h void *
|
typedef void *mpool_h;
|
||||||
|
|
||||||
mpool_h taosMemPoolInit(int maxNum, int blockSize);
|
mpool_h taosMemPoolInit(int32_t maxNum, int32_t blockSize);
|
||||||
|
char *taosMemPoolMalloc(mpool_h handle);
|
||||||
char *taosMemPoolMalloc(mpool_h handle);
|
void taosMemPoolFree(mpool_h handle, char *p);
|
||||||
|
void taosMemPoolCleanUp(mpool_h handle);
|
||||||
void taosMemPoolFree(mpool_h handle, char *p);
|
|
||||||
|
|
||||||
void taosMemPoolCleanUp(mpool_h handle);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_MEMPOOL_H*/
|
#endif /*_TD_UTIL_MEMPOOL_H_*/
|
||||||
|
|
|
@ -13,23 +13,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TPAGEDBUF_H
|
#ifndef _TD_UTIL_PAGEDBUF_H_
|
||||||
#define TDENGINE_TPAGEDBUF_H
|
#define _TD_UTIL_PAGEDBUF_H_
|
||||||
|
|
||||||
|
#include "thash.h"
|
||||||
|
#include "tlist.h"
|
||||||
|
#include "tlockfree.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tlist.h"
|
typedef struct SArray* SIDList;
|
||||||
#include "thash.h"
|
typedef struct SPageInfo SPageInfo;
|
||||||
#include "os.h"
|
|
||||||
#include "tlockfree.h"
|
|
||||||
|
|
||||||
typedef struct SArray* SIDList;
|
|
||||||
typedef struct SPageInfo SPageInfo;
|
|
||||||
typedef struct SDiskbasedBuf SDiskbasedBuf;
|
typedef struct SDiskbasedBuf SDiskbasedBuf;
|
||||||
|
|
||||||
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes
|
#define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes
|
||||||
|
|
||||||
typedef struct SFilePage {
|
typedef struct SFilePage {
|
||||||
int32_t num;
|
int32_t num;
|
||||||
|
@ -193,4 +192,4 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TDENGINE_TPAGEDBUF_H
|
#endif // _TD_UTIL_PAGEDBUF_H_
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_QUEUE_H
|
#ifndef _TD_UTIL_QUEUE_H_
|
||||||
#define _TD_UTIL_QUEUE_H
|
#define _TD_UTIL_QUEUE_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -47,7 +48,7 @@ typedef void (*FItems)(void *ahandle, STaosQall *qall, int32_t numOfItems);
|
||||||
STaosQueue *taosOpenQueue();
|
STaosQueue *taosOpenQueue();
|
||||||
void taosCloseQueue(STaosQueue *queue);
|
void taosCloseQueue(STaosQueue *queue);
|
||||||
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp);
|
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp);
|
||||||
void * taosAllocateQitem(int32_t size);
|
void *taosAllocateQitem(int32_t size);
|
||||||
void taosFreeQitem(void *pItem);
|
void taosFreeQitem(void *pItem);
|
||||||
int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
|
int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
|
||||||
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
||||||
|
@ -80,4 +81,4 @@ int32_t taosGetQsetItemsNumber(STaosQset *qset);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_QUEUE_H*/
|
#endif /*_TD_UTIL_QUEUE_H_*/
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_REF_H
|
#ifndef _TD_UTIL_REF_H_
|
||||||
#define _TD_UTIL_REF_H
|
#define _TD_UTIL_REF_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -25,40 +25,40 @@ extern "C" {
|
||||||
|
|
||||||
// open a reference set, max is the mod used by hash, fp is the pointer to free resource function
|
// open a reference set, max is the mod used by hash, fp is the pointer to free resource function
|
||||||
// return rsetId which will be used by other APIs. On error, -1 is returned, and terrno is set appropriately
|
// return rsetId which will be used by other APIs. On error, -1 is returned, and terrno is set appropriately
|
||||||
int taosOpenRef(int max, void (*fp)(void *));
|
int32_t taosOpenRef(int32_t max, void (*fp)(void *));
|
||||||
|
|
||||||
// close the reference set, refId is the return value by taosOpenRef
|
// close the reference set, refId is the return value by taosOpenRef
|
||||||
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
||||||
int taosCloseRef(int refId);
|
int32_t taosCloseRef(int32_t refId);
|
||||||
|
|
||||||
// add ref, p is the pointer to resource or pointer ID
|
// add ref, p is the pointer to resource or pointer ID
|
||||||
// return Reference ID(rid) allocated. On error, -1 is returned, and terrno is set appropriately
|
// return Reference ID(rid) allocated. On error, -1 is returned, and terrno is set appropriately
|
||||||
int64_t taosAddRef(int refId, void *p);
|
int64_t taosAddRef(int32_t refId, void *p);
|
||||||
|
|
||||||
// remove ref, rid is the reference ID returned by taosAddRef
|
// remove ref, rid is the reference ID returned by taosAddRef
|
||||||
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
||||||
int taosRemoveRef(int rsetId, int64_t rid);
|
int32_t taosRemoveRef(int32_t rsetId, int64_t rid);
|
||||||
|
|
||||||
// acquire ref, rid is the reference ID returned by taosAddRef
|
// acquire ref, rid is the reference ID returned by taosAddRef
|
||||||
// return the resource p. On error, NULL is returned, and terrno is set appropriately
|
// return the resource p. On error, NULL is returned, and terrno is set appropriately
|
||||||
void *taosAcquireRef(int rsetId, int64_t rid);
|
void *taosAcquireRef(int32_t rsetId, int64_t rid);
|
||||||
|
|
||||||
// release ref, rid is the reference ID returned by taosAddRef
|
// release ref, rid is the reference ID returned by taosAddRef
|
||||||
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
// return 0 if success. On error, -1 is returned, and terrno is set appropriately
|
||||||
int taosReleaseRef(int rsetId, int64_t rid);
|
int32_t taosReleaseRef(int32_t rsetId, int64_t rid);
|
||||||
|
|
||||||
// return the first reference if rid is 0, otherwise return the next after current reference.
|
// return the first reference if rid is 0, otherwise return the next after current reference.
|
||||||
// if return value is NULL, it means list is over(if terrno is set, it means error happens)
|
// if return value is NULL, it means list is over(if terrno is set, it means error happens)
|
||||||
void *taosIterateRef(int rsetId, int64_t rid);
|
void *taosIterateRef(int32_t rsetId, int64_t rid);
|
||||||
|
|
||||||
// return the number of references in system
|
// return the number of references in system
|
||||||
int taosListRef();
|
int32_t taosListRef();
|
||||||
|
|
||||||
#define RID_VALID(x) ((x) > 0)
|
#define RID_VALID(x) ((x) > 0)
|
||||||
|
|
||||||
/* sample code to iterate the refs
|
/* sample code to iterate the refs
|
||||||
|
|
||||||
void demoIterateRefs(int rsetId) {
|
void demoIterateRefs(int32_t rsetId) {
|
||||||
|
|
||||||
void *p = taosIterateRef(refId, 0);
|
void *p = taosIterateRef(refId, 0);
|
||||||
while (p) {
|
while (p) {
|
||||||
|
@ -76,4 +76,4 @@ void demoIterateRefs(int rsetId) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_REF_H*/
|
#endif /*_TD_UTIL_REF_H_*/
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_SCHED_H
|
#ifndef _TD_UTIL_SCHED_H_
|
||||||
#define _TD_UTIL_SCHED_H
|
#define _TD_UTIL_SCHED_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -36,7 +38,7 @@ typedef struct SSchedMsg {
|
||||||
* @param label the label of the queue
|
* @param label the label of the queue
|
||||||
* @return the created queue scheduler
|
* @return the created queue scheduler
|
||||||
*/
|
*/
|
||||||
void *taosInitScheduler(int capacity, int numOfThreads, const char *label);
|
void *taosInitScheduler(int32_t capacity, int32_t numOfThreads, const char *label);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a thread-safe ring-buffer based task queue and return the instance.
|
* Create a thread-safe ring-buffer based task queue and return the instance.
|
||||||
|
@ -47,7 +49,7 @@ void *taosInitScheduler(int capacity, int numOfThreads, const char *label);
|
||||||
* @param tmrCtrl the timer controller, tmr_ctrl_t*
|
* @param tmrCtrl the timer controller, tmr_ctrl_t*
|
||||||
* @return the created queue scheduler
|
* @return the created queue scheduler
|
||||||
*/
|
*/
|
||||||
void *taosInitSchedulerWithInfo(int capacity, int numOfThreads, const char *label, void *tmrCtrl);
|
void *taosInitSchedulerWithInfo(int32_t capacity, int32_t numOfThreads, const char *label, void *tmrCtrl);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up the queue scheduler instance and free the memory.
|
* Clean up the queue scheduler instance and free the memory.
|
||||||
|
@ -68,4 +70,4 @@ void taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_SCHED_H*/
|
#endif /*_TD_UTIL_SCHED_H_*/
|
||||||
|
|
|
@ -16,22 +16,22 @@
|
||||||
#ifndef _TD_UTIL_SKILIST_H
|
#ifndef _TD_UTIL_SKILIST_H
|
||||||
#define _TD_UTIL_SKILIST_H
|
#define _TD_UTIL_SKILIST_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "tfunctional.h"
|
#include "tfunctional.h"
|
||||||
|
|
||||||
#define MAX_SKIP_LIST_LEVEL 15
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAX_SKIP_LIST_LEVEL 15
|
||||||
#define SKIP_LIST_RECORD_PERFORMANCE 0
|
#define SKIP_LIST_RECORD_PERFORMANCE 0
|
||||||
|
|
||||||
// For key property setting
|
// For key property setting
|
||||||
#define SL_ALLOW_DUP_KEY (uint8_t)0x0 // Allow duplicate key exists (for tag index usage)
|
#define SL_ALLOW_DUP_KEY (uint8_t)0x0 // Allow duplicate key exists (for tag index usage)
|
||||||
#define SL_DISCARD_DUP_KEY (uint8_t)0x1 // Discard duplicate key (for data update=0 case)
|
#define SL_DISCARD_DUP_KEY (uint8_t)0x1 // Discard duplicate key (for data update=0 case)
|
||||||
#define SL_UPDATE_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert (for data update!=0 case)
|
#define SL_UPDATE_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert (for data update!=0 case)
|
||||||
|
|
||||||
// For thread safety setting
|
// For thread safety setting
|
||||||
#define SL_THREAD_SAFE (uint8_t)0x4
|
#define SL_THREAD_SAFE (uint8_t)0x4
|
||||||
|
@ -39,17 +39,17 @@ extern "C" {
|
||||||
typedef char *SSkipListKey;
|
typedef char *SSkipListKey;
|
||||||
typedef char *(*__sl_key_fn_t)(const void *);
|
typedef char *(*__sl_key_fn_t)(const void *);
|
||||||
|
|
||||||
typedef void (*sl_patch_row_fn_t)(void * pDst, const void * pSrc);
|
typedef void (*sl_patch_row_fn_t)(void *pDst, const void *pSrc);
|
||||||
typedef void* (*iter_next_fn_t)(void *iter);
|
typedef void *(*iter_next_fn_t)(void *iter);
|
||||||
|
|
||||||
typedef struct SSkipListNode {
|
typedef struct SSkipListNode {
|
||||||
uint8_t level;
|
uint8_t level;
|
||||||
void * pData;
|
void *pData;
|
||||||
struct SSkipListNode *forwards[];
|
struct SSkipListNode *forwards[];
|
||||||
} SSkipListNode;
|
} SSkipListNode;
|
||||||
|
|
||||||
#define SL_GET_NODE_DATA(n) (n)->pData
|
#define SL_GET_NODE_DATA(n) (n)->pData
|
||||||
#define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)]
|
#define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)]
|
||||||
#define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)]
|
#define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -100,14 +100,10 @@ typedef struct tSkipListState {
|
||||||
uint64_t nTotalElapsedTimeForInsert;
|
uint64_t nTotalElapsedTimeForInsert;
|
||||||
} tSkipListState;
|
} tSkipListState;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { SSkipListPutSuccess = 0, SSkipListPutEarlyStop = 1, SSkipListPutSkipOne = 2 } SSkipListPutStatus;
|
||||||
SSkipListPutSuccess = 0,
|
|
||||||
SSkipListPutEarlyStop = 1,
|
|
||||||
SSkipListPutSkipOne = 2
|
|
||||||
} SSkipListPutStatus;
|
|
||||||
|
|
||||||
typedef struct SSkipList {
|
typedef struct SSkipList {
|
||||||
unsigned int seed;
|
uint32_t seed;
|
||||||
__compar_fn_t comparFn;
|
__compar_fn_t comparFn;
|
||||||
__sl_key_fn_t keyFn;
|
__sl_key_fn_t keyFn;
|
||||||
pthread_rwlock_t *lock;
|
pthread_rwlock_t *lock;
|
||||||
|
@ -117,41 +113,41 @@ typedef struct SSkipList {
|
||||||
uint8_t type; // static info above
|
uint8_t type; // static info above
|
||||||
uint8_t level;
|
uint8_t level;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
SSkipListNode * pHead; // point to the first element
|
SSkipListNode *pHead; // point to the first element
|
||||||
SSkipListNode * pTail; // point to the last element
|
SSkipListNode *pTail; // point to the last element
|
||||||
#if SKIP_LIST_RECORD_PERFORMANCE
|
#if SKIP_LIST_RECORD_PERFORMANCE
|
||||||
tSkipListState state; // skiplist state
|
tSkipListState state; // skiplist state
|
||||||
#endif
|
#endif
|
||||||
tGenericSavedFunc* insertHandleFn;
|
tGenericSavedFunc *insertHandleFn;
|
||||||
} SSkipList;
|
} SSkipList;
|
||||||
|
|
||||||
typedef struct SSkipListIterator {
|
typedef struct SSkipListIterator {
|
||||||
SSkipList * pSkipList;
|
SSkipList *pSkipList;
|
||||||
SSkipListNode *cur;
|
SSkipListNode *cur;
|
||||||
int32_t step; // the number of nodes that have been checked already
|
int32_t step; // the number of nodes that have been checked already
|
||||||
int32_t order; // order of the iterator
|
int32_t order; // order of the iterator
|
||||||
SSkipListNode *next; // next points to the true qualified node in skiplist
|
SSkipListNode *next; // next points to the true qualified node in skiplist
|
||||||
} SSkipListIterator;
|
} SSkipListIterator;
|
||||||
|
|
||||||
#define SL_IS_THREAD_SAFE(s) (((s)->flags) & SL_THREAD_SAFE)
|
#define SL_IS_THREAD_SAFE(s) (((s)->flags) & SL_THREAD_SAFE)
|
||||||
#define SL_DUP_MODE(s) (((s)->flags) & ((((uint8_t)1) << 2) - 1))
|
#define SL_DUP_MODE(s) (((s)->flags) & ((((uint8_t)1) << 2) - 1))
|
||||||
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn((n)->pData))
|
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn((n)->pData))
|
||||||
#define SL_GET_MIN_KEY(s) SL_GET_NODE_KEY(s, SL_NODE_GET_FORWARD_POINTER((s)->pHead, 0))
|
#define SL_GET_MIN_KEY(s) SL_GET_NODE_KEY(s, SL_NODE_GET_FORWARD_POINTER((s)->pHead, 0))
|
||||||
#define SL_GET_MAX_KEY(s) SL_GET_NODE_KEY((s), SL_NODE_GET_BACKWARD_POINTER((s)->pTail, 0))
|
#define SL_GET_MAX_KEY(s) SL_GET_NODE_KEY((s), SL_NODE_GET_BACKWARD_POINTER((s)->pTail, 0))
|
||||||
#define SL_SIZE(s) (s)->size
|
#define SL_SIZE(s) (s)->size
|
||||||
|
|
||||||
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
|
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
|
||||||
__sl_key_fn_t fn);
|
__sl_key_fn_t fn);
|
||||||
void tSkipListDestroy(SSkipList *pSkipList);
|
void tSkipListDestroy(SSkipList *pSkipList);
|
||||||
SSkipListNode * tSkipListPut(SSkipList *pSkipList, void *pData);
|
SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData);
|
||||||
void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t iterate);
|
void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t iterate);
|
||||||
SArray * tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey);
|
SArray *tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey);
|
||||||
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel);
|
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel);
|
||||||
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList);
|
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList);
|
||||||
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order);
|
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order);
|
||||||
bool tSkipListIterNext(SSkipListIterator *iter);
|
bool tSkipListIterNext(SSkipListIterator *iter);
|
||||||
SSkipListNode * tSkipListIterGet(SSkipListIterator *iter);
|
SSkipListNode *tSkipListIterGet(SSkipListIterator *iter);
|
||||||
void * tSkipListDestroyIter(SSkipListIterator *iter);
|
void *tSkipListDestroyIter(SSkipListIterator *iter);
|
||||||
uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key);
|
uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key);
|
||||||
void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode);
|
void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode);
|
||||||
|
|
||||||
|
@ -159,4 +155,4 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNod
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_SKILIST_H*/
|
#endif /*_TD_UTIL_SKILIST_H*/
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
/*
|
|
||||||
* 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_STEP_H_
|
|
||||||
#define _TD_UTIL_STEP_H_
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct SSteps SSteps;
|
|
||||||
typedef int32_t (*InitFp)();
|
|
||||||
typedef void (*CleanupFp)();
|
|
||||||
typedef void (*ReportFp)(char *name, char *desc);
|
|
||||||
|
|
||||||
SSteps *taosStepInit(int32_t maxsize, ReportFp fp);
|
|
||||||
int32_t taosStepExec(SSteps *steps);
|
|
||||||
void taosStepCleanup(SSteps *steps);
|
|
||||||
int32_t taosStepAdd(SSteps *steps, char *name, InitFp initFp, CleanupFp cleanupFp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_UTIL_STEP_H_*/
|
|
|
@ -13,12 +13,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_STRING_BUILDER_H
|
#ifndef _TD_UTIL_STRING_BUILDER_H_
|
||||||
#define _TD_UTIL_STRING_BUILDER_H
|
#define _TD_UTIL_STRING_BUILDER_H_
|
||||||
|
|
||||||
#include <stddef.h>
|
#include "os.h"
|
||||||
#include <stdint.h>
|
|
||||||
#include <setjmp.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -26,16 +24,16 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct SStringBuilder {
|
typedef struct SStringBuilder {
|
||||||
jmp_buf jb;
|
jmp_buf jb;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
char* buf;
|
char* buf;
|
||||||
} SStringBuilder;
|
} SStringBuilder;
|
||||||
|
|
||||||
#define taosStringBuilderSetJmp(sb) setjmp((sb)->jb)
|
#define taosStringBuilderSetJmp(sb) setjmp((sb)->jb)
|
||||||
|
|
||||||
void taosStringBuilderEnsureCapacity(SStringBuilder* sb, size_t size);
|
void taosStringBuilderEnsureCapacity(SStringBuilder* sb, size_t size);
|
||||||
char* taosStringBuilderGetResult(SStringBuilder* sb, size_t* len);
|
char* taosStringBuilderGetResult(SStringBuilder* sb, size_t* len);
|
||||||
void taosStringBuilderDestroy(SStringBuilder* sb);
|
void taosStringBuilderDestroy(SStringBuilder* sb);
|
||||||
|
|
||||||
void taosStringBuilderAppend(SStringBuilder* sb, const void* data, size_t len);
|
void taosStringBuilderAppend(SStringBuilder* sb, const void* data, size_t len);
|
||||||
void taosStringBuilderAppendChar(SStringBuilder* sb, char c);
|
void taosStringBuilderAppendChar(SStringBuilder* sb, char c);
|
||||||
|
@ -49,4 +47,4 @@ void taosStringBuilderAppendDouble(SStringBuilder* sb, double v);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_STRING_BUILDER_H*/
|
#endif /*_TD_UTIL_STRING_BUILDER_H_*/
|
|
@ -13,25 +13,21 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_THREAD_H
|
#ifndef _TD_UTIL_THREAD_H_
|
||||||
#define _TD_UTIL_THREAD_H
|
#define _TD_UTIL_THREAD_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tdef.h"
|
|
||||||
|
|
||||||
// create new thread
|
|
||||||
pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param);
|
pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param);
|
||||||
// destory thread
|
bool taosDestoryThread(pthread_t* pthread);
|
||||||
bool taosDestoryThread(pthread_t* pthread);
|
bool taosThreadRunning(pthread_t* pthread);
|
||||||
// thread running return true
|
|
||||||
bool taosThreadRunning(pthread_t* pthread);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_THREAD_H*/
|
#endif /*_TD_UTIL_THREAD_H_*/
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_TIMER_H
|
#ifndef _TD_UTIL_TIMER_H_
|
||||||
#define _TD_UTIL_TIMER_H
|
#define _TD_UTIL_TIMER_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -25,23 +25,23 @@ extern "C" {
|
||||||
typedef void *tmr_h;
|
typedef void *tmr_h;
|
||||||
typedef void (*TAOS_TMR_CALLBACK)(void *, void *);
|
typedef void (*TAOS_TMR_CALLBACK)(void *, void *);
|
||||||
|
|
||||||
extern int taosTmrThreads;
|
extern int32_t taosTmrThreads;
|
||||||
|
|
||||||
#define MSECONDS_PER_TICK 5
|
#define MSECONDS_PER_TICK 5
|
||||||
|
|
||||||
void *taosTmrInit(int maxTmr, int resoultion, int longest, const char *label);
|
void *taosTmrInit(int32_t maxTmr, int32_t resoultion, int32_t longest, const char *label);
|
||||||
|
|
||||||
tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void *param, void *handle);
|
tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int32_t mseconds, void *param, void *handle);
|
||||||
|
|
||||||
bool taosTmrStop(tmr_h tmrId);
|
bool taosTmrStop(tmr_h tmrId);
|
||||||
|
|
||||||
bool taosTmrStopA(tmr_h *timerId);
|
bool taosTmrStopA(tmr_h *timerId);
|
||||||
|
|
||||||
bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void *param, void *handle, tmr_h *pTmrId);
|
bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void *param, void *handle, tmr_h *pTmrId);
|
||||||
|
|
||||||
void taosTmrCleanUp(void *handle);
|
void taosTmrCleanUp(void *handle);
|
||||||
|
|
||||||
int32_t taosInitTimer(void (*callback)(int), int32_t ms);
|
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
|
||||||
|
|
||||||
void taosUninitTimer();
|
void taosUninitTimer();
|
||||||
|
|
||||||
|
@ -49,4 +49,4 @@ void taosUninitTimer();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_TIMER_H*/
|
#endif /*_TD_UTIL_TIMER_H_*/
|
||||||
|
|
|
@ -13,18 +13,18 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_UTIL_H
|
#ifndef _TD_UTIL_UTIL_H_
|
||||||
#define _TD_UTIL_UTIL_H
|
#define _TD_UTIL_UTIL_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tcrc32c.h"
|
#include "tcrc32c.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
#include "tmd5.h"
|
#include "tmd5.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
int32_t strdequote(char *src);
|
int32_t strdequote(char *src);
|
||||||
int32_t strndequote(char *dst, const char *z, int32_t len);
|
int32_t strndequote(char *dst, const char *z, int32_t len);
|
||||||
int32_t strRmquote(char *z, int32_t len);
|
int32_t strRmquote(char *z, int32_t len);
|
||||||
|
@ -49,7 +49,7 @@ void taosIpPort2String(uint32_t ip, uint16_t port, char *str);
|
||||||
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
|
static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) {
|
||||||
T_MD5_CTX context;
|
T_MD5_CTX context;
|
||||||
tMD5Init(&context);
|
tMD5Init(&context);
|
||||||
tMD5Update(&context, inBuf, (unsigned int)inLen);
|
tMD5Update(&context, inBuf, (uint32_t)inLen);
|
||||||
tMD5Final(&context);
|
tMD5Final(&context);
|
||||||
memcpy(target, context.digest, tListLen(context.digest));
|
memcpy(target, context.digest, tListLen(context.digest));
|
||||||
}
|
}
|
||||||
|
@ -57,17 +57,17 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
|
||||||
static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) {
|
static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *target) {
|
||||||
T_MD5_CTX context;
|
T_MD5_CTX context;
|
||||||
tMD5Init(&context);
|
tMD5Init(&context);
|
||||||
tMD5Update(&context, inBuf, (unsigned int)len);
|
tMD5Update(&context, inBuf, (uint32_t)len);
|
||||||
tMD5Final(&context);
|
tMD5Final(&context);
|
||||||
|
|
||||||
sprintf(target, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], context.digest[1], context.digest[2],
|
sprintf(target, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0],
|
||||||
context.digest[3], context.digest[4], context.digest[5], context.digest[6], context.digest[7],
|
context.digest[1], context.digest[2], context.digest[3], context.digest[4], context.digest[5],
|
||||||
context.digest[8], context.digest[9], context.digest[10], context.digest[11], context.digest[12],
|
context.digest[6], context.digest[7], context.digest[8], context.digest[9], context.digest[10],
|
||||||
context.digest[13], context.digest[14], context.digest[15]);
|
context.digest[11], context.digest[12], context.digest[13], context.digest[14], context.digest[15]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_UTIL_H*/
|
#endif /*_TD_UTIL_UTIL_H_*/
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_VERSION_H
|
#ifndef _TD_UTIL_VERSION_H_
|
||||||
#define _TD_UTIL_VERSION_H
|
#define _TD_UTIL_VERSION_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -28,4 +30,4 @@ int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_VERSION_H*/
|
#endif /*_TD_UTIL_VERSION_H_*/
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_WORKER_H
|
#ifndef _TD_UTIL_WORKER_H_
|
||||||
#define _TD_UTIL_WORKER_H
|
#define _TD_UTIL_WORKER_H_
|
||||||
|
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -34,25 +35,25 @@ typedef struct SQWorkerPool {
|
||||||
int32_t max; // max number of workers
|
int32_t max; // max number of workers
|
||||||
int32_t min; // min number of workers
|
int32_t min; // min number of workers
|
||||||
int32_t num; // current number of workers
|
int32_t num; // current number of workers
|
||||||
STaosQset * qset;
|
STaosQset *qset;
|
||||||
const char * name;
|
const char *name;
|
||||||
SQWorker * workers;
|
SQWorker *workers;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
} SQWorkerPool, SFWorkerPool;
|
} SQWorkerPool, SFWorkerPool;
|
||||||
|
|
||||||
typedef struct SWWorker {
|
typedef struct SWWorker {
|
||||||
int32_t id; // worker id
|
int32_t id; // worker id
|
||||||
pthread_t thread; // thread
|
pthread_t thread; // thread
|
||||||
STaosQall * qall;
|
STaosQall *qall;
|
||||||
STaosQset * qset; // queue set
|
STaosQset *qset; // queue set
|
||||||
SWWorkerPool *pool;
|
SWWorkerPool *pool;
|
||||||
} SWWorker;
|
} SWWorker;
|
||||||
|
|
||||||
typedef struct SWWorkerPool {
|
typedef struct SWWorkerPool {
|
||||||
int32_t max; // max number of workers
|
int32_t max; // max number of workers
|
||||||
int32_t nextId; // from 0 to max-1, cyclic
|
int32_t nextId; // from 0 to max-1, cyclic
|
||||||
const char * name;
|
const char *name;
|
||||||
SWWorker * workers;
|
SWWorker *workers;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
} SWWorkerPool;
|
} SWWorkerPool;
|
||||||
|
|
||||||
|
@ -75,4 +76,4 @@ void tWWorkerFreeQueue(SWWorkerPool *pool, STaosQueue *queue);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_WORKER_H*/
|
#endif /*_TD_UTIL_WORKER_H_*/
|
||||||
|
|
|
@ -22,14 +22,14 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GET_INT8_VAL(x) (*(int8_t *)(x))
|
#define GET_INT8_VAL(x) (*(int8_t *)(x))
|
||||||
#define GET_INT16_VAL(x) (*(int16_t *)(x))
|
#define GET_INT16_VAL(x) (*(int16_t *)(x))
|
||||||
#define GET_INT32_VAL(x) (*(int32_t *)(x))
|
#define GET_INT32_VAL(x) (*(int32_t *)(x))
|
||||||
#define GET_INT64_VAL(x) (*(int64_t *)(x))
|
#define GET_INT64_VAL(x) (*(int64_t *)(x))
|
||||||
#define GET_UINT8_VAL(x) (*(uint8_t*) (x))
|
#define GET_UINT8_VAL(x) (*(uint8_t *)(x))
|
||||||
#define GET_UINT16_VAL(x) (*(uint16_t *)(x))
|
#define GET_UINT16_VAL(x) (*(uint16_t *)(x))
|
||||||
#define GET_UINT32_VAL(x) (*(uint32_t *)(x))
|
#define GET_UINT32_VAL(x) (*(uint32_t *)(x))
|
||||||
#define GET_UINT64_VAL(x) (*(uint64_t *)(x))
|
#define GET_UINT64_VAL(x) (*(uint64_t *)(x))
|
||||||
|
|
||||||
static FORCE_INLINE float taos_align_get_float(const char *pBuf) {
|
static FORCE_INLINE float taos_align_get_float(const char *pBuf) {
|
||||||
#if __STDC_VERSION__ >= 201112L
|
#if __STDC_VERSION__ >= 201112L
|
||||||
|
@ -64,23 +64,33 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) {
|
||||||
// #define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); }
|
// #define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); }
|
||||||
// #define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); }
|
// #define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); }
|
||||||
// #else
|
// #else
|
||||||
#define GET_FLOAT_VAL(x) (*(float *)(x))
|
#define GET_FLOAT_VAL(x) (*(float *)(x))
|
||||||
#define GET_DOUBLE_VAL(x) (*(double *)(x))
|
#define GET_DOUBLE_VAL(x) (*(double *)(x))
|
||||||
#define SET_BIGINT_VAL(x, y) { (*(int64_t *)(x)) = (int64_t)(y); }
|
#define SET_BIGINT_VAL(x, y) \
|
||||||
#define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); }
|
{ (*(int64_t *)(x)) = (int64_t)(y); }
|
||||||
#define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); }
|
#define SET_FLOAT_VAL(x, y) \
|
||||||
#define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); }
|
{ (*(float *)(x)) = (float)(y); }
|
||||||
#define SET_DOUBLE_PTR(x, y) { (*(double *)(x)) = (*(double *)(y)); }
|
#define SET_DOUBLE_VAL(x, y) \
|
||||||
|
{ (*(double *)(x)) = (double)(y); }
|
||||||
|
#define SET_FLOAT_PTR(x, y) \
|
||||||
|
{ (*(float *)(x)) = (*(float *)(y)); }
|
||||||
|
#define SET_DOUBLE_PTR(x, y) \
|
||||||
|
{ (*(double *)(x)) = (*(double *)(y)); }
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
typedef uint16_t VarDataLenT; // maxVarDataLen: 32767
|
typedef uint16_t VarDataLenT; // maxVarDataLen: 32767
|
||||||
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
|
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
|
||||||
|
|
||||||
#define varDataLen(v) ((VarDataLenT *)(v))[0]
|
#define varDataLen(v) ((VarDataLenT *)(v))[0]
|
||||||
#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE))
|
#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE))
|
||||||
|
|
||||||
typedef int32_t VarDataOffsetT;
|
typedef int32_t VarDataOffsetT;
|
||||||
|
|
||||||
|
typedef struct tstr {
|
||||||
|
VarDataLenT len;
|
||||||
|
char data[];
|
||||||
|
} tstr;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_VERSION_H
|
#ifndef _TD_UTIL_VERSION_H_
|
||||||
#define _TD_UTIL_VERSION_H
|
#define _TD_UTIL_VERSION_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -30,4 +30,4 @@ extern char buildinfo[];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_VERSION_H*/
|
#endif /*_TD_UTIL_VERSION_H_*/
|
||||||
|
|
|
@ -1,111 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 "tcompare.h"
|
|
||||||
|
|
||||||
|
|
||||||
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) {
|
|
||||||
__compar_fn_t comparFn = NULL;
|
|
||||||
|
|
||||||
switch (keyType) {
|
|
||||||
case TSDB_DATA_TYPE_TINYINT:
|
|
||||||
case TSDB_DATA_TYPE_BOOL:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareInt8Val:compareInt8ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_SMALLINT:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareInt16Val:compareInt16ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_INT:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareInt32Val:compareInt32ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_BIGINT:
|
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareInt64Val:compareInt64ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_FLOAT:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareFloatVal:compareFloatValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_DOUBLE:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareDoubleVal:compareDoubleValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_UTINYINT:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareUint8Val:compareUint8ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_USMALLINT:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareUint16Val:compareUint16ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_UINT:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareUint32Val:compareUint32ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_UBIGINT:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareUint64Val:compareUint64ValDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareLenPrefixedStr:compareLenPrefixedStrDesc;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareLenPrefixedWStr:compareLenPrefixedWStrDesc;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
comparFn = (order == TSDB_ORDER_ASC)? compareInt32Val:compareInt32ValDesc;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return comparFn;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
|
|
||||||
switch (type) {
|
|
||||||
case TSDB_DATA_TYPE_INT: DEFAULT_COMP(GET_INT32_VAL(f1), GET_INT32_VAL(f2));
|
|
||||||
case TSDB_DATA_TYPE_DOUBLE: DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(f1), GET_DOUBLE_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_BOOL: DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2));
|
|
||||||
case TSDB_DATA_TYPE_UTINYINT: DEFAULT_COMP(GET_UINT8_VAL(f1), GET_UINT8_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: {
|
|
||||||
tstr* t1 = (tstr*) f1;
|
|
||||||
tstr* t2 = (tstr*) f2;
|
|
||||||
|
|
||||||
if (t1->len != t2->len) {
|
|
||||||
return t1->len > t2->len? 1:-1;
|
|
||||||
}
|
|
||||||
int32_t ret = memcmp((wchar_t*) t1, (wchar_t*) t2, t2->len);
|
|
||||||
if (ret == 0) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return (ret < 0) ? -1 : 1;
|
|
||||||
}
|
|
||||||
default: { // todo refactor
|
|
||||||
tstr* t1 = (tstr*) f1;
|
|
||||||
tstr* t2 = (tstr*) f2;
|
|
||||||
|
|
||||||
if (t1->len != t2->len) {
|
|
||||||
return t1->len > t2->len? 1:-1;
|
|
||||||
} else {
|
|
||||||
int32_t ret = strncmp(t1->data, t2->data, t1->len);
|
|
||||||
if (ret == 0) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return ret < 0? -1:1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "tep.h"
|
#include "tep.h"
|
||||||
#include <compare.h>
|
#include "tcompare.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tlockfree.h"
|
#include "tlockfree.h"
|
||||||
|
|
|
@ -207,6 +207,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosAddClientLogCfg(SConfig *pCfg) {
|
static int32_t taosAddClientLogCfg(SConfig *pCfg) {
|
||||||
|
if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1;
|
||||||
|
if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1;
|
||||||
if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1;
|
if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1;
|
||||||
if (cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, 1) != 0) return -1;
|
if (cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "numOfLogLines", tsNumOfLogLines, 1000, 2000000000, 1) != 0) return -1;
|
||||||
|
@ -218,8 +220,6 @@ static int32_t taosAddClientLogCfg(SConfig *pCfg) {
|
||||||
if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "simDebugFlag", 143, 0, 255, 1) != 0) return -1;
|
||||||
if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1;
|
|
||||||
if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1;
|
|
||||||
if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, 1) != 0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -325,6 +325,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
||||||
static void taosSetClientLogCfg(SConfig *pCfg) {
|
static void taosSetClientLogCfg(SConfig *pCfg) {
|
||||||
SConfigItem *pItem = cfgGetItem(pCfg, "logDir");
|
SConfigItem *pItem = cfgGetItem(pCfg, "logDir");
|
||||||
tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
|
tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
|
||||||
|
taosExpandDir(tsLogDir, tsLogDir, PATH_MAX);
|
||||||
tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval;
|
tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval;
|
||||||
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
|
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
|
||||||
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
|
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
|
||||||
|
@ -349,12 +350,24 @@ static void taosSetServerLogCfg(SConfig *pCfg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosSetClientCfg(SConfig *pCfg) {
|
static void taosSetClientCfg(SConfig *pCfg) {
|
||||||
tstrncpy(tsFirst, cfgGetItem(pCfg, "firstEp")->str, TSDB_EP_LEN);
|
|
||||||
tstrncpy(tsSecond, cfgGetItem(pCfg, "secondEp")->str, TSDB_EP_LEN);
|
|
||||||
tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_EP_LEN);
|
tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_EP_LEN);
|
||||||
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
||||||
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
|
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
|
||||||
|
|
||||||
|
SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp");
|
||||||
|
SEp firstEp = {0};
|
||||||
|
taosGetFqdnPortFromEp(pFirstEpItem->str, &firstEp);
|
||||||
|
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port);
|
||||||
|
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype);
|
||||||
|
|
||||||
|
SConfigItem *pSecondpItem = cfgGetItem(pCfg, "secondEp");
|
||||||
|
SEp secondEp = {0};
|
||||||
|
taosGetFqdnPortFromEp(pSecondpItem->str, &secondEp);
|
||||||
|
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
|
||||||
|
cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype);
|
||||||
|
|
||||||
tstrncpy(tsLogDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
tstrncpy(tsLogDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
||||||
|
taosExpandDir(tsLogDir, tsLogDir, PATH_MAX);
|
||||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
|
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
|
||||||
|
|
||||||
tsNumOfThreadsPerCore = cfgGetItem(pCfg, "maxTmrCtrl")->fval;
|
tsNumOfThreadsPerCore = cfgGetItem(pCfg, "maxTmrCtrl")->fval;
|
||||||
|
@ -395,6 +408,8 @@ static void taosSetSystemCfg(SConfig *pCfg) {
|
||||||
|
|
||||||
static void taosSetServerCfg(SConfig *pCfg) {
|
static void taosSetServerCfg(SConfig *pCfg) {
|
||||||
tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
|
tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
|
||||||
|
taosExpandDir(tsDataDir, tsDataDir, PATH_MAX);
|
||||||
|
|
||||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
|
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
|
||||||
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
|
tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32;
|
||||||
tsRatioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval;
|
tsRatioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval;
|
||||||
|
@ -473,10 +488,10 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
||||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||||
} else {
|
} else {
|
||||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
|
||||||
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
|
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||||
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
||||||
|
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||||
|
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
|
||||||
}
|
}
|
||||||
taosAddSystemCfg(tsCfg);
|
taosAddSystemCfg(tsCfg);
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ SDnodeObjCfg dmnGetObjCfg() {
|
||||||
SDnodeObjCfg objCfg = {0};
|
SDnodeObjCfg objCfg = {0};
|
||||||
|
|
||||||
objCfg.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
|
objCfg.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
|
||||||
tstrncpy(objCfg.dataDir, cfgGetItem(pCfg, "dataDir")->str, sizeof(objCfg.dataDir));
|
tstrncpy(objCfg.dataDir, tsDataDir, sizeof(objCfg.dataDir));
|
||||||
tstrncpy(objCfg.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp));
|
tstrncpy(objCfg.firstEp, tsFirst, sizeof(objCfg.firstEp));
|
||||||
tstrncpy(objCfg.secondEp, cfgGetItem(pCfg, "secondEp")->str, sizeof(objCfg.firstEp));
|
tstrncpy(objCfg.secondEp, tsSecond, sizeof(objCfg.firstEp));
|
||||||
objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
objCfg.serverPort = tsServerPort;
|
||||||
tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn));
|
tstrncpy(objCfg.localFqdn, tsLocalFqdn, sizeof(objCfg.localFqdn));
|
||||||
snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort);
|
snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort);
|
||||||
objCfg.pDisks = tsDiskCfg;
|
objCfg.pDisks = tsDiskCfg;
|
||||||
objCfg.numOfDisks = tsDiskCfgNum;
|
objCfg.numOfDisks = tsDiskCfgNum;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "tkey.h"
|
#include "tbase64.h"
|
||||||
|
|
||||||
#define TSDB_USER_VER_NUMBER 1
|
#define TSDB_USER_VER_NUMBER 1
|
||||||
#define TSDB_USER_RESERVE_SIZE 64
|
#define TSDB_USER_RESERVE_SIZE 64
|
||||||
|
|
|
@ -119,8 +119,8 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
||||||
EXPECT_EQ(test.GetShowRows(), 2);
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
CheckInt32(2);
|
CheckInt32(2);
|
||||||
CheckInt32(3);
|
CheckInt32(3);
|
||||||
CheckInt32(0);
|
IgnoreInt32();
|
||||||
CheckInt32(0);
|
IgnoreInt32();
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckBinary("master", 9);
|
CheckBinary("master", 9);
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
#ifndef _TD_META_H_
|
#ifndef _TD_META_H_
|
||||||
#define _TD_META_H_
|
#define _TD_META_H_
|
||||||
|
|
||||||
#include "mallocator.h"
|
#include "tmallocator.h"
|
||||||
#include "os.h"
|
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "trow.h"
|
#include "trow.h"
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,8 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "executor.h"
|
#include "executor.h"
|
||||||
#include "mallocator.h"
|
#include "tmallocator.h"
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "os.h"
|
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_TSDB_H_
|
#ifndef _TD_TSDB_H_
|
||||||
#define _TD_TSDB_H_
|
#define _TD_TSDB_H_
|
||||||
|
|
||||||
#include "mallocator.h"
|
#include "tmallocator.h"
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "tfs.h"
|
#include "tfs.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_META_DEF_H_
|
#ifndef _TD_META_DEF_H_
|
||||||
#define _TD_META_DEF_H_
|
#define _TD_META_DEF_H_
|
||||||
|
|
||||||
#include "mallocator.h"
|
#include "tmallocator.h"
|
||||||
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_TSDB_DEF_H_
|
#ifndef _TD_TSDB_DEF_H_
|
||||||
#define _TD_TSDB_DEF_H_
|
#define _TD_TSDB_DEF_H_
|
||||||
|
|
||||||
#include "mallocator.h"
|
#include "tmallocator.h"
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "tcompression.h"
|
#include "tcompression.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_VNODE_DEF_H_
|
#ifndef _TD_VNODE_DEF_H_
|
||||||
#define _TD_VNODE_DEF_H_
|
#define _TD_VNODE_DEF_H_
|
||||||
|
|
||||||
#include "mallocator.h"
|
#include "tmallocator.h"
|
||||||
// #include "sync.h"
|
// #include "sync.h"
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
#include "tfs.h"
|
#include "tfs.h"
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "tsdbLog.h"
|
#include "tsdbLog.h"
|
||||||
#include "tsdbReadImpl.h"
|
#include "tsdbReadImpl.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "exception.h"
|
#include "texception.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "talgo.h"
|
#include "talgo.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#include <tsdb.h>
|
#include <tsdb.h>
|
||||||
#include "dataSinkMgt.h"
|
#include "dataSinkMgt.h"
|
||||||
#include "exception.h"
|
#include "texception.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
|
|
|
@ -12,11 +12,12 @@
|
||||||
* 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 "os.h"
|
||||||
|
|
||||||
#include "tep.h"
|
#include "tep.h"
|
||||||
#include "tsort.h"
|
#include "tsort.h"
|
||||||
#include "exception.h"
|
#include "texception.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tlinearhash.h"
|
#include "tlinearhash.h"
|
||||||
#include "tcfg.h"
|
#include "tdef.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tpagedbuf.h"
|
#include "tpagedbuf.h"
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "tsort.h"
|
#include "tsort.h"
|
||||||
#include "tep.h"
|
#include "tep.h"
|
||||||
#include "tcfg.h"
|
#include "tdef.h"
|
||||||
#include "tlosertree.h"
|
#include "tlosertree.h"
|
||||||
#include "tpagedbuf.h"
|
#include "tpagedbuf.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "function.h"
|
#include "function.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "exception.h"
|
#include "texception.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
* 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 <tglobal.h>
|
|
||||||
#include "os.h"
|
#include "tglobal.h"
|
||||||
|
#include "tcompare.h"
|
||||||
|
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
|
|
|
@ -16,12 +16,15 @@
|
||||||
#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"
|
||||||
|
#include "tutil.h"
|
||||||
|
|
||||||
#ifdef USE_LUCENE
|
#ifdef USE_LUCENE
|
||||||
#include <lucene++/Lucene_c.h>
|
#include <lucene++/Lucene_c.h>
|
||||||
|
|
|
@ -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 @@
|
||||||
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 @@
|
||||||
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 @@
|
||||||
#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 @@
|
||||||
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 @@
|
||||||
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 @@
|
||||||
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 @@
|
||||||
#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 @@
|
||||||
#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 @@
|
||||||
* 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 @@
|
||||||
* 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 {
|
||||||
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 {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
||||||
// 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() {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
#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) {
|
||||||
// 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) {
|
||||||
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};
|
||||||
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 {
|
||||||
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 {
|
||||||
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 {
|
||||||
// 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 {
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "plannerInt.h"
|
#include "plannerInt.h"
|
||||||
#include "exception.h"
|
#include "texception.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
#define STORE_CURRENT_SUBPLAN(cxt) SSubplan* _ = cxt->pCurrentSubplan
|
#define STORE_CURRENT_SUBPLAN(cxt) SSubplan* _ = cxt->pCurrentSubplan
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_WAL_INT_H_
|
#ifndef _TD_WAL_INT_H_
|
||||||
#define _TD_WAL_INT_H_
|
#define _TD_WAL_INT_H_
|
||||||
|
|
||||||
#include "compare.h"
|
#include "tcompare.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
|
|
|
@ -14,10 +14,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "compare.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() {
|
||||||
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 @@
|
||||||
* 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 @@
|
||||||
#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 @@
|
||||||
#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) {
|
||||||
|
|
|
@ -46,6 +46,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight) {
|
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight) {
|
||||||
|
if (inTimezone == NULL || inTimezone[0] == 0) return;
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
char winStr[TD_LOCALE_LEN * 2];
|
char winStr[TD_LOCALE_LEN * 2];
|
||||||
sprintf(winStr, "TZ=%s", inTimezone);
|
sprintf(winStr, "TZ=%s", inTimezone);
|
||||||
|
|
|
@ -1,166 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 "os.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
static threadlocal SExceptionNode* expList;
|
|
||||||
|
|
||||||
void exceptionPushNode( SExceptionNode* node ) {
|
|
||||||
node->prev = expList;
|
|
||||||
expList = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t exceptionPopNode() {
|
|
||||||
SExceptionNode* node = expList;
|
|
||||||
expList = node->prev;
|
|
||||||
return node->code;
|
|
||||||
}
|
|
||||||
|
|
||||||
void exceptionThrow( int32_t code ) {
|
|
||||||
expList->code = code;
|
|
||||||
longjmp( expList->jb, 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void cleanupWrapper_void_ptr_ptr( SCleanupAction* ca ) {
|
|
||||||
void (*func)( void*, void* ) = ca->func;
|
|
||||||
func( ca->arg1.Ptr, ca->arg2.Ptr );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanupWrapper_void_ptr_bool( SCleanupAction* ca ) {
|
|
||||||
void (*func)( void*, bool ) = ca->func;
|
|
||||||
func( ca->arg1.Ptr, ca->arg2.Bool );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanupWrapper_void_ptr( SCleanupAction* ca ) {
|
|
||||||
void (*func)( void* ) = ca->func;
|
|
||||||
func( ca->arg1.Ptr );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanupWrapper_int_int( SCleanupAction* ca ) {
|
|
||||||
int (*func)( int ) = ca->func;
|
|
||||||
func( ca->arg1.Int );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanupWrapper_void( SCleanupAction* ca ) {
|
|
||||||
void (*func)() = ca->func;
|
|
||||||
func();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanupWrapper_int_ptr( SCleanupAction* ca ) {
|
|
||||||
int (*func)( void* ) = ca->func;
|
|
||||||
func( ca->arg1.Ptr );
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef void (*wrapper)(SCleanupAction*);
|
|
||||||
static wrapper wrappers[] = {
|
|
||||||
cleanupWrapper_void_ptr_ptr,
|
|
||||||
cleanupWrapper_void_ptr_bool,
|
|
||||||
cleanupWrapper_void_ptr,
|
|
||||||
cleanupWrapper_int_int,
|
|
||||||
cleanupWrapper_void,
|
|
||||||
cleanupWrapper_int_ptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void cleanupPush_void_ptr_ptr( bool failOnly, void* func, void* arg1, void* arg2 ) {
|
|
||||||
assert( expList->numCleanupAction < expList->maxCleanupAction );
|
|
||||||
|
|
||||||
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
|
|
||||||
ca->wrapper = 0;
|
|
||||||
ca->failOnly = failOnly;
|
|
||||||
ca->func = func;
|
|
||||||
ca->arg1.Ptr = arg1;
|
|
||||||
ca->arg2.Ptr = arg2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanupPush_void_ptr_bool( bool failOnly, void* func, void* arg1, bool arg2 ) {
|
|
||||||
assert( expList->numCleanupAction < expList->maxCleanupAction );
|
|
||||||
|
|
||||||
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
|
|
||||||
ca->wrapper = 1;
|
|
||||||
ca->failOnly = failOnly;
|
|
||||||
ca->func = func;
|
|
||||||
ca->arg1.Ptr = arg1;
|
|
||||||
ca->arg2.Bool = arg2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanupPush_void_ptr( bool failOnly, void* func, void* arg ) {
|
|
||||||
assert( expList->numCleanupAction < expList->maxCleanupAction );
|
|
||||||
|
|
||||||
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
|
|
||||||
ca->wrapper = 2;
|
|
||||||
ca->failOnly = failOnly;
|
|
||||||
ca->func = func;
|
|
||||||
ca->arg1.Ptr = arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanupPush_int_int( bool failOnly, void* func, int arg ) {
|
|
||||||
assert( expList->numCleanupAction < expList->maxCleanupAction );
|
|
||||||
|
|
||||||
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
|
|
||||||
ca->wrapper = 3;
|
|
||||||
ca->failOnly = failOnly;
|
|
||||||
ca->func = func;
|
|
||||||
ca->arg1.Int = arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanupPush_void( bool failOnly, void* func ) {
|
|
||||||
assert( expList->numCleanupAction < expList->maxCleanupAction );
|
|
||||||
|
|
||||||
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
|
|
||||||
ca->wrapper = 4;
|
|
||||||
ca->failOnly = failOnly;
|
|
||||||
ca->func = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanupPush_int_ptr( bool failOnly, void* func, void* arg ) {
|
|
||||||
assert( expList->numCleanupAction < expList->maxCleanupAction );
|
|
||||||
|
|
||||||
SCleanupAction *ca = expList->cleanupActions + expList->numCleanupAction++;
|
|
||||||
ca->wrapper = 5;
|
|
||||||
ca->failOnly = failOnly;
|
|
||||||
ca->func = func;
|
|
||||||
ca->arg1.Ptr = arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32_t cleanupGetActionCount() {
|
|
||||||
return expList->numCleanupAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void doExecuteCleanup( SExceptionNode* node, int32_t anchor, bool failed ) {
|
|
||||||
while( node->numCleanupAction > anchor ) {
|
|
||||||
--node->numCleanupAction;
|
|
||||||
SCleanupAction *ca = node->cleanupActions + node->numCleanupAction;
|
|
||||||
if( failed || !(ca->failOnly) ) {
|
|
||||||
wrappers[ca->wrapper]( ca );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanupExecuteTo( int32_t anchor, bool failed ) {
|
|
||||||
doExecuteCleanup( expList, anchor, failed );
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanupExecute( SExceptionNode* node, bool failed ) {
|
|
||||||
doExecuteCleanup( node, 0, failed );
|
|
||||||
}
|
|
||||||
bool cleanupExceedLimit() {
|
|
||||||
return expList->numCleanupAction >= expList->maxCleanupAction;
|
|
||||||
}
|
|
|
@ -13,16 +13,18 @@
|
||||||
* 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"
|
#define _DEFAULT_SOURCE
|
||||||
#include "talgo.h"
|
#include "talgo.h"
|
||||||
|
|
||||||
#define doswap(__left, __right, __size, __buf) do {\
|
#define doswap(__left, __right, __size, __buf) \
|
||||||
memcpy((__buf), (__left), (__size));\
|
do { \
|
||||||
memcpy((__left), (__right),(__size));\
|
memcpy((__buf), (__left), (__size)); \
|
||||||
memcpy((__right), (__buf), (__size));\
|
memcpy((__left), (__right), (__size)); \
|
||||||
} while (0);
|
memcpy((__right), (__buf), (__size)); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
static void median(void *src, size_t size, size_t s, size_t e, const void *param, __ext_compar_fn_t comparFn, void* buf) {
|
static void median(void *src, int64_t size, int64_t s, int64_t e, const void *param, __ext_compar_fn_t comparFn,
|
||||||
|
void *buf) {
|
||||||
int32_t mid = ((int32_t)(e - s) >> 1u) + (int32_t)s;
|
int32_t mid = ((int32_t)(e - s) >> 1u) + (int32_t)s;
|
||||||
|
|
||||||
if (comparFn(elePtrAt(src, size, mid), elePtrAt(src, size, s), param) == 1) {
|
if (comparFn(elePtrAt(src, size, mid), elePtrAt(src, size, s), param) == 1) {
|
||||||
|
@ -36,7 +38,8 @@ static void median(void *src, size_t size, size_t s, size_t e, const void *param
|
||||||
doswap(elePtrAt(src, size, s), elePtrAt(src, size, e), size, buf);
|
doswap(elePtrAt(src, size, s), elePtrAt(src, size, e), size, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(comparFn(elePtrAt(src, size, mid), elePtrAt(src, size, s), param) <= 0 && comparFn(elePtrAt(src, size, s), elePtrAt(src, size, e), param) <= 0);
|
assert(comparFn(elePtrAt(src, size, mid), elePtrAt(src, size, s), param) <= 0 &&
|
||||||
|
comparFn(elePtrAt(src, size, s), elePtrAt(src, size, e), param) <= 0);
|
||||||
|
|
||||||
#ifdef _DEBUG_VIEW
|
#ifdef _DEBUG_VIEW
|
||||||
// tTagsPrints(src[s], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
// tTagsPrints(src[s], pOrderDesc->pColumnModel, &pOrderDesc->orderIdx);
|
||||||
|
@ -45,8 +48,8 @@ static void median(void *src, size_t size, size_t s, size_t e, const void *param
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tInsertSort(void *src, size_t size, int32_t s, int32_t e, const void *param, __ext_compar_fn_t comparFn,
|
static void tInsertSort(void *src, int64_t size, int32_t s, int32_t e, const void *param, __ext_compar_fn_t comparFn,
|
||||||
void* buf) {
|
void *buf) {
|
||||||
for (int32_t i = s + 1; i <= e; ++i) {
|
for (int32_t i = s + 1; i <= e; ++i) {
|
||||||
for (int32_t j = i; j > s; --j) {
|
for (int32_t j = i; j > s; --j) {
|
||||||
if (comparFn(elePtrAt(src, size, j), elePtrAt(src, size, j - 1), param) == -1) {
|
if (comparFn(elePtrAt(src, size, j), elePtrAt(src, size, j - 1), param) == -1) {
|
||||||
|
@ -58,8 +61,8 @@ static void tInsertSort(void *src, size_t size, int32_t s, int32_t e, const void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tqsortImpl(void *src, int32_t start, int32_t end, size_t size, const void *param, __ext_compar_fn_t comparFn,
|
static void tqsortImpl(void *src, int32_t start, int32_t end, int64_t size, const void *param,
|
||||||
void* buf) {
|
__ext_compar_fn_t comparFn, void *buf) {
|
||||||
// short array sort, incur another sort procedure instead of quick sort process
|
// short array sort, incur another sort procedure instead of quick sort process
|
||||||
const int32_t THRESHOLD_SIZE = 6;
|
const int32_t THRESHOLD_SIZE = 6;
|
||||||
if (end - start + 1 <= THRESHOLD_SIZE) {
|
if (end - start + 1 <= THRESHOLD_SIZE) {
|
||||||
|
@ -79,7 +82,7 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, size_t size, const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//move the data that equals to pivotal value to the right end of the list
|
// move the data that equals to pivotal value to the right end of the list
|
||||||
if (ret == 0 && e != endRightS) {
|
if (ret == 0 && e != endRightS) {
|
||||||
doswap(elePtrAt(src, size, e), elePtrAt(src, size, endRightS), size, buf);
|
doswap(elePtrAt(src, size, e), elePtrAt(src, size, endRightS), size, buf);
|
||||||
endRightS--;
|
endRightS--;
|
||||||
|
@ -149,18 +152,18 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, size_t size, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ext_compar_fn_t comparFn) {
|
void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn) {
|
||||||
char *buf = calloc(1, size); // prepare the swap buffer
|
char *buf = calloc(1, size); // prepare the swap buffer
|
||||||
tqsortImpl(src, 0, (int32_t)numOfElem - 1, (int32_t)size, param, comparFn, buf);
|
tqsortImpl(src, 0, (int32_t)numOfElem - 1, (int32_t)size, param, comparFn, buf);
|
||||||
tfree(buf);
|
tfree(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, __compar_fn_t compar, int flags) {
|
void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t compar, int32_t flags) {
|
||||||
// TODO: need to check the correctness of this function
|
// TODO: need to check the correctness of this function
|
||||||
int l = 0;
|
int32_t l = 0;
|
||||||
int r = (int)nmemb;
|
int32_t r = (int32_t)nmemb;
|
||||||
int idx = 0;
|
int32_t idx = 0;
|
||||||
int comparison;
|
int32_t comparison;
|
||||||
|
|
||||||
if (flags == TD_EQ) {
|
if (flags == TD_EQ) {
|
||||||
return bsearch(key, base, nmemb, size, compar);
|
return bsearch(key, base, nmemb, size, compar);
|
||||||
|
@ -225,11 +228,11 @@ void * taosbsearch(const void *key, const void *base, size_t nmemb, size_t size,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot)
|
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar,
|
||||||
{
|
__ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot) {
|
||||||
int32_t parent;
|
int32_t parent;
|
||||||
int32_t child;
|
int32_t child;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
if (base && size > 0 && compar) {
|
if (base && size > 0 && compar) {
|
||||||
parent = start;
|
parent = start;
|
||||||
|
@ -244,7 +247,8 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
|
||||||
|
|
||||||
if (maxroot) {
|
if (maxroot) {
|
||||||
while (child <= end) {
|
while (child <= end) {
|
||||||
if (child + 1 <= end && (*compar)(elePtrAt(base, size, child), elePtrAt(base, size, child + 1), parcompar) < 0) {
|
if (child + 1 <= end &&
|
||||||
|
(*compar)(elePtrAt(base, size, child), elePtrAt(base, size, child + 1), parcompar) < 0) {
|
||||||
child++;
|
child++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +267,8 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (child <= end) {
|
while (child <= end) {
|
||||||
if (child + 1 <= end && (*compar)(elePtrAt(base, size, child), elePtrAt(base, size, child + 1), parcompar) > 0) {
|
if (child + 1 <= end &&
|
||||||
|
(*compar)(elePtrAt(base, size, child), elePtrAt(base, size, child + 1), parcompar) > 0) {
|
||||||
child++;
|
child++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,9 +293,9 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, const void *parswap, __ext_swap_fn_t swap, bool maxroot)
|
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar,
|
||||||
{
|
const void *parswap, __ext_swap_fn_t swap, bool maxroot) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
|
||||||
if (base && size > 0) {
|
if (base && size > 0) {
|
||||||
for (i = len / 2 - 1; i >= 0; i--) {
|
for (i = len / 2 - 1; i >= 0; i--) {
|
||||||
|
@ -298,15 +303,14 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
char *buf = calloc(1, size);
|
char *buf = calloc(1, size);
|
||||||
|
|
||||||
for (i = len - 1; i > 0; i--) {
|
for (i = len - 1; i > 0; i--) {
|
||||||
doswap(elePtrAt(base, size, 0), elePtrAt(base, size, i));
|
doswap(elePtrAt(base, size, 0), elePtrAt(base, size, i));
|
||||||
taosheapadjust(base, size, 0, i - 1, parcompar, compar, parswap, swap, maxroot);
|
taosheapadjust(base, size, 0, i - 1, parcompar, compar, parswap, swap, maxroot);
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(buf);
|
tfree(buf);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,8 @@
|
||||||
* 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"
|
#define _DEFAULT_SOURCE
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "talgo.h"
|
|
||||||
|
|
||||||
SArray* taosArrayInit(size_t size, size_t elemSize) {
|
SArray* taosArrayInit(size_t size, size_t elemSize) {
|
||||||
assert(elemSize > 0);
|
assert(elemSize > 0);
|
||||||
|
@ -75,12 +74,12 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t newCap) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArrayAddBatch(SArray* pArray, const void* pData, int nEles) {
|
void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles) {
|
||||||
if (pArray == NULL || pData == NULL) {
|
if (pArray == NULL || pData == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(taosArrayEnsureCap(pArray, pArray->size + nEles) != 0){
|
if (taosArrayEnsureCap(pArray, pArray->size + nEles) != 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ void* taosArrayAddBatch(SArray* pArray, const void* pData, int nEles) {
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfElems) {
|
void taosArrayRemoveBatch(SArray* pArray, const int32_t* pData, int32_t numOfElems) {
|
||||||
assert(pArray != NULL && pData != NULL);
|
assert(pArray != NULL && pData != NULL);
|
||||||
if (numOfElems <= 0) {
|
if (numOfElems <= 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -104,7 +103,7 @@ void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfEle
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t i = pData[0] + 1, j = 0;
|
int32_t i = pData[0] + 1, j = 0;
|
||||||
while(i < size) {
|
while (i < size) {
|
||||||
if (j == numOfElems - 1) {
|
if (j == numOfElems - 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +132,7 @@ void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfEle
|
||||||
pArray->size -= numOfElems;
|
pArray->size -= numOfElems;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)(void*)) {
|
void taosArrayRemoveDuplicate(SArray* pArray, __compar_fn_t comparFn, void (*fp)(void*)) {
|
||||||
assert(pArray);
|
assert(pArray);
|
||||||
|
|
||||||
size_t size = pArray->size;
|
size_t size = pArray->size;
|
||||||
|
@ -142,7 +141,7 @@ void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t pos = 0;
|
int32_t pos = 0;
|
||||||
for(int32_t i = 1; i < size; ++i) {
|
for (int32_t i = 1; i < size; ++i) {
|
||||||
char* p1 = taosArrayGet(pArray, pos);
|
char* p1 = taosArrayGet(pArray, pos);
|
||||||
char* p2 = taosArrayGet(pArray, i);
|
char* p2 = taosArrayGet(pArray, i);
|
||||||
|
|
||||||
|
@ -164,7 +163,7 @@ void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
for(int32_t i = pos + 1; i < pArray->size; ++i) {
|
for (int32_t i = pos + 1; i < pArray->size; ++i) {
|
||||||
void* p = taosArrayGet(pArray, i);
|
void* p = taosArrayGet(pArray, i);
|
||||||
fp(p);
|
fp(p);
|
||||||
}
|
}
|
||||||
|
@ -174,11 +173,11 @@ void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArrayAddAll(SArray* pArray, const SArray* pInput) {
|
void* taosArrayAddAll(SArray* pArray, const SArray* pInput) {
|
||||||
return taosArrayAddBatch(pArray, pInput->pData, (int32_t) taosArrayGetSize(pInput));
|
return taosArrayAddBatch(pArray, pInput->pData, (int32_t)taosArrayGetSize(pInput));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArrayPop(SArray* pArray) {
|
void* taosArrayPop(SArray* pArray) {
|
||||||
assert( pArray != NULL );
|
assert(pArray != NULL);
|
||||||
|
|
||||||
if (pArray->size == 0) {
|
if (pArray->size == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -200,9 +199,7 @@ void* taosArrayGetP(const SArray* pArray, size_t index) {
|
||||||
return *(void**)d;
|
return *(void**)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArrayGetLast(const SArray* pArray) {
|
void* taosArrayGetLast(const SArray* pArray) { return TARRAY_GET_ELEM(pArray, pArray->size - 1); }
|
||||||
return TARRAY_GET_ELEM(pArray, pArray->size - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t taosArrayGetSize(const SArray* pArray) {
|
size_t taosArrayGetSize(const SArray* pArray) {
|
||||||
if (pArray == NULL) {
|
if (pArray == NULL) {
|
||||||
|
@ -252,7 +249,7 @@ void taosArraySet(SArray* pArray, size_t index, void* pData) {
|
||||||
void taosArrayPopFrontBatch(SArray* pArray, size_t cnt) {
|
void taosArrayPopFrontBatch(SArray* pArray, size_t cnt) {
|
||||||
assert(cnt <= pArray->size);
|
assert(cnt <= pArray->size);
|
||||||
pArray->size = pArray->size - cnt;
|
pArray->size = pArray->size - cnt;
|
||||||
if(pArray->size == 0) {
|
if (pArray->size == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memmove(pArray->pData, (char*)pArray->pData + cnt * pArray->elemSize, pArray->size * pArray->elemSize);
|
memmove(pArray->pData, (char*)pArray->pData + cnt * pArray->elemSize, pArray->size * pArray->elemSize);
|
||||||
|
@ -272,7 +269,8 @@ void taosArrayRemove(SArray* pArray, size_t index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t remain = pArray->size - index - 1;
|
size_t remain = pArray->size - index - 1;
|
||||||
memmove((char*)pArray->pData + index * pArray->elemSize, (char*)pArray->pData + (index + 1) * pArray->elemSize, remain * pArray->elemSize);
|
memmove((char*)pArray->pData + index * pArray->elemSize, (char*)pArray->pData + (index + 1) * pArray->elemSize,
|
||||||
|
remain * pArray->elemSize);
|
||||||
pArray->size -= 1;
|
pArray->size -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +287,7 @@ SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize) {
|
||||||
SArray* taosArrayDup(const SArray* pSrc) {
|
SArray* taosArrayDup(const SArray* pSrc) {
|
||||||
assert(pSrc != NULL);
|
assert(pSrc != NULL);
|
||||||
|
|
||||||
if (pSrc->size == 0) { // empty array list
|
if (pSrc->size == 0) { // empty array list
|
||||||
return taosArrayInit(8, pSrc->elemSize);
|
return taosArrayInit(8, pSrc->elemSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +322,7 @@ void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int32_t i = 0; i < pArray->size; ++i) {
|
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||||
fp(TARRAY_GET_ELEM(pArray, i));
|
fp(TARRAY_GET_ELEM(pArray, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,14 +336,14 @@ void taosArraySort(SArray* pArray, __compar_fn_t compar) {
|
||||||
qsort(pArray->pData, pArray->size, pArray->elemSize, compar);
|
qsort(pArray->pData, pArray->size, pArray->elemSize, compar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags) {
|
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags) {
|
||||||
assert(pArray != NULL && comparFn != NULL);
|
assert(pArray != NULL && comparFn != NULL);
|
||||||
assert(key != NULL);
|
assert(key != NULL);
|
||||||
|
|
||||||
return taosbsearch(key, pArray->pData, pArray->size, pArray->elemSize, comparFn, flags);
|
return taosbsearch(key, pArray->pData, pArray->size, pArray->elemSize, comparFn, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int flags) {
|
int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags) {
|
||||||
void* item = taosArraySearch(pArray, key, comparFn, flags);
|
void* item = taosArraySearch(pArray, key, comparFn, flags);
|
||||||
return item == NULL ? -1 : (int32_t)((char*)item - (char*)pArray->pData) / pArray->elemSize;
|
return item == NULL ? -1 : (int32_t)((char*)item - (char*)pArray->pData) / pArray->elemSize;
|
||||||
}
|
}
|
||||||
|
@ -355,7 +353,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn) {
|
||||||
qsort(pArray->pData, pArray->size, pArray->elemSize, comparFn);
|
qsort(pArray->pData, pArray->size, pArray->elemSize, comparFn);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int flags) {
|
char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn, int32_t flags) {
|
||||||
assert(pArray != NULL);
|
assert(pArray != NULL);
|
||||||
assert(key != NULL);
|
assert(key != NULL);
|
||||||
|
|
||||||
|
@ -366,17 +364,21 @@ char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t
|
||||||
return *(char**)p;
|
return *(char**)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int taosArrayPartition(SArray *pArray, int i, int j, __ext_compar_fn_t fn, const void *userData) {
|
static int32_t taosArrayPartition(SArray* pArray, int32_t i, int32_t j, __ext_compar_fn_t fn, const void* userData) {
|
||||||
void* key = taosArrayGetP(pArray, i);
|
void* key = taosArrayGetP(pArray, i);
|
||||||
while (i < j) {
|
while (i < j) {
|
||||||
while (i < j && fn(taosArrayGetP(pArray, j), key, userData) >= 0) { j--; }
|
while (i < j && fn(taosArrayGetP(pArray, j), key, userData) >= 0) {
|
||||||
|
j--;
|
||||||
|
}
|
||||||
if (i < j) {
|
if (i < j) {
|
||||||
void *a = taosArrayGetP(pArray, j);
|
void* a = taosArrayGetP(pArray, j);
|
||||||
taosArraySet(pArray, i, &a);
|
taosArraySet(pArray, i, &a);
|
||||||
}
|
}
|
||||||
while (i < j && fn(taosArrayGetP(pArray, i), key, userData) <= 0) { i++;}
|
while (i < j && fn(taosArrayGetP(pArray, i), key, userData) <= 0) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
if (i < j) {
|
if (i < j) {
|
||||||
void *a = taosArrayGetP(pArray, i);
|
void* a = taosArrayGetP(pArray, i);
|
||||||
taosArraySet(pArray, j, &a);
|
taosArraySet(pArray, j, &a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,29 +386,31 @@ static int taosArrayPartition(SArray *pArray, int i, int j, __ext_compar_fn_t fn
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosArrayQuicksortHelper(SArray *pArray, int low, int high, __ext_compar_fn_t fn, const void *param) {
|
static void taosArrayQuicksortHelper(SArray* pArray, int32_t low, int32_t high, __ext_compar_fn_t fn,
|
||||||
|
const void* param) {
|
||||||
if (low < high) {
|
if (low < high) {
|
||||||
int idx = taosArrayPartition(pArray, low, high, fn, param);
|
int32_t idx = taosArrayPartition(pArray, low, high, fn, param);
|
||||||
taosArrayQuicksortHelper(pArray, low, idx - 1, fn, param);
|
taosArrayQuicksortHelper(pArray, low, idx - 1, fn, param);
|
||||||
taosArrayQuicksortHelper(pArray, idx + 1, high, fn, param);
|
taosArrayQuicksortHelper(pArray, idx + 1, high, fn, param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosArrayQuickSort(SArray* pArray, __ext_compar_fn_t fn, const void *param) {
|
static void taosArrayQuickSort(SArray* pArray, __ext_compar_fn_t fn, const void* param) {
|
||||||
if (pArray->size <= 1) {
|
if (pArray->size <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
taosArrayQuicksortHelper(pArray, 0, (int)(taosArrayGetSize(pArray) - 1), fn, param);
|
taosArrayQuicksortHelper(pArray, 0, (int32_t)(taosArrayGetSize(pArray) - 1), fn, param);
|
||||||
}
|
}
|
||||||
static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void *param) {
|
|
||||||
|
static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void* param) {
|
||||||
if (pArray->size <= 1) {
|
if (pArray->size <= 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 1; i <= pArray->size - 1; ++i) {
|
for (int32_t i = 1; i <= pArray->size - 1; ++i) {
|
||||||
for (int j = i; j > 0; --j) {
|
for (int32_t j = i; j > 0; --j) {
|
||||||
if (fn(taosArrayGetP(pArray, j), taosArrayGetP(pArray, j - 1), param) == -1) {
|
if (fn(taosArrayGetP(pArray, j), taosArrayGetP(pArray, j - 1), param) == -1) {
|
||||||
void *a = taosArrayGetP(pArray, j);
|
void* a = taosArrayGetP(pArray, j);
|
||||||
void *b = taosArrayGetP(pArray, j - 1);
|
void* b = taosArrayGetP(pArray, j - 1);
|
||||||
taosArraySet(pArray, j - 1, &a);
|
taosArraySet(pArray, j - 1, &a);
|
||||||
taosArraySet(pArray, j, &b);
|
taosArraySet(pArray, j, &b);
|
||||||
} else {
|
} else {
|
||||||
|
@ -415,11 +419,10 @@ static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
// order array<type *>
|
// order array<type *>
|
||||||
void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void *param) {
|
void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param) {
|
||||||
taosArrayGetSize(pArray) > 8 ?
|
taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param);
|
||||||
taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param);
|
|
||||||
}
|
}
|
||||||
//TODO(yihaoDeng) add order array<type>
|
// TODO(yihaoDeng) add order array<type>
|
||||||
|
|
|
@ -13,15 +13,15 @@
|
||||||
* 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"
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "tbase64.h"
|
||||||
|
|
||||||
// deprecated this file for bug prone
|
|
||||||
// base64 encode
|
|
||||||
static char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
static char basis_64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
char *base64_encode(const unsigned char *value, int vlen) {
|
|
||||||
unsigned char oval = 0;
|
char *base64_encode(const uint8_t *value, int32_t vlen) {
|
||||||
char * result = (char *)malloc((size_t)(vlen * 4) / 3 + 10);
|
uint8_t oval = 0;
|
||||||
char * out = result;
|
char *result = (char *)malloc((size_t)(vlen * 4) / 3 + 10);
|
||||||
|
char *out = result;
|
||||||
while (vlen >= 3) {
|
while (vlen >= 3) {
|
||||||
*out++ = basis_64[value[0] >> 2];
|
*out++ = basis_64[value[0] >> 2];
|
||||||
*out++ = basis_64[((value[0] << 4) & 0x30) | (value[1] >> 4)];
|
*out++ = basis_64[((value[0] << 4) & 0x30) | (value[1] >> 4)];
|
||||||
|
@ -42,8 +42,8 @@ char *base64_encode(const unsigned char *value, int vlen) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// base64 decode
|
|
||||||
#define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)])
|
#define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)])
|
||||||
|
|
||||||
static signed char index_64[128] = {
|
static signed char index_64[128] = {
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55,
|
||||||
|
@ -51,10 +51,10 @@ static signed char index_64[128] = {
|
||||||
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32,
|
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32,
|
||||||
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1};
|
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1};
|
||||||
|
|
||||||
unsigned char *base64_decode(const char *value, int inlen, int *outlen) {
|
uint8_t *base64_decode(const char *value, int32_t inlen, int32_t *outlen) {
|
||||||
int c1, c2, c3, c4;
|
int32_t c1, c2, c3, c4;
|
||||||
unsigned char *result = (unsigned char *)malloc((size_t)(inlen * 3) / 4 + 1);
|
uint8_t *result = (uint8_t *)malloc((size_t)(inlen * 3) / 4 + 1);
|
||||||
unsigned char *out = result;
|
uint8_t *out = result;
|
||||||
|
|
||||||
*outlen = 0;
|
*outlen = 0;
|
||||||
|
|
||||||
|
@ -80,13 +80,13 @@ unsigned char *base64_decode(const char *value, int inlen, int *outlen) {
|
||||||
if ((c4 != '=') && (CHAR64(c4) == -1)) goto base64_decode_error;
|
if ((c4 != '=') && (CHAR64(c4) == -1)) goto base64_decode_error;
|
||||||
|
|
||||||
value += 4;
|
value += 4;
|
||||||
*out++ = (unsigned char)((CHAR64(c1) << 2) | (CHAR64(c2) >> 4));
|
*out++ = (uint8_t)((CHAR64(c1) << 2) | (CHAR64(c2) >> 4));
|
||||||
*outlen += 1;
|
*outlen += 1;
|
||||||
if (c3 != '=') {
|
if (c3 != '=') {
|
||||||
*out++ = (unsigned char)(((CHAR64(c2) << 4) & 0xf0) | (CHAR64(c3) >> 2));
|
*out++ = (uint8_t)(((CHAR64(c2) << 4) & 0xf0) | (CHAR64(c3) >> 2));
|
||||||
*outlen += 1;
|
*outlen += 1;
|
||||||
if (c4 != '=') {
|
if (c4 != '=') {
|
||||||
*out++ = (unsigned char)(((CHAR64(c3) << 6) & 0xc0) | CHAR64(c4));
|
*out++ = (uint8_t)(((CHAR64(c3) << 6) & 0xc0) | CHAR64(c4));
|
||||||
*outlen += 1;
|
*outlen += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
#include "tbuffer.h"
|
#include "tbuffer.h"
|
||||||
#include "exception.h"
|
#include "texception.h"
|
||||||
#include "os.h"
|
|
||||||
//#include "taoserror.h"
|
|
||||||
|
|
||||||
typedef union Un4B {
|
typedef union Un4B {
|
||||||
uint32_t ui;
|
uint32_t ui;
|
||||||
|
|
|
@ -14,11 +14,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "tcache.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tcache.h"
|
|
||||||
|
|
||||||
static FORCE_INLINE void __cache_wr_lock(SCacheObj *pCacheObj) {
|
static FORCE_INLINE void __cache_wr_lock(SCacheObj *pCacheObj) {
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
|
@ -62,15 +61,15 @@ static void doCleanupDataCache(SCacheObj *pCacheObj);
|
||||||
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime
|
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime
|
||||||
* @param handle Cache object handle
|
* @param handle Cache object handle
|
||||||
*/
|
*/
|
||||||
static void* taosCacheTimedRefresh(void *handle);
|
static void *taosCacheTimedRefresh(void *handle);
|
||||||
|
|
||||||
static pthread_t cacheRefreshWorker = {0};
|
static pthread_t cacheRefreshWorker = {0};
|
||||||
static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT;
|
static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT;
|
||||||
static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static SArray* pCacheArrayList = NULL;
|
static SArray *pCacheArrayList = NULL;
|
||||||
static bool stopRefreshWorker = false;
|
static bool stopRefreshWorker = false;
|
||||||
static bool refreshWorkerNormalStopped = false;
|
static bool refreshWorkerNormalStopped = false;
|
||||||
static bool refreshWorkerUnexpectedStopped = false;
|
static bool refreshWorkerUnexpectedStopped = false;
|
||||||
|
|
||||||
static void doInitRefreshThread(void) {
|
static void doInitRefreshThread(void) {
|
||||||
pCacheArrayList = taosArrayInit(4, POINTER_BYTES);
|
pCacheArrayList = taosArrayInit(4, POINTER_BYTES);
|
||||||
|
@ -83,7 +82,7 @@ static void doInitRefreshThread(void) {
|
||||||
pthread_attr_destroy(&thattr);
|
pthread_attr_destroy(&thattr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_t doRegisterCacheObj(SCacheObj* pCacheObj) {
|
pthread_t doRegisterCacheObj(SCacheObj *pCacheObj) {
|
||||||
pthread_once(&cacheThreadInit, doInitRefreshThread);
|
pthread_once(&cacheThreadInit, doInitRefreshThread);
|
||||||
|
|
||||||
pthread_mutex_lock(&guard);
|
pthread_mutex_lock(&guard);
|
||||||
|
@ -102,7 +101,8 @@ pthread_t doRegisterCacheObj(SCacheObj* pCacheObj) {
|
||||||
* @param lifespan total survial expiredTime from now
|
* @param lifespan total survial expiredTime from now
|
||||||
* @return SCacheDataNode
|
* @return SCacheDataNode
|
||||||
*/
|
*/
|
||||||
static SCacheDataNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pData, size_t size, uint64_t duration);
|
static SCacheDataNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pData, size_t size,
|
||||||
|
uint64_t duration);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addedTime object node into trash, and this object is closed for referencing if it is addedTime to trash
|
* addedTime object node into trash, and this object is closed for referencing if it is addedTime to trash
|
||||||
|
@ -146,18 +146,18 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNo
|
||||||
free(pNode);
|
free(pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE STrashElem* doRemoveElemInTrashcan(SCacheObj* pCacheObj, STrashElem *pElem) {
|
static FORCE_INLINE STrashElem *doRemoveElemInTrashcan(SCacheObj *pCacheObj, STrashElem *pElem) {
|
||||||
if (pElem->pData->signature != (uint64_t) pElem->pData) {
|
if (pElem->pData->signature != (uint64_t)pElem->pData) {
|
||||||
uWarn("key:sig:0x%" PRIx64 " %p data has been released, ignore", pElem->pData->signature, pElem->pData);
|
uWarn("key:sig:0x%" PRIx64 " %p data has been released, ignore", pElem->pData->signature, pElem->pData);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
STrashElem* next = pElem->next;
|
STrashElem *next = pElem->next;
|
||||||
|
|
||||||
pCacheObj->numOfElemsInTrash--;
|
pCacheObj->numOfElemsInTrash--;
|
||||||
if (pElem->prev) {
|
if (pElem->prev) {
|
||||||
pElem->prev->next = pElem->next;
|
pElem->prev->next = pElem->next;
|
||||||
} else { // pnode is the header, update header
|
} else { // pnode is the header, update header
|
||||||
pCacheObj->pTrash = pElem->next;
|
pCacheObj->pTrash = pElem->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ static FORCE_INLINE STrashElem* doRemoveElemInTrashcan(SCacheObj* pCacheObj, STr
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj* pCacheObj, STrashElem *pElem) {
|
static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj *pCacheObj, STrashElem *pElem) {
|
||||||
if (pCacheObj->freeFp) {
|
if (pCacheObj->freeFp) {
|
||||||
pCacheObj->freeFp(pElem->pData->data);
|
pCacheObj->freeFp(pElem->pData->data);
|
||||||
}
|
}
|
||||||
|
@ -181,8 +181,9 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj* pCacheObj, STrashElem
|
||||||
free(pElem);
|
free(pElem);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char* cacheName) {
|
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn,
|
||||||
const int32_t SLEEP_DURATION = 500; //500 ms
|
const char *cacheName) {
|
||||||
|
const int32_t SLEEP_DURATION = 500; // 500 ms
|
||||||
|
|
||||||
if (refreshTimeInSeconds <= 0) {
|
if (refreshTimeInSeconds <= 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -203,9 +204,9 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
|
||||||
}
|
}
|
||||||
|
|
||||||
// set free cache node callback function
|
// set free cache node callback function
|
||||||
pCacheObj->freeFp = fn;
|
pCacheObj->freeFp = fn;
|
||||||
pCacheObj->refreshTime = refreshTimeInSeconds * 1000;
|
pCacheObj->refreshTime = refreshTimeInSeconds * 1000;
|
||||||
pCacheObj->checkTick = pCacheObj->refreshTime / SLEEP_DURATION;
|
pCacheObj->checkTick = pCacheObj->refreshTime / SLEEP_DURATION;
|
||||||
pCacheObj->extendLifespan = extendLifespan; // the TTL after the last access
|
pCacheObj->extendLifespan = extendLifespan; // the TTL after the last access
|
||||||
|
|
||||||
if (__cache_lock_init(pCacheObj) != 0) {
|
if (__cache_lock_init(pCacheObj) != 0) {
|
||||||
|
@ -220,7 +221,8 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
|
||||||
return pCacheObj;
|
return pCacheObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize, int durationMS) {
|
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize,
|
||||||
|
int32_t durationMS) {
|
||||||
if (pCacheObj == NULL || pCacheObj->pHashTable == NULL || pCacheObj->deleting == 1) {
|
if (pCacheObj == NULL || pCacheObj->pHashTable == NULL || pCacheObj->deleting == 1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -242,8 +244,8 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v
|
||||||
(int32_t)taosHashGetSize(pCacheObj->pHashTable), pCacheObj->totalSize, (int64_t)dataSize);
|
(int32_t)taosHashGetSize(pCacheObj->pHashTable), pCacheObj->totalSize, (int64_t)dataSize);
|
||||||
} else { // duplicated key exists
|
} else { // duplicated key exists
|
||||||
while (1) {
|
while (1) {
|
||||||
SCacheDataNode* p = NULL;
|
SCacheDataNode *p = NULL;
|
||||||
// int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, key, keyLen, (void*) &p, sizeof(void*));
|
// int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, key, keyLen, (void*) &p, sizeof(void*));
|
||||||
int32_t ret = taosHashRemove(pCacheObj->pHashTable, key, keyLen);
|
int32_t ret = taosHashRemove(pCacheObj->pHashTable, key, keyLen);
|
||||||
|
|
||||||
// add to trashcan
|
// add to trashcan
|
||||||
|
@ -283,10 +285,10 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v
|
||||||
return pNode1->data;
|
return pNode1->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void incRefFn(void* ptNode) {
|
static void incRefFn(void *ptNode) {
|
||||||
assert(ptNode != NULL);
|
assert(ptNode != NULL);
|
||||||
|
|
||||||
SCacheDataNode** p = (SCacheDataNode**) ptNode;
|
SCacheDataNode **p = (SCacheDataNode **)ptNode;
|
||||||
assert(T_REF_VAL_GET(*p) >= 0);
|
assert(T_REF_VAL_GET(*p) >= 0);
|
||||||
|
|
||||||
int32_t ret = T_REF_INC(*p);
|
int32_t ret = T_REF_INC(*p);
|
||||||
|
@ -303,15 +305,16 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCacheDataNode* ptNode = NULL;
|
SCacheDataNode *ptNode = NULL;
|
||||||
taosHashGetClone(pCacheObj->pHashTable, key, keyLen, &ptNode);
|
taosHashGetClone(pCacheObj->pHashTable, key, keyLen, &ptNode);
|
||||||
// taosHashGetClone(pCacheObj->pHashTable, key, keyLen, incRefFn, &ptNode);
|
// taosHashGetClone(pCacheObj->pHashTable, key, keyLen, incRefFn, &ptNode);
|
||||||
|
|
||||||
void* pData = (ptNode != NULL)? ptNode->data:NULL;
|
void *pData = (ptNode != NULL) ? ptNode->data : NULL;
|
||||||
|
|
||||||
if (pData != NULL) {
|
if (pData != NULL) {
|
||||||
atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1);
|
||||||
uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, T_REF_VAL_GET(ptNode));
|
uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData,
|
||||||
|
T_REF_VAL_GET(ptNode));
|
||||||
} else {
|
} else {
|
||||||
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
||||||
uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key);
|
uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key);
|
||||||
|
@ -371,7 +374,6 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// The operation of removal from hash table and addition to trashcan is not an atomic operation,
|
// The operation of removal from hash table and addition to trashcan is not an atomic operation,
|
||||||
// therefore the check for the empty of both the hash table and the trashcan has a race condition.
|
// therefore the check for the empty of both the hash table and the trashcan has a race condition.
|
||||||
// It happens when there is only one object in the cache, and two threads which has referenced this object
|
// It happens when there is only one object in the cache, and two threads which has referenced this object
|
||||||
|
@ -391,20 +393,20 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
|
|
||||||
if (pCacheObj->extendLifespan && (!inTrashcan) && (!_remove)) {
|
if (pCacheObj->extendLifespan && (!inTrashcan) && (!_remove)) {
|
||||||
atomic_store_64(&pNode->expireTime, pNode->lifespan + taosGetTimestampMs());
|
atomic_store_64(&pNode->expireTime, pNode->lifespan + taosGetTimestampMs());
|
||||||
uDebug("cache:%s, data:%p extend expire time: %"PRId64, pCacheObj->name, pNode->data, pNode->expireTime);
|
uDebug("cache:%s, data:%p extend expire time: %" PRId64, pCacheObj->name, pNode->data, pNode->expireTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_remove) {
|
if (_remove) {
|
||||||
// NOTE: once refcount is decrease, pNode may be freed by other thread immediately.
|
// NOTE: once refcount is decrease, pNode may be freed by other thread immediately.
|
||||||
char* key = pNode->key;
|
char *key = pNode->key;
|
||||||
char* d = pNode->data;
|
char *d = pNode->data;
|
||||||
|
|
||||||
int32_t ref = T_REF_VAL_GET(pNode);
|
int32_t ref = T_REF_VAL_GET(pNode);
|
||||||
uDebug("cache:%s, key:%p, %p is released, refcnt:%d, in trashcan:%d", pCacheObj->name, key, d, ref - 1, inTrashcan);
|
uDebug("cache:%s, key:%p, %p is released, refcnt:%d, in trashcan:%d", pCacheObj->name, key, d, ref - 1, inTrashcan);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it is not referenced by other users, remove it immediately. Otherwise move this node to trashcan wait for all users
|
* If it is not referenced by other users, remove it immediately. Otherwise move this node to trashcan wait for all
|
||||||
* releasing this resources.
|
* users releasing this resources.
|
||||||
*
|
*
|
||||||
* NOTE: previous ref is 0, and current ref is still 0, remove it. If previous is not 0, there is another thread
|
* NOTE: previous ref is 0, and current ref is still 0, remove it. If previous is not 0, there is another thread
|
||||||
* that tries to do the same thing.
|
* that tries to do the same thing.
|
||||||
|
@ -433,16 +435,19 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
// NOTE: remove it from hash in the first place, otherwise, the pNode may have been released by other thread
|
// NOTE: remove it from hash in the first place, otherwise, the pNode may have been released by other thread
|
||||||
// when reaches here.
|
// when reaches here.
|
||||||
SCacheDataNode *p = NULL;
|
SCacheDataNode *p = NULL;
|
||||||
int32_t ret = taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize);
|
int32_t ret = taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize);
|
||||||
// int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, pNode->key, pNode->keySize, &p, sizeof(void *));
|
// int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, pNode->key, pNode->keySize, &p, sizeof(void
|
||||||
|
// *));
|
||||||
ref = T_REF_DEC(pNode);
|
ref = T_REF_DEC(pNode);
|
||||||
|
|
||||||
// successfully remove from hash table, if failed, this node must have been move to trash already, do nothing.
|
// successfully remove from hash table, if failed, this node must have been move to trash already, do nothing.
|
||||||
// note that the remove operation can be executed only once.
|
// note that the remove operation can be executed only once.
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
if (p != pNode) {
|
if (p != pNode) {
|
||||||
uDebug( "cache:%s, key:%p, successfully removed a new entry:%p, refcnt:%d, prev entry:%p has been removed by "
|
uDebug(
|
||||||
"others already", pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data);
|
"cache:%s, key:%p, successfully removed a new entry:%p, refcnt:%d, prev entry:%p has been removed by "
|
||||||
|
"others already",
|
||||||
|
pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data);
|
||||||
|
|
||||||
assert(p->pTNodeHeader == NULL);
|
assert(p->pTNodeHeader == NULL);
|
||||||
taosAddToTrashcan(pCacheObj, p);
|
taosAddToTrashcan(pCacheObj, p);
|
||||||
|
@ -468,35 +473,36 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uDebug("cache:%s, key:%p, %p has been removed from hash table by others already, refcnt:%d",
|
uDebug("cache:%s, key:%p, %p has been removed from hash table by others already, refcnt:%d", pCacheObj->name,
|
||||||
pCacheObj->name, pNode->key, pNode->data, ref);
|
pNode->key, pNode->data, ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// NOTE: once refcount is decrease, pNode may be freed by other thread immediately.
|
// NOTE: once refcount is decrease, pNode may be freed by other thread immediately.
|
||||||
char* key = pNode->key;
|
char *key = pNode->key;
|
||||||
char* p = pNode->data;
|
char *p = pNode->data;
|
||||||
|
|
||||||
// int32_t ref = T_REF_VAL_GET(pNode);
|
// int32_t ref = T_REF_VAL_GET(pNode);
|
||||||
//
|
//
|
||||||
// if (ref == 1 && inTrashcan) {
|
// if (ref == 1 && inTrashcan) {
|
||||||
// // If it is the last ref, remove it from trashcan linked-list first, and then destroy it.Otherwise, it may be
|
// // If it is the last ref, remove it from trashcan linked-list first, and then destroy it.Otherwise, it may
|
||||||
// // destroyed by refresh worker if decrease ref count before removing it from linked-list.
|
// be
|
||||||
// assert(pNode->pTNodeHeader->pData == pNode);
|
// // destroyed by refresh worker if decrease ref count before removing it from linked-list.
|
||||||
//
|
// assert(pNode->pTNodeHeader->pData == pNode);
|
||||||
// __cache_wr_lock(pCacheObj);
|
//
|
||||||
// doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader);
|
// __cache_wr_lock(pCacheObj);
|
||||||
// __cache_unlock(pCacheObj);
|
// doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader);
|
||||||
//
|
// __cache_unlock(pCacheObj);
|
||||||
// ref = T_REF_DEC(pNode);
|
//
|
||||||
// assert(ref == 0);
|
// ref = T_REF_DEC(pNode);
|
||||||
//
|
// assert(ref == 0);
|
||||||
// doDestroyTrashcanElem(pCacheObj, pNode->pTNodeHeader);
|
//
|
||||||
// } else {
|
// doDestroyTrashcanElem(pCacheObj, pNode->pTNodeHeader);
|
||||||
// ref = T_REF_DEC(pNode);
|
// } else {
|
||||||
// assert(ref >= 0);
|
// ref = T_REF_DEC(pNode);
|
||||||
// }
|
// assert(ref >= 0);
|
||||||
|
// }
|
||||||
|
|
||||||
int32_t ref = T_REF_DEC(pNode);
|
int32_t ref = T_REF_DEC(pNode);
|
||||||
uDebug("cache:%s, key:%p, %p released, refcnt:%d, data in trashcan:%d", pCacheObj->name, key, p, ref, inTrashcan);
|
uDebug("cache:%s, key:%p, %p released, refcnt:%d, data in trashcan:%d", pCacheObj->name, key, p, ref, inTrashcan);
|
||||||
|
@ -504,21 +510,21 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct SHashTravSupp {
|
typedef struct SHashTravSupp {
|
||||||
SCacheObj* pCacheObj;
|
SCacheObj *pCacheObj;
|
||||||
int64_t time;
|
int64_t time;
|
||||||
__cache_trav_fn_t fp;
|
__cache_trav_fn_t fp;
|
||||||
void* param1;
|
void *param1;
|
||||||
} SHashTravSupp;
|
} SHashTravSupp;
|
||||||
|
|
||||||
static bool travHashTableEmptyFn(void* param, void* data) {
|
static bool travHashTableEmptyFn(void *param, void *data) {
|
||||||
SHashTravSupp* ps = (SHashTravSupp*) param;
|
SHashTravSupp *ps = (SHashTravSupp *)param;
|
||||||
SCacheObj* pCacheObj= ps->pCacheObj;
|
SCacheObj *pCacheObj = ps->pCacheObj;
|
||||||
|
|
||||||
SCacheDataNode *pNode = *(SCacheDataNode **) data;
|
SCacheDataNode *pNode = *(SCacheDataNode **)data;
|
||||||
|
|
||||||
if (T_REF_VAL_GET(pNode) == 0) {
|
if (T_REF_VAL_GET(pNode) == 0) {
|
||||||
taosCacheReleaseNode(pCacheObj, pNode);
|
taosCacheReleaseNode(pCacheObj, pNode);
|
||||||
} else { // do add to trashcan
|
} else { // do add to trashcan
|
||||||
taosAddToTrashcan(pCacheObj, pNode);
|
taosAddToTrashcan(pCacheObj, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,7 +535,7 @@ static bool travHashTableEmptyFn(void* param, void* data) {
|
||||||
void taosCacheEmpty(SCacheObj *pCacheObj) {
|
void taosCacheEmpty(SCacheObj *pCacheObj) {
|
||||||
SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = NULL, .time = taosGetTimestampMs()};
|
SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = NULL, .time = taosGetTimestampMs()};
|
||||||
|
|
||||||
// taosHashCondTraverse(pCacheObj->pHashTable, travHashTableEmptyFn, &sup);
|
// taosHashCondTraverse(pCacheObj->pHashTable, travHashTableEmptyFn, &sup);
|
||||||
taosTrashcanEmpty(pCacheObj, false);
|
taosTrashcanEmpty(pCacheObj, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +548,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj) {
|
||||||
|
|
||||||
// wait for the refresh thread quit before destroying the cache object.
|
// wait for the refresh thread quit before destroying the cache object.
|
||||||
// But in the dll, the child thread will be killed before atexit takes effect.
|
// But in the dll, the child thread will be killed before atexit takes effect.
|
||||||
while(atomic_load_8(&pCacheObj->deleting) != 0) {
|
while (atomic_load_8(&pCacheObj->deleting) != 0) {
|
||||||
if (refreshWorkerNormalStopped) break;
|
if (refreshWorkerNormalStopped) break;
|
||||||
if (refreshWorkerUnexpectedStopped) return;
|
if (refreshWorkerUnexpectedStopped) return;
|
||||||
taosMsleep(50);
|
taosMsleep(50);
|
||||||
|
@ -568,11 +574,11 @@ SCacheDataNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *
|
||||||
|
|
||||||
memcpy(pNewNode->key, key, keyLen);
|
memcpy(pNewNode->key, key, keyLen);
|
||||||
|
|
||||||
pNewNode->addedTime = (uint64_t)taosGetTimestampMs();
|
pNewNode->addedTime = (uint64_t)taosGetTimestampMs();
|
||||||
pNewNode->lifespan = duration;
|
pNewNode->lifespan = duration;
|
||||||
pNewNode->expireTime = pNewNode->addedTime + pNewNode->lifespan;
|
pNewNode->expireTime = pNewNode->addedTime + pNewNode->lifespan;
|
||||||
pNewNode->signature = (uint64_t)pNewNode;
|
pNewNode->signature = (uint64_t)pNewNode;
|
||||||
pNewNode->size = (uint32_t)totalSize;
|
pNewNode->size = (uint32_t)totalSize;
|
||||||
|
|
||||||
return pNewNode;
|
return pNewNode;
|
||||||
}
|
}
|
||||||
|
@ -610,16 +616,17 @@ void taosTrashcanEmpty(SCacheObj *pCacheObj, bool force) {
|
||||||
if (pCacheObj->numOfElemsInTrash == 0) {
|
if (pCacheObj->numOfElemsInTrash == 0) {
|
||||||
if (pCacheObj->pTrash != NULL) {
|
if (pCacheObj->pTrash != NULL) {
|
||||||
pCacheObj->pTrash = NULL;
|
pCacheObj->pTrash = NULL;
|
||||||
uError("cache:%s, key:inconsistency data in cache, numOfElem in trashcan:%d", pCacheObj->name, pCacheObj->numOfElemsInTrash);
|
uError("cache:%s, key:inconsistency data in cache, numOfElem in trashcan:%d", pCacheObj->name,
|
||||||
|
pCacheObj->numOfElemsInTrash);
|
||||||
}
|
}
|
||||||
|
|
||||||
__cache_unlock(pCacheObj);
|
__cache_unlock(pCacheObj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* stat[] = {"false", "true"};
|
const char *stat[] = {"false", "true"};
|
||||||
uDebug("cache:%s start to cleanup trashcan, numOfElem in trashcan:%d, free:%s", pCacheObj->name,
|
uDebug("cache:%s start to cleanup trashcan, numOfElem in trashcan:%d, free:%s", pCacheObj->name,
|
||||||
pCacheObj->numOfElemsInTrash, (force? stat[1]:stat[0]));
|
pCacheObj->numOfElemsInTrash, (force ? stat[1] : stat[0]));
|
||||||
|
|
||||||
STrashElem *pElem = pCacheObj->pTrash;
|
STrashElem *pElem = pCacheObj->pTrash;
|
||||||
while (pElem) {
|
while (pElem) {
|
||||||
|
@ -627,8 +634,8 @@ void taosTrashcanEmpty(SCacheObj *pCacheObj, bool force) {
|
||||||
assert(pElem->next != pElem && pElem->prev != pElem);
|
assert(pElem->next != pElem && pElem->prev != pElem);
|
||||||
|
|
||||||
if (force || (T_REF_VAL_GET(pElem->pData) == 0)) {
|
if (force || (T_REF_VAL_GET(pElem->pData) == 0)) {
|
||||||
uDebug("cache:%s, key:%p, %p removed from trashcan. numOfElem in trashcan:%d", pCacheObj->name, pElem->pData->key, pElem->pData->data,
|
uDebug("cache:%s, key:%p, %p removed from trashcan. numOfElem in trashcan:%d", pCacheObj->name, pElem->pData->key,
|
||||||
pCacheObj->numOfElemsInTrash - 1);
|
pElem->pData->data, pCacheObj->numOfElemsInTrash - 1);
|
||||||
|
|
||||||
doRemoveElemInTrashcan(pCacheObj, pElem);
|
doRemoveElemInTrashcan(pCacheObj, pElem);
|
||||||
doDestroyTrashcanElem(pCacheObj, pElem);
|
doDestroyTrashcanElem(pCacheObj, pElem);
|
||||||
|
@ -642,8 +649,8 @@ void taosTrashcanEmpty(SCacheObj *pCacheObj, bool force) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void doCleanupDataCache(SCacheObj *pCacheObj) {
|
void doCleanupDataCache(SCacheObj *pCacheObj) {
|
||||||
// SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = NULL, .time = taosGetTimestampMs()};
|
// SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = NULL, .time = taosGetTimestampMs()};
|
||||||
// taosHashCondTraverse(pCacheObj->pHashTable, travHashTableEmptyFn, &sup);
|
// taosHashCondTraverse(pCacheObj->pHashTable, travHashTableEmptyFn, &sup);
|
||||||
|
|
||||||
// todo memory leak if there are object with refcount greater than 0 in hash table?
|
// todo memory leak if there are object with refcount greater than 0 in hash table?
|
||||||
taosHashCleanup(pCacheObj->pHashTable);
|
taosHashCleanup(pCacheObj->pHashTable);
|
||||||
|
@ -656,11 +663,11 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
|
||||||
free(pCacheObj);
|
free(pCacheObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool travHashTableFn(void* param, void* data) {
|
bool travHashTableFn(void *param, void *data) {
|
||||||
SHashTravSupp* ps = (SHashTravSupp*) param;
|
SHashTravSupp *ps = (SHashTravSupp *)param;
|
||||||
SCacheObj* pCacheObj= ps->pCacheObj;
|
SCacheObj *pCacheObj = ps->pCacheObj;
|
||||||
|
|
||||||
SCacheDataNode* pNode = *(SCacheDataNode **) data;
|
SCacheDataNode *pNode = *(SCacheDataNode **)data;
|
||||||
if ((int64_t)pNode->expireTime < ps->time && T_REF_VAL_GET(pNode) <= 0) {
|
if ((int64_t)pNode->expireTime < ps->time && T_REF_VAL_GET(pNode) <= 0) {
|
||||||
taosCacheReleaseNode(pCacheObj, pNode);
|
taosCacheReleaseNode(pCacheObj, pNode);
|
||||||
|
|
||||||
|
@ -676,30 +683,30 @@ bool travHashTableFn(void* param, void* data) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_trav_fn_t fp, void* param1) {
|
static void doCacheRefresh(SCacheObj *pCacheObj, int64_t time, __cache_trav_fn_t fp, void *param1) {
|
||||||
assert(pCacheObj != NULL);
|
assert(pCacheObj != NULL);
|
||||||
|
|
||||||
SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = fp, .time = time, .param1 = param1};
|
SHashTravSupp sup = {.pCacheObj = pCacheObj, .fp = fp, .time = time, .param1 = param1};
|
||||||
// taosHashCondTraverse(pCacheObj->pHashTable, travHashTableFn, &sup);
|
// taosHashCondTraverse(pCacheObj->pHashTable, travHashTableFn, &sup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosCacheRefreshWorkerUnexpectedStopped(void) {
|
void taosCacheRefreshWorkerUnexpectedStopped(void) {
|
||||||
if(!refreshWorkerNormalStopped) {
|
if (!refreshWorkerNormalStopped) {
|
||||||
refreshWorkerUnexpectedStopped=true;
|
refreshWorkerUnexpectedStopped = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* taosCacheTimedRefresh(void *handle) {
|
void *taosCacheTimedRefresh(void *handle) {
|
||||||
assert(pCacheArrayList != NULL);
|
assert(pCacheArrayList != NULL);
|
||||||
uDebug("cache refresh thread starts");
|
uDebug("cache refresh thread starts");
|
||||||
|
|
||||||
setThreadName("cacheRefresh");
|
setThreadName("cacheRefresh");
|
||||||
|
|
||||||
const int32_t SLEEP_DURATION = 500; //500 ms
|
const int32_t SLEEP_DURATION = 500; // 500 ms
|
||||||
int64_t count = 0;
|
int64_t count = 0;
|
||||||
atexit(taosCacheRefreshWorkerUnexpectedStopped);
|
atexit(taosCacheRefreshWorkerUnexpectedStopped);
|
||||||
|
|
||||||
while(1) {
|
while (1) {
|
||||||
taosMsleep(SLEEP_DURATION);
|
taosMsleep(SLEEP_DURATION);
|
||||||
if (stopRefreshWorker) {
|
if (stopRefreshWorker) {
|
||||||
goto _end;
|
goto _end;
|
||||||
|
@ -711,9 +718,9 @@ void* taosCacheTimedRefresh(void *handle) {
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
for(int32_t i = 0; i < size; ++i) {
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
pthread_mutex_lock(&guard);
|
pthread_mutex_lock(&guard);
|
||||||
SCacheObj* pCacheObj = taosArrayGetP(pCacheArrayList, i);
|
SCacheObj *pCacheObj = taosArrayGetP(pCacheArrayList, i);
|
||||||
|
|
||||||
if (pCacheObj == NULL) {
|
if (pCacheObj == NULL) {
|
||||||
uError("object is destroyed. ignore and try next");
|
uError("object is destroyed. ignore and try next");
|
||||||
|
@ -726,8 +733,8 @@ void* taosCacheTimedRefresh(void *handle) {
|
||||||
taosArrayRemove(pCacheArrayList, i);
|
taosArrayRemove(pCacheArrayList, i);
|
||||||
size = taosArrayGetSize(pCacheArrayList);
|
size = taosArrayGetSize(pCacheArrayList);
|
||||||
|
|
||||||
uDebug("%s is destroying, remove it from refresh list, remain cache obj:%"PRIzu, pCacheObj->name, size);
|
uDebug("%s is destroying, remove it from refresh list, remain cache obj:%" PRIzu, pCacheObj->name, size);
|
||||||
pCacheObj->deleting = 0; //reset the deleting flag to enable pCacheObj to continue releasing resources.
|
pCacheObj->deleting = 0; // reset the deleting flag to enable pCacheObj to continue releasing resources.
|
||||||
|
|
||||||
pthread_mutex_unlock(&guard);
|
pthread_mutex_unlock(&guard);
|
||||||
continue;
|
continue;
|
||||||
|
@ -757,18 +764,18 @@ void* taosCacheTimedRefresh(void *handle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
taosArrayDestroy(pCacheArrayList);
|
taosArrayDestroy(pCacheArrayList);
|
||||||
|
|
||||||
pCacheArrayList = NULL;
|
pCacheArrayList = NULL;
|
||||||
pthread_mutex_destroy(&guard);
|
pthread_mutex_destroy(&guard);
|
||||||
refreshWorkerNormalStopped=true;
|
refreshWorkerNormalStopped = true;
|
||||||
|
|
||||||
uDebug("cache refresh thread quits");
|
uDebug("cache refresh thread quits");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void* param1) {
|
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void *param1) {
|
||||||
if (pCacheObj == NULL) {
|
if (pCacheObj == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -777,6 +784,4 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void* param1)
|
||||||
doCacheRefresh(pCacheObj, now, fp, param1);
|
doCacheRefresh(pCacheObj, now, fp, param1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosStopCacheRefreshWorker(void) {
|
void taosStopCacheRefreshWorker(void) { stopRefreshWorker = true; }
|
||||||
stopRefreshWorker = true;
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue