home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / stratus / 99 < prev    next >
Encoding:
Internet Message Format  |  1993-01-12  |  13.0 KB

  1. Path: sparky!uunet!noc.near.net!transfer.stratus.com!transfer.stratus.com!usenet
  2. From: dan@az.stratus.com (Dan Danz)
  3. Newsgroups: comp.sys.stratus
  4. Subject: Re: loss of end-of-file mark problem (LONG)
  5. Followup-To: comp.sys.stratus
  6. Date: 12 Jan 1993 21:06:27 GMT
  7. Organization: Stratus Computer Inc, Marlboro MA
  8. Lines: 260
  9. Distribution: world
  10. Message-ID: <1ivbsjINN2f2@transfer.stratus.com>
  11. References: <1993Jan7.131833.15374@porthos.cc.bellcore.com>
  12. NNTP-Posting-Host: bittersprings.az.stratus.com
  13. Keywords: TPF end_of_file runout cache salvage recreate_index verify_end_of_file LPF ESD
  14.  
  15. [dante writes]
  16. > In the event of a VOS crash, I have heard that it is possible that VOS
  17. > can lose a files's end of file mark, thereby corrupting the file and
  18. > losing access to the file on reboot. The solution to the problem is to 
  19. > Transaction Protect(TP) the file. I was wondering if anyone has heard
  20. > of the problem and if so, then to discuss the problem and its possible 
  21. > solutions.
  22.  
  23. Before we can understand potential solutions (and there are more than
  24. one), we need to understand all the players, such as Disk Cache, Disk
  25. Salvage, the end of file pointer, etc.
  26.  
  27. DISK CACHE
  28.  
  29. VOS maintains a disk cache in main memory in which it holds recently
  30. accessed blocks of disk.  When programs (including portions of the
  31. operating system) request access to disk data, the cache manager first
  32. attempts to locate the data in the disk cache.  If the data can be
  33. found there, the resultant access time can be several orders of
  34. magnitude faster than if the disk itself has to be accessed.  When the
  35. data in the cache is changed, VOS rewrites the changed blocks back to
  36. disk at its convenience and according to an algorithm that includes
  37. measures to avoid needless writes to disk when the block is constantly
  38. changing.  Note that blocks belonging to directories and
  39. sub-directories of the file system also participate in the caching
  40. scheme.
  41.      
  42. In the event of a system interruption (which can occur, for example,
  43. because of such diverse things as extended power failures,
  44. software-detected inconsistencies in system behavior, or an operator
  45. inadvertently pressing the power switch), some in-memory disk blocks
  46. might not be flushed to disk.  Frequently, it happens that new data
  47. blocks for a file are written to disk but the directory information
  48. for the file has not yet been updated at the time of an interruption.
  49.      
  50. Note that if the system is stopped using the shutdown command, then
  51. the disk cache is flushed to disk before the system is truly stopped,
  52. and the integrity of the file system is not impacted.  Note also that
  53. the integrity of files protected by the VOS Transaction Protection
  54. Facility (TPF) will not be affected by system interruptions.
  55.           
  56. DISK SALVAGE
  57.  
  58. When the system is restarted following such an interruption, the
  59. "salvage_disk" command is automatically executed for each disk volume
  60. that is mounted.  The salvage_disk operation is a time-consuming, disk
  61. intensive, operation that must complete prior to allowing any new
  62. operations on the files.
  63.  
  64. One of the tasks of the salvager is to detect and repair directory
  65. information about files.  It is capable of detecting when, for
  66. example, new data blocks have been allocated to a file and written to
  67. the disk but are not reflected in the count of the number of blocks in
  68. the directory entry for the file.
  69.      
  70. END OF FILE POINTER
  71.  
  72. The salvager, however, does not attempt to verify another directory
  73. item: last_record_number.  This field is used differently by the
  74. various file types, but is colloquially referred to as the "end of
  75. file pointer".  It indicates to the file system where to begin when
  76. writing new records and beyond which the application programs should
  77. not be allowed to read data.  This value is typically updated only at
  78. the time the file is closed or runout.  In the interim, the
  79. information is kept only in VOS memory.
  80.      
  81. Data can be lost when the value of this field does not reflect the
  82. true end of file.  Consider the following example.
  83.      
  84. 1.  An application program opens a file for sequential output (or
  85.     update or append) operations.
  86.      
  87. 2.  It writes 200 records to the file, that occupy 1.5 blocks of disk
  88.     space.
  89.      
  90. 3.  The file is closed (or s$control RUNOUT_OPCODE is used to flush
  91.     blocks of data and the directory entries to disk).  The value of
  92.     the last_record_number field at this point is that associated with
  93.     a point in the file in the middle of the second block immediately
  94.     beyond the 200th record.
  95.      
  96. 4.  The file is re-opened for update or append operations and 300 more
  97.     records are written to the file.  Two new blocks are allocated to
  98.     the file to hold the records.
  99.      
  100. 5.  A system interruption occurs.  The salvager is likely to report
  101.     that the number of blocks (2) in the directory entry for the file
  102.     is wrong and change it to the correct value (4).  However, the
  103.     last_record_number field retains the same value as in step #3 above
  104.     (someplace in the middle of the second block).
  105.      
  106. 6.  The following scenarios are typical of what happens next:
  107.      
  108.         a.)  An application program that sequentially reads the file
  109.              receives e$end_of_file when attempting to access any
  110.              record beyond the 200th.  The dump_file command, however,
  111.              displays all the blocks of the file, and records 201
  112.              through (say) 465 can be seen.  The first part of the
  113.              next record 466 can be seen at the end of the last block.
  114.              In some rare cases, the last block holding data will be
  115.              followed by one or more blocks containing only bytes of
  116.              FFx (this occurs when the block has been allocated but
  117.              never written).
  118.                
  119.         b.)  An application program that attempts to write new records
  120.              to the file overwrites records beginning at record 201.
  121.  
  122.         c.)  An application program that accesses the file using keyed
  123.              reads via an index receives the error code
  124.              e$invalid_record_number when it attempts to access
  125.              records beyond the 200th, or the record returned is one
  126.              of the records written by (b.) above.
  127.  
  128. Posts (by Tom Moser, Dan Swartzendruber, Walt Mankowski) have offered
  129. some possible solutions, and I'd like to put the total set in
  130. perspective.
  131.  
  132. EMERGENCY SHUTDOWN
  133.  
  134. VOS Release 11.1 includes a feature called Emergency Shutdown (ESD);
  135. if the operating system is about to experience a system interruption
  136. because of software detected conditions, it first tries to invoke ESD,
  137. which attempts a sequence of events similar to an actual shutdown;
  138. that is, it tries to complete all outstanding I/O, including writing
  139. out the file partition bit maps on all disks, and updating the labels
  140. on all mounted disks. The reboot process does not need to salvage any
  141. disks that were shut down in this orderly fashion, thus eliminating
  142. the time it would normally take to salvage them.  It also ensures that
  143. the the end-of-file pointer information is recorded properly in the
  144. directory entry.
  145.  
  146. ESD takes a conservative approach, however; before flushing any of the
  147. disk cache, it validates the integrity of the software and hardware
  148. that will be used.  (It doesn't want to flush the cache if the reason
  149. for the crash is that the disk cache control structures have been
  150. corrupted, for example.)
  151.  
  152. ESD is not (and cannot be) invoked for extended power failures,
  153. emergency power-off, the failure of a simplexed component, or in the
  154. rare case of failure of both partners of a duplexed component.
  155.  
  156. RUNOUT
  157.  
  158. The application program(s) writing the file can ensure that all the
  159. blocks of the file, it's indexes, and the directory entry have been
  160. written to disk by calling s$control with the RUNOUT_OPCODE.  This
  161. feature is available in all releases of VOS and can been done by any
  162. process having write access to the file, which suggests a user-written
  163. daemon could periodically flush some critical files, perhaps based on
  164. activity and/or time between flushes.  This technique narrows the
  165. window in which the problem can occur, but does not close it entirely.
  166.  
  167. VERIFY_END_OF_FILE 
  168.  
  169. A tool called verify_end_of_file was developed to detect (and correct)
  170. many cases of incorrect end-of-file pointers and has been shipped to
  171. all sites since VOS release 6.3.  Until recently, it was an
  172. undocumented tool and was shipped in the >system>maint_library.
  173. Beginning in release 11.6, verify_end_of_file is in
  174. >system>command_library and has been documented in Stratus manuals.
  175.  
  176. The tool starts at the last recorded end-of-file position
  177. and attempts to read records beyond this point.  If it's successful,
  178. it is capable of updating the directory information.  For it to be
  179. totally successful, all data blocks in the disk cache must have been
  180. written to disk, however; if not, the tool attempts to recover as many
  181. whole records as it is able to read.
  182.  
  183. In addition, if the end-of-file pointer needs to be adjusted and the
  184. file has indexes, it's probable that the index contents and the data
  185. are not consistent, so any indexes on the file must be recreated.
  186.  
  187. RECREATE_INDEX
  188.  
  189. For embedded indexes (where the file contains all the information used
  190. in the index keys), a recreate_index tool has been provided (also
  191. since VOS release 6.3).  It automates the manual steps of
  192. display_file_status (to get the index parameters), delete_index, and
  193. create_index that are required to rebuild an index.
  194.  
  195. VOS had a limitation of only allowing one index to be created at a
  196. time; this restriction was removed in VOS release 10.3, and
  197. recreate_index was rewritten to spawn multiple processes, greatly
  198. shortening the time required to rebuild multiple indexes on large
  199. files.
  200.  
  201. Starting with VOS release 11.6, recreate_index becomes a fully-
  202. documented user command in >system>command_library.
  203.  
  204. LOG PROTECTED FILES (LPF)
  205.  
  206. A future release of VOS (probably release 12) will contain a feature
  207. called Log Protected Files.  Here's a preview of this feature.
  208.  
  209. A log protected file is conceptually an intermediate step between
  210. ordinary VOS files and transaction protected files.  It guarantees
  211. data consistency after a system interruption, but does not permit an
  212. application to combine multiple operations into a single transaction.
  213. Instead, each s$subroutine call is treated as a separate, atomic
  214. transaction.
  215.  
  216. The protection provided to log protected files is automatic; existing
  217. applications can be changed to use log protection without
  218. redevelopment or internal changes by using a new command to enable the
  219. log protected attribute for the appropriate files.  Such files are
  220. then called log protected files.
  221.  
  222. Each s$subroutine call that modifies a log protected file makes sure
  223. that all the resulting changes are written to a special log file
  224. before any of the changes are written to the actual file.  This
  225. includes changes to file indices and control information such as
  226. end-of-file pointers.  When VOS recovers from a system interruption,
  227. the logged modifications that are not marked as completed are
  228. re-applied to the appropriate files before the file system salvage and
  229. recovery operations are performed.
  230.  
  231. Log protection does not guarantee that all changes up to the very last
  232. s$subroutine call will be present after a system interruption, but it
  233. does guarantee that all changes up to and including some relatively
  234. recent s$subroutine call will be present, and that no modifications
  235. made after that call will be present.  "Relatively recent" means that
  236. the time will vary dynamically depending upon the setting of the
  237. existing module tuning parameter "modified grace time".  This
  238. parameter may range from 1 second to 1 hour, but is typically on the
  239. order of 1 to 4 minutes.  If desired, the application can cause
  240. changes to be logged immediately by using the runout s$control
  241. operation.
  242.  
  243.  
  244. TRANSACTION PROTECTION (TP)
  245.  
  246. Transaction Protection remains the ultimate in file integrity
  247. protection, especially when the application requires atomic operations
  248. on data that resides in multiple records and/or files.  TP-protected
  249. files are not exposed to any of the dangers discussed above; however,
  250. the TP solution is the most expensive of all in terms of resource use
  251. and it requires active application program participation in the process.  
  252.  
  253.  
  254. SUMMARY
  255.  
  256. System failures, whatever the cause (hardware, software,
  257. environmental, operator error) can damage open output files.  However,
  258. there are various levels of protection and correction, depending on
  259. the release of the operating system and the nature of the application.
  260.  
  261. Stratus Systems Engineers (there's at least one assigned to most
  262. sites) can work with you to design your application, explain the
  263. tradeoffs involved, and help ensure that the integrity of your files
  264. is adequately protected.
  265.  
  266. If you have a specific question about any of the tools or techniques
  267. involved, I urge you to contact your Customer Assistance Center.
  268.  
  269. --
  270. L. W. "Dan" Danz     (WA5SKM)     VOS Mail:  Dan_Danz@vos.stratus.com
  271. Sr Consulting Software SE         NeXT Mail: dan@az.stratus.com
  272. Customer Assistance Center        Voice Mail/Pager: (602) 852-3107
  273. Telecommunications Division       Customer Service: (800) 828-8513
  274. Stratus Computer, Inc. 4455 E. Camelback #115-A, Phoenix AZ 85018
  275.