more code refact
This commit is contained in:
parent
5a45dab080
commit
fcbaa6082b
|
@ -17,6 +17,7 @@
|
|||
#define _TD_OS_ENV_H_
|
||||
|
||||
#include "osSysinfo.h"
|
||||
#include "osTimezone.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef TDIGEST_H
|
||||
#define TDIGEST_H
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846264338327950288 /* pi */
|
||||
#endif
|
||||
|
|
|
@ -31,8 +31,7 @@ typedef struct TdDir {
|
|||
HANDLE hFind;
|
||||
} TdDir;
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
WRDE_NOSPACE = 1, /* Ran out of memory. */
|
||||
WRDE_BADCHAR, /* A metachar appears in the wrong place. */
|
||||
WRDE_BADVAL, /* Undefined var reference with WRDE_UNDEF. */
|
||||
|
@ -309,10 +308,12 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
|
|||
// printf("failed to expand path:%s since Out of memory\n", dirname);
|
||||
return -1;
|
||||
case WRDE_BADCHAR:
|
||||
// printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n", dirname);
|
||||
// printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n",
|
||||
// dirname);
|
||||
return -1;
|
||||
case WRDE_SYNTAX:
|
||||
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched quotes\n", dirname);
|
||||
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched
|
||||
// quotes\n", dirname);
|
||||
return -1;
|
||||
default:
|
||||
// printf("failed to expand path:%s since %s\n", dirname, strerror(errno));
|
||||
|
|
|
@ -75,8 +75,10 @@ void taosPrintBackTrace() {
|
|||
// SymSetOptions(SYMOPT_LOAD_LINES);
|
||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
||||
|
||||
if (SymFromAddr(process, address, &displacementSym, pSymbol) && SymGetLineFromAddr64(process, address, &displacementLine, &line)) {
|
||||
snprintf(buf_tmp,sizeof(buf_tmp),"BackTrace %08" PRId64 " %s:%d %s\n", taosGetSelfPthreadId(), line.FileName, line.LineNumber, pSymbol->Name);
|
||||
if (SymFromAddr(process, address, &displacementSym, pSymbol) &&
|
||||
SymGetLineFromAddr64(process, address, &displacementLine, &line)) {
|
||||
snprintf(buf_tmp, sizeof(buf_tmp), "BackTrace %08" PRId64 " %s:%d %s\n", taosGetSelfPthreadId(), line.FileName,
|
||||
line.LineNumber, pSymbol->Name);
|
||||
} else {
|
||||
snprintf(buf_tmp, sizeof(buf_tmp), "BackTrace error: %d\n", GetLastError());
|
||||
}
|
||||
|
@ -126,14 +128,13 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
|
|||
|
||||
#ifdef USE_ADDR2LINE
|
||||
|
||||
#include "osThread.h"
|
||||
#include "libdwarf.h"
|
||||
#include "dwarf.h"
|
||||
#include "libdwarf.h"
|
||||
#include "osThread.h"
|
||||
|
||||
#define DW_PR_DUu "llu"
|
||||
|
||||
typedef struct lookup_table
|
||||
{
|
||||
typedef struct lookup_table {
|
||||
Dwarf_Line *table;
|
||||
Dwarf_Line_Context *ctxts;
|
||||
int cnt;
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#ifdef WINDOWS
|
||||
#include "windows.h"
|
||||
#include "wincrypt.h"
|
||||
#include "windows.h"
|
||||
#else
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
|
||||
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
|
|
@ -214,7 +214,6 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool taosCheckSystemIsLittleEnd() {
|
||||
union check {
|
||||
int16_t i;
|
||||
|
@ -338,7 +337,8 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
|
|||
#ifdef WINDOWS
|
||||
char value[100];
|
||||
DWORD bufferSize = sizeof(value);
|
||||
RegGetValue(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
||||
RegGetValue(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString",
|
||||
RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
||||
tstrncpy(cpuModel, value, maxLen);
|
||||
SYSTEM_INFO si;
|
||||
memset(&si, 0, sizeof(SYSTEM_INFO));
|
||||
|
@ -776,8 +776,9 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
|
|||
#ifdef WINDOWS
|
||||
GUID guid;
|
||||
CoCreateGuid(&guid);
|
||||
snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
|
||||
guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
|
||||
snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6],
|
||||
guid.Data4[7]);
|
||||
|
||||
return 0;
|
||||
#elif defined(_TD_DARWIN_64)
|
||||
|
@ -971,14 +972,17 @@ SysNameInfo taosGetSysNameInfo() {
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool taosCheckCurrentInDll() {
|
||||
#ifdef WINDOWS
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
char path[PATH_MAX] = {0};
|
||||
GetModuleFileName(((VirtualQuery(taosCheckCurrentInDll,&mbi,sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL), path, PATH_MAX);
|
||||
GetModuleFileName(
|
||||
((VirtualQuery(taosCheckCurrentInDll, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL), path,
|
||||
PATH_MAX);
|
||||
int strLastIndex = strlen(path);
|
||||
if ((path[strLastIndex-3] == 'd' || path[strLastIndex-3] == 'D') && (path[strLastIndex-2] == 'l' || path[strLastIndex-2] == 'L') && (path[strLastIndex-1] == 'l' || path[strLastIndex-1] == 'L')) {
|
||||
if ((path[strLastIndex - 3] == 'd' || path[strLastIndex - 3] == 'D') &&
|
||||
(path[strLastIndex - 2] == 'l' || path[strLastIndex - 2] == 'L') &&
|
||||
(path[strLastIndex - 1] == 'l' || path[strLastIndex - 1] == 'L')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -21,9 +21,7 @@ int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*star
|
|||
return pthread_create(tid, attr, start, arg);
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrDestroy(TdThreadAttr * attr) {
|
||||
return pthread_attr_destroy(attr);
|
||||
}
|
||||
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { return pthread_attr_destroy(attr); }
|
||||
|
||||
int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachstate) {
|
||||
return pthread_attr_getdetachstate(attr, detachstate);
|
||||
|
@ -49,9 +47,7 @@ int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize
|
|||
return pthread_attr_getstacksize(attr, stacksize);
|
||||
}
|
||||
|
||||
int32_t taosThreadAttrInit(TdThreadAttr * attr) {
|
||||
return pthread_attr_init(attr);
|
||||
}
|
||||
int32_t taosThreadAttrInit(TdThreadAttr *attr) { return pthread_attr_init(attr); }
|
||||
|
||||
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) {
|
||||
return pthread_attr_setdetachstate(attr, detachstate);
|
||||
|
@ -77,117 +73,77 @@ int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) {
|
|||
return pthread_attr_setstacksize(attr, stacksize);
|
||||
}
|
||||
|
||||
int32_t taosThreadCancel(TdThread thread) {
|
||||
return pthread_cancel(thread);
|
||||
}
|
||||
int32_t taosThreadCancel(TdThread thread) { return pthread_cancel(thread); }
|
||||
|
||||
int32_t taosThreadCondDestroy(TdThreadCond * cond) {
|
||||
return pthread_cond_destroy(cond);
|
||||
}
|
||||
int32_t taosThreadCondDestroy(TdThreadCond *cond) { return pthread_cond_destroy(cond); }
|
||||
|
||||
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr) {
|
||||
return pthread_cond_init(cond, attr);
|
||||
}
|
||||
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { return pthread_cond_init(cond, attr); }
|
||||
|
||||
int32_t taosThreadCondSignal(TdThreadCond * cond) {
|
||||
return pthread_cond_signal(cond);
|
||||
}
|
||||
int32_t taosThreadCondSignal(TdThreadCond *cond) { return pthread_cond_signal(cond); }
|
||||
|
||||
int32_t taosThreadCondBroadcast(TdThreadCond * cond) {
|
||||
return pthread_cond_broadcast(cond);
|
||||
}
|
||||
int32_t taosThreadCondBroadcast(TdThreadCond *cond) { return pthread_cond_broadcast(cond); }
|
||||
|
||||
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex) {
|
||||
return pthread_cond_wait(cond, mutex);
|
||||
}
|
||||
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { return pthread_cond_wait(cond, mutex); }
|
||||
|
||||
int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const struct timespec *abstime) {
|
||||
return pthread_cond_timedwait(cond, mutex, abstime);
|
||||
}
|
||||
|
||||
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr) {
|
||||
return pthread_condattr_destroy(attr);
|
||||
}
|
||||
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) { return pthread_condattr_destroy(attr); }
|
||||
|
||||
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) {
|
||||
return pthread_condattr_getpshared(attr, pshared);
|
||||
}
|
||||
|
||||
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr) {
|
||||
return pthread_condattr_init(attr);
|
||||
}
|
||||
int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) { return pthread_condattr_init(attr); }
|
||||
|
||||
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
|
||||
return pthread_condattr_setpshared(attr, pshared);
|
||||
}
|
||||
|
||||
int32_t taosThreadDetach(TdThread thread) {
|
||||
return pthread_detach(thread);
|
||||
}
|
||||
int32_t taosThreadDetach(TdThread thread) { return pthread_detach(thread); }
|
||||
|
||||
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
|
||||
return pthread_equal(t1, t2);
|
||||
}
|
||||
int32_t taosThreadEqual(TdThread t1, TdThread t2) { return pthread_equal(t1, t2); }
|
||||
|
||||
void taosThreadExit(void *valuePtr) {
|
||||
return pthread_exit(valuePtr);
|
||||
}
|
||||
void taosThreadExit(void *valuePtr) { return pthread_exit(valuePtr); }
|
||||
|
||||
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
|
||||
return pthread_getschedparam(thread, policy, param);
|
||||
}
|
||||
|
||||
void *taosThreadGetSpecific(TdThreadKey key) {
|
||||
return pthread_getspecific(key);
|
||||
}
|
||||
void *taosThreadGetSpecific(TdThreadKey key) { return pthread_getspecific(key); }
|
||||
|
||||
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
|
||||
return pthread_join(thread, valuePtr);
|
||||
}
|
||||
int32_t taosThreadJoin(TdThread thread, void **valuePtr) { return pthread_join(thread, valuePtr); }
|
||||
|
||||
int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
|
||||
return pthread_key_create(key, destructor);
|
||||
}
|
||||
|
||||
int32_t taosThreadKeyDelete(TdThreadKey key) {
|
||||
return pthread_key_delete(key);
|
||||
}
|
||||
int32_t taosThreadKeyDelete(TdThreadKey key) { return pthread_key_delete(key); }
|
||||
|
||||
int32_t taosThreadKill(TdThread thread, int32_t sig) {
|
||||
return pthread_kill(thread, sig);
|
||||
}
|
||||
int32_t taosThreadKill(TdThread thread, int32_t sig) { return pthread_kill(thread, sig); }
|
||||
|
||||
// int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
|
||||
// return pthread_mutex_consistent(mutex);
|
||||
// }
|
||||
|
||||
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) {
|
||||
return pthread_mutex_destroy(mutex);
|
||||
}
|
||||
int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) { return pthread_mutex_destroy(mutex); }
|
||||
|
||||
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) {
|
||||
return pthread_mutex_init(mutex, attr);
|
||||
}
|
||||
|
||||
int32_t taosThreadMutexLock(TdThreadMutex * mutex) {
|
||||
return pthread_mutex_lock(mutex);
|
||||
}
|
||||
int32_t taosThreadMutexLock(TdThreadMutex *mutex) { return pthread_mutex_lock(mutex); }
|
||||
|
||||
// int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) {
|
||||
// return pthread_mutex_timedlock(mutex, abstime);
|
||||
// }
|
||||
|
||||
int32_t taosThreadMutexTryLock(TdThreadMutex * mutex) {
|
||||
return pthread_mutex_trylock(mutex);
|
||||
}
|
||||
int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) { return pthread_mutex_trylock(mutex); }
|
||||
|
||||
int32_t taosThreadMutexUnlock(TdThreadMutex * mutex) {
|
||||
return pthread_mutex_unlock(mutex);
|
||||
}
|
||||
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { return pthread_mutex_unlock(mutex); }
|
||||
|
||||
int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr) {
|
||||
return pthread_mutexattr_destroy(attr);
|
||||
}
|
||||
int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) { return pthread_mutexattr_destroy(attr); }
|
||||
|
||||
int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *pshared) {
|
||||
return pthread_mutexattr_getpshared(attr, pshared);
|
||||
|
@ -201,9 +157,7 @@ int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind
|
|||
return pthread_mutexattr_gettype(attr, kind);
|
||||
}
|
||||
|
||||
int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr) {
|
||||
return pthread_mutexattr_init(attr);
|
||||
}
|
||||
int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) { return pthread_mutexattr_init(attr); }
|
||||
|
||||
int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared) {
|
||||
return pthread_mutexattr_setpshared(attr, pshared);
|
||||
|
@ -221,17 +175,13 @@ int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)) {
|
|||
return pthread_once(onceControl, initRoutine);
|
||||
}
|
||||
|
||||
int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock) {
|
||||
return pthread_rwlock_destroy(rwlock);
|
||||
}
|
||||
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { return pthread_rwlock_destroy(rwlock); }
|
||||
|
||||
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) {
|
||||
return pthread_rwlock_init(rwlock, attr);
|
||||
}
|
||||
|
||||
int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
|
||||
return pthread_rwlock_rdlock(rwlock);
|
||||
}
|
||||
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { return pthread_rwlock_rdlock(rwlock); }
|
||||
|
||||
// int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
|
||||
// return pthread_rwlock_timedrdlock(rwlock, abstime);
|
||||
|
@ -241,57 +191,37 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
|
|||
// return pthread_rwlock_timedwrlock(rwlock, abstime);
|
||||
// }
|
||||
|
||||
int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock) {
|
||||
return pthread_rwlock_tryrdlock(rwlock);
|
||||
}
|
||||
int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) { return pthread_rwlock_tryrdlock(rwlock); }
|
||||
|
||||
int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock) {
|
||||
return pthread_rwlock_trywrlock(rwlock);
|
||||
}
|
||||
int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) { return pthread_rwlock_trywrlock(rwlock); }
|
||||
|
||||
int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock) {
|
||||
return pthread_rwlock_unlock(rwlock);
|
||||
}
|
||||
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { return pthread_rwlock_unlock(rwlock); }
|
||||
|
||||
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock) {
|
||||
return pthread_rwlock_wrlock(rwlock);
|
||||
}
|
||||
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { return pthread_rwlock_wrlock(rwlock); }
|
||||
|
||||
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr) {
|
||||
return pthread_rwlockattr_destroy(attr);
|
||||
}
|
||||
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) { return pthread_rwlockattr_destroy(attr); }
|
||||
|
||||
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) {
|
||||
return pthread_rwlockattr_getpshared(attr, pshared);
|
||||
}
|
||||
|
||||
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr) {
|
||||
return pthread_rwlockattr_init(attr);
|
||||
}
|
||||
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) { return pthread_rwlockattr_init(attr); }
|
||||
|
||||
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared) {
|
||||
return pthread_rwlockattr_setpshared(attr, pshared);
|
||||
}
|
||||
|
||||
TdThread taosThreadSelf(void) {
|
||||
return pthread_self();
|
||||
}
|
||||
TdThread taosThreadSelf(void) { return pthread_self(); }
|
||||
|
||||
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
|
||||
return pthread_setcancelstate(state, oldstate);
|
||||
}
|
||||
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { return pthread_setcancelstate(state, oldstate); }
|
||||
|
||||
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
|
||||
return pthread_setcanceltype(type, oldtype);
|
||||
}
|
||||
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { return pthread_setcanceltype(type, oldtype); }
|
||||
|
||||
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
|
||||
return pthread_setschedparam(thread, policy, param);
|
||||
}
|
||||
|
||||
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
|
||||
return pthread_setspecific(key, value);
|
||||
}
|
||||
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { return pthread_setspecific(key, value); }
|
||||
|
||||
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
|
||||
#ifdef TD_USE_SPINLOCK_AS_MUTEX
|
||||
|
@ -334,10 +264,6 @@ int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void taosThreadTestCancel(void) {
|
||||
return pthread_testcancel();
|
||||
}
|
||||
void taosThreadTestCancel(void) { return pthread_testcancel(); }
|
||||
|
||||
void taosThreadClear(TdThread *thread) {
|
||||
memset(thread, 0, sizeof(TdThread));
|
||||
}
|
||||
void taosThreadClear(TdThread *thread) { memset(thread, 0, sizeof(TdThread)); }
|
|
@ -167,7 +167,8 @@ int taosInitTimer(void (*callback)(int), int ms) {
|
|||
|
||||
r = taosThreadCreate(&timer_thread, NULL, timer_routine, NULL);
|
||||
if (r) {
|
||||
fprintf(stderr, "==%s[%d]%s()==failed to create timer thread\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__);
|
||||
fprintf(stderr, "==%s[%d]%s()==failed to create timer thread\n", taosDirEntryBaseName(__FILE__), __LINE__,
|
||||
__func__);
|
||||
// since no caller of this func checks the return value for the moment
|
||||
abort();
|
||||
}
|
||||
|
|
|
@ -740,7 +740,8 @@ char *tz_win[554][2]={{"Asia/Shanghai", "China Standard Time"},
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight, enum TdTimezone *tsTimezone) {
|
||||
void taosSetSystemTimezone(const char *inTimezoneStr, char *outTimezoneStr, int8_t *outDaylight,
|
||||
enum TdTimezone *tsTimezone) {
|
||||
if (inTimezoneStr == NULL || inTimezoneStr[0] == 0) return;
|
||||
|
||||
char *buf = taosMemoryMalloc(strlen(inTimezoneStr) + 1);
|
||||
|
@ -828,7 +829,8 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
char value[100];
|
||||
char keyPath[100];
|
||||
DWORD bufferSize = sizeof(value);
|
||||
RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", "TimeZoneKeyName", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
||||
RegGetValue(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation", "TimeZoneKeyName",
|
||||
RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
||||
strcpy(outTimezoneStr, "not configured");
|
||||
*tsTimezone = 0;
|
||||
if (bufferSize > 0) {
|
||||
|
@ -840,7 +842,8 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
RegGetValue(HKEY_LOCAL_MACHINE, keyPath, "Display", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
|
||||
if (bufferSize > 0) {
|
||||
// value[4] = (value[4] == '+' ? '-' : '+');
|
||||
sprintf(outTimezoneStr, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5], value[6], value[8], value[9]);
|
||||
sprintf(outTimezoneStr, "%s (UTC, %c%c%c%c%c)", outTimezoneStr, value[4], value[5], value[6], value[8],
|
||||
value[9]);
|
||||
*tsTimezone = taosStr2Int32(&value[4], NULL, 10);
|
||||
}
|
||||
break;
|
||||
|
@ -964,7 +967,8 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
|
|||
* Asia/Shanghai (CST, +0800)
|
||||
* Europe/London (BST, +0100)
|
||||
*/
|
||||
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
||||
snprintf(outTimezoneStr, TD_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-",
|
||||
abs(tz));
|
||||
} else {
|
||||
printf("There is not /etc/timezone.\n");
|
||||
}
|
||||
|
|
|
@ -85,8 +85,7 @@ int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf,
|
||||
uint32_t len) {
|
||||
int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
|
||||
uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len);
|
||||
uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len);
|
||||
const register uint64_t size = pBF->numBits;
|
||||
|
@ -145,6 +144,4 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
bool tBloomFilterIsFull(const SBloomFilter *pBF) {
|
||||
return pBF->size >= pBF->expectedEntries;
|
||||
}
|
||||
bool tBloomFilterIsFull(const SBloomFilter *pBF) { return pBF->size >= pBF->expectedEntries; }
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "tcache.h"
|
||||
#include "taoserror.h"
|
||||
#include "osThread.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
|
|
|
@ -392,7 +392,6 @@ int32_t compareInt16Uint64(const void *pLeft, const void *pRight) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t compareInt32Int8(const void *pLeft, const void *pRight) {
|
||||
int32_t left = GET_INT32_VAL(pLeft);
|
||||
int8_t right = GET_INT8_VAL(pRight);
|
||||
|
@ -997,10 +996,7 @@ int32_t compareUint64Uint32(const void *pLeft, const void *pRight) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t compareJsonValDesc(const void *pLeft, const void *pRight) {
|
||||
return compareJsonVal(pRight, pLeft);
|
||||
}
|
||||
int32_t compareJsonValDesc(const void *pLeft, const void *pRight) { return compareJsonVal(pRight, pLeft); }
|
||||
/*
|
||||
* Compare two strings
|
||||
* TSDB_MATCH: Match
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "tconfig.h"
|
||||
#include "cJSON.h"
|
||||
#include "taoserror.h"
|
||||
#include "tenv.h"
|
||||
#include "tgrant.h"
|
||||
#include "tjson.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
#include "tenv.h"
|
||||
#include "cJSON.h"
|
||||
#include "tjson.h"
|
||||
#include "tgrant.h"
|
||||
|
||||
#define CFG_NAME_PRINT_LEN 24
|
||||
#define CFG_SRC_PRINT_LEN 12
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -24,9 +24,9 @@
|
|||
* Copyright (c) 2016, Usman Masood <usmanm at fastmail dot fm>
|
||||
*/
|
||||
|
||||
#include "tdigest.h"
|
||||
#include "os.h"
|
||||
#include "osMath.h"
|
||||
#include "tdigest.h"
|
||||
|
||||
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
|
||||
//#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
|
||||
|
@ -65,25 +65,20 @@ TDigest *tdigestNewFrom(void* pBuf, int32_t compression) {
|
|||
static int32_t cmpCentroid(const void *a, const void *b) {
|
||||
SCentroid *c1 = (SCentroid *)a;
|
||||
SCentroid *c2 = (SCentroid *)b;
|
||||
if (c1->mean < c2->mean)
|
||||
return -1;
|
||||
if (c1->mean > c2->mean)
|
||||
return 1;
|
||||
if (c1->mean < c2->mean) return -1;
|
||||
if (c1->mean > c2->mean) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void mergeCentroid(SMergeArgs *args, SCentroid *merge) {
|
||||
double k2;
|
||||
SCentroid *c = &args->centroids[args->idx];
|
||||
|
||||
args->weight_so_far += merge->weight;
|
||||
k2 = INTEGRATED_LOCATION(args->t->size,
|
||||
args->weight_so_far / args->t->total_weight);
|
||||
k2 = INTEGRATED_LOCATION(args->t->size, args->weight_so_far / args->t->total_weight);
|
||||
// idx++
|
||||
if (k2 - args->k1 > 1 && c->weight > 0) {
|
||||
if(args->idx + 1 < args->t->size
|
||||
&& merge->mean != args->centroids[args->idx].mean) {
|
||||
if (args->idx + 1 < args->t->size && merge->mean != args->centroids[args->idx].mean) {
|
||||
args->idx++;
|
||||
}
|
||||
args->k1 = k2;
|
||||
|
@ -110,8 +105,7 @@ void tdigestCompress(TDigest *t) {
|
|||
int32_t i, j;
|
||||
SMergeArgs args;
|
||||
|
||||
if (t->num_buffered_pts <= 0)
|
||||
return;
|
||||
if (t->num_buffered_pts <= 0) return;
|
||||
|
||||
unmerged_centroids = (SCentroid *)taosMemoryMalloc(sizeof(SCentroid) * t->num_buffered_pts);
|
||||
for (i = 0; i < num_unmerged; i++) {
|
||||
|
@ -175,8 +169,7 @@ void tdigestCompress(TDigest *t) {
|
|||
}
|
||||
|
||||
void tdigestAdd(TDigest *t, double x, int64_t w) {
|
||||
if (w == 0)
|
||||
return;
|
||||
if (w == 0) return;
|
||||
|
||||
int32_t i = t->num_buffered_pts;
|
||||
if (i > 0 && t->buffered_pts[i - 1].value == x) {
|
||||
|
@ -187,14 +180,11 @@ void tdigestAdd(TDigest* t, double x, int64_t w) {
|
|||
t->num_buffered_pts++;
|
||||
}
|
||||
|
||||
|
||||
if (t->num_buffered_pts >= t->threshold)
|
||||
tdigestCompress(t);
|
||||
if (t->num_buffered_pts >= t->threshold) tdigestCompress(t);
|
||||
}
|
||||
|
||||
double tdigestCDF(TDigest *t, double x) {
|
||||
if (t == NULL)
|
||||
return 0;
|
||||
if (t == NULL) return 0;
|
||||
|
||||
int32_t i;
|
||||
double left, right;
|
||||
|
@ -202,15 +192,11 @@ double tdigestCDF(TDigest *t, double x) {
|
|||
SCentroid *a, *b, tmp;
|
||||
|
||||
tdigestCompress(t);
|
||||
if (t->num_centroids == 0)
|
||||
return NAN;
|
||||
if (x < t->min)
|
||||
return 0;
|
||||
if (x > t->max)
|
||||
return 1;
|
||||
if (t->num_centroids == 0) return NAN;
|
||||
if (x < t->min) return 0;
|
||||
if (x > t->max) return 1;
|
||||
if (t->num_centroids == 1) {
|
||||
if (FLOAT_EQ(t->max, t->min))
|
||||
return 0.5;
|
||||
if (FLOAT_EQ(t->max, t->min)) return 0.5;
|
||||
|
||||
return INTERPOLATE(x, t->min, t->max);
|
||||
}
|
||||
|
@ -230,10 +216,7 @@ double tdigestCDF(TDigest *t, double x) {
|
|||
right = (b->mean - a->mean) * a->weight / (a->weight + b->weight);
|
||||
|
||||
if (x < a->mean + right) {
|
||||
double cdf = (weight_so_far
|
||||
+ a->weight
|
||||
* INTERPOLATE(x, a->mean - left, a->mean + right))
|
||||
/ t->total_weight;
|
||||
double cdf = (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right)) / t->total_weight;
|
||||
return TMAX(cdf, 0.0);
|
||||
}
|
||||
|
||||
|
@ -245,16 +228,14 @@ double tdigestCDF(TDigest *t, double x) {
|
|||
right = t->max - a->mean;
|
||||
|
||||
if (x < a->mean + right) {
|
||||
return (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right))
|
||||
/ t->total_weight;
|
||||
return (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right)) / t->total_weight;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
double tdigestQuantile(TDigest *t, double q) {
|
||||
if (t == NULL)
|
||||
return 0;
|
||||
if (t == NULL) return 0;
|
||||
|
||||
int32_t i;
|
||||
double left, right, idx;
|
||||
|
@ -262,14 +243,10 @@ double tdigestQuantile(TDigest *t, double q) {
|
|||
SCentroid *a, *b, tmp;
|
||||
|
||||
tdigestCompress(t);
|
||||
if (t->num_centroids == 0)
|
||||
return NAN;
|
||||
if (t->num_centroids == 1)
|
||||
return t->centroids[0].mean;
|
||||
if (FLOAT_EQ(q, 0.0))
|
||||
return t->min;
|
||||
if (FLOAT_EQ(q, 1.0))
|
||||
return t->max;
|
||||
if (t->num_centroids == 0) return NAN;
|
||||
if (t->num_centroids == 1) return t->centroids[0].mean;
|
||||
if (FLOAT_EQ(q, 0.0)) return t->min;
|
||||
if (FLOAT_EQ(q, 1.0)) return t->max;
|
||||
|
||||
idx = q * t->total_weight;
|
||||
weight_so_far = 0;
|
||||
|
|
|
@ -890,5 +890,3 @@ void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
|||
void taosHashRelease(SHashObj *pHashObj, void *p) { taosHashCancelIterate(pHashObj, p); }
|
||||
|
||||
int64_t taosHashGetCompTimes(SHashObj *pHashObj) { return atomic_load_64(&pHashObj->compTimes); }
|
||||
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "thash.h"
|
||||
#include "tcompare.h"
|
||||
#include "thash.h"
|
||||
#include "types.h"
|
||||
|
||||
#define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r)))
|
||||
|
@ -29,7 +29,8 @@
|
|||
(h) *= 0x85ebca6b; \
|
||||
(h) ^= (h) >> 13; \
|
||||
(h) *= 0xc2b2ae35; \
|
||||
(h) ^= (h) >> 16; } while (0)
|
||||
(h) ^= (h) >> 16; \
|
||||
} while (0)
|
||||
|
||||
uint32_t MurmurHash3_32(const char *key, uint32_t len) {
|
||||
const uint8_t *data = (const uint8_t *)key;
|
||||
|
@ -98,13 +99,20 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) {
|
|||
}
|
||||
|
||||
switch (len & 7) {
|
||||
case 7: h ^= (uint64_t)data[6] << 48; /* fall-thru */
|
||||
case 6: h ^= (uint64_t)data[5] << 40; /* fall-thru */
|
||||
case 5: h ^= (uint64_t)data[4] << 32; /* fall-thru */
|
||||
case 4: h ^= (uint64_t)data[3] << 24; /* fall-thru */
|
||||
case 3: h ^= (uint64_t)data[2] << 16; /* fall-thru */
|
||||
case 2: h ^= (uint64_t)data[1] << 8; /* fall-thru */
|
||||
case 1: h ^= (uint64_t)data[0];
|
||||
case 7:
|
||||
h ^= (uint64_t)data[6] << 48; /* fall-thru */
|
||||
case 6:
|
||||
h ^= (uint64_t)data[5] << 40; /* fall-thru */
|
||||
case 5:
|
||||
h ^= (uint64_t)data[4] << 32; /* fall-thru */
|
||||
case 4:
|
||||
h ^= (uint64_t)data[3] << 24; /* fall-thru */
|
||||
case 3:
|
||||
h ^= (uint64_t)data[2] << 16; /* fall-thru */
|
||||
case 2:
|
||||
h ^= (uint64_t)data[1] << 8; /* fall-thru */
|
||||
case 1:
|
||||
h ^= (uint64_t)data[0];
|
||||
h *= m; /* fall-thru */
|
||||
};
|
||||
|
||||
|
@ -210,9 +218,15 @@ int32_t taosDoubleEqual(const void *a, const void *b, size_t UNUSED_PARAM(sz)) {
|
|||
_equal_fn_t taosGetDefaultEqualFunction(int32_t type) {
|
||||
_equal_fn_t fn = NULL;
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_FLOAT: fn = taosFloatEqual; break;
|
||||
case TSDB_DATA_TYPE_DOUBLE: fn = taosDoubleEqual; break;
|
||||
default: fn = memcmp; break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
fn = taosFloatEqual;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
fn = taosDoubleEqual;
|
||||
break;
|
||||
default:
|
||||
fn = memcmp;
|
||||
break;
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ struct SDiskbasedBuf {
|
|||
};
|
||||
|
||||
static int32_t createDiskFile(SDiskbasedBuf* pBuf) {
|
||||
pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
||||
pBuf->pFile =
|
||||
taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
||||
if (pBuf->pFile == NULL) {
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
@ -402,7 +403,8 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
|
|||
|
||||
// allocate buf
|
||||
if (availablePage == NULL) {
|
||||
pi->pData = taosMemoryCalloc(1, getAllocPageSize(pBuf->pageSize)); // add extract bytes in case of zipped buffer increased.
|
||||
pi->pData =
|
||||
taosMemoryCalloc(1, getAllocPageSize(pBuf->pageSize)); // add extract bytes in case of zipped buffer increased.
|
||||
} else {
|
||||
pi->pData = availablePage;
|
||||
}
|
||||
|
@ -438,7 +440,8 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
|
|||
#endif
|
||||
return (void*)(GET_DATA_PAYLOAD(*pi));
|
||||
} else { // not in memory
|
||||
assert((*pi)->pData == NULL && (*pi)->pn == NULL && (((*pi)->length >= 0 && (*pi)->offset >= 0) || ((*pi)->length == -1 && (*pi)->offset == -1)));
|
||||
assert((*pi)->pData == NULL && (*pi)->pn == NULL &&
|
||||
(((*pi)->length >= 0 && (*pi)->offset >= 0) || ((*pi)->length == -1 && (*pi)->offset == -1)));
|
||||
|
||||
char* availablePage = NULL;
|
||||
if (NO_IN_MEM_AVAILABLE_PAGES(pBuf)) {
|
||||
|
@ -520,12 +523,12 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) {
|
|||
{
|
||||
SDiskbasedBufStatis* ps = &pBuf->statis;
|
||||
if (ps->loadPages == 0) {
|
||||
uDebug(
|
||||
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages)",
|
||||
ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages);
|
||||
uDebug("Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages)", ps->getPages,
|
||||
ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages);
|
||||
} else {
|
||||
uDebug(
|
||||
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f Kb",
|
||||
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f "
|
||||
"Kb",
|
||||
ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f,
|
||||
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
|
||||
}
|
||||
|
@ -614,7 +617,8 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf) {
|
|||
|
||||
if (ps->loadPages > 0) {
|
||||
printf(
|
||||
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f Kb\n",
|
||||
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f "
|
||||
"Kb\n",
|
||||
ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f,
|
||||
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
|
||||
} else {
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
#define DEFAULT_GROWTH 2
|
||||
#define DEFAULT_TIGHTENING_RATIO 0.5
|
||||
|
||||
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries,
|
||||
double errorRate);
|
||||
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, double errorRate);
|
||||
|
||||
SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
|
||||
const uint32_t defaultSize = 8;
|
||||
|
@ -46,8 +45,7 @@ SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
|
|||
int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
|
||||
int32_t size = taosArrayGetSize(pSBf->bfArray);
|
||||
for (int32_t i = size - 2; i >= 0; --i) {
|
||||
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i),
|
||||
keyBuf, len) != TSDB_CODE_SUCCESS) {
|
||||
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), keyBuf, len) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +53,7 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
|
|||
SBloomFilter *pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1);
|
||||
ASSERT(pNormalBf);
|
||||
if (tBloomFilterIsFull(pNormalBf)) {
|
||||
pNormalBf = tScalableBfAddFilter(pSBf,
|
||||
pNormalBf->expectedEntries * pSBf->growth,
|
||||
pNormalBf = tScalableBfAddFilter(pSBf, pNormalBf->expectedEntries * pSBf->growth,
|
||||
pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO);
|
||||
if (pNormalBf == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -65,20 +62,17 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
|
|||
return tBloomFilterPut(pNormalBf, keyBuf, len);
|
||||
}
|
||||
|
||||
int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf,
|
||||
uint32_t len) {
|
||||
int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
|
||||
int32_t size = taosArrayGetSize(pSBf->bfArray);
|
||||
for (int32_t i = size - 1; i >= 0; --i) {
|
||||
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i),
|
||||
keyBuf, len) != TSDB_CODE_SUCCESS) {
|
||||
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), keyBuf, len) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries,
|
||||
double errorRate) {
|
||||
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, double errorRate) {
|
||||
SBloomFilter *pNormalBf = tBloomFilterInit(expectedEntries, errorRate);
|
||||
if (pNormalBf == NULL) {
|
||||
return NULL;
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "ttimer.h"
|
||||
#include "taoserror.h"
|
||||
#include "tdef.h"
|
||||
#include "tlog.h"
|
||||
#include "tsched.h"
|
||||
#include "tdef.h"
|
||||
|
||||
#define tmrFatal(...) \
|
||||
{ \
|
||||
|
|
|
@ -49,9 +49,7 @@ static void remove_batch_test() {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
TEST(arrayTest, array_list_test) {
|
||||
remove_batch_test();
|
||||
}
|
||||
TEST(arrayTest, array_list_test) { remove_batch_test(); }
|
||||
|
||||
TEST(arrayTest, array_search_test) {
|
||||
SArray* pa = (SArray*)taosArrayInit(4, sizeof(int32_t));
|
||||
|
@ -80,7 +78,6 @@ TEST(arrayTest, array_search_test) {
|
|||
} else {
|
||||
ASSERT_EQ(taosArrayGet(pa, idx), pRet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
taosArrayDestroy(pa);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tscalablebf.h"
|
||||
#include "taoserror.h"
|
||||
#include "tscalablebf.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -55,7 +55,6 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) {
|
|||
tBloomFilterDestroy(pBF2);
|
||||
tBloomFilterDestroy(pBF3);
|
||||
tBloomFilterDestroy(pBF4);
|
||||
|
||||
}
|
||||
|
||||
TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) {
|
||||
|
@ -116,7 +115,6 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) {
|
|||
GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF1, &ts, sizeof(int64_t)), TSDB_CODE_FAILED);
|
||||
}
|
||||
|
||||
|
||||
int64_t size = 10000;
|
||||
SScalableBf *pSBF4 = tScalableBfInit(size, 0.001);
|
||||
for (int64_t i = 0; i < 1000; i++) {
|
||||
|
@ -136,5 +134,4 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) {
|
|||
|
||||
tScalableBfDestroy(pSBF1);
|
||||
tScalableBfDestroy(pSBF4);
|
||||
|
||||
}
|
|
@ -3,9 +3,9 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "os.h"
|
||||
#include "taos.h"
|
||||
#include "taosdef.h"
|
||||
#include "thash.h"
|
||||
#include "taos.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -15,7 +15,8 @@ typedef struct TESTSTRUCT {
|
|||
|
||||
// the simple test code for basic operations
|
||||
void simpleTest() {
|
||||
SHashObj* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
SHashObj* hashTable =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
ASSERT_EQ(taosHashGetSize(hashTable), 0);
|
||||
|
||||
// put 400 elements in the hash table
|
||||
|
@ -52,7 +53,8 @@ void simpleTest() {
|
|||
}
|
||||
|
||||
void stringKeyTest() {
|
||||
auto* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
auto* hashTable =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
ASSERT_EQ(taosHashGetSize(hashTable), 0);
|
||||
|
||||
char key[128] = {0};
|
||||
|
@ -93,16 +95,15 @@ void stringKeyTest() {
|
|||
taosHashCleanup(hashTable);
|
||||
}
|
||||
|
||||
void functionTest() {
|
||||
|
||||
}
|
||||
void functionTest() {}
|
||||
|
||||
/**
|
||||
* evaluate the performance issue, by add 10million elements in to hash table in
|
||||
* a single threads situation
|
||||
*/
|
||||
void noLockPerformanceTest() {
|
||||
auto* hashTable = (SHashObj*) taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
auto* hashTable =
|
||||
(SHashObj*)taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
|
||||
ASSERT_EQ(taosHashGetSize(hashTable), 0);
|
||||
|
||||
char key[128] = {0};
|
||||
|
@ -131,7 +132,8 @@ void noLockPerformanceTest() {
|
|||
}
|
||||
|
||||
et = taosGetTimestampUs();
|
||||
printf("Elpased time:%" PRId64 " us to fetch all %d elements, avg cost:%lf us\n", et - st, num, (et - st)/(double) num);
|
||||
printf("Elpased time:%" PRId64 " us to fetch all %d elements, avg cost:%lf us\n", et - st, num,
|
||||
(et - st) / (double)num);
|
||||
|
||||
printf("The maximum length of overflow linklist in hash table is:%d\n", taosHashGetMaxOverflowLinkLength(hashTable));
|
||||
taosHashCleanup(hashTable);
|
||||
|
@ -142,12 +144,11 @@ void multithreadsTest() {
|
|||
}
|
||||
|
||||
// check the function robustness
|
||||
void invalidOperationTest() {
|
||||
|
||||
}
|
||||
void invalidOperationTest() {}
|
||||
|
||||
void acquireRleaseTest() {
|
||||
SHashObj* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
SHashObj* hashTable =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
ASSERT_EQ(taosHashGetSize(hashTable), 0);
|
||||
|
||||
int32_t key = 2;
|
||||
|
@ -198,13 +199,20 @@ void acquireRleaseTest() {
|
|||
}
|
||||
|
||||
void perfTest() {
|
||||
SHashObj* hash1h = (SHashObj*) taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash1s = (SHashObj*) taosHashInit(1000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash10s = (SHashObj*) taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash100s = (SHashObj*) taosHashInit(100000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash1m = (SHashObj*) taosHashInit(1000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash10m = (SHashObj*) taosHashInit(10000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash100m = (SHashObj*) taosHashInit(100000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash1h =
|
||||
(SHashObj*)taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash1s =
|
||||
(SHashObj*)taosHashInit(1000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash10s =
|
||||
(SHashObj*)taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash100s =
|
||||
(SHashObj*)taosHashInit(100000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash1m =
|
||||
(SHashObj*)taosHashInit(1000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash10m =
|
||||
(SHashObj*)taosHashInit(10000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
SHashObj* hash100m =
|
||||
(SHashObj*)taosHashInit(100000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
|
||||
char* name = (char*)taosMemoryCalloc(50000000, 9);
|
||||
for (int64_t i = 0; i < 50000000; ++i) {
|
||||
|
@ -295,7 +303,6 @@ void perfTest() {
|
|||
int64_t end100m = taosGetTimestampMs();
|
||||
int64_t end100mCt = taosHashGetCompTimes(hash100m);
|
||||
|
||||
|
||||
SArray* sArray[1000] = {0};
|
||||
for (int64_t i = 0; i < 1000; ++i) {
|
||||
sArray[i] = taosArrayInit(100000, 9);
|
||||
|
@ -391,8 +398,7 @@ void perfTest() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
|
|
@ -159,7 +159,6 @@ void recyclePageTest() {
|
|||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
TEST(testCase, resultBufferTest) {
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
simpleTest();
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#include "tref.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "os.h"
|
||||
#include "tref.h"
|
||||
#include "tlog.h"
|
||||
#include "tglobal.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -83,9 +82,7 @@ void *acquireRelease(void *param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void myfree(void *p) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
void myfree(void *p) { taosMemoryFree(p); }
|
||||
|
||||
void *openRefSpace(void *param) {
|
||||
SRefSpace *pSpace = (SRefSpace *)param;
|
||||
|
@ -189,4 +186,3 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ cd ${PRJ_ROOT_DIR}
|
|||
|
||||
FORMAT_DIR_LIST=(
|
||||
"include"
|
||||
# "source"
|
||||
"source/os"
|
||||
"source/util"
|
||||
)
|
||||
|
||||
for d in ${FORMAT_DIR_LIST[@]}; do
|
||||
|
|
Loading…
Reference in New Issue