src/worker.cc
// Write a block to disk.
// Return false if the block is not written.
Write a block to disk.
Return false if the block is not written.
Write a block to disk . Return false if the block is not written .
bool DiskThread::WriteBlockToDisk(int fd, BlockData *block) {
  memset(block_buffer_, 0, block->GetSize());
  struct page_entry pe;
  if (!sat_->GetValid(&pe)) {
    unsigned int *memblock = static_cast<unsigned int *>(block_buffer_);
    block->SetPattern(patternlist_->GetRandomPattern());
    logprintf(11, "Log: Warning, using pattern fill fallback in "
                  "DiskThread::WriteBlockToDisk on disk %s (thread %d).\n",
              device_name_.c_str(), thread_num_);
    for (int i = 0; i < block->GetSize()/wordsize_; i++) {
      memblock[i] = block->GetPattern()->pattern(i);
    }
  } else {
    memcpy(block_buffer_, pe.addr, block->GetSize());
    block->SetPattern(pe.pattern);
    sat_->PutValid(&pe);
  }
  logprintf(12, "Log: Writing %lld sectors starting at %lld on disk %s"
            " (thread %d).\n",
            block->GetSize()/kSectorSize, block->GetAddress(),
            device_name_.c_str(), thread_num_);
  int64 start_time = GetTime();
  if (!AsyncDiskIO(ASYNC_IO_WRITE, fd, block_buffer_, block->GetSize(),
                   block->GetAddress() * kSectorSize, write_timeout_)) {
    return false;
  }
  int64 end_time = GetTime();
  logprintf(12, "Log: Writing time: %lld us (thread %d).\n",
            end_time - start_time, thread_num_);
  if (end_time - start_time > write_threshold_) {
    logprintf(5, "Log: Write took %lld us which is longer than threshold "
                 "%lld us on disk %s (thread %d).\n",
              end_time - start_time, write_threshold_, device_name_.c_str(),
              thread_num_);
  }
  return true;
}
bool DiskThread :: WriteBlockToDisk ( int fd , BlockData * block ) { memset ( block_buffer_ , 0 , block -> GetSize ( ) ) ; struct page_entry pe ; if ( ! sat_ -> GetValid ( & pe ) ) { unsigned int * memblock = static_cast < unsigned int * > ( block_buffer_ ) ; block -> SetPattern ( patternlist_ -> GetRandomPattern ( ) ) ; logprintf ( 11 , " " " \n " , device_name_ . c_str ( ) , thread_num_ ) ; for ( int i = 0 ; i < block -> GetSize ( ) / wordsize_ ; i ++ ) { memblock [ i ] = block -> GetPattern ( ) -> pattern ( i ) ; } } else { memcpy ( block_buffer_ , pe . addr , block -> GetSize ( ) ) ; block -> SetPattern ( pe . pattern ) ; sat_ -> PutValid ( & pe ) ; } logprintf ( 12 , " " " \n " , block -> GetSize ( ) / kSectorSize , block -> GetAddress ( ) , device_name_ . c_str ( ) , thread_num_ ) ; int64 start_time = GetTime ( ) ; if ( ! AsyncDiskIO ( ASYNC_IO_WRITE , fd , block_buffer_ , block -> GetSize ( ) , block -> GetAddress ( ) * kSectorSize , write_timeout_ ) ) { return false ; } int64 end_time = GetTime ( ) ; logprintf ( 12 , " \n " , end_time - start_time , thread_num_ ) ; if ( end_time - start_time > write_threshold_ ) { logprintf ( 5 , " " " \n " , end_time - start_time , write_threshold_ , device_name_ . c_str ( ) , thread_num_ ) ; } return true ; }
Write a block to disk.
Write a block to disk .
// Fill block buffer with a pattern // Even though a valid page could not be obatined, it is not an error // since we can always fill in a pattern directly, albeit slower.