*** empty log message ***
authornavid <navid>
Tue, 10 Feb 2009 05:29:03 +0000 (05:29 +0000)
committernavid <navid>
Tue, 10 Feb 2009 05:29:03 +0000 (05:29 +0000)
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/BlockDataStructure.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/ExtendedTransaction.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYReadWriteWLock.java [deleted file]
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java

index 8370c091b407bec77c3bb16f479210ad5d85c7c5..c23db7646fe94de4c1f29dcf7b31aa527edce033 100644 (file)
@@ -15,7 +15,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
  * @author navid
  */
 public class BlockDataStructure {
-    private ReentrantReadWriteLock lock;
+    //private ReentrantReadWriteLock lock;
+    private MYReadWriteLock lock;
     private ExtendedTransaction owner;
     private INode inode;
     private int blocknumber;
@@ -31,7 +32,8 @@ public class BlockDataStructure {
         version = new AtomicInteger(0);
         //lock = new ReentrantReadWriteLock();
         blockreaders = new Vector();
-        lock = new ReentrantReadWriteLock();
+        //lock = new ReentrantReadWriteLock();
+        lock = new MYReadWriteLock();
         this.inode = inode;
         this.blocknumber = blocknumber;
         referncount = 0;
@@ -46,11 +48,11 @@ public class BlockDataStructure {
         this.blockreaders = readers;
     }
     
-    public ReentrantReadWriteLock getLock() {
+    public MYReadWriteLock getLock() {
         return lock;
     }
 
-    public void setLock(ReentrantReadWriteLock lock) {
+    public void setLock(MYReadWriteLock lock) {
         this.lock = lock;
     }
 
index 2afcfa56e2118114036a775ccef92fff9aaf426b..e804d736288d587a319aec935b035511b59080e9 100644 (file)
@@ -40,7 +40,6 @@ public class ExtendedTransaction implements TransactionStatu {
     public TransactionStatu memorystate;
     public int starttime;
     public int endtime;
-    public TreeMap msg = new TreeMap();
     public int numberofwrites;
     public int numberofreads;
     private TreeMap sortedAccesedFiles;
@@ -50,7 +49,7 @@ public class ExtendedTransaction implements TransactionStatu {
         ABORTED, ACTIVE, COMMITTED
     };
     private boolean writesmerged = true;
-    private Vector heldlengthlocks;
+    //private Vector heldlengthlocks;
     //private Vector<ReentrantLock> heldoffsetlocks;    
     // private Vector heldoffsetlocks;
     //private Vector<ReentrantLock> heldblocklocks;    
@@ -67,7 +66,8 @@ public class ExtendedTransaction implements TransactionStatu {
     //public ReentrantReadWriteLock[] toholoffsetlocks;
     public MYLock[] toholoffsetlocks;
     public int offsetcount = 0;
-    public Lock[] toholdblocklocks;
+    //public Lock[] toholdblocklocks;
+    public MYReadWriteLock[] toholdblocklocks;
     public int blockcount = 0;
 
     public ExtendedTransaction() {
@@ -75,10 +75,10 @@ public class ExtendedTransaction implements TransactionStatu {
         // id = Integer.valueOf(Thread.currentThread().getName().substring(7));
         //toholoffsetlocks = new ReentrantReadWriteLock[20];
         toholoffsetlocks = new MYLock[20];
-        toholdblocklocks = new Lock[20];
+        toholdblocklocks = new MYReadWriteLock[20];
         //  for (int i=0; i<20; i++)
         //      toholoffsetlocks[i] = new ReentrantLock();
-        heldlengthlocks = new Vector();
+//        heldlengthlocks = new Vector();
 //        heldblocklocks = new Vector();
         //  heldoffsetlocks = new Vector();
         AccessedFiles = new HashMap();
@@ -193,15 +193,20 @@ public class ExtendedTransaction implements TransactionStatu {
 
 
 
-        TreeMap hm = getSortedFileAccessMap(AccessedFiles);
+        TreeMap<INode, Vector<TransactionalFile>> hm = getSortedFileAccessMap(AccessedFiles);
+        //for (Map.Entry<INode>Vector<TransactionalFile>> entry : hm.entrySet())  {
+            
+        //}
+    //    entry.getKey().someMethod(entry.getValue());  
         Iterator iter = hm.keySet().iterator();
         offsetcount = 0;
-
+        for (Map.Entry<INode,Vector<TransactionalFile>> entry : hm.entrySet())  {
         // for (int j=0; j< hm.size(); j++){
-        while (iter.hasNext()/* && (this.getStatus() == Status.ACTIVE)*/) {
-            INode key = (INode) iter.next();
-            Vector vec = (Vector) AccessedFiles.get(key);
-
+        //while (iter.hasNext()/* && (this.getStatus() == Status.ACTIVE)*/) {
+          //  INode key = (INode) iter.next();
+            //Vector vec = (Vector) AccessedFiles.get(key);
+            INode key = entry.getKey();
+            Vector vec = entry.getValue();
             Collections.sort(vec);
             for (int i = 0; i < vec.size(); i++) {
                 //Iterator it = vec.iterator();
@@ -244,23 +249,31 @@ public class ExtendedTransaction implements TransactionStatu {
 
     public boolean lockBlock(BlockDataStructure block, BlockAccessModesEnum mode/*, GlobalINodeState adapter, BlockAccessModesEnum mode, int expvalue, INode inode, TransactionLocalFileAttributes tf*/) {
 
-        Lock lock;
+        //Lock lock;
         if (mode == BlockAccessModesEnum.READ) {
-            lock = block.getLock().readLock();
+          
+                //lock =block.getLock().readLock();
+                block.getLock().readLock();
+          
         } else {
-            lock = block.getLock().writeLock();
+         
+                //lock = block.getLock().writeLock();
+                block.getLock().writeLock();
+            
         }
 
-        lock.lock();
+        //lock.lock();
 
         if (toholdblocklocks[blockcount] == null) {
             //if (mode == BlockAccessModesEnum.READ) {
             //    toholdblocklocks[blockcount] = new ReentrantReadWriteLock().readLock();
             //}
             // else 
-            toholdblocklocks[blockcount] = new ReentrantReadWriteLock().writeLock();
+            //toholdblocklocks[blockcount] = new ReentrantReadWriteLock().writeLock();
+            toholdblocklocks[blockcount] = new MYReadWriteLock();
         }
-        toholdblocklocks[blockcount] = lock;
+        //toholdblocklocks[blockcount] = lock;
+        toholdblocklocks[blockcount] = block.getLock();
         blockcount++;
         //heldblocklocks.add(lock);
         return true;
@@ -292,7 +305,8 @@ public class ExtendedTransaction implements TransactionStatu {
         while (iter.hasNext() && (this.getStatus() == Status.ACTIVE)) {
             INode key = (INode) iter.next();
             vec = (Vector) hm.get(key);
-            Collections.sort(vec);
+            //if (!(isWritesmerged()))
+                Collections.sort(vec);
             //Iterator it = vec.iterator();
             for (int j = 0; j < vec.size(); j++) {
                 //while (it.hasNext()) {
@@ -516,6 +530,7 @@ public class ExtendedTransaction implements TransactionStatu {
         //          lock.unlock();
         //     }
         // heldblocklocks.clear();
+        
         for (int i = 0; i < blockcount; i++) {
             toholdblocklocks[i].unlock();
         }
@@ -635,9 +650,9 @@ public class ExtendedTransaction implements TransactionStatu {
 //    public Vector getHeldoffsetlocks() {
     //       return heldoffsetlocks;
     //   }
-    public Vector getHeldlengthlocks() {
-        return heldlengthlocks;
-    }
+  //  public Vector getHeldlengthlocks() {
+   //     return heldlengthlocks;
+   // }
 
     //   public void setHeldoffsetlocks(Vector heldoffsetlocks) {
     //       this.heldoffsetlocks = heldoffsetlocks;
diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYReadWriteWLock.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYReadWriteWLock.java
deleted file mode 100644 (file)
index 7283a69..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package TransactionalIO.core;
-
-public class MYReadWriteWLock
-{
-       private int givenLocks;
-       private int waitingWriters;
-       private int waitingReaders;
-       private Object mutex;
-       
-       
-       public void getReadLock()
-       {
-               synchronized(mutex)
-               {
-                       while((givenLocks == -1) || 
-                                  (waitingWriters != 0))
-                       {
-                               mutex.wait();
-                       }
-
-                       givenLocks++;
-
-               }
-       }
-       
-       public void getWriteLock()
-       {
-               synchronized(mutex)
-               {
-                       waitingWriters++;
-
-                       while(givenLocks != 0)
-                       {
-                               mutex.wait();
-                       }
-
-                       waitingWriters--;
-                       givenLocks = -1;
-               }
-       }
-
-       public void releaseLock();
-       {
-               synchronized(mutex)
-               {
-
-                       if(givenLocks == 0)
-                               return;
-               
-                       if(givenLocks == -1)
-                               givenLocks = 0;
-                       else
-                               givenLocks--;
-
-                       mutex.notifyAll();
-               }
-       }
-
-}
\ No newline at end of file
index 4d86f86903fbd0f33179344dd6c0da2eb6674fa5..7a7d9131f0b2d32e582a96095adf82d417ca8178 100644 (file)
@@ -815,7 +815,8 @@ public class TransactionalFile implements Comparable {
 
                     block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));//(BlockDataStructure) tmp.adapter.lockmap.get(Integer.valueOf(k)));
 
-                    block.getLock().readLock().lock();
+                    //block.getLock().readLock().lock();
+                    block.getLock().readLock();
                     if (!(block.getReaders().contains(me))) {
                         block.getReaders().add(me);
                     }
@@ -825,9 +826,11 @@ public class TransactionalFile implements Comparable {
                     for (int i = 0; i < k; i++) {
                         block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));
                         if (me.toholdblocklocks[me.blockcount] == null) {
-                            me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+                            //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+                            me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
                         }
-                        me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+                        //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+                        me.toholdblocklocks[me.blockcount] = block.getLock();
                         me.blockcount++;
                     //me.getHeldblocklocks().add(block.getLock().readLock());
                     }
@@ -851,9 +854,11 @@ public class TransactionalFile implements Comparable {
                     for (k = 0; k < occupiedblocks.size(); k++) {
                         block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));
                         if (me.toholdblocklocks[me.blockcount] == null) {
-                            me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+                            me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
+                            //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
                         }
-                        me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+                        me.toholdblocklocks[me.blockcount] = block.getLock();
+                        //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
                         me.blockcount++;
                     //me.getHeldblocklocks().add(block.getLock().readLock());
                     }
@@ -861,7 +866,8 @@ public class TransactionalFile implements Comparable {
                 }
                 for (k = 0; k < occupiedblocks.size(); k++) {
                     block = this.inodestate.getBlockDataStructure((Integer) (occupiedblocks.get(k)));
-                    block.getLock().readLock().unlock();
+                    //block.getLock().readLock().unlock();
+                    block.getLock().unlockRead();
                 }
                 // offsetlock.unlock();
                 tmp.setLocaloffset(tmp.getLocaloffset() + result);
@@ -974,7 +980,8 @@ public class TransactionalFile implements Comparable {
 
         for (k = st; k <= end /*&& me.getStatus() == Status.ACTIVE*/; k++) {
             block = this.inodestate.getBlockDataStructure(Integer.valueOf(k));
-            block.getLock().readLock().lock();
+            //block.getLock().readLock().lock();
+            block.getLock().readLock();
 
             //  locks[k-st] = block.getLock().readLock();
             if (!(block.getReaders().contains(me))) {
@@ -989,9 +996,11 @@ public class TransactionalFile implements Comparable {
             //me.blockcount = k - st;
             for (int i = st; i < k; i++) {
                 if (me.toholdblocklocks[me.blockcount] == null) {
-                    me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+                    //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+                    me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
                 }
-                me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+                //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+                me.toholdblocklocks[me.blockcount] = block.getLock();
                 me.blockcount++;
             // block = this.inodestate.getBlockDataStructure(Integer.valueOf(i));
             //me.getHeldblocklocks().add(block.getLock().readLock());
@@ -1018,9 +1027,11 @@ public class TransactionalFile implements Comparable {
                 block = this.inodestate.getBlockDataStructure(Integer.valueOf(i));
                 // me.toholdblocklocks[i-st] = this.inodestate.getBlockDataStructure(Integer.valueOf(i)).getLock().readLock();
                 if (me.toholdblocklocks[me.blockcount] == null) {
-                    me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+                    //me.toholdblocklocks[me.blockcount] = new ReentrantReadWriteLock().readLock();
+                    me.toholdblocklocks[me.blockcount] = new MYReadWriteLock();
                 }
-                me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+                //me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
+                me.toholdblocklocks[me.blockcount] = block.getLock();
                 me.blockcount++;
             //me.getHeldblocklocks().add(block.getLock().readLock());
             // me.toholdblocklocks[me.blockcount] = block.getLock().readLock();
@@ -1033,7 +1044,8 @@ public class TransactionalFile implements Comparable {
         //unlock the locks
         for (k = st; k <= end; k++) {
             block = this.inodestate.getBlockDataStructure(Integer.valueOf(k));
-            block.getLock().readLock().unlock();
+            //block.getLock().readLock().unlock();
+            block.getLock().unlockRead();
         //locks[k-st].unlock();
         }
         return size;
@@ -1230,13 +1242,16 @@ public class TransactionalFile implements Comparable {
         int startblock = FileBlockManager.getCurrentFragmentIndexofTheFile(committedoffset.getOffsetnumber());
         int targetblock = FileBlockManager.getTargetFragmentIndexofTheFile(committedoffset.getOffsetnumber(), data.length);
 
-
-        WriteLock[] blocksar;
-        blocksar = new WriteLock[targetblock - startblock + 1];
+        //WriteLock[] blocksar;
+        //blocksar = new WriteLock[targetblock - startblock + 1];
+        MYReadWriteLock[] blocksar;
+        blocksar = new MYReadWriteLock[targetblock - startblock + 1];
         for (int i = startblock; i <= targetblock; i++) {
             BlockDataStructure block = this.inodestate.getBlockDataStructure(i);
-            block.getLock().writeLock().lock();
-            blocksar[i - startblock] = block.getLock().writeLock();
+            //block.getLock().writeLock().lock();
+            block.getLock().writeLock();
+            //blocksar[i - startblock] = block.getLock().writeLock();
+            blocksar[i - startblock] = block.getLock();
         //heldlocks.add(block.getLock().writeLock());
         }
 
@@ -1249,7 +1264,8 @@ public class TransactionalFile implements Comparable {
         } finally {
             //   unlockLocks(heldlocks);
             for (int i = startblock; i <= targetblock; i++) {
-                blocksar[i - startblock].unlock();
+                //blocksar[i - startblock].unlock();
+                blocksar[i - startblock].unlockWrite();
             }
             myoffsetlock.non_Transactional_Release();
             //offsetlock.writeLock().unlock();
@@ -1269,13 +1285,18 @@ public class TransactionalFile implements Comparable {
         startblock = FileBlockManager.getCurrentFragmentIndexofTheFile(committedoffset.getOffsetnumber());
         targetblock = FileBlockManager.getTargetFragmentIndexofTheFile(committedoffset.getOffsetnumber(), size);
 
-        ReadLock[] blocksar;
-        blocksar = new ReadLock[targetblock - startblock + 1];
+        //ReadLock[] blocksar;
+        //blocksar = new ReadLock[targetblock - startblock + 1];
+        
+        MYReadWriteLock[] blocksar;
+        blocksar = new MYReadWriteLock[targetblock - startblock + 1];
 
         for (int i = startblock; i <= targetblock; i++) {
             BlockDataStructure block = this.inodestate.getBlockDataStructure(i);
-            block.getLock().readLock().lock();
-            blocksar[i - startblock] = block.getLock().readLock();
+            block.getLock().readLock();
+            blocksar[i - startblock] = block.getLock();
+            //block.getLock().readLock().lock();
+            //blocksar[i - startblock] = block.getLock().readLock();
         }
 
         size = invokeNativepread(b, committedoffset.getOffsetnumber(), b.length);
@@ -1293,7 +1314,8 @@ public class TransactionalFile implements Comparable {
         }
 
         for (int i = startblock; i <= targetblock; i++) {
-            blocksar[i - startblock].unlock();
+            //blocksar[i - startblock].unlock();
+            blocksar[i - startblock].unlockWrite();
         }
 
         //unlockLocks(heldlocks);