directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1446554 - in /directory/jdbm/trunk/jdbm2/src/main/java/jdbm: helper/LRUCache.java recman/BaseRecordManager.java
Date Fri, 15 Feb 2013 12:33:56 GMT
Author: elecharny
Date: Fri Feb 15 12:33:56 2013
New Revision: 1446554

URL: http://svn.apache.org/r1446554
Log:
o Fixed the Logger problem (removed the XXX.class.getSimpleName()) (See DIRSERVER-1804)

Modified:
    directory/jdbm/trunk/jdbm2/src/main/java/jdbm/helper/LRUCache.java
    directory/jdbm/trunk/jdbm2/src/main/java/jdbm/recman/BaseRecordManager.java

Modified: directory/jdbm/trunk/jdbm2/src/main/java/jdbm/helper/LRUCache.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm2/src/main/java/jdbm/helper/LRUCache.java?rev=1446554&r1=1446553&r2=1446554&view=diff
==============================================================================
--- directory/jdbm/trunk/jdbm2/src/main/java/jdbm/helper/LRUCache.java (original)
+++ directory/jdbm/trunk/jdbm2/src/main/java/jdbm/helper/LRUCache.java Fri Feb 15 12:33:56 2013
@@ -1,22 +1,22 @@
-    /*
- *  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. 
- *  
- */
+/*
+*  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 jdbm.helper;
 
 
@@ -53,114 +53,115 @@ import org.slf4j.LoggerFactory;
 public class LRUCache<K, V>
 {
     /** A logger for this class */
-    private static final Logger LOG = LoggerFactory.getLogger( LRUCache.class.getSimpleName() );
-       
+    private static final Logger LOG = LoggerFactory.getLogger( LRUCache.class );
+
     /** Array of hash buckets */
     private List<CacheEntry> buckets[];
-    
+
     /** Array of latches protecting buckets */
     private Lock latches[];
 
     /** Power of two number of buckets */
     private final int numBuckets;
-    
+
     /** Log of number of hash buckets each latch protects */
     private final static int LOG_BUCKET_PER_LATCH = 0;
-    
+
     /** Number of lrus */
     private final static int NUM_LRUS = 16;
-    
+
     /** Min number of entries */
     private final static int MIN_ENTRIES = 1 << 10;
-    
+
     /** Max sleep time(in ms) for writes in case of cache eviction failure */
     private final static long MAX_WRITE_SLEEP_TIME = 600000;
-    
+
     /** lru list */
     LRU lrus[];
-    
+
     /** Random number generator used for randomizing access to LRUS */
     Random lruRandomizer = new Random();
-    
+
     /** current number of cache entries */
     private AtomicInteger numEntries;
-    
+
     /** maximum number of entries */
     private final int maxEntries;
 
     /** Callback used to initialize entries not in cache */
     private final EntryIO<K, V> entryIO;
-   
+
     /** minimum version cache has to satisfy during reads */
     private long minReadVersion;
-    
+
     /** Stats to keep track of cache gets */
     private long cacheGets;
-    
+
     /** Stats to keep track of cache hits for cache gets */
     private long cacheMisses;
-    
+
     /** Stats to keep track of cache puts */
     private long cachePuts;
-    
+
     /** Stats to keep track of # of times writes sleep for free cache entry */
     private long cachePutSleeps;
-    
-    @SuppressWarnings("unchecked") 
+
+
+    @SuppressWarnings("unchecked")
     public LRUCache( EntryIO<K, V> entryIO, int cacheSize )
     {
         int idx;
-        this.entryIO =entryIO;
-        
+        this.entryIO = entryIO;
+
         if ( cacheSize < MIN_ENTRIES )
         {
             cacheSize = MIN_ENTRIES;
         }
-        
+
         maxEntries = cacheSize;
-        
+
         int numHashBuckets = MIN_ENTRIES;
-        
+
         while ( numHashBuckets < maxEntries )
         {
-            numHashBuckets  = numHashBuckets << 1;
+            numHashBuckets = numHashBuckets << 1;
         }
-        
-        if ( numHashBuckets >  maxEntries)
+
+        if ( numHashBuckets > maxEntries )
         {
             numBuckets = numHashBuckets >> 1;
         }
         else
         {
-            numBuckets  = numHashBuckets;
+            numBuckets = numHashBuckets;
+        }
+
+        buckets = new LinkedList[numBuckets];
+
+        for ( idx = 0; idx < numBuckets; idx++ )
+        {
+            buckets[idx] = new LinkedList<CacheEntry>();
+        }
+
+        int numLatches = numBuckets >> LOG_BUCKET_PER_LATCH;
+        latches = new Lock[numLatches];
+
+        for ( idx = 0; idx < numLatches; idx++ )
+        {
+            latches[idx] = new ReentrantLock();
+        }
+
+        lrus = new LRUCache.LRU[NUM_LRUS];
+
+        for ( idx = 0; idx < NUM_LRUS; idx++ )
+        {
+            lrus[idx] = new LRU();
         }
-        
-       buckets = ( List<CacheEntry>[] )new LinkedList[numBuckets];
-       
-       for ( idx = 0; idx < numBuckets; idx++ ) 
-       {
-           buckets[idx] = new LinkedList<CacheEntry>(); 
-       }
-        
-       int numLatches = numBuckets >> LOG_BUCKET_PER_LATCH;
-       latches = new Lock[numLatches];
-       
-       for ( idx = 0; idx < numLatches; idx++ )
-       {
-           latches[idx] = new ReentrantLock(); 
-       }
-       
-       lrus = ( LRUCache.LRU[] ) new LRUCache.LRU[NUM_LRUS];
-       
-       for ( idx = 0; idx < NUM_LRUS; idx++ )
-       {
-           lrus[idx] = new LRU(); 
-       }
-       
-       numEntries = new AtomicInteger( 0 );
+
+        numEntries = new AtomicInteger( 0 );
     }
-    
-    
+
+
     /**
      * Called as the minimum version that readers will use advances. This lets
      * cache get rid of the older versions of entries.
@@ -171,8 +172,8 @@ public class LRUCache<K, V>
     {
         minReadVersion = minVersion;
     }
-    
-    
+
+
     /**
      * Updates the entry identified with the key with the new value.
      *   
@@ -183,15 +184,15 @@ public class LRUCache<K, V>
      * @param neverReplace true if caller wants to always keep the entry in cache 
      * @throws IOException, CacheEvictionException
      */
-    public void put( K key, V value, long newVersion , Serializer serializer, 
+    public void put( K key, V value, long newVersion, Serializer serializer,
         boolean neverReplace ) throws IOException, CacheEvictionException
     {
-        int hashValue = hash(key);
+        int hashValue = hash( key );
         int hashIndex = ( hashValue & ( numBuckets - 1 ) );
         int latchIndex = ( hashIndex >> LOG_BUCKET_PER_LATCH );
-        long sleepInterval = 100; 
+        long sleepInterval = 100;
         long totalSleepTime = 0;
-        
+
         /*
          * Lock the hash bucket and find the current version of the entry: 
          * 1) If entry exists
@@ -205,29 +206,29 @@ public class LRUCache<K, V>
          * 
          * While reading or waiting, latch is released.
          */
-        
+
         this.cachePuts++;
-        
+
         while ( true )
         {
             latches[latchIndex].lock();
             boolean entryExists = false;
             boolean sleepForFreeEntry = false;
-            
+
             Iterator<CacheEntry> it = buckets[hashIndex].listIterator();
             CacheEntry entry = null;
-            
-            while (it.hasNext() )
+
+            while ( it.hasNext() )
             {
                 entry = it.next();
-                
+
                 if ( entry.getKey().equals( key ) )
                 {
                     entryExists = true;
                     break;
                 }
             }
-    
+
             try
             {
                 if ( entryExists )
@@ -235,17 +236,18 @@ public class LRUCache<K, V>
                     switch ( entry.getState() )
                     {
                         case ENTRY_READY: // should be the common case
-                            
+
                             if ( !entry.isCurrentVersion() )
                             {
                                 if ( entry.isNeverReplace() == true )
                                 {
-                                    throw new IllegalStateException( " Non current entry should not have neverReplace set " + entry );
+                                    throw new IllegalStateException(
+                                        " Non current entry should not have neverReplace set " + entry );
                                 }
-                                                            
+
                                 entry.setNeverReplace();
                                 CacheEntry newEntry = null;
-                                
+
                                 try
                                 {
                                     newEntry = this.findNewEntry( key, hashIndex >> LOG_BUCKET_PER_LATCH );
@@ -254,7 +256,7 @@ public class LRUCache<K, V>
                                 {
                                     entry.clearNeverReplace();
                                 }
-                                
+
                                 /*
                                  * Remove existing entry, chain as a snapshot
                                  * entry to the new entry and add newentry to the
@@ -266,37 +268,37 @@ public class LRUCache<K, V>
                                 entry = newEntry;
                                 this.doRead( entry, latches[latchIndex], serializer );
                             }
-                            
-                            this.putNewVersion( entry, key, value, newVersion, hashIndex, 
-                                latches[latchIndex], serializer, neverReplace );                       
+
+                            this.putNewVersion( entry, key, value, newVersion, hashIndex,
+                                latches[latchIndex], serializer, neverReplace );
                             break;
-                            
+
                         case ENTRY_READING:
                             // Somebody is reading our entry, wait until the read is done and then retry
                             this.doWaitForStateChange( entry, latches[latchIndex] );
-                            
+
                             if ( entry.getState() == EntryState.ENTRY_READY )
                             {
-                                this.putNewVersion( entry, key, value, newVersion, hashIndex, latches[latchIndex], 
+                                this.putNewVersion( entry, key, value, newVersion, hashIndex, latches[latchIndex],
                                     serializer, neverReplace );
                                 break;
                             }
-                            
+
                             LOG.warn( "Entry with key {} is at intial state after waiting for IO", entry.getKey() );
                             // FALLTHROUGH
-                            
+
                         case ENTRY_INITIAL:
                             LOG.warn( "Entry with key {} is at intial while trying to read from it", entry.getKey() );
                             this.doRead( entry, latches[latchIndex], serializer );
-                            this.putNewVersion( entry, key, value, newVersion, hashIndex, latches[latchIndex], 
+                            this.putNewVersion( entry, key, value, newVersion, hashIndex, latches[latchIndex],
                                 serializer, neverReplace );
                             break;
-                            
+
                         case ENTRY_WRITING:
                             // FALLTHROUGH
-                            
+
                         default:
-                            throw new IllegalStateException( "Unknown cache entry state: " + entry ) ;
+                            throw new IllegalStateException( "Unknown cache entry state: " + entry );
                     }
                 }
                 else
@@ -304,17 +306,17 @@ public class LRUCache<K, V>
                     entry = this.findNewEntry( key, latchIndex );
                     buckets[hashIndex].add( entry );
                     this.doRead( entry, latches[latchIndex], serializer );
-                    this.putNewVersion( entry, key, value, newVersion, hashIndex, latches[latchIndex], 
+                    this.putNewVersion( entry, key, value, newVersion, hashIndex, latches[latchIndex],
                         serializer, neverReplace );
-                }            
+                }
             }
             catch ( CacheEvictionException e )
             {
                 sleepForFreeEntry = totalSleepTime < this.MAX_WRITE_SLEEP_TIME;
-                
+
                 if ( sleepForFreeEntry == false )
                 {
-                    System.out.println(" NO cache entry for write " + totalSleepTime );
+                    System.out.println( " NO cache entry for write " + totalSleepTime );
                     throw e;
                 }
             }
@@ -322,7 +324,7 @@ public class LRUCache<K, V>
             {
                 latches[latchIndex].unlock();
             }
-            
+
             if ( sleepForFreeEntry )
             {
                 try
@@ -334,7 +336,7 @@ public class LRUCache<K, V>
                     // Restore interrupted stat
                     Thread.currentThread().interrupt();
                 }
-                
+
                 totalSleepTime += sleepInterval;
             }
             else
@@ -342,14 +344,13 @@ public class LRUCache<K, V>
                 break;
             }
         }
-        
+
         if ( totalSleepTime != 0 )
-        {  
+        {
             this.cachePutSleeps++;
         }
     }
-    
-    
+
 
     /**
      * Finds and returns the entry corresponding to the given key and version.
@@ -363,11 +364,11 @@ public class LRUCache<K, V>
      */
     public V get( K key, long version, Serializer serializer, boolean neverReplace ) throws IOException
     {
-        int hashValue = hash(key);
+        int hashValue = hash( key );
         int hashIndex = ( hashValue & ( numBuckets - 1 ) );
         int latchIndex = ( hashIndex >> LOG_BUCKET_PER_LATCH );
         V value = null;
-        
+
         /*
          * 1) If entry exists
          *   1.1) if the version chain contains the desired version, then return it, otherwise read
@@ -380,19 +381,19 @@ public class LRUCache<K, V>
          * 
          * While reading or waiting, latch is released.
          */
-        
+
         this.cacheGets++;
-        
+
         latches[latchIndex].lock();
         boolean chainExists = false;
-        
+
         Iterator<CacheEntry> it = buckets[hashIndex].listIterator();
         CacheEntry entry = null;
-        
+
         while ( it.hasNext() )
         {
             entry = it.next();
-            
+
             if ( entry.getKey().equals( key ) )
             {
                 chainExists = true;
@@ -410,27 +411,28 @@ public class LRUCache<K, V>
                         if ( !entry.isCurrentVersion() )
                         {
                             value = this.searchChainForVersion( entry, version, neverReplace );
-                            
+
                             if ( value != null )
                             {
                                 break;
                             }
-                            
+
                             if ( neverReplace )
                             {
                                 break;
                             }
-                            
+
                             this.cacheMisses++;
-                            
+
                             if ( entry.isNeverReplace() == true )
                             {
-                                throw new IllegalStateException( "Non Current Entry has neverReplace set to true:" + entry );
+                                throw new IllegalStateException( "Non Current Entry has neverReplace set to true:"
+                                    + entry );
                             }
-                            
+
                             entry.setNeverReplace();
                             CacheEntry newEntry = null;
-                            
+
                             try
                             {
                                 newEntry = this.findNewEntry( key, hashIndex >> LOG_BUCKET_PER_LATCH );
@@ -439,7 +441,7 @@ public class LRUCache<K, V>
                             {
                                 entry.clearNeverReplace();
                             }
-    
+
                             /*
                              * Remove existing entry, chain as a snapshot
                              * entry to the new entry and add newentry to the
@@ -451,16 +453,16 @@ public class LRUCache<K, V>
                             entry = newEntry;
                             this.doRead( entry, latches[latchIndex], serializer );
                         }
-                        
+
                         // FALLTHROUGH
-                    case ENTRY_WRITING:    // being written entry is always at current version                        
+                    case ENTRY_WRITING: // being written entry is always at current version                        
                         value = this.searchChainForVersion( entry, version, neverReplace );
                         break;
-                        
+
                     case ENTRY_READING:
                         // Somebody is reading our entry, wait until the read is done and then retry
                         this.doWaitForStateChange( entry, latches[latchIndex] );
-                        
+
                         if ( entry.getState() == EntryState.ENTRY_READY )
                         {
                             value = this.searchChainForVersion( entry, version, neverReplace );
@@ -468,17 +470,17 @@ public class LRUCache<K, V>
                         }
                         LOG.warn( "Entry with key {} is at intial state after waiting for IO", entry.getKey() );
                         // FALLTHROUGH
-                        
+
                     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, neverReplace );
@@ -497,7 +499,7 @@ public class LRUCache<K, V>
                 value = this.searchChainForVersion( entry, version, neverReplace );
             }
         }
-        catch ( CacheEvictionException e)
+        catch ( CacheEvictionException e )
         {
             /*
              * In this case read while holding the hash bucket lock. Entry
@@ -510,10 +512,11 @@ public class LRUCache<K, V>
         {
             latches[latchIndex].unlock();
         }
-        
+
         return value;
     }
-    
+
+
     @Override
     public String toString()
     {
@@ -526,10 +529,11 @@ public class LRUCache<K, V>
         sb.append( ",cachePuts:" ).append( this.cachePuts );
         sb.append( ",cachePutSleeps:" ).append( this.cachePutSleeps );
         sb.append( ")\n" );
-        
+
         return sb.toString();
     }
-     
+
+
     /**
      * Creates a new version of the given entry with the given new version.
      *
@@ -543,23 +547,23 @@ public class LRUCache<K, V>
      * @param neverReplace true if most recent version of entry should be kept in memory all the time
      * @throws IOException
      */
-    private void putNewVersion( CacheEntry entry, K key, V value, long newVersion, int hashIndex, 
+    private void putNewVersion( CacheEntry entry, K key, V value, long newVersion, int hashIndex,
         Lock latch, Serializer serializer, boolean neverReplace ) throws IOException, CacheEvictionException
     {
-        
-        if ( entry.getStartVersion() != newVersion  )
+
+        if ( entry.getStartVersion() != newVersion )
         {
-            
+
             boolean resetNeverReplace = true;
-            
+
             if ( entry.isNeverReplace() )
-            {  
+            {
                 resetNeverReplace = false;
             }
-            
+
             entry.setNeverReplace();
             CacheEntry newEntry = null;
-            
+
             try
             {
                 newEntry = this.findNewEntry( key, hashIndex >> LOG_BUCKET_PER_LATCH );
@@ -571,7 +575,7 @@ public class LRUCache<K, V>
                     entry.clearNeverReplace();
                 }
             }
-            
+
             // Set to new version 
             newEntry.setAsCurrentVersion( value, newVersion );
 
@@ -582,45 +586,44 @@ public class LRUCache<K, V>
              */
             buckets[hashIndex].remove( entry );
             entry.setAsSnapshotVersion( newVersion );
-            newEntry.getVersionsLink().splice( entry.getVersionsLink() );  // splices entry and its chain after the newEntry
+            newEntry.getVersionsLink().splice( entry.getVersionsLink() ); // splices entry and its chain after the newEntry
             buckets[hashIndex].add( newEntry );
             entry = newEntry;
         }
         else
         {
-            if  ( entry.isCurrentVersion() == false )
+            if ( entry.isCurrentVersion() == false )
             {
                 throw new IllegalStateException( "Entry not at expected version: " + entry );
             }
-            
+
             // Entry already at current version. Just update the value
             entry.setAsCurrentVersion( value, newVersion );
         }
-        
+
         if ( neverReplace )
         {
             entry.setNeverReplace();
         }
-        
+
         entry.setState( EntryState.ENTRY_WRITING );
         latch.unlock();
-        
+
         try
         {
             entryIO.write( key, value, serializer );
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
             /*
              * Not much we can do here, just leave the entry in an
              * inconsistent state.
              */
             latch.lock();
-            
-            
+
             entry.setState( EntryState.ENTRY_INITIAL );
             entry.clearNeverReplace();
-            
+
             if ( entry.anyWaiters() )
             {
                 entry.getStateCondition( latch ).notifyAll();
@@ -632,17 +635,17 @@ public class LRUCache<K, V>
                 lru.moveToTail( entry );
                 lru.getLock().unlock();
             }
-            
+
             latch.unlock();
-            
+
             throw e;
         }
-        
+
         latch.lock();
         entry.setState( EntryState.ENTRY_READY );
     }
-    
-    
+
+
     /**
      * Searches the given version for the entry that can satisfy the read with the 
      * given version and returns the value of that entry. Cache is responsible is for
@@ -658,43 +661,43 @@ public class LRUCache<K, V>
         CacheEntry curEntry;
         boolean mustFind = true;
         long curStartVersion = 0;
-        
+
         V value = null;
-        
-        if ( head.getState() !=  EntryState.ENTRY_READY || !head.isCurrentVersion() || neverReplace )
+
+        if ( head.getState() != EntryState.ENTRY_READY || !head.isCurrentVersion() || neverReplace )
         {
             mustFind = false;
         }
-        
+
         do
         {
             curEntry = curLink.getElement();
-            
+
             if ( curEntry.getState() != EntryState.ENTRY_READY )
             {
                 if ( curEntry != head )
                 {
                     throw new IllegalStateException( "Unexpected state for entry: " + curEntry );
                 }
-    
+
                 curLink = curLink.getNext();
                 continue;
             }
-        
+
             if ( curStartVersion != 0 && ( curEntry.getEndVersion() > curStartVersion ) )
             {
-                throw new IllegalStateException( "Unexpected version number for entry. curStartVersion: " 
-                        + curStartVersion + " entry: " + curEntry );
+                throw new IllegalStateException( "Unexpected version number for entry. curStartVersion: "
+                    + curStartVersion + " entry: " + curEntry );
             }
-            
+
             curStartVersion = curEntry.getStartVersion();
-            
+
             if ( !curEntry.canReadFrom( version ) )
             {
                 curLink = curLink.getNext();
                 continue;
             }
-            
+
             // found it
             if ( curEntry.isCurrentVersion() )
             {
@@ -704,21 +707,22 @@ public class LRUCache<K, V>
                 lru.touch( curEntry );
                 lru.getLock().unlock();
             }
-            
+
             value = curEntry.getValue();
             break;
-            
-        } while ( curLink != head.getVersionsLink() );
-        
+
+        }
+        while ( curLink != head.getVersionsLink() );
+
         if ( value == null && mustFind == true )
         {
             throw new IllegalStateException( "Traversed all versions and could not find cache entry" );
         }
-        
+
         return value;
     }
-    
-    
+
+
     /**
      * Wait for the state change to happen. Usually used to wait for another 
      * thread to complete the IO.Latch covering the entry is held at the entry.
@@ -731,42 +735,43 @@ public class LRUCache<K, V>
         EntryState curState = entry.getState();
         Condition cond = entry.getStateCondition( latch );
         entry.bumpWaiters();
-        
+
         do
         {
             cond.awaitUninterruptibly();
-            
-        } while ( curState == entry.getState() );
-        
+
+        }
+        while ( curState == entry.getState() );
+
         entry.decrementWaiters();
     }
-    
-    
-   /**
-    * Does read the value for the given entry. At entry, latch is held. It is
-    * dropped during the read and regotten after a successful read. 
-    *
-    * @param entry entry for which we will do the read
-    * @param latch latch protecting the entry to which the bucket belongs
-    * @param serializer used in case of IO
-    * @throws IOException
-    */
+
+
+    /**
+     * Does read the value for the given entry. At entry, latch is held. It is
+     * dropped during the read and regotten after a successful read. 
+     *
+     * @param entry entry for which we will do the read
+     * @param latch latch protecting the entry to which the bucket belongs
+     * @param serializer used in case of IO
+     * @throws IOException
+     */
     private void doRead( CacheEntry entry, Lock latch, Serializer serializer ) throws IOException
     {
         V value = null;
         entry.setState( EntryState.ENTRY_READING );
         latch.unlock();
-        
+
         try
         {
-           value = entryIO.read( entry.getKey(), serializer ); 
+            value = entryIO.read( entry.getKey(), serializer );
         }
         catch ( IOException e )
         {
             // do cleanup and rethrow
             latch.lock();
             entry.setState( EntryState.ENTRY_INITIAL );
-            
+
             if ( entry.anyWaiters() )
             {
                 entry.getStateCondition( latch ).notifyAll();
@@ -778,18 +783,18 @@ public class LRUCache<K, V>
                 lru.moveToTail( entry );
                 lru.getLock().unlock();
             }
-            
+
             latch.unlock();
-            
+
             throw e;
         }
-        
+
         latch.lock();
-        
+
         // set the version range
         ExplicitList.Link<CacheEntry> nextLink = entry.getVersionsLink().getNext();
         long startVersion;
-        
+
         if ( entry.getVersionsLink().isUnLinked() )
         {
             startVersion = 0;
@@ -798,15 +803,16 @@ public class LRUCache<K, V>
         {
             startVersion = nextLink.getElement().getEndVersion();
         }
-        
+
         entry.setAsCurrentVersion( value, startVersion );
-        
+
         if ( entry.anyWaiters() )
         {
             entry.getStateCondition( latch ).signalAll();
         }
     }
-    
+
+
     /**
      * Finds a victim entry to be replaced by the given key. 
      * 
@@ -822,21 +828,21 @@ public class LRUCache<K, V>
         int index = lruRandomizer.nextInt( NUM_LRUS );
         int id, curIndex;
         boolean lruLocked = false;
-        
+
         // if under max entries, allocate a new one and add it to the lru with the index.. numEntries check is dirty
         if ( numEntries.get() < maxEntries )
         {
             numEntries.incrementAndGet();
-            CacheEntry newEntry  = new CacheEntry( index );
+            CacheEntry newEntry = new CacheEntry( index );
             lru = lrus[index];
             newEntry.initialize( key );
             lru.getLock().lock();
             lru.addToLRU( newEntry );
             lru.getLock().unlock();
-            
+
             return newEntry;
         }
-        
+
         /*
          * We start with a lru determined by the lru randomizer and try to lock the lru without waiting. 
          * If this doesnt work, we wait on the first lru lock. 
@@ -844,47 +850,45 @@ public class LRUCache<K, V>
         CacheEntry victimEntry = null;
         lru = null;
         curIndex = 0;
-        
+
         for ( id = 0; id < NUM_LRUS; id++ )
         {
             curIndex = ( index + id ) % NUM_LRUS;
             lru = lrus[curIndex];
-            
+
             if ( lru.getLock().tryLock() == true )
             {
                 lruLocked = true;
                 break;
             }
         }
-        
+
         if ( !lruLocked )
         {
             curIndex = index;
             lru = lrus[curIndex];
             lru.getLock().lock();
         }
-        
+
         victimEntry = lru.findVictim( latchIndex );
-        
-        
+
         if ( victimEntry != null )
-        { 
+        {
             victimEntry.initialize( key );
             lru.getLock().unlock();
         }
         else
         {
             lru.getLock().unlock();
-            
+
             LOG.warn( "Cache eviction failure: " + this.minReadVersion );
             throw new CacheEvictionException( null );
         }
-        
-        
+
         return victimEntry;
     }
-    
-   
+
+
     private int hash( K key )
     {
         int h = key.hashCode();
@@ -892,11 +896,10 @@ public class LRUCache<K, V>
         h ^= ( h >>> 14 );
         h += ( h << 4 );
         h ^= ( h >>> 10 );
-        
+
         return h;
     }
-    
-    
+
     private enum EntryState
     {
         ENTRY_INITIAL,
@@ -918,7 +921,7 @@ public class LRUCache<K, V>
 
         /** End of valid range. endVersion == Long.MAX_VALUE iff entry current version */
         private long endVersion;
-        
+
         /** hash index of the key */
         private int hashIndex;
 
@@ -933,23 +936,25 @@ public class LRUCache<K, V>
 
         /** Used to build a sorted chain of versions with the most current entry at the head */
         private ExplicitList.Link<CacheEntry> versionsLink;
-                
+
         /** Used to put on lru list */
         private ExplicitList.Link<CacheEntry> lruLink;
-        
+
         /** id of lru this cache entry lives on */
         int lruid;
-        
+
         /** true if entry should not be replaced */
         boolean neverReplace;
-        
-        public CacheEntry(int lruid)
+
+
+        public CacheEntry( int lruid )
         {
             versionsLink = new ExplicitList.Link<CacheEntry>( this );
             lruLink = new ExplicitList.Link<CacheEntry>( this );
-            this.lruid = lruid;        
+            this.lruid = lruid;
         }
 
+
         /**
          *  inits the fields..used after a cache entry is replaced 
          *
@@ -963,44 +968,46 @@ public class LRUCache<K, V>
             endVersion = Long.MAX_VALUE;
 
             stateCondition = null;
-            
+
             if ( numWaiters != 0 )
             {
                 throw new IllegalStateException( "Numwaiters is not zero when entry is newly initialized: " + this );
             }
-   
+
             state = EntryState.ENTRY_INITIAL;
 
             if ( versionsLink.isUnLinked() == false )
             {
                 throw new IllegalStateException( "Versions link is still linked when entry is initialized" );
             }
-           
-            
+
             hashIndex = hash( key ) & ( numBuckets - 1 );
-            
+
             if ( neverReplace == true )
             {
                 throw new IllegalStateException( "Neverreplace is true when entry is newly intialized:" + this );
             }
         }
 
+
         public void setNeverReplace()
         {
             neverReplace = true;
         }
-        
+
+
         public void clearNeverReplace()
         {
             neverReplace = false;
         }
-        
+
+
         public boolean isNeverReplace()
         {
             return neverReplace;
         }
-        
-        
+
+
         public K getKey()
         {
             return key;
@@ -1011,20 +1018,20 @@ public class LRUCache<K, V>
         {
             return value;
         }
-        
-        
+
+
         public int getHashIndex()
         {
             return hashIndex;
         }
-        
+
 
         public LRU getLru()
         {
             return lrus[lruid];
         }
 
-        
+
         public Condition getStateCondition( Lock lock )
         {
             if ( stateCondition == null )
@@ -1048,7 +1055,7 @@ public class LRUCache<K, V>
             {
                 throw new IllegalStateException( "Unexpected num waiters for entry:" + this );
             }
-            
+
             numWaiters--;
         }
 
@@ -1057,20 +1064,20 @@ public class LRUCache<K, V>
         {
             return numWaiters > 0;
         }
-        
+
 
         public long getEndVersion()
         {
             return endVersion;
         }
-        
-        
+
+
         public long getStartVersion()
         {
             return startVersion;
         }
-        
-        
+
+
         /**
          * Check if entry is the most recent version for its key
          * 
@@ -1105,20 +1112,20 @@ public class LRUCache<K, V>
         {
             this.state = newState;
         }
-        
+
 
         public ExplicitList.Link<CacheEntry> getVersionsLink()
         {
             return versionsLink;
         }
-        
-        
+
+
         public ExplicitList.Link<CacheEntry> getLruLink()
         {
             return lruLink;
         }
-        
-        
+
+
         public void setAsCurrentVersion( V newValue, long startVersion )
         {
             this.startVersion = startVersion;
@@ -1126,8 +1133,8 @@ public class LRUCache<K, V>
             this.value = newValue;
             this.state = EntryState.ENTRY_READY;
         }
-        
-        
+
+
         public void setAsSnapshotVersion( long newEndVersion )
         {
             this.clearNeverReplace();
@@ -1137,53 +1144,54 @@ public class LRUCache<K, V>
             lru.addToSnapshots( this );
             lru.getLock().unlock();
         }
-        
-        
+
+
         public boolean isEntryFreeable()
         {
-            return ( this.state != EntryState.ENTRY_READING && this.numWaiters == 0 && 
-                this.state != EntryState.ENTRY_WRITING && !neverReplace);
+            return ( this.state != EntryState.ENTRY_READING && this.numWaiters == 0 &&
+                this.state != EntryState.ENTRY_WRITING && !neverReplace );
         }
-        
+
+
         @Override
         public String toString()
         {
             StringBuilder sb = new StringBuilder();
             sb.append( "Entry: " );
-            sb.append("(state: ").append( this.state );
-            sb.append(",numWaiters:").append( this.numWaiters );
-            sb.append(",startVersion:").append( this.startVersion );
-            sb.append(",endVersion:").append( this.endVersion );
-            sb.append(",key:").append( this.key );
-            sb.append(",value:").append( this.value ).append( ")" );
+            sb.append( "(state: " ).append( this.state );
+            sb.append( ",numWaiters:" ).append( this.numWaiters );
+            sb.append( ",startVersion:" ).append( this.startVersion );
+            sb.append( ",endVersion:" ).append( this.endVersion );
+            sb.append( ",key:" ).append( this.key );
+            sb.append( ",value:" ).append( this.value ).append( ")" );
             sb.append( "\n" );
-            
+
             return sb.toString();
-            
+
         }
     }
-    
-        
+
     private class LRU
     {
         /** List of entries representing most recent versions */
         private ExplicitList<CacheEntry> mostRecentVersions = new ExplicitList<CacheEntry>();
-        
+
         /** List of snapshot entries */
-        private ExplicitList<CacheEntry> snapshotVersions = new ExplicitList<CacheEntry>(); 
-        
+        private ExplicitList<CacheEntry> snapshotVersions = new ExplicitList<CacheEntry>();
+
         /** Lock protecting the list */
         private Lock lock = new ReentrantLock();
-        
+
         /** Number of snaphot versions created */
         private int numSnapshotsCreated;
-        
+
+
         public Lock getLock()
         {
             return lock;
         }
-        
-        
+
+
         /**
          * add the new entry to the head of the lru
          *
@@ -1193,8 +1201,8 @@ public class LRUCache<K, V>
         {
             mostRecentVersions.addFirst( entry.getLruLink() );
         }
-        
-        
+
+
         /**
          * Removes the entry from the lru list and Adds the entry to the list of snapshot entries.
          * Entry should a most recent entry. 
@@ -1205,11 +1213,11 @@ public class LRUCache<K, V>
         {
             mostRecentVersions.remove( entry.getLruLink() );
             snapshotVersions.addLast( entry.getLruLink() );
-            
+
             numSnapshotsCreated++;
         }
-        
-        
+
+
         /**
          * Moves the entry to the cold end of the lru. Entry should be a most
          * recent entry
@@ -1221,8 +1229,8 @@ public class LRUCache<K, V>
             mostRecentVersions.remove( entry.getLruLink() );
             mostRecentVersions.addFirst( entry.getLruLink() );
         }
-        
-        
+
+
         /**
          * Increases the hotness of the given entry
          *
@@ -1234,8 +1242,8 @@ public class LRUCache<K, V>
             mostRecentVersions.remove( entry.getLruLink() );
             mostRecentVersions.addLast( entry.getLruLink() );
         }
-        
-        
+
+
         /**
          * Finds a freeable entry from the lru.  Lru lock is held at entry and exit.
          *
@@ -1247,61 +1255,61 @@ public class LRUCache<K, V>
             CacheEntry victimEntry = null;
             int victimBucketIndex;
             int victimLatchIndex;
-            
+
             /*
              * If expired snapshot entries exist, they are preferred, otherwise an entry is
              * gotten from the tail of the lru.
              */
-            
+
             ExplicitList.Link<CacheEntry> curLink;
-              
+
             curLink = snapshotVersions.begin();
-            
+
             while ( curLink != snapshotVersions.end() )
             {
                 victimEntry = curLink.getElement();
-                
+
                 if ( victimEntry.getEndVersion() > minReadVersion )
                 {
                     break;
                 }
-                      
+
                 if ( victimEntry.getKey() == null )
                 {
                     throw new IllegalStateException( "Snapshot victimEntry doesnt have key set:" + victimEntry );
                 }
-                
+
                 if ( victimEntry.isNeverReplace() )
                 {
-                    curLink = curLink.getNext();    
+                    curLink = curLink.getNext();
                     continue;
                 }
-                
+
                 victimBucketIndex = victimEntry.getHashIndex();
-                victimLatchIndex = (victimBucketIndex >> LOG_BUCKET_PER_LATCH );
-                
+                victimLatchIndex = ( victimBucketIndex >> LOG_BUCKET_PER_LATCH );
+
                 if ( ( latchIndex != victimLatchIndex ) && ( latches[victimLatchIndex].tryLock() == false ) )
                 {
-                    curLink = curLink.getNext();    
+                    curLink = curLink.getNext();
                     continue;
                 }
-                
+
                 if ( victimEntry.isEntryFreeable() == false )
                 {
                     throw new IllegalStateException( "Snapshot victimEntry is not freeable:" + victimEntry );
                 }
-                
+
                 int hashChainIndex = buckets[victimEntry.getHashIndex()].indexOf( victimEntry );
-                
+
                 if ( hashChainIndex != -1 )
                 {
                     buckets[victimEntry.getHashIndex()].remove( hashChainIndex );
-                    
+
                     if ( victimEntry.getVersionsLink().isLinked() )
                     {
                         ExplicitList.Link<CacheEntry> nextLink = victimEntry.getVersionsLink().getNext();
                         victimEntry.getVersionsLink().remove();
-                        
+
                         CacheEntry newEntry = nextLink.getElement();
                         buckets[newEntry.getHashIndex()].add( newEntry );
                     }
@@ -1310,72 +1318,71 @@ public class LRUCache<K, V>
                 {
                     victimEntry.getVersionsLink().remove();
                 }
-                
+
                 if ( latchIndex != victimLatchIndex )
                 {
                     latches[victimLatchIndex].unlock();
                 }
-                
+
                 this.snapshotVersions.remove( victimEntry.getLruLink() );
                 this.mostRecentVersions.addLast( victimEntry.getLruLink() );
-                
+
                 return victimEntry;
             }
-            
+
             curLink = mostRecentVersions.begin();
-            
+
             while ( curLink != mostRecentVersions.end() )
             {
                 victimEntry = curLink.getElement();
-                
+
                 // Dirty check
                 if ( victimEntry.isEntryFreeable() == false )
                 {
                     curLink = curLink.getNext();
                     continue;
                 }
-                    
-                
+
                 victimBucketIndex = victimEntry.getHashIndex();
-                victimLatchIndex = (victimBucketIndex >> LOG_BUCKET_PER_LATCH );
-                
+                victimLatchIndex = ( victimBucketIndex >> LOG_BUCKET_PER_LATCH );
+
                 if ( latchIndex != victimLatchIndex && latches[victimLatchIndex].tryLock() == false )
                 {
                     curLink = curLink.getNext();
                     continue;
                 }
-                
+
                 if ( victimEntry.isEntryFreeable() == false )
                 {
                     if ( latchIndex != victimLatchIndex )
                     {
                         latches[victimLatchIndex].unlock();
                     }
-                    
+
                     curLink = curLink.getNext();
                     continue;
                 }
-                
+
                 buckets[victimEntry.getHashIndex()].remove( victimEntry );
-                
+
                 if ( victimEntry.getVersionsLink().isLinked() )
                 {
                     ExplicitList.Link<CacheEntry> nextLink = victimEntry.getVersionsLink().getNext();
                     victimEntry.getVersionsLink().remove();
-                    
+
                     CacheEntry newEntry = nextLink.getElement();
                     buckets[newEntry.getHashIndex()].add( newEntry );
                 }
-                
+
                 if ( latchIndex != victimLatchIndex )
                 {
                     latches[victimLatchIndex].unlock();
                 }
-                
+
                 this.touch( victimEntry );
                 return victimEntry;
             }
-            
+
             return null;
         }
     }

Modified: directory/jdbm/trunk/jdbm2/src/main/java/jdbm/recman/BaseRecordManager.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm2/src/main/java/jdbm/recman/BaseRecordManager.java?rev=1446554&r1=1446553&r2=1446554&view=diff
==============================================================================
--- directory/jdbm/trunk/jdbm2/src/main/java/jdbm/recman/BaseRecordManager.java (original)
+++ directory/jdbm/trunk/jdbm2/src/main/java/jdbm/recman/BaseRecordManager.java Fri Feb 15 12:33:56 2013
@@ -48,6 +48,7 @@
 
 package jdbm.recman;
 
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -56,14 +57,15 @@ import java.util.concurrent.locks.Condit
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+import jdbm.I18n;
 import jdbm.RecordManager;
 import jdbm.helper.DefaultSerializer;
 import jdbm.helper.Serializer;
 
-import jdbm.I18n;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 /**
  *  This class manages records, which are uninterpreted blobs of data. The
  *  set of operations is simple and straightforward: you communicate with
@@ -89,8 +91,8 @@ import org.slf4j.LoggerFactory;
 public final class BaseRecordManager implements RecordManager
 {
     /** A logger for this class */
-    private static final Logger LOG = LoggerFactory.getLogger( BaseRecordManager.class.getSimpleName() );
-    
+    private static final Logger LOG = LoggerFactory.getLogger( BaseRecordManager.class );
+
     /** Underlying record recordFile. */
     private RecordFile recordFile;
 
@@ -114,8 +116,8 @@ public final class BaseRecordManager imp
      * directory, stored as a Hashtable.  It can be retrieved by using
      * the NAME_DIRECTORY_ROOT.
      */
-    private Map<String,Long> nameDirectory;
-    
+    private Map<String, Long> nameDirectory;
+
     private static enum IOType
     {
         READ_IO,
@@ -205,7 +207,6 @@ public final class BaseRecordManager imp
         }
     }
 
-    
     /**
      * Map used to synchronize reads and writes on the same logical
      * recid.
@@ -235,7 +236,7 @@ public final class BaseRecordManager imp
     public TransactionManager getTransactionManager() throws IOException
     {
         checkIfClosed();
-        
+
         return recordFile.getTxnMgr();
     }
 
@@ -255,7 +256,7 @@ public final class BaseRecordManager imp
         recordFile.disableTransactions();
     }
 
-    
+
     /**
      * Closes the record manager.
      *
@@ -285,7 +286,7 @@ public final class BaseRecordManager imp
         return insert( obj, DefaultSerializer.INSTANCE );
     }
 
-    
+
     /**
      * Inserts a new record using a custom serializer.
      *
@@ -296,22 +297,22 @@ public final class BaseRecordManager imp
      */
     public long insert( Object obj, Serializer serializer ) throws IOException
     {
-        byte[]    data;
-        long      recid;
-        Location  physRowId;
-        
+        byte[] data;
+        long recid;
+        Location physRowId;
+
         checkIfClosed();
 
         data = serializer.serialize( obj );
         physRowId = physMgr.insert( data, 0, data.length );
         recid = logMgr.insert( physRowId ).toLong();
-     
-        LOG.debug( "BaseRecordManager.insert() recid {} length {}", recid, data.length ) ;
-        
+
+        LOG.debug( "BaseRecordManager.insert() recid {} length {}", recid, data.length );
+
         return recid;
     }
 
-    
+
     /**
      * Deletes a record.
      *
@@ -322,17 +323,16 @@ public final class BaseRecordManager imp
     {
         LockElement element;
         checkIfClosed();
-        
+
         if ( recid <= 0 )
         {
             throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) );
         }
 
-        LOG.debug( "BaseRecordManager.delete() recid {}", recid ) ;
+        LOG.debug( "BaseRecordManager.delete() recid {}", recid );
 
-        
         element = beginIO( recid, IOType.WRITE_IO );
-        
+
         try
         {
             Location logRowId = new Location( recid );
@@ -358,7 +358,7 @@ public final class BaseRecordManager imp
     {
         update( recid, obj, DefaultSerializer.INSTANCE );
     }
-    
+
 
     /**
      * Updates a record using a custom serializer.
@@ -371,7 +371,7 @@ public final class BaseRecordManager imp
     public void update( long recid, Object obj, Serializer serializer ) throws IOException
     {
         LockElement element;
-        
+
         checkIfClosed();
 
         if ( recid <= 0 )
@@ -380,29 +380,29 @@ public final class BaseRecordManager imp
         }
 
         element = this.beginIO( recid, IOType.WRITE_IO );
-         
+
         try
         {
             Location logRecid = new Location( recid );
             Location physRecid = logMgr.fetch( logRecid );
 
             byte[] data = serializer.serialize( obj );
-            
-            LOG.debug( "BaseRecordManager.update() recid {} length {}", recid, data.length ) ;
-            
+
+            LOG.debug( "BaseRecordManager.update() recid {} length {}", recid, data.length );
+
             Location newRecid = physMgr.update( physRecid, data, 0, data.length );
-            
-            if ( ! newRecid.equals( physRecid ) )
+
+            if ( !newRecid.equals( physRecid ) )
             {
                 logMgr.update( logRecid, newRecid );
             }
-         }
-         finally
-         {
-             endIO( recid, element, IOType.WRITE_IO );
-         }
+        }
+        finally
+        {
+            endIO( recid, element, IOType.WRITE_IO );
+        }
     }
-    
+
 
     /**
      * Fetches a record using standard java object serialization.
@@ -416,7 +416,7 @@ public final class BaseRecordManager imp
         return fetch( recid, DefaultSerializer.INSTANCE );
     }
 
-    
+
     /**
      * Fetches a record using a custom serializer.
      *
@@ -429,32 +429,32 @@ public final class BaseRecordManager imp
     {
         Object result;
         LockElement element;
-        
+
         checkIfClosed();
-        
+
         if ( recid <= 0 )
         {
             throw new IllegalArgumentException( I18n.err( I18n.ERR_536, recid ) );
         }
-        
-        element = this.beginIO(recid, IOType.READ_IO);
-        
+
+        element = this.beginIO( recid, IOType.READ_IO );
+
         try
         {
             byte[] data;
-            
-            Location location = logMgr.fetch( new Location( recid ) ) ;
+
+            Location location = logMgr.fetch( new Location( recid ) );
             data = physMgr.fetch( location );
-            
-            LOG.debug( "BaseRecordManager.fetch() recid {} length {}", recid, data.length ) ;
-            
+
+            LOG.debug( "BaseRecordManager.fetch() recid {} length {}", recid, data.length );
+
             result = serializer.deserialize( data );
         }
         finally
         {
-            endIO(recid, element, IOType.READ_IO);
+            endIO( recid, element, IOType.READ_IO );
         }
-        
+
         return result;
     }
 
@@ -470,7 +470,7 @@ public final class BaseRecordManager imp
         return FileHeader.NROOTS;
     }
 
-    
+
     /**
      *  Returns the indicated root rowid.
      *
@@ -505,17 +505,17 @@ public final class BaseRecordManager imp
     {
         checkIfClosed();
 
-        Map<String,Long> nameDirectory = getNameDirectory();
+        Map<String, Long> nameDirectory = getNameDirectory();
         Long recid = nameDirectory.get( name );
 
         if ( recid == null )
         {
             return 0;
         }
-        
+
         return recid;
     }
-    
+
 
     /**
      * Set the record id of a named object.
@@ -533,8 +533,8 @@ public final class BaseRecordManager imp
         {
             getNameDirectory().put( name, recid );
         }
-        
-        saveNameDirectory( );
+
+        saveNameDirectory();
     }
 
 
@@ -564,11 +564,11 @@ public final class BaseRecordManager imp
      * Load name directory
      */
     @SuppressWarnings("unchecked")
-    private Map<String,Long> getNameDirectory() throws IOException
+    private Map<String, Long> getNameDirectory() throws IOException
     {
         // retrieve directory of named hashtable
         long nameDirectory_recid = getRoot( NAME_DIRECTORY_ROOT );
-        
+
         if ( nameDirectory_recid == 0 )
         {
             nameDirectory = new HashMap<String, Long>();
@@ -579,20 +579,20 @@ public final class BaseRecordManager imp
         {
             nameDirectory = ( Map<String, Long> ) fetch( nameDirectory_recid );
         }
-        
+
         return nameDirectory;
     }
 
 
-    private void saveNameDirectory( ) throws IOException
+    private void saveNameDirectory() throws IOException
     {
         long recid = getRoot( NAME_DIRECTORY_ROOT );
-        
+
         if ( recid == 0 )
         {
             throw new IOException( I18n.err( I18n.ERR_537 ) );
         }
-        
+
         update( recid, nameDirectory );
     }
 
@@ -607,7 +607,7 @@ public final class BaseRecordManager imp
             throw new IllegalStateException( I18n.err( I18n.ERR_538 ) );
         }
     }
-    
+
 
     /**
      * Used to serialize reads/write on a given logical rowid. Checks if there is a
@@ -624,96 +624,96 @@ public final class BaseRecordManager imp
         LockElement element = null;
 
         // loop until we successfully verify that there is no concurrent writer
-/*
-        element = lockElements.get( recid );
-        
-        do
-        {
-            if ( element == null )
-            {
-                element = new LockElement();
-
-                if ( io == IOType.READ_IO )
-                {
-                    element.bumpReaders();
-                }
-                else
-                {
-                    element.setWritten();
-                }
-
-                LockElement existingElement = lockElements.putIfAbsent( recid, element );
-
-                if ( existingElement == null )
-                {
-                    lockVerified = true;
-                }
-                else
-                {
-                    element = existingElement;
-                }
-            }
-            else
-            {
-                Lock lock = element.getLock();
-                lock.lock();
+        /*
+                element = lockElements.get( recid );
                 
-                if ( element.anyUser() )
+                do
                 {
-                    if ( this.conflictingIOPredicate( io, element ) )
+                    if ( element == null )
                     {
-                        element.bumpWaiters();
-                        
-                        do
+                        element = new LockElement();
+
+                        if ( io == IOType.READ_IO )
                         {
-                            element.getNoConflictingIOCondition()
-                                .awaitUninterruptibly();
+                            element.bumpReaders();
+                        }
+                        else
+                        {
+                            element.setWritten();
                         }
-                        while ( this.conflictingIOPredicate( io, element ) );
-
-                        element.decrementWaiters();
-                    }
-
-                    // no conflicting IO anymore..done
-                    if ( io == IOType.READ_IO )
-                    {
-                        element.bumpReaders();
-                    }
-                    else
-                    {
-                        element.setWritten();
-                    }
-                    
-                    lockVerified = true;
-                }
-                else
-                {
-                    if ( io == IOType.READ_IO )
-                    {
-                        element.bumpReaders();
-                    }
-                    else
-                    {
-                        element.setWritten();
-                    }
 
-                    LockElement existingElement = lockElements.get( recid );
+                        LockElement existingElement = lockElements.putIfAbsent( recid, element );
 
-                    if ( element != existingElement )
-                    {
-                        element = existingElement;
+                        if ( existingElement == null )
+                        {
+                            lockVerified = true;
+                        }
+                        else
+                        {
+                            element = existingElement;
+                        }
                     }
                     else
                     {
-                        lockVerified = true; // done
+                        Lock lock = element.getLock();
+                        lock.lock();
+                        
+                        if ( element.anyUser() )
+                        {
+                            if ( this.conflictingIOPredicate( io, element ) )
+                            {
+                                element.bumpWaiters();
+                                
+                                do
+                                {
+                                    element.getNoConflictingIOCondition()
+                                        .awaitUninterruptibly();
+                                }
+                                while ( this.conflictingIOPredicate( io, element ) );
+
+                                element.decrementWaiters();
+                            }
+
+                            // no conflicting IO anymore..done
+                            if ( io == IOType.READ_IO )
+                            {
+                                element.bumpReaders();
+                            }
+                            else
+                            {
+                                element.setWritten();
+                            }
+                            
+                            lockVerified = true;
+                        }
+                        else
+                        {
+                            if ( io == IOType.READ_IO )
+                            {
+                                element.bumpReaders();
+                            }
+                            else
+                            {
+                                element.setWritten();
+                            }
+
+                            LockElement existingElement = lockElements.get( recid );
+
+                            if ( element != existingElement )
+                            {
+                                element = existingElement;
+                            }
+                            else
+                            {
+                                lockVerified = true; // done
+                            }
+                        }
+                        
+                        lock.unlock();
                     }
                 }
-                
-                lock.unlock();
-            }
-        }
-        while ( !lockVerified );
-*/
+                while ( !lockVerified );
+        */
         return element;
     }
 



Mime
View raw message