directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1208331 - in /directory/apacheds/branches/apacheds-txns/jdbm/src: main/java/jdbm/btree/ main/java/jdbm/helper/ main/java/jdbm/recman/ test/java/jdbm/btree/ test/java/jdbm/helper/
Date Wed, 30 Nov 2011 08:53:48 GMT
Author: saya
Date: Wed Nov 30 08:53:46 2011
New Revision: 1208331

URL: http://svn.apache.org/viewvc?rev=1208331&view=rev
Log:
With txn layer changes, when entries are being modified, they are firt cloned. So entries
cached at jdbm layer will not be modified directly. So it is not necessary to do deep copy
at jdbm layer anymore.

Modified:
    directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BPage.java
    directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BTree.java
    directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/helper/LRUCache.java
    directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java
    directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/btree/TestSnapshotBTree.java
    directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/helper/TestVersionedCache.java

Modified: directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BPage.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BPage.java?rev=1208331&r1=1208330&r2=1208331&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BPage.java (original)
+++ directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BPage.java Wed
Nov 30 08:53:46 2011
@@ -168,7 +168,7 @@ public class BPage<K, V> implements Seri
         keys[btree.pageSize - 1] = null; // I am the root BPage for now
 
         values = (V[])new Object[btree.pageSize];
-        values[btree.pageSize - 2] = btree.copyValue( value );
+        values[btree.pageSize - 2] = value;
         values[btree.pageSize - 1] = null; // I am the root BPage for now
 
         recordId = btree.recordManager.insert( this, this );
@@ -405,7 +405,7 @@ public class BPage<K, V> implements Seri
                 
                 if ( replace )
                 {
-                    pageNewCopy.values[index] = btree.copyValue( value );
+                    pageNewCopy.values[index] = value;
                     btree.recordManager.update( recordId, pageNewCopy, this );
                 }
                 
@@ -916,7 +916,7 @@ public class BPage<K, V> implements Seri
         System.arraycopy( values, start, values, start - 1, count );
         page.first -= 1;
         keys[index] = key;
-        values[index] = btree.copyValue( value );
+        values[index] = value;
     }
 
 
@@ -963,7 +963,7 @@ public class BPage<K, V> implements Seri
     private void setEntry( BPage<K, V> page, int index, K key, V value ) throws IOException
     {
         page.keys[index] = key;
-        page.values[index] = btree.copyValue( value );
+        page.values[index] = value;
     }
 
 
@@ -1485,7 +1485,7 @@ public class BPage<K, V> implements Seri
                 }
     
                 tuple.setKey( page.keys[index] );
-                tuple.setValue( btree.copyValue( page.values[index] ) );
+                tuple.setValue( page.values[index] );
                 index++;
             }
             catch( IOException e )
@@ -1528,7 +1528,7 @@ public class BPage<K, V> implements Seri
     
                 index--;
                 tuple.setKey( page.keys[index] );
-                tuple.setValue( btree.copyValue( page.values[index] ) );
+                tuple.setValue( page.values[index] );
             }
             catch( IOException e )
             {

Modified: directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BTree.java?rev=1208331&r1=1208330&r2=1208331&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BTree.java (original)
+++ directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/btree/BTree.java Wed
Nov 30 08:53:46 2011
@@ -293,7 +293,9 @@ public class BTree<K, V> implements Exte
             btree.recordManager = recman;
             btree.bpageSerializer = new BPage<K, V>();
             btree.bpageSerializer.btree = btree;
-            btree.updateMetaRoot( btree.rootId, btree.bTreeHeight );
+            
+            btree.metaRoot.rootID = btree.rootId;
+            btree.metaRoot.treeHeight = btree.bTreeHeight;
 
         }
         catch ( IOException e )
@@ -560,7 +562,7 @@ public class BTree<K, V> implements Exte
                 }
                 else
                 {
-                   return this.copyValue( tuple.getValue() );
+                   return tuple.getValue();
                 }
             }
             else
@@ -617,7 +619,7 @@ public class BTree<K, V> implements Exte
             
             if ( browser.getNext( tuple ) )
             {
-                tuple.setValue( this.copyValue( tuple.getValue() ) );
+                tuple.setValue( tuple.getValue() );
                 return tuple;
             }
             else
@@ -792,7 +794,16 @@ public class BTree<K, V> implements Exte
     {
         if ( isActionCapable )
         { 
-            return ( MetaRoot )recordManager.fetch( -this.recordId );
+            MetaRoot readRoot =  ( MetaRoot )recordManager.fetch( -this.recordId );
+            
+            if ( readRoot != null )
+            {
+                return readRoot;
+            }
+            else
+            {
+                return metaRoot;
+            }
         }
         else
         {
@@ -943,73 +954,6 @@ public class BTree<K, V> implements Exte
     }
     
     
-    V copyValue( V value) throws IOException 
-    {
-        byte[] array;
-        V valueCopy = null;
-        
-        
-        if ( value == null )
-        {
-            return null;
-        }
-        
-        if ( this.valueSerializer != null )
-        {
-            array = this.valueSerializer.serialize( value );
-            valueCopy = (V) this.valueSerializer.deserialize( array );
-        }
-        else
-        {
-            ObjectOutputStream out = null;
-            ObjectInputStream in = null;
-            ByteArrayOutputStream bout = null;
-            ByteArrayInputStream bin = null;
-
-            try
-            {
-                bout = new ByteArrayOutputStream();
-                out = new ObjectOutputStream( bout );
-                out.writeObject( value );
-                out.flush();
-                byte[]  arr = bout.toByteArray();
-                bin = new ByteArrayInputStream( arr );
-                in = new ObjectInputStream( bin );
-                valueCopy = ( V )in.readObject();
-            }
-            catch ( ClassNotFoundException e )
-            {
-                throw new WrappedRuntimeException( e );
-            }
-            finally
-            {
-                if ( bout != null )
-                {
-                    bout.close();
-                }
-
-                if ( out != null )
-                {
-                    out.close();
-                }
-
-                if ( bin != null )
-                {
-                    bin.close();
-                }
-
-                if ( in != null )
-                {
-                    in.close();
-                }
-            }
-
-        }
-        
-        return valueCopy;
-    }
-    
-    
     public String toString()
     {
         StringBuilder sb = new StringBuilder();

Modified: directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/helper/LRUCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/helper/LRUCache.java?rev=1208331&r1=1208330&r2=1208331&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/helper/LRUCache.java
(original)
+++ directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/helper/LRUCache.java
Wed Nov 30 08:53:46 2011
@@ -357,10 +357,11 @@ public class LRUCache<K, V>
      * @param key the identifier for the entry
      * @param version version the caller want to read
      * @param serializer used in case of IO
+     * @param neverReplace true if entry is never synced to disk( entry wont be read from
disk if not found in memory )
      * @return value read
      * @throws IOException
      */
-    public V get( K key, long version, Serializer serializer ) throws IOException
+    public V get( K key, long version, Serializer serializer, boolean neverReplace ) throws
IOException
     {
         int hashValue = hash(key);
         int hashIndex = ( hashValue & ( numBuckets - 1 ) );
@@ -408,13 +409,18 @@ public class LRUCache<K, V>
                     case ENTRY_READY: // should be the common case
                         if ( !entry.isCurrentVersion() )
                         {
-                            value = this.searchChainForVersion( entry, version );
+                            value = this.searchChainForVersion( entry, version, neverReplace
);
                             
                             if ( value != null )
                             {
                                 break;
                             }
                             
+                            if ( neverReplace )
+                            {
+                                break;
+                            }
+                            
                             this.cacheMisses++;
                             
                             if ( entry.isNeverReplace() == true )
@@ -448,7 +454,7 @@ public class LRUCache<K, V>
                         
                         // FALLTHROUGH
                     case ENTRY_WRITING:    // being written entry is always at current version
                       
-                        value = this.searchChainForVersion( entry, version );
+                        value = this.searchChainForVersion( entry, version, neverReplace
);
                         break;
                         
                     case ENTRY_READING:
@@ -457,7 +463,7 @@ public class LRUCache<K, V>
                         
                         if ( entry.getState() == EntryState.ENTRY_READY )
                         {
-                            value = this.searchChainForVersion( entry, version );
+                            value = this.searchChainForVersion( entry, version, neverReplace
);
                             break;
                         }
                         LOG.warn( "Entry with key {} is at intial state after waiting for
IO", entry.getKey() );
@@ -466,9 +472,16 @@ public class LRUCache<K, V>
                     case ENTRY_INITIAL:
                         
                         LOG.warn( "Entry with key {} is at intial while trying to read from
it", entry.getKey() );
+                        
+                        // Do not read entries which are not supposed to exist on disk
+                        if ( neverReplace )
+                        {
+                            break;
+                        }
+                        
                         this.cacheMisses++;
                         this.doRead( entry, latches[latchIndex], serializer );
-                        value = this.searchChainForVersion( entry, version );
+                        value = this.searchChainForVersion( entry, version, neverReplace
);
                         break;
 
                     default:
@@ -481,7 +494,7 @@ public class LRUCache<K, V>
                 entry = this.findNewEntry( key, latchIndex );
                 buckets[hashIndex].add( entry );
                 this.doRead( entry, latches[latchIndex], serializer );
-                value = this.searchChainForVersion( entry, version );
+                value = this.searchChainForVersion( entry, version, neverReplace );
             }
         }
         catch ( CacheEvictionException e)
@@ -639,7 +652,7 @@ public class LRUCache<K, V>
      * @param version version the caller wants to read at
      * @return value found.
      */
-    private V searchChainForVersion( CacheEntry head, long version )
+    private V searchChainForVersion( CacheEntry head, long version, boolean neverReplace
)
     {
         ExplicitList.Link<CacheEntry> curLink = head.getVersionsLink();
         CacheEntry curEntry;
@@ -648,7 +661,7 @@ public class LRUCache<K, V>
         
         V value = null;
         
-        if ( head.getState() !=  EntryState.ENTRY_READY || !head.isCurrentVersion() )
+        if ( head.getState() !=  EntryState.ENTRY_READY || !head.isCurrentVersion() || neverReplace
)
         {
             mustFind = false;
         }

Modified: directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java?rev=1208331&r1=1208330&r2=1208331&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java
(original)
+++ directory/apacheds/branches/apacheds-txns/jdbm/src/main/java/jdbm/recman/SnapshotRecordManager.java
Wed Nov 30 08:53:46 2011
@@ -470,7 +470,7 @@ public class SnapshotRecordManager imple
         try 
         {
            obj = versionedCache.get( Long.valueOf( recid ), actionContext.getVersion().getVersion(),
-               serializer );
+               serializer, recid < 0 );
         } 
         catch ( IOException e )
         {

Modified: directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/btree/TestSnapshotBTree.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/btree/TestSnapshotBTree.java?rev=1208331&r1=1208330&r2=1208331&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/btree/TestSnapshotBTree.java
(original)
+++ directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/btree/TestSnapshotBTree.java
Wed Nov 30 08:53:46 2011
@@ -158,7 +158,7 @@ public class TestSnapshotBTree
                 {
                     Thread.sleep( 1 );
                 }
-
+                
                 assertTrue( tuple.getValue().value != -1 );
             }
 
@@ -195,12 +195,12 @@ public class TestSnapshotBTree
             
             Integer key = new Integer( 1023 );
             IntWrapper value = btree.find( key );
-            value.value = -1;
+            value = new IntWrapper( -1 );
             btree.insert( key, value, true );
             
-            key = new Integer(512);
+            key = new Integer(46);
             value = btree.find( key );
-            value.value = -1;
+            value = new IntWrapper( -1 );
             
             btree.insert( key, value , true );
             for ( idx = 1024; idx < 2048; idx++ )
@@ -210,7 +210,7 @@ public class TestSnapshotBTree
 
             key = new Integer(1);
             value = btree.find( key );
-            value.value = -1;
+            value = new IntWrapper( -1 );
             
             btree.insert( key, value , true );
             btree.insert( new Integer(1024), new IntWrapper( -1 ), true );
@@ -380,7 +380,7 @@ public class TestSnapshotBTree
                 {
                     Integer key = new Integer( 0 );
                     IntWrapper value = btree.find( key );
-                    value.value = idx;
+                    value = new IntWrapper( idx );
                     btree.insert( key, value, true );
                     
                     for ( int updates = 0; updates < 2048; updates++ )
@@ -390,7 +390,7 @@ public class TestSnapshotBTree
                         
                         assertTrue( value.value <= idx );
                         
-                        value.value = idx;
+                        value = new IntWrapper( idx );
                         btree.insert( key, value, true );
                     }
                 }

Modified: directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/helper/TestVersionedCache.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/helper/TestVersionedCache.java?rev=1208331&r1=1208330&r2=1208331&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/helper/TestVersionedCache.java
(original)
+++ directory/apacheds/branches/apacheds-txns/jdbm/src/test/java/jdbm/helper/TestVersionedCache.java
Wed Nov 30 08:53:46 2011
@@ -60,10 +60,10 @@ public class TestVersionedCache
         
         LRUCache<Integer, Integer> cache = new LRUCache<Integer, Integer>( arrayIO,
numEntries );
         
-        Integer val = cache.get( new Integer ( 5 ), 0, null );
+        Integer val = cache.get( new Integer ( 5 ), 0, null, false );
         assertEquals( val.intValue(), 1 );
         
-        val = cache.get( new Integer ( 20 ), 0, null );
+        val = cache.get( new Integer ( 20 ), 0, null, false );
         assertEquals( val.intValue(), 1 );
         
         cache.put( new Integer(1), 2, 1, null, false );
@@ -73,7 +73,7 @@ public class TestVersionedCache
         int sum = 0;
         for ( idx = 0; idx < numEntries; idx++ )
         {
-            sum += cache.get( new Integer( idx ), 0, null ).intValue();
+            sum += cache.get( new Integer( idx ), 0, null, false ).intValue();
         }
         
         assertEquals( sum, numEntries );
@@ -82,7 +82,7 @@ public class TestVersionedCache
         cache.advanceMinReadVersion( 1 );
         for ( idx = 0; idx < numEntries; idx++ )
         {
-            sum += cache.get( new Integer( idx ), 1, null ).intValue();
+            sum += cache.get( new Integer( idx ), 1, null, false ).intValue();
         }
         
         System.out.println( "Sum is: "+ sum);
@@ -136,7 +136,7 @@ public class TestVersionedCache
         cache.advanceMinReadVersion( 2 );        
         for ( idx = 0; idx < intsArray.length; idx++ )
         {
-            sum += cache.get( new Integer( idx ), 2, null ).intValue();
+            sum += cache.get( new Integer( idx ), 2, null, false ).intValue();
         }
         
         assertEquals( sum, expectedSum );
@@ -223,7 +223,7 @@ public class TestVersionedCache
                
                 for ( idx = 0; idx < intsArray.length; idx++ )
                 {
-                    sum += cache.get( new Integer( idx ), 0, null ).intValue();
+                    sum += cache.get( new Integer( idx ), 0, null, false ).intValue();
                 }
                 
                 assertEquals( sum, intsArray.length );
@@ -246,7 +246,7 @@ public class TestVersionedCache
                 
                 for ( idx = 0; idx < intsArray.length; idx++ )
                 {
-                    sum += cache.get( new Integer( idx ), 2, null ).intValue();
+                    sum += cache.get( new Integer( idx ), 2, null, false ).intValue();
                 }
                 
                 assertEquals( sum, expectedSum );



Mime
View raw message