Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aa1a5700
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
aa1a5700
编写于
12月 07, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-2371
上级
1fc33800
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
225 addition
and
258 deletion
+225
-258
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
+0
-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
+28
-31
src/util/src/tnote.c
src/util/src/tnote.c
+190
-211
未找到文件。
src/client/src/tscAsync.c
浏览文件 @
aa1a5700
...
...
@@ -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
浏览文件 @
aa1a5700
...
...
@@ -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
浏览文件 @
aa1a5700
...
...
@@ -41,7 +41,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 +77,6 @@ int32_t tscInitRpc(const char *user, const char *secretEncrypt, void **pDnodeCon
return
0
;
}
void
taos_init_imp
(
void
)
{
char
temp
[
128
]
=
{
0
};
...
...
@@ -111,11 +109,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
浏览文件 @
aa1a5700
...
...
@@ -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
浏览文件 @
aa1a5700
...
...
@@ -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
浏览文件 @
aa1a5700
...
...
@@ -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
浏览文件 @
aa1a5700
...
...
@@ -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
浏览文件 @
aa1a5700
...
...
@@ -20,41 +20,38 @@
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
taosNoteMaxLines
;
int
taosNoteLines
;
char
taosNoteName
[
NOTE_FILE_NAME_LEN
];
int
taosNoteFlag
;
int
taosNoteFd
;
int
taosNoteOpenInProgress
;
pthread_mutex_t
taosNoteMutex
;
}
taosNoteInfo
;
void
taosNotePrint
(
taosNoteInfo
*
pNote
,
const
char
*
const
format
,
...);
extern
taosNoteInfo
m_HttpNote
;
extern
taosNoteInfo
m_TscNote
;
extern
int
tsHttpEnableRecordSql
;
extern
int
tsTscEnableRecordSql
;
#define taosNotePrintHttp(...) \
typedef
struct
{
int32_t
fileNum
;
int32_t
maxLines
;
int32_t
lines
;
int32_t
flag
;
int32_t
fd
;
int32_t
openInProgress
;
char
name
[
NOTE_FILE_NAME_LEN
];
pthread_mutex_t
mutex
;
}
SNoteObj
;
extern
SNoteObj
tsHttpNote
;
extern
SNoteObj
tsTscNote
;
extern
SNoteObj
tsErrorNote
;
void
taosInitNotes
();
void
taosNotePrint
(
SNoteObj
*
pNote
,
const
char
*
const
format
,
...);
#define nPrintHttp(...) \
if (tsHttpEnableRecordSql) { \
taosNotePrint(&
m_
HttpNote, __VA_ARGS__); \
taosNotePrint(&
ts
HttpNote, __VA_ARGS__); \
}
#define taosNotePrintTsc(...) \
if (tsTscEnableRecordSql) { \
taosNotePrint(&m_TscNote, __VA_ARGS__); \
}
#define nPrintTsc(...) \
if (tsTscEnableRecordSql) { \
taosNotePrint(&tsTscNote, __VA_ARGS__); \
}
#define nError(...) taosNotePrint(&tsErrorNote, __VA_ARGS__);
#ifdef __cplusplus
}
...
...
src/util/src/tnote.c
浏览文件 @
aa1a5700
...
...
@@ -13,277 +13,256 @@
* 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
tsErrorNote
;
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
}
;
void
taosInitNote
(
int
32_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
"
);
}
memset
(
pNote
,
0
,
sizeof
(
taosNoteInfo
));
pNote
->
taosNoteFileNum
=
1
;
//pNote->taosNoteMaxLines = 0;
//pNote->taosNoteLines = 0;
//pNote->taosNoteFlag = 0;
pNote
->
taosNoteFd
=
-
1
;
//pNote->taosNoteOpenInProgress = 0;
taosNotePrint
(
pNote
,
"=================================================="
);
taosNotePrint
(
pNote
,
"=================== new note ==================="
);
taosNotePrint
(
pNote
,
"=================================================="
);
}
if
(
taosOpenNoteWithMaxLines
(
temp
,
numOfNoteLines
,
maxNotes
,
pNote
)
<
0
)
fprintf
(
stderr
,
"failed to init note file
\n
"
)
;
void
taosInitNotes
()
{
char
name
[
TSDB_FILENAME_LEN
*
2
]
=
{
0
}
;
taosNotePrint
(
pNote
,
"=================================================="
);
taosNotePrint
(
pNote
,
"=================== new note ==================="
);
taosNotePrint
(
pNote
,
"=================================================="
);
if
(
tsTscEnableRecordSql
)
{
snprintf
(
name
,
TSDB_FILENAME_LEN
*
2
,
"%s/tscsql-%d"
,
tsLogDir
,
taosGetPId
());
taosInitNote
(
tsNumOfLogLines
,
1
,
&
tsTscNote
,
name
);
}
if
(
tsHttpEnableRecordSql
)
{
snprintf
(
name
,
TSDB_FILENAME_LEN
*
2
,
"%s/httpsql"
,
tsLogDir
);
taosInitNote
(
tsNumOfLogLines
,
1
,
&
tsHttpNote
,
name
);
}
if
(
tscEmbedded
==
0
)
{
snprintf
(
name
,
TSDB_FILENAME_LEN
*
2
,
"%s/note"
,
tsLogDir
);
taosInitNote
(
tsNumOfLogLines
,
1
,
&
tsErrorNote
,
name
);
}
}
void
taosCloseNoteByFd
(
int
oldFd
,
taosNoteInfo
*
pNote
);
bool
taosLockNote
(
int
fd
,
taosNoteInfo
*
pNote
)
{
if
(
fd
<
0
)
return
false
;
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
;
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
;
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
);
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;
}
*/
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
;
}
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
;
}
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
];
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
;
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
notestat0
,
notestat1
;
pNote
->
taosNoteM
axLines
=
maxLines
;
pNote
->
taosNoteF
ileNum
=
maxNoteNum
;
taosGetNoteName
(
fn
,
pNote
);
pNote
->
m
axLines
=
maxLines
;
pNote
->
f
ileNum
=
maxNoteNum
;
taosGetNoteName
(
fn
,
pNote
);
if
(
strlen
(
fn
)
>
NOTE_FILE_NAME_LEN
*
2
-
2
)
{
fprintf
(
stderr
,
"the len of file name overflow:%s
\n
"
,
fn
);
return
-
1
;
}
if
(
strlen
(
fn
)
>
NOTE_FILE_NAME_LEN
*
2
-
2
)
{
fprintf
(
stderr
,
"the len of file name overflow:%s
\n
"
,
fn
);
return
-
1
;
}
strcpy
(
name
,
fn
);
strcat
(
name
,
".0"
);
strcpy
(
name
,
fn
);
strcat
(
name
,
".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
;
// if none of the note files exist, open 0, if both exists, open the old one
if
(
stat
(
name
,
&
notestat0
)
<
0
)
{
pNote
->
flag
=
0
;
}
else
{
strcpy
(
name
,
fn
);
strcat
(
name
,
".1"
);
if
(
stat
(
name
,
&
notestat1
)
<
0
)
{
pNote
->
flag
=
1
;
}
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
;
}
pNote
->
flag
=
(
notestat0
.
st_mtime
>
notestat1
.
st_mtime
)
?
0
:
1
;
}
}
char
noteName
[
NOTE_FILE_NAME_LEN
*
2
]
=
"
\0
"
;
sprintf
(
noteName
,
"%s.%d"
,
pNote
->
taosNoteName
,
pNote
->
taosNoteF
lag
);
pthread_mutex_init
(
&
pNote
->
taosNoteM
utex
,
NULL
);
char
noteName
[
NOTE_FILE_NAME_LEN
*
2
]
=
"
\0
"
;
sprintf
(
noteName
,
"%s.%d"
,
pNote
->
name
,
pNote
->
f
lag
);
pthread_mutex_init
(
&
pNote
->
m
utex
,
NULL
);
umask
(
0
);
pNote
->
taosNoteF
d
=
open
(
noteName
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
umask
(
0
);
pNote
->
f
d
=
open
(
noteName
,
O_WRONLY
|
O_CREAT
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
if
(
pNote
->
taosNoteF
d
<
0
)
{
fprintf
(
stderr
,
"failed to open note file:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
-
1
;
}
taosLockNote
(
pNote
->
taosNoteF
d
,
pNote
);
if
(
pNote
->
f
d
<
0
)
{
fprintf
(
stderr
,
"failed to open note file:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
-
1
;
}
taosLockNote
(
pNote
->
f
d
,
pNote
);
// only an estimate for number of lines
struct
stat
filestat
;
if
(
fstat
(
pNote
->
taosNoteF
d
,
&
filestat
)
<
0
)
{
fprintf
(
stderr
,
"failed to fstat note file:%s reason:%s
\n
"
,
noteName
,
strerror
(
errno
));
return
-
1
;
}
size
=
(
in
t
)
filestat
.
st_size
;
pNote
->
taosNoteL
ines
=
size
/
60
;
// only an estimate for number of lines
struct
stat
filestat
;
if
(
fstat
(
pNote
->
f
d
,
&
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
->
l
ines
=
size
/
60
;
lseek
(
pNote
->
taosNoteF
d
,
0
,
SEEK_END
);
lseek
(
pNote
->
f
d
,
0
,
SEEK_END
);
return
0
;
return
0
;
}
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
;
if
(
pNote
->
fd
>=
0
)
{
taosWrite
(
pNote
->
fd
,
buffer
,
len
);
if
(
pNote
->
maxLines
>
0
)
{
pNote
->
lines
++
;
if
((
pNote
->
lines
>
pNote
->
maxLines
)
&&
(
pNote
->
openInProgress
==
0
))
taosOpenNewNote
(
pNote
);
}
}
}
void
taosCloseNote
(
taosNoteInfo
*
pNote
)
{
taosCloseNoteByFd
(
pNote
->
taosNoteFd
,
pNote
);
}
void
taosCloseNote
(
SNoteObj
*
pNote
)
{
taosCloseNoteByFd
(
pNote
->
fd
,
pNote
);
}
void
taosCloseNoteByFd
(
int
fd
,
taosNoteInfo
*
pNote
)
{
if
(
fd
>=
0
)
{
taosUnLockNote
(
fd
,
pNote
);
close
(
fd
);
}
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录