incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1203817 - /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
Date Fri, 18 Nov 2011 20:26:43 GMT
Author: kwright
Date: Fri Nov 18 20:26:42 2011
New Revision: 1203817

URL: http://svn.apache.org/viewvc?rev=1203817&view=rev
Log:
Comments and cleanup of table rows on deletion

Modified:
    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/TableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java?rev=1203817&r1=1203816&r2=1203817&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 20:26:42 2011
@@ -191,7 +191,7 @@ public class TableStore implements WHTab
     return null;
   }
 
-  // Non-interface methods
+  // Non-interface public methods
   
   /** Delete a table row from all the indexes that are based on a table.
   */
@@ -291,7 +291,8 @@ public class TableStore implements WHTab
     }
   }
   
-  /** Set a table column value */
+  /** Set a table column value.
+  */
   public void setTableColumnValue(String tableName, long rowID, String columnName, WHValue
value)
     throws WHException
   {
@@ -299,7 +300,8 @@ public class TableStore implements WHTab
     currentTransaction.put(key,value);
   }
   
-  /** Get a table column value */
+  /** Get a table column value.
+  */
   public WHValue getTableColumnValue(String tableName, long rowID, String columnName)
     throws WHException
   {
@@ -307,7 +309,8 @@ public class TableStore implements WHTab
     return currentTransaction.get(key);
   }
   
-  /** Build a table accessor, which accesses all the table rows. */
+  /** Build a table accessor, which accesses all the table rows.
+  */
   public WHAccessor buildTableAccessor(String tableName)
     throws WHException
   {
@@ -328,15 +331,6 @@ public class TableStore implements WHTab
     return nextValue.getValue();
   }
   
-  
-  // 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 ID.
   */
   public long allocateNewTableRow(String tableName)
@@ -367,62 +361,66 @@ public class TableStore implements WHTab
   
   // Protected classes and methods
 
+  /** Delete a table definition.
+  * Also deletes associated indexes.
+  */
   protected void deleteTable(Table t)
     throws WHException
   {
-    tables.remove(t.getName());
-    TableIndexKey tik = new TableIndexKey(t.getName());
-    StringArray tiv = (StringArray)currentTransaction.get(tik);
-    if (tiv == null)
-      throw new WHDeadlockException();
-    String[] indexes = tiv.getValue();
+    // First, remove indexes associated with this table
+    Index[] indexes = findIndexes(t.getName());
     for (int i = 0 ; i < indexes.length ; i++)
     {
-      Index index = findIndex(indexes[i]);
-      if (index == null)
-        throw new WHDeadlockException();
-      deleteIndex(index);
+      deleteIndex(indexes[i]);
     }
-    currentTransaction.put(tik,null);
     
-    TableKey tk = new TableKey(t.getName());
-    currentTransaction.put(tk,null);
-    TableRowIDFactoryKey tlk = new TableRowIDFactoryKey(t.getName());
-    currentTransaction.put(tlk,null);
+    // Now that the indexes are gone, delete all the table rows
+    t.deleteRows(buildTableAccessor(t.getName()),null);
+
+    // Delete the keys that belong to the table, and clean up cached values
+    tables.remove(t.getName());
+    indexesPerTable.remove(t.getName());
+    currentTransaction.put(new TableIndexKey(t.getName()),null);
+    currentTransaction.put(new TableKey(t.getName()),null);
+    currentTransaction.put(new TableRowIDFactoryKey(t.getName()),null);
   }
   
+  /** Delete an index definition.
+  */
   protected void deleteIndex(Index i)
     throws WHException
   {
-    indexes.remove(i.getName());
+    // First, remove this index from the indexes stored for each table
     Table t = (Table)i.getTable();
-    TableIndexKey tik = new TableIndexKey(t.getName());
-    StringArray tiv = (StringArray)currentTransaction.get(tik);
-    if (tiv == null)
-      throw new WHDeadlockException();
-    String[] indexList = tiv.getValue();
+    Index[] indexList = findIndexes(t.getName());
     if (indexList.length == 0)
       throw new WHDeadlockException();
     String[] newIndexList = new String[indexList.length - 1];
     int k = 0;
     for (int j = 0 ; j < indexList.length ; j++)
     {
-      if (!indexList[j].equals(i.getName()))
+      if (!indexList[j].getName().equals(i.getName()))
       {
-        newIndexList[k++] = indexList[j];
-        if (k == indexList.length)
+        newIndexList[k++] = indexList[j].getName();
+        if (k == newIndexList.length)
           break;
       }
     }
-    tiv = new StringArray(newIndexList);
-    currentTransaction.put(tik,tiv);
+    if (k != newIndexList.length)
+      throw new WHDeadlockException();
+    currentTransaction.put(new TableIndexKey(t.getName()),new StringArray(newIndexList));
     indexesPerTable.remove(t.getName());
-    IndexKey ik = new IndexKey(i.getName());
-    currentTransaction.put(ik,null);
-    IndexNodeIDFactoryKey tlk = new IndexNodeIDFactoryKey(i.getName());
-    currentTransaction.put(tlk,null);
+
+    // MHL to delete the index nodes
+
+    // Clean out the index definition and other associated keys, and blow away cached copies
+    indexes.remove(i.getName());
+    currentTransaction.put(new IndexKey(i.getName()),null);
+    currentTransaction.put(new IndexNodeIDFactoryKey(i.getName()),null);
   }
     
+  /** Find a table definition given its name.
+  */
   protected Table findTable(String name)
     throws WHException
   {
@@ -437,6 +435,8 @@ public class TableStore implements WHTab
     return t;
   }
   
+  /** Find an index definition given its name.
+  */
   protected Index findIndex(String name)
     throws WHException
   {
@@ -455,6 +455,8 @@ public class TableStore implements WHTab
     return i;
   }
   
+  /** Find a set of associated index definitions given a table name.
+  */
   protected Index[] findIndexes(String tableName)
     throws WHException
   {



Mime
View raw message