Source:
<code>public byte[] getOrCreateId(int dimensionNum, byte[] input, int numIdBytes) throws IOException, InterruptedException { Validate.validateDimensionNum(dimensionNum); Validate.validateNumIdBytes(numIdBytes); final byte[] lookupKey = makeLookupKey(dimensionNum, input); final Optional<byte[]> existingId = getId(lookupKey, numIdBytes); if (existingId.isPresent()) { return existingId.get(); } byte[] counterKey = makeCounterKey(dimensionNum); final long id = WithHTable.increment(pool, counterTable, counterKey, cf, QUALIFIER, 1L); if (log.isDebugEnabled()) { log.debug("Allocated new id " + id); } final long maxId = LongMath.pow(2L, numIdBytes * 8); if (id > maxId) { throw new RuntimeException("Exhausted IDs for dimension " + dimensionNum); } else if (id < 0) { throw new RuntimeException("Somehow ID was less than zero. Weird!"); } final Put put = new Put(lookupKey); byte[] allocatedRecord = ArrayUtils.addAll(HBaseIdService.ALLOCATED_BYTES, Util.longToBytes(id)); put.add(cf, QUALIFIER, allocatedRecord); boolean swapSuccess = WithHTable.checkAndPut(pool, lookupTable, lookupKey, cf, QUALIFIER, EMPTY, put); if (swapSuccess) { return Util.leastSignificantBytes(id, numIdBytes); } else { <START> final Optional<byte[]> currentValue = getId(lookupKey, numIdBytes); <END> if (currentValue.isPresent()) { return currentValue.get(); } else { throw new RuntimeException("Failed to get id for row " + Bytes.toString(lookupKey) + " after CAS failed"); } } }</code><technical_language>this violates "correctness" of data cube works in user defines "capacity" of id range honors that. done is possibly burn throw due database contention. wrong me</technical_language>

Target:
public byte[] getOrCreateId(int dimensionNum, byte[] input, int numIdBytes) throws IOException, InterruptedException { Validate.validateDimensionNum(dimensionNum); Validate.validateNumIdBytes(numIdBytes); final byte[] lookupKey = makeLookupKey(dimensionNum, input); final Optional<byte[]> existingId = getId(lookupKey, numIdBytes); if (existingId.isPresent()) { return existingId.get(); } final TimerContext timer = idCreationTime.time(); byte[] counterKey = makeCounterKey(dimensionNum); final long id = WithHTable.increment(pool, counterTable, counterKey, cf, QUALIFIER, 1L); if (log.isDebugEnabled()) { log.debug("Allocated new id " + id); } final long maxId = LongMath.pow(2L, numIdBytes * 8); if (id > maxId) { throw new RuntimeException("Exhausted IDs for dimension " + dimensionNum); } else if (id < 0) { throw new RuntimeException("Somehow ID was less than zero. Weird!"); } else if (maxId / id <= 2) { dimensionsApproachingExhaustion.add(dimensionNum); } final Put put = new Put(lookupKey); byte[] allocatedRecord = ArrayUtils.addAll(HBaseIdService.ALLOCATED_BYTES, Util.longToBytes(id)); put.add(cf, QUALIFIER, allocatedRecord); boolean swapSuccess = WithHTable.checkAndPut(pool, lookupTable, lookupKey, cf, QUALIFIER, EMPTY, put); if (swapSuccess) { timer.stop(); return Util.leastSignificantBytes(id, numIdBytes); } else { wastedIdNumbers.mark(); final Optional<byte[]> currentValue = getId(lookupKey, numIdBytes); timer.stop(); if (currentValue.isPresent()) { return currentValue.get(); } else { throw new RuntimeException("Failed to get id for row " + Bytes.toString(lookupKey) + " after CAS failed"); } } }