incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1203461 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore: Index.java Table.java TableStore.java
Date Fri, 18 Nov 2011 02:08:24 GMT
Author: kwright
Date: Fri Nov 18 02:08:24 2011
New Revision: 1203461

URL: http://svn.apache.org/viewvc?rev=1203461&view=rev
Log:
Add methods that allocate node and row numbers

Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java?rev=1203461&r1=1203460&r2=1203461&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
Fri Nov 18 02:08:24 2011
@@ -106,18 +106,4 @@ public class Index implements WHIndex
     return indexName;
   }
   
-  /** Create the index */
-  public void create()
-    throws WHException
-  {
-    // MHL
-  }
-
-  /** Drop the index */
-  public void drop()
-    throws WHException
-  {
-    // MHL
-  }
-
 }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java?rev=1203461&r1=1203460&r2=1203461&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
Fri Nov 18 02:08:24 2011
@@ -114,20 +114,6 @@ public class Table implements WHTable
     return tableName;
   }
   
-  /** Create the table */
-  public void create()
-    throws WHException
-  {
-    // MHL
-  }
-
-  /** Drop the table */
-  public void drop()
-    throws WHException
-  {
-    // MHL
-  }
-  
   // Protected methods
   
   /** Delete a specified table row from all indexes attached to the table.

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java?rev=1203461&r1=1203460&r2=1203461&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
Fri Nov 18 02:08:24 2011
@@ -27,11 +27,17 @@ import java.util.*;
 */
 public class TableStore implements WHTableStore
 {
+  /** The underlying transactional store */
   protected WHTransactionalStore transactionalStore;
+  
+  /** The current transaction, if any */
   protected WHTransaction currentTransaction = null;
   
+  /** Map of table name to table object, good for the current transaction */
   protected Map<String,Table> tables = null;
+  /** Map of index name to index object, good for the current transaction */
   protected Map<String,Index> indexes = null;
+  /** Map of table name to index set, good for the current transaction */
   protected Map<String,Index[]> indexesPerTable = null;
   
   /** Constructor */
@@ -102,7 +108,8 @@ public class TableStore implements WHTab
     TableIndexKey tik = new TableIndexKey(name);
     TableIndexValue tiv = new TableIndexValue(new String[0]);
     currentTransaction.put(tik,tiv);
-    t.create();
+    TableRowLimitKey tlk = new TableRowLimitKey(name);
+    currentTransaction.put(tlk,new TableRowLimitValue(0));
     return t;
   }
   
@@ -157,7 +164,8 @@ public class TableStore implements WHTab
     tiv = new TableIndexValue(newIndexList);
     currentTransaction.put(tik,tiv);
     indexesPerTable.remove(t.getName());
-    i.create();
+    IndexNodeLimitKey tlk = new IndexNodeLimitKey(name);
+    currentTransaction.put(tlk,new IndexNodeLimitValue(0));
     return i;
   }
     
@@ -209,6 +217,54 @@ public class TableStore implements WHTab
     }
   }
   
+  // Row and node number allocators.
+  // Eventually we should be able to make it so that we allocate multiple row numbers or
node numbers
+  // at a time, which persist cross transaction.  That would reduce the number of collisions
that happen
+  // because the row counters are incrementing simultaneously.  However, cross-transaction
management
+  // is very tricky because when a transaction is abandoned, the row counter information
must revert;
+  // otherwise the same row numbers can be allocated by two threads inadvertently.  The added
complexity
+  // must therefore be worth it, and so far I'm not sure that is the case.
+  
+  /** Allocate the next table row number.
+  */
+  public int allocateNewTableRow(String tableName)
+    throws WHException
+  {
+    TableRowLimitKey tlk = new TableRowLimitKey(tableName);
+    TableRowLimitValue tlv = (TableRowLimitValue)currentTransaction.get(tlk);
+    if (tlv == null)
+      throw new WHDeadlockException();
+    int rval = tlv.getRowCounter();
+    currentTransaction.put(tlk,new TableRowLimitValue(rval+1));
+    return rval;
+  }
+  
+  /** Get the current max table row number, plus one.
+  */
+  public int getMaxTableRow(String tableName)
+    throws WHException
+  {
+    TableRowLimitKey tlk = new TableRowLimitKey(tableName);
+    TableRowLimitValue tlv = (TableRowLimitValue)currentTransaction.get(tlk);
+    if (tlv == null)
+      throw new WHDeadlockException();
+    return tlv.getRowCounter();
+  }
+  
+  /** Allocate the next index node number.
+  */
+  public int allocateNextIndexNode(String indexName)
+    throws WHException
+  {
+    IndexNodeLimitKey tlk = new IndexNodeLimitKey(indexName);
+    IndexNodeLimitValue tlv = (IndexNodeLimitValue)currentTransaction.get(tlk);
+    if (tlv == null)
+      throw new WHDeadlockException();
+    int rval = tlv.getNodeCounter();
+    currentTransaction.put(tlk,new IndexNodeLimitValue(rval+1));
+    return rval;
+  }
+  
   // Protected classes and methods
 
   protected void deleteTable(Table t)
@@ -231,7 +287,8 @@ public class TableStore implements WHTab
     
     TableKey tk = new TableKey(t.getName());
     currentTransaction.put(tk,null);
-    t.drop();
+    TableRowLimitKey tlk = new TableRowLimitKey(t.getName());
+    currentTransaction.put(tlk,null);
   }
   
   protected void deleteIndex(Index i)
@@ -262,7 +319,8 @@ public class TableStore implements WHTab
     indexesPerTable.remove(t.getName());
     IndexKey ik = new IndexKey(i.getName());
     currentTransaction.put(ik,null);
-    i.drop();
+    IndexNodeLimitKey tlk = new IndexNodeLimitKey(i.getName());
+    currentTransaction.put(tlk,null);
   }
     
   protected Table findTable(String name)
@@ -482,4 +540,87 @@ public class TableStore implements WHTab
       return unique;
     }
   }
+  
+  protected static class TableRowLimitKey extends StringValue
+  {
+    /** Constructor */
+    public TableRowLimitKey(String name)
+    {
+      super(name);
+    }
+    
+    public TableRowLimitKey(byte[] data)
+    {
+      super(data);
+    }
+
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof TableRowLimitKey))
+        return false;
+      return super.equals(o);
+    }
+
+  }
+
+  protected static class TableRowLimitValue extends IntegerValue
+  {
+    /** Constructor */
+    public TableRowLimitValue(int value)
+    {
+      super(value);
+    }
+    
+    public TableRowLimitValue(byte[] data)
+    {
+      super(data);
+    }
+    
+    public int getRowCounter()
+    {
+      return getValue();
+    }
+  }
+  
+  protected static class IndexNodeLimitKey extends StringValue
+  {
+    /** Constructor */
+    public IndexNodeLimitKey(String name)
+    {
+      super(name);
+    }
+    
+    public IndexNodeLimitKey(byte[] data)
+    {
+      super(data);
+    }
+
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof IndexNodeLimitKey))
+        return false;
+      return super.equals(o);
+    }
+
+  }
+
+  protected static class IndexNodeLimitValue extends IntegerValue
+  {
+    /** Constructor */
+    public IndexNodeLimitValue(int value)
+    {
+      super(value);
+    }
+    
+    public IndexNodeLimitValue(byte[] data)
+    {
+      super(data);
+    }
+    
+    public int getNodeCounter()
+    {
+      return getValue();
+    }
+  }
+
 }



Mime
View raw message