use of org.apache.ignite.internal.vault.VaultEntry in project ignite-3 by apache.
the class ItPersistencePropertiesVaultServiceTest method testPersistentRestart.
/**
* Tests that the Vault Service correctly persists data after multiple service restarts.
*/
@Test
void testPersistentRestart() throws Exception {
var data = Map.of(new ByteArray("key" + 1), fromString("value" + 1), new ByteArray("key" + 2), fromString("value" + 2), new ByteArray("key" + 3), fromString("value" + 3));
try (var vaultService = new PersistentVaultService(vaultDir)) {
vaultService.start();
vaultService.putAll(data).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
try (var vaultService = new PersistentVaultService(vaultDir)) {
vaultService.start();
assertThat(vaultService.get(new ByteArray("key" + 1)), willBe(equalTo(new VaultEntry(new ByteArray("key" + 1), fromString("value" + 1)))));
}
try (var vaultService = new PersistentVaultService(vaultDir)) {
vaultService.start();
try (var cursor = vaultService.range(new ByteArray("key" + 1), new ByteArray("key" + 4))) {
var actualData = new ArrayList<VaultEntry>();
cursor.forEachRemaining(actualData::add);
List<VaultEntry> expectedData = data.entrySet().stream().map(e -> new VaultEntry(e.getKey(), e.getValue())).sorted(Comparator.comparing(VaultEntry::key)).collect(Collectors.toList());
assertThat(actualData, is(expectedData));
}
}
}
use of org.apache.ignite.internal.vault.VaultEntry in project ignite-3 by apache.
the class DistributedConfigurationStorage method readAll.
/**
* {@inheritDoc}
*/
@Override
public Data readAll() throws StorageException {
var data = new HashMap<String, Serializable>();
VaultEntry appliedRevEntry = vaultMgr.get(MetaStorageManager.APPLIED_REV).join();
long appliedRevision = appliedRevEntry.value() == null ? 0L : ByteUtils.bytesToLong(appliedRevEntry.value());
try (Cursor<VaultEntry> entries = storedDistributedConfigKeys()) {
for (VaultEntry entry : entries) {
ByteArray key = entry.key();
byte[] value = entry.value();
// vault iterator should not return nulls as values
assert value != null;
if (key.equals(MASTER_KEY)) {
continue;
}
String dataKey = key.toString().substring(DISTRIBUTED_PREFIX.length());
data.put(dataKey, ConfigurationSerializationUtil.fromBytes(value));
}
} catch (Exception e) {
throw new StorageException("Exception when closing a Vault cursor", e);
}
assert data.isEmpty() || appliedRevision > 0;
changeId.set(data.isEmpty() ? 0 : appliedRevision);
return new Data(data, appliedRevision);
}
use of org.apache.ignite.internal.vault.VaultEntry in project ignite-3 by apache.
the class LocalConfigurationStorage method readAll.
/**
* Retrieves all data, which keys lie in between {@code [rangeStart, rangeEnd)}.
*/
private Data readAll(ByteArray rangeStart, ByteArray rangeEnd) {
var data = new HashMap<String, Serializable>();
try (Cursor<VaultEntry> cursor = vaultMgr.range(rangeStart, rangeEnd)) {
for (VaultEntry entry : cursor) {
String key = entry.key().toString().substring(LOC_PREFIX.length());
byte[] value = entry.value();
// vault iterator should not return nulls as values
assert value != null;
data.put(key, ConfigurationSerializationUtil.fromBytes(value));
}
} catch (Exception e) {
throw new StorageException("Exception when closing a Vault cursor", e);
}
// TODO: https://issues.apache.org/jira/browse/IGNITE-14697
return new Data(data, ver.get());
}
use of org.apache.ignite.internal.vault.VaultEntry in project ignite-3 by apache.
the class PersistentVaultService method range.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public Cursor<VaultEntry> range(@NotNull ByteArray fromKey, @NotNull ByteArray toKey) {
var readOpts = new ReadOptions();
var upperBound = new Slice(toKey.bytes());
readOpts.setIterateUpperBound(upperBound);
RocksIterator it = db.newIterator(readOpts);
it.seek(fromKey.bytes());
return new RocksIteratorAdapter<>(it) {
@Override
protected VaultEntry decodeEntry(byte[] key, byte[] value) {
return new VaultEntry(new ByteArray(key), value);
}
@Override
public void close() throws Exception {
super.close();
IgniteUtils.closeAll(upperBound, readOpts);
}
};
}
Aggregations