提交 5f3ce43e 编写于 作者: D dapan1121

fix bug

上级 c3b84da1
......@@ -68,6 +68,8 @@ int8_t tsAsyncLog = 1;
float tsTotalLogDirGB = 0;
float tsAvailLogDirGB = 0;
float tsMinimalLogDirGB = 1.0f;
int64_t asyncLogLostLines = 0;
#ifdef _TD_POWER_
char tsLogDir[TSDB_FILENAME_LEN] = "/var/log/power";
#else
......@@ -527,10 +529,27 @@ static void taosLogBuffDestroy(SLogBuff *tLogBuff) {
}
#endif
static void taosCopyLogBuffer(SLogBuff *tLogBuff, int32_t start, int32_t end, char *msg, int32_t msgLen) {
if (start > end) {
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen);
} else {
if (LOG_BUF_SIZE(tLogBuff) - end < msgLen) {
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, LOG_BUF_SIZE(tLogBuff) - end);
memcpy(LOG_BUF_BUFFER(tLogBuff), msg + LOG_BUF_SIZE(tLogBuff) - end, msgLen - LOG_BUF_SIZE(tLogBuff) + end);
} else {
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen);
}
}
LOG_BUF_END(tLogBuff) = (LOG_BUF_END(tLogBuff) + msgLen) % LOG_BUF_SIZE(tLogBuff);
}
static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen) {
int32_t start = 0;
int32_t end = 0;
int32_t remainSize = 0;
static int64_t lostLine = 0;
char tmpBuf[40] = {0};
int32_t tmpBufLen = 0;
if (tLogBuff == NULL || tLogBuff->stop) return -1;
......@@ -540,22 +559,24 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen)
remainSize = (start > end) ? (end - start - 1) : (start + LOG_BUF_SIZE(tLogBuff) - end - 1);
if (remainSize <= msgLen) {
if (lostLine > 0) {
sprintf(tmpBuf, "\n...Lost %"PRId64" lines here...\n", lostLine);
tmpBufLen = strlen(tmpBuf);
}
if (remainSize <= msgLen || ((lostLine > 0) && (remainSize <= (msgLen + tmpBufLen)))) {
lostLine++;
asyncLogLostLines++;
pthread_mutex_unlock(&LOG_BUF_MUTEX(tLogBuff));
return -1;
}
if (start > end) {
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen);
} else {
if (LOG_BUF_SIZE(tLogBuff) - end < msgLen) {
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, LOG_BUF_SIZE(tLogBuff) - end);
memcpy(LOG_BUF_BUFFER(tLogBuff), msg + LOG_BUF_SIZE(tLogBuff) - end, msgLen - LOG_BUF_SIZE(tLogBuff) + end);
} else {
memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen);
}
if (lostLine > 0) {
taosCopyLogBuffer(tLogBuff, start, end, tmpBuf, tmpBufLen);
lostLine = 0;
}
LOG_BUF_END(tLogBuff) = (LOG_BUF_END(tLogBuff) + msgLen) % LOG_BUF_SIZE(tLogBuff);
taosCopyLogBuffer(tLogBuff, LOG_BUF_START(tLogBuff), LOG_BUF_END(tLogBuff), msg, msgLen);
// TODO : put string in the buffer
......@@ -603,7 +624,7 @@ static void *taosAsyncOutputLog(void *param) {
// Polling the buffer
while (1) {
log_size = taosPollLogBuffer(tLogBuff, tempBuffer, TSDB_DEFAULT_LOG_BUF_UNIT);
log_size = taosPollLogBuffer(tLogBuff, tempBuffer, sizeof(tempBuffer));
if (log_size) {
taosWrite(tLogBuff->fd, tempBuffer, log_size);
LOG_BUF_START(tLogBuff) = (LOG_BUF_START(tLogBuff) + log_size) % LOG_BUF_SIZE(tLogBuff);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册