use of org.apache.ignite.internal.metastorage.server.Entry in project ignite-3 by apache.
the class RangeCursor method createIterator.
/**
* Creates an iterator for this cursor.
*
* @return Iterator.
*/
@NotNull
private Iterator<Entry> createIterator() {
return new Iterator<>() {
/**
* {@inheritDoc}
*/
@Override
public boolean hasNext() {
storage.lock().readLock().lock();
try {
while (true) {
if (finished) {
return false;
}
if (nextRetEntry != null) {
return true;
}
byte[] key = lastRetKey;
while (nextRetEntry == null) {
Map.Entry<byte[], long[]> e = key == null ? storage.revisionCeilingEntry(keyFrom) : storage.revisionHigherEntry(key);
if (e == null) {
finished = true;
break;
}
key = e.getKey();
if (keyTo != null && RocksDbKeyValueStorage.CMP.compare(key, keyTo) >= 0) {
finished = true;
break;
}
long[] revs = e.getValue();
assert revs != null && revs.length != 0 : "Revisions should not be empty or null: [revs=" + Arrays.toString(revs) + ']';
long lastRev = RocksDbKeyValueStorage.maxRevision(revs, rev);
if (lastRev == -1) {
continue;
}
Entry entry = storage.doGetValue(key, lastRev);
assert !entry.empty() : "Iterator should not return empty entry.";
nextRetEntry = entry;
}
}
} finally {
storage.lock().readLock().unlock();
}
}
/**
* {@inheritDoc}
*/
@Override
public Entry next() {
storage.lock().readLock().lock();
try {
if (!hasNext()) {
throw new NoSuchElementException();
}
Entry e = nextRetEntry;
nextRetEntry = null;
assert e != null;
lastRetKey = e.key();
return e;
} finally {
storage.lock().readLock().unlock();
}
}
};
}
use of org.apache.ignite.internal.metastorage.server.Entry in project ignite-3 by apache.
the class RocksDbKeyValueStorage method addToBatchForRemoval.
/**
* Adds a key to a batch marking the value as a tombstone.
*
* @param batch Write batch.
* @param key Target key.
* @param curRev Revision.
* @param counter Update counter.
* @return {@code true} if an entry can be deleted.
* @throws RocksDBException If failed.
*/
private boolean addToBatchForRemoval(WriteBatch batch, byte[] key, long curRev, long counter) throws RocksDBException {
Entry e = doGet(key, LATEST_REV, false);
if (e.empty() || e.tombstone()) {
return false;
}
addDataToBatch(batch, key, TOMBSTONE, curRev, counter);
return true;
}
use of org.apache.ignite.internal.metastorage.server.Entry in project ignite-3 by apache.
the class RocksDbKeyValueStorage method invoke.
/**
* {@inheritDoc}
*/
@Override
public boolean invoke(Condition condition, Collection<Operation> success, Collection<Operation> failure) {
rwLock.writeLock().lock();
try {
Entry[] entries = getAll(Arrays.asList(condition.keys())).toArray(new Entry[] {});
boolean branch = condition.test(entries);
Collection<Operation> ops = branch ? success : failure;
applyOperations(ops);
return branch;
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.ignite.internal.metastorage.server.Entry in project ignite-3 by apache.
the class RocksDbKeyValueStorage method invoke.
@Override
public StatementResult invoke(If iif) {
rwLock.writeLock().lock();
try {
If currIf = iif;
byte maximumNumOfNestedBranch = 100;
while (true) {
if (maximumNumOfNestedBranch-- <= 0) {
throw new IgniteInternalException("Too many nested (" + maximumNumOfNestedBranch + ") statements in multi-invoke command.");
}
Entry[] entries = getAll(Arrays.asList(currIf.cond().keys())).toArray(new Entry[] {});
Statement branch = (currIf.cond().test(entries)) ? currIf.andThen() : currIf.orElse();
if (branch.isTerminal()) {
Update update = branch.update();
applyOperations(update.operations());
return update.result();
} else {
currIf = branch.iif();
}
}
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.ignite.internal.metastorage.server.Entry in project ignite-3 by apache.
the class RocksDbKeyValueStorage method doGetValue.
/**
* Gets the value by a key and a revision.
*
* @param key Target key.
* @param revision Target revision.
* @return Entry.
*/
@NotNull
Entry doGetValue(byte[] key, long revision) {
if (revision == 0) {
return Entry.empty(key);
}
byte[] valueBytes;
try {
valueBytes = data.get(keyToRocksKey(revision, key));
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
}
if (valueBytes == null || valueBytes.length == 0) {
return Entry.empty(key);
}
Value lastVal = bytesToValue(valueBytes);
if (lastVal.tombstone()) {
return Entry.tombstone(key, revision, lastVal.updateCounter());
}
return new Entry(key, lastVal.bytes(), revision, lastVal.updateCounter());
}
Aggregations