| | |
| | | final void delete(WriteableStorage txn, ByteSequence key, ImportIDSet importIdSet) |
| | | throws StorageRuntimeException |
| | | { |
| | | ByteString value = read(txn, key, false); |
| | | ByteString value = txn.read(getName(), key); |
| | | if (value != null) { |
| | | newImportIDSet.clear(); |
| | | newImportIDSet.remove(value, importIdSet); |
| | | if (newImportIDSet.isDefined() && newImportIDSet.size() == 0) |
| | | { |
| | | delete(txn, key); |
| | | txn.delete(getName(), key); |
| | | } |
| | | else |
| | | { |
| | | value = newImportIDSet.valueToByteString(); |
| | | put(txn, key, value); |
| | | txn.create(getName(), key, value); |
| | | } |
| | | } else { |
| | | // Should never happen -- the keys should always be there. |
| | |
| | | final void insert(WriteableStorage txn, ByteSequence key, ImportIDSet importIdSet) |
| | | throws StorageRuntimeException |
| | | { |
| | | ByteString value = read(txn, key, false); |
| | | ByteString value = txn.read(getName(), key); |
| | | if(value != null) { |
| | | newImportIDSet.clear(); |
| | | if (newImportIDSet.merge(value, importIdSet)) { |
| | |
| | | } |
| | | value = importIdSet.valueToByteString(); |
| | | } |
| | | put(txn, key, value); |
| | | txn.create(getName(), key, value); |
| | | } |
| | | |
| | | void updateKey(WriteableStorage txn, ByteString key, EntryIDSet deletedIDs, EntryIDSet addedIDs) |
| | |
| | | */ |
| | | if (deletedIDs == null && addedIDs == null) |
| | | { |
| | | boolean success = delete(txn, key); |
| | | boolean success = txn.delete(getName(), key); |
| | | if (success && logger.isTraceEnabled()) |
| | | { |
| | | StringBuilder builder = new StringBuilder(); |
| | | StaticUtils.byteArrayToHexPlusAscii(builder, key.toByteArray(), 4); |
| | | logger.trace("The expected key does not exist in the index %s.\nKey:%s ", treeName, builder); |
| | | logger.trace("The expected key does not exist in the index %s.\nKey:%s ", getName(), builder); |
| | | } |
| | | return; |
| | | } |
| | |
| | | * Avoid taking a write lock on a record which has hit all IDs because it is likely to be a |
| | | * point of contention. |
| | | */ |
| | | ByteString value = read(txn, key, false); |
| | | ByteString value = txn.read(getName(), key); |
| | | if (value != null) |
| | | { |
| | | EntryIDSet entryIDList = new EntryIDSet(key, value); |
| | |
| | | |
| | | if ((rebuildRunning || trusted) |
| | | && isNotNullOrEmpty(addedIDs) |
| | | && !insert(txn, key, addedIDs.toByteString())) |
| | | && !txn.putIfAbsent(getName(), key, addedIDs.toByteString())) |
| | | { |
| | | updateKeyWithRMW(txn, key, deletedIDs, addedIDs); |
| | | } |
| | |
| | | private void updateKeyWithRMW(WriteableStorage txn, ByteString key, EntryIDSet deletedIDs, EntryIDSet addedIDs) |
| | | throws StorageRuntimeException |
| | | { |
| | | final ByteString value = read(txn, key, true); |
| | | final ByteString value = txn.getRMW(getName(), key); |
| | | if (value != null) |
| | | { |
| | | EntryIDSet entryIDList = computeEntryIDList(key, value, deletedIDs, addedIDs); |
| | | ByteString after = entryIDList.toByteString(); |
| | | if (!after.isEmpty()) |
| | | { |
| | | put(txn, key, after); |
| | | txn.create(getName(), key, after); |
| | | } |
| | | else |
| | | { |
| | | // No more IDs, so remove the key. If index is not |
| | | // trusted then this will cause all subsequent reads |
| | | // for this key to return undefined set. |
| | | delete(txn, key); |
| | | txn.delete(getName(), key); |
| | | } |
| | | } |
| | | else |
| | |
| | | |
| | | if ((rebuildRunning || trusted) && isNotNullOrEmpty(addedIDs)) |
| | | { |
| | | insert(txn, key, addedIDs.toByteString()); |
| | | txn.putIfAbsent(getName(), key, addedIDs.toByteString()); |
| | | } |
| | | } |
| | | } |
| | |
| | | StaticUtils.byteArrayToHexPlusAscii(builder, key.toByteArray(), 4); |
| | | logger.trace("Index entry exceeded in index %s. " + |
| | | "Limit: %d. ID list size: %d.\nKey:%s", |
| | | treeName, indexEntryLimit, idCountDelta + addedIDs.size(), builder); |
| | | getName(), indexEntryLimit, idCountDelta + addedIDs.size(), builder); |
| | | |
| | | } |
| | | } |
| | |
| | | { |
| | | StringBuilder builder = new StringBuilder(); |
| | | StaticUtils.byteArrayToHexPlusAscii(builder, key.toByteArray(), 4); |
| | | logger.trace("The expected key does not exist in the index %s.\nKey:%s", treeName, builder); |
| | | logger.trace("The expected key does not exist in the index %s.\nKey:%s", getName(), builder); |
| | | } |
| | | |
| | | setTrusted(txn, false); |
| | | logger.error(ERR_JEB_INDEX_CORRUPT_REQUIRES_REBUILD, treeName); |
| | | logger.error(ERR_JEB_INDEX_CORRUPT_REQUIRES_REBUILD, getName()); |
| | | } |
| | | |
| | | void delete(IndexBuffer buffer, ByteString keyBytes) |
| | |
| | | return ConditionResult.UNDEFINED; |
| | | } |
| | | |
| | | ByteString value = read(txn, key, false); |
| | | ByteString value = txn.read(getName(), key); |
| | | if (value != null) |
| | | { |
| | | EntryIDSet entryIDList = new EntryIDSet(key, value); |
| | |
| | | |
| | | try |
| | | { |
| | | ByteString value = read(txn, key, false); |
| | | ByteString value = txn.read(getName(), key); |
| | | if (value == null) |
| | | { |
| | | if(trusted) |
| | |
| | | |
| | | ArrayList<EntryIDSet> lists = new ArrayList<EntryIDSet>(); |
| | | |
| | | Cursor cursor = txn.openCursor(treeName); |
| | | Cursor cursor = txn.openCursor(getName()); |
| | | try |
| | | { |
| | | boolean success; |