home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / doc / db-recovery.txt < prev    next >
Text File  |  2010-03-31  |  4KB  |  127 lines

  1. # 2009-11-5
  2. # Notes on recoverying corrupted Berkeley DB files in PVFS
  3. ====================================================================
  4.  
  5. The pvfs2-server daemon uses Berkeley DB as the mechanism for storing file
  6. system metadata.  There are 5 database files in total that can be found in
  7. the following locations in the storage space:
  8.  
  9. ./storage_attributes.db
  10. ./50a6d673/collection_attributes.db
  11. ./50a6d673/dataspace_attributes.db
  12. ./50a6d673/keyval.db
  13. ./collections.db
  14.  
  15. The dataspace_attributes.db and keyval.db are most frequently used by
  16. the file system.  If one of these database files is corrupted for some
  17. reason, then it may prevent the file system from operating correctly.
  18.  
  19. One common technique for repairing a Berkeley DB database is to dump its
  20. contents using db_dump (possibly found in the db4-utils package) and then
  21. reload it into a new .db file with db_load.  However, both the keyval.db and
  22. dataspace_attributes.db use a custom function for sorting entries in order
  23. to improve PVFS performance.  db_load must therefore be modified to use the
  24. correct key order.
  25.  
  26. Here are the steps needed to build a db_load utility that will work on the
  27. keyval.db or dataspace_attributes.db file:
  28.  
  29. - download the source code for Berkeley DB
  30. - edit db_load/db_load.c
  31. - find the section marked by #if 0 that indicates where to insert
  32.   application specific btree comparison or hash functions
  33. - insert the code listed at the end of this file (NOTE: there is different
  34.   code depending on which .db file you are trying to recover)
  35. - build Berkeley DB
  36. - rename db_load binary to db_load_pvfs_keyval to avoid confusion
  37.  
  38. For keyval.db:
  39. ====================================================================
  40. #include <stdint.h>
  41.  
  42. typedef uint64_t PVFS_handle;
  43. typedef PVFS_handle                TROVE_handle;
  44.  
  45. #define PVFS_NAME_MAX            256
  46. #define DBPF_MAX_KEY_LENGTH PVFS_NAME_MAX
  47.  
  48. struct dbpf_keyval_db_entry
  49. {
  50.     TROVE_handle handle;
  51.     char key[DBPF_MAX_KEY_LENGTH];
  52. };
  53.  
  54. #define DBPF_KEYVAL_DB_ENTRY_TOTAL_SIZE(_size) \
  55.     (sizeof(TROVE_handle) + _size)
  56.  
  57. #define DBPF_KEYVAL_DB_ENTRY_KEY_SIZE(_size) \
  58.     (_size - sizeof(TROVE_handle))
  59.  
  60. int PINT_trove_dbpf_keyval_compare(
  61.     DB * dbp, const DBT * a, const DBT * b)
  62. {
  63.     const struct dbpf_keyval_db_entry * db_entry_a;
  64.     const struct dbpf_keyval_db_entry * db_entry_b;
  65.  
  66.     db_entry_a = (const struct dbpf_keyval_db_entry *) a->data;
  67.     db_entry_b = (const struct dbpf_keyval_db_entry *) b->data;
  68.  
  69.     if(db_entry_a->handle != db_entry_b->handle)
  70.     {
  71.         return (db_entry_a->handle < db_entry_b->handle) ? -1 : 1;
  72.     }
  73.  
  74.     if(a->size > b->size)
  75.     {
  76.         return 1;
  77.     }
  78.  
  79.     if(a->size < b->size)
  80.     {
  81.         return -1;
  82.     }
  83.  
  84.     /* must be equal */
  85.     return (memcmp(db_entry_a->key, db_entry_b->key,
  86.                     DBPF_KEYVAL_DB_ENTRY_KEY_SIZE(a->size)));
  87. }
  88.  
  89. if ((ret = dbp->set_bt_compare(dbp, PINT_trove_dbpf_keyval_compare)) != 0)
  90.  
  91.         dbp->err(dbp, ret, "DB->set_bt_compare");
  92.         goto err;
  93. }
  94.  
  95. ====================================================================
  96.  
  97. For dataspace_attributes.db:
  98. ====================================================================
  99.  
  100. #include <stdint.h>
  101.  
  102. typedef uint64_t PVFS_handle;
  103. typedef PVFS_handle                TROVE_handle;
  104.  
  105. int PINT_trove_dbpf_ds_attr_compare(DB * dbp, const DBT * a, const DBT * b)
  106. {
  107.     const TROVE_handle * handle_a;
  108.     const TROVE_handle * handle_b;
  109.  
  110.     handle_a = (const TROVE_handle *) a->data;
  111.     handle_b = (const TROVE_handle *) b->data;
  112.  
  113.     if(*handle_a == *handle_b)
  114.     {
  115.         return 0;
  116.     }
  117.  
  118.     return (*handle_a > *handle_b) ? -1 : 1;
  119. }
  120.  
  121. if ((ret = dbp->set_bt_compare(dbp, PINT_trove_dbpf_ds_attr_compare)) != 0) {
  122.         dbp->err(dbp, ret, "DB->set_bt_compare");
  123.         goto err;
  124. }
  125.  
  126. ====================================================================
  127.