*** empty log message ***
authornavid <navid>
Fri, 23 Jan 2009 02:29:12 +0000 (02:29 +0000)
committernavid <navid>
Fri, 23 Jan 2009 02:29:12 +0000 (02:29 +0000)
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/ExtendedTransaction.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/GlobalLength.java
Robust/Transactions/TransactionalIO/src/TransactionalIO/core/TransactionalFile.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTableTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/RowTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/ValueTransactional.java

index 90f5b7644e7336e41fde623c33b00f0abfdc7495..db536b17cea65e1cfc379f80c443d70c3eb4a114 100644 (file)
@@ -195,8 +195,9 @@ public class ExtendedTransaction implements TransactionStatu {
     }
 
     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();
         Vector dummy;
 
         if (AccessedFiles.containsKey(tf.getInode())) {
index 44d19fdab79f238f24d4ca90bfa353eff1f44221..de68c1c765ce5ab783e2e1eeeee8014c6c377d80 100644 (file)
@@ -16,7 +16,6 @@ public class GlobalLength {
    private long length;
     //private Vector<ExtendedTransaction> offsetReaders;
     private Vector lengthReaders = new Vector();
-    private ExtendedTransaction offsetOwner;
     public ReentrantLock lengthlock;
 
     public GlobalLength(long length) {
index dcadae6da865a340c7569c5f14b7a009ca007208..9f5be1408eaafe162d9d9c301b9d6fd3e2833828 100644 (file)
@@ -12,11 +12,13 @@ import TransactionalIO.core.ExtendedTransaction.Status;
 import TransactionalIO.interfaces.BlockAccessModesEnum;
 import TransactionalIO.interfaces.OffsetDependency;
 import com.sun.org.apache.bcel.internal.generic.IFEQ;
+import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.io.UTFDataFormatException;
 import java.nio.ByteBuffer;
 import java.util.Collections;
 import java.util.Iterator;
@@ -269,6 +271,10 @@ public class TransactionalFile implements Comparable {
         return tmp.getLocaloffset();
     }
 
+    public void force(){
+        
+    }
+    
     public void seek(long offset) {
 
         ExtendedTransaction me = Wrapper.getTransaction();
@@ -402,6 +408,10 @@ public class TransactionalFile implements Comparable {
 
     }
     
+    public final void writeFloat(Float v){
+        writeInt(Float.floatToIntBits(v));
+    }
+    
      public final void writeLong(long value){
         try {
             byte[] result = new byte[4];
@@ -420,6 +430,14 @@ public class TransactionalFile implements Comparable {
 
     }
      
+     public final void writeDouble(Double v) {
+        writeLong(Double.doubleToLongBits(v));
+     }
+     
+     public final void writeBoolean(boolean v){
+          writeByte(v ? 1 : 0);
+     }
+     
      public final void writeChars(String s) throws IOException {
             int clen = s.length();
             int blen = 2*clen;
@@ -432,6 +450,65 @@ public class TransactionalFile implements Comparable {
             }
             write(b);
     }
+     
+    public final int writeUTF(String str) throws UTFDataFormatException{
+        int strlen = str.length();
+        int utflen = 0;
+        int c, count = 0;
+            /* use charAt instead of copying String to char array */
+        for (int i = 0; i < strlen; i++) {
+            c = str.charAt(i);
+            if ((c >= 0x0001) && (c <= 0x007F)) {
+                utflen++;
+            } else if (c > 0x07FF) {
+                utflen += 3;
+            } else {
+                utflen += 2;
+            }
+        }
+
+        if (utflen > 65535)
+              throw new UTFDataFormatException(
+                  "encoded string too long: " + utflen + " bytes");
+
+               byte[] bytearr = null;
+                
+               bytearr = new byte[utflen + 2];
+                
+
+                bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
+                bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
+
+                int i = 0;
+               for (i = 0; i < strlen; i++) {
+                    c = str.charAt(i);
+                    if (!((c >= 0x0001) && (c <= 0x007F)))
+                       break;
+                    bytearr[count++] = (byte) c;
+                }
+
+                for (; i < strlen; i++) {
+                    c = str.charAt(i);
+                    if ((c >= 0x0001) && (c <= 0x007F)) {
+                        bytearr[count++] = (byte) c;
+
+                    } else if (c > 0x07FF) {
+                        bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
+                        bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F));
+                        bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
+                    } else {
+                        bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
+                        bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
+                   }
+               }
+        try {
+            write(bytearr);
+        } catch (IOException ex) {
+            Logger.getLogger(TransactionalFile.class.getName()).log(Level.SEVERE, null, ex);
+        }
+               //write(bytearr, 0, utflen + 2);
+               return utflen + 2;
+    }
     
     public int read(byte[] b) {
 
index d506fa383e2c0f24fe14b9982a9e8b7607aeed43..af4be46f593ed2e15be8aefbecfee239c1fde310 100644 (file)
@@ -32,6 +32,7 @@
 package com.solidosystems.tuplesoup.core;
  
 
+import TransactionalIO.core.TransactionalFile;
 import java.io.*;
 import java.util.*;
 import java.nio.channels.*;
@@ -51,16 +52,19 @@ public class DualFileTableTransactional implements TableTransactional{
     private String filealock="filea-dummy";
     private String fileblock="fileb-dummy";
 
-    private DataOutputStream fileastream=null;
-    private DataOutputStream filebstream=null;
-    private RandomAccessFile filearandom=null;
-    private RandomAccessFile filebrandom=null;
+//    private DataOutputStream fileastream=null;
+//    private DataOutputStream filebstream=null;
+    private TransactionalFile fileastream=null;
+    private TransactionalFile filebstream=null;
+//    private RandomAccessFile filearandom=null;
+    private TransactionalFile filearandom=null;
+    private TransactionalFile filebrandom=null;
     FileChannel fca=null;
     FileChannel fcb=null;
     private TableIndexTransactional index=null;
      
-    private long fileaposition=0;
-    private long filebposition=0;
+//    private long fileaposition=0;
//   private long filebposition=0;
      
     private boolean rowswitch=true;
      
@@ -69,7 +73,7 @@ public class DualFileTableTransactional implements TableTransactional{
      
     private TableIndexNodeTransactional indexcachefirst;
     private TableIndexNodeTransactional indexcachelast;
-    private int indexcacheusage;
+    //private int indexcacheusage;
     
     private StringKeyHashMap<TableIndexNodeTransactional> indexcache;
     //private Hashtable<String,TableIndexNode> indexcache;
@@ -88,6 +92,9 @@ public class DualFileTableTransactional implements TableTransactional{
         long getstat_cache_hit();
         long getstat_cache_miss();
         long getstat_cache_drop();
+        long getFileaposition();
+        long getFilebposition();
+        int getIndexcacheusage();
         
         void setstat_add(long val);
         void setstat_update(long val);
@@ -99,6 +106,9 @@ public class DualFileTableTransactional implements TableTransactional{
         void setstat_cache_hit(long val);
         void setstat_cache_miss(long val);
         void setstat_cache_drop(long val);
+        void setIndexcacheusage(int val);
+        void setFileaposition(long val);
+        void setFilebposition(long val);
     }
   
     /*long stat_add=0;
@@ -179,7 +189,9 @@ public class DualFileTableTransactional implements TableTransactional{
         }
         indexcachefirst=null;
         indexcachelast=null;
-        indexcacheusage=0;
+        atomicfields.setFileaposition(0);
+        atomicfields.setFilebposition(0);
+        atomicfields.setIndexcacheusage(0);
         indexcache=new StringKeyHashMap<TableIndexNodeTransactional>();
     }
      
@@ -248,15 +260,21 @@ public class DualFileTableTransactional implements TableTransactional{
      private synchronized void openFile(int type) throws IOException{
          switch(type){
              case FILEA  : if(fileastream==null){
-                                fileastream=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getFileName(FILEA),true)));
-                                File ftest=new File(getFileName(FILEA));
-                                fileaposition=ftest.length();
+                               // fileastream=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getFileName(FILEA),true)));
+                                fileastream=new TransactionalFile(getFileName(FILEA),"rw");
+                                 
+                                //File ftest=new File(getFileName(FILEA));
+                                //atomicfields.setFileaposition(ftest.length());
+                                atomicfields.setFileaposition(fileastream.length());
+                                fileastream.seek(fileastream.length());
                            }
                           break;
              case FILEB  : if(filebstream==null){
-                                filebstream=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getFileName(FILEB),true)));
-                                File ftest=new File(getFileName(FILEB));
-                                filebposition=ftest.length();
+                                filebstream=new TransactionalFile(getFileName(FILEB),"rw");
+                                //File ftest=new File(getFileName(FILEB));
+                                //atomicfields.setFilebposition(ftest.length());
+                                atomicfields.setFilebposition(filebstream.length());
+                                filebstream.seek(filebstream.length());
                            }
                           break;
          }
@@ -277,11 +295,11 @@ public class DualFileTableTransactional implements TableTransactional{
      
      private void addCacheEntry(TableIndexEntryTransactional entry){
          synchronized(indexcache){
-             if(indexcacheusage>INDEXCACHESIZE){
+             if(atomicfields.getIndexcacheusage()>INDEXCACHESIZE){
                  // remove first entry
                  TableIndexNodeTransactional node=indexcachefirst;
                  indexcache.remove(node.getData().getId());
-                 indexcacheusage--;
+                 atomicfields.setIndexcacheusage(atomicfields.getIndexcacheusage()-1);
                  synchronized(statlock){
                      atomicfields.setstat_cache_drop(atomicfields.getstat_cache_drop()+1);
                  }
@@ -301,48 +319,54 @@ public class DualFileTableTransactional implements TableTransactional{
              }
              indexcachelast=node;
              indexcache.put(entry.getId(),node);
-             indexcacheusage++;
+             atomicfields.setIndexcacheusage(atomicfields.getIndexcacheusage()+1);
         }
      }
      
      private void addRowA(RowTransactional row) throws IOException{
          synchronized(filealock){
-             openFile(FILEA);
-             int pre=fileastream.size();
-             row.writeToStream(fileastream);
-             int post=fileastream.size();
-             fileastream.flush();
+             openFile(FILEA);             
+             //int pre=fileastream.size();
+             int pre= (int)fileastream.getFilePointer();
+             //row.writeToStream(fileastream);
+             row.writeToFile(fileastream);
+             //int post= fileastream.size();
+             int post= (int)fileastream.getFilePointer();
+             //fileastream.flush();
              
              synchronized(statlock){
                   atomicfields.setstat_add(atomicfields.getstat_add()+1);
                   atomicfields.setstat_add_size(atomicfields.getstat_add_size()+row.getSize());
              }
              
-             index.addEntry(row.getId(),row.getSize(),FILEA,fileaposition);
+             index.addEntry(row.getId(),row.getSize(),FILEA,atomicfields.getFilebposition());
              if(INDEXCACHESIZE>0){
-                 TableIndexEntryTransactional entry=new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEA,fileaposition);
+                 TableIndexEntryTransactional entry=new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEA,atomicfields.getFileaposition());
                  addCacheEntry(entry);
              }
-             fileaposition+=Row.calcSize(pre,post);
+             atomicfields.setFileaposition(atomicfields.getFileaposition()+Row.calcSize(pre,post));
          }
      }
      private void addRowB(RowTransactional row) throws IOException{
          synchronized(fileblock){
              openFile(FILEB);
-             int pre=filebstream.size();
-             row.writeToStream(filebstream);
-             int post=filebstream.size();
-             filebstream.flush();
+             //int pre=filebstream.size();
+             int pre= (int)filebstream.getFilePointer();
+             //row.writeToStream(filebstream);
+             row.writeToFile(filebstream);
+             int post=(int)filebstream.getFilePointer();
+             //int post=filebstream.size();
+             //filebstream.flush();
              synchronized(statlock){
                   atomicfields.setstat_add(atomicfields.getstat_add()+1);
                   atomicfields.setstat_add_size(atomicfields.getstat_add_size()+row.getSize());
               }
-             index.addEntry(row.getId(),row.getSize(),FILEB,filebposition);
+             index.addEntry(row.getId(),row.getSize(),FILEB,atomicfields.getFilebposition());
              if(INDEXCACHESIZE>0){
-                 TableIndexEntryTransactional entry=new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEB,filebposition);
+                 TableIndexEntryTransactional entry=new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEB,atomicfields.getFilebposition());
                  addCacheEntry(entry);
              }
-             filebposition+=RowTransactional.calcSize(pre,post);
+             atomicfields.setFilebposition(atomicfields.getFilebposition()+Row.calcSize(pre,post));
          }
      }
      
@@ -373,10 +397,10 @@ public class DualFileTableTransactional implements TableTransactional{
                 if(indexcache.containsKey(id)){
                     TableIndexNodeTransactional node=indexcache.get(id);
                     indexcache.remove(id);
-                    if(indexcacheusage==1){
+                    if(atomicfields.getIndexcacheusage()==1){
                         indexcachefirst=null;
                         indexcachelast=null;
-                        indexcacheusage=0;
+                        atomicfields.setIndexcacheusage(0);
                         return;
                     }
                     if(node==indexcachefirst){
@@ -388,7 +412,7 @@ public class DualFileTableTransactional implements TableTransactional{
                     }else{
                         node.remove();
                     }
-                    indexcacheusage--;
+                    atomicfields.setIndexcacheusage(atomicfields.getIndexcacheusage()-1);
                     synchronized(statlock){
                          atomicfields.setstat_cache_drop(atomicfields.getstat_cache_drop()+1);
                     }
@@ -457,8 +481,8 @@ public class DualFileTableTransactional implements TableTransactional{
             switch(entry.getLocation()){
                 case FILEA  :synchronized(filealock){
                                 if(filearandom==null){
-                                    filearandom=new RandomAccessFile(getFileName(FILEA),"rw");
-                                    fca=filearandom.getChannel();
+                                    filearandom=new TransactionalFile(getFileName(FILEA),"rw");
+                                   // fca=filearandom.getChannel();
                                 }
                                 filearandom.seek(entry.getPosition());
                                 row.writeToFile(filearandom);
@@ -468,8 +492,8 @@ public class DualFileTableTransactional implements TableTransactional{
                             break;
                 case FILEB :synchronized(fileblock){
                                 if(filebrandom==null){
-                                    filebrandom=new RandomAccessFile(getFileName(FILEB),"rw");
-                                    fcb=filebrandom.getChannel();
+                                    filebrandom=new TransactionalFile(getFileName(FILEB),"rw");
+                                  //  fcb=filebrandom.getChannel();
                                 }
                                 filebrandom.seek(entry.getPosition());
                                 row.writeToFile(filebrandom);
@@ -495,34 +519,40 @@ public class DualFileTableTransactional implements TableTransactional{
      private void updateRowA(RowTransactional row) throws IOException{
          synchronized(filealock){
               openFile(FILEA);
-              int pre=fileastream.size();
-              row.writeToStream(fileastream);
-              int post=fileastream.size();
-              fileastream.flush();
-              index.updateEntry(row.getId(),row.getSize(),FILEA,fileaposition);
+              //int pre=filebstream.size();
+              int pre=(int)fileastream.getFilePointer();
+              //row.writeToStream(filebstream);
+              row.writeToFile(fileastream);
+              //int post=filebstream.size();
+              int post=(int)fileastream.getFilePointer();
+              //fileastream.flush();
+              index.updateEntry(row.getId(),row.getSize(),FILEA,atomicfields.getFileaposition());
               
               // Handle index entry caching
               if(INDEXCACHESIZE>0){
-                  updateCacheEntry(new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEA,fileaposition));
+                  updateCacheEntry(new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEA,atomicfields.getFileaposition()));
               }
-              fileaposition+=Row.calcSize(pre,post);
+              atomicfields.setFileaposition(atomicfields.getFilebposition()+RowTransactional.calcSize(pre,post));
           }
      }
 
      private void updateRowB(RowTransactional row) throws IOException{
          synchronized(fileblock){
               openFile(FILEB);
-              int pre=filebstream.size();
-              row.writeToStream(filebstream);
-              int post=filebstream.size();
-              filebstream.flush();
-              index.updateEntry(row.getId(),row.getSize(),FILEB,filebposition);
+              //int pre=filebstream.size();
+              int pre=(int)filebstream.getFilePointer();
+              //row.writeToStream(filebstream);
+              row.writeToFile(filebstream);
+              //int post=filebstream.size();
+              int post=(int)filebstream.getFilePointer();
+              //filebstream.flush();
+              index.updateEntry(row.getId(),row.getSize(),FILEB,atomicfields.getFilebposition());
               // Handle index entry caching
               // Handle index entry caching
                 if(INDEXCACHESIZE>0){
-                    updateCacheEntry(new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEB,filebposition));
+                    updateCacheEntry(new TableIndexEntryTransactional(row.getId(),row.getSize(),FILEB,atomicfields.getFilebposition()));
                 }
-                filebposition+=Row.calcSize(pre,post);
+                atomicfields.setFilebposition(atomicfields.getFilebposition()+RowTransactional.calcSize(pre,post));
           }
      }
 
index 1e6e005cc624ec234946b06a53bbbb7f45f14cc5..cbe908cdf267c221769aca4fd82fff85b8e5c90e 100644 (file)
@@ -5,6 +5,7 @@
 
 package com.solidosystems.tuplesoup.core;
 
+import TransactionalIO.core.TransactionalFile;
 import dstm2.atomic;
 import dstm2.util.StringKeyHashMap;
 import java.io.ByteArrayOutputStream;
@@ -246,7 +247,7 @@ public class RowTransactional {
      /**
       * Writes the contents of this row to the given RandomAccessFile
       */
-     public void writeToFile(RandomAccessFile out) throws IOException{
+     public void writeToFile(TransactionalFile out) throws IOException{
           long pre=out.getFilePointer();
           
           out.writeUTF(id);
@@ -260,6 +261,7 @@ public class RowTransactional {
              out.writeUTF(key);
              value.writeToFile(out);
           }
+          
           long post=out.getFilePointer();
           int size=(int)(post-pre);
           this.atomicfields.setSize(size+4);
index f3be9829a4b344c9a7ba2daa0a78a41e9ce2a6b4..ab7083b93dbb1067ca554a0e362595d02f27a450 100644 (file)
@@ -5,6 +5,7 @@
 
 package com.solidosystems.tuplesoup.core;
 
+import TransactionalIO.core.TransactionalFile;
 import dstm2.AtomicByteArray;
 import dstm2.AtomicSuperClass;
 import dstm2.atomic;
@@ -487,7 +488,7 @@ public class ValueTransactional implements AtomicSuperClass{
        * 
        * @param out the DataOutputStream the Value should be written to
        */
-      public void writeToFile(DataOutput out) throws IOException{
+      public void writeToFile(TransactionalFile out) throws IOException{
           out.writeByte(atomicfields.getType());
           switch(atomicfields.getType()){
               case STRING :   out.writeInt(atomicfields.getStr_value().length());
@@ -509,7 +510,7 @@ public class ValueTransactional implements AtomicSuperClass{
                           break;
               case BINARY : out.writeInt(atomicfields.getBinary().length());
                             for (int i=0; i<atomicfields.getBinary().length(); i++) 
-                                out.write(atomicfields.getBinary().get(i));
+                                out.writeByte(atomicfields.getBinary().get(i));
                             
           }
       }