Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fcbaa608
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fcbaa608
编写于
10月 13, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more code refact
上级
5a45dab0
变更
42
展开全部
显示空白变更内容
内联
并排
Showing
42 changed file
with
2759 addition
and
3186 deletion
+2759
-3186
include/os/osEnv.h
include/os/osEnv.h
+1
-0
include/util/tdigest.h
include/util/tdigest.h
+2
-0
source/os/src/osAtomic.c
source/os/src/osAtomic.c
+3
-3
source/os/src/osDir.c
source/os/src/osDir.c
+29
-28
source/os/src/osEnv.c
source/os/src/osEnv.c
+1
-1
source/os/src/osFile.c
source/os/src/osFile.c
+11
-11
source/os/src/osLocale.c
source/os/src/osLocale.c
+1
-1
source/os/src/osMemory.c
source/os/src/osMemory.c
+52
-51
source/os/src/osProc.c
source/os/src/osProc.c
+2
-2
source/os/src/osRand.c
source/os/src/osRand.c
+6
-6
source/os/src/osSignal.c
source/os/src/osSignal.c
+3
-3
source/os/src/osSleep.c
source/os/src/osSleep.c
+9
-10
source/os/src/osString.c
source/os/src/osString.c
+6
-6
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+24
-20
source/os/src/osSystem.c
source/os/src/osSystem.c
+41
-41
source/os/src/osThread.c
source/os/src/osThread.c
+78
-152
source/os/src/osTimer.c
source/os/src/osTimer.c
+12
-11
source/os/src/osTimezone.c
source/os/src/osTimezone.c
+769
-765
source/util/src/talgo.c
source/util/src/talgo.c
+3
-3
source/util/src/tbloomfilter.c
source/util/src/tbloomfilter.c
+16
-19
source/util/src/tcache.c
source/util/src/tcache.c
+5
-5
source/util/src/tcompare.c
source/util/src/tcompare.c
+81
-85
source/util/src/tconfig.c
source/util/src/tconfig.c
+41
-41
source/util/src/tcrc32c.c
source/util/src/tcrc32c.c
+708
-1050
source/util/src/tdigest.c
source/util/src/tdigest.c
+217
-240
source/util/src/tenv.c
source/util/src/tenv.c
+4
-4
source/util/src/thash.c
source/util/src/thash.c
+1
-3
source/util/src/thashutil.c
source/util/src/thashutil.c
+44
-30
source/util/src/tmempool.c
source/util/src/tmempool.c
+6
-6
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+27
-23
source/util/src/tscalablebf.c
source/util/src/tscalablebf.c
+13
-19
source/util/src/tthread.c
source/util/src/tthread.c
+1
-1
source/util/src/ttimer.c
source/util/src/ttimer.c
+11
-11
source/util/src/tworker.c
source/util/src/tworker.c
+1
-1
source/util/test/arrayTest.cpp
source/util/test/arrayTest.cpp
+13
-16
source/util/test/bloomFilterTest.cpp
source/util/test/bloomFilterTest.cpp
+32
-35
source/util/test/hashTest.cpp
source/util/test/hashTest.cpp
+114
-108
source/util/test/pageBufferTest.cpp
source/util/test/pageBufferTest.cpp
+23
-24
source/util/test/stringTest.cpp
source/util/test/stringTest.cpp
+1
-1
source/util/test/taosbsearchTest.cpp
source/util/test/taosbsearchTest.cpp
+299
-299
source/util/test/trefTest.c
source/util/test/trefTest.c
+46
-50
tools/scripts/codeFormat.sh
tools/scripts/codeFormat.sh
+2
-1
未找到文件。
include/os/osEnv.h
浏览文件 @
fcbaa608
...
...
@@ -17,6 +17,7 @@
#define _TD_OS_ENV_H_
#include "osSysinfo.h"
#include "osTimezone.h"
#ifdef __cplusplus
extern
"C"
{
...
...
include/util/tdigest.h
浏览文件 @
fcbaa608
...
...
@@ -22,6 +22,8 @@
#ifndef TDIGEST_H
#define TDIGEST_H
#include "os.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
/* pi */
#endif
...
...
source/os/src/osAtomic.c
浏览文件 @
fcbaa608
source/os/src/osDir.c
浏览文件 @
fcbaa608
...
...
@@ -31,14 +31,13 @@ typedef struct TdDir {
HANDLE
hFind
;
}
TdDir
;
enum
{
enum
{
WRDE_NOSPACE
=
1
,
/* Ran out of memory. */
WRDE_BADCHAR
,
/* A metachar appears in the wrong place. */
WRDE_BADVAL
,
/* Undefined var reference with WRDE_UNDEF. */
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
;
...
...
@@ -301,18 +300,20 @@ 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
))
{
switch
(
wordexp
(
dirname
,
&
full_path
,
0
))
{
case
0
:
break
;
case
WRDE_NOSPACE
:
wordfree
(
&
full_path
);
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);
// printf("failed to expand path:%s since illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }\n",
// dirname);
return
-
1
;
case
WRDE_SYNTAX
:
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched quotes\n", dirname);
// printf("failed to expand path:%s since Shell syntax error, such as unbalanced parentheses or unmatched
// quotes\n", dirname);
return
-
1
;
default:
// printf("failed to expand path:%s since %s\n", dirname, strerror(errno));
...
...
@@ -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
;
...
...
source/os/src/osEnv.c
浏览文件 @
fcbaa608
...
...
@@ -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
());
...
...
source/os/src/osFile.c
浏览文件 @
fcbaa608
...
...
@@ -58,7 +58,7 @@ typedef struct TdFile {
#define FILE_WITH_LOCK 1
typedef
struct
AutoDelFile
*
AutoDelFilePtr
;
typedef
struct
AutoDelFile
*
AutoDelFilePtr
;
typedef
struct
AutoDelFile
{
char
*
name
;
AutoDelFilePtr
lastAutoDelFilePtr
;
...
...
@@ -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
;
...
...
source/os/src/osLocale.c
浏览文件 @
fcbaa608
...
...
@@ -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
))
{
...
...
source/os/src/osMemory.c
浏览文件 @
fcbaa608
...
...
@@ -52,7 +52,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
#pragma comment(lib, "dbghelp.lib")
void
taosPrintBackTrace
()
{
#define MAX_STACK_FRAMES 20
#define MAX_STACK_FRAMES 20
void
*
pStack
[
MAX_STACK_FRAMES
];
...
...
@@ -72,15 +72,17 @@ void taosPrintBackTrace() {
DWORD
displacementLine
=
0
;
IMAGEHLP_LINE64
line
;
//
SymSetOptions(SYMOPT_LOAD_LINES);
//
SymSetOptions(SYMOPT_LOAD_LINES);
line
.
SizeOfStruct
=
sizeof
(
IMAGEHLP_LINE64
);
if
(
SymFromAddr
(
process
,
address
,
&
displacementSym
,
pSymbol
)
&&
SymGetLineFromAddr64
(
process
,
address
,
&
displacementLine
,
&
line
))
{
snprintf
(
buf_tmp
,
sizeof
(
buf_tmp
),
"BackTrace %08"
PRId64
" %s:%d %s
\n
"
,
taosGetSelfPthreadId
(),
line
.
FileName
,
line
.
LineNumber
,
pSymbol
->
Name
);
if
(
SymFromAddr
(
process
,
address
,
&
displacementSym
,
pSymbol
)
&&
SymGetLineFromAddr64
(
process
,
address
,
&
displacementLine
,
&
line
))
{
snprintf
(
buf_tmp
,
sizeof
(
buf_tmp
),
"BackTrace %08"
PRId64
" %s:%d %s
\n
"
,
taosGetSelfPthreadId
(),
line
.
FileName
,
line
.
LineNumber
,
pSymbol
->
Name
);
}
else
{
snprintf
(
buf_tmp
,
sizeof
(
buf_tmp
),
"BackTrace error: %d
\n
"
,
GetLastError
());
snprintf
(
buf_tmp
,
sizeof
(
buf_tmp
),
"BackTrace error: %d
\n
"
,
GetLastError
());
}
write
(
1
,
buf_tmp
,
strlen
(
buf_tmp
));
write
(
1
,
buf_tmp
,
strlen
(
buf_tmp
));
}
}
#endif
...
...
@@ -126,14 +128,13 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
#ifdef USE_ADDR2LINE
#include "osThread.h"
#include "libdwarf.h"
#include "dwarf.h"
#include "libdwarf.h"
#include "osThread.h"
#define DW_PR_DUu "llu"
typedef
struct
lookup_table
{
typedef
struct
lookup_table
{
Dwarf_Line
*
table
;
Dwarf_Line_Context
*
ctxts
;
int
cnt
;
...
...
source/os/src/osProc.c
浏览文件 @
fcbaa608
source/os/src/osRand.c
浏览文件 @
fcbaa608
...
...
@@ -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,7 +27,7 @@ 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
);
#else
...
...
source/os/src/osSignal.c
浏览文件 @
fcbaa608
...
...
@@ -47,7 +47,7 @@ void taosDflSignal(int32_t signum) {
signal
(
signum
,
SIG_DFL
);
}
void
taosKillChildOnParentStopped
()
{
}
void
taosKillChildOnParentStopped
()
{}
#else
...
...
source/os/src/osSleep.c
浏览文件 @
fcbaa608
...
...
@@ -17,7 +17,6 @@
#define _DEFAULT_SOURCE
#include "os.h"
#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#include <unistd.h>
#endif
...
...
source/os/src/osString.c
浏览文件 @
fcbaa608
...
...
@@ -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
);
...
...
source/os/src/osSysinfo.c
浏览文件 @
fcbaa608
...
...
@@ -214,7 +214,6 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
return
0
;
}
bool
taosCheckSystemIsLittleEnd
()
{
union
check
{
int16_t
i
;
...
...
@@ -338,10 +337,11 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) {
#ifdef WINDOWS
char
value
[
100
];
DWORD
bufferSize
=
sizeof
(
value
);
RegGetValue
(
HKEY_LOCAL_MACHINE
,
"HARDWARE
\\
DESCRIPTION
\\
System
\\
CentralProcessor
\\
0"
,
"ProcessorNameString"
,
RRF_RT_ANY
,
NULL
,
(
PVOID
)
&
value
,
&
bufferSize
);
RegGetValue
(
HKEY_LOCAL_MACHINE
,
"HARDWARE
\\
DESCRIPTION
\\
System
\\
CentralProcessor
\\
0"
,
"ProcessorNameString"
,
RRF_RT_ANY
,
NULL
,
(
PVOID
)
&
value
,
&
bufferSize
);
tstrncpy
(
cpuModel
,
value
,
maxLen
);
SYSTEM_INFO
si
;
memset
(
&
si
,
0
,
sizeof
(
SYSTEM_INFO
));
memset
(
&
si
,
0
,
sizeof
(
SYSTEM_INFO
));
GetSystemInfo
(
&
si
);
*
numOfCores
=
si
.
dwNumberOfProcessors
;
return
0
;
...
...
@@ -776,8 +776,9 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen) {
#ifdef WINDOWS
GUID
guid
;
CoCreateGuid
(
&
guid
);
snprintf
(
uid
,
uidlen
,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"
,
guid
.
Data1
,
guid
.
Data2
,
guid
.
Data3
,
guid
.
Data4
[
0
],
guid
.
Data4
[
1
],
guid
.
Data4
[
2
],
guid
.
Data4
[
3
],
guid
.
Data4
[
4
],
guid
.
Data4
[
5
],
guid
.
Data4
[
6
],
guid
.
Data4
[
7
]);
snprintf
(
uid
,
uidlen
,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X"
,
guid
.
Data1
,
guid
.
Data2
,
guid
.
Data3
,
guid
.
Data4
[
0
],
guid
.
Data4
[
1
],
guid
.
Data4
[
2
],
guid
.
Data4
[
3
],
guid
.
Data4
[
4
],
guid
.
Data4
[
5
],
guid
.
Data4
[
6
],
guid
.
Data4
[
7
]);
return
0
;
#elif defined(_TD_DARWIN_64)
...
...
@@ -971,14 +972,17 @@ SysNameInfo taosGetSysNameInfo() {
#endif
}
bool
taosCheckCurrentInDll
()
{
#ifdef WINDOWS
MEMORY_BASIC_INFORMATION
mbi
;
char
path
[
PATH_MAX
]
=
{
0
};
GetModuleFileName
(((
VirtualQuery
(
taosCheckCurrentInDll
,
&
mbi
,
sizeof
(
mbi
))
!=
0
)
?
(
HMODULE
)
mbi
.
AllocationBase
:
NULL
),
path
,
PATH_MAX
);
GetModuleFileName
(
((
VirtualQuery
(
taosCheckCurrentInDll
,
&
mbi
,
sizeof
(
mbi
))
!=
0
)
?
(
HMODULE
)
mbi
.
AllocationBase
:
NULL
),
path
,
PATH_MAX
);
int
strLastIndex
=
strlen
(
path
);
if
((
path
[
strLastIndex
-
3
]
==
'd'
||
path
[
strLastIndex
-
3
]
==
'D'
)
&&
(
path
[
strLastIndex
-
2
]
==
'l'
||
path
[
strLastIndex
-
2
]
==
'L'
)
&&
(
path
[
strLastIndex
-
1
]
==
'l'
||
path
[
strLastIndex
-
1
]
==
'L'
))
{
if
((
path
[
strLastIndex
-
3
]
==
'd'
||
path
[
strLastIndex
-
3
]
==
'D'
)
&&
(
path
[
strLastIndex
-
2
]
==
'l'
||
path
[
strLastIndex
-
2
]
==
'L'
)
&&
(
path
[
strLastIndex
-
1
]
==
'l'
||
path
[
strLastIndex
-
1
]
==
'L'
))
{
return
true
;
}
return
false
;
...
...
source/os/src/osSystem.c
浏览文件 @
fcbaa608
...
...
@@ -18,7 +18,7 @@
#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
;
...
...
@@ -31,14 +31,14 @@ void WINAPI windowsServiceCtrlHandle(DWORD request) {
ServiceStatus
.
dwCurrentState
=
SERVICE_STOP_PENDING
;
if
(
!
SetServiceStatus
(
hServiceStatusHandle
,
&
ServiceStatus
))
{
DWORD
nError
=
GetLastError
();
printf
(
"failed to send stopped status to windows service: %d"
,
nError
);
printf
(
"failed to send stopped status to windows service: %d"
,
nError
);
}
break
;
default:
return
;
}
}
void
WINAPI
mainWindowsService
(
int
argc
,
char
**
argv
)
{
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
;
...
...
@@ -50,19 +50,19 @@ void WINAPI mainWindowsService(int argc,char** argv) {
hServiceStatusHandle
=
RegisterServiceCtrlHandler
(
"taosd"
,
&
windowsServiceCtrlHandle
);
if
(
hServiceStatusHandle
==
0
)
{
DWORD
nError
=
GetLastError
();
printf
(
"failed to register windows service ctrl handler: %d"
,
nError
);
printf
(
"failed to register windows service ctrl handler: %d"
,
nError
);
}
ServiceStatus
.
dwCurrentState
=
SERVICE_RUNNING
;
if
(
SetServiceStatus
(
hServiceStatusHandle
,
&
ServiceStatus
))
{
DWORD
nError
=
GetLastError
();
printf
(
"failed to send running status to windows service: %d"
,
nError
);
printf
(
"failed to send running status to windows service: %d"
,
nError
);
}
if
(
mainWindowsFunc
!=
NULL
)
mainWindowsFunc
(
argc
,
argv
);
ServiceStatus
.
dwCurrentState
=
SERVICE_STOPPED
;
if
(
!
SetServiceStatus
(
hServiceStatusHandle
,
&
ServiceStatus
))
{
DWORD
nError
=
GetLastError
();
printf
(
"failed to send stopped status to windows service: %d"
,
nError
);
printf
(
"failed to send stopped status to windows service: %d"
,
nError
);
}
}
void
stratWindowsService
(
MainWindows
mainWindows
)
{
...
...
@@ -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
;
}
...
...
source/os/src/osThread.c
浏览文件 @
fcbaa608
...
...
@@ -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
));
}
\ No newline at end of file
void
taosThreadClear
(
TdThread
*
thread
)
{
memset
(
thread
,
0
,
sizeof
(
TdThread
));
}
\ No newline at end of file
source/os/src/osTimer.c
浏览文件 @
fcbaa608
...
...
@@ -86,7 +86,7 @@ static void taosDeleteTimer(void *tharg) {
static
TdThread
timerThread
;
static
timer_t
timerId
;
static
volatile
bool
stopTimer
=
false
;
static
void
*
taosProcessAlarmSignal
(
void
*
tharg
)
{
static
void
*
taosProcessAlarmSignal
(
void
*
tharg
)
{
// Block the signal
sigset_t
sigset
;
sigemptyset
(
&
sigset
);
...
...
@@ -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
();
}
...
...
source/os/src/osTimezone.c
浏览文件 @
fcbaa608
此差异已折叠。
点击以展开。
source/util/src/talgo.c
浏览文件 @
fcbaa608
...
...
@@ -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
)
{
...
...
source/util/src/tbloomfilter.c
浏览文件 @
fcbaa608
...
...
@@ -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
));
...
...
@@ -85,8 +85,7 @@ int32_t tBloomFilterPut(SBloomFilter *pBF, const void *keyBuf, uint32_t len) {
return
TSDB_CODE_FAILED
;
}
int32_t
tBloomFilterNoContain
(
const
SBloomFilter
*
pBF
,
const
void
*
keyBuf
,
uint32_t
len
)
{
int32_t
tBloomFilterNoContain
(
const
SBloomFilter
*
pBF
,
const
void
*
keyBuf
,
uint32_t
len
)
{
uint64_t
h1
=
(
uint64_t
)
pBF
->
hashFn1
(
keyBuf
,
len
);
uint64_t
h2
=
(
uint64_t
)
pBF
->
hashFn2
(
keyBuf
,
len
);
const
register
uint64_t
size
=
pBF
->
numBits
;
...
...
@@ -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
;
}
\ No newline at end of file
bool
tBloomFilterIsFull
(
const
SBloomFilter
*
pBF
)
{
return
pBF
->
size
>=
pBF
->
expectedEntries
;
}
\ No newline at end of file
source/util/src/tcache.c
浏览文件 @
fcbaa608
...
...
@@ -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
...
...
source/util/src/tcompare.c
浏览文件 @
fcbaa608
...
...
@@ -226,23 +226,23 @@ 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
;
}
...
...
@@ -392,7 +392,6 @@ int32_t compareInt16Uint64(const void *pLeft, const void *pRight) {
return
0
;
}
int32_t
compareInt32Int8
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
int32_t
left
=
GET_INT32_VAL
(
pLeft
);
int8_t
right
=
GET_INT8_VAL
(
pRight
);
...
...
@@ -997,10 +996,7 @@ int32_t compareUint64Uint32(const void *pLeft, const void *pRight) {
return
0
;
}
int32_t
compareJsonValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compareJsonVal
(
pRight
,
pLeft
);
}
int32_t
compareJsonValDesc
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
return
compareJsonVal
(
pRight
,
pLeft
);
}
/*
* Compare two strings
* TSDB_MATCH: Match
...
...
source/util/src/tconfig.c
浏览文件 @
fcbaa608
...
...
@@ -15,13 +15,13 @@
#define _DEFAULT_SOURCE
#include "tconfig.h"
#include "cJSON.h"
#include "taoserror.h"
#include "tlog.h"
#include "tutil.h"
#include "tenv.h"
#include "cJSON.h"
#include "tjson.h"
#include "tgrant.h"
#include "tjson.h"
#include "tlog.h"
#include "tutil.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
:
...
...
@@ -634,11 +634,11 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
int32_t
code
=
0
;
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,9 +676,9 @@ 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
++
;
...
...
@@ -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
;
...
...
@@ -941,13 +941,13 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
size_t
fileSize
=
taosLSeekFile
(
pFile
,
0
,
SEEK_END
);
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
);
...
...
@@ -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,23 +1042,23 @@ 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
;
...
...
@@ -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
;
...
...
source/util/src/tcrc32c.c
浏览文件 @
fcbaa608
此差异已折叠。
点击以展开。
source/util/src/tdigest.c
浏览文件 @
fcbaa608
...
...
@@ -24,13 +24,13 @@
* 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 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
{
...
...
@@ -41,16 +41,16 @@ typedef struct SMergeArgs {
double
k1
;
double
min
;
double
max
;
}
SMergeArgs
;
}
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
)
{
TDigest
*
tdigestNewFrom
(
void
*
pBuf
,
int32_t
compression
)
{
memset
(
pBuf
,
0
,
(
size_t
)
TDIGEST_SIZE
(
compression
));
TDigest
*
t
=
(
TDigest
*
)
pBuf
;
TDigest
*
t
=
(
TDigest
*
)
pBuf
;
tdigestAutoFill
(
t
,
compression
);
t
->
compression
=
compression
;
...
...
@@ -63,34 +63,29 @@ TDigest *tdigestNewFrom(void* pBuf, int32_t compression) {
}
static
int32_t
cmpCentroid
(
const
void
*
a
,
const
void
*
b
)
{
SCentroid
*
c1
=
(
SCentroid
*
)
a
;
SCentroid
*
c2
=
(
SCentroid
*
)
b
;
if
(
c1
->
mean
<
c2
->
mean
)
return
-
1
;
if
(
c1
->
mean
>
c2
->
mean
)
return
1
;
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
];
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
)
{
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
)
{
if
(
c
->
mean
==
merge
->
mean
)
{
c
->
weight
+=
merge
->
weight
;
}
else
{
c
->
weight
+=
merge
->
weight
;
...
...
@@ -110,10 +105,9 @@ void tdigestCompress(TDigest *t) {
int32_t
i
,
j
;
SMergeArgs
args
;
if
(
t
->
num_buffered_pts
<=
0
)
return
;
if
(
t
->
num_buffered_pts
<=
0
)
return
;
unmerged_centroids
=
(
SCentroid
*
)
taosMemoryMalloc
(
sizeof
(
SCentroid
)
*
t
->
num_buffered_pts
);
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
];
...
...
@@ -126,7 +120,7 @@ void tdigestCompress(TDigest *t) {
taosSort
(
unmerged_centroids
,
num_unmerged
,
sizeof
(
SCentroid
),
cmpCentroid
);
memset
(
&
args
,
0
,
sizeof
(
SMergeArgs
));
args
.
centroids
=
(
SCentroid
*
)
taosMemoryMalloc
((
size_t
)(
sizeof
(
SCentroid
)
*
t
->
size
));
args
.
centroids
=
(
SCentroid
*
)
taosMemoryMalloc
((
size_t
)(
sizeof
(
SCentroid
)
*
t
->
size
));
memset
(
args
.
centroids
,
0
,
(
size_t
)(
sizeof
(
SCentroid
)
*
t
->
size
));
args
.
t
=
t
;
...
...
@@ -154,7 +148,7 @@ void tdigestCompress(TDigest *t) {
mergeCentroid
(
&
args
,
&
unmerged_centroids
[
i
++
]);
assert
(
args
.
idx
<
t
->
size
);
}
taosMemoryFree
((
void
*
)
unmerged_centroids
);
taosMemoryFree
((
void
*
)
unmerged_centroids
);
while
(
j
<
t
->
num_centroids
)
{
mergeCentroid
(
&
args
,
&
t
->
centroids
[
j
++
]);
...
...
@@ -171,15 +165,14 @@ void tdigestCompress(TDigest *t) {
}
memcpy
(
t
->
centroids
,
args
.
centroids
,
sizeof
(
SCentroid
)
*
t
->
num_centroids
);
taosMemoryFree
((
void
*
)
args
.
centroids
);
taosMemoryFree
((
void
*
)
args
.
centroids
);
}
void
tdigestAdd
(
TDigest
*
t
,
double
x
,
int64_t
w
)
{
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
)
{
if
(
i
>
0
&&
t
->
buffered_pts
[
i
-
1
].
value
==
x
)
{
t
->
buffered_pts
[
i
].
weight
=
w
;
}
else
{
t
->
buffered_pts
[
i
].
value
=
x
;
...
...
@@ -187,14 +180,11 @@ void tdigestAdd(TDigest* t, double x, int64_t w) {
t
->
num_buffered_pts
++
;
}
if
(
t
->
num_buffered_pts
>=
t
->
threshold
)
tdigestCompress
(
t
);
if
(
t
->
num_buffered_pts
>=
t
->
threshold
)
tdigestCompress
(
t
);
}
double
tdigestCDF
(
TDigest
*
t
,
double
x
)
{
if
(
t
==
NULL
)
return
0
;
if
(
t
==
NULL
)
return
0
;
int32_t
i
;
double
left
,
right
;
...
...
@@ -202,15 +192,11 @@ double tdigestCDF(TDigest *t, double x) {
SCentroid
*
a
,
*
b
,
tmp
;
tdigestCompress
(
t
);
if
(
t
->
num_centroids
==
0
)
return
NAN
;
if
(
x
<
t
->
min
)
return
0
;
if
(
x
>
t
->
max
)
return
1
;
if
(
t
->
num_centroids
==
0
)
return
NAN
;
if
(
x
<
t
->
min
)
return
0
;
if
(
x
>
t
->
max
)
return
1
;
if
(
t
->
num_centroids
==
1
)
{
if
(
FLOAT_EQ
(
t
->
max
,
t
->
min
))
return
0
.
5
;
if
(
FLOAT_EQ
(
t
->
max
,
t
->
min
))
return
0
.
5
;
return
INTERPOLATE
(
x
,
t
->
min
,
t
->
max
);
}
...
...
@@ -230,10 +216,7 @@ double tdigestCDF(TDigest *t, double x) {
right
=
(
b
->
mean
-
a
->
mean
)
*
a
->
weight
/
(
a
->
weight
+
b
->
weight
);
if
(
x
<
a
->
mean
+
right
)
{
double
cdf
=
(
weight_so_far
+
a
->
weight
*
INTERPOLATE
(
x
,
a
->
mean
-
left
,
a
->
mean
+
right
))
/
t
->
total_weight
;
double
cdf
=
(
weight_so_far
+
a
->
weight
*
INTERPOLATE
(
x
,
a
->
mean
-
left
,
a
->
mean
+
right
))
/
t
->
total_weight
;
return
TMAX
(
cdf
,
0
.
0
);
}
...
...
@@ -245,16 +228,14 @@ double tdigestCDF(TDigest *t, double x) {
right
=
t
->
max
-
a
->
mean
;
if
(
x
<
a
->
mean
+
right
)
{
return
(
weight_so_far
+
a
->
weight
*
INTERPOLATE
(
x
,
a
->
mean
-
left
,
a
->
mean
+
right
))
/
t
->
total_weight
;
return
(
weight_so_far
+
a
->
weight
*
INTERPOLATE
(
x
,
a
->
mean
-
left
,
a
->
mean
+
right
))
/
t
->
total_weight
;
}
return
1
;
}
double
tdigestQuantile
(
TDigest
*
t
,
double
q
)
{
if
(
t
==
NULL
)
return
0
;
if
(
t
==
NULL
)
return
0
;
int32_t
i
;
double
left
,
right
,
idx
;
...
...
@@ -262,14 +243,10 @@ double tdigestQuantile(TDigest *t, double q) {
SCentroid
*
a
,
*
b
,
tmp
;
tdigestCompress
(
t
);
if
(
t
->
num_centroids
==
0
)
return
NAN
;
if
(
t
->
num_centroids
==
1
)
return
t
->
centroids
[
0
].
mean
;
if
(
FLOAT_EQ
(
q
,
0
.
0
))
return
t
->
min
;
if
(
FLOAT_EQ
(
q
,
1
.
0
))
return
t
->
max
;
if
(
t
->
num_centroids
==
0
)
return
NAN
;
if
(
t
->
num_centroids
==
1
)
return
t
->
centroids
[
0
].
mean
;
if
(
FLOAT_EQ
(
q
,
0
.
0
))
return
t
->
min
;
if
(
FLOAT_EQ
(
q
,
1
.
0
))
return
t
->
max
;
idx
=
q
*
t
->
total_weight
;
weight_so_far
=
0
;
...
...
@@ -284,7 +261,7 @@ double tdigestQuantile(TDigest *t, double q) {
left
=
right
;
b
=
c
;
right
=
(
b
->
weight
*
a
->
mean
+
a
->
weight
*
b
->
mean
)
/
(
a
->
weight
+
b
->
weight
);
right
=
(
b
->
weight
*
a
->
mean
+
a
->
weight
*
b
->
mean
)
/
(
a
->
weight
+
b
->
weight
);
if
(
idx
<
weight_so_far
+
a
->
weight
)
{
double
p
=
(
idx
-
weight_so_far
)
/
a
->
weight
;
return
left
*
(
1
-
p
)
+
right
*
p
;
...
...
@@ -307,10 +284,10 @@ double tdigestQuantile(TDigest *t, double q) {
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
;
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
--
;
t2
->
num_buffered_pts
--
;
}
// centroids
for
(
int32_t
i
=
0
;
i
<
t2
->
num_centroids
;
i
++
)
{
...
...
source/util/src/tenv.c
浏览文件 @
fcbaa608
...
...
@@ -62,9 +62,9 @@ int32_t taosEnvToCfg(const char *envStr, char *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'
;
...
...
source/util/src/thash.c
浏览文件 @
fcbaa608
...
...
@@ -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
);
}
source/util/src/thashutil.c
浏览文件 @
fcbaa608
...
...
@@ -14,8 +14,8 @@
*/
#define _DEFAULT_SOURCE
#include "thash.h"
#include "tcompare.h"
#include "thash.h"
#include "types.h"
#define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r)))
...
...
@@ -29,7 +29,8 @@
(h) *= 0x85ebca6b; \
(h) ^= (h) >> 13; \
(h) *= 0xc2b2ae35; \
(h) ^= (h) >> 16; } while (0)
(h) ^= (h) >> 16; \
} while (0)
uint32_t
MurmurHash3_32
(
const
char
*
key
,
uint32_t
len
)
{
const
uint8_t
*
data
=
(
const
uint8_t
*
)
key
;
...
...
@@ -84,10 +85,10 @@ uint64_t MurmurHash3_64(const char *key, uint32_t len) {
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,7 +134,7 @@ 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
)
{
if
(
fabs
(
f
)
<
FLT_MAX
/
BASE
-
DLT
)
{
int32_t
t
=
(
int32_t
)(
round
(
BASE
*
(
f
+
DLT
)));
return
(
uint32_t
)
t
;
}
else
{
...
...
@@ -142,7 +150,7 @@ 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
)
{
if
(
fabs
(
f
)
<
DBL_MAX
/
BASE
-
DLT
)
{
int32_t
t
=
(
int32_t
)(
round
(
BASE
*
(
f
+
DLT
)));
return
(
uint32_t
)
t
;
}
else
{
...
...
@@ -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
;
}
source/util/src/tmempool.c
浏览文件 @
fcbaa608
source/util/src/tpagedbuf.c
浏览文件 @
fcbaa608
...
...
@@ -48,7 +48,8 @@ struct SDiskbasedBuf {
};
static
int32_t
createDiskFile
(
SDiskbasedBuf
*
pBuf
)
{
pBuf
->
pFile
=
taosOpenFile
(
pBuf
->
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_READ
|
TD_FILE_TRUNC
|
TD_FILE_AUTO_DEL
);
pBuf
->
pFile
=
taosOpenFile
(
pBuf
->
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_READ
|
TD_FILE_TRUNC
|
TD_FILE_AUTO_DEL
);
if
(
pBuf
->
pFile
==
NULL
)
{
return
TAOS_SYSTEM_ERROR
(
errno
);
}
...
...
@@ -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
;
...
...
@@ -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
.
0
f
,
ps
->
flushPages
,
ps
->
loadBytes
/
1024
.
0
f
,
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
.
0
f
,
ps
->
flushPages
,
ps
->
loadBytes
/
1024
.
0
f
,
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
.
0
f
,
ps
->
flushPages
,
ps
->
loadBytes
/
1024
.
0
f
,
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
.
0
f
,
ps
->
flushPages
,
ps
->
loadBytes
/
1024
.
0
f
,
ps
->
loadPages
,
ps
->
loadBytes
/
(
1024
.
0
*
ps
->
loadPages
));
}
else
{
...
...
source/util/src/tscalablebf.c
浏览文件 @
fcbaa608
...
...
@@ -21,8 +21,7 @@
#define DEFAULT_GROWTH 2
#define DEFAULT_TIGHTENING_RATIO 0.5
static
SBloomFilter
*
tScalableBfAddFilter
(
SScalableBf
*
pSBf
,
uint64_t
expectedEntries
,
double
errorRate
);
static
SBloomFilter
*
tScalableBfAddFilter
(
SScalableBf
*
pSBf
,
uint64_t
expectedEntries
,
double
errorRate
);
SScalableBf
*
tScalableBfInit
(
uint64_t
expectedEntries
,
double
errorRate
)
{
const
uint32_t
defaultSize
=
8
;
...
...
@@ -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
);
}
...
...
source/util/src/tthread.c
浏览文件 @
fcbaa608
source/util/src/ttimer.c
浏览文件 @
fcbaa608
...
...
@@ -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(...) \
{ \
...
...
@@ -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
;
}
...
...
source/util/src/tworker.c
浏览文件 @
fcbaa608
source/util/test/arrayTest.cpp
浏览文件 @
fcbaa608
...
...
@@ -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
++
)
{
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
);
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
);
...
...
source/util/test/bloomFilterTest.cpp
浏览文件 @
fcbaa608
#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
);
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
));
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
;
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
);
}
\ No newline at end of file
source/util/test/hashTest.cpp
浏览文件 @
fcbaa608
此差异已折叠。
点击以展开。
source/util/test/pageBufferTest.cpp
浏览文件 @
fcbaa608
...
...
@@ -25,7 +25,7 @@ void simpleTest() {
SIDList
list
=
getDataBufPagesIdList
(
pBuf
);
ASSERT_EQ
(
taosArrayGetSize
(
list
),
1
);
//ASSERT_EQ(getNumOfBufGroupId(pBuf), 1);
//
ASSERT_EQ(getNumOfBufGroupId(pBuf), 1);
releaseBufPage
(
pBuf
,
pBufPage
);
...
...
@@ -57,7 +57,7 @@ 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
;
...
...
@@ -106,7 +106,7 @@ 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
;
...
...
@@ -159,7 +159,6 @@ void recyclePageTest() {
}
}
// namespace
TEST
(
testCase
,
resultBufferTest
)
{
taosSeedRand
(
taosGetTimestampSec
());
simpleTest
();
...
...
source/util/test/stringTest.cpp
浏览文件 @
fcbaa608
source/util/test/taosbsearchTest.cpp
浏览文件 @
fcbaa608
source/util/test/trefTest.c
浏览文件 @
fcbaa608
此差异已折叠。
点击以展开。
tools/scripts/codeFormat.sh
浏览文件 @
fcbaa608
...
...
@@ -9,7 +9,8 @@ cd ${PRJ_ROOT_DIR}
FORMAT_DIR_LIST
=(
"include"
# "source"
"source/os"
"source/util"
)
for
d
in
${
FORMAT_DIR_LIST
[@]
}
;
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录