use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class ChunkMetadataStoreTests method testEvictionFromBufferInParallel.
@Test
public void testEvictionFromBufferInParallel() {
if (metadataStore instanceof InMemoryMetadataStore) {
metadataStore.setMaxEntriesInCache(10);
metadataStore.setMaxEntriesInTxnBuffer(10);
val futures = new ArrayList<CompletableFuture<Void>>();
for (int i = 0; i < 10000; i++) {
final int k = i;
futures.add(CompletableFuture.runAsync(() -> simpleScenarioForKey("Key" + k)));
}
Futures.allOf(futures);
}
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class ChunkMetadataStoreTests method testCommitFailureAfterEvictionFromBuffer.
@Test
public void testCommitFailureAfterEvictionFromBuffer() throws Exception {
if (metadataStore instanceof InMemoryMetadataStore) {
val testMetadataStore = (InMemoryMetadataStore) metadataStore;
// Add some data
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
txn.create(new MockStorageMetadata(KEY1, VALUE0));
txn.commit().get();
}
// Force eviction of all cache
testMetadataStore.evictAllEligibleEntriesFromBuffer();
testMetadataStore.evictFromCache();
// Set hook to cause failure on next commit.
testMetadataStore.setWriteCallback(dummy -> CompletableFuture.failedFuture(new IntentionalException("Intentional")));
// This txn will fail to commit.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
val metadata = (MockStorageMetadata) txn.get(KEY1).get();
metadata.setValue(VALUE1);
txn.update(metadata);
txn.commit().get();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(Exceptions.unwrap(e) instanceof IntentionalException);
}
// disable hook.
testMetadataStore.setWriteCallback(null);
// Validate that object in buffer remains unchanged.
try (MetadataTransaction txn = metadataStore.beginTransaction(true, KEY1)) {
assertEquals(txn.get(KEY1), KEY1, VALUE0);
}
}
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class ChunkMetadataStoreTests method testCommitSafetyWithSubset.
/**
* Test that only one of the concurrent commit can proceed and others fail.
*
* @throws Exception Exception if any.
*/
@Test
public void testCommitSafetyWithSubset() throws Exception {
if (metadataStore instanceof InMemoryMetadataStore) {
// Set up the callback so that you can block writeAll call, to create situation where commit is in flight but not finished.
final CompletableFuture<Void> futureToBlockOn = new CompletableFuture<Void>();
((InMemoryMetadataStore) metadataStore).setWriteCallback(transactionDataList -> {
// Block only on KEY0.
if (transactionDataList.stream().filter(t -> t.getKey().equals(KEY0)).findAny().isPresent()) {
return futureToBlockOn.thenApplyAsync(v2 -> null, executorService());
} else {
return CompletableFuture.completedFuture(null);
}
});
CompletableFuture<Void> commitFuture;
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0, KEY1)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE0));
Assert.assertNotNull(txn.get(KEY0));
// Do not wait , this call should block
commitFuture = txn.commit();
}
try {
// Try commit on all keys
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEYS)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE1));
assertEquals(txn.get(KEY0), KEY0, VALUE1);
AssertExtensions.assertFutureThrows("Transaction should fail.", txn.commit(), ex -> ex instanceof StorageMetadataVersionMismatchException);
}
// Try commit only on only one key.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE1));
assertEquals(txn.get(KEY0), KEY0, VALUE1);
AssertExtensions.assertFutureThrows("Transaction should fail.", txn.commit(), ex -> ex instanceof StorageMetadataVersionMismatchException);
}
// Try commit only on only one key.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
assertNull(txn.get(KEY0));
txn.create(new MockStorageMetadata(KEY0, VALUE1));
assertEquals(txn.get(KEY0), KEY0, VALUE1);
AssertExtensions.assertFutureThrows("Transaction should fail.", txn.commit(), ex -> ex instanceof StorageMetadataVersionMismatchException);
}
// Make sure transactions on unrelated keys works.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY4)) {
assertNull(txn.get(KEY4));
txn.create(new MockStorageMetadata(KEY4, VALUE4));
assertEquals(txn.get(KEY4), KEY4, VALUE4);
txn.commit().join();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(true, KEY4)) {
assertEquals(txn.get(KEY4), KEY4, VALUE4);
}
} finally {
futureToBlockOn.complete(null);
}
commitFuture.join();
// make sure the valid transaction went through.
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY0)) {
assertEquals(txn.get(KEY0), KEY0, VALUE0);
}
}
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class ChunkMetadataStoreTests method testParallelReadsAfterEviction.
@Test
public void testParallelReadsAfterEviction() throws Exception {
if (!(metadataStore instanceof InMemoryMetadataStore)) {
return;
}
val testMetadataStore = (InMemoryMetadataStore) metadataStore;
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY1)) {
txn.create(new MockStorageMetadata(KEY1, VALUE1));
txn.commit().get();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY2)) {
val metadata = new MockStorageMetadata(KEY2, VALUE2);
txn.create(metadata);
txn.markPinned(metadata);
txn.commit().get();
}
try (MetadataTransaction txn = metadataStore.beginTransaction(false, KEY4)) {
val metadata = new MockStorageMetadata(KEY4, VALUE4);
txn.create(metadata);
txn.commit(true).get();
}
testMetadataStore.evictFromCache();
testMetadataStore.getBackingStore().clear();
Assert.assertNull(testMetadataStore.getBackingStore().get(KEY1));
// Invoke eviction, this will move data from buffer to the Guava cache.
testMetadataStore.evictAllEligibleEntriesFromBuffer();
val futures = new ArrayList<CompletableFuture<Void>>();
for (int i = 0; i < 100; i++) {
futures.add(CompletableFuture.runAsync(() -> {
readKey(KEY1, VALUE1);
readKey(KEY2, VALUE2);
readKey(KEY4, VALUE4);
evictAll(testMetadataStore);
}));
}
Futures.allOf(futures);
evictAll(testMetadataStore);
val futures2 = new ArrayList<CompletableFuture<Void>>();
for (int i = 0; i < 100; i++) {
futures.add(CompletableFuture.runAsync(() -> {
readKey(KEY1, VALUE1);
readKey(KEY2, VALUE2);
readKey(KEY4, VALUE4);
testMetadataStore.evictFromCache();
// Invoke eviction, this will move data from buffer to the Guava cache.
testMetadataStore.evictAllEligibleEntriesFromBuffer();
}));
}
Futures.allOf(futures2);
evictAll(testMetadataStore);
val futures3 = new ArrayList<CompletableFuture<Void>>();
for (int i = 0; i < 100; i++) {
futures.add(CompletableFuture.runAsync(() -> {
readKey(KEY1, VALUE1);
readKey(KEY2, VALUE2);
readKey(KEY4, VALUE4);
}));
}
Futures.allOf(futures3);
}
use of io.pravega.segmentstore.storage.mocks.InMemoryMetadataStore in project pravega by pravega.
the class ChunkMetadataStoreTests method setUp.
@Before
public void setUp() throws Exception {
super.before();
metadataStore = new InMemoryMetadataStore(ChunkedSegmentStorageConfig.DEFAULT_CONFIG, executorService());
}
Aggregations