------------------------------------------------------------------------- LogFile::preproc_and_try_delete preprocess the given buffer data before write to target file and try to delete it when its reference become zero. -------------------------------------------------------------------------*/
| 424 | and try to delete it when its reference become zero. |
| 425 | -------------------------------------------------------------------------*/ |
| 426 | int |
| 427 | LogFile::preproc_and_try_delete(LogBuffer *lb) |
| 428 | { |
| 429 | int ret = -1; |
| 430 | LogBufferHeader *buffer_header; |
| 431 | |
| 432 | if (lb == nullptr) { |
| 433 | Note("Cannot write LogBuffer to LogFile %s; LogBuffer is NULL", m_name); |
| 434 | return -1; |
| 435 | } |
| 436 | |
| 437 | ink_atomic_increment(&lb->m_references, 1); |
| 438 | |
| 439 | if ((buffer_header = lb->header()) == nullptr) { |
| 440 | Note("Cannot write LogBuffer to LogFile %s; LogBufferHeader is NULL", m_name); |
| 441 | goto done; |
| 442 | } |
| 443 | if (buffer_header->entry_count == 0) { |
| 444 | // no bytes to write |
| 445 | Note("LogBuffer with 0 entries for LogFile %s, nothing to write", m_name); |
| 446 | goto done; |
| 447 | } |
| 448 | |
| 449 | // |
| 450 | // If the start time for this file has yet to be established, then grab |
| 451 | // the low_timestamp from the given LogBuffer. Then, we always set the |
| 452 | // end time to the high_timestamp, so it's always up to date. |
| 453 | // |
| 454 | if (m_log) { |
| 455 | if (!m_log->m_start_time) { |
| 456 | m_log->m_start_time = buffer_header->low_timestamp; |
| 457 | } |
| 458 | m_log->m_end_time = buffer_header->high_timestamp; |
| 459 | } |
| 460 | |
| 461 | if (m_file_format == LOG_FILE_BINARY) { |
| 462 | // |
| 463 | // Ok, now we need to write the binary buffer to the file, and we |
| 464 | // can do so in one swift write. The question is, do we write the |
| 465 | // LogBufferHeader with each buffer or not? The answer is yes. |
| 466 | // Even though we'll be puttint down redundant data (things that |
| 467 | // don't change between buffers), it's not worth trying to separate |
| 468 | // out the buffer-dependent data from the buffer-independent data. |
| 469 | // |
| 470 | LogFlushData *flush_data = new LogFlushData(this, lb); |
| 471 | |
| 472 | Metrics::Counter::increment(log_rsb.num_flush_to_disk, lb->header()->entry_count); |
| 473 | Metrics::Counter::increment(log_rsb.bytes_flush_to_disk, lb->header()->byte_count); |
| 474 | |
| 475 | ink_atomiclist_push(Log::flush_data_list, flush_data); |
| 476 | |
| 477 | Log::flush_notify->signal(); |
| 478 | |
| 479 | // |
| 480 | // LogBuffer will be deleted in flush thread |
| 481 | // |
| 482 | return 0; |
| 483 | } else if (m_file_format == LOG_FILE_ASCII || m_file_format == LOG_FILE_PIPE) { |
no test coverage detected