HAMMER VFS - Implement REDO recovery code
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 26 Mar 2010 05:42:47 +0000 (22:42 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 26 Mar 2010 05:42:47 +0000 (22:42 -0700)
commitc58123da115775ad9efb096a539933097879d078
treeefd801488b985755175b95bf0f4d3741c12b226a
parent8ac50aa3da37c67bd7f34312e01d303b793d9ec9
HAMMER VFS - Implement REDO recovery code

* Implement the primary REDO recovery mechanics and document the whole mess.
  REDO recovery essentially works using an expanded UNDO/REDO FIFO range.

  The nominal UNDO range, required for running UNDOs, is calculated first.
  If a REDO_SYNC record is found within this range the record specifies
  the expanded FIFO start offset required to run REDOs.  This is necessary
  because the inodes related to REDOs layed down in the FIFO are not
  necessarily flush in the next flush sequence, so the recovery code may
  have to scan the UNDO/REDO FIFO backwards considerably beyond the nominal
  recovery ranged required to run UNDOs in order to find active REDOs.

  When a REDO_SYNC record is found the recovery code expands the range
  by scanning backwards and validating the UNDO/REDO FIFO as it goes.
  It must make sure that the sequence space remains contiguous all the
  back to the REDO_SYNC point.

  While doing the reverse scan the recovery code collects REDO_TERM_*
  records which are used to mask earlier REDO_* records once their
  meta-data has been flushed.  Only TERM records in the expanded range
  that are outside the nominal UNDO range matter.  Any TERM records in
  the nominal UNDO range refer to meta-data which was undone by the
  stage1 UNDO recovery and so must be ignored (we want to run the
  related REDOs).

  The recovery code then does a forward scan through the entire expanded
  range of the UNDO/REDO FIFO executing any REDO_* records it finds
  which have not been masked by later REDO_TERM_* records.  It executes
  the REDOs using the live filesystem.

* Expand the REDO FIFO structure, I had forgotten to add a localization
  field, otherwise HAMMER doesn't know which PFS the REDO is refering to.

* Umount was improperly flushing the FIFO to the disk for read-only mounts.
  Fix it.

* The recovery code now detects whether any REDOs are present by the
  observation of a REDO_SYNC record in the nominal UNDO recovery range.
  It will not run stage2 (the REDO pass) if it does not see this record.

* Properly generate a REDO_SYNC record in the UNDO space when generating
  only REDOs, as well as UNDOs.  HAMMER was previously only generating
  the REDO_SYNC record when generating UNDOs.

* Generate a REDO_TRUNC record during a file flush if any records were
  previously queued with REDO, even if those records no longer exist
  (e.g. due to a truncation) and even if REDO is now turned off due to
  redo heuristic limits being exceeded.

  This is necessary in order for the recovery code to properly sequence
  REDOs and TRUNCations during recovery.

* For now be very verbose during redo recovery.

* Make sure that mount -o ro and mount -u -o rw work properly.  The
  stage2 REDO cannot be run on a read-only mount because it requires a
  live filesystem.  The operations are defered until the mount is
  upgraded to rw.
sys/vfs/hammer/hammer.h
sys/vfs/hammer/hammer_disk.h
sys/vfs/hammer/hammer_flusher.c
sys/vfs/hammer/hammer_mount.h
sys/vfs/hammer/hammer_recover.c
sys/vfs/hammer/hammer_redo.c
sys/vfs/hammer/hammer_vnops.c