src/worker.cc
// Verify a block on disk.
// Return true if the block was read, also increment errorcount
// if the block had data errors or performance problems.
Verify a block on disk.
Return true if the block was read, also increment errorcount
if the block had data errors or performance problems.
Verify a block on disk . Return true if the block was read also increment errorcount if the block had data errors or performance problems .
bool DiskThread::ValidateBlockOnDisk(int fd, BlockData *block) {
  int64 blocks = block->GetSize() / read_block_size_;
  int64 bytes_read = 0;
  int64 current_blocks;
  int64 current_bytes;
  uint64 address = block->GetAddress();
  logprintf(20, "Log: Reading sectors starting at %lld on disk %s "
            "(thread %d).\n",
            address, device_name_.c_str(), thread_num_);
  if (lseek64(fd, address * kSectorSize, SEEK_SET) == -1) {
    logprintf(0, "Process Error: Unable to seek to sector %lld in "
              "DiskThread::ValidateSectorsOnDisk on disk %s "
              "(thread %d).\n", address, device_name_.c_str(), thread_num_);
    return false;
  }
  int64 start_time = GetTime();
  while (blocks != 0) {
    current_blocks = (random() % blocks) + 1;
    current_bytes = current_blocks * read_block_size_;
    memset(block_buffer_, 0, current_bytes);
    logprintf(20, "Log: Reading %lld sectors starting at sector %lld on "
              "disk %s (thread %d)\n",
              current_bytes / kSectorSize,
              (address * kSectorSize + bytes_read) / kSectorSize,
              device_name_.c_str(), thread_num_);
    if (!AsyncDiskIO(ASYNC_IO_READ, fd, block_buffer_, current_bytes,
                     address * kSectorSize + bytes_read,
                     write_timeout_)) {
      return false;
    }
    int64 end_time = GetTime();
    logprintf(20, "Log: Reading time: %lld us (thread %d).\n",
              end_time - start_time, thread_num_);
    if (end_time - start_time > read_threshold_) {
      logprintf(5, "Log: Read took %lld us which is longer than threshold "
                "%lld us on disk %s (thread %d).\n",
                end_time - start_time, read_threshold_,
                device_name_.c_str(), thread_num_);
    }
    if (!non_destructive_) {
      if (CheckRegion(block_buffer_, block->GetPattern(), current_bytes,
                      0, bytes_read)) {
        os_->ErrorReport(device_name_.c_str(), "disk-pattern-error", 1);
        errorcount_ += 1;
        logprintf(0, "Hardware Error: Pattern mismatch in block starting at "
                  "sector %lld in DiskThread::ValidateSectorsOnDisk on "
                  "disk %s (thread %d).\n",
                  address, device_name_.c_str(), thread_num_);
      }
    }
    bytes_read += current_blocks * read_block_size_;
    blocks -= current_blocks;
  }
  return true;
}
bool DiskThread :: ValidateBlockOnDisk ( int fd , BlockData * block ) { int64 blocks = block -> GetSize ( ) / read_block_size_ ; int64 bytes_read = 0 ; int64 current_blocks ; int64 current_bytes ; uint64 address = block -> GetAddress ( ) ; logprintf ( 20 , " " " \n " , address , device_name_ . c_str ( ) , thread_num_ ) ; if ( lseek64 ( fd , address * kSectorSize , SEEK_SET ) == -1 ) { logprintf ( 0 , " " " " " \n " , address , device_name_ . c_str ( ) , thread_num_ ) ; return false ; } int64 start_time = GetTime ( ) ; while ( blocks != 0 ) { current_blocks = ( random ( ) % blocks ) + 1 ; current_bytes = current_blocks * read_block_size_ ; memset ( block_buffer_ , 0 , current_bytes ) ; logprintf ( 20 , " " " \n " , current_bytes / kSectorSize , ( address * kSectorSize + bytes_read ) / kSectorSize , device_name_ . c_str ( ) , thread_num_ ) ; if ( ! AsyncDiskIO ( ASYNC_IO_READ , fd , block_buffer_ , current_bytes , address * kSectorSize + bytes_read , write_timeout_ ) ) { return false ; } int64 end_time = GetTime ( ) ; logprintf ( 20 , " \n " , end_time - start_time , thread_num_ ) ; if ( end_time - start_time > read_threshold_ ) { logprintf ( 5 , " " " \n " , end_time - start_time , read_threshold_ , device_name_ . c_str ( ) , thread_num_ ) ; } if ( ! non_destructive_ ) { if ( CheckRegion ( block_buffer_ , block -> GetPattern ( ) , current_bytes , 0 , bytes_read ) ) { os_ -> ErrorReport ( device_name_ . c_str ( ) , " " , 1 ) ; errorcount_ += 1 ; logprintf ( 0 , " " " " " \n " , address , device_name_ . c_str ( ) , thread_num_ ) ; } } bytes_read += current_blocks * read_block_size_ ; blocks -= current_blocks ; } return true ; }
Verify a block on disk.
Verify a block on disk .
// Read block from disk and time the read.  If it takes longer than the // threshold, complain. // Split a large write-sized block into small read-sized blocks and // read them in groups of randomly-sized multiples of read block size. // This assures all data written on disk by this particular block // will be tested using a random reading pattern. // Test all read blocks in a written block. // In non-destructive mode, don't compare the block to the pattern since // the block was never written to disk in the first place.