src/backend/logging/loggers/wal_frontend_logger.cpp
/**
 * @brief flush all the log records to the file
 */
@brief flush all the log records to the file
@brief flush all the log records to the file
void WriteAheadFrontendLogger::FlushLogRecords(void) {
  if (global_queue.size() != 0 && this->log_file_fd == -1) {
    this->CreateNewLogFile(false);
  }
  size_t global_queue_size = global_queue.size();
  for (oid_t global_queue_itr = 0; global_queue_itr < global_queue_size;
       global_queue_itr++) {
    if (this->FileSwitchCondIsTrue()) {
      fflush_and_sync(log_file, log_file_fd, fsync_count);
      this->CreateNewLogFile(true);
    }
    auto &record = global_queue[global_queue_itr];
    fwrite(record->GetMessage(), sizeof(char), record->GetMessageLength(),
           log_file);
    LOG_INFO("TransactionID of this Log is %d",
             (int)record->GetTransactionId());
    if (record->GetTransactionId() > this->max_commit_id) {
      LOG_INFO("MaxSoFar is %d", (int)this->max_commit_id);
      this->max_commit_id = record->GetTransactionId();
    }
  }
  fflush_and_sync(log_file, log_file_fd, fsync_count);
  global_queue.clear();
  {
    for (auto backend_logger : backend_loggers) {
      backend_logger->FinishedFlushing();
    }
  }
}
void WriteAheadFrontendLogger :: FlushLogRecords ( void ) { if ( global_queue . size ( ) != 0 && this -> log_file_fd == -1 ) { this -> CreateNewLogFile ( false ) ; } size_t global_queue_size = global_queue . size ( ) ; for ( oid_t global_queue_itr = 0 ; global_queue_itr < global_queue_size ; global_queue_itr ++ ) { if ( this -> FileSwitchCondIsTrue ( ) ) { fflush_and_sync ( log_file , log_file_fd , fsync_count ) ; this -> CreateNewLogFile ( true ) ; } auto & record = global_queue [ global_queue_itr ] ; fwrite ( record -> GetMessage ( ) , sizeof ( char ) , record -> GetMessageLength ( ) , log_file ) ; LOG_INFO ( " " , ( int ) record -> GetTransactionId ( ) ) ; if ( record -> GetTransactionId ( ) > this -> max_commit_id ) { LOG_INFO ( " " , ( int ) this -> max_commit_id ) ; this -> max_commit_id = record -> GetTransactionId ( ) ; } } fflush_and_sync ( log_file , log_file_fd , fsync_count ) ; global_queue . clear ( ) ; { for ( auto backend_logger : backend_loggers ) { backend_logger -> FinishedFlushing ( ) ; } } }
@brief flush all the log records to the file
@brief flush all the log records to the file
// First, write all the record in the queue // Clean up the frontend logger's queue // Commit each backend logger