未验证 提交 5a470e7b 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #4480 from taosdata/feature/wal

[TD-2371]<enhance>:Record important information to a separate log file called taoinfo
......@@ -96,7 +96,7 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa
return;
}
taosNotePrintTsc(sqlstr);
nPrintTsc(sqlstr);
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
if (pSql == NULL) {
......
......@@ -344,7 +344,7 @@ TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen, TAOS_RES
return NULL;
}
taosNotePrintTsc(sqlstr);
nPrintTsc(sqlstr);
SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
if (pSql == NULL) {
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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}};
......
......@@ -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);
taosNotePrintHttp(sql);
nPrintHttp(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);
taosNotePrintHttp(sql);
nPrintHttp(sql);
taos_query_a(pSession->taos, sql, httpProcessSingleSqlCallBack, (void *)pContext);
}
......
......@@ -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);
......
......@@ -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 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 tsInfoNote;
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
}
......
......@@ -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) {
......
......@@ -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->taosNoteFileNum > 1) {
flock(fd, LOCK_UN | LOCK_NB);
}
if (pNote->fileNum > 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->taosNoteFlag ^= 1;
pNote->taosNoteLines = 0;
sprintf(name, "%s.%d", pNote->taosNoteName, pNote->taosNoteFlag);
pNote->flag ^= 1;
pNote->lines = 0;
sprintf(name, "%s.%d", pNote->name, pNote->flag);
umask(0);
umask(0);
int 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->taosNoteFd;
pNote->taosNoteFd = fd;
pNote->taosNoteLines = 0;
pNote->taosNoteOpenInProgress = 0;
taosNotePrint(pNote, "=============== new note is opened =============");
int32_t oldFd = pNote->fd;
pNote->fd = fd;
pNote->lines = 0;
pNote->openInProgress = 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->taosNoteOpenInProgress == 0) {
pNote->taosNoteOpenInProgress = 1;
if (pNote->lines > pNote->maxLines && pNote->openInProgress == 0) {
pNote->openInProgress = 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->taosNoteMutex);
pthread_mutex_unlock(&pNote->mutex);
return pNote->taosNoteFd;
return pNote->fd;
}
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->taosNoteName, fn);
}
if (strlen(fn) < NOTE_FILE_NAME_LEN) {
strcpy(pNote->name, 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.
先完成此消息的编辑!
想要评论请 注册