提交 fcbaa608 编写于 作者: H Hongze Cheng

more code refact

上级 5a45dab0
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#define _TD_OS_ENV_H_ #define _TD_OS_ENV_H_
#include "osSysinfo.h" #include "osSysinfo.h"
#include "osTimezone.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#ifndef TDIGEST_H #ifndef TDIGEST_H
#define TDIGEST_H #define TDIGEST_H
#include "os.h"
#ifndef M_PI #ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288 /* pi */ #define M_PI 3.14159265358979323846264338327950288 /* pi */
#endif #endif
......
...@@ -31,14 +31,13 @@ typedef struct TdDir { ...@@ -31,14 +31,13 @@ typedef struct TdDir {
HANDLE hFind; HANDLE hFind;
} TdDir; } TdDir;
enum enum {
{
WRDE_NOSPACE = 1, /* Ran out of memory. */ WRDE_NOSPACE = 1, /* Ran out of memory. */
WRDE_BADCHAR, /* A metachar appears in the wrong place. */ WRDE_BADCHAR, /* A metachar appears in the wrong place. */
WRDE_BADVAL, /* Undefined var reference with WRDE_UNDEF. */ WRDE_BADVAL, /* Undefined var reference with WRDE_UNDEF. */
WRDE_CMDSUB, /* Command substitution with WRDE_NOCMD. */ WRDE_CMDSUB, /* Command substitution with WRDE_NOCMD. */
WRDE_SYNTAX /* Shell syntax error. */ WRDE_SYNTAX /* Shell syntax error. */
}; };
int wordexp(char *words, wordexp_t *pwordexp, int flags) { int wordexp(char *words, wordexp_t *pwordexp, int flags) {
pwordexp->we_offs = 0; pwordexp->we_offs = 0;
...@@ -301,18 +300,20 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { ...@@ -301,18 +300,20 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
wordexp_t full_path; wordexp_t full_path;
switch (wordexp (dirname, &full_path, 0)) { switch (wordexp(dirname, &full_path, 0)) {
case 0: case 0:
break; break;
case WRDE_NOSPACE: case WRDE_NOSPACE:
wordfree (&full_path); wordfree(&full_path);
// printf("failed to expand path:%s since Out of memory\n", dirname); // printf("failed to expand path:%s since Out of memory\n", dirname);
return -1; return -1;
case WRDE_BADCHAR: 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; return -1;
case WRDE_SYNTAX: 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; return -1;
default: default:
// printf("failed to expand path:%s since %s\n", dirname, strerror(errno)); // printf("failed to expand path:%s since %s\n", dirname, strerror(errno));
...@@ -417,7 +418,7 @@ TdDirPtr taosOpenDir(const char *dirname) { ...@@ -417,7 +418,7 @@ TdDirPtr taosOpenDir(const char *dirname) {
DIR *pDir = opendir(dirname); DIR *pDir = opendir(dirname);
if (pDir == NULL) return NULL; if (pDir == NULL) return NULL;
TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir)); TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir));
dirPtr->dirEntryPtr = (TdDirEntryPtr)&(dirPtr->dirEntry1); dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1);
dirPtr->pDir = pDir; dirPtr->pDir = pDir;
return dirPtr; return dirPtr;
#else #else
...@@ -435,7 +436,7 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) { ...@@ -435,7 +436,7 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
} }
return (TdDirEntryPtr) & (pDir->dirEntry.findFileData); return (TdDirEntryPtr) & (pDir->dirEntry.findFileData);
#elif defined(DARWIN) #elif defined(DARWIN)
if (readdir_r(pDir->pDir, (dirent*)&(pDir->dirEntry), (dirent**)&(pDir->dirEntryPtr)) == 0) { if (readdir_r(pDir->pDir, (dirent *)&(pDir->dirEntry), (dirent **)&(pDir->dirEntryPtr)) == 0) {
return pDir->dirEntryPtr; return pDir->dirEntryPtr;
} else { } else {
return NULL; return NULL;
......
...@@ -35,7 +35,7 @@ int64_t tsOpenMax = 0; ...@@ -35,7 +35,7 @@ int64_t tsOpenMax = 0;
int64_t tsStreamMax = 0; int64_t tsStreamMax = 0;
float tsNumOfCores = 0; float tsNumOfCores = 0;
int64_t tsTotalMemoryKB = 0; int64_t tsTotalMemoryKB = 0;
char* tsProcPath = NULL; char *tsProcPath = NULL;
void osDefaultInit() { void osDefaultInit() {
taosSeedRand(taosSafeRand()); taosSeedRand(taosSafeRand());
......
...@@ -58,7 +58,7 @@ typedef struct TdFile { ...@@ -58,7 +58,7 @@ typedef struct TdFile {
#define FILE_WITH_LOCK 1 #define FILE_WITH_LOCK 1
typedef struct AutoDelFile * AutoDelFilePtr; typedef struct AutoDelFile *AutoDelFilePtr;
typedef struct AutoDelFile { typedef struct AutoDelFile {
char *name; char *name;
AutoDelFilePtr lastAutoDelFilePtr; AutoDelFilePtr lastAutoDelFilePtr;
...@@ -706,11 +706,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in ...@@ -706,11 +706,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
int64_t sentbytes; int64_t sentbytes;
while (leftbytes > 0) { while (leftbytes > 0) {
#ifdef _TD_ARM_32 #ifdef _TD_ARM_32
sentbytes = sendfile(pFileOut->fd, pFileIn->fd, (long int*)offset, leftbytes); sentbytes = sendfile(pFileOut->fd, pFileIn->fd, (long int *)offset, leftbytes);
#else #else
sentbytes = sendfile(pFileOut->fd, pFileIn->fd, offset, leftbytes); sentbytes = sendfile(pFileOut->fd, pFileIn->fd, offset, leftbytes);
#endif #endif
if (sentbytes == -1) { if (sentbytes == -1) {
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
continue; continue;
......
...@@ -77,7 +77,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) { ...@@ -77,7 +77,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
// default locale or user specified locale is not valid, abort launch // default locale or user specified locale is not valid, abort launch
if (inLocale == NULL || strlen(inLocale) == 0) { if (inLocale == NULL || strlen(inLocale) == 0) {
//printf("Invalid locale:%s, please set the valid locale in config file\n", inLocale); // printf("Invalid locale:%s, please set the valid locale in config file\n", inLocale);
} }
if (!taosValidateEncodec(inCharSet)) { if (!taosValidateEncodec(inCharSet)) {
......
...@@ -52,7 +52,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) { ...@@ -52,7 +52,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
#pragma comment(lib, "dbghelp.lib") #pragma comment(lib, "dbghelp.lib")
void taosPrintBackTrace() { void taosPrintBackTrace() {
#define MAX_STACK_FRAMES 20 #define MAX_STACK_FRAMES 20
void *pStack[MAX_STACK_FRAMES]; void *pStack[MAX_STACK_FRAMES];
...@@ -72,15 +72,17 @@ void taosPrintBackTrace() { ...@@ -72,15 +72,17 @@ void taosPrintBackTrace() {
DWORD displacementLine = 0; DWORD displacementLine = 0;
IMAGEHLP_LINE64 line; IMAGEHLP_LINE64 line;
//SymSetOptions(SYMOPT_LOAD_LINES); // SymSetOptions(SYMOPT_LOAD_LINES);
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
if (SymFromAddr(process, address, &displacementSym, pSymbol) && SymGetLineFromAddr64(process, address, &displacementLine, &line)) { if (SymFromAddr(process, address, &displacementSym, pSymbol) &&
snprintf(buf_tmp,sizeof(buf_tmp),"BackTrace %08" PRId64 " %s:%d %s\n", taosGetSelfPthreadId(), line.FileName, line.LineNumber, pSymbol->Name); 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 { } else {
snprintf(buf_tmp,sizeof(buf_tmp),"BackTrace error: %d\n",GetLastError()); snprintf(buf_tmp, sizeof(buf_tmp), "BackTrace error: %d\n", GetLastError());
} }
write(1,buf_tmp,strlen(buf_tmp)); write(1, buf_tmp, strlen(buf_tmp));
} }
} }
#endif #endif
...@@ -126,14 +128,13 @@ int32_t taosBackTrace(void **buffer, int32_t size) { ...@@ -126,14 +128,13 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
#ifdef USE_ADDR2LINE #ifdef USE_ADDR2LINE
#include "osThread.h"
#include "libdwarf.h"
#include "dwarf.h" #include "dwarf.h"
#include "libdwarf.h"
#include "osThread.h"
#define DW_PR_DUu "llu" #define DW_PR_DUu "llu"
typedef struct lookup_table typedef struct lookup_table {
{
Dwarf_Line *table; Dwarf_Line *table;
Dwarf_Line_Context *ctxts; Dwarf_Line_Context *ctxts;
int cnt; int cnt;
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#ifdef WINDOWS #ifdef WINDOWS
#include "windows.h"
#include "wincrypt.h" #include "wincrypt.h"
#include "windows.h"
#else #else
#include <sys/file.h> #include <sys/file.h>
#include <unistd.h> #include <unistd.h>
...@@ -27,7 +27,7 @@ void taosSeedRand(uint32_t seed) { return srand(seed); } ...@@ -27,7 +27,7 @@ void taosSeedRand(uint32_t seed) { return srand(seed); }
uint32_t taosRand(void) { return rand(); } uint32_t taosRand(void) { return rand(); }
uint32_t taosRandR(uint32_t *pSeed) { uint32_t taosRandR(uint32_t* pSeed) {
#ifdef WINDOWS #ifdef WINDOWS
return rand_s(pSeed); return rand_s(pSeed);
#else #else
......
...@@ -47,7 +47,7 @@ void taosDflSignal(int32_t signum) { ...@@ -47,7 +47,7 @@ void taosDflSignal(int32_t signum) {
signal(signum, SIG_DFL); signal(signum, SIG_DFL);
} }
void taosKillChildOnParentStopped() { } void taosKillChildOnParentStopped() {}
#else #else
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) #if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#include <unistd.h> #include <unistd.h>
#endif #endif
......
...@@ -26,10 +26,10 @@ extern int wcswidth(const wchar_t *s, size_t n); ...@@ -26,10 +26,10 @@ extern int wcswidth(const wchar_t *s, size_t n);
#ifdef WINDOWS #ifdef WINDOWS
char *strsep(char **stringp, const char *delim) { char *strsep(char **stringp, const char *delim) {
char * s; char *s;
const char *spanp; const char *spanp;
int32_t c, sc; int32_t c, sc;
char * tok; char *tok;
if ((s = *stringp) == NULL) return (NULL); if ((s = *stringp) == NULL) return (NULL);
for (tok = s;;) { for (tok = s;;) {
c = *s++; c = *s++;
...@@ -50,7 +50,7 @@ char *strsep(char **stringp, const char *delim) { ...@@ -50,7 +50,7 @@ char *strsep(char **stringp, const char *delim) {
/* Duplicate a string, up to at most size characters */ /* Duplicate a string, up to at most size characters */
char *strndup(const char *s, int size) { char *strndup(const char *s, int size) {
size_t l; size_t l;
char * s2; char *s2;
l = strlen(s); l = strlen(s);
if (l > size) l = size; if (l > size) l = size;
s2 = malloc(l + 1); s2 = malloc(l + 1);
......
...@@ -214,7 +214,6 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { ...@@ -214,7 +214,6 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
return 0; return 0;
} }
bool taosCheckSystemIsLittleEnd() { bool taosCheckSystemIsLittleEnd() {
union check { union check {
int16_t i; int16_t i;
...@@ -338,10 +337,11 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { ...@@ -338,10 +337,11 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
#ifdef WINDOWS #ifdef WINDOWS
char value[100]; char value[100];
DWORD bufferSize = sizeof(value); 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); tstrncpy(cpuModel, value, maxLen);
SYSTEM_INFO si; SYSTEM_INFO si;
memset(&si,0,sizeof(SYSTEM_INFO)); memset(&si, 0, sizeof(SYSTEM_INFO));
GetSystemInfo(&si); GetSystemInfo(&si);
*numOfCores = si.dwNumberOfProcessors; *numOfCores = si.dwNumberOfProcessors;
return 0; return 0;
...@@ -776,8 +776,9 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { ...@@ -776,8 +776,9 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
#ifdef WINDOWS #ifdef WINDOWS
GUID guid; GUID guid;
CoCreateGuid(&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], snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3,
guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); 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; return 0;
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
...@@ -971,14 +972,17 @@ SysNameInfo taosGetSysNameInfo() { ...@@ -971,14 +972,17 @@ SysNameInfo taosGetSysNameInfo() {
#endif #endif
} }
bool taosCheckCurrentInDll() { bool taosCheckCurrentInDll() {
#ifdef WINDOWS #ifdef WINDOWS
MEMORY_BASIC_INFORMATION mbi; MEMORY_BASIC_INFORMATION mbi;
char path[PATH_MAX] = {0}; 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); 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 true;
} }
return false; return false;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "os.h" #include "os.h"
#if defined(WINDOWS) #if defined(WINDOWS)
typedef void (*MainWindows)(int argc,char** argv); typedef void (*MainWindows)(int argc, char** argv);
MainWindows mainWindowsFunc = NULL; MainWindows mainWindowsFunc = NULL;
SERVICE_STATUS ServiceStatus; SERVICE_STATUS ServiceStatus;
...@@ -31,14 +31,14 @@ void WINAPI windowsServiceCtrlHandle(DWORD request) { ...@@ -31,14 +31,14 @@ void WINAPI windowsServiceCtrlHandle(DWORD request) {
ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) { if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError(); DWORD nError = GetLastError();
printf("failed to send stopped status to windows service: %d",nError); printf("failed to send stopped status to windows service: %d", nError);
} }
break; break;
default: default:
return; return;
} }
} }
void WINAPI mainWindowsService(int argc,char** argv) { void WINAPI mainWindowsService(int argc, char** argv) {
int ret = 0; int ret = 0;
ServiceStatus.dwServiceType = SERVICE_WIN32; ServiceStatus.dwServiceType = SERVICE_WIN32;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
...@@ -50,19 +50,19 @@ void WINAPI mainWindowsService(int argc,char** argv) { ...@@ -50,19 +50,19 @@ void WINAPI mainWindowsService(int argc,char** argv) {
hServiceStatusHandle = RegisterServiceCtrlHandler("taosd", &windowsServiceCtrlHandle); hServiceStatusHandle = RegisterServiceCtrlHandler("taosd", &windowsServiceCtrlHandle);
if (hServiceStatusHandle == 0) { if (hServiceStatusHandle == 0) {
DWORD nError = GetLastError(); DWORD nError = GetLastError();
printf("failed to register windows service ctrl handler: %d",nError); printf("failed to register windows service ctrl handler: %d", nError);
} }
ServiceStatus.dwCurrentState = SERVICE_RUNNING; ServiceStatus.dwCurrentState = SERVICE_RUNNING;
if (SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) { if (SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError(); DWORD nError = GetLastError();
printf("failed to send running status to windows service: %d",nError); printf("failed to send running status to windows service: %d", nError);
} }
if (mainWindowsFunc != NULL) mainWindowsFunc(argc, argv); if (mainWindowsFunc != NULL) mainWindowsFunc(argc, argv);
ServiceStatus.dwCurrentState = SERVICE_STOPPED; ServiceStatus.dwCurrentState = SERVICE_STOPPED;
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) { if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError(); DWORD nError = GetLastError();
printf("failed to send stopped status to windows service: %d",nError); printf("failed to send stopped status to windows service: %d", nError);
} }
} }
void stratWindowsService(MainWindows mainWindows) { void stratWindowsService(MainWindows mainWindows) {
...@@ -248,7 +248,7 @@ TdCmdPtr taosOpenCmd(const char* cmd) { ...@@ -248,7 +248,7 @@ TdCmdPtr taosOpenCmd(const char* cmd) {
#endif #endif
} }
int64_t taosGetsCmd(TdCmdPtr pCmd, int32_t maxSize, char *__restrict buf) { int64_t taosGetsCmd(TdCmdPtr pCmd, int32_t maxSize, char* __restrict buf) {
if (pCmd == NULL || buf == NULL) { if (pCmd == NULL || buf == NULL) {
return -1; return -1;
} }
......
...@@ -17,179 +17,135 @@ ...@@ -17,179 +17,135 @@
#include <pthread.h> #include <pthread.h>
#include "os.h" #include "os.h"
int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg) { int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)(void *), void *arg) {
return pthread_create(tid, attr, start, arg); return pthread_create(tid, attr, start, arg);
} }
int32_t taosThreadAttrDestroy(TdThreadAttr * attr) { int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { return pthread_attr_destroy(attr); }
return pthread_attr_destroy(attr);
}
int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate) { int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachstate) {
return pthread_attr_getdetachstate(attr, detachstate); return pthread_attr_getdetachstate(attr, detachstate);
} }
int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched) { int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inheritsched) {
return pthread_attr_getinheritsched(attr, inheritsched); return pthread_attr_getinheritsched(attr, inheritsched);
} }
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param) { int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param *param) {
return pthread_attr_getschedparam(attr, param); return pthread_attr_getschedparam(attr, param);
} }
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy) { int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy) {
return pthread_attr_getschedpolicy(attr, policy); return pthread_attr_getschedpolicy(attr, policy);
} }
int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope) { int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscope) {
return pthread_attr_getscope(attr, contentionscope); return pthread_attr_getscope(attr, contentionscope);
} }
int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize) { int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) {
return pthread_attr_getstacksize(attr, stacksize); return pthread_attr_getstacksize(attr, stacksize);
} }
int32_t taosThreadAttrInit(TdThreadAttr * attr) { int32_t taosThreadAttrInit(TdThreadAttr *attr) { return pthread_attr_init(attr); }
return pthread_attr_init(attr);
}
int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate) { int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) {
return pthread_attr_setdetachstate(attr, detachstate); return pthread_attr_setdetachstate(attr, detachstate);
} }
int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched) { int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched) {
return pthread_attr_setinheritsched(attr, inheritsched); return pthread_attr_setinheritsched(attr, inheritsched);
} }
int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param) { int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param *param) {
return pthread_attr_setschedparam(attr, param); return pthread_attr_setschedparam(attr, param);
} }
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy) { int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) {
return pthread_attr_setschedpolicy(attr, policy); return pthread_attr_setschedpolicy(attr, policy);
} }
int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope) { int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) {
return pthread_attr_setscope(attr, contentionscope); return pthread_attr_setscope(attr, contentionscope);
} }
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) { int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
return pthread_attr_setstacksize(attr, stacksize); return pthread_attr_setstacksize(attr, stacksize);
} }
int32_t taosThreadCancel(TdThread thread) { int32_t taosThreadCancel(TdThread thread) { return pthread_cancel(thread); }
return pthread_cancel(thread);
}
int32_t taosThreadCondDestroy(TdThreadCond * cond) { int32_t taosThreadCondDestroy(TdThreadCond *cond) { return pthread_cond_destroy(cond); }
return pthread_cond_destroy(cond);
}
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr) { int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { return pthread_cond_init(cond, attr); }
return pthread_cond_init(cond, attr);
}
int32_t taosThreadCondSignal(TdThreadCond * cond) { int32_t taosThreadCondSignal(TdThreadCond *cond) { return pthread_cond_signal(cond); }
return pthread_cond_signal(cond);
}
int32_t taosThreadCondBroadcast(TdThreadCond * cond) { int32_t taosThreadCondBroadcast(TdThreadCond *cond) { return pthread_cond_broadcast(cond); }
return pthread_cond_broadcast(cond);
}
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex) { int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { return pthread_cond_wait(cond, mutex); }
return pthread_cond_wait(cond, mutex);
}
int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime) { int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const struct timespec *abstime) {
return pthread_cond_timedwait(cond, mutex, abstime); return pthread_cond_timedwait(cond, mutex, abstime);
} }
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr) { int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) { return pthread_condattr_destroy(attr); }
return pthread_condattr_destroy(attr);
}
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared) { int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) {
return pthread_condattr_getpshared(attr, pshared); return pthread_condattr_getpshared(attr, pshared);
} }
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr) { int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) { return pthread_condattr_init(attr); }
return pthread_condattr_init(attr);
}
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared) { int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
return pthread_condattr_setpshared(attr, pshared); return pthread_condattr_setpshared(attr, pshared);
} }
int32_t taosThreadDetach(TdThread thread) { int32_t taosThreadDetach(TdThread thread) { return pthread_detach(thread); }
return pthread_detach(thread);
}
int32_t taosThreadEqual(TdThread t1, TdThread t2) { int32_t taosThreadEqual(TdThread t1, TdThread t2) { return pthread_equal(t1, t2); }
return pthread_equal(t1, t2);
}
void taosThreadExit(void *valuePtr) { void taosThreadExit(void *valuePtr) { return pthread_exit(valuePtr); }
return pthread_exit(valuePtr);
}
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) { int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
return pthread_getschedparam(thread, policy, param); return pthread_getschedparam(thread, policy, param);
} }
void *taosThreadGetSpecific(TdThreadKey key) { void *taosThreadGetSpecific(TdThreadKey key) { return pthread_getspecific(key); }
return pthread_getspecific(key);
}
int32_t taosThreadJoin(TdThread thread, void **valuePtr) { int32_t taosThreadJoin(TdThread thread, void **valuePtr) { return pthread_join(thread, valuePtr); }
return pthread_join(thread, valuePtr);
}
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *)) { int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
return pthread_key_create(key, destructor); return pthread_key_create(key, destructor);
} }
int32_t taosThreadKeyDelete(TdThreadKey key) { int32_t taosThreadKeyDelete(TdThreadKey key) { return pthread_key_delete(key); }
return pthread_key_delete(key);
}
int32_t taosThreadKill(TdThread thread, int32_t sig) { int32_t taosThreadKill(TdThread thread, int32_t sig) { return pthread_kill(thread, sig); }
return pthread_kill(thread, sig);
}
// int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) { // int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
// return pthread_mutex_consistent(mutex); // return pthread_mutex_consistent(mutex);
// } // }
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) { int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) { return pthread_mutex_destroy(mutex); }
return pthread_mutex_destroy(mutex);
}
int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr) { int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) {
return pthread_mutex_init(mutex, attr); return pthread_mutex_init(mutex, attr);
} }
int32_t taosThreadMutexLock(TdThreadMutex * mutex) { int32_t taosThreadMutexLock(TdThreadMutex *mutex) { return pthread_mutex_lock(mutex); }
return pthread_mutex_lock(mutex);
}
// int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) { // int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) {
// return pthread_mutex_timedlock(mutex, abstime); // return pthread_mutex_timedlock(mutex, abstime);
// } // }
int32_t taosThreadMutexTryLock(TdThreadMutex * mutex) { int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) { return pthread_mutex_trylock(mutex); }
return pthread_mutex_trylock(mutex);
}
int32_t taosThreadMutexUnlock(TdThreadMutex * mutex) { int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { return pthread_mutex_unlock(mutex); }
return pthread_mutex_unlock(mutex);
}
int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr) { int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) { return pthread_mutexattr_destroy(attr); }
return pthread_mutexattr_destroy(attr);
}
int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared) { int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *pshared) {
return pthread_mutexattr_getpshared(attr, pshared); return pthread_mutexattr_getpshared(attr, pshared);
} }
...@@ -197,15 +153,13 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *p ...@@ -197,15 +153,13 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *p
// return pthread_mutexattr_getrobust(attr, robust); // return pthread_mutexattr_getrobust(attr, robust);
// } // }
int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind) { int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind) {
return pthread_mutexattr_gettype(attr, kind); return pthread_mutexattr_gettype(attr, kind);
} }
int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr) { int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) { return pthread_mutexattr_init(attr); }
return pthread_mutexattr_init(attr);
}
int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared) { int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared) {
return pthread_mutexattr_setpshared(attr, pshared); return pthread_mutexattr_setpshared(attr, pshared);
} }
...@@ -213,25 +167,21 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared) ...@@ -213,25 +167,21 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared)
// return pthread_mutexattr_setrobust(attr, robust); // return pthread_mutexattr_setrobust(attr, robust);
// } // }
int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind) { int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) {
return pthread_mutexattr_settype(attr, kind); return pthread_mutexattr_settype(attr, kind);
} }
int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)) { int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
return pthread_once(onceControl, initRoutine); return pthread_once(onceControl, initRoutine);
} }
int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock) { int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { return pthread_rwlock_destroy(rwlock); }
return pthread_rwlock_destroy(rwlock);
}
int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr) { int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) {
return pthread_rwlock_init(rwlock, attr); return pthread_rwlock_init(rwlock, attr);
} }
int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) { int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { return pthread_rwlock_rdlock(rwlock); }
return pthread_rwlock_rdlock(rwlock);
}
// int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) { // int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
// return pthread_rwlock_timedrdlock(rwlock, abstime); // return pthread_rwlock_timedrdlock(rwlock, abstime);
...@@ -241,103 +191,79 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) { ...@@ -241,103 +191,79 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
// return pthread_rwlock_timedwrlock(rwlock, abstime); // return pthread_rwlock_timedwrlock(rwlock, abstime);
// } // }
int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock) { int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) { return pthread_rwlock_tryrdlock(rwlock); }
return pthread_rwlock_tryrdlock(rwlock);
}
int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock) { int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) { return pthread_rwlock_trywrlock(rwlock); }
return pthread_rwlock_trywrlock(rwlock);
}
int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock) { int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { return pthread_rwlock_unlock(rwlock); }
return pthread_rwlock_unlock(rwlock);
}
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock) { int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { return pthread_rwlock_wrlock(rwlock); }
return pthread_rwlock_wrlock(rwlock);
}
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr) { int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) { return pthread_rwlockattr_destroy(attr); }
return pthread_rwlockattr_destroy(attr);
}
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared) { int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) {
return pthread_rwlockattr_getpshared(attr, pshared); return pthread_rwlockattr_getpshared(attr, pshared);
} }
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr) { int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) { return pthread_rwlockattr_init(attr); }
return pthread_rwlockattr_init(attr);
}
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared) { int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared) {
return pthread_rwlockattr_setpshared(attr, pshared); return pthread_rwlockattr_setpshared(attr, pshared);
} }
TdThread taosThreadSelf(void) { TdThread taosThreadSelf(void) { return pthread_self(); }
return pthread_self();
}
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { return pthread_setcancelstate(state, oldstate); }
return pthread_setcancelstate(state, oldstate);
}
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { return pthread_setcanceltype(type, oldtype); }
return pthread_setcanceltype(type, oldtype);
}
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) { int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
return pthread_setschedparam(thread, policy, param); return pthread_setschedparam(thread, policy, param);
} }
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { return pthread_setspecific(key, value); }
return pthread_setspecific(key, value);
}
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) { int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_destroy((pthread_mutex_t*)lock); return pthread_mutex_destroy((pthread_mutex_t *)lock);
#else #else
return pthread_spin_destroy((pthread_spinlock_t*)lock); return pthread_spin_destroy((pthread_spinlock_t *)lock);
#endif #endif
} }
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) { int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX #ifdef TD_USE_SPINLOCK_AS_MUTEX
assert(pshared == 0); assert(pshared == 0);
return pthread_mutex_init((pthread_mutex_t*)lock, NULL); return pthread_mutex_init((pthread_mutex_t *)lock, NULL);
#else #else
return pthread_spin_init((pthread_spinlock_t*)lock, pshared); return pthread_spin_init((pthread_spinlock_t *)lock, pshared);
#endif #endif
} }
int32_t taosThreadSpinLock(TdThreadSpinlock * lock) { int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_lock((pthread_mutex_t*)lock); return pthread_mutex_lock((pthread_mutex_t *)lock);
#else #else
return pthread_spin_lock((pthread_spinlock_t*)lock); return pthread_spin_lock((pthread_spinlock_t *)lock);
#endif #endif
} }
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) { int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_trylock((pthread_mutex_t*)lock); return pthread_mutex_trylock((pthread_mutex_t *)lock);
#else #else
return pthread_spin_trylock((pthread_spinlock_t*)lock); return pthread_spin_trylock((pthread_spinlock_t *)lock);
#endif #endif
} }
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) { int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX #ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_unlock((pthread_mutex_t*)lock); return pthread_mutex_unlock((pthread_mutex_t *)lock);
#else #else
return pthread_spin_unlock((pthread_spinlock_t*)lock); return pthread_spin_unlock((pthread_spinlock_t *)lock);
#endif #endif
} }
void taosThreadTestCancel(void) { void taosThreadTestCancel(void) { return pthread_testcancel(); }
return pthread_testcancel();
}
void taosThreadClear(TdThread *thread) { void taosThreadClear(TdThread *thread) { memset(thread, 0, sizeof(TdThread)); }
memset(thread, 0, sizeof(TdThread)); \ No newline at end of file
}
\ No newline at end of file
...@@ -86,7 +86,7 @@ static void taosDeleteTimer(void *tharg) { ...@@ -86,7 +86,7 @@ static void taosDeleteTimer(void *tharg) {
static TdThread timerThread; static TdThread timerThread;
static timer_t timerId; static timer_t timerId;
static volatile bool stopTimer = false; static volatile bool stopTimer = false;
static void * taosProcessAlarmSignal(void *tharg) { static void *taosProcessAlarmSignal(void *tharg) {
// Block the signal // Block the signal
sigset_t sigset; sigset_t sigset;
sigemptyset(&sigset); sigemptyset(&sigset);
...@@ -167,7 +167,8 @@ int taosInitTimer(void (*callback)(int), int ms) { ...@@ -167,7 +167,8 @@ int taosInitTimer(void (*callback)(int), int ms) {
r = taosThreadCreate(&timer_thread, NULL, timer_routine, NULL); r = taosThreadCreate(&timer_thread, NULL, timer_routine, NULL);
if (r) { 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 // since no caller of this func checks the return value for the moment
abort(); abort();
} }
......
此差异已折叠。
...@@ -175,11 +175,11 @@ void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size ...@@ -175,11 +175,11 @@ void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size
c = compar(key, p); c = compar(key, p);
if (c == 0) { if (c == 0) {
if (flags == TD_GT){ if (flags == TD_GT) {
lidx = midx + 1; lidx = midx + 1;
} else if(flags == TD_LT){ } else if (flags == TD_LT) {
ridx = midx - 1; ridx = midx - 1;
}else{ } else {
break; break;
} }
} else if (c < 0) { } else if (c < 0) {
......
...@@ -51,12 +51,12 @@ SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate) { ...@@ -51,12 +51,12 @@ SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate) {
// ln(2)^2 = 0.480453013918201 // ln(2)^2 = 0.480453013918201
// m = - n * ln(P) / ( ln(2) )^2 // m = - n * ln(P) / ( ln(2) )^2
// m is the size of bloom filter, n is expected entries, P is false positive probability // m is the size of bloom filter, n is expected entries, P is false positive probability
pBF->numUnits = (uint64_t) ceil(expectedEntries * lnRate / 0.480453013918201 / UNIT_NUM_BITS); pBF->numUnits = (uint64_t)ceil(expectedEntries * lnRate / 0.480453013918201 / UNIT_NUM_BITS);
pBF->numBits = pBF->numUnits * 64; pBF->numBits = pBF->numUnits * 64;
pBF->size = 0; pBF->size = 0;
// ln(2) = 0.693147180559945 // ln(2) = 0.693147180559945
pBF->hashFunctions = (uint32_t) ceil(lnRate / 0.693147180559945); pBF->hashFunctions = (uint32_t)ceil(lnRate / 0.693147180559945);
pBF->hashFn1 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP); pBF->hashFn1 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP);
pBF->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR); pBF->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR);
pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t)); pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t));
...@@ -85,8 +85,7 @@ int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len) { ...@@ -85,8 +85,7 @@ int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf, int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
uint32_t len) {
uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len); uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len);
uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len); uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len);
const register uint64_t size = pBF->numBits; const register uint64_t size = pBF->numBits;
...@@ -108,21 +107,21 @@ void tBloomFilterDestroy(SBloomFilter *pBF) { ...@@ -108,21 +107,21 @@ void tBloomFilterDestroy(SBloomFilter *pBF) {
taosMemoryFree(pBF); taosMemoryFree(pBF);
} }
int32_t tBloomFilterEncode(const SBloomFilter *pBF, SEncoder* pEncoder) { int32_t tBloomFilterEncode(const SBloomFilter *pBF, SEncoder *pEncoder) {
if (tEncodeU32(pEncoder, pBF->hashFunctions) < 0) return -1; if (tEncodeU32(pEncoder, pBF->hashFunctions) < 0) return -1;
if (tEncodeU64(pEncoder, pBF->expectedEntries) < 0) return -1; if (tEncodeU64(pEncoder, pBF->expectedEntries) < 0) return -1;
if (tEncodeU64(pEncoder, pBF->numUnits) < 0) return -1; if (tEncodeU64(pEncoder, pBF->numUnits) < 0) return -1;
if (tEncodeU64(pEncoder, pBF->numBits) < 0) return -1; if (tEncodeU64(pEncoder, pBF->numBits) < 0) return -1;
if (tEncodeU64(pEncoder, pBF->size) < 0) return -1; if (tEncodeU64(pEncoder, pBF->size) < 0) return -1;
for (uint64_t i = 0; i < pBF->numUnits; i++) { for (uint64_t i = 0; i < pBF->numUnits; i++) {
uint64_t* pUnits = (uint64_t*)pBF->buffer; uint64_t *pUnits = (uint64_t *)pBF->buffer;
if (tEncodeU64(pEncoder, pUnits[i]) < 0) return -1; if (tEncodeU64(pEncoder, pUnits[i]) < 0) return -1;
} }
if (tEncodeDouble(pEncoder, pBF->errorRate) < 0) return -1; if (tEncodeDouble(pEncoder, pBF->errorRate) < 0) return -1;
return 0; return 0;
} }
SBloomFilter* tBloomFilterDecode(SDecoder* pDecoder) { SBloomFilter *tBloomFilterDecode(SDecoder *pDecoder) {
SBloomFilter *pBF = taosMemoryCalloc(1, sizeof(SBloomFilter)); SBloomFilter *pBF = taosMemoryCalloc(1, sizeof(SBloomFilter));
pBF->buffer = NULL; pBF->buffer = NULL;
if (tDecodeU32(pDecoder, &pBF->hashFunctions) < 0) goto _error; if (tDecodeU32(pDecoder, &pBF->hashFunctions) < 0) goto _error;
...@@ -132,7 +131,7 @@ SBloomFilter* tBloomFilterDecode(SDecoder* pDecoder) { ...@@ -132,7 +131,7 @@ SBloomFilter* tBloomFilterDecode(SDecoder* pDecoder) {
if (tDecodeU64(pDecoder, &pBF->size) < 0) goto _error; if (tDecodeU64(pDecoder, &pBF->size) < 0) goto _error;
pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t)); pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t));
for (int32_t i = 0; i < pBF->numUnits; i++) { for (int32_t i = 0; i < pBF->numUnits; i++) {
uint64_t* pUnits = (uint64_t*)pBF->buffer; uint64_t *pUnits = (uint64_t *)pBF->buffer;
if (tDecodeU64(pDecoder, pUnits + i) < 0) goto _error; if (tDecodeU64(pDecoder, pUnits + i) < 0) goto _error;
} }
if (tDecodeDouble(pDecoder, &pBF->errorRate) < 0) goto _error; if (tDecodeDouble(pDecoder, &pBF->errorRate) < 0) goto _error;
...@@ -145,6 +144,4 @@ _error: ...@@ -145,6 +144,4 @@ _error:
return NULL; return NULL;
} }
bool tBloomFilterIsFull(const SBloomFilter *pBF) { bool tBloomFilterIsFull(const SBloomFilter *pBF) { return pBF->size >= pBF->expectedEntries; }
return pBF->size >= pBF->expectedEntries; \ No newline at end of file
}
\ No newline at end of file
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "tcache.h" #include "tcache.h"
#include "taoserror.h"
#include "osThread.h" #include "osThread.h"
#include "taoserror.h"
#include "tlog.h" #include "tlog.h"
#include "tutil.h" #include "tutil.h"
...@@ -35,7 +35,7 @@ typedef struct SCacheNode { ...@@ -35,7 +35,7 @@ typedef struct SCacheNode {
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
int64_t expireTime; // expire time int64_t expireTime; // expire time
void* signature; void *signature;
struct STrashElem *pTNodeHeader; // point to trash node head struct STrashElem *pTNodeHeader; // point to trash node head
uint16_t keyLen : 15; // max key size: 32kb uint16_t keyLen : 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
......
...@@ -226,23 +226,23 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) { ...@@ -226,23 +226,23 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) {
// string > number > bool > null // string > number > bool > null
// ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison // ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
int32_t compareJsonVal(const void *pLeft, const void *pRight) { int32_t compareJsonVal(const void *pLeft, const void *pRight) {
char leftType = *(char*)pLeft; char leftType = *(char *)pLeft;
char rightType = *(char*)pRight; char rightType = *(char *)pRight;
if(leftType != rightType){ if (leftType != rightType) {
return leftType > rightType ? 1 : -1; return leftType > rightType ? 1 : -1;
} }
char* realDataLeft = POINTER_SHIFT(pLeft, CHAR_BYTES); char *realDataLeft = POINTER_SHIFT(pLeft, CHAR_BYTES);
char* realDataRight = POINTER_SHIFT(pRight, CHAR_BYTES); char *realDataRight = POINTER_SHIFT(pRight, CHAR_BYTES);
if(leftType == TSDB_DATA_TYPE_BOOL) { if (leftType == TSDB_DATA_TYPE_BOOL) {
DEFAULT_COMP(GET_INT8_VAL(realDataLeft), GET_INT8_VAL(realDataRight)); DEFAULT_COMP(GET_INT8_VAL(realDataLeft), GET_INT8_VAL(realDataRight));
}else if(leftType == TSDB_DATA_TYPE_DOUBLE){ } else if (leftType == TSDB_DATA_TYPE_DOUBLE) {
DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(realDataLeft), GET_DOUBLE_VAL(realDataRight)); DEFAULT_DOUBLE_COMP(GET_DOUBLE_VAL(realDataLeft), GET_DOUBLE_VAL(realDataRight));
}else if(leftType == TSDB_DATA_TYPE_NCHAR){ } else if (leftType == TSDB_DATA_TYPE_NCHAR) {
return compareLenPrefixedWStr(realDataLeft, realDataRight); return compareLenPrefixedWStr(realDataLeft, realDataRight);
}else if(leftType == TSDB_DATA_TYPE_NULL) { } else if (leftType == TSDB_DATA_TYPE_NULL) {
return 0; return 0;
}else{ } else {
assert(0); assert(0);
return 0; return 0;
} }
...@@ -392,7 +392,6 @@ int32_t compareInt16Uint64(const void *pLeft, const void *pRight) { ...@@ -392,7 +392,6 @@ int32_t compareInt16Uint64(const void *pLeft, const void *pRight) {
return 0; return 0;
} }
int32_t compareInt32Int8(const void *pLeft, const void *pRight) { int32_t compareInt32Int8(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft); int32_t left = GET_INT32_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight); int8_t right = GET_INT8_VAL(pRight);
...@@ -997,10 +996,7 @@ int32_t compareUint64Uint32(const void *pLeft, const void *pRight) { ...@@ -997,10 +996,7 @@ int32_t compareUint64Uint32(const void *pLeft, const void *pRight) {
return 0; 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 * Compare two strings
* TSDB_MATCH: Match * TSDB_MATCH: Match
......
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "tconfig.h" #include "tconfig.h"
#include "cJSON.h"
#include "taoserror.h" #include "taoserror.h"
#include "tlog.h"
#include "tutil.h"
#include "tenv.h" #include "tenv.h"
#include "cJSON.h"
#include "tjson.h"
#include "tgrant.h" #include "tgrant.h"
#include "tjson.h"
#include "tlog.h"
#include "tutil.h"
#define CFG_NAME_PRINT_LEN 24 #define CFG_NAME_PRINT_LEN 24
#define CFG_SRC_PRINT_LEN 12 #define CFG_SRC_PRINT_LEN 12
...@@ -508,7 +508,7 @@ const char *cfgDtypeStr(ECfgDataType type) { ...@@ -508,7 +508,7 @@ const char *cfgDtypeStr(ECfgDataType type) {
} }
} }
void cfgDumpItemValue(SConfigItem *pItem, char* buf, int32_t bufSize, int32_t* pLen) { void cfgDumpItemValue(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t *pLen) {
int32_t len = 0; int32_t len = 0;
switch (pItem->dtype) { switch (pItem->dtype) {
case CFG_DTYPE_BOOL: case CFG_DTYPE_BOOL:
...@@ -634,11 +634,11 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) { ...@@ -634,11 +634,11 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
int32_t code = 0; int32_t code = 0;
char **pEnv = environ; char **pEnv = environ;
line[1023] = 0; line[1023] = 0;
while(*pEnv != NULL) { while (*pEnv != NULL) {
name = value = value2 = value3 = NULL; name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0; olen = vlen = vlen2 = vlen3 = 0;
strncpy(line, *pEnv, sizeof(line)-1); strncpy(line, *pEnv, sizeof(line) - 1);
pEnv++; pEnv++;
taosEnvToCfg(line, line); taosEnvToCfg(line, line);
...@@ -676,9 +676,9 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) { ...@@ -676,9 +676,9 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
int32_t code = 0; int32_t code = 0;
int32_t index = 0; int32_t index = 0;
if (envCmd == NULL) return 0; if (envCmd == NULL) return 0;
while (envCmd[index]!=NULL) { while (envCmd[index] != NULL) {
strncpy(buf, envCmd[index], sizeof(buf)-1); strncpy(buf, envCmd[index], sizeof(buf) - 1);
buf[sizeof(buf)-1] = 0; buf[sizeof(buf) - 1] = 0;
taosEnvToCfg(buf, buf); taosEnvToCfg(buf, buf);
index++; index++;
...@@ -720,13 +720,13 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { ...@@ -720,13 +720,13 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
ssize_t _bytes = 0; ssize_t _bytes = 0;
const char *filepath = ".env"; const char *filepath = ".env";
if (envFile != NULL && strlen(envFile)>0) { if (envFile != NULL && strlen(envFile) > 0) {
if (!taosCheckExistFile(envFile)) { if (!taosCheckExistFile(envFile)) {
uError("failed to load env file: %s", envFile); uError("failed to load env file: %s", envFile);
return -1; return -1;
} }
filepath = envFile; filepath = envFile;
}else { } else {
if (!taosCheckExistFile(filepath)) { if (!taosCheckExistFile(filepath)) {
uInfo("failed to load env file: %s", filepath); uInfo("failed to load env file: %s", filepath);
return 0; return 0;
...@@ -747,7 +747,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { ...@@ -747,7 +747,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
if (_bytes <= 0) { if (_bytes <= 0) {
break; break;
} }
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
taosEnvToCfg(line, line); taosEnvToCfg(line, line);
paGetToken(line, &name, &olen); paGetToken(line, &name, &olen);
...@@ -808,7 +808,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -808,7 +808,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
break; break;
} }
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
paGetToken(line, &name, &olen); paGetToken(line, &name, &olen);
if (olen == 0) continue; if (olen == 0) continue;
...@@ -941,13 +941,13 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { ...@@ -941,13 +941,13 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
char *buf = taosMemoryMalloc(fileSize); char *buf = taosMemoryMalloc(fileSize);
taosLSeekFile(pFile, 0, SEEK_SET); taosLSeekFile(pFile, 0, SEEK_SET);
if(taosReadFile(pFile, buf, fileSize) <= 0) { if (taosReadFile(pFile, buf, fileSize) <= 0) {
taosCloseFile(&pFile); taosCloseFile(&pFile);
uError("load json file error: %s", filepath); uError("load json file error: %s", filepath);
return -1; return -1;
} }
taosCloseFile(&pFile); taosCloseFile(&pFile);
SJson* pJson = tjsonParse(buf); SJson *pJson = tjsonParse(buf);
if (NULL == pJson) { if (NULL == pJson) {
const char *jsonParseError = tjsonGetError(); const char *jsonParseError = tjsonGetError();
if (jsonParseError != NULL) { if (jsonParseError != NULL) {
...@@ -958,8 +958,8 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { ...@@ -958,8 +958,8 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
taosMemoryFreeClear(buf); taosMemoryFreeClear(buf);
int32_t jsonArraySize = tjsonGetArraySize(pJson); int32_t jsonArraySize = tjsonGetArraySize(pJson);
for(int32_t i = 0; i < jsonArraySize; i++) { for (int32_t i = 0; i < jsonArraySize; i++) {
cJSON* item = tjsonGetArrayItem(pJson, i); cJSON *item = tjsonGetArrayItem(pJson, i);
if (item == NULL) break; if (item == NULL) break;
char *itemName = NULL, *itemValueString = NULL; char *itemName = NULL, *itemValueString = NULL;
tjsonGetObjectName(item, &itemName); tjsonGetObjectName(item, &itemName);
...@@ -971,7 +971,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { ...@@ -971,7 +971,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2); cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2);
memcpy(cfgLineBuf, itemName, itemNameLen); memcpy(cfgLineBuf, itemName, itemNameLen);
cfgLineBuf[itemNameLen] = ' '; cfgLineBuf[itemNameLen] = ' ';
memcpy(&cfgLineBuf[itemNameLen+1], itemValueString, itemValueStringLen); memcpy(&cfgLineBuf[itemNameLen + 1], itemValueString, itemValueStringLen);
cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0'; cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0';
paGetToken(cfgLineBuf, &name, &olen); paGetToken(cfgLineBuf, &name, &olen);
...@@ -1010,19 +1010,19 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { ...@@ -1010,19 +1010,19 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
return 0; return 0;
} }
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl) { int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl) {
int32_t index = 0; int32_t index = 0;
if (envCmd == NULL) return 0; if (envCmd == NULL) return 0;
while (envCmd[index]!=NULL) { while (envCmd[index] != NULL) {
if (strncmp(envCmd[index], "TAOS_APOLLO_URL", 14) == 0) { if (strncmp(envCmd[index], "TAOS_APOLLO_URL", 14) == 0) {
char *p = strchr(envCmd[index], '='); char *p = strchr(envCmd[index], '=');
if (p != NULL) { if (p != NULL) {
p++; p++;
if (*p == '\'') { if (*p == '\'') {
p++; p++;
p[strlen(p)-1] = '\0'; p[strlen(p) - 1] = '\0';
} }
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
uInfo("get apollo url from env cmd success"); uInfo("get apollo url from env cmd success");
return 0; return 0;
} }
...@@ -1033,8 +1033,8 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl ...@@ -1033,8 +1033,8 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
char line[1024]; char line[1024];
char **pEnv = environ; char **pEnv = environ;
line[1023] = 0; line[1023] = 0;
while(*pEnv != NULL) { while (*pEnv != NULL) {
strncpy(line, *pEnv, sizeof(line)-1); strncpy(line, *pEnv, sizeof(line) - 1);
pEnv++; pEnv++;
if (strncmp(line, "TAOS_APOLLO_URL", 14) == 0) { if (strncmp(line, "TAOS_APOLLO_URL", 14) == 0) {
char *p = strchr(line, '='); char *p = strchr(line, '=');
...@@ -1042,23 +1042,23 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl ...@@ -1042,23 +1042,23 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
p++; p++;
if (*p == '\'') { if (*p == '\'') {
p++; p++;
p[strlen(p)-1] = '\0'; p[strlen(p) - 1] = '\0';
} }
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl); uInfo("get apollo url from env variables success, apolloUrl=%s", apolloUrl);
return 0; return 0;
} }
} }
} }
const char *filepath = ".env"; const char *filepath = ".env";
if (envFile != NULL && strlen(envFile)>0) { if (envFile != NULL && strlen(envFile) > 0) {
if (!taosCheckExistFile(envFile)) { if (!taosCheckExistFile(envFile)) {
uError("failed to load env file: %s", envFile); uError("failed to load env file: %s", envFile);
return -1; return -1;
} }
filepath = envFile; filepath = envFile;
}else { } else {
if (!taosCheckExistFile(filepath)) { if (!taosCheckExistFile(filepath)) {
uInfo("failed to load env file: %s", filepath); uInfo("failed to load env file: %s", filepath);
return 0; return 0;
...@@ -1072,16 +1072,16 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl ...@@ -1072,16 +1072,16 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
if (_bytes <= 0) { if (_bytes <= 0) {
break; break;
} }
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0; if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
if (strncmp(line, "TAOS_APOLLO_URL", 14) == 0) { if (strncmp(line, "TAOS_APOLLO_URL", 14) == 0) {
char *p = strchr(line, '='); char *p = strchr(line, '=');
if (p != NULL) { if (p != NULL) {
p++; p++;
if (*p == '\'') { if (*p == '\'') {
p++; p++;
p[strlen(p)-1] = '\0'; p[strlen(p) - 1] = '\0';
} }
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX)); memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
taosCloseFile(&pFile); taosCloseFile(&pFile);
uInfo("get apollo url from env file success"); uInfo("get apollo url from env file success");
return 0; return 0;
......
此差异已折叠。
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
* Copyright (c) 2016, Usman Masood <usmanm at fastmail dot fm> * Copyright (c) 2016, Usman Masood <usmanm at fastmail dot fm>
*/ */
#include "tdigest.h"
#include "os.h" #include "os.h"
#include "osMath.h" #include "osMath.h"
#include "tdigest.h"
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0))) #define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
//#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI) //#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (double)(q) - 1)/M_PI + (double)1/2)) #define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (double)(q)-1) / M_PI + (double)1 / 2))
#define FLOAT_EQ(f1, f2) (fabs((f1) - (f2)) <= FLT_EPSILON) #define FLOAT_EQ(f1, f2) (fabs((f1) - (f2)) <= FLT_EPSILON)
typedef struct SMergeArgs { typedef struct SMergeArgs {
...@@ -41,16 +41,16 @@ typedef struct SMergeArgs { ...@@ -41,16 +41,16 @@ typedef struct SMergeArgs {
double k1; double k1;
double min; double min;
double max; double max;
}SMergeArgs; } SMergeArgs;
void tdigestAutoFill(TDigest* t, int32_t compression) { void tdigestAutoFill(TDigest *t, int32_t compression) {
t->centroids = (SCentroid*)((char*)t + sizeof(TDigest)); t->centroids = (SCentroid *)((char *)t + sizeof(TDigest));
t->buffered_pts = (SPt*) ((char*)t + sizeof(TDigest) + sizeof(SCentroid) * (int32_t)GET_CENTROID(compression)); t->buffered_pts = (SPt *)((char *)t + sizeof(TDigest) + sizeof(SCentroid) * (int32_t)GET_CENTROID(compression));
} }
TDigest *tdigestNewFrom(void* pBuf, int32_t compression) { TDigest *tdigestNewFrom(void *pBuf, int32_t compression) {
memset(pBuf, 0, (size_t)TDIGEST_SIZE(compression)); memset(pBuf, 0, (size_t)TDIGEST_SIZE(compression));
TDigest* t = (TDigest*)pBuf; TDigest *t = (TDigest *)pBuf;
tdigestAutoFill(t, compression); tdigestAutoFill(t, compression);
t->compression = compression; t->compression = compression;
...@@ -63,34 +63,29 @@ TDigest *tdigestNewFrom(void* pBuf, int32_t compression) { ...@@ -63,34 +63,29 @@ TDigest *tdigestNewFrom(void* pBuf, int32_t compression) {
} }
static int32_t cmpCentroid(const void *a, const void *b) { static int32_t cmpCentroid(const void *a, const void *b) {
SCentroid *c1 = (SCentroid *) a; SCentroid *c1 = (SCentroid *)a;
SCentroid *c2 = (SCentroid *) b; SCentroid *c2 = (SCentroid *)b;
if (c1->mean < c2->mean) if (c1->mean < c2->mean) return -1;
return -1; if (c1->mean > c2->mean) return 1;
if (c1->mean > c2->mean)
return 1;
return 0; return 0;
} }
static void mergeCentroid(SMergeArgs *args, SCentroid *merge) { static void mergeCentroid(SMergeArgs *args, SCentroid *merge) {
double k2; double k2;
SCentroid *c = &args->centroids[args->idx]; SCentroid *c = &args->centroids[args->idx];
args->weight_so_far += merge->weight; args->weight_so_far += merge->weight;
k2 = INTEGRATED_LOCATION(args->t->size, k2 = INTEGRATED_LOCATION(args->t->size, args->weight_so_far / args->t->total_weight);
args->weight_so_far / args->t->total_weight); // idx++
//idx++ if (k2 - args->k1 > 1 && c->weight > 0) {
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->idx++;
} }
args->k1 = k2; args->k1 = k2;
} }
c = &args->centroids[args->idx]; c = &args->centroids[args->idx];
if(c->mean == merge->mean) { if (c->mean == merge->mean) {
c->weight += merge->weight; c->weight += merge->weight;
} else { } else {
c->weight += merge->weight; c->weight += merge->weight;
...@@ -110,10 +105,9 @@ void tdigestCompress(TDigest *t) { ...@@ -110,10 +105,9 @@ void tdigestCompress(TDigest *t) {
int32_t i, j; int32_t i, j;
SMergeArgs args; SMergeArgs args;
if (t->num_buffered_pts <= 0) if (t->num_buffered_pts <= 0) return;
return;
unmerged_centroids = (SCentroid*)taosMemoryMalloc(sizeof(SCentroid) * t->num_buffered_pts); unmerged_centroids = (SCentroid *)taosMemoryMalloc(sizeof(SCentroid) * t->num_buffered_pts);
for (i = 0; i < num_unmerged; i++) { for (i = 0; i < num_unmerged; i++) {
SPt *p = t->buffered_pts + i; SPt *p = t->buffered_pts + i;
SCentroid *c = &unmerged_centroids[i]; SCentroid *c = &unmerged_centroids[i];
...@@ -126,7 +120,7 @@ void tdigestCompress(TDigest *t) { ...@@ -126,7 +120,7 @@ void tdigestCompress(TDigest *t) {
taosSort(unmerged_centroids, num_unmerged, sizeof(SCentroid), cmpCentroid); taosSort(unmerged_centroids, num_unmerged, sizeof(SCentroid), cmpCentroid);
memset(&args, 0, sizeof(SMergeArgs)); memset(&args, 0, sizeof(SMergeArgs));
args.centroids = (SCentroid*)taosMemoryMalloc((size_t)(sizeof(SCentroid) * t->size)); args.centroids = (SCentroid *)taosMemoryMalloc((size_t)(sizeof(SCentroid) * t->size));
memset(args.centroids, 0, (size_t)(sizeof(SCentroid) * t->size)); memset(args.centroids, 0, (size_t)(sizeof(SCentroid) * t->size));
args.t = t; args.t = t;
...@@ -154,7 +148,7 @@ void tdigestCompress(TDigest *t) { ...@@ -154,7 +148,7 @@ void tdigestCompress(TDigest *t) {
mergeCentroid(&args, &unmerged_centroids[i++]); mergeCentroid(&args, &unmerged_centroids[i++]);
assert(args.idx < t->size); assert(args.idx < t->size);
} }
taosMemoryFree((void*)unmerged_centroids); taosMemoryFree((void *)unmerged_centroids);
while (j < t->num_centroids) { while (j < t->num_centroids) {
mergeCentroid(&args, &t->centroids[j++]); mergeCentroid(&args, &t->centroids[j++]);
...@@ -171,15 +165,14 @@ void tdigestCompress(TDigest *t) { ...@@ -171,15 +165,14 @@ void tdigestCompress(TDigest *t) {
} }
memcpy(t->centroids, args.centroids, sizeof(SCentroid) * t->num_centroids); memcpy(t->centroids, args.centroids, sizeof(SCentroid) * t->num_centroids);
taosMemoryFree((void*)args.centroids); taosMemoryFree((void *)args.centroids);
} }
void tdigestAdd(TDigest* t, double x, int64_t w) { void tdigestAdd(TDigest *t, double x, int64_t w) {
if (w == 0) if (w == 0) return;
return;
int32_t i = t->num_buffered_pts; int32_t i = t->num_buffered_pts;
if(i > 0 && t->buffered_pts[i-1].value == x ) { if (i > 0 && t->buffered_pts[i - 1].value == x) {
t->buffered_pts[i].weight = w; t->buffered_pts[i].weight = w;
} else { } else {
t->buffered_pts[i].value = x; t->buffered_pts[i].value = x;
...@@ -187,14 +180,11 @@ void tdigestAdd(TDigest* t, double x, int64_t w) { ...@@ -187,14 +180,11 @@ void tdigestAdd(TDigest* t, double x, int64_t w) {
t->num_buffered_pts++; 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) { double tdigestCDF(TDigest *t, double x) {
if (t == NULL) if (t == NULL) return 0;
return 0;
int32_t i; int32_t i;
double left, right; double left, right;
...@@ -202,15 +192,11 @@ double tdigestCDF(TDigest *t, double x) { ...@@ -202,15 +192,11 @@ double tdigestCDF(TDigest *t, double x) {
SCentroid *a, *b, tmp; SCentroid *a, *b, tmp;
tdigestCompress(t); tdigestCompress(t);
if (t->num_centroids == 0) if (t->num_centroids == 0) return NAN;
return NAN; if (x < t->min) return 0;
if (x < t->min) if (x > t->max) return 1;
return 0;
if (x > t->max)
return 1;
if (t->num_centroids == 1) { if (t->num_centroids == 1) {
if (FLOAT_EQ(t->max, t->min)) if (FLOAT_EQ(t->max, t->min)) return 0.5;
return 0.5;
return INTERPOLATE(x, t->min, t->max); return INTERPOLATE(x, t->min, t->max);
} }
...@@ -230,10 +216,7 @@ double tdigestCDF(TDigest *t, double x) { ...@@ -230,10 +216,7 @@ double tdigestCDF(TDigest *t, double x) {
right = (b->mean - a->mean) * a->weight / (a->weight + b->weight); right = (b->mean - a->mean) * a->weight / (a->weight + b->weight);
if (x < a->mean + right) { if (x < a->mean + right) {
double cdf = (weight_so_far double cdf = (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right)) / t->total_weight;
+ a->weight
* INTERPOLATE(x, a->mean - left, a->mean + right))
/ t->total_weight;
return TMAX(cdf, 0.0); return TMAX(cdf, 0.0);
} }
...@@ -245,16 +228,14 @@ double tdigestCDF(TDigest *t, double x) { ...@@ -245,16 +228,14 @@ double tdigestCDF(TDigest *t, double x) {
right = t->max - a->mean; right = t->max - a->mean;
if (x < a->mean + right) { if (x < a->mean + right) {
return (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right)) return (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right)) / t->total_weight;
/ t->total_weight;
} }
return 1; return 1;
} }
double tdigestQuantile(TDigest *t, double q) { double tdigestQuantile(TDigest *t, double q) {
if (t == NULL) if (t == NULL) return 0;
return 0;
int32_t i; int32_t i;
double left, right, idx; double left, right, idx;
...@@ -262,14 +243,10 @@ double tdigestQuantile(TDigest *t, double q) { ...@@ -262,14 +243,10 @@ double tdigestQuantile(TDigest *t, double q) {
SCentroid *a, *b, tmp; SCentroid *a, *b, tmp;
tdigestCompress(t); tdigestCompress(t);
if (t->num_centroids == 0) if (t->num_centroids == 0) return NAN;
return NAN; if (t->num_centroids == 1) return t->centroids[0].mean;
if (t->num_centroids == 1) if (FLOAT_EQ(q, 0.0)) return t->min;
return t->centroids[0].mean; if (FLOAT_EQ(q, 1.0)) return t->max;
if (FLOAT_EQ(q, 0.0))
return t->min;
if (FLOAT_EQ(q, 1.0))
return t->max;
idx = q * t->total_weight; idx = q * t->total_weight;
weight_so_far = 0; weight_so_far = 0;
...@@ -284,7 +261,7 @@ double tdigestQuantile(TDigest *t, double q) { ...@@ -284,7 +261,7 @@ double tdigestQuantile(TDigest *t, double q) {
left = right; left = right;
b = c; b = c;
right = (b->weight * a->mean + a->weight * b->mean)/ (a->weight + b->weight); right = (b->weight * a->mean + a->weight * b->mean) / (a->weight + b->weight);
if (idx < weight_so_far + a->weight) { if (idx < weight_so_far + a->weight) {
double p = (idx - weight_so_far) / a->weight; double p = (idx - weight_so_far) / a->weight;
return left * (1 - p) + right * p; return left * (1 - p) + right * p;
...@@ -307,10 +284,10 @@ double tdigestQuantile(TDigest *t, double q) { ...@@ -307,10 +284,10 @@ double tdigestQuantile(TDigest *t, double q) {
void tdigestMerge(TDigest *t1, TDigest *t2) { void tdigestMerge(TDigest *t1, TDigest *t2) {
// SPoints // SPoints
int32_t num_pts = t2->num_buffered_pts; int32_t num_pts = t2->num_buffered_pts;
for(int32_t i = num_pts - 1; i >= 0; i--) { for (int32_t i = num_pts - 1; i >= 0; i--) {
SPt* p = t2->buffered_pts + i; SPt *p = t2->buffered_pts + i;
tdigestAdd(t1, p->value, p->weight); tdigestAdd(t1, p->value, p->weight);
t2->num_buffered_pts --; t2->num_buffered_pts--;
} }
// centroids // centroids
for (int32_t i = 0; i < t2->num_centroids; i++) { for (int32_t i = 0; i < t2->num_centroids; i++) {
......
...@@ -62,9 +62,9 @@ int32_t taosEnvToCfg(const char *envStr, char *cfgStr) { ...@@ -62,9 +62,9 @@ int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
if (p != NULL) { if (p != NULL) {
char buf[CFG_NAME_MAX_LEN]; char buf[CFG_NAME_MAX_LEN];
if (*(p+1) == '\'') { if (*(p + 1) == '\'') {
*(p+1)= ' '; *(p + 1) = ' ';
char *pEnd = &cfgStr[strlen(cfgStr)-1]; char *pEnd = &cfgStr[strlen(cfgStr) - 1];
if (*pEnd == '\'') *pEnd = '\0'; if (*pEnd == '\'') *pEnd = '\0';
} }
*p = '\0'; *p = '\0';
......
...@@ -890,5 +890,3 @@ void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen) { ...@@ -890,5 +890,3 @@ void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen) {
void taosHashRelease(SHashObj *pHashObj, void *p) { taosHashCancelIterate(pHashObj, p); } void taosHashRelease(SHashObj *pHashObj, void *p) { taosHashCancelIterate(pHashObj, p); }
int64_t taosHashGetCompTimes(SHashObj *pHashObj) { return atomic_load_64(&pHashObj->compTimes); } int64_t taosHashGetCompTimes(SHashObj *pHashObj) { return atomic_load_64(&pHashObj->compTimes); }
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "thash.h"
#include "tcompare.h" #include "tcompare.h"
#include "thash.h"
#include "types.h" #include "types.h"
#define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r))) #define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r)))
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
(h) *= 0x85ebca6b; \ (h) *= 0x85ebca6b; \
(h) ^= (h) >> 13; \ (h) ^= (h) >> 13; \
(h) *= 0xc2b2ae35; \ (h) *= 0xc2b2ae35; \
(h) ^= (h) >> 16; } while (0) (h) ^= (h) >> 16; \
} while (0)
uint32_t MurmurHash3_32(const char *key, uint32_t len) { uint32_t MurmurHash3_32(const char *key, uint32_t len) {
const uint8_t *data = (const uint8_t *)key; const uint8_t *data = (const uint8_t *)key;
...@@ -84,10 +85,10 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) { ...@@ -84,10 +85,10 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) {
uint32_t seed = 0x12345678; uint32_t seed = 0x12345678;
uint64_t h = seed ^ (len * m); uint64_t h = seed ^ (len * m);
const uint8_t *data = (const uint8_t *)key; const uint8_t *data = (const uint8_t *)key;
const uint8_t *end = data + (len-(len&7)); const uint8_t *end = data + (len - (len & 7));
while(data != end) { while (data != end) {
uint64_t k = *((uint64_t*)data); uint64_t k = *((uint64_t *)data);
k *= m; k *= m;
k ^= k >> r; k ^= k >> r;
...@@ -97,14 +98,21 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) { ...@@ -97,14 +98,21 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) {
data += 8; data += 8;
} }
switch(len & 7) { switch (len & 7) {
case 7: h ^= (uint64_t)data[6] << 48; /* fall-thru */ case 7:
case 6: h ^= (uint64_t)data[5] << 40; /* fall-thru */ h ^= (uint64_t)data[6] << 48; /* fall-thru */
case 5: h ^= (uint64_t)data[4] << 32; /* fall-thru */ case 6:
case 4: h ^= (uint64_t)data[3] << 24; /* fall-thru */ h ^= (uint64_t)data[5] << 40; /* fall-thru */
case 3: h ^= (uint64_t)data[2] << 16; /* fall-thru */ case 5:
case 2: h ^= (uint64_t)data[1] << 8; /* fall-thru */ h ^= (uint64_t)data[4] << 32; /* fall-thru */
case 1: h ^= (uint64_t)data[0]; 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 */ h *= m; /* fall-thru */
}; };
...@@ -126,7 +134,7 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) { ...@@ -126,7 +134,7 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (FLT_EQUAL(f, 0.0)) { if (FLT_EQUAL(f, 0.0)) {
return 0; return 0;
} }
if (fabs(f) < FLT_MAX/BASE - DLT) { if (fabs(f) < FLT_MAX / BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT))); int32_t t = (int32_t)(round(BASE * (f + DLT)));
return (uint32_t)t; return (uint32_t)t;
} else { } else {
...@@ -142,7 +150,7 @@ uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) { ...@@ -142,7 +150,7 @@ uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (FLT_EQUAL(f, 0.0)) { if (FLT_EQUAL(f, 0.0)) {
return 0; return 0;
} }
if (fabs(f) < DBL_MAX/BASE - DLT) { if (fabs(f) < DBL_MAX / BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT))); int32_t t = (int32_t)(round(BASE * (f + DLT)));
return (uint32_t)t; return (uint32_t)t;
} else { } else {
...@@ -160,7 +168,7 @@ uint32_t taosIntHash_64(const char *key, uint32_t UNUSED_PARAM(len)) { ...@@ -160,7 +168,7 @@ uint32_t taosIntHash_64(const char *key, uint32_t UNUSED_PARAM(len)) {
_hash_fn_t taosGetDefaultHashFunction(int32_t type) { _hash_fn_t taosGetDefaultHashFunction(int32_t type) {
_hash_fn_t fn = NULL; _hash_fn_t fn = NULL;
switch(type) { switch (type) {
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
...@@ -210,9 +218,15 @@ int32_t taosDoubleEqual(const void *a, const void *b, size_t UNUSED_PARAM(sz)) { ...@@ -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 taosGetDefaultEqualFunction(int32_t type) {
_equal_fn_t fn = NULL; _equal_fn_t fn = NULL;
switch (type) { switch (type) {
case TSDB_DATA_TYPE_FLOAT: fn = taosFloatEqual; break; case TSDB_DATA_TYPE_FLOAT:
case TSDB_DATA_TYPE_DOUBLE: fn = taosDoubleEqual; break; fn = taosFloatEqual;
default: fn = memcmp; break; break;
case TSDB_DATA_TYPE_DOUBLE:
fn = taosDoubleEqual;
break;
default:
fn = memcmp;
break;
} }
return fn; return fn;
} }
...@@ -48,7 +48,8 @@ struct SDiskbasedBuf { ...@@ -48,7 +48,8 @@ struct SDiskbasedBuf {
}; };
static int32_t createDiskFile(SDiskbasedBuf* pBuf) { 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) { if (pBuf->pFile == NULL) {
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} }
...@@ -318,7 +319,7 @@ static void lruListMoveToFront(SList* pList, SPageInfo* pi) { ...@@ -318,7 +319,7 @@ static void lruListMoveToFront(SList* pList, SPageInfo* pi) {
} }
static SPageInfo* getPageInfoFromPayload(void* page) { static SPageInfo* getPageInfoFromPayload(void* page) {
char* p = (char *)page - POINTER_BYTES; char* p = (char*)page - POINTER_BYTES;
SPageInfo* ppi = ((SPageInfo**)p)[0]; SPageInfo* ppi = ((SPageInfo**)p)[0];
return ppi; return ppi;
...@@ -402,14 +403,15 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) { ...@@ -402,14 +403,15 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
// allocate buf // allocate buf
if (availablePage == NULL) { 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 { } else {
pi->pData = availablePage; pi->pData = availablePage;
} }
((void**)pi->pData)[0] = pi; ((void**)pi->pData)[0] = pi;
#ifdef BUF_PAGE_DEBUG #ifdef BUF_PAGE_DEBUG
uDebug("page_getNewBufPage , pi->pData:%p, pageId:%d, offset:%"PRId64, pi->pData, pi->pageId, pi->offset); uDebug("page_getNewBufPage , pi->pData:%p, pageId:%d, offset:%" PRId64, pi->pData, pi->pageId, pi->offset);
#endif #endif
return (void*)(GET_DATA_PAYLOAD(pi)); return (void*)(GET_DATA_PAYLOAD(pi));
} }
...@@ -434,11 +436,12 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) { ...@@ -434,11 +436,12 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
lruListMoveToFront(pBuf->lruList, (*pi)); lruListMoveToFront(pBuf->lruList, (*pi));
(*pi)->used = true; (*pi)->used = true;
#ifdef BUF_PAGE_DEBUG #ifdef BUF_PAGE_DEBUG
uDebug("page_getBufPage1 pageId:%d, offset:%"PRId64, (*pi)->pageId, (*pi)->offset); uDebug("page_getBufPage1 pageId:%d, offset:%" PRId64, (*pi)->pageId, (*pi)->offset);
#endif #endif
return (void*)(GET_DATA_PAYLOAD(*pi)); return (void*)(GET_DATA_PAYLOAD(*pi));
} else { // not in memory } 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; char* availablePage = NULL;
if (NO_IN_MEM_AVAILABLE_PAGES(pBuf)) { if (NO_IN_MEM_AVAILABLE_PAGES(pBuf)) {
...@@ -468,7 +471,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) { ...@@ -468,7 +471,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
} }
} }
#ifdef BUF_PAGE_DEBUG #ifdef BUF_PAGE_DEBUG
uDebug("page_getBufPage2 pageId:%d, offset:%"PRId64, (*pi)->pageId, (*pi)->offset); uDebug("page_getBufPage2 pageId:%d, offset:%" PRId64, (*pi)->pageId, (*pi)->offset);
#endif #endif
return (void*)(GET_DATA_PAYLOAD(*pi)); return (void*)(GET_DATA_PAYLOAD(*pi));
} }
...@@ -482,7 +485,7 @@ void releaseBufPage(SDiskbasedBuf* pBuf, void* page) { ...@@ -482,7 +485,7 @@ void releaseBufPage(SDiskbasedBuf* pBuf, void* page) {
void releaseBufPageInfo(SDiskbasedBuf* pBuf, SPageInfo* pi) { void releaseBufPageInfo(SDiskbasedBuf* pBuf, SPageInfo* pi) {
#ifdef BUF_PAGE_DEBUG #ifdef BUF_PAGE_DEBUG
uDebug("page_releaseBufPageInfo pageId:%d, used:%d, offset:%"PRId64, pi->pageId, pi->used, pi->offset); uDebug("page_releaseBufPageInfo pageId:%d, used:%d, offset:%" PRId64, pi->pageId, pi->used, pi->offset);
#endif #endif
// assert(pi->pData != NULL && pi->used == true); // assert(pi->pData != NULL && pi->used == true);
assert(pi->pData != NULL); assert(pi->pData != NULL);
...@@ -520,12 +523,12 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) { ...@@ -520,12 +523,12 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) {
{ {
SDiskbasedBufStatis* ps = &pBuf->statis; SDiskbasedBufStatis* ps = &pBuf->statis;
if (ps->loadPages == 0) { if (ps->loadPages == 0) {
uDebug( uDebug("Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages)", ps->getPages,
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages)", ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages);
ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages);
} else { } else {
uDebug( 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->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f,
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages)); ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
} }
...@@ -614,7 +617,8 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf) { ...@@ -614,7 +617,8 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf) {
if (ps->loadPages > 0) { if (ps->loadPages > 0) {
printf( 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->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f,
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages)); ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
} else { } else {
......
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
#define DEFAULT_GROWTH 2 #define DEFAULT_GROWTH 2
#define DEFAULT_TIGHTENING_RATIO 0.5 #define DEFAULT_TIGHTENING_RATIO 0.5
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, double errorRate);
double errorRate);
SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) { SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
const uint32_t defaultSize = 8; const uint32_t defaultSize = 8;
...@@ -35,7 +34,7 @@ SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) { ...@@ -35,7 +34,7 @@ SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
} }
pSBf->numBits = 0; pSBf->numBits = 0;
pSBf->bfArray = taosArrayInit(defaultSize, sizeof(void *)); pSBf->bfArray = taosArrayInit(defaultSize, sizeof(void *));
if (tScalableBfAddFilter(pSBf, expectedEntries, errorRate * DEFAULT_TIGHTENING_RATIO) == NULL ) { if (tScalableBfAddFilter(pSBf, expectedEntries, errorRate * DEFAULT_TIGHTENING_RATIO) == NULL) {
tScalableBfDestroy(pSBf); tScalableBfDestroy(pSBf);
return NULL; return NULL;
} }
...@@ -46,8 +45,7 @@ SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) { ...@@ -46,8 +45,7 @@ SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) { int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
int32_t size = taosArrayGetSize(pSBf->bfArray); int32_t size = taosArrayGetSize(pSBf->bfArray);
for (int32_t i = size - 2; i >= 0; --i) { for (int32_t i = size - 2; i >= 0; --i) {
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), keyBuf, len) != TSDB_CODE_SUCCESS) {
keyBuf, len) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
} }
...@@ -55,8 +53,7 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) { ...@@ -55,8 +53,7 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
SBloomFilter *pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1); SBloomFilter *pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1);
ASSERT(pNormalBf); ASSERT(pNormalBf);
if (tBloomFilterIsFull(pNormalBf)) { if (tBloomFilterIsFull(pNormalBf)) {
pNormalBf = tScalableBfAddFilter(pSBf, pNormalBf = tScalableBfAddFilter(pSBf, pNormalBf->expectedEntries * pSBf->growth,
pNormalBf->expectedEntries * pSBf->growth,
pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO); pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO);
if (pNormalBf == NULL) { if (pNormalBf == NULL) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
...@@ -65,25 +62,22 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) { ...@@ -65,25 +62,22 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
return tBloomFilterPut(pNormalBf, keyBuf, len); return tBloomFilterPut(pNormalBf, keyBuf, len);
} }
int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf, int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
uint32_t len) {
int32_t size = taosArrayGetSize(pSBf->bfArray); int32_t size = taosArrayGetSize(pSBf->bfArray);
for (int32_t i = size - 1; i >= 0; --i) { for (int32_t i = size - 1; i >= 0; --i) {
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), keyBuf, len) != TSDB_CODE_SUCCESS) {
keyBuf, len) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, double errorRate) {
double errorRate) {
SBloomFilter *pNormalBf = tBloomFilterInit(expectedEntries, errorRate); SBloomFilter *pNormalBf = tBloomFilterInit(expectedEntries, errorRate);
if (pNormalBf == NULL) { if (pNormalBf == NULL) {
return NULL; return NULL;
} }
if(taosArrayPush(pSBf->bfArray, &pNormalBf) == NULL) { if (taosArrayPush(pSBf->bfArray, &pNormalBf) == NULL) {
tBloomFilterDestroy(pNormalBf); tBloomFilterDestroy(pNormalBf);
return NULL; return NULL;
} }
...@@ -101,7 +95,7 @@ void tScalableBfDestroy(SScalableBf *pSBf) { ...@@ -101,7 +95,7 @@ void tScalableBfDestroy(SScalableBf *pSBf) {
taosMemoryFree(pSBf); taosMemoryFree(pSBf);
} }
int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) { int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder *pEncoder) {
if (!pSBf) { if (!pSBf) {
if (tEncodeI32(pEncoder, 0) < 0) return -1; if (tEncodeI32(pEncoder, 0) < 0) return -1;
return 0; return 0;
...@@ -109,7 +103,7 @@ int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) { ...@@ -109,7 +103,7 @@ int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) {
int32_t size = taosArrayGetSize(pSBf->bfArray); int32_t size = taosArrayGetSize(pSBf->bfArray);
if (tEncodeI32(pEncoder, size) < 0) return -1; if (tEncodeI32(pEncoder, size) < 0) return -1;
for (int32_t i = 0; i < size; i++) { for (int32_t i = 0; i < size; i++) {
SBloomFilter* pBF = taosArrayGetP(pSBf->bfArray, i); SBloomFilter *pBF = taosArrayGetP(pSBf->bfArray, i);
if (tBloomFilterEncode(pBF, pEncoder) < 0) return -1; if (tBloomFilterEncode(pBF, pEncoder) < 0) return -1;
} }
if (tEncodeU32(pEncoder, pSBf->growth) < 0) return -1; if (tEncodeU32(pEncoder, pSBf->growth) < 0) return -1;
...@@ -117,7 +111,7 @@ int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) { ...@@ -117,7 +111,7 @@ int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) {
return 0; return 0;
} }
SScalableBf* tScalableBfDecode(SDecoder* pDecoder) { SScalableBf *tScalableBfDecode(SDecoder *pDecoder) {
SScalableBf *pSBf = taosMemoryCalloc(1, sizeof(SScalableBf)); SScalableBf *pSBf = taosMemoryCalloc(1, sizeof(SScalableBf));
pSBf->bfArray = NULL; pSBf->bfArray = NULL;
int32_t size = 0; int32_t size = 0;
...@@ -128,7 +122,7 @@ SScalableBf* tScalableBfDecode(SDecoder* pDecoder) { ...@@ -128,7 +122,7 @@ SScalableBf* tScalableBfDecode(SDecoder* pDecoder) {
} }
pSBf->bfArray = taosArrayInit(size * 2, sizeof(void *)); pSBf->bfArray = taosArrayInit(size * 2, sizeof(void *));
for (int32_t i = 0; i < size; i++) { for (int32_t i = 0; i < size; i++) {
SBloomFilter* pBF = tBloomFilterDecode(pDecoder); SBloomFilter *pBF = tBloomFilterDecode(pDecoder);
if (!pBF) goto _error; if (!pBF) goto _error;
taosArrayPush(pSBf->bfArray, &pBF); taosArrayPush(pSBf->bfArray, &pBF);
} }
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "ttimer.h" #include "ttimer.h"
#include "taoserror.h" #include "taoserror.h"
#include "tdef.h"
#include "tlog.h" #include "tlog.h"
#include "tsched.h" #include "tsched.h"
#include "tdef.h"
#define tmrFatal(...) \ #define tmrFatal(...) \
{ \ { \
...@@ -133,7 +133,7 @@ static timer_map_t timerMap; ...@@ -133,7 +133,7 @@ static timer_map_t timerMap;
static uintptr_t getNextTimerId() { static uintptr_t getNextTimerId() {
uintptr_t id; uintptr_t id;
do { do {
id = (uintptr_t)atomic_add_fetch_ptr((void **)&nextTimerId, 1); id = (uintptr_t)atomic_add_fetch_ptr((void**)&nextTimerId, 1);
} while (id == 0); } while (id == 0);
return id; return id;
} }
......
...@@ -9,21 +9,21 @@ ...@@ -9,21 +9,21 @@
namespace { namespace {
static void remove_batch_test() { static void remove_batch_test() {
SArray *pa = (SArray*) taosArrayInit(4, sizeof(int32_t)); SArray* pa = (SArray*)taosArrayInit(4, sizeof(int32_t));
for(int32_t i = 0; i < 20; ++i) { for (int32_t i = 0; i < 20; ++i) {
int32_t a = i; int32_t a = i;
taosArrayPush(pa, &a); taosArrayPush(pa, &a);
} }
SArray* delList = (SArray*)taosArrayInit(4, sizeof(int32_t)); SArray* delList = (SArray*)taosArrayInit(4, sizeof(int32_t));
taosArrayRemoveBatch(pa, (const int32_t*) TARRAY_GET_START(delList), taosArrayGetSize(delList)); taosArrayRemoveBatch(pa, (const int32_t*)TARRAY_GET_START(delList), taosArrayGetSize(delList));
EXPECT_EQ(taosArrayGetSize(pa), 20); EXPECT_EQ(taosArrayGetSize(pa), 20);
int32_t a = 5; int32_t a = 5;
taosArrayPush(delList, &a); taosArrayPush(delList, &a);
taosArrayRemoveBatch(pa, (const int32_t*) TARRAY_GET_START(delList), taosArrayGetSize(delList)); taosArrayRemoveBatch(pa, (const int32_t*)TARRAY_GET_START(delList), taosArrayGetSize(delList));
EXPECT_EQ(taosArrayGetSize(pa), 19); EXPECT_EQ(taosArrayGetSize(pa), 19);
EXPECT_EQ(*(int*)taosArrayGet(pa, 5), 6); EXPECT_EQ(*(int*)taosArrayGet(pa, 5), 6);
...@@ -41,7 +41,7 @@ static void remove_batch_test() { ...@@ -41,7 +41,7 @@ static void remove_batch_test() {
a = 14; a = 14;
taosArrayPush(delList, &a); taosArrayPush(delList, &a);
taosArrayRemoveBatch(pa, (const int32_t*) TARRAY_GET_START(delList), taosArrayGetSize(delList)); taosArrayRemoveBatch(pa, (const int32_t*)TARRAY_GET_START(delList), taosArrayGetSize(delList));
EXPECT_EQ(taosArrayGetSize(pa), 17); EXPECT_EQ(taosArrayGetSize(pa), 17);
taosArrayDestroy(pa); taosArrayDestroy(pa);
...@@ -49,24 +49,22 @@ static void remove_batch_test() { ...@@ -49,24 +49,22 @@ static void remove_batch_test() {
} }
} // namespace } // namespace
TEST(arrayTest, array_list_test) { TEST(arrayTest, array_list_test) { remove_batch_test(); }
remove_batch_test();
}
TEST(arrayTest, array_search_test) { TEST(arrayTest, array_search_test) {
SArray *pa = (SArray*) taosArrayInit(4, sizeof(int32_t)); SArray* pa = (SArray*)taosArrayInit(4, sizeof(int32_t));
for(int32_t i = 10; i < 20; ++i) { for (int32_t i = 10; i < 20; ++i) {
int32_t a = i; int32_t a = i;
taosArrayPush(pa, &a); taosArrayPush(pa, &a);
} }
for(int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
int32_t k = i; int32_t k = i;
int32_t* pRet = (int32_t*)taosArraySearch(pa, &k, compareInt32Val, TD_GE); int32_t* pRet = (int32_t*)taosArraySearch(pa, &k, compareInt32Val, TD_GE);
int32_t idx = taosArraySearchIdx(pa, &k, compareInt32Val, TD_GE); int32_t idx = taosArraySearchIdx(pa, &k, compareInt32Val, TD_GE);
if(pRet == NULL) { if (pRet == NULL) {
ASSERT_EQ(idx, -1); ASSERT_EQ(idx, -1);
} else { } else {
ASSERT_EQ(taosArrayGet(pa, idx), pRet); ASSERT_EQ(taosArrayGet(pa, idx), pRet);
...@@ -75,12 +73,11 @@ TEST(arrayTest, array_search_test) { ...@@ -75,12 +73,11 @@ TEST(arrayTest, array_search_test) {
pRet = (int32_t*)taosArraySearch(pa, &k, compareInt32Val, TD_LE); pRet = (int32_t*)taosArraySearch(pa, &k, compareInt32Val, TD_LE);
idx = taosArraySearchIdx(pa, &k, compareInt32Val, TD_LE); idx = taosArraySearchIdx(pa, &k, compareInt32Val, TD_LE);
if(pRet == NULL) { if (pRet == NULL) {
ASSERT_EQ(idx, -1); ASSERT_EQ(idx, -1);
} else { } else {
ASSERT_EQ(taosArrayGet(pa, idx), pRet); ASSERT_EQ(taosArrayGet(pa, idx), pRet);
} }
} }
taosArrayDestroy(pa); taosArrayDestroy(pa);
......
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "tscalablebf.h"
#include "taoserror.h" #include "taoserror.h"
#include "tscalablebf.h"
using namespace std; using namespace std;
...@@ -15,38 +15,38 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) { ...@@ -15,38 +15,38 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) {
SBloomFilter *pBF1 = tBloomFilterInit(100, 0.005); SBloomFilter *pBF1 = tBloomFilterInit(100, 0.005);
GTEST_ASSERT_EQ(pBF1->numBits, 1152); GTEST_ASSERT_EQ(pBF1->numBits, 1152);
GTEST_ASSERT_EQ(pBF1->numUnits, 1152/64); GTEST_ASSERT_EQ(pBF1->numUnits, 1152 / 64);
int64_t count = 0; int64_t count = 0;
for(int64_t i = 0; count < 100; i++) { for (int64_t i = 0; count < 100; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
if(tBloomFilterPut(pBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { if (tBloomFilterPut(pBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
count++; count++;
} }
} }
ASSERT_TRUE(tBloomFilterIsFull(pBF1)); ASSERT_TRUE(tBloomFilterIsFull(pBF1));
SBloomFilter *pBF2 = tBloomFilterInit(1000*10000, 0.1); SBloomFilter *pBF2 = tBloomFilterInit(1000 * 10000, 0.1);
GTEST_ASSERT_EQ(pBF2->numBits, 47925312); GTEST_ASSERT_EQ(pBF2->numBits, 47925312);
GTEST_ASSERT_EQ(pBF2->numUnits, 47925312/64); GTEST_ASSERT_EQ(pBF2->numUnits, 47925312 / 64);
SBloomFilter *pBF3 = tBloomFilterInit(10000*10000, 0.001); SBloomFilter *pBF3 = tBloomFilterInit(10000 * 10000, 0.001);
GTEST_ASSERT_EQ(pBF3->numBits, 1437758784); GTEST_ASSERT_EQ(pBF3->numBits, 1437758784);
GTEST_ASSERT_EQ(pBF3->numUnits, 1437758784/64); GTEST_ASSERT_EQ(pBF3->numUnits, 1437758784 / 64);
int64_t size = 10000; int64_t size = 10000;
SBloomFilter *pBF4 = tBloomFilterInit(size, 0.001); SBloomFilter *pBF4 = tBloomFilterInit(size, 0.001);
for(int64_t i = 0; i < 1000; i++) { for (int64_t i = 0; i < 1000; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
GTEST_ASSERT_EQ(tBloomFilterPut(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); GTEST_ASSERT_EQ(tBloomFilterPut(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS);
} }
ASSERT_TRUE(!tBloomFilterIsFull(pBF4)); ASSERT_TRUE(!tBloomFilterIsFull(pBF4));
for(int64_t i = 0; i < 1000; i++) { for (int64_t i = 0; i < 1000; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
GTEST_ASSERT_EQ(tBloomFilterNoContain(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_FAILED); GTEST_ASSERT_EQ(tBloomFilterNoContain(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_FAILED);
} }
for(int64_t i = 2000; i < 3000; i++) { for (int64_t i = 2000; i < 3000; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
GTEST_ASSERT_EQ(tBloomFilterNoContain(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); GTEST_ASSERT_EQ(tBloomFilterNoContain(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS);
} }
...@@ -55,7 +55,6 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) { ...@@ -55,7 +55,6 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) {
tBloomFilterDestroy(pBF2); tBloomFilterDestroy(pBF2);
tBloomFilterDestroy(pBF3); tBloomFilterDestroy(pBF3);
tBloomFilterDestroy(pBF4); tBloomFilterDestroy(pBF4);
} }
TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) { TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) {
...@@ -70,71 +69,69 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) { ...@@ -70,71 +69,69 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) {
GTEST_ASSERT_EQ(pSBF1->numBits, 1152); GTEST_ASSERT_EQ(pSBF1->numBits, 1152);
int64_t count = 0; int64_t count = 0;
int64_t index = 0; int64_t index = 0;
for( ; count < 100; index++) { for (; count < 100; index++) {
int64_t ts = index + ts1; int64_t ts = index + ts1;
if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { if (tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
count++; count++;
} }
} }
GTEST_ASSERT_EQ(pSBF1->numBits, 1152); GTEST_ASSERT_EQ(pSBF1->numBits, 1152);
for( ; count < 300; index++) { for (; count < 300; index++) {
int64_t ts = index + ts1; int64_t ts = index + ts1;
if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { if (tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
count++; count++;
} }
} }
GTEST_ASSERT_EQ(pSBF1->numBits, 1152+2496); GTEST_ASSERT_EQ(pSBF1->numBits, 1152 + 2496);
for( ; count < 700; index++) { for (; count < 700; index++) {
int64_t ts = index + ts1; int64_t ts = index + ts1;
if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { if (tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
count++; count++;
} }
} }
GTEST_ASSERT_EQ(pSBF1->numBits, 1152+2496+5568); GTEST_ASSERT_EQ(pSBF1->numBits, 1152 + 2496 + 5568);
for( ; count < 1500; index++) { for (; count < 1500; index++) {
int64_t ts = index + ts1; int64_t ts = index + ts1;
if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) { if (tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
count++; count++;
} }
} }
GTEST_ASSERT_EQ(pSBF1->numBits, 1152+2496+5568+12288); GTEST_ASSERT_EQ(pSBF1->numBits, 1152 + 2496 + 5568 + 12288);
int32_t aSize = taosArrayGetSize(pSBF1->bfArray); int32_t aSize = taosArrayGetSize(pSBF1->bfArray);
int64_t totalBits = 0; int64_t totalBits = 0;
for(int64_t i = 0; i < aSize; i++) { for (int64_t i = 0; i < aSize; i++) {
SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF1->bfArray, i); SBloomFilter *pBF = (SBloomFilter *)taosArrayGetP(pSBF1->bfArray, i);
ASSERT_TRUE(tBloomFilterIsFull(pBF)); ASSERT_TRUE(tBloomFilterIsFull(pBF));
totalBits += pBF->numBits; totalBits += pBF->numBits;
} }
GTEST_ASSERT_EQ(pSBF1->numBits, totalBits); GTEST_ASSERT_EQ(pSBF1->numBits, totalBits);
for(int64_t i = 0; i < index; i++) { for (int64_t i = 0; i < index; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF1, &ts, sizeof(int64_t)), TSDB_CODE_FAILED); GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF1, &ts, sizeof(int64_t)), TSDB_CODE_FAILED);
} }
int64_t size = 10000; int64_t size = 10000;
SScalableBf *pSBF4 = tScalableBfInit(size, 0.001); SScalableBf *pSBF4 = tScalableBfInit(size, 0.001);
for(int64_t i = 0; i < 1000; i++) { for (int64_t i = 0; i < 1000; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
GTEST_ASSERT_EQ(tScalableBfPut(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); GTEST_ASSERT_EQ(tScalableBfPut(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS);
} }
for(int64_t i = 0; i < 1000; i++) { for (int64_t i = 0; i < 1000; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_FAILED); GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_FAILED);
} }
for(int64_t i = 2000; i < 3000; i++) { for (int64_t i = 2000; i < 3000; i++) {
int64_t ts = i + ts1; int64_t ts = i + ts1;
GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS); GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS);
} }
tScalableBfDestroy(pSBF1); tScalableBfDestroy(pSBF1);
tScalableBfDestroy(pSBF4); tScalableBfDestroy(pSBF4);
} }
\ No newline at end of file
此差异已折叠。
...@@ -25,7 +25,7 @@ void simpleTest() { ...@@ -25,7 +25,7 @@ void simpleTest() {
SIDList list = getDataBufPagesIdList(pBuf); SIDList list = getDataBufPagesIdList(pBuf);
ASSERT_EQ(taosArrayGetSize(list), 1); ASSERT_EQ(taosArrayGetSize(list), 1);
//ASSERT_EQ(getNumOfBufGroupId(pBuf), 1); // ASSERT_EQ(getNumOfBufGroupId(pBuf), 1);
releaseBufPage(pBuf, pBufPage); releaseBufPage(pBuf, pBufPage);
...@@ -57,7 +57,7 @@ void simpleTest() { ...@@ -57,7 +57,7 @@ void simpleTest() {
void writeDownTest() { void writeDownTest() {
SDiskbasedBuf* pBuf = NULL; SDiskbasedBuf* pBuf = NULL;
int32_t ret = createDiskbasedBuf(&pBuf, 1024, 4*1024, "1", TD_TMP_DIR_PATH); int32_t ret = createDiskbasedBuf(&pBuf, 1024, 4 * 1024, "1", TD_TMP_DIR_PATH);
int32_t pageId = 0; int32_t pageId = 0;
int32_t writePageId = 0; int32_t writePageId = 0;
...@@ -106,7 +106,7 @@ void writeDownTest() { ...@@ -106,7 +106,7 @@ void writeDownTest() {
void recyclePageTest() { void recyclePageTest() {
SDiskbasedBuf* pBuf = NULL; SDiskbasedBuf* pBuf = NULL;
int32_t ret = createDiskbasedBuf(&pBuf, 1024, 4*1024, "1", TD_TMP_DIR_PATH); int32_t ret = createDiskbasedBuf(&pBuf, 1024, 4 * 1024, "1", TD_TMP_DIR_PATH);
int32_t pageId = 0; int32_t pageId = 0;
int32_t writePageId = 0; int32_t writePageId = 0;
...@@ -159,7 +159,6 @@ void recyclePageTest() { ...@@ -159,7 +159,6 @@ void recyclePageTest() {
} }
} // namespace } // namespace
TEST(testCase, resultBufferTest) { TEST(testCase, resultBufferTest) {
taosSeedRand(taosGetTimestampSec()); taosSeedRand(taosGetTimestampSec());
simpleTest(); simpleTest();
......
此差异已折叠。
...@@ -9,7 +9,8 @@ cd ${PRJ_ROOT_DIR} ...@@ -9,7 +9,8 @@ cd ${PRJ_ROOT_DIR}
FORMAT_DIR_LIST=( FORMAT_DIR_LIST=(
"include" "include"
# "source" "source/os"
"source/util"
) )
for d in ${FORMAT_DIR_LIST[@]}; do for d in ${FORMAT_DIR_LIST[@]}; do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册