*** empty log message ***
authornavid <navid>
Thu, 22 Jan 2009 07:44:55 +0000 (07:44 +0000)
committernavid <navid>
Thu, 22 Jan 2009 07:44:55 +0000 (07:44 +0000)
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/DualFileTable.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndex.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/PagedIndexTransactional.java
Robust/Transactions/mytuplesoup/src/com/solidosystems/tuplesoup/core/RowTransactional.java

index 8bfbe140b3bea0cdeff3cc41c5c6c67ec6b0be55..61dbecf04a88a04056669f534c4d20e2a84cc99d 100644 (file)
@@ -35,6 +35,7 @@ import java.io.*;
 import java.util.*;
 import java.nio.channels.*;
 import com.solidosystems.tuplesoup.filter.*;
+import dstm2.atomic;
 
 /**
  * The table stores a group of rows.
@@ -69,8 +70,34 @@ public class DualFileTable implements Table{
     private int indexcacheusage;
     private Hashtable<String,TableIndexNode> indexcache;
     
+    
+    DualFileTableTSInf atomicfields;
     // Statistic counters
-    long stat_add=0;
+    public @atomic interface DualFileTableTSInf{
+        long getstat_add();
+        long getstat_update();
+        long getstat_delete();
+        long getstat_add_size();
+        long getstat_update_size();
+        long getstat_read_size();
+        long getstat_read();
+        long getstat_cache_hit();
+        long getstat_cache_miss();
+        long getstat_cache_drop();
+        
+        void setstat_add(long val);
+        void setstat_update(long val);
+        void setstat_delete(long val);
+        void setstat_add_size(long val);
+        void setstat_update_size(long val);
+        void setstat_read_size(long val);
+        void setstat_read(long val);
+        void setstat_cache_hit(long val);
+        void setstat_cache_miss(long val);
+        void setstat_cache_drop(long val);
+    }
+  
+    /*long stat_add=0;
     long stat_update=0;
     long stat_delete=0;
     long stat_add_size=0;
@@ -79,7 +106,7 @@ public class DualFileTable implements Table{
     long stat_read=0;
     long stat_cache_hit=0;
     long stat_cache_miss=0;
-    long stat_cache_drop=0;
+    long stat_cache_drop=0;*/
     
     protected String statlock="stat-dummy";
     
@@ -103,26 +130,26 @@ public class DualFileTable implements Table{
     public Hashtable<String,Long> readStatistics(){
         Hashtable<String,Long> hash=new Hashtable<String,Long>();
         synchronized(statlock){
-            hash.put("stat_table_add",stat_add);
-            hash.put("stat_table_update",stat_update);
-            hash.put("stat_table_delete",stat_delete);
-            hash.put("stat_table_add_size",stat_add_size);
-            hash.put("stat_table_update_size",stat_update_size);
-            hash.put("stat_table_read_size",stat_read_size);
-            hash.put("stat_table_read",stat_read);
-            hash.put("stat_table_cache_hit",stat_cache_hit);
-            hash.put("stat_table_cache_miss",stat_cache_miss);
-            hash.put("stat_table_cache_drop",stat_cache_drop);
-            stat_add=0;
-            stat_update=0;
-            stat_delete=0;
-            stat_add_size=0;
-            stat_update_size=0;
-            stat_read_size=0;
-            stat_read=0;
-            stat_cache_hit=0;
-            stat_cache_miss=0;
-            stat_cache_drop=0;
+            hash.put("stat_table_add",atomicfields.getstat_add());
+            hash.put("stat_table_update",atomicfields.getstat_update());
+            hash.put("stat_table_delete",atomicfields.getstat_delete());
+            hash.put("stat_table_add_size",atomicfields.getstat_add_size());
+            hash.put("stat_table_update_size",atomicfields.getstat_update_size());
+            hash.put("stat_table_read_size",atomicfields.getstat_read_size());
+            hash.put("stat_table_read",atomicfields.getstat_read());
+            hash.put("stat_table_cache_hit",atomicfields.getstat_cache_hit());
+            hash.put("stat_table_cache_miss",atomicfields.getstat_cache_miss());
+            hash.put("stat_table_cache_drop",atomicfields.getstat_cache_drop());
+            atomicfields.setstat_add(0);
+            atomicfields.setstat_update(0);
+            atomicfields.setstat_delete(0);
+            atomicfields.setstat_add_size(0);
+            atomicfields.setstat_update_size(0);
+            atomicfields.setstat_read_size(0);
+            atomicfields.setstat_read(0);
+            atomicfields.setstat_cache_hit(0);
+            atomicfields.setstat_cache_miss(0);
+            atomicfields.setstat_cache_drop(0);
             Hashtable<String,Long> ihash=index.readStatistics();
             hash.putAll(ihash);
         }
@@ -252,7 +279,7 @@ public class DualFileTable implements Table{
                  indexcache.remove(node.getData().getId());
                  indexcacheusage--;
                  synchronized(statlock){
-                     stat_cache_drop++;
+                     atomicfields.setstat_cache_drop(atomicfields.getstat_cache_drop()+1);
                  }
                  indexcachefirst=node.getNext();
                  if(indexcachefirst==null){
@@ -281,10 +308,12 @@ public class DualFileTable implements Table{
              row.writeToStream(fileastream);
              int post=fileastream.size();
              fileastream.flush();
+             
              synchronized(statlock){
-                  stat_add++;
-                  stat_add_size+=row.getSize();
-              }
+                  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);
              if(INDEXCACHESIZE>0){
                  TableIndexEntry entry=new TableIndexEntry(row.getId(),row.getSize(),FILEA,fileaposition);
@@ -301,8 +330,8 @@ public class DualFileTable implements Table{
              int post=filebstream.size();
              filebstream.flush();
              synchronized(statlock){
-                  stat_add++;
-                  stat_add_size+=row.getSize();
+                  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);
              if(INDEXCACHESIZE>0){
@@ -357,7 +386,7 @@ public class DualFileTable implements Table{
                     }
                     indexcacheusage--;
                     synchronized(statlock){
-                         stat_cache_drop++;
+                         atomicfields.setstat_cache_drop(atomicfields.getstat_cache_drop()+1);
                     }
                 }
           }
@@ -378,13 +407,13 @@ public class DualFileTable implements Table{
                         indexcachelast=node;
                   }
                   synchronized(statlock){
-                       stat_cache_hit++;
+                       atomicfields.setstat_cache_hit(atomicfields.getstat_cache_hit()+1);
                    }
                   return node.getData();
               }
           }
           synchronized(statlock){
-               stat_cache_miss++;
+               atomicfields.setstat_cache_miss(atomicfields.getstat_cache_miss()+1);
            }
           return null;
       }
@@ -454,8 +483,8 @@ public class DualFileTable implements Table{
               rowswitch=!rowswitch;
          }
          synchronized(statlock){
-              stat_update++;
-              stat_update_size+=row.getSize();
+              atomicfields.setstat_update(atomicfields.getstat_update()+1);
+              atomicfields.setstat_update_size(atomicfields.getstat_update_size()+row.getSize());
          }
      }
      
@@ -504,7 +533,7 @@ public class DualFileTable implements Table{
           }
           index.updateEntry(row.getId(),row.getSize(),DELETE,0);
           synchronized(statlock){
-               stat_delete++;
+              atomicfields.setstat_delete(atomicfields.getstat_delete()+1);
           }
      }
      
@@ -572,8 +601,8 @@ public class DualFileTable implements Table{
                   Row row=Row.readFromStream(data);
                   data.close();
                   synchronized(statlock){
-                       stat_read++;
-                       stat_read_size+=row.getSize();
+                       atomicfields.setstat_read(atomicfields.getstat_read()+1);
+                       atomicfields.setstat_read_size(atomicfields.getstat_read_size()+row.getSize());
                   }
                   return row;
               }
index 914f41ff3a99cdb35a7dff650f31dae65d019b16..a790399500df957341eb13082085c25311b048e8 100644 (file)
@@ -39,23 +39,7 @@ import java.nio.channels.*;
 
 public class PagedIndex implements TableIndex{
     
-    public @atomic interface PageIndexTSInf{
-       Long getStat_read();
-       Long getStat_write();
-       Long getStat_create_page();
-       Long getStat_page_next();
-       Long getStat_page_branch();
-       AtomicArray<TableIndexPageTransactional> getRoots();
-       
-       void setRoots(AtomicArray<TableIndexPageTransactional> roots);
-       void setStat_read(Long val);
-       void setStat_write(Long val);
-       void setStat_create_page(Long val);
-       void setStat_page_next(Long val);
-       void setStat_page_branch(Long val);
-    }
-    
-    protected static final int INITIALPAGEHASH=1024;
+protected static final int INITIALPAGEHASH=1024;
     protected static final int PAGESIZE=2048;
     
     private RandomAccessFile out=null;
index 0a7e6790a8afd965cb95605ffc55b4c7b69a4e1a..3fea916033a73c8f053e8d76cb7b09843cae652c 100644 (file)
@@ -5,10 +5,31 @@
 
 package com.solidosystems.tuplesoup.core;
 
+import dstm2.AtomicArray;
+import dstm2.atomic;
+
 /**
  *
  * @author navid
  */
 public class PagedIndexTransactional {
 
+       public @atomic interface PageIndexTSInf{
+       Long getStat_read();
+       Long getStat_write();
+       Long getStat_create_page();
+       Long getStat_page_next();
+       Long getStat_page_branch();
+       AtomicArray<TableIndexPageTransactional> getRoots();
+       
+       void setRoots(AtomicArray<TableIndexPageTransactional> roots);
+       void setStat_read(Long val);
+       void setStat_write(Long val);
+       void setStat_create_page(Long val);
+       void setStat_page_next(Long val);
+       void setStat_page_branch(Long val);
+    }
+    
+    protected static final int INITIALPAGEHASH=1024;
+    protected static final int PAGESIZE=2048;
 }
index 76685082b692ffca9076e1caa8458d81da252b84..1e6e005cc624ec234946b06a53bbbb7f45f14cc5 100644 (file)
@@ -6,13 +6,15 @@
 package com.solidosystems.tuplesoup.core;
 
 import dstm2.atomic;
-import dstm2.util.HashMap;
+import dstm2.util.StringKeyHashMap;
 import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 /**
  *
@@ -20,17 +22,19 @@ import java.util.Set;
  */
 public class RowTransactional {
      private String id;
-     private int size;
-     private HashMap<ValueTransactional> values;
+    // private int size;
+     RowTSInf atomicfields;
+     private StringKeyHashMap<ValueTransactional> values;
      
      public @atomic interface RowTSInf{
-        
+        int getSize();
+        void setSize(int val);
      }
      
      public RowTransactional(String id){
          this.id=id;
-         size=-1;
-         values=new HashMap<ValueTransactional>();
+         atomicfields.setSize(-1);
+         values=new StringKeyHashMap<ValueTransactional>();
      }
      
      /**
@@ -48,8 +52,8 @@ public class RowTransactional {
       * Returns the actual size in bytes this row will take when written to a stream.
       */
      public int getSize(){
-         if(size==-1)recalcSize();
-         return size;
+         if(atomicfields.getSize()==-1)recalcSize();
+         return atomicfields.getSize();
      }
 
      /**
@@ -78,71 +82,71 @@ public class RowTransactional {
       * Stores the given value for the given key.
       */
      public void put(String key,ValueTransactional value){
-         size=-1;
-         values.put(key.hashCode(),value);
+         atomicfields.setSize(-1);
+         values.put(key,value);
      }
      
      /**
       * Stores the given string wrapped in a value object for the given key.
       */
      public void put(String key,String value){
-         size=-1;
-         values.put(key.hashCode(),new ValueTransactional(value));
+         atomicfields.setSize(-1);
+         values.put(key,new ValueTransactional(value));
      }
      
      /**
       * Stores the given int wrapped in a value object for the given key.
       */
      public void put(String key,int value){
-         size=-1;
-         values.put(key.hashCode(),new ValueTransactional(value));
+         atomicfields.setSize(-1);
+         values.put(key,new ValueTransactional(value));
      }
      
      /**
       * Stores the given long wrapped in a value object for the given key.
       */
      public void put(String key,long value){
-         size=-1;
-         values.put(key.hashCode(),new ValueTransactional(value));
+         atomicfields.setSize(-1);
+         values.put(key,new ValueTransactional(value));
      }
      
      /**
       * Stores the given float wrapped in a value object for the given key.
       */
      public void put(String key,float value){
-         size=-1;
-         values.put(key.hashCode(),new ValueTransactional(value));
+         atomicfields.setSize(-1);
+         values.put(key,new ValueTransactional(value));
      }
      
      /**
       * Stores the given double wrapped in a value object for the given key.
       */
      public void put(String key,double value){
-         size=-1;
-         values.put(key.hashCode(),new ValueTransactional(value));
+         atomicfields.setSize(-1);
+         values.put(key,new ValueTransactional(value));
      }
      
      /**
       * Stores the given boolean wrapped in a value object for the given key.
       */
      public void put(String key,boolean value){
-         size=-1;
-         values.put(key.hashCode(),new ValueTransactional(value));
+         atomicfields.setSize(-1);
+         values.put(key,new ValueTransactional(value));
      }
      
      /**
       * Stores the given Date wrapped in a value object for the given key.
       */
      public void put(String key,Date value){
-         size=-1;
-         values.put(key.hashCode(),new ValueTransactional(value));
+         atomicfields.setSize(-1);
+         values.put(key,new ValueTransactional(value));
      }
      
      /**
       * Returns the value stored for the current key, or a null value (not null) if the key does not exist.
       */
      public ValueTransactional get(String key){
-         if(!values.containsKey(key.hashCode()))return new ValueTransactional();
+         if(!values.containsKey(key))return new ValueTransactional();
          return values.get(key.hashCode());
      }
      
@@ -152,7 +156,7 @@ public class RowTransactional {
       * See the documentation for Value to learn how the string value is generated.
       */
      public String getString(String key){
-         if(!values.containsKey(key.hashCode()))return "";
+         if(!values.containsKey(key))return "";
          return values.get(key.hashCode()).getString();
      }
      
@@ -162,7 +166,7 @@ public class RowTransactional {
       * See the documentation for Value to learn how the string value is generated.
       */
      public int getInt(String key){
-         if(!values.containsKey(key.hashCode()))return 0;
+         if(!values.containsKey(key))return 0;
           return values.get(key.hashCode()).getInt();
      }
      
@@ -172,7 +176,7 @@ public class RowTransactional {
       * See the documentation for Value to learn how the string value is generated.
       */
      public long getLong(String key){
-         if(!values.containsKey(key.hashCode()))return 0;
+         if(!values.containsKey(key))return 0;
           return values.get(key.hashCode()).getLong();
      }
      
@@ -182,7 +186,7 @@ public class RowTransactional {
       * See the documentation for Value to learn how the string value is generated.
       */
      public float getFloat(String key){
-         if(!values.containsKey(key.hashCode()))return 0f;
+         if(!values.containsKey(key))return 0f;
           return values.get(key.hashCode()).getFloat();
      }
      
@@ -192,7 +196,7 @@ public class RowTransactional {
       * See the documentation for Value to learn how the string value is generated.
       */
      public double getDouble(String key){
-         if(!values.containsKey(key.hashCode()))return 0d;
+         if(!values.containsKey(key))return 0d;
           return values.get(key.hashCode()).getDouble();
      }
      
@@ -202,7 +206,7 @@ public class RowTransactional {
       * See the documentation for Value to learn how the string value is generated.
       */
      public boolean getBoolean(String key){
-         if(!values.containsKey(key.hashCode()))return false;
+         if(!values.containsKey(key))return false;
           return values.get(key.hashCode()).getBoolean();
      }
      
@@ -212,7 +216,7 @@ public class RowTransactional {
       * See the documentation for Value to learn how the string value is generated.
       */
      public Date getTimestamp(String key){
-         if(!values.containsKey(key.hashCode()))return new Date(0);
+         if(!values.containsKey(key))return new Date(0);
           return values.get(key.hashCode()).getTimestamp();
       }
  
@@ -233,7 +237,7 @@ public class RowTransactional {
              ByteArrayOutputStream bout=new ByteArrayOutputStream();
              DataOutputStream dout=new DataOutputStream(bout);
              writeToStream(dout);
-             size=bout.size();
+             this.atomicfields.setSize(bout.size());
              dout.close();
              bout.close();
          }catch(Exception e){}
@@ -247,19 +251,19 @@ public class RowTransactional {
           
           out.writeUTF(id);
           
-          Set keys=values.keySet();
-          out.writeInt(keys.size());
-          Iterator<String> it=keys.iterator();
+          Set<StringKeyHashMap.TEntry<ValueTransactional>> pairs=values.entrySet(); 
+          out.writeInt(pairs.size());
+          Iterator<StringKeyHashMap.TEntry<ValueTransactional>> it= pairs.iterator();
           while(it.hasNext()){
-             Integer key= (Integer)it.next();
-             ValueTransactional value=values.get(key.hashCode());
+             String key= it.next().getKey();
+             ValueTransactional value= values.get(key);
              out.writeUTF(key);
              value.writeToFile(out);
           }
           long post=out.getFilePointer();
           int size=(int)(post-pre);
-          this.size=size+4;
-          out.writeInt(this.size);
+          this.atomicfields.setSize(size+4);
+          out.writeInt(this.atomicfields.getSize());
       }
  
       /**
@@ -268,35 +272,36 @@ public class RowTransactional {
       public void writeToStream(DataOutputStream out) throws IOException{
          int pre=out.size();
          out.writeUTF(id);
-         Set<String> keys=values.keySet();
-         out.writeInt(keys.size());
-         Iterator<String> it=keys.iterator();
+         Set<StringKeyHashMap.TEntry<ValueTransactional>> pairs=values.entrySet();
+         out.writeInt(pairs.size());
+         
+         Iterator<StringKeyHashMap.TEntry<ValueTransactional>> it=pairs.iterator();
          while(it.hasNext()){
-             String key=it.next();
-             ValueTransactional value=values.get(key.hashCode());
+             String key=it.next().getKey();
+             ValueTransactional value=values.get(key);
              out.writeUTF(key);
              value.writeToStream(out);
          }
          int post=out.size();
          int size=calcSize(pre,post);
-         this.size=size+4;
-         out.writeInt(this.size);
+         this.atomicfields.setSize(size+4);
+         out.writeInt(this.atomicfields.getSize());
      }
  
      /**
       * Reads a full row from the given DataInputStream and returns it.
       */
-     public static Row readFromStream(DataInputStream in) throws IOException{
+     public static RowTransactional readFromStream(DataInputStream in) throws IOException{
          String id=in.readUTF();
-         Row row=new Row(id);
+         RowTransactional row=new RowTransactional(id);
          int size=in.readInt();
          for(int i=0;i<size;i++){
              String key=in.readUTF();
-             Value value=Value.readFromStream(in);
+             ValueTransactional value=ValueTransactional.readFromStream(in);
              row.put(key,value);
          }
          size=in.readInt();
-         row.size=size;
+         row.atomicfields.setSize(size);
          return row;
      }
  
@@ -309,7 +314,7 @@ public class RowTransactional {
      public String toString(){
          StringBuffer buf=new StringBuffer();
          buf.append("("+id+")=>{");
-         Iterator<String> it=values.keySet().iterator();
+         Iterator<StringKeyHashMap.TEntry<ValueTransactional>> it=values.entrySet().iterator();
          boolean first=true;
          while(it.hasNext()){
              if(!first){
@@ -317,11 +322,11 @@ public class RowTransactional {
              }else{
                  first=false;
              }
-              key=it.next();
+             String key=it.next().getKey();
              buf.append("\"");
              buf.append(key);
              buf.append("\":");
-             Value value=values.get(key);
+             ValueTransactional value=values.get(key);
              buf.append(value.getTypeName());
              buf.append(":");
              if(value.getType()==Value.STRING){
@@ -365,10 +370,10 @@ public class RowTransactional {
          StringBuffer buf=new StringBuffer();
          buf.append(indentation);
          buf.append("<row id=\""+id+"\">\n");
-         Iterator it=values.entrySet().iterator();
+         Iterator<StringKeyHashMap.TEntry<ValueTransactional>> it=values.entrySet().iterator();
          while(it.hasNext()){
-             String key=(String)it.next();
-             ValueTransactional value=values.get(key.hashCode());
+             String key=it.next().getKey();
+             ValueTransactional value=values.get(key);
              buf.append(indentation);
              buf.append("   ");
              buf.append(value.toBasicXMLString(key));