Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4f4c3479
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4f4c3479
编写于
12月 08, 2020
作者:
L
liuyq-617
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into test/jenkins
上级
63f2e024
5a470e7b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
243 addition
and
265 deletion
+243
-265
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+1
-1
src/client/src/tscSql.c
src/client/src/tscSql.c
+1
-1
src/client/src/tscSystem.c
src/client/src/tscSystem.c
+2
-7
src/dnode/src/dnodeMain.c
src/dnode/src/dnodeMain.c
+2
-0
src/kit/shell/src/shellLinux.c
src/kit/shell/src/shellLinux.c
+1
-1
src/plugins/http/src/httpSql.c
src/plugins/http/src/httpSql.c
+2
-2
src/plugins/http/src/httpSystem.c
src/plugins/http/src/httpSystem.c
+0
-4
src/util/inc/tnote.h
src/util/inc/tnote.h
+32
-31
src/util/src/tlog.c
src/util/src/tlog.c
+2
-1
src/util/src/tnote.c
src/util/src/tnote.c
+200
-217
未找到文件。
src/client/src/tscAsync.c
浏览文件 @
4f4c3479
...
...
@@ -96,7 +96,7 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa
return
;
}
taosNote
PrintTsc
(
sqlstr
);
n
PrintTsc
(
sqlstr
);
SSqlObj
*
pSql
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pSql
==
NULL
)
{
...
...
src/client/src/tscSql.c
浏览文件 @
4f4c3479
...
...
@@ -344,7 +344,7 @@ TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen, TAOS_RES
return
NULL
;
}
taosNote
PrintTsc
(
sqlstr
);
n
PrintTsc
(
sqlstr
);
SSqlObj
*
pSql
=
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pSql
==
NULL
)
{
...
...
src/client/src/tscSystem.c
浏览文件 @
4f4c3479
...
...
@@ -17,6 +17,7 @@
#include "taosmsg.h"
#include "tref.h"
#include "trpc.h"
#include "tnote.h"
#include "tsystem.h"
#include "ttimer.h"
#include "tutil.h"
...
...
@@ -41,7 +42,6 @@ int tscRefId = -1;
int
tscNumOfThreads
;
static
pthread_once_t
tscinit
=
PTHREAD_ONCE_INIT
;
void
taosInitNote
(
int
numOfNoteLines
,
int
maxNotes
,
char
*
lable
);
//void tscUpdateEpSet(void *ahandle, SRpcEpSet *pEpSet);
void
tscCheckDiskUsage
(
void
*
UNUSED_PARAM
(
para
),
void
*
UNUSED_PARAM
(
param
))
{
...
...
@@ -78,7 +78,6 @@ int32_t tscInitRpc(const char *user, const char *secretEncrypt, void **pDnodeCon
return
0
;
}
void
taos_init_imp
(
void
)
{
char
temp
[
128
]
=
{
0
};
...
...
@@ -104,6 +103,7 @@ void taos_init_imp(void) {
taosReadGlobalCfg
();
taosCheckGlobalCfg
();
taosInitNotes
();
rpcInit
();
tscDebug
(
"starting to initialize TAOS client ..."
);
...
...
@@ -111,11 +111,6 @@ void taos_init_imp(void) {
}
taosSetCoreDump
();
if
(
tsTscEnableRecordSql
!=
0
)
{
taosInitNote
(
tsNumOfLogLines
/
10
,
1
,
(
char
*
)
"tsc_note"
);
}
tscInitMsgsFp
();
int
queueSize
=
tsMaxConnections
*
2
;
...
...
src/dnode/src/dnodeMain.c
浏览文件 @
4f4c3479
...
...
@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taos.h"
#include "tnote.h"
#include "tconfig.h"
#include "tfile.h"
#include "twal.h"
...
...
@@ -98,6 +99,7 @@ int32_t dnodeInitSystem() {
taosInitGlobalCfg
();
taosReadGlobalLogCfg
();
taosSetCoreDump
();
taosInitNotes
();
signal
(
SIGPIPE
,
SIG_IGN
);
if
(
dnodeCreateDir
(
tsLogDir
)
<
0
)
{
...
...
src/kit/shell/src/shellLinux.c
浏览文件 @
4f4c3479
...
...
@@ -46,7 +46,7 @@ static struct argp_option options[] = {
{
"thread"
,
'T'
,
"THREADNUM"
,
0
,
"Number of threads when using multi-thread to import data."
},
{
"database"
,
'd'
,
"DATABASE"
,
0
,
"Database to use when connecting to the server."
},
{
"timezone"
,
't'
,
"TIMEZONE"
,
0
,
"Time zone of the shell, default is local."
},
{
"netrole"
,
'n'
,
"NETROLE"
,
0
,
"Net role when network connectivity test, default is
NULL
, options: client|server|rpc|startup."
},
{
"netrole"
,
'n'
,
"NETROLE"
,
0
,
"Net role when network connectivity test, default is
startup
, options: client|server|rpc|startup."
},
{
"pktlen"
,
'l'
,
"PKTLEN"
,
0
,
"Packet length used for net test, default is 1000 bytes."
},
{
0
}};
...
...
src/plugins/http/src/httpSql.c
浏览文件 @
4f4c3479
...
...
@@ -181,7 +181,7 @@ void httpProcessMultiSql(HttpContext *pContext) {
char
*
sql
=
httpGetCmdsString
(
pContext
,
cmd
->
sql
);
httpTraceL
(
"context:%p, fd:%d, user:%s, process pos:%d, start query, sql:%s"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
multiCmds
->
pos
,
sql
);
taosNote
PrintHttp
(
sql
);
n
PrintHttp
(
sql
);
taos_query_a
(
pContext
->
session
->
taos
,
sql
,
httpProcessMultiSqlCallBack
,
(
void
*
)
pContext
);
}
...
...
@@ -329,7 +329,7 @@ void httpProcessSingleSqlCmd(HttpContext *pContext) {
}
httpTraceL
(
"context:%p, fd:%d, user:%s, start query, sql:%s"
,
pContext
,
pContext
->
fd
,
pContext
->
user
,
sql
);
taosNote
PrintHttp
(
sql
);
n
PrintHttp
(
sql
);
taos_query_a
(
pSession
->
taos
,
sql
,
httpProcessSingleSqlCallBack
,
(
void
*
)
pContext
);
}
...
...
src/plugins/http/src/httpSystem.c
浏览文件 @
4f4c3479
...
...
@@ -37,7 +37,6 @@ void opInitHandle(HttpServer* pServer) {}
#endif
HttpServer
tsHttpServer
;
void
taosInitNote
(
int32_t
numOfNoteLines
,
int32_t
maxNotes
,
char
*
lable
);
int32_t
httpInitSystem
()
{
strcpy
(
tsHttpServer
.
label
,
"rest"
);
...
...
@@ -48,9 +47,6 @@ int32_t httpInitSystem() {
pthread_mutex_init
(
&
tsHttpServer
.
serverMutex
,
NULL
);
if
(
tsHttpEnableRecordSql
!=
0
)
{
taosInitNote
(
tsNumOfLogLines
/
10
,
1
,
(
char
*
)
"http_note"
);
}
restInitHandle
(
&
tsHttpServer
);
adminInitHandle
(
&
tsHttpServer
);
gcInitHandle
(
&
tsHttpServer
);
...
...
src/util/inc/tnote.h
浏览文件 @
4f4c3479
...
...
@@ -20,41 +20,42 @@
extern
"C"
{
#endif
#include "os.h"
#include "tutil.h"
#include "tglobal.h"
#define MAX_NOTE_LINE_SIZE 66000
#define NOTE_FILE_NAME_LEN 300
typedef
struct
_taosNoteInfo
{
int
taosNoteFileNum
;
int
taosNoteM
axLines
;
int
taosNoteL
ines
;
char
taosNoteName
[
NOTE_FILE_NAME_LEN
]
;
int
taosNoteFlag
;
int
taosNoteFd
;
int
taosNoteOpenInProgress
;
pthread_mutex_t
taosNoteM
utex
;
}
taosNoteInfo
;
void
taosNotePrint
(
taosNoteInfo
*
pNote
,
const
char
*
const
format
,
...)
;
extern
taosNoteInfo
m_Http
Note
;
extern
taosNoteInfo
m_TscNote
;
extern
int
tsHttpEnableRecordSql
;
extern
int
tsTscEnableRecordSql
;
#define
taosNotePrintHttp(...)
\
typedef
struct
{
int
32_t
fileNum
;
int
32_t
m
axLines
;
int
32_t
l
ines
;
int32_t
flag
;
int
32_t
fd
;
int
32_t
openInProgress
;
char
name
[
NOTE_FILE_NAME_LEN
]
;
pthread_mutex_t
m
utex
;
}
SNoteObj
;
extern
SNoteObj
tsHttpNote
;
extern
SNoteObj
tsTscNote
;
extern
SNoteObj
tsInfo
Note
;
void
taosInitNotes
();
void
taosNotePrint
(
SNoteObj
*
pNote
,
const
char
*
const
format
,
...)
;
void
taosNotePrintBuffer
(
SNoteObj
*
pNote
,
char
*
buffer
,
int32_t
len
)
;
#define
nPrintHttp(...)
\
if (tsHttpEnableRecordSql) { \
taosNotePrint(&m_HttpNote, __VA_ARGS__); \
taosNotePrint(&tsHttpNote, __VA_ARGS__); \
}
#define nPrintTsc(...) \
if (tsTscEnableRecordSql) { \
taosNotePrint(&tsTscNote, __VA_ARGS__); \
}
#define nInfo(buffer, len) \
if (tscEmbedded == 1) { \
taosNotePrintBuffer(&tsInfoNote, buffer, len); \
}
#define taosNotePrintTsc(...) \
if (tsTscEnableRecordSql) { \
taosNotePrint(&m_TscNote, __VA_ARGS__); \
}
#ifdef __cplusplus
}
...
...
src/util/src/tlog.c
浏览文件 @
4f4c3479
...
...
@@ -17,6 +17,7 @@
#include "os.h"
#include "tulog.h"
#include "tlog.h"
#include "tnote.h"
#include "tutil.h"
#define MAX_LOGLINE_SIZE (1000)
...
...
@@ -287,7 +288,6 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
tsLogObj
.
fileNum
=
maxFileNum
;
taosGetLogFileName
(
fn
);
if
(
strlen
(
fn
)
<
LOG_FILE_NAME_LEN
+
50
-
2
)
{
strcpy
(
name
,
fn
);
strcat
(
name
,
".0"
);
...
...
@@ -401,6 +401,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) {
}
if
(
dflag
&
DEBUG_SCREEN
)
taosWrite
(
1
,
buffer
,
(
uint32_t
)
len
);
if
(
dflag
==
255
)
nInfo
(
buffer
,
len
);
}
void
taosDumpData
(
unsigned
char
*
msg
,
int32_t
len
)
{
...
...
src/util/src/tnote.c
浏览文件 @
4f4c3479
...
...
@@ -13,277 +13,260 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tutil.h"
#include "tglobal.h"
#include "tnote.h"
taosNoteInfo
m_HttpNote
;
taosNoteInfo
m_TscNote
;
SNoteObj
tsHttpNote
;
SNoteObj
tsTscNote
;
SNoteObj
tsInfoNote
;
int
taosOpenNoteWithMaxLines
(
char
*
fn
,
int
maxLines
,
int
maxNoteNum
,
taosNoteInfo
*
pNote
);
static
int32_t
taosOpenNoteWithMaxLines
(
char
*
fn
,
int32_t
maxLines
,
int32_t
maxNoteNum
,
SNoteObj
*
pNote
);
static
void
taosCloseNoteByFd
(
int32_t
oldFd
,
SNoteObj
*
pNote
);
void
taosInitNote
(
int
numOfNoteLines
,
int
maxNotes
,
char
*
lable
)
{
taosNoteInfo
*
pNote
=
NULL
;
char
temp
[
128
]
=
{
0
}
;
static
void
taosInitNote
(
int32_t
numOfLines
,
int32_t
maxNotes
,
SNoteObj
*
pNote
,
char
*
name
)
{
memset
(
pNote
,
0
,
sizeof
(
SNoteObj
));
pNote
->
fileNum
=
1
;
pNote
->
fd
=
-
1
;
if
(
strcasecmp
(
lable
,
"http_note"
)
==
0
)
{
pNote
=
&
m_HttpNote
;
sprintf
(
temp
,
"%s/httpnote"
,
tsLogDir
);
}
else
if
(
strcasecmp
(
lable
,
"tsc_note"
)
==
0
)
{
pNote
=
&
m_TscNote
;
sprintf
(
temp
,
"%s/tscnote-%d"
,
tsLogDir
,
getpid
());
}
else
{
return
;
}
if
(
taosOpenNoteWithMaxLines
(
name
,
numOfLines
,
maxNotes
,
pNote
)
<
0
)
{
fprintf
(
stderr
,
"failed to init note file
\n
"
);
}
taosNotePrint
(
pNote
,
"=================================================="
);
taosNotePrint
(
pNote
,
"=================== new note ==================="
);
taosNotePrint
(
pNote
,
"=================================================="
);
}
memset
(
pNote
,
0
,
sizeof
(
taosNoteInfo
));
pNote
->
taosNoteFileNum
=
1
;
//pNote->taosNoteMaxLines = 0;
//pNote->taosNoteLines = 0;
//pNote->taosNoteFlag = 0;
pNote
->
taosNoteFd
=
-
1
;
//pNote->taosNoteOpenInProgress = 0;
void
taosInitNotes
()
{
char
name
[
TSDB_FILENAME_LEN
*
2
]
=
{
0
};
if
(
taosOpenNoteWithMaxLines
(
temp
,
numOfNoteLines
,
maxNotes
,
pNote
)
<
0
)
fprintf
(
stderr
,
"failed to init note file
\n
"
);
if
(
tsTscEnableRecordSql
)
{
snprintf
(
name
,
TSDB_FILENAME_LEN
*
2
,
"%s/tscsql-%d"
,
tsLogDir
,
taosGetPId
());
taosInitNote
(
tsNumOfLogLines
,
1
,
&
tsTscNote
,
name
);
}
taosNotePrint
(
pNote
,
"=================================================="
);
taosNotePrint
(
pNote
,
"=================== new note ==================="
);
taosNotePrint
(
pNote
,
"=================================================="
);
if
(
tsHttpEnableRecordSql
)
{
snprintf
(
name
,
TSDB_FILENAME_LEN
*
2
,
"%s/httpsql"
,
tsLogDir
);
taosInitNote
(
tsNumOfLogLines
,
1
,
&
tsHttpNote
,
name
);
}
if
(
tscEmbedded
==
1
)
{
snprintf
(
name
,
TSDB_FILENAME_LEN
*
2
,
"%s/taosinfo"
,
tsLogDir
);
taosInitNote
(
tsNumOfLogLines
,
1
,
&
tsInfoNote
,
name
);
}
}
void
taosCloseNoteByFd
(
int
oldFd
,
taosNoteInfo
*
pNote
);
bool
taosLockNote
(
int
fd
,
taosNoteInfo
*
pNote
)
{
if
(
fd
<
0
)
return
false
;
static
bool
taosLockNote
(
int32_t
fd
,
SNoteObj
*
pNote
)
{
if
(
fd
<
0
)
return
false
;
if
(
pNote
->
taosNoteFileNum
>
1
)
{
int
ret
=
(
int
)(
flock
(
fd
,
LOCK_EX
|
LOCK_NB
));
if
(
ret
==
0
)
{
return
true
;
}
if
(
pNote
->
fileNum
>
1
)
{
int32_t
ret
=
(
int32_t
)(
flock
(
fd
,
LOCK_EX
|
LOCK_NB
));
if
(
ret
==
0
)
{
return
true
;
}
}
return
false
;
return
false
;
}
void
taosUnLockNote
(
int
fd
,
taosNoteInfo
*
pNote
)
{
if
(
fd
<
0
)
return
;
static
void
taosUnLockNote
(
int32_t
fd
,
SNoteObj
*
pNote
)
{
if
(
fd
<
0
)
return
;
if
(
pNote
->
taosNoteF
ileNum
>
1
)
{
flock
(
fd
,
LOCK_UN
|
LOCK_NB
);
}
if
(
pNote
->
f
ileNum
>
1
)
{
flock
(
fd
,
LOCK_UN
|
LOCK_NB
);
}
}
void
*
taosThreadToOpenNewNote
(
void
*
param
)
{
char
name
[
NOTE_FILE_NAME_LEN
*
2
];
taosNoteInfo
*
pNote
=
(
taosNoteInfo
*
)
param
;
static
void
*
taosThreadToOpenNewNote
(
void
*
param
)
{
char
name
[
NOTE_FILE_NAME_LEN
*
2
];
SNoteObj
*
pNote
=
(
SNoteObj
*
)
param
;
pNote
->
taosNoteF
lag
^=
1
;
pNote
->
taosNoteL
ines
=
0
;
sprintf
(
name
,
"%s.%d"
,
pNote
->
taosNoteName
,
pNote
->
taosNoteF
lag
);
pNote
->
f
lag
^=
1
;
pNote
->
l
ines
=
0
;
sprintf
(
name
,
"%s.%d"
,
pNote
->
name
,
pNote
->
f
lag
);
umask
(
0
);
umask
(
0
);
in
t
fd
=
open
(
name
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
fd
<
0
)
{
return
NULL
;
}
int32_
t
fd
=
open
(
name
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
fd
<
0
)
{
return
NULL
;
}
taosLockNote
(
fd
,
pNote
);
(
void
)
lseek
(
fd
,
0
,
SEEK_SET
);
taosLockNote
(
fd
,
pNote
);
(
void
)
lseek
(
fd
,
0
,
SEEK_SET
);
int
oldFd
=
pNote
->
taosNoteF
d
;
pNote
->
taosNoteF
d
=
fd
;
pNote
->
taosNoteL
ines
=
0
;
pNote
->
taosNoteO
penInProgress
=
0
;
taosNotePrint
(
pNote
,
"=============== new note is opened ============="
);
int32_t
oldFd
=
pNote
->
f
d
;
pNote
->
f
d
=
fd
;
pNote
->
l
ines
=
0
;
pNote
->
o
penInProgress
=
0
;
taosNotePrint
(
pNote
,
"=============== new note is opened ============="
);
taosCloseNoteByFd
(
oldFd
,
pNote
);
return
NULL
;
taosCloseNoteByFd
(
oldFd
,
pNote
);
return
NULL
;
}
int
taosOpenNewNote
(
taosNoteInfo
*
pNote
)
{
pthread_mutex_lock
(
&
pNote
->
taosNoteMutex
);
static
int32_t
taosOpenNewNote
(
SNoteObj
*
pNote
)
{
pthread_mutex_lock
(
&
pNote
->
mutex
);
if
(
pNote
->
taosNoteLines
>
pNote
->
taosNoteMaxLines
&&
pNote
->
taosNoteO
penInProgress
==
0
)
{
pNote
->
taosNoteO
penInProgress
=
1
;
if
(
pNote
->
lines
>
pNote
->
maxLines
&&
pNote
->
o
penInProgress
==
0
)
{
pNote
->
o
penInProgress
=
1
;
taosNotePrint
(
pNote
,
"=============== open new note =================="
);
pthread_t
pattern
;
pthread_attr_t
attr
;
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
taosNotePrint
(
pNote
,
"=============== open new note =================="
);
pthread_t
pattern
;
pthread_attr_t
attr
;
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
pthread_create
(
&
pattern
,
&
attr
,
taosThreadToOpenNewNote
,
(
void
*
)
pNote
);
pthread_attr_destroy
(
&
attr
);
}
pthread_create
(
&
pattern
,
&
attr
,
taosThreadToOpenNewNote
,
(
void
*
)
pNote
);
pthread_attr_destroy
(
&
attr
);
}
pthread_mutex_unlock
(
&
pNote
->
taosNoteM
utex
);
pthread_mutex_unlock
(
&
pNote
->
m
utex
);
return
pNote
->
taosNoteF
d
;
return
pNote
->
f
d
;
}
bool
taosCheckNoteIsOpen
(
char
*
noteName
,
taosNoteInfo
*
pNote
)
{
/*
int exist = access(noteName, F_OK);
if (exist != 0) {
return false;
}
*/
int
fd
=
open
(
noteName
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"failed to open note:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
true
;
}
static
bool
taosCheckNoteIsOpen
(
char
*
noteName
,
SNoteObj
*
pNote
)
{
int32_t
fd
=
open
(
noteName
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"failed to open note:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
true
;
}
if
(
taosLockNote
(
fd
,
pNote
))
{
taosUnLockNote
(
fd
,
pNote
);
close
(
fd
);
return
false
;
}
else
{
close
(
fd
);
return
true
;
}
if
(
taosLockNote
(
fd
,
pNote
))
{
taosUnLockNote
(
fd
,
pNote
);
close
(
fd
);
return
false
;
}
else
{
close
(
fd
);
return
true
;
}
}
void
taosGetNoteName
(
char
*
fn
,
taosNoteInfo
*
pNote
)
{
if
(
pNote
->
taosNoteFileNum
>
1
)
{
for
(
int
i
=
0
;
i
<
pNote
->
taosNoteFileNum
;
i
++
)
{
char
fileName
[
NOTE_FILE_NAME_LEN
];
static
void
taosGetNoteName
(
char
*
fn
,
SNoteObj
*
pNote
)
{
if
(
pNote
->
fileNum
>
1
)
{
for
(
int32_t
i
=
0
;
i
<
pNote
->
fileNum
;
i
++
)
{
char
fileName
[
NOTE_FILE_NAME_LEN
];
sprintf
(
fileName
,
"%s%d.0"
,
fn
,
i
);
bool
file1open
=
taosCheckNoteIsOpen
(
fileName
,
pNote
);
sprintf
(
fileName
,
"%s%d.0"
,
fn
,
i
);
bool
file1open
=
taosCheckNoteIsOpen
(
fileName
,
pNote
);
sprintf
(
fileName
,
"%s%d.1"
,
fn
,
i
);
bool
file2open
=
taosCheckNoteIsOpen
(
fileName
,
pNote
);
sprintf
(
fileName
,
"%s%d.1"
,
fn
,
i
);
bool
file2open
=
taosCheckNoteIsOpen
(
fileName
,
pNote
);
if
(
!
file1open
&&
!
file2open
)
{
sprintf
(
pNote
->
taosNoteName
,
"%s%d"
,
fn
,
i
);
return
;
}
}
if
(
!
file1open
&&
!
file2open
)
{
sprintf
(
pNote
->
name
,
"%s%d"
,
fn
,
i
);
return
;
}
}
}
if
(
strlen
(
fn
)
<
NOTE_FILE_NAME_LEN
)
{
strcpy
(
pNote
->
taosNoteN
ame
,
fn
);
}
if
(
strlen
(
fn
)
<
NOTE_FILE_NAME_LEN
)
{
strcpy
(
pNote
->
n
ame
,
fn
);
}
}
int
taosOpenNoteWithMaxLines
(
char
*
fn
,
int
maxLines
,
int
maxNoteNum
,
taosNoteInfo
*
pNote
)
{
char
name
[
NOTE_FILE_NAME_LEN
*
2
]
=
"
\0
"
;
struct
stat
notestat0
,
notestat1
;
int
size
;
pNote
->
taosNoteMaxLines
=
maxLines
;
pNote
->
taosNoteFileNum
=
maxNoteNum
;
taosGetNoteName
(
fn
,
pNote
);
static
int32_t
taosOpenNoteWithMaxLines
(
char
*
fn
,
int32_t
maxLines
,
int32_t
maxNoteNum
,
SNoteObj
*
pNote
)
{
char
name
[
NOTE_FILE_NAME_LEN
*
2
]
=
{
0
};
int32_t
size
;
struct
stat
logstat0
,
logstat1
;
if
(
strlen
(
fn
)
>
NOTE_FILE_NAME_LEN
*
2
-
2
)
{
fprintf
(
stderr
,
"the len of file name overflow:%s
\n
"
,
fn
);
return
-
1
;
}
pNote
->
maxLines
=
maxLines
;
pNote
->
fileNum
=
maxNoteNum
;
taosGetNoteName
(
fn
,
pNote
);
if
(
strlen
(
fn
)
<
NOTE_FILE_NAME_LEN
+
50
-
2
)
{
strcpy
(
name
,
fn
);
strcat
(
name
,
".0"
);
}
bool
log0Exist
=
stat
(
name
,
&
logstat0
)
>=
0
;
// if none of the note files exist, open 0, if both exists, open the old one
if
(
stat
(
name
,
&
notestat0
)
<
0
)
{
pNote
->
taosNoteFlag
=
0
;
}
else
{
strcpy
(
name
,
fn
);
strcat
(
name
,
".1"
);
if
(
stat
(
name
,
&
notestat1
)
<
0
)
{
pNote
->
taosNoteFlag
=
1
;
}
else
{
pNote
->
taosNoteFlag
=
(
notestat0
.
st_mtime
>
notestat1
.
st_mtime
)
?
0
:
1
;
}
}
char
noteName
[
NOTE_FILE_NAME_LEN
*
2
]
=
"
\0
"
;
sprintf
(
noteName
,
"%s.%d"
,
pNote
->
taosNoteName
,
pNote
->
taosNoteFlag
);
pthread_mutex_init
(
&
pNote
->
taosNoteMutex
,
NULL
);
umask
(
0
);
pNote
->
taosNoteFd
=
open
(
noteName
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
pNote
->
taosNoteFd
<
0
)
{
fprintf
(
stderr
,
"failed to open note file:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
-
1
;
}
taosLockNote
(
pNote
->
taosNoteFd
,
pNote
);
// only an estimate for number of lines
struct
stat
filestat
;
if
(
fstat
(
pNote
->
taosNoteFd
,
&
filestat
)
<
0
)
{
fprintf
(
stderr
,
"failed to fstat note file:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
-
1
;
}
size
=
(
int
)
filestat
.
st_size
;
pNote
->
taosNoteLines
=
size
/
60
;
if
(
strlen
(
fn
)
<
NOTE_FILE_NAME_LEN
+
50
-
2
)
{
strcpy
(
name
,
fn
);
strcat
(
name
,
".1"
);
}
bool
log1Exist
=
stat
(
name
,
&
logstat1
)
>=
0
;
if
(
!
log0Exist
&&
!
log1Exist
)
{
pNote
->
flag
=
0
;
}
else
if
(
!
log1Exist
)
{
pNote
->
flag
=
0
;
}
else
if
(
!
log0Exist
)
{
pNote
->
flag
=
1
;
}
else
{
pNote
->
flag
=
(
logstat0
.
st_mtime
>
logstat1
.
st_mtime
)
?
0
:
1
;
}
char
noteName
[
NOTE_FILE_NAME_LEN
*
2
]
=
{
0
};
sprintf
(
noteName
,
"%s.%d"
,
pNote
->
name
,
pNote
->
flag
);
pthread_mutex_init
(
&
pNote
->
mutex
,
NULL
);
umask
(
0
);
pNote
->
fd
=
open
(
noteName
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
pNote
->
fd
<
0
)
{
fprintf
(
stderr
,
"failed to open note file:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
-
1
;
}
taosLockNote
(
pNote
->
fd
,
pNote
);
// only an estimate for number of lines
struct
stat
filestat
;
if
(
fstat
(
pNote
->
fd
,
&
filestat
)
<
0
)
{
fprintf
(
stderr
,
"failed to fstat note file:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
-
1
;
}
size
=
(
int32_t
)
filestat
.
st_size
;
pNote
->
lines
=
size
/
60
;
lseek
(
pNote
->
fd
,
0
,
SEEK_END
);
return
0
;
}
lseek
(
pNote
->
taosNoteFd
,
0
,
SEEK_END
);
void
taosNotePrintBuffer
(
SNoteObj
*
pNote
,
char
*
buffer
,
int32_t
len
)
{
if
(
pNote
->
fd
<
0
)
return
;
taosWrite
(
pNote
->
fd
,
buffer
,
len
);
return
0
;
if
(
pNote
->
maxLines
>
0
)
{
pNote
->
lines
++
;
if
((
pNote
->
lines
>
pNote
->
maxLines
)
&&
(
pNote
->
openInProgress
==
0
))
taosOpenNewNote
(
pNote
);
}
}
void
taosNotePrint
(
taosNoteInfo
*
pNote
,
const
char
*
const
format
,
...)
{
va_list
argpointer
;
char
buffer
[
MAX_NOTE_LINE_SIZE
+
2
];
int
len
;
struct
tm
Tm
,
*
ptm
;
struct
timeval
timeSecs
;
time_t
curTime
;
gettimeofday
(
&
timeSecs
,
NULL
);
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
#ifndef LINUX
len
=
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d 0x%lld "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int
)
timeSecs
.
tv_usec
,
taosGetPthreadId
());
#else
len
=
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d %lx "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int
)
timeSecs
.
tv_usec
,
(
unsigned
long
int
)
pthread_self
());
#endif
va_start
(
argpointer
,
format
);
len
+=
vsnprintf
(
buffer
+
len
,
MAX_NOTE_LINE_SIZE
-
len
,
format
,
argpointer
);
va_end
(
argpointer
);
if
(
len
>=
MAX_NOTE_LINE_SIZE
)
len
=
MAX_NOTE_LINE_SIZE
-
2
;
buffer
[
len
++
]
=
'\n'
;
buffer
[
len
]
=
0
;
if
(
pNote
->
taosNoteFd
>=
0
)
{
taosWrite
(
pNote
->
taosNoteFd
,
buffer
,
(
unsigned
int
)
len
);
if
(
pNote
->
taosNoteMaxLines
>
0
)
{
pNote
->
taosNoteLines
++
;
if
((
pNote
->
taosNoteLines
>
pNote
->
taosNoteMaxLines
)
&&
(
pNote
->
taosNoteOpenInProgress
==
0
))
taosOpenNewNote
(
pNote
);
}
}
void
taosNotePrint
(
SNoteObj
*
pNote
,
const
char
*
const
format
,
...)
{
va_list
argpointer
;
char
buffer
[
MAX_NOTE_LINE_SIZE
+
2
];
int32_t
len
;
struct
tm
Tm
,
*
ptm
;
struct
timeval
timeSecs
;
time_t
curTime
;
gettimeofday
(
&
timeSecs
,
NULL
);
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
len
=
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d 0x%08"
PRIx64
" "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int32_t
)
timeSecs
.
tv_usec
,
taosGetPthreadId
());
va_start
(
argpointer
,
format
);
len
+=
vsnprintf
(
buffer
+
len
,
MAX_NOTE_LINE_SIZE
-
len
,
format
,
argpointer
);
va_end
(
argpointer
);
if
(
len
>=
MAX_NOTE_LINE_SIZE
)
len
=
MAX_NOTE_LINE_SIZE
-
2
;
buffer
[
len
++
]
=
'\n'
;
buffer
[
len
]
=
0
;
taosNotePrintBuffer
(
pNote
,
buffer
,
len
);
}
void
taosCloseNote
(
taosNoteInfo
*
pNote
)
{
taosCloseNoteByFd
(
pNote
->
taosNoteFd
,
pNote
);
}
// static void taosCloseNote(SNoteObj *pNote) { taosCloseNoteByFd(pNote->fd, pNote); }
void
taosCloseNoteByFd
(
int
fd
,
taosNoteInfo
*
pNote
)
{
if
(
fd
>=
0
)
{
taosUnLockNote
(
fd
,
pNote
);
close
(
fd
);
}
static
void
taosCloseNoteByFd
(
int32_t
fd
,
SNoteObj
*
pNote
)
{
if
(
fd
>=
0
)
{
taosUnLockNote
(
fd
,
pNote
);
close
(
fd
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录