more code refact

This commit is contained in:
Hongze Cheng 2022-10-13 11:49:46 +08:00
parent 5a45dab080
commit fcbaa6082b
42 changed files with 2742 additions and 3169 deletions

View File

@ -17,6 +17,7 @@
#define _TD_OS_ENV_H_
#include "osSysinfo.h"
#include "osTimezone.h"
#ifdef __cplusplus
extern "C" {

View File

@ -22,6 +22,8 @@
#ifndef TDIGEST_H
#define TDIGEST_H
#include "os.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288 /* pi */
#endif

View File

@ -193,11 +193,11 @@ void* interlocked_sub_fetch_ptr(void* volatile* ptr, void* val) {
}
int32_t interlocked_fetch_sub_32(int32_t volatile* ptr, int32_t val) { return _InterlockedExchangeAdd(ptr, -val); }
int64_t interlocked_fetch_sub_64(int64_t volatile* ptr, int64_t val) {
int64_t interlocked_fetch_sub_64(int64_t volatile* ptr, int64_t val) {
#ifdef _TD_WINDOWS_32
return _InterlockedExchangeAdd((int32_t volatile*)ptr, -(int32_t)val);
return _InterlockedExchangeAdd((int32_t volatile*)ptr, -(int32_t)val);
#else
return _InterlockedExchangeAdd64(ptr, -val);
return _InterlockedExchangeAdd64(ptr, -val);
#endif
}

View File

@ -31,14 +31,13 @@ typedef struct TdDir {
HANDLE hFind;
} TdDir;
enum
{
WRDE_NOSPACE = 1, /* Ran out of memory. */
WRDE_BADCHAR, /* A metachar appears in the wrong place. */
WRDE_BADVAL, /* Undefined var reference with WRDE_UNDEF. */
WRDE_CMDSUB, /* Command substitution with WRDE_NOCMD. */
WRDE_SYNTAX /* Shell syntax error. */
};
enum {
WRDE_NOSPACE = 1, /* Ran out of memory. */
WRDE_BADCHAR, /* A metachar appears in the wrong place. */
WRDE_BADVAL, /* Undefined var reference with WRDE_UNDEF. */
WRDE_CMDSUB, /* Command substitution with WRDE_NOCMD. */
WRDE_SYNTAX /* Shell syntax error. */
};
int wordexp(char *words, wordexp_t *pwordexp, int flags) {
pwordexp->we_offs = 0;
@ -175,7 +174,7 @@ int32_t taosMulMkDir(const char *dirname) {
#ifdef WINDOWS
code = _mkdir(temp, 0755);
#elif defined(DARWIN)
code = mkdir(dirname, 0777);
code = mkdir(dirname, 0777);
#else
code = mkdir(temp, 0755);
#endif
@ -237,7 +236,7 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) {
#ifdef WINDOWS
code = _mkdir(temp, mode);
#elif defined(DARWIN)
code = mkdir(dirname, 0777);
code = mkdir(dirname, 0777);
#else
code = mkdir(temp, mode);
#endif
@ -301,22 +300,24 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) {
wordexp_t full_path;
switch (wordexp (dirname, &full_path, 0)) {
case 0:
break;
case WRDE_NOSPACE:
wordfree (&full_path);
// printf("failed to expand path:%s since Out of memory\n", dirname);
return -1;
case WRDE_BADCHAR:
// printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n", dirname);
return -1;
case WRDE_SYNTAX:
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched quotes\n", dirname);
return -1;
default:
// printf("failed to expand path:%s since %s\n", dirname, strerror(errno));
return -1;
switch (wordexp(dirname, &full_path, 0)) {
case 0:
break;
case WRDE_NOSPACE:
wordfree(&full_path);
// printf("failed to expand path:%s since Out of memory\n", dirname);
return -1;
case WRDE_BADCHAR:
// printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n",
// dirname);
return -1;
case WRDE_SYNTAX:
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched
// quotes\n", dirname);
return -1;
default:
// printf("failed to expand path:%s since %s\n", dirname, strerror(errno));
return -1;
}
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
@ -417,7 +418,7 @@ TdDirPtr taosOpenDir(const char *dirname) {
DIR *pDir = opendir(dirname);
if (pDir == NULL) return NULL;
TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir));
dirPtr->dirEntryPtr = (TdDirEntryPtr)&(dirPtr->dirEntry1);
dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1);
dirPtr->pDir = pDir;
return dirPtr;
#else
@ -435,7 +436,7 @@ TdDirEntryPtr taosReadDir(TdDirPtr pDir) {
}
return (TdDirEntryPtr) & (pDir->dirEntry.findFileData);
#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;
} else {
return NULL;

View File

@ -35,7 +35,7 @@ int64_t tsOpenMax = 0;
int64_t tsStreamMax = 0;
float tsNumOfCores = 0;
int64_t tsTotalMemoryKB = 0;
char* tsProcPath = NULL;
char *tsProcPath = NULL;
void osDefaultInit() {
taosSeedRand(taosSafeRand());

View File

@ -58,14 +58,14 @@ typedef struct TdFile {
#define FILE_WITH_LOCK 1
typedef struct AutoDelFile * AutoDelFilePtr;
typedef struct AutoDelFile *AutoDelFilePtr;
typedef struct AutoDelFile {
char *name;
AutoDelFilePtr lastAutoDelFilePtr;
char *name;
AutoDelFilePtr lastAutoDelFilePtr;
} AutoDelFile;
static TdThreadMutex autoDelFileLock;
static TdThreadMutex autoDelFileLock;
static AutoDelFilePtr nowAutoDelFilePtr = NULL;
static TdThreadOnce autoDelFileInit = PTHREAD_ONCE_INIT;
static TdThreadOnce autoDelFileInit = PTHREAD_ONCE_INIT;
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) {
#ifdef WINDOWS
@ -205,10 +205,10 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
#ifdef WINDOWS
struct _stati64 fileStat;
int32_t code = _stati64(path, &fileStat);
int32_t code = _stati64(path, &fileStat);
#else
struct stat fileStat;
int32_t code = stat(path, &fileStat);
int32_t code = stat(path, &fileStat);
#endif
if (code < 0) {
return code;
@ -706,11 +706,11 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
int64_t sentbytes;
while (leftbytes > 0) {
#ifdef _TD_ARM_32
sentbytes = sendfile(pFileOut->fd, pFileIn->fd, (long int*)offset, leftbytes);
#else
#ifdef _TD_ARM_32
sentbytes = sendfile(pFileOut->fd, pFileIn->fd, (long int *)offset, leftbytes);
#else
sentbytes = sendfile(pFileOut->fd, pFileIn->fd, offset, leftbytes);
#endif
#endif
if (sentbytes == -1) {
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
continue;

View File

@ -77,7 +77,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
// default locale or user specified locale is not valid, abort launch
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)) {

View File

@ -52,36 +52,38 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
#pragma comment(lib, "dbghelp.lib")
void taosPrintBackTrace() {
#define MAX_STACK_FRAMES 20
void *pStack[MAX_STACK_FRAMES];
HANDLE process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
WORD frames = CaptureStackBackTrace(1, MAX_STACK_FRAMES, pStack, NULL);
#define MAX_STACK_FRAMES 20
void *pStack[MAX_STACK_FRAMES];
HANDLE process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
WORD frames = CaptureStackBackTrace(1, MAX_STACK_FRAMES, pStack, NULL);
char buf_tmp[1024];
for (WORD i = 0; i < frames; ++i) {
DWORD64 address = (DWORD64)(pStack[i]);
DWORD64 displacementSym = 0;
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME;
DWORD displacementLine = 0;
IMAGEHLP_LINE64 line;
//SymSetOptions(SYMOPT_LOAD_LINES);
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
if (SymFromAddr(process, address, &displacementSym, pSymbol) && SymGetLineFromAddr64(process, address, &displacementLine, &line)) {
snprintf(buf_tmp,sizeof(buf_tmp),"BackTrace %08" PRId64 " %s:%d %s\n", taosGetSelfPthreadId(), line.FileName, line.LineNumber, pSymbol->Name);
} else {
snprintf(buf_tmp,sizeof(buf_tmp),"BackTrace error: %d\n",GetLastError());
}
write(1,buf_tmp,strlen(buf_tmp));
}
for (WORD i = 0; i < frames; ++i) {
DWORD64 address = (DWORD64)(pStack[i]);
DWORD64 displacementSym = 0;
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
pSymbol->MaxNameLen = MAX_SYM_NAME;
DWORD displacementLine = 0;
IMAGEHLP_LINE64 line;
// SymSetOptions(SYMOPT_LOAD_LINES);
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
if (SymFromAddr(process, address, &displacementSym, pSymbol) &&
SymGetLineFromAddr64(process, address, &displacementLine, &line)) {
snprintf(buf_tmp, sizeof(buf_tmp), "BackTrace %08" PRId64 " %s:%d %s\n", taosGetSelfPthreadId(), line.FileName,
line.LineNumber, pSymbol->Name);
} else {
snprintf(buf_tmp, sizeof(buf_tmp), "BackTrace error: %d\n", GetLastError());
}
write(1, buf_tmp, strlen(buf_tmp));
}
}
#endif
#else
@ -126,27 +128,26 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
#ifdef USE_ADDR2LINE
#include "osThread.h"
#include "libdwarf.h"
#include "dwarf.h"
#include "libdwarf.h"
#include "osThread.h"
#define DW_PR_DUu "llu"
typedef struct lookup_table
{
Dwarf_Line *table;
Dwarf_Line_Context *ctxts;
int cnt;
Dwarf_Addr low;
Dwarf_Addr high;
typedef struct lookup_table {
Dwarf_Line *table;
Dwarf_Line_Context *ctxts;
int cnt;
Dwarf_Addr low;
Dwarf_Addr high;
} lookup_tableT;
extern int create_lookup_table(Dwarf_Debug dbg, lookup_tableT *lookup_table);
extern int create_lookup_table(Dwarf_Debug dbg, lookup_tableT *lookup_table);
extern void delete_lookup_table(lookup_tableT *lookup_table);
size_t addr = 0;
lookup_tableT lookup_table;
Dwarf_Debug tDbg;
size_t addr = 0;
lookup_tableT lookup_table;
Dwarf_Debug tDbg;
static TdThreadOnce traceThreadInit = PTHREAD_ONCE_INIT;
void endTrace() {
@ -157,7 +158,7 @@ void endTrace() {
}
}
void startTrace() {
int ret;
int ret;
Dwarf_Ptr errarg = 0;
FILE *fp = fopen("/proc/self/maps", "r");
@ -178,7 +179,7 @@ void startTrace() {
atexit(endTrace);
}
static void print_line(Dwarf_Debug dbg, Dwarf_Line line, Dwarf_Addr pc) {
char *linesrc = "??";
char *linesrc = "??";
Dwarf_Unsigned lineno = 0;
if (line) {
@ -189,18 +190,18 @@ static void print_line(Dwarf_Debug dbg, Dwarf_Line line, Dwarf_Addr pc) {
if (line) dwarf_dealloc(dbg, linesrc, DW_DLA_STRING);
}
void taosPrintBackTrace() {
int size = 20;
void **buffer[20];
int size = 20;
void **buffer[20];
Dwarf_Addr pc;
int32_t frame = 0;
void **ebp;
void **ret = NULL;
size_t func_frame_distance = 0;
int32_t frame = 0;
void **ebp;
void **ret = NULL;
size_t func_frame_distance = 0;
taosThreadOnce(&traceThreadInit, startTrace);
if (buffer != NULL && size > 0) {
ebp = taosGetEbp();
ebp = taosGetEbp();
func_frame_distance = (size_t)*ebp - (size_t)ebp;
while (ebp && frame < size && (func_frame_distance < (1ULL << 24)) && (func_frame_distance > 0)) {
ret = ebp + 1;

View File

@ -44,11 +44,11 @@ void taosWaitProc(int32_t pid) {
#endif
}
void taosKillProc(int32_t pid) {
void taosKillProc(int32_t pid) {
#ifdef WINDOWS
assert(0);
#else
kill(pid, SIGINT);
kill(pid, SIGINT);
#endif
}

View File

@ -16,8 +16,8 @@
#define _DEFAULT_SOURCE
#include "os.h"
#ifdef WINDOWS
#include "windows.h"
#include "wincrypt.h"
#include "windows.h"
#else
#include <sys/file.h>
#include <unistd.h>
@ -27,17 +27,17 @@ void taosSeedRand(uint32_t seed) { return srand(seed); }
uint32_t taosRand(void) { return rand(); }
uint32_t taosRandR(uint32_t *pSeed) {
uint32_t taosRandR(uint32_t* pSeed) {
#ifdef WINDOWS
return rand_s(pSeed);
return rand_s(pSeed);
#else
return rand_r(pSeed);
return rand_r(pSeed);
#endif
}
uint32_t taosSafeRand(void) {
#ifdef WINDOWS
uint32_t seed = taosRand();
uint32_t seed = taosRand();
HCRYPTPROV hCryptProv;
if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, 0)) {
if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
@ -51,7 +51,7 @@ uint32_t taosSafeRand(void) {
return seed;
#else
TdFilePtr pFile;
int seed;
int seed;
pFile = taosOpenFile("/dev/urandom", TD_FILE_READ);
if (pFile == NULL) {

View File

@ -47,7 +47,7 @@ void taosDflSignal(int32_t signum) {
signal(signum, SIG_DFL);
}
void taosKillChildOnParentStopped() { }
void taosKillChildOnParentStopped() {}
#else
@ -73,9 +73,9 @@ void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); }
void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); }
void taosKillChildOnParentStopped() {
void taosKillChildOnParentStopped() {
#ifndef _TD_DARWIN_64
prctl(PR_SET_PDEATHSIG, SIGKILL);
prctl(PR_SET_PDEATHSIG, SIGKILL);
#endif
}

View File

@ -17,14 +17,13 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#include <unistd.h>
#endif
void taosSsleep(int32_t s) {
#ifdef WINDOWS
Sleep(1000 * s);
Sleep(1000 * s);
#else
sleep(s);
#endif
@ -32,7 +31,7 @@ void taosSsleep(int32_t s) {
void taosMsleep(int32_t ms) {
#ifdef WINDOWS
Sleep(ms);
Sleep(ms);
#else
usleep(ms * 1000);
#endif
@ -40,14 +39,14 @@ void taosMsleep(int32_t ms) {
void taosUsleep(int32_t us) {
#ifdef WINDOWS
HANDLE timer;
LARGE_INTEGER interval;
interval.QuadPart = (10 * us);
HANDLE timer;
LARGE_INTEGER interval;
interval.QuadPart = (10 * us);
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
timer = CreateWaitableTimer(NULL, TRUE, NULL);
SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
WaitForSingleObject(timer, INFINITE);
CloseHandle(timer);
#else
usleep(us);
#endif

View File

@ -26,10 +26,10 @@ extern int wcswidth(const wchar_t *s, size_t n);
#ifdef WINDOWS
char *strsep(char **stringp, const char *delim) {
char * s;
char *s;
const char *spanp;
int32_t c, sc;
char * tok;
char *tok;
if ((s = *stringp) == NULL) return (NULL);
for (tok = s;;) {
c = *s++;
@ -50,7 +50,7 @@ char *strsep(char **stringp, const char *delim) {
/* Duplicate a string, up to at most size characters */
char *strndup(const char *s, int size) {
size_t l;
char * s2;
char *s2;
l = strlen(s);
if (l > size) l = size;
s2 = malloc(l + 1);
@ -139,7 +139,7 @@ typedef struct {
int8_t inUse;
} SConv;
SConv *gConv = NULL;
SConv *gConv = NULL;
int32_t convUsed = 0;
int32_t gConvMaxNum = 0;
@ -167,7 +167,7 @@ iconv_t taosAcquireConv(int32_t *idx) {
*idx = -1;
return iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
}
while (true) {
int32_t used = atomic_add_fetch_32(&convUsed, 1);
if (used > gConvMaxNum) {
@ -175,7 +175,7 @@ iconv_t taosAcquireConv(int32_t *idx) {
sched_yield();
continue;
}
break;
}

View File

@ -136,7 +136,7 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
FILETIME idleTime;
FILETIME kernelTime;
FILETIME userTime;
bool res = GetSystemTimes(&idleTime, &kernelTime, &userTime);
bool res = GetSystemTimes(&idleTime, &kernelTime, &userTime);
if (res) {
cpuInfo->idle = CompareFileTime(&pre_idleTime, &idleTime);
cpuInfo->system = CompareFileTime(&pre_kernelTime, &kernelTime);
@ -174,14 +174,14 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
#ifdef WINDOWS
FILETIME pre_krnlTm = {0};
FILETIME pre_usrTm = {0};
FILETIME creatTm, exitTm, krnlTm, usrTm;
FILETIME creatTm, exitTm, krnlTm, usrTm;
if (GetThreadTimes(GetCurrentThread(), &creatTm, &exitTm, &krnlTm, &usrTm)) {
if (GetThreadTimes(GetCurrentThread(), &creatTm, &exitTm, &krnlTm, &usrTm)) {
cpuInfo->stime = CompareFileTime(&pre_krnlTm, &krnlTm);
cpuInfo->utime = CompareFileTime(&pre_usrTm, &usrTm);
cpuInfo->cutime = 0;
cpuInfo->cstime = 0;
}
}
#elif defined(DARWIN)
cpuInfo->stime = 0;
cpuInfo->utime = 0;
@ -214,7 +214,6 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
return 0;
}
bool taosCheckSystemIsLittleEnd() {
union check {
int16_t i;
@ -336,12 +335,13 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
#ifdef WINDOWS
char value[100];
char value[100];
DWORD bufferSize = sizeof(value);
RegGetValue(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString", RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
RegGetValue(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "ProcessorNameString",
RRF_RT_ANY, NULL, (PVOID)&value, &bufferSize);
tstrncpy(cpuModel, value, maxLen);
SYSTEM_INFO si;
memset(&si,0,sizeof(SYSTEM_INFO));
memset(&si, 0, sizeof(SYSTEM_INFO));
GetSystemInfo(&si);
*numOfCores = si.dwNumberOfProcessors;
return 0;
@ -416,10 +416,10 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
}
if ((done & 2) == 0) {
*numOfCores = coreCount;
done |= 2;
*numOfCores = coreCount;
done |= 2;
}
return code;
#endif
}
@ -702,7 +702,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
if (pFile == NULL) return -1;
ssize_t _bytes = 0;
char line[1024];
char line[1024];
while (!taosEOFFile(pFile)) {
int64_t o_rbytes = 0;
@ -776,13 +776,14 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
#ifdef WINDOWS
GUID guid;
CoCreateGuid(&guid);
snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
snprintf(uid, uidlen, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6],
guid.Data4[7]);
return 0;
#elif defined(_TD_DARWIN_64)
uuid_t uuid = {0};
char buf[37] = {0};
char buf[37] = {0};
uuid_generate(uuid);
// it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null
uuid_unparse_lower(uuid, buf);
@ -929,7 +930,7 @@ void taosSetCoreDump(bool enable) {
SysNameInfo taosGetSysNameInfo() {
#ifdef WINDOWS
SysNameInfo info = {0};
DWORD dwVersion = GetVersion();
DWORD dwVersion = GetVersion();
char *tmp = NULL;
tmp = getenv("OS");
@ -971,14 +972,17 @@ SysNameInfo taosGetSysNameInfo() {
#endif
}
bool taosCheckCurrentInDll() {
#ifdef WINDOWS
MEMORY_BASIC_INFORMATION mbi;
char path[PATH_MAX] = {0};
GetModuleFileName(((VirtualQuery(taosCheckCurrentInDll,&mbi,sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL), path, PATH_MAX);
char path[PATH_MAX] = {0};
GetModuleFileName(
((VirtualQuery(taosCheckCurrentInDll, &mbi, sizeof(mbi)) != 0) ? (HMODULE)mbi.AllocationBase : NULL), path,
PATH_MAX);
int strLastIndex = strlen(path);
if ((path[strLastIndex-3] == 'd' || path[strLastIndex-3] == 'D') && (path[strLastIndex-2] == 'l' || path[strLastIndex-2] == 'L') && (path[strLastIndex-1] == 'l' || path[strLastIndex-1] == 'L')) {
if ((path[strLastIndex - 3] == 'd' || path[strLastIndex - 3] == 'D') &&
(path[strLastIndex - 2] == 'l' || path[strLastIndex - 2] == 'L') &&
(path[strLastIndex - 1] == 'l' || path[strLastIndex - 1] == 'L')) {
return true;
}
return false;

View File

@ -18,52 +18,52 @@
#include "os.h"
#if defined(WINDOWS)
typedef void (*MainWindows)(int argc,char** argv);
typedef void (*MainWindows)(int argc, char** argv);
MainWindows mainWindowsFunc = NULL;
SERVICE_STATUS ServiceStatus;
SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hServiceStatusHandle;
void WINAPI windowsServiceCtrlHandle(DWORD request) {
switch (request) {
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
raise(SIGINT);
ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError();
printf("failed to send stopped status to windows service: %d",nError);
}
break;
default:
return;
}
void WINAPI windowsServiceCtrlHandle(DWORD request) {
switch (request) {
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
raise(SIGINT);
ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError();
printf("failed to send stopped status to windows service: %d", nError);
}
break;
default:
return;
}
}
void WINAPI mainWindowsService(int argc,char** argv) {
int ret = 0;
ServiceStatus.dwServiceType = SERVICE_WIN32;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
hServiceStatusHandle = RegisterServiceCtrlHandler("taosd", &windowsServiceCtrlHandle);
if (hServiceStatusHandle == 0) {
DWORD nError = GetLastError();
printf("failed to register windows service ctrl handler: %d",nError);
}
void WINAPI mainWindowsService(int argc, char** argv) {
int ret = 0;
ServiceStatus.dwServiceType = SERVICE_WIN32;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
hServiceStatusHandle = RegisterServiceCtrlHandler("taosd", &windowsServiceCtrlHandle);
if (hServiceStatusHandle == 0) {
DWORD nError = GetLastError();
printf("failed to register windows service ctrl handler: %d", nError);
}
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
if (SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError();
printf("failed to send running status to windows service: %d",nError);
}
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
if (SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError();
printf("failed to send running status to windows service: %d", nError);
}
if (mainWindowsFunc != NULL) mainWindowsFunc(argc, argv);
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError();
printf("failed to send stopped status to windows service: %d",nError);
}
if (!SetServiceStatus(hServiceStatusHandle, &ServiceStatus)) {
DWORD nError = GetLastError();
printf("failed to send stopped status to windows service: %d", nError);
}
}
void stratWindowsService(MainWindows mainWindows) {
mainWindowsFunc = mainWindows;
@ -248,7 +248,7 @@ TdCmdPtr taosOpenCmd(const char* cmd) {
#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) {
return -1;
}

View File

@ -17,179 +17,135 @@
#include <pthread.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);
}
int32_t taosThreadAttrDestroy(TdThreadAttr * attr) {
return pthread_attr_destroy(attr);
}
int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { return pthread_attr_destroy(attr); }
int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate) {
int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *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);
}
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);
}
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy) {
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *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);
}
int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize) {
int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) {
return pthread_attr_getstacksize(attr, stacksize);
}
int32_t taosThreadAttrInit(TdThreadAttr * attr) {
return pthread_attr_init(attr);
}
int32_t taosThreadAttrInit(TdThreadAttr *attr) { return pthread_attr_init(attr); }
int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate) {
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t 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);
}
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);
}
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy) {
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t 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);
}
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize) {
int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) {
return pthread_attr_setstacksize(attr, stacksize);
}
int32_t taosThreadCancel(TdThread thread) {
return pthread_cancel(thread);
}
int32_t taosThreadCancel(TdThread thread) { return pthread_cancel(thread); }
int32_t taosThreadCondDestroy(TdThreadCond * cond) {
return pthread_cond_destroy(cond);
}
int32_t taosThreadCondDestroy(TdThreadCond *cond) { return pthread_cond_destroy(cond); }
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr) {
return pthread_cond_init(cond, attr);
}
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { return pthread_cond_init(cond, attr); }
int32_t taosThreadCondSignal(TdThreadCond * cond) {
return pthread_cond_signal(cond);
}
int32_t taosThreadCondSignal(TdThreadCond *cond) { return pthread_cond_signal(cond); }
int32_t taosThreadCondBroadcast(TdThreadCond * cond) {
return pthread_cond_broadcast(cond);
}
int32_t taosThreadCondBroadcast(TdThreadCond *cond) { return pthread_cond_broadcast(cond); }
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex) {
return pthread_cond_wait(cond, mutex);
}
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { return pthread_cond_wait(cond, mutex); }
int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime) {
int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const struct timespec *abstime) {
return pthread_cond_timedwait(cond, mutex, abstime);
}
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr) {
return pthread_condattr_destroy(attr);
}
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) { return pthread_condattr_destroy(attr); }
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared) {
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) {
return pthread_condattr_getpshared(attr, pshared);
}
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr) {
return pthread_condattr_init(attr);
}
int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) { return pthread_condattr_init(attr); }
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared) {
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) {
return pthread_condattr_setpshared(attr, pshared);
}
int32_t taosThreadDetach(TdThread thread) {
return pthread_detach(thread);
}
int32_t taosThreadDetach(TdThread thread) { return pthread_detach(thread); }
int32_t taosThreadEqual(TdThread t1, TdThread t2) {
return pthread_equal(t1, t2);
}
int32_t taosThreadEqual(TdThread t1, TdThread t2) { return pthread_equal(t1, t2); }
void taosThreadExit(void *valuePtr) {
return pthread_exit(valuePtr);
}
void taosThreadExit(void *valuePtr) { return pthread_exit(valuePtr); }
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) {
return pthread_getschedparam(thread, policy, param);
}
void *taosThreadGetSpecific(TdThreadKey key) {
return pthread_getspecific(key);
}
void *taosThreadGetSpecific(TdThreadKey key) { return pthread_getspecific(key); }
int32_t taosThreadJoin(TdThread thread, void **valuePtr) {
return pthread_join(thread, valuePtr);
}
int32_t taosThreadJoin(TdThread thread, void **valuePtr) { return pthread_join(thread, valuePtr); }
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *)) {
int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) {
return pthread_key_create(key, destructor);
}
int32_t taosThreadKeyDelete(TdThreadKey key) {
return pthread_key_delete(key);
}
int32_t taosThreadKeyDelete(TdThreadKey key) { return pthread_key_delete(key); }
int32_t taosThreadKill(TdThread thread, int32_t sig) {
return pthread_kill(thread, sig);
}
int32_t taosThreadKill(TdThread thread, int32_t sig) { return pthread_kill(thread, sig); }
// int32_t taosThreadMutexConsistent(TdThreadMutex* mutex) {
// return pthread_mutex_consistent(mutex);
// }
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex) {
return pthread_mutex_destroy(mutex);
}
int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) { return pthread_mutex_destroy(mutex); }
int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr) {
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) {
return pthread_mutex_init(mutex, attr);
}
int32_t taosThreadMutexLock(TdThreadMutex * mutex) {
return pthread_mutex_lock(mutex);
}
int32_t taosThreadMutexLock(TdThreadMutex *mutex) { return pthread_mutex_lock(mutex); }
// int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime) {
// return pthread_mutex_timedlock(mutex, abstime);
// }
int32_t taosThreadMutexTryLock(TdThreadMutex * mutex) {
return pthread_mutex_trylock(mutex);
}
int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) { return pthread_mutex_trylock(mutex); }
int32_t taosThreadMutexUnlock(TdThreadMutex * mutex) {
return pthread_mutex_unlock(mutex);
}
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { return pthread_mutex_unlock(mutex); }
int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr) {
return pthread_mutexattr_destroy(attr);
}
int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) { return pthread_mutexattr_destroy(attr); }
int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared) {
int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *pshared) {
return pthread_mutexattr_getpshared(attr, pshared);
}
@ -197,15 +153,13 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *p
// 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);
}
int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr) {
return pthread_mutexattr_init(attr);
}
int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) { return pthread_mutexattr_init(attr); }
int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared) {
int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared) {
return pthread_mutexattr_setpshared(attr, pshared);
}
@ -213,25 +167,21 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared)
// 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);
}
int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void)) {
int32_t taosThreadOnce(TdThreadOnce *onceControl, void (*initRoutine)(void)) {
return pthread_once(onceControl, initRoutine);
}
int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock) {
return pthread_rwlock_destroy(rwlock);
}
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { return pthread_rwlock_destroy(rwlock); }
int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr) {
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) {
return pthread_rwlock_init(rwlock, attr);
}
int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_rdlock(rwlock);
}
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { return pthread_rwlock_rdlock(rwlock); }
// int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime) {
// return pthread_rwlock_timedrdlock(rwlock, abstime);
@ -241,103 +191,79 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock) {
// return pthread_rwlock_timedwrlock(rwlock, abstime);
// }
int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_tryrdlock(rwlock);
}
int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) { return pthread_rwlock_tryrdlock(rwlock); }
int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_trywrlock(rwlock);
}
int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) { return pthread_rwlock_trywrlock(rwlock); }
int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_unlock(rwlock);
}
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { return pthread_rwlock_unlock(rwlock); }
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock) {
return pthread_rwlock_wrlock(rwlock);
}
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { return pthread_rwlock_wrlock(rwlock); }
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr) {
return pthread_rwlockattr_destroy(attr);
}
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) { return pthread_rwlockattr_destroy(attr); }
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared) {
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) {
return pthread_rwlockattr_getpshared(attr, pshared);
}
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr) {
return pthread_rwlockattr_init(attr);
}
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) { return pthread_rwlockattr_init(attr); }
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared) {
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared) {
return pthread_rwlockattr_setpshared(attr, pshared);
}
TdThread taosThreadSelf(void) {
return pthread_self();
}
TdThread taosThreadSelf(void) { return pthread_self(); }
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) {
return pthread_setcancelstate(state, oldstate);
}
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate) { return pthread_setcancelstate(state, oldstate); }
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) {
return pthread_setcanceltype(type, oldtype);
}
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { return pthread_setcanceltype(type, oldtype); }
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) {
return pthread_setschedparam(thread, policy, param);
}
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) {
return pthread_setspecific(key, value);
}
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { return pthread_setspecific(key, value); }
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock) {
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_destroy((pthread_mutex_t*)lock);
return pthread_mutex_destroy((pthread_mutex_t *)lock);
#else
return pthread_spin_destroy((pthread_spinlock_t*)lock);
return pthread_spin_destroy((pthread_spinlock_t *)lock);
#endif
}
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared) {
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
assert(pshared == 0);
return pthread_mutex_init((pthread_mutex_t*)lock, NULL);
return pthread_mutex_init((pthread_mutex_t *)lock, NULL);
#else
return pthread_spin_init((pthread_spinlock_t*)lock, pshared);
return pthread_spin_init((pthread_spinlock_t *)lock, pshared);
#endif
}
int32_t taosThreadSpinLock(TdThreadSpinlock * lock) {
int32_t taosThreadSpinLock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_lock((pthread_mutex_t*)lock);
return pthread_mutex_lock((pthread_mutex_t *)lock);
#else
return pthread_spin_lock((pthread_spinlock_t*)lock);
return pthread_spin_lock((pthread_spinlock_t *)lock);
#endif
}
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock) {
int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_trylock((pthread_mutex_t*)lock);
return pthread_mutex_trylock((pthread_mutex_t *)lock);
#else
return pthread_spin_trylock((pthread_spinlock_t*)lock);
return pthread_spin_trylock((pthread_spinlock_t *)lock);
#endif
}
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock) {
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) {
#ifdef TD_USE_SPINLOCK_AS_MUTEX
return pthread_mutex_unlock((pthread_mutex_t*)lock);
return pthread_mutex_unlock((pthread_mutex_t *)lock);
#else
return pthread_spin_unlock((pthread_spinlock_t*)lock);
return pthread_spin_unlock((pthread_spinlock_t *)lock);
#endif
}
void taosThreadTestCancel(void) {
return pthread_testcancel();
}
void taosThreadTestCancel(void) { return pthread_testcancel(); }
void taosThreadClear(TdThread *thread) {
memset(thread, 0, sizeof(TdThread));
}
void taosThreadClear(TdThread *thread) { memset(thread, 0, sizeof(TdThread)); }

View File

@ -44,7 +44,7 @@ static MMRESULT timerId;
static void (*timer_callback)(int);
static int timer_ms = 0;
static TdThread timer_thread;
static TdThread timer_thread;
static int timer_kq = -1;
static volatile int timer_stop = 0;
@ -83,11 +83,11 @@ static void taosDeleteTimer(void *tharg) {
timer_delete(*pTimer);
}
static TdThread timerThread;
static TdThread timerThread;
static timer_t timerId;
static volatile bool stopTimer = false;
static void * taosProcessAlarmSignal(void *tharg) {
// Block the signal
static void *taosProcessAlarmSignal(void *tharg) {
// Block the signal
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
@ -109,7 +109,7 @@ static void * taosProcessAlarmSignal(void *tharg) {
sevent.sigev_signo = SIGALRM;
if (timer_create(CLOCK_REALTIME, &sevent, &timerId) == -1) {
// printf("Failed to create timer");
// printf("Failed to create timer");
}
taosThreadCleanupPush(taosDeleteTimer, &timerId);
@ -121,19 +121,19 @@ static void * taosProcessAlarmSignal(void *tharg) {
ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK;
if (timer_settime(timerId, 0, &ts, NULL)) {
// printf("Failed to init timer");
// printf("Failed to init timer");
return NULL;
}
int signo;
while (!stopTimer) {
if (sigwait(&sigset, &signo)) {
// printf("Failed to wait signal: number %d", signo);
if (sigwait(&sigset, &signo)) {
// printf("Failed to wait signal: number %d", signo);
continue;
}
/* //printf("Signal handling: number %d ......\n", signo); */
/* //printf("Signal handling: number %d ......\n", signo); */
callback(0);
callback(0);
}
taosThreadCleanupPop(1);
@ -167,7 +167,8 @@ int taosInitTimer(void (*callback)(int), int ms) {
r = taosThreadCreate(&timer_thread, NULL, timer_routine, NULL);
if (r) {
fprintf(stderr, "==%s[%d]%s()==failed to create timer thread\n", taosDirEntryBaseName(__FILE__), __LINE__, __func__);
fprintf(stderr, "==%s[%d]%s()==failed to create timer thread\n", taosDirEntryBaseName(__FILE__), __LINE__,
__func__);
// since no caller of this func checks the return value for the moment
abort();
}

File diff suppressed because it is too large Load Diff

View File

@ -175,11 +175,11 @@ void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size
c = compar(key, p);
if (c == 0) {
if (flags == TD_GT){
if (flags == TD_GT) {
lidx = midx + 1;
} else if(flags == TD_LT){
} else if (flags == TD_LT) {
ridx = midx - 1;
}else{
} else {
break;
}
} else if (c < 0) {

View File

@ -19,7 +19,7 @@
#include "taos.h"
#include "taoserror.h"
#define UNIT_NUM_BITS 64
#define UNIT_NUM_BITS 64
#define UNIT_ADDR_NUM_BITS 6
static FORCE_INLINE bool setBit(uint64_t *buf, uint64_t index) {
@ -51,12 +51,12 @@ SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate) {
// ln(2)^2 = 0.480453013918201
// m = - n * ln(P) / ( ln(2) )^2
// 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->size = 0;
// 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->hashFn2 = taosGetDefaultHashFunction(TSDB_DATA_TYPE_NCHAR);
pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t));
@ -69,11 +69,11 @@ SBloomFilter *tBloomFilterInit(uint64_t expectedEntries, double errorRate) {
int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
ASSERT(!tBloomFilterIsFull(pBF));
uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len);
uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len);
bool hasChange = false;
uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len);
uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len);
bool hasChange = false;
const register uint64_t size = pBF->numBits;
uint64_t cbHash = h1;
uint64_t cbHash = h1;
for (uint64_t i = 0; i < pBF->hashFunctions; ++i) {
hasChange |= setBit(pBF->buffer, cbHash % size);
cbHash += h2;
@ -85,12 +85,11 @@ int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
return TSDB_CODE_FAILED;
}
int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf,
uint32_t len) {
uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len);
uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len);
int32_t tBloomFilterNoContain(const SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
uint64_t h1 = (uint64_t)pBF->hashFn1(keyBuf, len);
uint64_t h2 = (uint64_t)pBF->hashFn2(keyBuf, len);
const register uint64_t size = pBF->numBits;
uint64_t cbHash = h1;
uint64_t cbHash = h1;
for (uint64_t i = 0; i < pBF->hashFunctions; ++i) {
if (!getBit(pBF->buffer, cbHash % size)) {
return TSDB_CODE_SUCCESS;
@ -108,21 +107,21 @@ void tBloomFilterDestroy(SBloomFilter *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 (tEncodeU64(pEncoder, pBF->expectedEntries) < 0) return -1;
if (tEncodeU64(pEncoder, pBF->numUnits) < 0) return -1;
if (tEncodeU64(pEncoder, pBF->numBits) < 0) return -1;
if (tEncodeU64(pEncoder, pBF->size) < 0) return -1;
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 (tEncodeDouble(pEncoder, pBF->errorRate) < 0) return -1;
return 0;
}
SBloomFilter* tBloomFilterDecode(SDecoder* pDecoder) {
SBloomFilter *tBloomFilterDecode(SDecoder *pDecoder) {
SBloomFilter *pBF = taosMemoryCalloc(1, sizeof(SBloomFilter));
pBF->buffer = NULL;
if (tDecodeU32(pDecoder, &pBF->hashFunctions) < 0) goto _error;
@ -132,7 +131,7 @@ SBloomFilter* tBloomFilterDecode(SDecoder* pDecoder) {
if (tDecodeU64(pDecoder, &pBF->size) < 0) goto _error;
pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t));
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 (tDecodeDouble(pDecoder, &pBF->errorRate) < 0) goto _error;
@ -145,6 +144,4 @@ _error:
return NULL;
}
bool tBloomFilterIsFull(const SBloomFilter *pBF) {
return pBF->size >= pBF->expectedEntries;
}
bool tBloomFilterIsFull(const SBloomFilter *pBF) { return pBF->size >= pBF->expectedEntries; }

View File

@ -15,8 +15,8 @@
#define _DEFAULT_SOURCE
#include "tcache.h"
#include "taoserror.h"
#include "osThread.h"
#include "taoserror.h"
#include "tlog.h"
#include "tutil.h"
@ -35,7 +35,7 @@ typedef struct SCacheNode {
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
int64_t expireTime; // expire time
void* signature;
void *signature;
struct STrashElem *pTNodeHeader; // point to trash node head
uint16_t keyLen : 15; // max key size: 32kb
bool inTrashcan : 1; // denote if it is in trash or not
@ -279,7 +279,7 @@ static void removeNodeInEntryList(SCacheEntry *pe, SCacheNode *prev, SCacheNode
pNode->pNext = NULL;
pe->num -= 1;
ASSERT((pe->next && pe->num > 0) || (NULL == pe->next && pe->num == 0));
ASSERT((pe->next && pe->num > 0) || (NULL == pe->next && pe->num == 0));
}
static FORCE_INLINE SCacheEntry *doFindEntry(SCacheObj *pCacheObj, const void *key, size_t keyLen) {
@ -660,7 +660,7 @@ void doTraverseElems(SCacheObj *pCacheObj, bool (*fp)(void *param, SCacheNode *p
taosWLockLatch(&pEntry->latch);
SCacheNode **pPre = &pEntry->next;
SCacheNode *pNode = pEntry->next;
SCacheNode *pNode = pEntry->next;
while (pNode != NULL) {
SCacheNode *next = pNode->pNext;
@ -945,7 +945,7 @@ bool taosCacheIterNext(SCacheIter *pIter) {
char *p = pIter->pCurrent[i]->data;
taosCacheRelease(pCacheObj, (void **)&p, false);
pIter->pCurrent[i] = NULL;
}
}
if (pIter->entryIndex + 1 >= pCacheObj->capacity) {
return false;

View File

@ -226,30 +226,30 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) {
// string > number > bool > null
// ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
int32_t compareJsonVal(const void *pLeft, const void *pRight) {
char leftType = *(char*)pLeft;
char rightType = *(char*)pRight;
if(leftType != rightType){
char leftType = *(char *)pLeft;
char rightType = *(char *)pRight;
if (leftType != rightType) {
return leftType > rightType ? 1 : -1;
}
char* realDataLeft = POINTER_SHIFT(pLeft, CHAR_BYTES);
char* realDataRight = POINTER_SHIFT(pRight, CHAR_BYTES);
if(leftType == TSDB_DATA_TYPE_BOOL) {
char *realDataLeft = POINTER_SHIFT(pLeft, CHAR_BYTES);
char *realDataRight = POINTER_SHIFT(pRight, CHAR_BYTES);
if (leftType == TSDB_DATA_TYPE_BOOL) {
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));
}else if(leftType == TSDB_DATA_TYPE_NCHAR){
} else if (leftType == TSDB_DATA_TYPE_NCHAR) {
return compareLenPrefixedWStr(realDataLeft, realDataRight);
}else if(leftType == TSDB_DATA_TYPE_NULL) {
} else if (leftType == TSDB_DATA_TYPE_NULL) {
return 0;
}else{
} else {
assert(0);
return 0;
}
}
int32_t compareInt8Int16(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
int8_t left = GET_INT32_VAL(pLeft);
int16_t right = GET_INT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -257,7 +257,7 @@ int32_t compareInt8Int16(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Int32(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
int8_t left = GET_INT32_VAL(pLeft);
int32_t right = GET_INT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -265,7 +265,7 @@ int32_t compareInt8Int32(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Int64(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
int8_t left = GET_INT32_VAL(pLeft);
int64_t right = GET_INT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -274,7 +274,7 @@ int32_t compareInt8Int64(const void *pLeft, const void *pRight) {
int32_t compareInt8Float(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -289,7 +289,7 @@ int32_t compareInt8Double(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Uint8(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
int8_t left = GET_INT32_VAL(pLeft);
uint8_t right = GET_UINT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -297,7 +297,7 @@ int32_t compareInt8Uint8(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Uint16(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
int8_t left = GET_INT32_VAL(pLeft);
uint16_t right = GET_UINT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -305,7 +305,7 @@ int32_t compareInt8Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Uint32(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
int8_t left = GET_INT32_VAL(pLeft);
uint32_t right = GET_UINT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -313,7 +313,7 @@ int32_t compareInt8Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Uint64(const void *pLeft, const void *pRight) {
int8_t left = GET_INT32_VAL(pLeft);
int8_t left = GET_INT32_VAL(pLeft);
uint64_t right = GET_UINT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -322,7 +322,7 @@ int32_t compareInt8Uint64(const void *pLeft, const void *pRight) {
int32_t compareInt16Int8(const void *pLeft, const void *pRight) {
int16_t left = GET_INT32_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -346,7 +346,7 @@ int32_t compareInt16Int64(const void *pLeft, const void *pRight) {
int32_t compareInt16Float(const void *pLeft, const void *pRight) {
int16_t left = GET_INT32_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -354,7 +354,7 @@ int32_t compareInt16Float(const void *pLeft, const void *pRight) {
int32_t compareInt16Double(const void *pLeft, const void *pRight) {
int16_t left = GET_INT32_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
double right = GET_DOUBLE_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -369,7 +369,7 @@ int32_t compareInt16Uint8(const void *pLeft, const void *pRight) {
}
int32_t compareInt16Uint16(const void *pLeft, const void *pRight) {
int16_t left = GET_INT32_VAL(pLeft);
int16_t left = GET_INT32_VAL(pLeft);
uint16_t right = GET_UINT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -377,7 +377,7 @@ int32_t compareInt16Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareInt16Uint32(const void *pLeft, const void *pRight) {
int16_t left = GET_INT32_VAL(pLeft);
int16_t left = GET_INT32_VAL(pLeft);
uint32_t right = GET_UINT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -385,17 +385,16 @@ int32_t compareInt16Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt16Uint64(const void *pLeft, const void *pRight) {
int16_t left = GET_INT32_VAL(pLeft);
int16_t left = GET_INT32_VAL(pLeft);
uint64_t right = GET_UINT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
}
int32_t compareInt32Int8(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -419,7 +418,7 @@ int32_t compareInt32Int64(const void *pLeft, const void *pRight) {
int32_t compareInt32Float(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -427,7 +426,7 @@ int32_t compareInt32Float(const void *pLeft, const void *pRight) {
int32_t compareInt32Double(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
double right = GET_DOUBLE_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -442,7 +441,7 @@ int32_t compareInt32Uint8(const void *pLeft, const void *pRight) {
}
int32_t compareInt32Uint16(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
int32_t left = GET_INT32_VAL(pLeft);
uint16_t right = GET_UINT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -450,7 +449,7 @@ int32_t compareInt32Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareInt32Uint32(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
int32_t left = GET_INT32_VAL(pLeft);
uint32_t right = GET_UINT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -458,7 +457,7 @@ int32_t compareInt32Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt32Uint64(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
int32_t left = GET_INT32_VAL(pLeft);
uint64_t right = GET_UINT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -467,7 +466,7 @@ int32_t compareInt32Uint64(const void *pLeft, const void *pRight) {
int32_t compareInt64Int8(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -491,7 +490,7 @@ int32_t compareInt64Int32(const void *pLeft, const void *pRight) {
int32_t compareInt64Float(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -499,7 +498,7 @@ int32_t compareInt64Float(const void *pLeft, const void *pRight) {
int32_t compareInt64Double(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
double right = GET_DOUBLE_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -514,7 +513,7 @@ int32_t compareInt64Uint8(const void *pLeft, const void *pRight) {
}
int32_t compareInt64Uint16(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft);
int64_t left = GET_INT64_VAL(pLeft);
uint16_t right = GET_UINT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -522,7 +521,7 @@ int32_t compareInt64Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareInt64Uint32(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft);
int64_t left = GET_INT64_VAL(pLeft);
uint32_t right = GET_UINT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -530,7 +529,7 @@ int32_t compareInt64Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt64Uint64(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft);
int64_t left = GET_INT64_VAL(pLeft);
uint64_t right = GET_UINT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -538,7 +537,7 @@ int32_t compareInt64Uint64(const void *pLeft, const void *pRight) {
}
int32_t compareFloatInt8(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -546,7 +545,7 @@ int32_t compareFloatInt8(const void *pLeft, const void *pRight) {
}
int32_t compareFloatInt16(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
int16_t right = GET_INT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -554,7 +553,7 @@ int32_t compareFloatInt16(const void *pLeft, const void *pRight) {
}
int32_t compareFloatInt32(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
int32_t right = GET_INT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -562,7 +561,7 @@ int32_t compareFloatInt32(const void *pLeft, const void *pRight) {
}
int32_t compareFloatInt64(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
int64_t right = GET_INT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -570,7 +569,7 @@ int32_t compareFloatInt64(const void *pLeft, const void *pRight) {
}
int32_t compareFloatDouble(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
if (isnan(left) && isnan(right)) {
@ -592,7 +591,7 @@ int32_t compareFloatDouble(const void *pLeft, const void *pRight) {
}
int32_t compareFloatUint8(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
uint8_t right = GET_UINT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -600,7 +599,7 @@ int32_t compareFloatUint8(const void *pLeft, const void *pRight) {
}
int32_t compareFloatUint16(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
uint16_t right = GET_UINT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -608,7 +607,7 @@ int32_t compareFloatUint16(const void *pLeft, const void *pRight) {
}
int32_t compareFloatUint32(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
uint32_t right = GET_UINT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -616,7 +615,7 @@ int32_t compareFloatUint32(const void *pLeft, const void *pRight) {
}
int32_t compareFloatUint64(const void *pLeft, const void *pRight) {
float left = GET_FLOAT_VAL(pLeft);
float left = GET_FLOAT_VAL(pLeft);
uint64_t right = GET_UINT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -632,7 +631,7 @@ int32_t compareDoubleInt8(const void *pLeft, const void *pRight) {
}
int32_t compareDoubleInt16(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
double left = GET_DOUBLE_VAL(pLeft);
int16_t right = GET_INT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -640,7 +639,7 @@ int32_t compareDoubleInt16(const void *pLeft, const void *pRight) {
}
int32_t compareDoubleInt32(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
double left = GET_DOUBLE_VAL(pLeft);
int32_t right = GET_INT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -648,7 +647,7 @@ int32_t compareDoubleInt32(const void *pLeft, const void *pRight) {
}
int32_t compareDoubleInt64(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
double left = GET_DOUBLE_VAL(pLeft);
int64_t right = GET_INT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -657,7 +656,7 @@ int32_t compareDoubleInt64(const void *pLeft, const void *pRight) {
int32_t compareDoubleFloat(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (isnan(left) && isnan(right)) {
return 0;
@ -678,7 +677,7 @@ int32_t compareDoubleFloat(const void *pLeft, const void *pRight) {
}
int32_t compareDoubleUint8(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
double left = GET_DOUBLE_VAL(pLeft);
uint8_t right = GET_UINT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -686,7 +685,7 @@ int32_t compareDoubleUint8(const void *pLeft, const void *pRight) {
}
int32_t compareDoubleUint16(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
double left = GET_DOUBLE_VAL(pLeft);
uint16_t right = GET_UINT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -694,7 +693,7 @@ int32_t compareDoubleUint16(const void *pLeft, const void *pRight) {
}
int32_t compareDoubleUint32(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
double left = GET_DOUBLE_VAL(pLeft);
uint32_t right = GET_UINT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -702,7 +701,7 @@ int32_t compareDoubleUint32(const void *pLeft, const void *pRight) {
}
int32_t compareDoubleUint64(const void *pLeft, const void *pRight) {
double left = GET_DOUBLE_VAL(pLeft);
double left = GET_DOUBLE_VAL(pLeft);
uint64_t right = GET_UINT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -711,7 +710,7 @@ int32_t compareDoubleUint64(const void *pLeft, const void *pRight) {
int32_t compareUint8Int8(const void *pLeft, const void *pRight) {
uint8_t left = GET_UINT8_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -743,7 +742,7 @@ int32_t compareUint8Int64(const void *pLeft, const void *pRight) {
int32_t compareUint8Float(const void *pLeft, const void *pRight) {
uint8_t left = GET_UINT8_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -751,14 +750,14 @@ int32_t compareUint8Float(const void *pLeft, const void *pRight) {
int32_t compareUint8Double(const void *pLeft, const void *pRight) {
uint8_t left = GET_UINT8_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
double right = GET_DOUBLE_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
}
int32_t compareUint8Uint16(const void *pLeft, const void *pRight) {
uint8_t left = GET_UINT8_VAL(pLeft);
uint8_t left = GET_UINT8_VAL(pLeft);
uint16_t right = GET_UINT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -766,7 +765,7 @@ int32_t compareUint8Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareUint8Uint32(const void *pLeft, const void *pRight) {
uint8_t left = GET_UINT8_VAL(pLeft);
uint8_t left = GET_UINT8_VAL(pLeft);
uint32_t right = GET_UINT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -774,7 +773,7 @@ int32_t compareUint8Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareUint8Uint64(const void *pLeft, const void *pRight) {
uint8_t left = GET_UINT8_VAL(pLeft);
uint8_t left = GET_UINT8_VAL(pLeft);
uint64_t right = GET_UINT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
@ -783,7 +782,7 @@ int32_t compareUint8Uint64(const void *pLeft, const void *pRight) {
int32_t compareUint16Int8(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -791,7 +790,7 @@ int32_t compareUint16Int8(const void *pLeft, const void *pRight) {
int32_t compareUint16Int16(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft);
int16_t right = GET_INT16_VAL(pRight);
int16_t right = GET_INT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -799,7 +798,7 @@ int32_t compareUint16Int16(const void *pLeft, const void *pRight) {
int32_t compareUint16Int32(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft);
int32_t right = GET_INT32_VAL(pRight);
int32_t right = GET_INT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -807,7 +806,7 @@ int32_t compareUint16Int32(const void *pLeft, const void *pRight) {
int32_t compareUint16Int64(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft);
int64_t right = GET_INT64_VAL(pRight);
int64_t right = GET_INT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -815,7 +814,7 @@ int32_t compareUint16Int64(const void *pLeft, const void *pRight) {
int32_t compareUint16Float(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -823,7 +822,7 @@ int32_t compareUint16Float(const void *pLeft, const void *pRight) {
int32_t compareUint16Double(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
double right = GET_DOUBLE_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -831,7 +830,7 @@ int32_t compareUint16Double(const void *pLeft, const void *pRight) {
int32_t compareUint16Uint8(const void *pLeft, const void *pRight) {
uint16_t left = GET_UINT16_VAL(pLeft);
uint8_t right = GET_UINT8_VAL(pRight);
uint8_t right = GET_UINT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -855,7 +854,7 @@ int32_t compareUint16Uint64(const void *pLeft, const void *pRight) {
int32_t compareUint32Int8(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -863,7 +862,7 @@ int32_t compareUint32Int8(const void *pLeft, const void *pRight) {
int32_t compareUint32Int16(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft);
int16_t right = GET_INT16_VAL(pRight);
int16_t right = GET_INT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -871,7 +870,7 @@ int32_t compareUint32Int16(const void *pLeft, const void *pRight) {
int32_t compareUint32Int32(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft);
int32_t right = GET_INT32_VAL(pRight);
int32_t right = GET_INT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -879,7 +878,7 @@ int32_t compareUint32Int32(const void *pLeft, const void *pRight) {
int32_t compareUint32Int64(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft);
int64_t right = GET_INT64_VAL(pRight);
int64_t right = GET_INT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -887,7 +886,7 @@ int32_t compareUint32Int64(const void *pLeft, const void *pRight) {
int32_t compareUint32Float(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -895,7 +894,7 @@ int32_t compareUint32Float(const void *pLeft, const void *pRight) {
int32_t compareUint32Double(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
double right = GET_DOUBLE_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -903,7 +902,7 @@ int32_t compareUint32Double(const void *pLeft, const void *pRight) {
int32_t compareUint32Uint8(const void *pLeft, const void *pRight) {
uint32_t left = GET_UINT32_VAL(pLeft);
uint8_t right = GET_UINT8_VAL(pRight);
uint8_t right = GET_UINT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -927,7 +926,7 @@ int32_t compareUint32Uint64(const void *pLeft, const void *pRight) {
int32_t compareUint64Int8(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft);
int8_t right = GET_INT8_VAL(pRight);
int8_t right = GET_INT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -935,7 +934,7 @@ int32_t compareUint64Int8(const void *pLeft, const void *pRight) {
int32_t compareUint64Int16(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft);
int16_t right = GET_INT16_VAL(pRight);
int16_t right = GET_INT16_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -943,7 +942,7 @@ int32_t compareUint64Int16(const void *pLeft, const void *pRight) {
int32_t compareUint64Int32(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft);
int32_t right = GET_INT32_VAL(pRight);
int32_t right = GET_INT32_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -951,7 +950,7 @@ int32_t compareUint64Int32(const void *pLeft, const void *pRight) {
int32_t compareUint64Int64(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft);
int64_t right = GET_INT64_VAL(pRight);
int64_t right = GET_INT64_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -959,7 +958,7 @@ int32_t compareUint64Int64(const void *pLeft, const void *pRight) {
int32_t compareUint64Float(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft);
float right = GET_FLOAT_VAL(pRight);
float right = GET_FLOAT_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -967,7 +966,7 @@ int32_t compareUint64Float(const void *pLeft, const void *pRight) {
int32_t compareUint64Double(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft);
double right = GET_DOUBLE_VAL(pRight);
double right = GET_DOUBLE_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -975,7 +974,7 @@ int32_t compareUint64Double(const void *pLeft, const void *pRight) {
int32_t compareUint64Uint8(const void *pLeft, const void *pRight) {
uint64_t left = GET_UINT64_VAL(pLeft);
uint8_t right = GET_UINT8_VAL(pRight);
uint8_t right = GET_UINT8_VAL(pRight);
if (left > right) return 1;
if (left < right) return -1;
return 0;
@ -997,10 +996,7 @@ int32_t compareUint64Uint32(const void *pLeft, const void *pRight) {
return 0;
}
int32_t compareJsonValDesc(const void *pLeft, const void *pRight) {
return compareJsonVal(pRight, pLeft);
}
int32_t compareJsonValDesc(const void *pLeft, const void *pRight) { return compareJsonVal(pRight, pLeft); }
/*
* Compare two strings
* TSDB_MATCH: Match

View File

@ -15,13 +15,13 @@
#define _DEFAULT_SOURCE
#include "tconfig.h"
#include "cJSON.h"
#include "taoserror.h"
#include "tenv.h"
#include "tgrant.h"
#include "tjson.h"
#include "tlog.h"
#include "tutil.h"
#include "tenv.h"
#include "cJSON.h"
#include "tjson.h"
#include "tgrant.h"
#define CFG_NAME_PRINT_LEN 24
#define CFG_SRC_PRINT_LEN 12
@ -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;
switch (pItem->dtype) {
case CFG_DTYPE_BOOL:
@ -629,16 +629,16 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
}
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
char line[1024], *name, *value, *value2, *value3;
char line[1024], *name, *value, *value2, *value3;
int32_t olen, vlen, vlen2, vlen3;
int32_t code = 0;
char **pEnv = environ;
char **pEnv = environ;
line[1023] = 0;
while(*pEnv != NULL) {
while (*pEnv != NULL) {
name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0;
strncpy(line, *pEnv, sizeof(line)-1);
strncpy(line, *pEnv, sizeof(line) - 1);
pEnv++;
taosEnvToCfg(line, line);
@ -676,12 +676,12 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
int32_t code = 0;
int32_t index = 0;
if (envCmd == NULL) return 0;
while (envCmd[index]!=NULL) {
strncpy(buf, envCmd[index], sizeof(buf)-1);
buf[sizeof(buf)-1] = 0;
while (envCmd[index] != NULL) {
strncpy(buf, envCmd[index], sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
taosEnvToCfg(buf, buf);
index++;
name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0;
@ -720,13 +720,13 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
ssize_t _bytes = 0;
const char *filepath = ".env";
if (envFile != NULL && strlen(envFile)>0) {
if (envFile != NULL && strlen(envFile) > 0) {
if (!taosCheckExistFile(envFile)) {
uError("failed to load env file: %s", envFile);
return -1;
}
filepath = envFile;
}else {
} else {
if (!taosCheckExistFile(filepath)) {
uInfo("failed to load env file: %s", filepath);
return 0;
@ -747,7 +747,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
if (_bytes <= 0) {
break;
}
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
taosEnvToCfg(line, line);
paGetToken(line, &name, &olen);
@ -808,7 +808,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
break;
}
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
paGetToken(line, &name, &olen);
if (olen == 0) continue;
@ -918,7 +918,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
uInfo("fail to load apoll url");
return 0;
}
char *p = strchr(url, ':');
if (p == NULL) {
uError("fail to load apoll url: %s, unknown format", url);
@ -939,15 +939,15 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
return -1;
}
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
char *buf = taosMemoryMalloc(fileSize);
char *buf = taosMemoryMalloc(fileSize);
taosLSeekFile(pFile, 0, SEEK_SET);
if(taosReadFile(pFile, buf, fileSize) <= 0) {
if (taosReadFile(pFile, buf, fileSize) <= 0) {
taosCloseFile(&pFile);
uError("load json file error: %s", filepath);
return -1;
}
taosCloseFile(&pFile);
SJson* pJson = tjsonParse(buf);
SJson *pJson = tjsonParse(buf);
if (NULL == pJson) {
const char *jsonParseError = tjsonGetError();
if (jsonParseError != NULL) {
@ -958,8 +958,8 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
taosMemoryFreeClear(buf);
int32_t jsonArraySize = tjsonGetArraySize(pJson);
for(int32_t i = 0; i < jsonArraySize; i++) {
cJSON* item = tjsonGetArrayItem(pJson, i);
for (int32_t i = 0; i < jsonArraySize; i++) {
cJSON *item = tjsonGetArrayItem(pJson, i);
if (item == NULL) break;
char *itemName = NULL, *itemValueString = NULL;
tjsonGetObjectName(item, &itemName);
@ -971,7 +971,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2);
memcpy(cfgLineBuf, itemName, itemNameLen);
cfgLineBuf[itemNameLen] = ' ';
memcpy(&cfgLineBuf[itemNameLen+1], itemValueString, itemValueStringLen);
memcpy(&cfgLineBuf[itemNameLen + 1], itemValueString, itemValueStringLen);
cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0';
paGetToken(cfgLineBuf, &name, &olen);
@ -999,8 +999,8 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
}
tjsonDelete(pJson);
// } else if (strncmp(url, "jsonUrl", 7) == 0) {
// } else if (strncmp(url, "etcdUrl", 7) == 0) {
// } else if (strncmp(url, "jsonUrl", 7) == 0) {
// } else if (strncmp(url, "etcdUrl", 7) == 0) {
} else {
uError("Unsupported url: %s", url);
return -1;
@ -1010,19 +1010,19 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
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;
if (envCmd == NULL) return 0;
while (envCmd[index]!=NULL) {
while (envCmd[index] != NULL) {
if (strncmp(envCmd[index], "TAOS_APOLLO_URL", 14) == 0) {
char *p = strchr(envCmd[index], '=');
if (p != NULL) {
p++;
if (*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");
return 0;
}
@ -1033,8 +1033,8 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
char line[1024];
char **pEnv = environ;
line[1023] = 0;
while(*pEnv != NULL) {
strncpy(line, *pEnv, sizeof(line)-1);
while (*pEnv != NULL) {
strncpy(line, *pEnv, sizeof(line) - 1);
pEnv++;
if (strncmp(line, "TAOS_APOLLO_URL", 14) == 0) {
char *p = strchr(line, '=');
@ -1042,29 +1042,29 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
p++;
if (*p == '\'') {
p++;
p[strlen(p)-1] = '\0';
p[strlen(p) - 1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl);
memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
uInfo("get apollo url from env variables success, apolloUrl=%s", apolloUrl);
return 0;
}
}
}
const char *filepath = ".env";
if (envFile != NULL && strlen(envFile)>0) {
if (envFile != NULL && strlen(envFile) > 0) {
if (!taosCheckExistFile(envFile)) {
uError("failed to load env file: %s", envFile);
return -1;
}
filepath = envFile;
}else {
} else {
if (!taosCheckExistFile(filepath)) {
uInfo("failed to load env file: %s", filepath);
return 0;
}
}
int64_t _bytes;
int64_t _bytes;
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
if (pFile != NULL) {
while (!taosEOFFile(pFile)) {
@ -1072,16 +1072,16 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl
if (_bytes <= 0) {
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) {
char *p = strchr(line, '=');
if (p != NULL) {
p++;
if (*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);
uInfo("get apollo url from env file success");
return 0;

File diff suppressed because it is too large Load Diff

View File

@ -24,296 +24,273 @@
* Copyright (c) 2016, Usman Masood <usmanm at fastmail dot fm>
*/
#include "tdigest.h"
#include "os.h"
#include "osMath.h"
#include "tdigest.h"
#define INTERPOLATE(x, x0, x1) (((x) - (x0)) / ((x1) - (x0)))
//#define INTEGRATED_LOCATION(compression, q) ((compression) * (asin(2 * (q) - 1) + M_PI / 2) / M_PI)
#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 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)
typedef struct SMergeArgs {
TDigest *t;
SCentroid *centroids;
int32_t idx;
double weight_so_far;
double k1;
double min;
double max;
}SMergeArgs;
TDigest *t;
SCentroid *centroids;
int32_t idx;
double weight_so_far;
double k1;
double min;
double max;
} SMergeArgs;
void tdigestAutoFill(TDigest* t, int32_t compression) {
t->centroids = (SCentroid*)((char*)t + sizeof(TDigest));
t->buffered_pts = (SPt*) ((char*)t + sizeof(TDigest) + sizeof(SCentroid) * (int32_t)GET_CENTROID(compression));
void tdigestAutoFill(TDigest *t, int32_t compression) {
t->centroids = (SCentroid *)((char *)t + sizeof(TDigest));
t->buffered_pts = (SPt *)((char *)t + sizeof(TDigest) + sizeof(SCentroid) * (int32_t)GET_CENTROID(compression));
}
TDigest *tdigestNewFrom(void* pBuf, int32_t compression) {
memset(pBuf, 0, (size_t)TDIGEST_SIZE(compression));
TDigest* t = (TDigest*)pBuf;
tdigestAutoFill(t, compression);
TDigest *tdigestNewFrom(void *pBuf, int32_t compression) {
memset(pBuf, 0, (size_t)TDIGEST_SIZE(compression));
TDigest *t = (TDigest *)pBuf;
tdigestAutoFill(t, compression);
t->compression = compression;
t->size = (int64_t)GET_CENTROID(compression);
t->threshold = (int32_t)GET_THRESHOLD(compression);
t->min = DOUBLE_MAX;
t->max = -DOUBLE_MAX;
t->compression = compression;
t->size = (int64_t)GET_CENTROID(compression);
t->threshold = (int32_t)GET_THRESHOLD(compression);
t->min = DOUBLE_MAX;
t->max = -DOUBLE_MAX;
return t;
return t;
}
static int32_t cmpCentroid(const void *a, const void *b) {
SCentroid *c1 = (SCentroid *) a;
SCentroid *c2 = (SCentroid *) b;
if (c1->mean < c2->mean)
return -1;
if (c1->mean > c2->mean)
return 1;
return 0;
SCentroid *c1 = (SCentroid *)a;
SCentroid *c2 = (SCentroid *)b;
if (c1->mean < c2->mean) return -1;
if (c1->mean > c2->mean) return 1;
return 0;
}
static void mergeCentroid(SMergeArgs *args, SCentroid *merge) {
double k2;
SCentroid *c = &args->centroids[args->idx];
double k2;
SCentroid *c = &args->centroids[args->idx];
args->weight_so_far += merge->weight;
k2 = INTEGRATED_LOCATION(args->t->size,
args->weight_so_far / args->t->total_weight);
//idx++
if(k2 - args->k1 > 1 && c->weight > 0) {
if(args->idx + 1 < args->t->size
&& merge->mean != args->centroids[args->idx].mean) {
args->idx++;
}
args->k1 = k2;
args->weight_so_far += merge->weight;
k2 = INTEGRATED_LOCATION(args->t->size, args->weight_so_far / args->t->total_weight);
// idx++
if (k2 - args->k1 > 1 && c->weight > 0) {
if (args->idx + 1 < args->t->size && merge->mean != args->centroids[args->idx].mean) {
args->idx++;
}
args->k1 = k2;
}
c = &args->centroids[args->idx];
if(c->mean == merge->mean) {
c->weight += merge->weight;
} else {
c->weight += merge->weight;
c->mean += (merge->mean - c->mean) * merge->weight / c->weight;
c = &args->centroids[args->idx];
if (c->mean == merge->mean) {
c->weight += merge->weight;
} else {
c->weight += merge->weight;
c->mean += (merge->mean - c->mean) * merge->weight / c->weight;
if (merge->weight > 0) {
args->min = TMIN(merge->mean, args->min);
args->max = TMAX(merge->mean, args->max);
}
if (merge->weight > 0) {
args->min = TMIN(merge->mean, args->min);
args->max = TMAX(merge->mean, args->max);
}
}
}
void tdigestCompress(TDigest *t) {
SCentroid *unmerged_centroids;
int64_t unmerged_weight = 0;
int32_t num_unmerged = t->num_buffered_pts;
int32_t i, j;
SMergeArgs args;
SCentroid *unmerged_centroids;
int64_t unmerged_weight = 0;
int32_t num_unmerged = t->num_buffered_pts;
int32_t i, j;
SMergeArgs args;
if (t->num_buffered_pts <= 0)
return;
if (t->num_buffered_pts <= 0) return;
unmerged_centroids = (SCentroid*)taosMemoryMalloc(sizeof(SCentroid) * t->num_buffered_pts);
for (i = 0; i < num_unmerged; i++) {
SPt *p = t->buffered_pts + i;
SCentroid *c = &unmerged_centroids[i];
c->mean = p->value;
c->weight = p->weight;
unmerged_weight += c->weight;
unmerged_centroids = (SCentroid *)taosMemoryMalloc(sizeof(SCentroid) * t->num_buffered_pts);
for (i = 0; i < num_unmerged; i++) {
SPt *p = t->buffered_pts + i;
SCentroid *c = &unmerged_centroids[i];
c->mean = p->value;
c->weight = p->weight;
unmerged_weight += c->weight;
}
t->num_buffered_pts = 0;
t->total_weight += unmerged_weight;
taosSort(unmerged_centroids, num_unmerged, sizeof(SCentroid), cmpCentroid);
memset(&args, 0, sizeof(SMergeArgs));
args.centroids = (SCentroid *)taosMemoryMalloc((size_t)(sizeof(SCentroid) * t->size));
memset(args.centroids, 0, (size_t)(sizeof(SCentroid) * t->size));
args.t = t;
args.min = DOUBLE_MAX;
args.max = -DOUBLE_MAX;
i = 0;
j = 0;
while (i < num_unmerged && j < t->num_centroids) {
SCentroid *a = &unmerged_centroids[i];
SCentroid *b = &t->centroids[j];
if (a->mean <= b->mean) {
mergeCentroid(&args, a);
assert(args.idx < t->size);
i++;
} else {
mergeCentroid(&args, b);
assert(args.idx < t->size);
j++;
}
t->num_buffered_pts = 0;
t->total_weight += unmerged_weight;
}
taosSort(unmerged_centroids, num_unmerged, sizeof(SCentroid), cmpCentroid);
memset(&args, 0, sizeof(SMergeArgs));
args.centroids = (SCentroid*)taosMemoryMalloc((size_t)(sizeof(SCentroid) * t->size));
memset(args.centroids, 0, (size_t)(sizeof(SCentroid) * t->size));
while (i < num_unmerged) {
mergeCentroid(&args, &unmerged_centroids[i++]);
assert(args.idx < t->size);
}
taosMemoryFree((void *)unmerged_centroids);
args.t = t;
args.min = DOUBLE_MAX;
args.max = -DOUBLE_MAX;
while (j < t->num_centroids) {
mergeCentroid(&args, &t->centroids[j++]);
assert(args.idx < t->size);
}
i = 0;
j = 0;
while (i < num_unmerged && j < t->num_centroids) {
SCentroid *a = &unmerged_centroids[i];
SCentroid *b = &t->centroids[j];
if (a->mean <= b->mean) {
mergeCentroid(&args, a);
assert(args.idx < t->size);
i++;
} else {
mergeCentroid(&args, b);
assert(args.idx < t->size);
j++;
}
if (t->total_weight > 0) {
t->min = TMIN(t->min, args.min);
if (args.centroids[args.idx].weight <= 0) {
args.idx--;
}
t->num_centroids = args.idx + 1;
t->max = TMAX(t->max, args.max);
}
while (i < num_unmerged) {
mergeCentroid(&args, &unmerged_centroids[i++]);
assert(args.idx < t->size);
}
taosMemoryFree((void*)unmerged_centroids);
while (j < t->num_centroids) {
mergeCentroid(&args, &t->centroids[j++]);
assert(args.idx < t->size);
}
if (t->total_weight > 0) {
t->min = TMIN(t->min, args.min);
if (args.centroids[args.idx].weight <= 0) {
args.idx--;
}
t->num_centroids = args.idx + 1;
t->max = TMAX(t->max, args.max);
}
memcpy(t->centroids, args.centroids, sizeof(SCentroid) * t->num_centroids);
taosMemoryFree((void*)args.centroids);
memcpy(t->centroids, args.centroids, sizeof(SCentroid) * t->num_centroids);
taosMemoryFree((void *)args.centroids);
}
void tdigestAdd(TDigest* t, double x, int64_t w) {
if (w == 0)
return;
void tdigestAdd(TDigest *t, double x, int64_t w) {
if (w == 0) return;
int32_t i = t->num_buffered_pts;
if(i > 0 && t->buffered_pts[i-1].value == x ) {
t->buffered_pts[i].weight = w;
} else {
t->buffered_pts[i].value = x;
t->buffered_pts[i].weight = w;
t->num_buffered_pts++;
}
int32_t i = t->num_buffered_pts;
if (i > 0 && t->buffered_pts[i - 1].value == x) {
t->buffered_pts[i].weight = w;
} else {
t->buffered_pts[i].value = x;
t->buffered_pts[i].weight = w;
t->num_buffered_pts++;
}
if (t->num_buffered_pts >= t->threshold)
tdigestCompress(t);
if (t->num_buffered_pts >= t->threshold) tdigestCompress(t);
}
double tdigestCDF(TDigest *t, double x) {
if (t == NULL)
return 0;
if (t == NULL) return 0;
int32_t i;
double left, right;
int64_t weight_so_far;
SCentroid *a, *b, tmp;
int32_t i;
double left, right;
int64_t weight_so_far;
SCentroid *a, *b, tmp;
tdigestCompress(t);
if (t->num_centroids == 0)
return NAN;
if (x < t->min)
return 0;
if (x > t->max)
return 1;
if (t->num_centroids == 1) {
if (FLOAT_EQ(t->max, t->min))
return 0.5;
tdigestCompress(t);
if (t->num_centroids == 0) return NAN;
if (x < t->min) return 0;
if (x > t->max) return 1;
if (t->num_centroids == 1) {
if (FLOAT_EQ(t->max, t->min)) return 0.5;
return INTERPOLATE(x, t->min, t->max);
}
return INTERPOLATE(x, t->min, t->max);
}
weight_so_far = 0;
a = b = &tmp;
b->mean = t->min;
b->weight = 0;
right = 0;
weight_so_far = 0;
a = b = &tmp;
b->mean = t->min;
b->weight = 0;
right = 0;
for (i = 0; i < t->num_centroids; i++) {
SCentroid *c = &t->centroids[i];
left = b->mean - (a->mean + right);
a = b;
b = c;
right = (b->mean - a->mean) * a->weight / (a->weight + b->weight);
if (x < a->mean + right) {
double cdf = (weight_so_far
+ a->weight
* INTERPOLATE(x, a->mean - left, a->mean + right))
/ t->total_weight;
return TMAX(cdf, 0.0);
}
weight_so_far += a->weight;
}
for (i = 0; i < t->num_centroids; i++) {
SCentroid *c = &t->centroids[i];
left = b->mean - (a->mean + right);
a = b;
right = t->max - a->mean;
b = c;
right = (b->mean - a->mean) * a->weight / (a->weight + b->weight);
if (x < a->mean + right) {
return (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right))
/ t->total_weight;
double cdf = (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right)) / t->total_weight;
return TMAX(cdf, 0.0);
}
return 1;
weight_so_far += a->weight;
}
left = b->mean - (a->mean + right);
a = b;
right = t->max - a->mean;
if (x < a->mean + right) {
return (weight_so_far + a->weight * INTERPOLATE(x, a->mean - left, a->mean + right)) / t->total_weight;
}
return 1;
}
double tdigestQuantile(TDigest *t, double q) {
if (t == NULL)
return 0;
if (t == NULL) return 0;
int32_t i;
double left, right, idx;
int64_t weight_so_far;
SCentroid *a, *b, tmp;
int32_t i;
double left, right, idx;
int64_t weight_so_far;
SCentroid *a, *b, tmp;
tdigestCompress(t);
if (t->num_centroids == 0)
return NAN;
if (t->num_centroids == 1)
return t->centroids[0].mean;
if (FLOAT_EQ(q, 0.0))
return t->min;
if (FLOAT_EQ(q, 1.0))
return t->max;
tdigestCompress(t);
if (t->num_centroids == 0) return NAN;
if (t->num_centroids == 1) return t->centroids[0].mean;
if (FLOAT_EQ(q, 0.0)) return t->min;
if (FLOAT_EQ(q, 1.0)) return t->max;
idx = q * t->total_weight;
weight_so_far = 0;
b = &tmp;
b->mean = t->min;
b->weight = 0;
right = t->min;
idx = q * t->total_weight;
weight_so_far = 0;
b = &tmp;
b->mean = t->min;
b->weight = 0;
right = t->min;
for (i = 0; i < t->num_centroids; i++) {
SCentroid *c = &t->centroids[i];
a = b;
left = right;
b = c;
right = (b->weight * a->mean + a->weight * b->mean)/ (a->weight + b->weight);
if (idx < weight_so_far + a->weight) {
double p = (idx - weight_so_far) / a->weight;
return left * (1 - p) + right * p;
}
weight_so_far += a->weight;
}
left = right;
for (i = 0; i < t->num_centroids; i++) {
SCentroid *c = &t->centroids[i];
a = b;
right = t->max;
left = right;
if (idx < weight_so_far + a->weight && a->weight != 0) {
double p = (idx - weight_so_far) / a->weight;
return left * (1 - p) + right * p;
b = c;
right = (b->weight * a->mean + a->weight * b->mean) / (a->weight + b->weight);
if (idx < weight_so_far + a->weight) {
double p = (idx - weight_so_far) / a->weight;
return left * (1 - p) + right * p;
}
weight_so_far += a->weight;
}
return t->max;
left = right;
a = b;
right = t->max;
if (idx < weight_so_far + a->weight && a->weight != 0) {
double p = (idx - weight_so_far) / a->weight;
return left * (1 - p) + right * p;
}
return t->max;
}
void tdigestMerge(TDigest *t1, TDigest *t2) {
// SPoints
int32_t num_pts = t2->num_buffered_pts;
for(int32_t i = num_pts - 1; i >= 0; i--) {
SPt* p = t2->buffered_pts + i;
tdigestAdd(t1, p->value, p->weight);
t2->num_buffered_pts --;
}
// centroids
for (int32_t i = 0; i < t2->num_centroids; i++) {
tdigestAdd(t1, t2->centroids[i].mean, t2->centroids[i].weight);
}
// SPoints
int32_t num_pts = t2->num_buffered_pts;
for (int32_t i = num_pts - 1; i >= 0; i--) {
SPt *p = t2->buffered_pts + i;
tdigestAdd(t1, p->value, p->weight);
t2->num_buffered_pts--;
}
// centroids
for (int32_t i = 0; i < t2->num_centroids; i++) {
tdigestAdd(t1, t2->centroids[i].mean, t2->centroids[i].weight);
}
}

View File

@ -59,12 +59,12 @@ int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
}
if (cfgStr != envStr) strcpy(cfgStr, envStr);
char *p = strchr(cfgStr, '=');
if (p != NULL) {
char buf[CFG_NAME_MAX_LEN];
if (*(p+1) == '\'') {
*(p+1)= ' ';
char *pEnd = &cfgStr[strlen(cfgStr)-1];
if (*(p + 1) == '\'') {
*(p + 1) = ' ';
char *pEnd = &cfgStr[strlen(cfgStr) - 1];
if (*pEnd == '\'') *pEnd = '\0';
}
*p = '\0';

View File

@ -333,7 +333,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo
// disable resize
taosHashRLock(pHashObj);
uint32_t slot = HASH_INDEX(hashVal, pHashObj->capacity);
uint32_t slot = HASH_INDEX(hashVal, pHashObj->capacity);
SHashEntry *pe = pHashObj->hashList[slot];
taosHashEntryWLock(pHashObj, pe);
@ -890,5 +890,3 @@ void *taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen) {
void taosHashRelease(SHashObj *pHashObj, void *p) { taosHashCancelIterate(pHashObj, p); }
int64_t taosHashGetCompTimes(SHashObj *pHashObj) { return atomic_load_64(&pHashObj->compTimes); }

View File

@ -14,13 +14,13 @@
*/
#define _DEFAULT_SOURCE
#include "thash.h"
#include "tcompare.h"
#include "thash.h"
#include "types.h"
#define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r)))
#define DLT (FLT_COMPAR_TOL_FACTOR * FLT_EPSILON)
#define DLT (FLT_COMPAR_TOL_FACTOR * FLT_EPSILON)
#define BASE 1000
#define FMIX32(h) \
@ -29,11 +29,12 @@
(h) *= 0x85ebca6b; \
(h) ^= (h) >> 13; \
(h) *= 0xc2b2ae35; \
(h) ^= (h) >> 16; } while (0)
(h) ^= (h) >> 16; \
} while (0)
uint32_t MurmurHash3_32(const char *key, uint32_t len) {
const uint8_t *data = (const uint8_t *)key;
const int32_t nblocks = len >> 2u;
const int32_t nblocks = len >> 2u;
uint32_t h1 = 0x12345678;
@ -80,14 +81,14 @@ uint32_t MurmurHash3_32(const char *key, uint32_t len) {
uint64_t MurmurHash3_64(const char *key, uint32_t len) {
const uint64_t m = 0x87c37b91114253d5;
const int r = 47;
uint32_t seed = 0x12345678;
uint64_t h = seed ^ (len * m);
const int r = 47;
uint32_t seed = 0x12345678;
uint64_t h = seed ^ (len * m);
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) {
uint64_t k = *((uint64_t*)data);
while (data != end) {
uint64_t k = *((uint64_t *)data);
k *= m;
k ^= k >> r;
@ -97,14 +98,21 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) {
data += 8;
}
switch(len & 7) {
case 7: h ^= (uint64_t)data[6] << 48; /* fall-thru */
case 6: h ^= (uint64_t)data[5] << 40; /* fall-thru */
case 5: h ^= (uint64_t)data[4] << 32; /* fall-thru */
case 4: h ^= (uint64_t)data[3] << 24; /* fall-thru */
case 3: h ^= (uint64_t)data[2] << 16; /* fall-thru */
case 2: h ^= (uint64_t)data[1] << 8; /* fall-thru */
case 1: h ^= (uint64_t)data[0];
switch (len & 7) {
case 7:
h ^= (uint64_t)data[6] << 48; /* fall-thru */
case 6:
h ^= (uint64_t)data[5] << 40; /* fall-thru */
case 5:
h ^= (uint64_t)data[4] << 32; /* fall-thru */
case 4:
h ^= (uint64_t)data[3] << 24; /* fall-thru */
case 3:
h ^= (uint64_t)data[2] << 16; /* fall-thru */
case 2:
h ^= (uint64_t)data[1] << 8; /* fall-thru */
case 1:
h ^= (uint64_t)data[0];
h *= m; /* fall-thru */
};
@ -126,11 +134,11 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (FLT_EQUAL(f, 0.0)) {
return 0;
}
if (fabs(f) < FLT_MAX/BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT)));
return (uint32_t)t;
if (fabs(f) < FLT_MAX / BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT)));
return (uint32_t)t;
} else {
return 0x7fc00000;
return 0x7fc00000;
}
}
uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) {
@ -142,11 +150,11 @@ uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (FLT_EQUAL(f, 0.0)) {
return 0;
}
if (fabs(f) < DBL_MAX/BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT)));
return (uint32_t)t;
if (fabs(f) < DBL_MAX / BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT)));
return (uint32_t)t;
} else {
return 0x7fc00000;
return 0x7fc00000;
}
}
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 fn = NULL;
switch(type) {
switch (type) {
case TSDB_DATA_TYPE_TIMESTAMP:
case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_BIGINT:
@ -210,9 +218,15 @@ int32_t taosDoubleEqual(const void *a, const void *b, size_t UNUSED_PARAM(sz)) {
_equal_fn_t taosGetDefaultEqualFunction(int32_t type) {
_equal_fn_t fn = NULL;
switch (type) {
case TSDB_DATA_TYPE_FLOAT: fn = taosFloatEqual; break;
case TSDB_DATA_TYPE_DOUBLE: fn = taosDoubleEqual; break;
default: fn = memcmp; break;
case TSDB_DATA_TYPE_FLOAT:
fn = taosFloatEqual;
break;
case TSDB_DATA_TYPE_DOUBLE:
fn = taosDoubleEqual;
break;
default:
fn = memcmp;
break;
}
return fn;
}

View File

@ -19,12 +19,12 @@
#include "tutil.h"
typedef struct {
int32_t numOfFree; /* number of free slots */
int32_t first; /* the first free slot */
int32_t numOfBlock; /* the number of blocks */
int32_t blockSize; /* block size in bytes */
int32_t *freeList; /* the index list */
char *pool; /* the actual mem block */
int32_t numOfFree; /* number of free slots */
int32_t first; /* the first free slot */
int32_t numOfBlock; /* the number of blocks */
int32_t blockSize; /* block size in bytes */
int32_t *freeList; /* the index list */
char *pool; /* the actual mem block */
TdThreadMutex mutex;
} pool_t;

View File

@ -42,13 +42,14 @@ struct SDiskbasedBuf {
bool comp; // compressed before flushed to disk
uint64_t nextPos; // next page flush position
char* id; // for debug purpose
bool printStatis; // Print statistics info when closing this buffer.
char* id; // for debug purpose
bool printStatis; // Print statistics info when closing this buffer.
SDiskbasedBufStatis statis;
};
static int32_t createDiskFile(SDiskbasedBuf* pBuf) {
pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
pBuf->pFile =
taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
if (pBuf->pFile == NULL) {
return TAOS_SYSTEM_ERROR(errno);
}
@ -247,12 +248,12 @@ static SPageInfo* registerPage(SDiskbasedBuf* pBuf, int32_t pageId) {
SPageInfo* ppi = taosMemoryMalloc(sizeof(SPageInfo));
ppi->pageId = pageId;
ppi->pData = NULL;
ppi->pData = NULL;
ppi->offset = -1;
ppi->length = -1;
ppi->used = true;
ppi->pn = NULL;
ppi->dirty = false;
ppi->used = true;
ppi->pn = NULL;
ppi->dirty = false;
return *(SPageInfo**)taosArrayPush(pBuf->pIdList, &ppi);
}
@ -318,7 +319,7 @@ static void lruListMoveToFront(SList* pList, SPageInfo* pi) {
}
static SPageInfo* getPageInfoFromPayload(void* page) {
char* p = (char *)page - POINTER_BYTES;
char* p = (char*)page - POINTER_BYTES;
SPageInfo* ppi = ((SPageInfo**)p)[0];
return ppi;
@ -334,12 +335,12 @@ int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMem
}
pPBuf->pageSize = pagesize;
pPBuf->numOfPages = 0; // all pages are in buffer in the first place
pPBuf->numOfPages = 0; // all pages are in buffer in the first place
pPBuf->totalBufSize = 0;
pPBuf->inMemPages = inMemBufSize / pagesize; // maximum allowed pages, it is a soft limit.
pPBuf->allocateId = -1;
pPBuf->pFile = NULL;
pPBuf->id = strdup(id);
pPBuf->pFile = NULL;
pPBuf->id = strdup(id);
pPBuf->fileSize = 0;
pPBuf->pFree = taosArrayInit(4, sizeof(SFreeListItem));
pPBuf->freePgList = tdListNew(POINTER_BYTES);
@ -402,14 +403,15 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t* pageId) {
// allocate buf
if (availablePage == NULL) {
pi->pData = taosMemoryCalloc(1, getAllocPageSize(pBuf->pageSize)); // add extract bytes in case of zipped buffer increased.
pi->pData =
taosMemoryCalloc(1, getAllocPageSize(pBuf->pageSize)); // add extract bytes in case of zipped buffer increased.
} else {
pi->pData = availablePage;
}
((void**)pi->pData)[0] = pi;
#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
return (void*)(GET_DATA_PAYLOAD(pi));
}
@ -434,11 +436,12 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
lruListMoveToFront(pBuf->lruList, (*pi));
(*pi)->used = true;
#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
return (void*)(GET_DATA_PAYLOAD(*pi));
} else { // not in memory
assert((*pi)->pData == NULL && (*pi)->pn == NULL && (((*pi)->length >= 0 && (*pi)->offset >= 0) || ((*pi)->length == -1 && (*pi)->offset == -1)));
assert((*pi)->pData == NULL && (*pi)->pn == NULL &&
(((*pi)->length >= 0 && (*pi)->offset >= 0) || ((*pi)->length == -1 && (*pi)->offset == -1)));
char* availablePage = NULL;
if (NO_IN_MEM_AVAILABLE_PAGES(pBuf)) {
@ -468,7 +471,7 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
}
}
#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
return (void*)(GET_DATA_PAYLOAD(*pi));
}
@ -482,7 +485,7 @@ void releaseBufPage(SDiskbasedBuf* pBuf, void* page) {
void releaseBufPageInfo(SDiskbasedBuf* pBuf, SPageInfo* pi) {
#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
// assert(pi->pData != NULL && pi->used == true);
assert(pi->pData != NULL);
@ -520,12 +523,12 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) {
{
SDiskbasedBufStatis* ps = &pBuf->statis;
if (ps->loadPages == 0) {
uDebug(
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages)",
ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages);
uDebug("Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages)", ps->getPages,
ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages);
} else {
uDebug(
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f Kb",
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f "
"Kb",
ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f,
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
}
@ -614,7 +617,8 @@ void dBufPrintStatis(const SDiskbasedBuf* pBuf) {
if (ps->loadPages > 0) {
printf(
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f Kb\n",
"Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f "
"Kb\n",
ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f,
ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages));
} else {
@ -640,7 +644,7 @@ void clearDiskbasedBuf(SDiskbasedBuf* pBuf) {
taosHashClear(pBuf->all);
pBuf->numOfPages = 0; // all pages are in buffer in the first place
pBuf->numOfPages = 0; // all pages are in buffer in the first place
pBuf->totalBufSize = 0;
pBuf->allocateId = -1;
pBuf->fileSize = 0;

View File

@ -18,11 +18,10 @@
#include "tscalablebf.h"
#include "taoserror.h"
#define DEFAULT_GROWTH 2
#define DEFAULT_GROWTH 2
#define DEFAULT_TIGHTENING_RATIO 0.5
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries,
double errorRate);
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, double errorRate);
SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
const uint32_t defaultSize = 8;
@ -35,7 +34,7 @@ SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
}
pSBf->numBits = 0;
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);
return NULL;
}
@ -46,8 +45,7 @@ SScalableBf *tScalableBfInit(uint64_t expectedEntries, double errorRate) {
int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
int32_t size = taosArrayGetSize(pSBf->bfArray);
for (int32_t i = size - 2; i >= 0; --i) {
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i),
keyBuf, len) != TSDB_CODE_SUCCESS) {
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), keyBuf, len) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_FAILED;
}
}
@ -55,8 +53,7 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
SBloomFilter *pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1);
ASSERT(pNormalBf);
if (tBloomFilterIsFull(pNormalBf)) {
pNormalBf = tScalableBfAddFilter(pSBf,
pNormalBf->expectedEntries * pSBf->growth,
pNormalBf = tScalableBfAddFilter(pSBf, pNormalBf->expectedEntries * pSBf->growth,
pNormalBf->errorRate * DEFAULT_TIGHTENING_RATIO);
if (pNormalBf == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
@ -65,25 +62,22 @@ int32_t tScalableBfPut(SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
return tBloomFilterPut(pNormalBf, keyBuf, len);
}
int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf,
uint32_t len) {
int32_t tScalableBfNoContain(const SScalableBf *pSBf, const void *keyBuf, uint32_t len) {
int32_t size = taosArrayGetSize(pSBf->bfArray);
for (int32_t i = size - 1; i >= 0; --i) {
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i),
keyBuf, len) != TSDB_CODE_SUCCESS) {
if (tBloomFilterNoContain(taosArrayGetP(pSBf->bfArray, i), keyBuf, len) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_FAILED;
}
}
return TSDB_CODE_SUCCESS;
}
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries,
double errorRate) {
static SBloomFilter *tScalableBfAddFilter(SScalableBf *pSBf, uint64_t expectedEntries, double errorRate) {
SBloomFilter *pNormalBf = tBloomFilterInit(expectedEntries, errorRate);
if (pNormalBf == NULL) {
return NULL;
}
if(taosArrayPush(pSBf->bfArray, &pNormalBf) == NULL) {
if (taosArrayPush(pSBf->bfArray, &pNormalBf) == NULL) {
tBloomFilterDestroy(pNormalBf);
return NULL;
}
@ -101,7 +95,7 @@ void tScalableBfDestroy(SScalableBf *pSBf) {
taosMemoryFree(pSBf);
}
int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) {
int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder *pEncoder) {
if (!pSBf) {
if (tEncodeI32(pEncoder, 0) < 0) return -1;
return 0;
@ -109,7 +103,7 @@ int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) {
int32_t size = taosArrayGetSize(pSBf->bfArray);
if (tEncodeI32(pEncoder, size) < 0) return -1;
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 (tEncodeU32(pEncoder, pSBf->growth) < 0) return -1;
@ -117,7 +111,7 @@ int32_t tScalableBfEncode(const SScalableBf *pSBf, SEncoder* pEncoder) {
return 0;
}
SScalableBf* tScalableBfDecode(SDecoder* pDecoder) {
SScalableBf *tScalableBfDecode(SDecoder *pDecoder) {
SScalableBf *pSBf = taosMemoryCalloc(1, sizeof(SScalableBf));
pSBf->bfArray = NULL;
int32_t size = 0;
@ -128,7 +122,7 @@ SScalableBf* tScalableBfDecode(SDecoder* pDecoder) {
}
pSBf->bfArray = taosArrayInit(size * 2, sizeof(void *));
for (int32_t i = 0; i < size; i++) {
SBloomFilter* pBF = tBloomFilterDecode(pDecoder);
SBloomFilter *pBF = tBloomFilterDecode(pDecoder);
if (!pBF) goto _error;
taosArrayPush(pSBf->bfArray, &pBF);
}

View File

@ -17,7 +17,7 @@
#include "tthread.h"
TdThread* taosCreateThread(void* (*__start_routine)(void*), void* param) {
TdThread* pthread = (TdThread*)taosMemoryMalloc(sizeof(TdThread));
TdThread* pthread = (TdThread*)taosMemoryMalloc(sizeof(TdThread));
TdThreadAttr thattr;
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);

View File

@ -16,9 +16,9 @@
#define _DEFAULT_SOURCE
#include "ttimer.h"
#include "taoserror.h"
#include "tdef.h"
#include "tlog.h"
#include "tsched.h"
#include "tdef.h"
#define tmrFatal(...) \
{ \
@ -104,21 +104,21 @@ typedef struct timer_map_t {
typedef struct time_wheel_t {
TdThreadMutex mutex;
int64_t nextScanAt;
uint32_t resolution;
uint16_t size;
uint16_t index;
tmr_obj_t** slots;
int64_t nextScanAt;
uint32_t resolution;
uint16_t size;
uint16_t index;
tmr_obj_t** slots;
} time_wheel_t;
static int32_t tsMaxTmrCtrl = TSDB_MAX_VNODES_PER_DB + 100;
static TdThreadOnce tmrModuleInit = PTHREAD_ONCE_INIT;
static TdThreadMutex tmrCtrlMutex;
static tmr_ctrl_t* tmrCtrls;
static tmr_ctrl_t* unusedTmrCtrl = NULL;
static void* tmrQhandle;
static int32_t numOfTmrCtrl = 0;
static tmr_ctrl_t* tmrCtrls;
static tmr_ctrl_t* unusedTmrCtrl = NULL;
static void* tmrQhandle;
static int32_t numOfTmrCtrl = 0;
int32_t taosTmrThreads = 1;
static uintptr_t nextTimerId = 0;
@ -133,7 +133,7 @@ static timer_map_t timerMap;
static uintptr_t getNextTimerId() {
uintptr_t id;
do {
id = (uintptr_t)atomic_add_fetch_ptr((void **)&nextTimerId, 1);
id = (uintptr_t)atomic_add_fetch_ptr((void**)&nextTimerId, 1);
} while (id == 0);
return id;
}

View File

@ -79,7 +79,7 @@ static void *tQWorkerThreadFp(SQWorker *worker) {
uDebug("worker:%s:%d is running", pool->name, worker->id);
while (1) {
if (taosReadQitemFromQset(pool->qset, (void **)&msg, &qinfo) == 0) {
if (taosReadQitemFromQset(pool->qset, (void **)&msg, &qinfo) == 0) {
uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, pool->qset);
break;
}

View File

@ -9,21 +9,21 @@
namespace {
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;
taosArrayPush(pa, &a);
}
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);
int32_t a = 5;
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(*(int*)taosArrayGet(pa, 5), 6);
@ -41,7 +41,7 @@ static void remove_batch_test() {
a = 14;
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);
taosArrayDestroy(pa);
@ -49,24 +49,22 @@ static void remove_batch_test() {
}
} // namespace
TEST(arrayTest, array_list_test) {
remove_batch_test();
}
TEST(arrayTest, array_list_test) { remove_batch_test(); }
TEST(arrayTest, array_search_test) {
SArray *pa = (SArray*) taosArrayInit(4, sizeof(int32_t));
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;
taosArrayPush(pa, &a);
}
for(int i = 0; i < 30; i++) {
int32_t k = i;
for (int i = 0; i < 30; i++) {
int32_t k = i;
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);
} else {
ASSERT_EQ(taosArrayGet(pa, idx), pRet);
@ -75,12 +73,11 @@ TEST(arrayTest, array_search_test) {
pRet = (int32_t*)taosArraySearch(pa, &k, compareInt32Val, TD_LE);
idx = taosArraySearchIdx(pa, &k, compareInt32Val, TD_LE);
if(pRet == NULL) {
if (pRet == NULL) {
ASSERT_EQ(idx, -1);
} else {
ASSERT_EQ(taosArrayGet(pa, idx), pRet);
}
}
taosArrayDestroy(pa);

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include "tscalablebf.h"
#include "taoserror.h"
#include "tscalablebf.h"
using namespace std;
@ -15,38 +15,38 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) {
SBloomFilter *pBF1 = tBloomFilterInit(100, 0.005);
GTEST_ASSERT_EQ(pBF1->numBits, 1152);
GTEST_ASSERT_EQ(pBF1->numUnits, 1152/64);
GTEST_ASSERT_EQ(pBF1->numUnits, 1152 / 64);
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;
if(tBloomFilterPut(pBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) {
if (tBloomFilterPut(pBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
count++;
}
}
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->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->numUnits, 1437758784/64);
int64_t size = 10000;
GTEST_ASSERT_EQ(pBF3->numUnits, 1437758784 / 64);
int64_t size = 10000;
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;
GTEST_ASSERT_EQ(tBloomFilterPut(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS);
}
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;
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;
GTEST_ASSERT_EQ(tBloomFilterNoContain(pBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS);
}
@ -55,7 +55,6 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, normal_bloomFilter) {
tBloomFilterDestroy(pBF2);
tBloomFilterDestroy(pBF3);
tBloomFilterDestroy(pBF4);
}
TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) {
@ -70,71 +69,69 @@ TEST(TD_UTIL_BLOOMFILTER_TEST, scalable_bloomFilter) {
GTEST_ASSERT_EQ(pSBF1->numBits, 1152);
int64_t count = 0;
int64_t index = 0;
for( ; count < 100; index++) {
for (; count < 100; index++) {
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++;
}
}
GTEST_ASSERT_EQ(pSBF1->numBits, 1152);
for( ; count < 300; index++) {
for (; count < 300; index++) {
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++;
}
}
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;
if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) {
if (tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
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;
if(tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS ) {
if (tScalableBfPut(pSBF1, &ts, sizeof(int64_t)) == TSDB_CODE_SUCCESS) {
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);
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);
ASSERT_TRUE(tBloomFilterIsFull(pBF));
ASSERT_TRUE(tBloomFilterIsFull(pBF));
totalBits += pBF->numBits;
}
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;
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);
for(int64_t i = 0; i < 1000; i++) {
for (int64_t i = 0; i < 1000; i++) {
int64_t ts = i + ts1;
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;
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;
GTEST_ASSERT_EQ(tScalableBfNoContain(pSBF4, &ts, sizeof(int64_t)), TSDB_CODE_SUCCESS);
}
tScalableBfDestroy(pSBF1);
tScalableBfDestroy(pSBF4);
}

View File

@ -3,162 +3,163 @@
#include <iostream>
#include "os.h"
#include "taos.h"
#include "taosdef.h"
#include "thash.h"
#include "taos.h"
namespace {
typedef struct TESTSTRUCT {
char *p;
}TESTSTRUCT;
char* p;
} TESTSTRUCT;
// the simple test code for basic operations
void simpleTest() {
SHashObj* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
SHashObj* hashTable =
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
ASSERT_EQ(taosHashGetSize(hashTable), 0);
// put 400 elements in the hash table
for(int32_t i = -200; i < 200; ++i) {
taosHashPut(hashTable, (const char*) &i, sizeof(int32_t), (char*) &i, sizeof(int32_t));
for (int32_t i = -200; i < 200; ++i) {
taosHashPut(hashTable, (const char*)&i, sizeof(int32_t), (char*)&i, sizeof(int32_t));
}
ASSERT_EQ(taosHashGetSize(hashTable), 400);
for(int32_t i = 0; i < 200; ++i) {
char* p = (char*) taosHashGet(hashTable, (const char*) &i, sizeof(int32_t));
for (int32_t i = 0; i < 200; ++i) {
char* p = (char*)taosHashGet(hashTable, (const char*)&i, sizeof(int32_t));
ASSERT_TRUE(p != nullptr);
ASSERT_EQ(*reinterpret_cast<int32_t*>(p), i);
}
for(int32_t i = 1000; i < 2000; ++i) {
taosHashRemove(hashTable, (const char*) &i, sizeof(int32_t));
for (int32_t i = 1000; i < 2000; ++i) {
taosHashRemove(hashTable, (const char*)&i, sizeof(int32_t));
}
ASSERT_EQ(taosHashGetSize(hashTable), 400);
for(int32_t i = 0; i < 100; ++i) {
taosHashRemove(hashTable, (const char*) &i, sizeof(int32_t));
for (int32_t i = 0; i < 100; ++i) {
taosHashRemove(hashTable, (const char*)&i, sizeof(int32_t));
}
ASSERT_EQ(taosHashGetSize(hashTable), 300);
for(int32_t i = 100; i < 150; ++i) {
taosHashRemove(hashTable, (const char*) &i, sizeof(int32_t));
for (int32_t i = 100; i < 150; ++i) {
taosHashRemove(hashTable, (const char*)&i, sizeof(int32_t));
}
ASSERT_EQ(taosHashGetSize(hashTable), 250);
taosHashCleanup(hashTable);
}
void stringKeyTest() {
auto* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
auto* hashTable =
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
ASSERT_EQ(taosHashGetSize(hashTable), 0);
char key[128] = {0};
// put 200 elements in the hash table
for(int32_t i = 0; i < 1000; ++i) {
for (int32_t i = 0; i < 1000; ++i) {
int32_t len = sprintf(key, "%d_1_%dabcefg_", i, i + 10);
taosHashPut(hashTable, key, len, (char*) &i, sizeof(int32_t));
taosHashPut(hashTable, key, len, (char*)&i, sizeof(int32_t));
}
ASSERT_EQ(taosHashGetSize(hashTable), 1000);
for(int32_t i = 0; i < 1000; ++i) {
for (int32_t i = 0; i < 1000; ++i) {
int32_t len = sprintf(key, "%d_1_%dabcefg_", i, i + 10);
char* p = (char*) taosHashGet(hashTable, key, len);
char* p = (char*)taosHashGet(hashTable, key, len);
ASSERT_TRUE(p != nullptr);
ASSERT_EQ(*reinterpret_cast<int32_t*>(p), i);
}
for(int32_t i = 500; i < 1000; ++i) {
for (int32_t i = 500; i < 1000; ++i) {
int32_t len = sprintf(key, "%d_1_%dabcefg_", i, i + 10);
taosHashRemove(hashTable, key, len);
}
ASSERT_EQ(taosHashGetSize(hashTable), 500);
for(int32_t i = 0; i < 499; ++i) {
for (int32_t i = 0; i < 499; ++i) {
int32_t len = sprintf(key, "%d_1_%dabcefg_", i, i + 10);
taosHashRemove(hashTable, key, len);
}
ASSERT_EQ(taosHashGetSize(hashTable), 1);
taosHashCleanup(hashTable);
}
void functionTest() {
}
void functionTest() {}
/**
* evaluate the performance issue, by add 10million elements in to hash table in
* a single threads situation
*/
void noLockPerformanceTest() {
auto* hashTable = (SHashObj*) taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
auto* hashTable =
(SHashObj*)taosHashInit(4096, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
ASSERT_EQ(taosHashGetSize(hashTable), 0);
char key[128] = {0};
char key[128] = {0};
int32_t num = 5000;
int64_t st = taosGetTimestampUs();
// put 10M elements in the hash table
for(int32_t i = 0; i < num; ++i) {
for (int32_t i = 0; i < num; ++i) {
int32_t len = sprintf(key, "%d_1_%dabcefg_", i, i + 10);
taosHashPut(hashTable, key, len, (char*) &i, sizeof(int32_t));
taosHashPut(hashTable, key, len, (char*)&i, sizeof(int32_t));
}
ASSERT_EQ(taosHashGetSize(hashTable), num);
int64_t et = taosGetTimestampUs();
printf("Elpased time:%" PRId64 " us to add %d elements, avg cost:%lf us\n", et - st, num, (et - st)/(double) num);
printf("Elpased time:%" PRId64 " us to add %d elements, avg cost:%lf us\n", et - st, num, (et - st) / (double)num);
st = taosGetTimestampUs();
for(int32_t i = 0; i < num; ++i) {
for (int32_t i = 0; i < num; ++i) {
int32_t len = sprintf(key, "%d_1_%dabcefg_", i, i + 10);
char* p = (char*) taosHashGet(hashTable, key, len);
char* p = (char*)taosHashGet(hashTable, key, len);
ASSERT_TRUE(p != nullptr);
ASSERT_EQ(*reinterpret_cast<int32_t*>(p), i);
}
et = taosGetTimestampUs();
printf("Elpased time:%" PRId64 " us to fetch all %d elements, avg cost:%lf us\n", et - st, num, (et - st)/(double) num);
printf("Elpased time:%" PRId64 " us to fetch all %d elements, avg cost:%lf us\n", et - st, num,
(et - st) / (double)num);
printf("The maximum length of overflow linklist in hash table is:%d\n", taosHashGetMaxOverflowLinkLength(hashTable));
taosHashCleanup(hashTable);
}
void multithreadsTest() {
//todo
// todo
}
// check the function robustness
void invalidOperationTest() {
}
void invalidOperationTest() {}
void acquireRleaseTest() {
SHashObj* hashTable = (SHashObj*) taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
SHashObj* hashTable =
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
ASSERT_EQ(taosHashGetSize(hashTable), 0);
int32_t key = 2;
int32_t code = 0;
int32_t num = 0;
TESTSTRUCT data = {0};
const char *str1 = "abcdefg";
const char *str2 = "aaaaaaa";
const char *str3 = "123456789";
int32_t key = 2;
int32_t code = 0;
int32_t num = 0;
TESTSTRUCT data = {0};
const char* str1 = "abcdefg";
const char* str2 = "aaaaaaa";
const char* str3 = "123456789";
data.p = (char *)taosMemoryMalloc(10);
data.p = (char*)taosMemoryMalloc(10);
strcpy(data.p, str1);
code = taosHashPut(hashTable, &key, sizeof(key), &data, sizeof(data));
@ -167,17 +168,17 @@ void acquireRleaseTest() {
TESTSTRUCT* pdata = (TESTSTRUCT*)taosHashAcquire(hashTable, &key, sizeof(key));
ASSERT_TRUE(pdata != nullptr);
ASSERT_TRUE(strcmp(pdata->p, str1) == 0);
code = taosHashRemove(hashTable, &key, sizeof(key));
ASSERT_EQ(code, 0);
ASSERT_TRUE(strcmp(pdata->p, str1) == 0);
num = taosHashGetSize(hashTable);
ASSERT_EQ(num, 1);
strcpy(pdata->p, str3);
data.p = (char *)taosMemoryMalloc(10);
data.p = (char*)taosMemoryMalloc(10);
strcpy(data.p, str2);
code = taosHashPut(hashTable, &key, sizeof(key), &data, sizeof(data));
ASSERT_EQ(code, 0);
@ -198,19 +199,26 @@ void acquireRleaseTest() {
}
void perfTest() {
SHashObj* hash1h = (SHashObj*) taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash1s = (SHashObj*) taosHashInit(1000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash10s = (SHashObj*) taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash100s = (SHashObj*) taosHashInit(100000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash1m = (SHashObj*) taosHashInit(1000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash10m = (SHashObj*) taosHashInit(10000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash100m = (SHashObj*) taosHashInit(100000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash1h =
(SHashObj*)taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash1s =
(SHashObj*)taosHashInit(1000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash10s =
(SHashObj*)taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash100s =
(SHashObj*)taosHashInit(100000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash1m =
(SHashObj*)taosHashInit(1000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash10m =
(SHashObj*)taosHashInit(10000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
SHashObj* hash100m =
(SHashObj*)taosHashInit(100000000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
char *name = (char*)taosMemoryCalloc(50000000, 9);
char* name = (char*)taosMemoryCalloc(50000000, 9);
for (int64_t i = 0; i < 50000000; ++i) {
sprintf(name + i * 9, "t%08d", i);
}
for (int64_t i = 0; i < 50; ++i) {
taosHashPut(hash1h, name + i * 9, 9, &i, sizeof(i));
}
@ -295,22 +303,21 @@ void perfTest() {
int64_t end100m = taosGetTimestampMs();
int64_t end100mCt = taosHashGetCompTimes(hash100m);
SArray *sArray[1000] = {0};
SArray* sArray[1000] = {0};
for (int64_t i = 0; i < 1000; ++i) {
sArray[i] = taosArrayInit(100000, 9);
}
int64_t cap = 4;
while (cap < 100000000) cap = (cap << 1u);
_hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
int32_t slotR = cap / 1000 + 1;
int32_t slotR = cap / 1000 + 1;
for (int64_t i = 0; i < 10000000; ++i) {
char* p = name + (i % 50000000) * 9;
char* p = name + (i % 50000000) * 9;
uint32_t v = (*hashFp)(p, 9);
taosArrayPush(sArray[(v%cap)/slotR], p);
taosArrayPush(sArray[(v % cap) / slotR], p);
}
SArray *slArray = taosArrayInit(100000000, 9);
SArray* slArray = taosArrayInit(100000000, 9);
for (int64_t i = 0; i < 1000; ++i) {
int32_t num = taosArrayGetSize(sArray[i]);
SArray* pArray = sArray[i];
@ -349,17 +356,17 @@ void perfTest() {
taosHashCleanup(hash10m);
taosHashCleanup(hash100m);
SHashObj *mhash[1000] = {0};
SHashObj* mhash[1000] = {0};
for (int64_t i = 0; i < 1000; ++i) {
mhash[i] = (SHashObj*) taosHashInit(100000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
mhash[i] = (SHashObj*)taosHashInit(100000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
}
for (int64_t i = 0; i < 50000000; ++i) {
#if 0
taosHashPut(mhash[i%1000], name + i * 9, 9, &i, sizeof(i));
#else
taosHashPut(mhash[i/50000], name + i * 9, 9, &i, sizeof(i));
#endif
taosHashPut(mhash[i / 50000], name + i * 9, 9, &i, sizeof(i));
#endif
}
int64_t startMhashCt = 0;
@ -373,15 +380,15 @@ void perfTest() {
ASSERT(taosHashGet(mhash[i%1000], name + i * 9, 9));
}
#else
// for (int64_t i = 0; i < 10000000; ++i) {
for (int64_t i = 0; i < 50000000; i+=5) {
ASSERT(taosHashGet(mhash[i/50000], name + i * 9, 9));
// for (int64_t i = 0; i < 10000000; ++i) {
for (int64_t i = 0; i < 50000000; i += 5) {
ASSERT(taosHashGet(mhash[i / 50000], name + i * 9, 9));
}
#endif
#endif
int64_t endMhash = taosGetTimestampMs();
int64_t endMhashCt = 0;
for (int64_t i = 0; i < 1000; ++i) {
printf(" %" PRId64 , taosHashGetCompTimes(mhash[i]));
printf(" %" PRId64, taosHashGetCompTimes(mhash[i]));
endMhashCt += taosHashGetCompTimes(mhash[i]);
}
printf("\n100m \t %" PRId64 "ms,%" PRId64 "\n", endMhash - startMhash, endMhashCt - startMhashCt);
@ -391,8 +398,7 @@ void perfTest() {
}
}
}
} // namespace
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
@ -405,5 +411,5 @@ TEST(testCase, hashTest) {
noLockPerformanceTest();
multithreadsTest();
acquireRleaseTest();
//perfTest();
// perfTest();
}

View File

@ -13,19 +13,19 @@ namespace {
// simple test
void simpleTest() {
SDiskbasedBuf* pBuf = NULL;
int32_t ret = createDiskbasedBuf(&pBuf, 1024, 4096, "", TD_TMP_DIR_PATH);
int32_t ret = createDiskbasedBuf(&pBuf, 1024, 4096, "", TD_TMP_DIR_PATH);
int32_t pageId = 0;
int32_t groupId = 0;
SFilePage* pBufPage = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
ASSERT_TRUE(pBufPage != NULL);
ASSERT_EQ(getTotalBufSize(pBuf), 1024);
SIDList list = getDataBufPagesIdList(pBuf);
ASSERT_EQ(taosArrayGetSize(list), 1);
//ASSERT_EQ(getNumOfBufGroupId(pBuf), 1);
// ASSERT_EQ(getNumOfBufGroupId(pBuf), 1);
releaseBufPage(pBuf, pBufPage);
@ -38,17 +38,17 @@ void simpleTest() {
SFilePage* t1 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t1 == pBufPage2);
SFilePage* pBufPage3 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage3 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t2 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t2 == pBufPage3);
SFilePage* pBufPage4 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage4 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t3 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t3 == pBufPage4);
releaseBufPage(pBuf, pBufPage2);
SFilePage* pBufPage5 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage5 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t4 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t4 == pBufPage5);
@ -57,19 +57,19 @@ void simpleTest() {
void writeDownTest() {
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 writePageId = 0;
int32_t groupId = 0;
int32_t nx = 12345;
SFilePage* pBufPage = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
ASSERT_TRUE(pBufPage != NULL);
*(int32_t*)(pBufPage->data) = nx;
writePageId = pageId;
setBufPageDirty(pBufPage, true);
releaseBufPage(pBuf, pBufPage);
@ -83,12 +83,12 @@ void writeDownTest() {
ASSERT_TRUE(t2 == pBufPage2);
ASSERT_TRUE(pageId == 2);
SFilePage* pBufPage3 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage3 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t3 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t3 == pBufPage3);
ASSERT_TRUE(pageId == 3);
SFilePage* pBufPage4 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage4 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t4 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t4 == pBufPage4);
ASSERT_TRUE(pageId == 4);
@ -106,39 +106,39 @@ void writeDownTest() {
void recyclePageTest() {
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 writePageId = 0;
int32_t groupId = 0;
int32_t nx = 12345;
SFilePage* pBufPage = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
ASSERT_TRUE(pBufPage != NULL);
releaseBufPage(pBuf, pBufPage);
SFilePage* pBufPage1 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage1 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t1 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t1 == pBufPage1);
ASSERT_TRUE(pageId == 1);
SFilePage* pBufPage2 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage2 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t2 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t2 == pBufPage2);
ASSERT_TRUE(pageId == 2);
SFilePage* pBufPage3 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage3 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t3 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t3 == pBufPage3);
ASSERT_TRUE(pageId == 3);
SFilePage* pBufPage4 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage4 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t4 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t4 == pBufPage4);
ASSERT_TRUE(pageId == 4);
releaseBufPage(pBuf, t4);
SFilePage* pBufPage5 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* pBufPage5 = static_cast<SFilePage*>(getNewBufPage(pBuf, &pageId));
SFilePage* t5 = static_cast<SFilePage*>(getBufPage(pBuf, pageId));
ASSERT_TRUE(t5 == pBufPage5);
ASSERT_TRUE(pageId == 5);
@ -147,7 +147,7 @@ void recyclePageTest() {
// flush the written page to disk, and read it out again
SFilePage* pBufPagex = static_cast<SFilePage*>(getBufPage(pBuf, writePageId));
*(int32_t*)(pBufPagex->data) = nx;
writePageId = pageId; // update the data
writePageId = pageId; // update the data
releaseBufPage(pBuf, pBufPagex);
SFilePage* pBufPagex1 = static_cast<SFilePage*>(getBufPage(pBuf, 1));
@ -157,8 +157,7 @@ void recyclePageTest() {
destroyDiskbasedBuf(pBuf);
}
} // namespace
} // namespace
TEST(testCase, resultBufferTest) {
taosSeedRand(taosGetTimestampSec());

View File

@ -19,7 +19,7 @@ TEST(testCase, string_dequote_test) {
EXPECT_EQ(3, len);
EXPECT_STRCASEEQ(t1, "abc");
char t21[] = " abc ";
char t21[] = " abc ";
int32_t lx = strtrim(t21);
EXPECT_STREQ("abc", t21);

View File

@ -5,247 +5,247 @@
static int compareFunc(const void *arg1, const void *arg2) { return (*(int *)arg1) - (*(int *)arg2); }
TEST(testCase, taosbsearch_equal) {
// For equal test
int key = 3;
void *pRet = NULL;
// For equal test
int key = 3;
void *pRet = NULL;
pRet = taosbsearch((void *)&key, NULL, 0, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
pRet = taosbsearch((void *)&key, NULL, 0, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
// 1 element
int array1[1] = {5};
// 1 element
int array1[1] = {5};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 5;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_EQ);
ASSERT_NE(pRet, nullptr);
ASSERT_EQ(*(int *)pRet, key);
key = 5;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_EQ);
ASSERT_NE(pRet, nullptr);
ASSERT_EQ(*(int *)pRet, key);
// 2 element
int array2[2] = {3, 6};
// 2 element
int array2[2] = {3, 6};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, key);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, key);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
// 3 element
int array3[3] = {3, 6, 8};
// 3 element
int array3[3] = {3, 6, 8};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_EQ);
ASSERT_EQ(pRet, nullptr);
}
TEST(testCase, taosbsearch_greater_or_equal) {
// For equal test
int key = 3;
void *pRet = NULL;
// For equal test
int key = 3;
void *pRet = NULL;
pRet = taosbsearch((void *)&key, NULL, 0, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
pRet = taosbsearch((void *)&key, NULL, 0, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
// 1 element
int array1[1] = {5};
// 1 element
int array1[1] = {5};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 5);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 5);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
key = 5;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_GE);
ASSERT_NE(pRet, nullptr);
ASSERT_EQ(*(int *)pRet, 5);
key = 5;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_GE);
ASSERT_NE(pRet, nullptr);
ASSERT_EQ(*(int *)pRet, 5);
// 2 element
int array2[2] = {3, 6};
// 2 element
int array2[2] = {3, 6};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
// 3 element
int array3[3] = {3, 6, 8};
// 3 element
int array3[3] = {3, 6, 8};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
// 4 element
int array4[4] = {3, 6, 8, 11};
// 4 element
int array4[4] = {3, 6, 8, 11};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
// 5 element
int array5[5] = {3, 6, 8, 11, 15};
// 5 element
int array5[5] = {3, 6, 8, 11, 15};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 11);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 15);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 15);
key = 15;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 15);
key = 15;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(*(int *)pRet, 15);
key = 17;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
key = 17;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_GE);
ASSERT_EQ(pRet, nullptr);
}
TEST(testCase, taosbsearch_greater) {
@ -413,168 +413,168 @@ TEST(testCase, taosbsearch_greater) {
}
TEST(testCase, taosbsearch_less_or_equal) {
// For equal test
int key = 3;
void *pRet = NULL;
// For equal test
int key = 3;
void *pRet = NULL;
pRet = taosbsearch((void *)&key, NULL, 0, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
pRet = taosbsearch((void *)&key, NULL, 0, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
// 1 element
int array1[1] = {5};
// 1 element
int array1[1] = {5};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 5);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 5);
key = 5;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_LE);
ASSERT_NE(pRet, nullptr);
ASSERT_EQ(*(int *)pRet, 5);
key = 5;
pRet = taosbsearch((void *)&key, (void *)array1, 1, sizeof(int), compareFunc, TD_LE);
ASSERT_NE(pRet, nullptr);
ASSERT_EQ(*(int *)pRet, 5);
// 2 element
int array2[2] = {3, 6};
// 2 element
int array2[2] = {3, 6};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array2, 2, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
// 3 element
int array3[3] = {3, 6, 8};
// 3 element
int array3[3] = {3, 6, 8};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array3, 3, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
// 4 element
int array4[4] = {3, 6, 8, 11};
// 4 element
int array4[4] = {3, 6, 8, 11};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array4, 4, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
// 5 element
int array5[5] = {3, 6, 8, 11, 15};
// 5 element
int array5[5] = {3, 6, 8, 11, 15};
key = 1;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 1;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(pRet, nullptr);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 3;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 4;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 3);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 6;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 7;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 6);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 8;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 9;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 8);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
key = 11;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
key = 13;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 11);
key = 15;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 15);
key = 15;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 15);
key = 17;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 15);
key = 17;
pRet = taosbsearch((void *)&key, (void *)array5, 5, sizeof(int), compareFunc, TD_LE);
ASSERT_EQ(*(int *)pRet, 15);
}
TEST(testCase, taosbsearch_less) {

View File

@ -1,91 +1,88 @@
#include "tref.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "os.h"
#include "tref.h"
#include "tlog.h"
#include "tglobal.h"
#include "taoserror.h"
#include "tglobal.h"
#include "tlog.h"
typedef struct {
int refNum;
int steps;
int rsetId;
int64_t*rid;
void **p;
int refNum;
int steps;
int rsetId;
int64_t *rid;
void **p;
} SRefSpace;
void iterateRefs(int rsetId) {
int count = 0;
int count = 0;
void *p = taosIterateRef(rsetId, 0);
while (p) {
// process P
count++;
p = taosIterateRef(rsetId, (int64_t) p);
}
p = taosIterateRef(rsetId, (int64_t)p);
}
printf(" %d ", count);
printf(" %d ", count);
}
void *addRef(void *param) {
SRefSpace *pSpace = (SRefSpace *)param;
int id;
int id;
for (int i=0; i < pSpace->steps; ++i) {
for (int i = 0; i < pSpace->steps; ++i) {
printf("a");
id = taosRand() % pSpace->refNum;
id = taosRand() % pSpace->refNum;
if (pSpace->rid[id] <= 0) {
pSpace->p[id] = taosMemoryMalloc(128);
pSpace->rid[id] = taosAddRef(pSpace->rsetId, pSpace->p[id]);
}
taosUsleep(100);
}
}
return NULL;
}
void *removeRef(void *param) {
SRefSpace *pSpace = (SRefSpace *)param;
int id, code;
int id, code;
for (int i=0; i < pSpace->steps; ++i) {
for (int i = 0; i < pSpace->steps; ++i) {
printf("d");
id = taosRand() % pSpace->refNum;
id = taosRand() % pSpace->refNum;
if (pSpace->rid[id] > 0) {
code = taosRemoveRef(pSpace->rsetId, pSpace->rid[id]);
if (code == 0) pSpace->rid[id] = 0;
}
taosUsleep(100);
}
}
return NULL;
}
void *acquireRelease(void *param) {
SRefSpace *pSpace = (SRefSpace *)param;
int id;
int id;
for (int i=0; i < pSpace->steps; ++i) {
for (int i = 0; i < pSpace->steps; ++i) {
printf("a");
id = taosRand() % pSpace->refNum;
void *p = taosAcquireRef(pSpace->rsetId, (int64_t) pSpace->p[id]);
id = taosRand() % pSpace->refNum;
void *p = taosAcquireRef(pSpace->rsetId, (int64_t)pSpace->p[id]);
if (p) {
taosUsleep(id % 5 + 1);
taosReleaseRef(pSpace->rsetId, (int64_t) pSpace->p[id]);
taosReleaseRef(pSpace->rsetId, (int64_t)pSpace->p[id]);
}
}
}
return NULL;
}
void myfree(void *p) {
taosMemoryFree(p);
}
void myfree(void *p) { taosMemoryFree(p); }
void *openRefSpace(void *param) {
SRefSpace *pSpace = (SRefSpace *)param;
@ -96,9 +93,9 @@ void *openRefSpace(void *param) {
if (pSpace->rsetId < 0) {
printf("failed to open ref, reason:%s\n", tstrerror(pSpace->rsetId));
return NULL;
}
}
pSpace->p = (void **) taosMemoryCalloc(sizeof(void *), pSpace->refNum);
pSpace->p = (void **)taosMemoryCalloc(sizeof(void *), pSpace->refNum);
pSpace->rid = taosMemoryCalloc(pSpace->refNum, sizeof(int64_t));
TdThreadAttr thattr;
@ -114,7 +111,7 @@ void *openRefSpace(void *param) {
taosThreadJoin(thread2, NULL);
taosThreadJoin(thread3, NULL);
for (int i=0; i<pSpace->refNum; ++i) {
for (int i = 0; i < pSpace->refNum; ++i) {
taosRemoveRef(pSpace->rsetId, pSpace->rid[i]);
}
@ -130,21 +127,21 @@ void *openRefSpace(void *param) {
int main(int argc, char *argv[]) {
int refNum = 100;
int threads = 10;
int steps = 10000;
int steps = 10000;
int loops = 1;
uDebugFlag = 143;
for (int i=1; i<argc; ++i) {
if (strcmp(argv[i], "-n")==0 && i < argc-1) {
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-n") == 0 && i < argc - 1) {
refNum = atoi(argv[++i]);
} else if (strcmp(argv[i], "-s")==0 && i < argc-1) {
} else if (strcmp(argv[i], "-s") == 0 && i < argc - 1) {
steps = atoi(argv[++i]);
} else if (strcmp(argv[i], "-t")==0 && i < argc-1) {
} else if (strcmp(argv[i], "-t") == 0 && i < argc - 1) {
threads = atoi(argv[++i]);
} else if (strcmp(argv[i], "-l")==0 && i < argc-1) {
} else if (strcmp(argv[i], "-l") == 0 && i < argc - 1) {
loops = atoi(argv[++i]);
} else if (strcmp(argv[i], "-d")==0 && i < argc-1) {
} else if (strcmp(argv[i], "-d") == 0 && i < argc - 1) {
uDebugFlag = atoi(argv[i]);
} else {
printf("\nusage: %s [options] \n", argv[0]);
@ -159,22 +156,22 @@ int main(int argc, char *argv[]) {
taosInitLog("tref.log", 10);
SRefSpace *pSpaceList = (SRefSpace *) taosMemoryCalloc(sizeof(SRefSpace), threads);
TdThread *pThreadList = (TdThread *) taosMemoryCalloc(sizeof(TdThread), threads);
SRefSpace *pSpaceList = (SRefSpace *)taosMemoryCalloc(sizeof(SRefSpace), threads);
TdThread *pThreadList = (TdThread *)taosMemoryCalloc(sizeof(TdThread), threads);
TdThreadAttr thattr;
taosThreadAttrInit(&thattr);
taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE);
for (int i=0; i<loops; ++i) {
for (int i = 0; i < loops; ++i) {
printf("\nloop: %d\n", i);
for (int j=0; j<threads; ++j) {
for (int j = 0; j < threads; ++j) {
pSpaceList[j].steps = steps;
pSpaceList[j].refNum = refNum;
taosThreadCreate(&(pThreadList[j]), &thattr, openRefSpace, (void *)(pSpaceList+j));
taosThreadCreate(&(pThreadList[j]), &thattr, openRefSpace, (void *)(pSpaceList + j));
}
for (int j=0; j<threads; ++j) {
for (int j = 0; j < threads; ++j) {
taosThreadJoin(pThreadList[j], NULL);
}
}
@ -189,4 +186,3 @@ int main(int argc, char *argv[]) {
return num;
}

View File

@ -9,7 +9,8 @@ cd ${PRJ_ROOT_DIR}
FORMAT_DIR_LIST=(
"include"
# "source"
"source/os"
"source/util"
)
for d in ${FORMAT_DIR_LIST[@]}; do