*** empty log message ***
authornavid <navid>
Tue, 10 Feb 2009 03:15:21 +0000 (03:15 +0000)
committernavid <navid>
Tue, 10 Feb 2009 03:15:21 +0000 (03:15 +0000)
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/ExtendedTransaction.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYLock.java [new file with mode: 0644]
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYReadWriteWLock.java [new file with mode: 0644]
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/OffsetLock.java [deleted file]
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/Wrapper.java

index 723a50e2379294611f3acdc8b0acb5c5fc3f081e..2afcfa56e2118114036a775ccef92fff9aaf426b 100644 (file)
@@ -37,16 +37,13 @@ import java.util.logging.Logger;
 public class ExtendedTransaction implements TransactionStatu {
 
     private static native int nativepwrite(byte buff[], long offset, int size, FileDescriptor fd);
-    
-
-
-
     public TransactionStatu memorystate;
     public int starttime;
     public int endtime;
     public TreeMap msg = new TreeMap();
     public int numberofwrites;
     public int numberofreads;
+    private TreeMap sortedAccesedFiles;
 
     public enum Status {
 
@@ -55,7 +52,7 @@ public class ExtendedTransaction implements TransactionStatu {
     private boolean writesmerged = true;
     private Vector heldlengthlocks;
     //private Vector<ReentrantLock> heldoffsetlocks;    
-   // private Vector heldoffsetlocks;
+    // private Vector heldoffsetlocks;
     //private Vector<ReentrantLock> heldblocklocks;    
     //private Vector heldblocklocks;
     //private HashMap<INode, Vector<TransactionalFile>> AccessedFiles;
@@ -67,7 +64,8 @@ public class ExtendedTransaction implements TransactionStatu {
     public HashMap merge_for_writes_done;
     private HashMap writeBuffer;
     private volatile Status status;
-    public ReentrantReadWriteLock[] toholoffsetlocks;
+    //public ReentrantReadWriteLock[] toholoffsetlocks;
+    public MYLock[] toholoffsetlocks;
     public int offsetcount = 0;
     public Lock[] toholdblocklocks;
     public int blockcount = 0;
@@ -75,13 +73,14 @@ public class ExtendedTransaction implements TransactionStatu {
     public ExtendedTransaction() {
         //  super();
         // id = Integer.valueOf(Thread.currentThread().getName().substring(7));
-        toholoffsetlocks = new ReentrantReadWriteLock[20];
+        //toholoffsetlocks = new ReentrantReadWriteLock[20];
+        toholoffsetlocks = new MYLock[20];
         toholdblocklocks = new Lock[20];
-      //  for (int i=0; i<20; i++)
-      //      toholoffsetlocks[i] = new ReentrantLock();
+        //  for (int i=0; i<20; i++)
+        //      toholoffsetlocks[i] = new ReentrantLock();
         heldlengthlocks = new Vector();
 //        heldblocklocks = new Vector();
-      //  heldoffsetlocks = new Vector();
+        //  heldoffsetlocks = new Vector();
         AccessedFiles = new HashMap();
         GlobaltoLocalMappings = new HashMap/*<TransactionalFile, TransactionLocalFileAttributes >*/();
         writeBuffer = new HashMap();
@@ -111,7 +110,6 @@ public class ExtendedTransaction implements TransactionStatu {
 
     }
 
-
     public void abort() {
         synchronized (this) {
             this.status = Status.ABORTED;
@@ -133,7 +131,6 @@ public class ExtendedTransaction implements TransactionStatu {
         return this.getStatus() == Status.ABORTED;
     }
 
-
     public HashMap getWriteBuffer() {
         return writeBuffer;
     }
@@ -169,14 +166,16 @@ public class ExtendedTransaction implements TransactionStatu {
     public TreeMap getSortedFileAccessMap(HashMap hmap) {
         /*TreeMap sortedMap = new TreeMap(hmap);
         return sortedMap;*/
-        return new TreeMap(hmap);
+        sortedAccesedFiles = new TreeMap(hmap);
+        return sortedAccesedFiles;
+        //return new TreeMap(hmap);
     }
 
-
     public void addFile(TransactionalFile tf, long offsetnumber/*, TransactionLocalFileAttributes tmp*/) {
-        tf.getInodestate().commitedfilesize.lengthlock.lock();
-        TransactionLocalFileAttributes tmp = new TransactionLocalFileAttributes(offsetnumber, tf.getInodestate().commitedfilesize.getLength());
-        tf.getInodestate().commitedfilesize.lengthlock.unlock();
+        //tf.getInodestate().commitedfilesize.lengthlock.lock();
+        //TransactionLocalFileAttributes tmp = new TransactionLocalFileAttributes(offsetnumber, tf.getInodestate().commitedfilesize.getLength());
+        TransactionLocalFileAttributes tmp = new TransactionLocalFileAttributes(offsetnumber, 0);
+        //tf.getInodestate().commitedfilesize.lengthlock.unlock();
         Vector dummy;
 
         if (AccessedFiles.containsKey(tf.getInode())) {
@@ -197,42 +196,47 @@ public class ExtendedTransaction implements TransactionStatu {
         TreeMap hm = getSortedFileAccessMap(AccessedFiles);
         Iterator iter = hm.keySet().iterator();
         offsetcount = 0;
-        
-       // for (int j=0; j< hm.size(); j++){
+
+        // 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);
-            
+
             Collections.sort(vec);
-            for (int i=0; i<vec.size(); i++){
-            //Iterator it = vec.iterator();
-            //while (it.hasNext() /*&& this.getStatus() == Status.ACTIVE*/) {
+            for (int i = 0; i < vec.size(); i++) {
+                //Iterator it = vec.iterator();
+                //while (it.hasNext() /*&& this.getStatus() == Status.ACTIVE*/) {
                 //TransactionalFile value = (TransactionalFile) it.next();
                 TransactionalFile value = (TransactionalFile) vec.get(i);
                 //System.out.println(Thread.currentThread() + " offset " + value);
-                if (toholoffsetlocks[offsetcount] == null)
-                    toholoffsetlocks[offsetcount] = new ReentrantReadWriteLock();
-                toholoffsetlocks[offsetcount] = value.offsetlock;
+               /* if (toholoffsetlocks[offsetcount] == null)
+                toholoffsetlocks[offsetcount] = new ReentrantReadWriteLock();
+                toholoffsetlocks[offsetcount] = value.offsetlock;*/
+                toholoffsetlocks[offsetcount] = value.myoffsetlock;
                 offsetcount++;
-                value.offsetlock.writeLock().lock();
+                
+                value.myoffsetlock.acquire(this);
+                //value.offsetlock.writeLock().lock();
 
                 //heldoffsetlocks.add(value.offsetlock);
 
-                if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(value)).lenght_read) {
+                
+                //should be uncommented
+                /*if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(value)).lenght_read) {
                     if (!(value.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread())) {
                         value.getInodestate().commitedfilesize.lengthlock.lock();
                         heldlengthlocks.add(value.getInodestate().commitedfilesize.lengthlock);
                     }
-                }
-               // break;
+                }*/
+            // break;
             }
         }
 
         if (this.getStatus() != Status.ACTIVE) {
-      //      for (int i=0; i<offsetcount; i++){
-      //          heldoffsetlocks.add(toholoffsetlocks[i]);
-      //      }
-      //      offsetcount = 0;
+            //      for (int i=0; i<offsetcount; i++){
+            //          heldoffsetlocks.add(toholoffsetlocks[i]);
+            //      }
+            //      offsetcount = 0;
             return false;
         }
         return true;
@@ -249,12 +253,12 @@ public class ExtendedTransaction implements TransactionStatu {
 
         lock.lock();
 
-        if (toholdblocklocks[blockcount] == null){
+        if (toholdblocklocks[blockcount] == null) {
             //if (mode == BlockAccessModesEnum.READ) {
             //    toholdblocklocks[blockcount] = new ReentrantReadWriteLock().readLock();
             //}
-           // else 
-                toholdblocklocks[blockcount] = new ReentrantReadWriteLock().writeLock();
+            // else 
+            toholdblocklocks[blockcount] = new ReentrantReadWriteLock().writeLock();
         }
         toholdblocklocks[blockcount] = lock;
         blockcount++;
@@ -290,8 +294,8 @@ public class ExtendedTransaction implements TransactionStatu {
             vec = (Vector) hm.get(key);
             Collections.sort(vec);
             //Iterator it = vec.iterator();
-            for (int j=0; j<vec.size(); j++){
-            //while (it.hasNext()) {
+            for (int j = 0; j < vec.size(); j++) {
+                //while (it.hasNext()) {
                 value = (WriteOperations) vec.get(j);
                 //value = (WriteOperations) it.next();
                 if (value.isUnknownoffset()) {
@@ -332,7 +336,7 @@ public class ExtendedTransaction implements TransactionStatu {
             }
 
         }
-
+       
         //toholdblocklocks = new Lock[100];
 
         Iterator it = this.getAccessedBlocks().keySet().iterator();
@@ -343,24 +347,85 @@ public class ExtendedTransaction implements TransactionStatu {
             Iterator iter2 = vec2.keySet().iterator();
             while (iter2.hasNext()/* && this.getStatus() == Status.ACTIVE*/) {
                 Integer num = (Integer) iter2.next();
-                
+
                 BlockDataStructure blockobj = inodestate.getBlockDataStructure(num);
-                
+
                 this.lockBlock(blockobj, (BlockAccessModesEnum) vec2.get(num));
-                
+
 
             }
         }
 
+
         if (this.getStatus() != Status.ACTIVE) {
             //    for (int i=0; i<blockcount; i++)
             //        heldblocklocks.add(toholdblocklocks[i]); 
             throw new AbortedException();
         }
+        
+        
+
+       
         abortAllReaders();
 
     }
 
+    public void commitOffset() {
+        Iterator k = GlobaltoLocalMappings.keySet().iterator();
+        while (k.hasNext()) {
+            TransactionalFile trf = (TransactionalFile) (k.next());
+            trf.getCommitedoffset().setOffsetnumber(((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocaloffset());
+            
+            
+            //should be uncommented
+           /* if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocalsize()) {
+                try {
+                    if (!(trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread())) {
+                        trf.getInodestate().commitedfilesize.lengthlock.lock();
+                    }
+                    //Iterator it2 = trf.getInodestate().commitedfilesize.getLengthReaders().iterator();
+
+
+                    //  if (((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getLocalsize()) {
+                    for (int adad = 0; adad < trf.getInodestate().commitedfilesize.getLengthReaders().size(); adad++) {
+                        //    while (it2.hasNext()) {
+                        ExtendedTransaction tr = (ExtendedTransaction) trf.getInodestate().commitedfilesize.getLengthReaders().get(adad);
+                        //ExtendedTransaction tr = (ExtendedTransaction) it2.next();
+                        if (tr != this) {
+                            tr.abort();
+                        }
+                    }
+                    trf.getInodestate().commitedfilesize.getLengthReaders().clear();
+                    // }
+                    trf.getInodestate().commitedfilesize.setLength(trf.file.length());
+
+                    if (trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread()) {
+                        heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
+                        trf.getInodestate().commitedfilesize.lengthlock.unlock();
+                    }
+                    if (((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).lenght_read) {
+                        trf.getInodestate().commitedfilesize.getLengthReaders().remove(this);
+                    //heldlengthlocks.remove(trf.getInodestate().commitedfilesize.lengthlock);
+                    //trf.getInodestate().commitedfilesize.lengthlock.unlock();
+                    }
+
+                } catch (IOException ex) {
+                    Logger.getLogger(ExtendedTransaction.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            }*/
+        }
+        for (int i=0; i<offsetcount; i++)
+            toholoffsetlocks[i].release(this);
+        offsetcount =0 ;
+        
+        /*for (int i = 0; i < heldlengthlocks.size(); i++) {
+            ReentrantLock lock = (ReentrantLock) heldlengthlocks.get(i);
+            //ReentrantLock lock = (ReentrantLock) it.next();
+            lock.unlock();
+        }*/
+
+    }
+
     public void commitChanges() {
 
         Map hm = getWriteBuffer();
@@ -372,10 +437,10 @@ public class ExtendedTransaction implements TransactionStatu {
             INode key = (INode) iter.next();
 
             vec = (Vector) hm.get(key);
-            Collections.sort(vec);
-            for (int j=0; j< vec.size(); j++){
-            //it = vec.iterator();
-            //while (it.hasNext()) {
+            //Collections.sort(vec);
+            for (int j = 0; j < vec.size(); j++) {
+                //it = vec.iterator();
+                //while (it.hasNext()) {
                 writeop = (WriteOperations) vec.get(j);
                 //writeop = (WriteOperations) it.next();
                 Byte[] data = new Byte[(int) (writeop.getRange().getEnd() - writeop.getRange().getStart())];
@@ -389,7 +454,7 @@ public class ExtendedTransaction implements TransactionStatu {
             }
         }
 
-        Iterator k = GlobaltoLocalMappings.keySet().iterator();
+  /*      Iterator k = GlobaltoLocalMappings.keySet().iterator();
         while (k.hasNext()) {
             TransactionalFile trf = (TransactionalFile) (k.next());
             trf.getCommitedoffset().setOffsetnumber(((TransactionLocalFileAttributes) GlobaltoLocalMappings.get(trf)).getLocaloffset());
@@ -400,18 +465,18 @@ public class ExtendedTransaction implements TransactionStatu {
                     }
                     //Iterator it2 = trf.getInodestate().commitedfilesize.getLengthReaders().iterator();
 
-                        
-                  //  if (((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getLocalsize()) {
-                    for(int adad=0; adad<trf.getInodestate().commitedfilesize.getLengthReaders().size(); adad++){ 
-                    //    while (it2.hasNext()) {
-                            ExtendedTransaction tr = (ExtendedTransaction) trf.getInodestate().commitedfilesize.getLengthReaders().get(adad);
-                            //ExtendedTransaction tr = (ExtendedTransaction) it2.next();
-                            if (tr != this) {
-                                tr.abort();
-                            }
+
+                    //  if (((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getInitiallocallength() != ((TransactionLocalFileAttributes) getGlobaltoLocalMappings().get(trf)).getLocalsize()) {
+                    for (int adad = 0; adad < trf.getInodestate().commitedfilesize.getLengthReaders().size(); adad++) {
+                        //    while (it2.hasNext()) {
+                        ExtendedTransaction tr = (ExtendedTransaction) trf.getInodestate().commitedfilesize.getLengthReaders().get(adad);
+                        //ExtendedTransaction tr = (ExtendedTransaction) it2.next();
+                        if (tr != this) {
+                            tr.abort();
                         }
-                        trf.getInodestate().commitedfilesize.getLengthReaders().clear();
-                   // }
+                    }
+                    trf.getInodestate().commitedfilesize.getLengthReaders().clear();
+                    // }
                     trf.getInodestate().commitedfilesize.setLength(trf.file.length());
 
                     if (trf.getInodestate().commitedfilesize.lengthlock.isHeldByCurrentThread()) {
@@ -428,9 +493,7 @@ public class ExtendedTransaction implements TransactionStatu {
                     Logger.getLogger(ExtendedTransaction.class.getName()).log(Level.SEVERE, null, ex);
                 }
             }
-
-
-        }
+        }*/
 
 
     /*  for (int i =0; i<blockcount; i++){
@@ -445,63 +508,68 @@ public class ExtendedTransaction implements TransactionStatu {
         //Iterator it = heldblocklocks.iterator();
 
 //        for (int i=0; i<heldblocklocks.size(); i++){
-            
+
         //while (it.hasNext()) {
 
-            //Lock lock = (Lock) it.next();
-  //          Lock lock = (Lock) heldblocklocks.get(i);
-  //          lock.unlock();
-   //     }
-       // heldblocklocks.clear();
-            for (int i=0; i< blockcount; i++){
-                toholdblocklocks[i].unlock();
-            }
-            blockcount = 0;
+        //Lock lock = (Lock) it.next();
+        //          Lock lock = (Lock) heldblocklocks.get(i);
+        //          lock.unlock();
+        //     }
+        // heldblocklocks.clear();
+        for (int i = 0; i < blockcount; i++) {
+            toholdblocklocks[i].unlock();
+        }
+        blockcount = 0;
+
         
-            for (int i=0; i< offsetcount; i++){
-                toholoffsetlocks[i].writeLock().unlock();
+        if (this.getStatus() == Status.ABORTED){
+            for (int i = 0; i < offsetcount; i++) {
+                //toholoffsetlocks[i].writeLock().unlock();
+                toholoffsetlocks[i].release(this);
             }
             offsetcount = 0;
-        
-        
+
+
         //it = heldoffsetlocks.iterator();
 //        for (int i=0; i<heldoffsetlocks.size(); i++){
         //while (it.hasNext()) {
-  //          ReentrantLock lock = (ReentrantLock) heldoffsetlocks.get(i);
-            //ReentrantLock lock = (ReentrantLock) it.next();
-  //          lock.unlock();
+        //          ReentrantLock lock = (ReentrantLock) heldoffsetlocks.get(i);
+        //ReentrantLock lock = (ReentrantLock) it.next();
+        //          lock.unlock();
 //        }
-      //  heldoffsetlocks.clear();
+        //  heldoffsetlocks.clear();
 
         //it = heldlengthlocks.iterator();
         //while (it.hasNext()) {
-        
-        for (int i=0; i<heldlengthlocks.size(); i++){
-            ReentrantLock lock = (ReentrantLock) heldlengthlocks.get(i);
-            //ReentrantLock lock = (ReentrantLock) it.next();
-            lock.unlock();
+
+           /* for (int i = 0; i < heldlengthlocks.size(); i++) {
+                ReentrantLock lock = (ReentrantLock) heldlengthlocks.get(i);
+                //ReentrantLock lock = (ReentrantLock) it.next();
+                lock.unlock();
+            }*/
         }
-       // heldlengthlocks.clear();
+    // heldlengthlocks.clear();
     }
 
     public void abortAllReaders() {
-        TreeMap hm = getSortedFileAccessMap(AccessedFiles);
+        //TreeMap hm = getSortedFileAccessMap(AccessedFiles);
+        
         //lock phase
-        Iterator iter = hm.keySet().iterator();
+        Iterator iter = sortedAccesedFiles.keySet().iterator();
         TransactionalFile value;
         while (iter.hasNext()) {
             INode key = (INode) iter.next();
             Vector vec = (Vector) AccessedFiles.get(key);
-            for (int i=0; i<vec.size(); i++){
-            //Iterator it = vec.iterator();
-            //while (it.hasNext()) {
+            for (int i = 0; i < vec.size(); i++) {
+                //Iterator it = vec.iterator();
+                //while (it.hasNext()) {
 
                 //value = (TransactionalFile) it.next();
                 value = (TransactionalFile) vec.get(i);
                 //Iterator it2 = value.getCommitedoffset().getOffsetReaders().iterator(); // for visible readers strategy
 
                 //while (it2.hasNext()) {
-                for (int j=0; j< value.getCommitedoffset().getOffsetReaders().size(); j++){
+                for (int j = 0; j < value.getCommitedoffset().getOffsetReaders().size(); j++) {
                     //ExtendedTransaction tr = (ExtendedTransaction) it2.next();
                     ExtendedTransaction tr = (ExtendedTransaction) value.getCommitedoffset().getOffsetReaders().get(j);
                     if (tr != this) {
@@ -531,9 +599,9 @@ public class ExtendedTransaction implements TransactionStatu {
                     BlockDataStructure blockobj = (BlockDataStructure) inodestate.getBlockDataStructure(num);
                     //lockmap.get(num);
                     //Iterator it4 = blockobj.getReaders().iterator(); // from here for visible readers strategy
-                    for (int i=0;i<blockobj.getReaders().size();i++){
-                    
-                    //while (it4.hasNext()) {
+                    for (int i = 0; i < blockobj.getReaders().size(); i++) {
+
+                        //while (it4.hasNext()) {
                         ExtendedTransaction tr = (ExtendedTransaction) blockobj.getReaders().get(i);
                         //ExtendedTransaction tr = (ExtendedTransaction) it4.next();
                         if (this != tr) {
@@ -548,7 +616,6 @@ public class ExtendedTransaction implements TransactionStatu {
         }
     }
 
-
     public TransactionStatu getOtherSystem() {
         return memorystate;
     }
@@ -557,26 +624,24 @@ public class ExtendedTransaction implements TransactionStatu {
         memorystate = othersystem;
     }
 
- //   public Vector getHeldblocklocks() {
- //       return heldblocklocks;
- //   }
   //   public Vector getHeldblocklocks() {
   //       return heldblocklocks;
   //   }
 
- //   public void setHeldblocklocks(Vector heldblocklocks) {
- //       this.heldblocklocks = heldblocklocks;
- //   }
   //   public void setHeldblocklocks(Vector heldblocklocks) {
   //       this.heldblocklocks = heldblocklocks;
   //   }
 
 //    public Vector getHeldoffsetlocks() {
- //       return heldoffsetlocks;
- //   }
-
+    //       return heldoffsetlocks;
+    //   }
     public Vector getHeldlengthlocks() {
         return heldlengthlocks;
     }
 
- //   public void setHeldoffsetlocks(Vector heldoffsetlocks) {
- //       this.heldoffsetlocks = heldoffsetlocks;
- //   }
-
+    //   public void setHeldoffsetlocks(Vector heldoffsetlocks) {
+    //       this.heldoffsetlocks = heldoffsetlocks;
+    //   }
     public void abortThisSystem() {
         abort();
     }
diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYLock.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYLock.java
new file mode 100644 (file)
index 0000000..0d01974
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package TransactionalIO.core;
+
+import TransactionalIO.core.ExtendedTransaction.Status;
+import TransactionalIO.exceptions.AbortedException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author navid
+ */
+public class MYLock {
+    boolean offsetlocked = false;
+
+    public MYLock() {
+        offsetlocked = false;
+    }
+    
+    synchronized void acquire(ExtendedTransaction me) {
+        try {
+            while (offsetlocked) {
+                wait();
+            }
+            if (me.getStatus() == Status.ACTIVE) {
+                //locking the offset
+                offsetlocked = true;
+            }
+
+            /*if (me.getStatus() == Status.ACTIVE) {                        //locking the offset
+            offsetlock.writeLock().lock();
+            locked = true;
+            }*/
+
+            if (me.getStatus() != Status.ACTIVE) {
+                /* if (locked) {
+                if (me.toholoffsetlocks[me.offsetcount] == null) {
+                me.toholoffsetlocks[me.offsetcount] = new ReentrantReadWriteLock();
+                }
+                me.toholoffsetlocks[me.offsetcount] = offsetlock;
+                me.offsetcount++;
+                //me.getHeldoffsetlocks().add(offsetlock);
+                }*/
+
+                offsetlocked = false;
+                throw new AbortedException();
+            }
+        } catch (InterruptedException ex) {
+            Logger.getLogger(MYLock.class.getName()).log(Level.SEVERE, null, ex);
+        }
+    }
+    
+    synchronized void release(ExtendedTransaction me) {
+        offsetlocked = false;
+        notifyAll();
+        
+    }
+    
+    synchronized void non_Transactional_Acquire() {
+        try {
+            while (offsetlocked) {
+                wait();
+            }
+            offsetlocked = true;
+        } catch (InterruptedException ex) {
+            Logger.getLogger(MYLock.class.getName()).log(Level.SEVERE, null, ex);
+        }
+    }
+    
+    synchronized void non_Transactional_Release() {
+        offsetlocked = false;
+        notifyAll();
+    }
+    
+
+}
diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYReadWriteWLock.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/MYReadWriteWLock.java
new file mode 100644 (file)
index 0000000..7283a69
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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
diff --git a/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/OffsetLock.java b/Robust/Transactions/TransactionalIO/src/TransactionalIO/core/OffsetLock.java
deleted file mode 100644 (file)
index 186a7fa..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package TransactionalIO.core;
-
-/**
- *
- * @author navid
- */
-public class OffsetLock {
-    boolean offsetlocked = false;
-
-    public OffsetLock() {
-        offsetlocked = false;
-    }
-    synchronized void acquire(ExtendedTransaction me) {
-        
-    }
-    
-    synchronized void release(ExtendedTransaction me) {
-        
-    }
-    
-
-}
index ea82de8f604e4f0f298392276904b213527f6746..4d86f86903fbd0f33179344dd6c0da2eb6674fa5 100644 (file)
@@ -50,7 +50,8 @@ public class TransactionalFile implements Comparable {
     public boolean to_be_created = false;
     public boolean writemode = false;
     public boolean appendmode = false;
-    public ReentrantReadWriteLock offsetlock;
+    //public ReentrantReadWriteLock offsetlock;
+    public MYLock myoffsetlock;
     //public boolean offsetlocked = false;
     private GlobalOffset committedoffset;
     AtomicBoolean open = new AtomicBoolean(true);
@@ -67,7 +68,8 @@ public class TransactionalFile implements Comparable {
 
             try {
 
-                offsetlock = new ReentrantReadWriteLock();
+                //offsetlock = new ReentrantReadWriteLock();
+                myoffsetlock = new MYLock();
                 file = new RandomAccessFile(f, mode);
             } catch (FileNotFoundException ex) {
 
@@ -114,7 +116,8 @@ public class TransactionalFile implements Comparable {
 
             try {
 
-                offsetlock = new ReentrantReadWriteLock();
+                //offsetlock = new ReentrantReadWriteLock();
+                myoffsetlock = new MYLock();
                 file = new RandomAccessFile(f, mode);
             } catch (FileNotFoundException ex) {
 
@@ -272,7 +275,8 @@ public class TransactionalFile implements Comparable {
             tmp.setOffsetdependency(OffsetDependency.READ_DEPENDENCY);
 
             long target;
-            lockOffset(me);
+            myoffsetlock.acquire(me);
+            //lockOffset(me);
 
             if (!(this.committedoffset.getOffsetReaders().contains(me))) {
                 this.committedoffset.getOffsetReaders().add(me);
@@ -282,8 +286,8 @@ public class TransactionalFile implements Comparable {
             target = this.committedoffset.getOffsetnumber() - tmp.getCopylocaloffset();
 
 
-
-            offsetlock.writeLock().unlock();
+            myoffsetlock.release(me);
+            //offsetlock.writeLock().unlock();
 
             //Iterator it;
 
@@ -696,8 +700,8 @@ public class TransactionalFile implements Comparable {
                 (dep == OffsetDependency.WRITE_DEPENDENCY_2)) {
             tmp.setOffsetdependency(OffsetDependency.READ_DEPENDENCY);
 
-            lockOffset(me);
-
+            //lockOffset(me);
+            myoffsetlock.acquire(me);
             if (dep != OffsetDependency.WRITE_DEPENDENCY_2) {
                 tmp.setLocaloffset(tmp.getLocaloffset() + this.committedoffset.getOffsetnumber() - tmp.getCopylocaloffset());
             }
@@ -706,7 +710,8 @@ public class TransactionalFile implements Comparable {
                 this.committedoffset.getOffsetReaders().add(me);
 
             }
-            offsetlock.writeLock().unlock();
+            myoffsetlock.release(me);
+            //offsetlock.writeLock().unlock();
 
 
         }
@@ -1063,13 +1068,12 @@ public class TransactionalFile implements Comparable {
         this.inode = inode;
     }
 
-    public void lockOffset(ExtendedTransaction me) {
+   /* public void lockOffset(ExtendedTransaction me) {
 
         boolean locked = false;
         if (me.getStatus() == Status.ACTIVE) {                        //locking the offset
-
+            
             offsetlock.writeLock().lock();
-            System.out.println("PEEEEEE");
             locked = true;
         }
 
@@ -1085,7 +1089,7 @@ public class TransactionalFile implements Comparable {
             throw new AbortedException();
         }
 
-    }
+    }*/
 
     public void lockLength(ExtendedTransaction me) {
         boolean locked = false;
@@ -1219,7 +1223,8 @@ public class TransactionalFile implements Comparable {
     public void non_Transactional_Write(byte[] data) {
 
         Vector heldlocks = new Vector();
-        offsetlock.writeLock().lock();
+        myoffsetlock.non_Transactional_Acquire();
+        //offsetlock.writeLock().lock();
 
 
         int startblock = FileBlockManager.getCurrentFragmentIndexofTheFile(committedoffset.getOffsetnumber());
@@ -1246,7 +1251,8 @@ public class TransactionalFile implements Comparable {
             for (int i = startblock; i <= targetblock; i++) {
                 blocksar[i - startblock].unlock();
             }
-            offsetlock.writeLock().unlock();
+            myoffsetlock.non_Transactional_Release();
+            //offsetlock.writeLock().unlock();
         }
 
     }
@@ -1255,7 +1261,8 @@ public class TransactionalFile implements Comparable {
         int size = -1;
 
 
-        offsetlock.writeLock().lock();
+        //offsetlock.writeLock().lock();
+        myoffsetlock.non_Transactional_Acquire();
 
         int startblock;
         int targetblock;
@@ -1290,7 +1297,8 @@ public class TransactionalFile implements Comparable {
         }
 
         //unlockLocks(heldlocks);
-        offsetlock.writeLock().unlock();
+        myoffsetlock.non_Transactional_Release();
+        //offsetlock.writeLock().unlock();
         if (size == 0) {
             size = -1;
         }
@@ -1299,17 +1307,21 @@ public class TransactionalFile implements Comparable {
     }
 
     public void non_Transactional_Seek(long offset) {
-        offsetlock.writeLock().lock();
+        //offsetlock.writeLock().lock();
+        myoffsetlock.non_Transactional_Acquire();
         committedoffset.setOffsetnumber(offset);
-        offsetlock.writeLock().unlock();
+        myoffsetlock.non_Transactional_Release();
+        //offsetlock.writeLock().unlock();
     }
 
     public long non_Transactional_getFilePointer() {
         long offset = -1;
 
-        offsetlock.writeLock().lock();
+        //offsetlock.writeLock().lock();
+        myoffsetlock.non_Transactional_Acquire();
         offset = committedoffset.getOffsetnumber();
-        offsetlock.writeLock().unlock();
+        myoffsetlock.non_Transactional_Release();
+        //offsetlock.writeLock().unlock();
 
         return offset;
     }
@@ -1341,11 +1353,9 @@ public class TransactionalFile implements Comparable {
             WriteOperations wrp = (WriteOperations) ((Vector) (me.getWriteBuffer().get(inode))).get(adad);
             if (wrp.isUnknownoffset()) {
                 wrp.setUnknownoffset(false);
-                synchronized (wrp.getOwnertransactionalFile()) {
-                    wrp.getOwnertransactionalFile().lockOffset(me);
-
-
-
+                //synchronized (wrp.getOwnertransactionalFile()) {
+                    //wrp.getOwnertransactionalFile().lockOffset(me);
+                    wrp.getOwnertransactionalFile().myoffsetlock.acquire(me);
                     wrp.getRange().setStart(wrp.getOwnertransactionalFile().committedoffset.getOffsetnumber() - wrp.getBelongingto().getCopylocaloffset() + wrp.getRange().getStart());
                     wrp.getRange().setEnd(wrp.getOwnertransactionalFile().committedoffset.getOffsetnumber() - wrp.getBelongingto().getCopylocaloffset() + wrp.getRange().getEnd());
                     if ((wrp.getBelongingto().getOffsetdependency() == OffsetDependency.WRITE_DEPENDENCY_1) ||
@@ -1358,9 +1368,10 @@ public class TransactionalFile implements Comparable {
                         }
                         wrp.getBelongingto().setLocaloffset(wrp.getBelongingto().getLocaloffset() + wrp.getOwnertransactionalFile().committedoffset.getOffsetnumber() - wrp.getBelongingto().getCopylocaloffset());
                     }
-                    wrp.getOwnertransactionalFile().offsetlock.writeLock().unlock();
+                    wrp.getOwnertransactionalFile().myoffsetlock.release(me);
+                    //wrp.getOwnertransactionalFile().offsetlock.writeLock().unlock();
 
-                }
+//                }
 
                 markAccessedBlocks(me, (int) wrp.getRange().getStart(), (int) (wrp.getRange().getEnd() - wrp.getRange().getStart()), BlockAccessModesEnum.WRITE);
 
index b68f488e2245105c025197055bd30c6608ff743f..435e1ee892a63b09760245a042f2a05da9d04b71 100644 (file)
@@ -35,6 +35,9 @@ public class Wrapper{
         getTransaction().commitChanges();
     }
     
+    public static void realseOffsets(){
+        getTransaction().commitOffset();
+    }
     
     
     public static void Initialize(TransactionStatu memory){