mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
01.47.2015 1815c2396e62b5a1fa6a0414a0dc5e30484a4a3c
OPENDJ-2016 Implement new on disk merge import strategy based on storage engine

Complement of r12381.

ID2Count.java:
Extracted methods toKey(), toValue() and fromValue().
1 files modified
27 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/ID2Count.java 27 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/ID2Count.java
@@ -41,6 +41,7 @@
 * Store a counter associated to a key. Counter value is sharded amongst multiple keys to allow concurrent
 * update without contention (at the price of a slower read).
 */
@SuppressWarnings("javadoc")
final class ID2Count extends AbstractTree
{
  /**
@@ -70,7 +71,7 @@
          @Override
          public Long transform(ByteString key, ByteString value) throws NeverThrowsException
          {
            return value.toLong();
            return fromValue(value);
          }
        });
  }
@@ -98,7 +99,7 @@
      public ByteSequence computeNewValue(ByteSequence oldValue)
      {
        final long currentValue = oldValue != null ? oldValue.asReader().getLong() : 0;
        return ByteString.valueOf(currentValue + delta);
        return toValue(currentValue + delta);
      }
    });
  }
@@ -118,7 +119,7 @@
  {
    Reject.ifNull(importer, "importer must not be null");
    final ByteSequence shardedKey = getShardedKey(entryID);
    importer.put(getName(), shardedKey, ByteString.valueOf(delta));
    importer.put(getName(), shardedKey, toValue(delta));
  }
  private ByteSequence getShardedKey(EntryID entryID)
@@ -127,6 +128,25 @@
    return getKeyFromEntryIDAndBucket(entryID, bucket);
  }
  ByteSequence toKey(EntryID entryID)
  {
    if (entryID == null)
    {
      entryID = TOTAL_COUNT_ENTRY_ID;
    }
    return getShardedKey(entryID);
  }
  ByteString toValue(final long count)
  {
    return ByteString.valueOf(count);
  }
  long fromValue(ByteString value)
  {
    return value.toLong();
  }
  /**
   * Get the counter value for the specified key
   * @param txn The transaction
@@ -144,7 +164,6 @@
        cursor.next();
      }
    }
    return counterValue;
  }