[haiku-commits] r35492 - haiku/trunk/src/add-ons/kernel/file_systems/bfs

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 16 Feb 2010 13:23:44 +0100 (CET)

Author: axeld
Date: 2010-02-16 13:23:43 +0100 (Tue, 16 Feb 2010)
New Revision: 35492
Changeset: http://dev.haiku-os.org/changeset/35492/haiku

Modified:
   haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp
   haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h
Log:
* BPlusTree is now using the TransactionListener mechanism to update its private
  fHeader copy on failure.


Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp       
2010-02-16 11:30:15 UTC (rev 35491)
+++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp       
2010-02-16 12:23:43 UTC (rev 35492)
@@ -198,6 +198,17 @@
        Unset();
 
        InternalSetTo(&transaction, 0LL);
+
+       if (fNode != NULL && !fTree->fInTransaction) {
+               transaction.AddListener(fTree);
+               fTree->fInTransaction = true;
+
+               if (!transaction.GetVolume()->IsInitializing()) {
+                       acquire_vnode(transaction.GetVolume()->FSVolume(),
+                               fTree->fStream->ID());
+               }
+       }
+
        return (bplustree_header*)fNode;
 }
 
@@ -343,7 +354,8 @@
 
 BPlusTree::BPlusTree(Transaction& transaction, Inode* stream, int32 nodeSize)
        :
-       fStream(NULL)
+       fStream(NULL),
+       fInTransaction(false)
 {
        mutex_init(&fIteratorLock, "bfs b+tree iterator");
        SetTo(transaction, stream);
@@ -352,7 +364,8 @@
 
 BPlusTree::BPlusTree(Inode* stream)
        :
-       fStream(NULL)
+       fStream(NULL),
+       fInTransaction(false)
 {
        mutex_init(&fIteratorLock, "bfs b+tree iterator");
        SetTo(stream);
@@ -364,6 +377,7 @@
        fStream(NULL),
        fNodeSize(BPLUSTREE_NODE_SIZE),
        fAllowDuplicates(true),
+       fInTransaction(false),
        fStatus(B_NO_INIT)
 {
        mutex_init(&fIteratorLock, "bfs b+tree iterator");
@@ -559,6 +573,32 @@
 }
 
 
+//     #pragma mark - TransactionListener implementation
+
+
+void
+BPlusTree::TransactionDone(bool success)
+{
+       if (!success) {
+               // update header from disk
+               CachedNode cached(this);
+               const bplustree_header* header = cached.SetToHeader();
+               if (header != NULL)
+                       memcpy(&fHeader, header, sizeof(bplustree_header));
+       }
+}
+
+
+void
+BPlusTree::RemovedFromTransaction()
+{
+       fInTransaction = false;
+
+       if (!fStream->GetVolume()->IsInitializing())
+               put_vnode(fStream->GetVolume()->FSVolume(), fStream->ID());
+}
+
+
 //     #pragma mark -
 
 

Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h 2010-02-16 
11:30:15 UTC (rev 35491)
+++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h 2010-02-16 
12:23:43 UTC (rev 35492)
@@ -196,7 +196,7 @@
 };
 
 
-class BPlusTree {
+class BPlusTree : public TransactionListener {
 public:
                                                                
BPlusTree(Transaction& transaction,
                                                                        Inode* 
stream,
@@ -246,6 +246,10 @@
        static  int32                           TypeCodeToKeyType(type_code 
code);
        static  int32                           ModeToKeyType(mode_t mode);
 
+protected:
+       virtual void                            TransactionDone(bool success);
+       virtual void                            RemovedFromTransaction();
+
 private:
                                                                BPlusTree(const 
BPlusTree& other);
                                                                BPlusTree& 
operator=(const BPlusTree& other);
@@ -296,6 +300,7 @@
                        bplustree_header        fHeader;
                        int32                           fNodeSize;
                        bool                            fAllowDuplicates;
+                       bool                            fInTransaction;
                        status_t                        fStatus;
                        mutex                           fIteratorLock;
                        SinglyLinkedList<TreeIterator> fIterators;


Other related posts:

  • » [haiku-commits] r35492 - haiku/trunk/src/add-ons/kernel/file_systems/bfs - axeld