incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1204399 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog: atomictransaction/ interfaces/ tablestore/
Date Mon, 21 Nov 2011 08:44:54 GMT
Author: kwright
Date: Mon Nov 21 08:44:53 2011
New Revision: 1204399

URL: http://svn.apache.org/viewvc?rev=1204399&view=rev
Log:
Revamp lower layers to make it feasible to keep local transaction partly on disk if necessary.

Added:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyIterator.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java
  (with props)
Modified:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/atomictransaction/TransactionImpl.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAtomicKeyValueStore.java
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTransaction.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/atomictransaction/TransactionImpl.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/atomictransaction/TransactionImpl.java?rev=1204399&r1=1204398&r2=1204399&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/atomictransaction/TransactionImpl.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/atomictransaction/TransactionImpl.java
Mon Nov 21 08:44:53 2011
@@ -28,8 +28,8 @@ public class TransactionImpl implements 
 {
   protected WHAtomicKeyValueStore underlyingStore;
   
-  protected Map<WHKey,WHValue> checkData = new HashMap<WHKey,WHValue>();
-  protected Map<WHKey,WHValue> localData = null;
+  protected KeyMap checkData = new KeyMap();
+  protected KeyMap localData = null;
 
   /** Constructor */
   public TransactionImpl(WHAtomicKeyValueStore underlyingStore)
@@ -42,7 +42,7 @@ public class TransactionImpl implements 
     throws WHException
   {
     if (localData == null)
-      localData = new HashMap<WHKey,WHValue>();
+      localData = new KeyMap();
     localData.put(key,value);
   }
 
@@ -77,4 +77,83 @@ public class TransactionImpl implements 
   {
     underlyingStore.setAll(checkData,localData);
   }
+  
+  /** Abandon this transaction.
+  * This is called as a nicety to free any resources associated with the
+  * transaction.  The implementation should also be robust as far as
+  * freeing resources if this method is NOT called, but might perform
+  * the necessary logic in a finalizer at an arbitrary time.
+  */
+  public void abandon()
+  {
+    // Does nothing so long as the entire temporary transaction is in
+    // memory.
+  }
+
+  /** Local implementation of WHKey/WHValue map */
+  protected static class KeyMap implements WHKeyMap
+  {
+    protected Map<WHKey,WHValue> map = new HashMap<WHKey,WHValue>();
+    
+    public KeyMap()
+    {
+    }
+    
+    /** Get a value from the map.
+    */
+    public WHValue get(WHKey key)
+      throws WHException
+    {
+      return map.get(key);
+    }
+    
+    /** Iterate over the keys in the map.
+    */
+    public WHKeyIterator iterator()
+      throws WHException
+    {
+      return new KeyIterator(map.keySet().iterator());
+    }
+    
+    /** Check if the map contains the specified key.
+    */
+    public boolean containsKey(WHKey key)
+    {
+      return map.containsKey(key);
+    }
+
+    /** Put a value.
+    */
+    public void put(WHKey key, WHValue value)
+    {
+      map.put(key,value);
+    }
+  }
+  
+  /** Key iterator for KeyMap */
+  protected static class KeyIterator implements WHKeyIterator
+  {
+    protected Iterator<WHKey> iterator;
+    
+    public KeyIterator(Iterator<WHKey> iterator)
+    {
+      this.iterator = iterator;
+    }
+    
+    /** Check if there is another value */
+    public boolean hasNext()
+      throws WHException
+    {
+      return iterator.hasNext();
+    }
+    
+    /** Get the next value */
+    public WHKey next()
+      throws WHException
+    {
+      return iterator.next();
+    }
+
+  }
+  
 }

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAtomicKeyValueStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAtomicKeyValueStore.java?rev=1204399&r1=1204398&r2=1204399&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAtomicKeyValueStore.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAtomicKeyValueStore.java
Mon Nov 21 08:44:53 2011
@@ -34,7 +34,7 @@ public interface WHAtomicKeyValueStore
   *@param checkValues is a map of keys/values that must be unchanged.  If any value is
   * changed, a WHDeadlockException is thrown.
   */
-  public void check(Map<WHKey,WHValue> checkValues)
+  public void check(WHKeyMap checkValues)
     throws WHException;
   
   /** Set a bunch of values atomically.
@@ -44,6 +44,6 @@ public interface WHAtomicKeyValueStore
   *@param setValues is a map of keys to set to specified new values.  A null value implies
removal of
   * the key.
   */
-  public void setAll(Map<WHKey,WHValue> checkValues, Map<WHKey,WHValue> setValues)
+  public void setAll(WHKeyMap checkValues, WHKeyMap setValues)
     throws WHException;
 }

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyIterator.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyIterator.java?rev=1204399&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyIterator.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyIterator.java
Mon Nov 21 08:44:53 2011
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.interfaces;
+
+/** This interface describes an iterator over a set of WHKeys.  WHException
+* is possible on every iterator step.
+*/
+public interface WHKeyIterator
+{
+  /** Check if there is another value */
+  public boolean hasNext()
+    throws WHException;
+  
+  /** Get the next value */
+  public WHKey next()
+    throws WHException;
+}
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyIterator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java?rev=1204399&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java
Mon Nov 21 08:44:53 2011
@@ -0,0 +1,38 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.interfaces;
+
+import java.util.*;
+
+/** This interface describes a set of key/value pairs that is maintained locally.
+*/
+public interface WHKeyMap
+{
+  /** Get a value from the map.
+  */
+  public WHValue get(WHKey key)
+    throws WHException;
+  
+  /** Iterate over the keys in the map.
+  */
+  public WHKeyIterator iterator()
+    throws WHException;
+}
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHKeyMap.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTransaction.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTransaction.java?rev=1204399&r1=1204398&r2=1204399&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTransaction.java
(original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTransaction.java
Mon Nov 21 08:44:53 2011
@@ -41,4 +41,13 @@ public interface WHTransaction
   * a WHDeadlockException will be thrown. */
   public void commit()
     throws WHException;
+  
+  /** Abandon this transaction.
+  * This is called as a nicety to free any resources associated with the
+  * transaction.  The implementation should also be robust as far as
+  * freeing resources if this method is NOT called, but might perform
+  * the necessary logic in a finalizer at an arbitrary time.
+  */
+  public void abandon();
+  
 }

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=1204399&r1=1204398&r2=1204399&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
Mon Nov 21 08:44:53 2011
@@ -77,6 +77,8 @@ public class TableStore implements WHTab
   {
     if (currentTransaction == null)
       throw new WHException("No transaction to abandon");
+    // As a nicety, tell the transaction we're done.
+    currentTransaction.abandon();
     currentTransaction = null;
     tables = null;
     indexes = null;



Mime
View raw message