Search in sources :

Example 1 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class ZKCounterTest method testCounterConcurrentUpdates.

@Test(timeout = 30000)
public void testCounterConcurrentUpdates() {
    ZKStoreHelper storeHelper = spy(new ZKStoreHelper(cli, executor));
    storeHelper.createZNodeIfNotExist("/store/scope").join();
    ZkInt96Counter counter1 = spy(new ZkInt96Counter(storeHelper));
    ZkInt96Counter counter2 = spy(new ZkInt96Counter(storeHelper));
    ZkInt96Counter counter3 = spy(new ZkInt96Counter(storeHelper));
    // first call should get the new range from store
    Int96 counter = counter1.getNextCounter().join();
    // verify that the generated counter is from new range
    assertEquals(0, counter.getMsb());
    assertEquals(1L, counter.getLsb());
    assertEquals(counter1.getCounterForTesting(), counter);
    Int96 limit = counter1.getLimitForTesting();
    assertEquals(ZkInt96Counter.COUNTER_RANGE, limit.getLsb());
    counter3.getRefreshFuture().join();
    assertEquals(ZkInt96Counter.COUNTER_RANGE, counter3.getCounterForTesting().getLsb());
    assertEquals(ZkInt96Counter.COUNTER_RANGE * 2, counter3.getLimitForTesting().getLsb());
    counter2.getRefreshFuture().join();
    assertEquals(ZkInt96Counter.COUNTER_RANGE * 2, counter2.getCounterForTesting().getLsb());
    assertEquals(ZkInt96Counter.COUNTER_RANGE * 3, counter2.getLimitForTesting().getLsb());
    counter1.getRefreshFuture().join();
    assertEquals(ZkInt96Counter.COUNTER_RANGE * 3, counter1.getCounterForTesting().getLsb());
    assertEquals(ZkInt96Counter.COUNTER_RANGE * 4, counter1.getLimitForTesting().getLsb());
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Int96(io.pravega.common.lang.Int96) Test(org.junit.Test)

Example 2 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class ZKStreamMetadataStoreTest method testCommittedTxnGc.

@Test
public void testCommittedTxnGc() {
    String scope = "scopeGC";
    String stream = "stream";
    store.createScope(scope, null, executor).join();
    StreamConfiguration config = StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build();
    store.createStream(scope, stream, config, System.currentTimeMillis(), null, executor).join();
    store.setState(scope, stream, State.ACTIVE, null, executor).join();
    ZKStreamMetadataStore zkStore = (ZKStreamMetadataStore) store;
    ZKStoreHelper storeHelper = zkStore.getStoreHelper();
    UUID txnId = new UUID(0L, 0L);
    createAndCommitTxn(txnId, scope, stream).join();
    // getTxnStatus
    TxnStatus status = store.transactionStatus(scope, stream, txnId, null, executor).join();
    assertEquals(TxnStatus.COMMITTED, status);
    // verify txns are created in a new batch
    List<Integer> batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).collect(Collectors.toList());
    assertEquals(1, batches.size());
    int firstBatch = batches.get(0);
    // create another transaction after introducing a delay greater than gcperiod so that it gets created in a new batch
    Futures.delayedFuture(() -> createAndCommitTxn(new UUID(0L, 1L), scope, stream), Duration.ofSeconds(2).toMillis(), executor).join();
    // verify that this gets created in a new batch
    batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
    assertEquals(2, batches.size());
    assertTrue(batches.contains(firstBatch));
    int secondBatch = batches.stream().max(Integer::compare).get();
    assertTrue(secondBatch > firstBatch);
    // let one more gc cycle run and verify that these two batches are not cleaned up.
    batches = Futures.delayedFuture(() -> storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH), Duration.ofSeconds(2).toMillis(), executor).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
    assertEquals(2, batches.size());
    // create third transaction after introducing a delay greater than gcperiod so that it gets created in a new batch
    Futures.delayedFuture(() -> createAndCommitTxn(new UUID(0L, 2L), scope, stream), Duration.ofSeconds(2).toMillis(), executor).join();
    // Verify that a new batch is created here.
    batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
    int thirdBatch = batches.stream().max(Long::compare).get();
    assertTrue(thirdBatch > secondBatch);
    // wait for more than TTL, then do another getTxnStatus
    status = Futures.delayedFuture(() -> store.transactionStatus(scope, stream, txnId, null, executor), Duration.ofSeconds(2).toMillis(), executor).join();
    assertEquals(TxnStatus.UNKNOWN, status);
    // verify that only 2 latest batches remain and that firstBatch has been GC'd
    batches = storeHelper.getChildren(ZKStreamMetadataStore.COMPLETED_TX_BATCH_ROOT_PATH).join().stream().map(Integer::parseInt).sorted().collect(Collectors.toList());
    assertEquals(2, batches.size());
    assertFalse(batches.contains(firstBatch));
    assertTrue(batches.contains(secondBatch));
    assertTrue(batches.contains(thirdBatch));
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class PravegaTablesStreamTest method setup.

@Override
public void setup() throws Exception {
    SegmentHelper segmentHelper = SegmentHelperMock.getSegmentHelperMockForTables(executor);
    GrpcAuthHelper authHelper = GrpcAuthHelper.getDisabledAuthHelper();
    storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executor);
    orderer = new ZkOrderedStore("txnOrderer", new ZKStoreHelper(PRAVEGA_ZK_CURATOR_RESOURCE.client, executor), executor);
    store = new PravegaTablesStreamMetadataStore(segmentHelper, PRAVEGA_ZK_CURATOR_RESOURCE.client, executor, Duration.ofSeconds(1), authHelper);
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) PravegaTablesStoreHelper(io.pravega.controller.store.PravegaTablesStoreHelper) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) SegmentHelper(io.pravega.controller.server.SegmentHelper)

Example 4 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class StreamTest method testZkCreateStream.

@Test(timeout = 10000)
public void testZkCreateStream() throws ExecutionException, InterruptedException {
    ZKStoreHelper zkStoreHelper = new ZKStoreHelper(PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService());
    ZkOrderedStore orderer = new ZkOrderedStore("txn", zkStoreHelper, executorService());
    ZKStream zkStream = new ZKStream("test1", "test1", zkStoreHelper, executorService(), orderer);
    testStream(zkStream);
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Test(org.junit.Test)

Example 5 with ZKStoreHelper

use of io.pravega.controller.store.ZKStoreHelper in project pravega by pravega.

the class StreamTest method testConcurrentGetSuccessorScaleZk.

@Test(timeout = 10000)
public void testConcurrentGetSuccessorScaleZk() throws Exception {
    try (final StreamMetadataStore store = new ZKStreamMetadataStore(PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService())) {
        ZKStoreHelper zkStoreHelper = new ZKStoreHelper(PRAVEGA_ZK_CURATOR_RESOURCE.client, executorService());
        testConcurrentGetSuccessorScale(store, (x, y) -> new ZKStream(x, y, zkStoreHelper, executorService(), orderer));
    }
}
Also used : ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) Test(org.junit.Test)

Aggregations

ZKStoreHelper (io.pravega.controller.store.ZKStoreHelper)12 Test (org.junit.Test)9 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)3 TestingServerStarter (io.pravega.test.common.TestingServerStarter)3 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)2 Int96 (io.pravega.common.lang.Int96)2 TestOperationContext (io.pravega.controller.store.TestOperationContext)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 RetryOneTime (org.apache.curator.retry.RetryOneTime)2 Before (org.junit.Before)2 ExecutorServiceHelpers (io.pravega.common.concurrent.ExecutorServiceHelpers)1 Futures (io.pravega.common.concurrent.Futures)1 SegmentHelper (io.pravega.controller.server.SegmentHelper)1 GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)1 PravegaTablesStoreHelper (io.pravega.controller.store.PravegaTablesStoreHelper)1 VersionedMetadata (io.pravega.controller.store.VersionedMetadata)1 ActiveTxnRecord (io.pravega.controller.store.stream.records.ActiveTxnRecord)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1