Search in sources :

Example 1 with ZKScope

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

the class ZKStreamMetadataStore method createStream.

@Override
public CompletableFuture<CreateStreamResponse> createStream(String scope, String name, StreamConfiguration configuration, long createTimestamp, OperationContext ctx, Executor executor) {
    OperationContext context = getOperationContext(ctx);
    ZKScope zkScope = (ZKScope) getScope(scope, context);
    ZKStream zkStream = (ZKStream) getStream(scope, name, context);
    return super.createStream(scope, name, configuration, createTimestamp, context, executor).thenCompose(status -> zkScope.getNextStreamPosition().thenCompose(zkStream::createStreamPositionNodeIfAbsent).thenCompose(v -> zkStream.getStreamPosition()).thenCompose(id -> zkScope.addStreamToScope(name, id)).thenApply(x -> status));
}
Also used : ZKScope(io.pravega.controller.store.ZKScope) Getter(lombok.Getter) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) BitConverter(io.pravega.common.util.BitConverter) ArrayList(java.util.ArrayList) ZKPaths(org.apache.curator.utils.ZKPaths) TagLogger(io.pravega.common.tracing.TagLogger) AccessLevel(lombok.AccessLevel) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Executor(java.util.concurrent.Executor) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Version(io.pravega.controller.store.Version) Config(io.pravega.controller.util.Config) Int96(io.pravega.common.lang.Int96) Preconditions(com.google.common.base.Preconditions) ZKHostIndex(io.pravega.controller.store.index.ZKHostIndex) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Futures(io.pravega.common.concurrent.Futures) ZKScope(io.pravega.controller.store.ZKScope)

Example 2 with ZKScope

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

the class ZKStreamMetadataStore method deleteStream.

@Override
public CompletableFuture<Void> deleteStream(String scope, String name, OperationContext context, Executor executor) {
    ZKScope zkScope = (ZKScope) getScope(scope, context);
    ZKStream zkStream = (ZKStream) getStream(scope, name, context);
    return Futures.exceptionallyExpecting(zkStream.getStreamPosition().thenCompose(id -> zkScope.removeStreamFromScope(name, id)), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException, null).thenCompose(v -> super.deleteStream(scope, name, context, executor));
}
Also used : ZKScope(io.pravega.controller.store.ZKScope) Getter(lombok.Getter) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) BitConverter(io.pravega.common.util.BitConverter) ArrayList(java.util.ArrayList) ZKPaths(org.apache.curator.utils.ZKPaths) TagLogger(io.pravega.common.tracing.TagLogger) AccessLevel(lombok.AccessLevel) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Executor(java.util.concurrent.Executor) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ZKStoreHelper(io.pravega.controller.store.ZKStoreHelper) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Version(io.pravega.controller.store.Version) Config(io.pravega.controller.util.Config) Int96(io.pravega.common.lang.Int96) Preconditions(com.google.common.base.Preconditions) ZKHostIndex(io.pravega.controller.store.index.ZKHostIndex) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Futures(io.pravega.common.concurrent.Futures) ZKScope(io.pravega.controller.store.ZKScope)

Example 3 with ZKScope

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

the class ZKStreamMetadataStoreTest method listStreamsInScopes.

@Test
public void listStreamsInScopes() throws Exception {
    // list stream in scope
    String scope = "scopeList";
    ZKStreamMetadataStore zkStore = spy((ZKStreamMetadataStore) store);
    store.createScope(scope, null, executor).get();
    LinkedBlockingQueue<Integer> nextPositionList = new LinkedBlockingQueue<>();
    nextPositionList.put(0);
    nextPositionList.put(2);
    nextPositionList.put(10000);
    nextPositionList.put((int) Math.pow(10, 8));
    nextPositionList.put((int) Math.pow(10, 9));
    ZKScope myScope = spy((ZKScope) zkStore.getScope(scope, null));
    doAnswer(x -> CompletableFuture.completedFuture(nextPositionList.poll())).when(myScope).getNextStreamPosition();
    doAnswer(x -> myScope).when(zkStore).getScope(scope, null);
    String stream1 = "stream1";
    String stream2 = "stream2";
    String stream3 = "stream3";
    String stream4 = "stream4";
    String stream5 = "stream5";
    // add three streams and then list them. We should get 2 + 1 + 0
    zkStore.createStream(scope, stream1, configuration1, System.currentTimeMillis(), null, executor).get();
    zkStore.setState(scope, stream1, State.ACTIVE, null, executor).get();
    zkStore.createStream(scope, stream2, configuration2, System.currentTimeMillis(), null, executor).get();
    zkStore.setState(scope, stream2, State.ACTIVE, null, executor).get();
    zkStore.createStream(scope, stream3, configuration2, System.currentTimeMillis(), null, executor).get();
    zkStore.setState(scope, stream3, State.ACTIVE, null, executor).get();
    Pair<List<String>, String> streamInScope = store.listStream(scope, "", 2, executor, null).get();
    assertEquals("List streams in scope", 2, streamInScope.getKey().size());
    assertTrue(streamInScope.getKey().contains(stream1));
    assertTrue(streamInScope.getKey().contains(stream2));
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
    streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
    assertEquals("List streams in scope", 1, streamInScope.getKey().size());
    assertTrue(streamInScope.getKey().contains(stream3));
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
    streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
    assertEquals("List streams in scope", 0, streamInScope.getKey().size());
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
    // add 4th stream
    zkStore.createStream(scope, stream4, configuration2, System.currentTimeMillis(), null, executor).get();
    zkStore.setState(scope, stream4, State.ACTIVE, null, executor).get();
    // list on previous token we should get 1 entry
    streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
    assertEquals("List streams in scope", 1, streamInScope.getKey().size());
    assertTrue(streamInScope.getKey().contains(stream4));
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
    // add 5th stream
    zkStore.createStream(scope, stream5, configuration2, System.currentTimeMillis(), null, executor).get();
    zkStore.setState(scope, stream5, State.ACTIVE, null, executor).get();
    // delete stream 1
    store.deleteStream(scope, stream1, null, executor).join();
    // start listing with empty/default continuation token
    streamInScope = store.listStream(scope, "", 2, executor, null).get();
    assertEquals("List streams in scope", 2, streamInScope.getKey().size());
    assertTrue(streamInScope.getKey().contains(stream2));
    assertTrue(streamInScope.getKey().contains(stream3));
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
    streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
    assertEquals("List streams in scope", 2, streamInScope.getKey().size());
    assertTrue(streamInScope.getKey().contains(stream4));
    assertTrue(streamInScope.getKey().contains(stream5));
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
    // delete stream 3
    store.deleteStream(scope, stream3, null, executor).join();
    // start listing with empty/default continuation token
    streamInScope = store.listStream(scope, "", 2, executor, null).get();
    assertEquals("List streams in scope", 2, streamInScope.getKey().size());
    assertTrue(streamInScope.getKey().contains(stream2));
    assertTrue(streamInScope.getKey().contains(stream4));
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
    streamInScope = store.listStream(scope, streamInScope.getValue(), 2, executor, null).get();
    assertEquals("List streams in scope", 1, streamInScope.getKey().size());
    assertTrue(streamInScope.getKey().contains(stream5));
    assertFalse(Strings.isNullOrEmpty(streamInScope.getValue()));
}
Also used : List(java.util.List) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ZKScope(io.pravega.controller.store.ZKScope) Test(org.junit.Test)

Aggregations

ZKScope (io.pravega.controller.store.ZKScope)3 List (java.util.List)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions (com.google.common.base.Preconditions)2 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Exceptions (io.pravega.common.Exceptions)2 Futures (io.pravega.common.concurrent.Futures)2 Int96 (io.pravega.common.lang.Int96)2 TagLogger (io.pravega.common.tracing.TagLogger)2 BitConverter (io.pravega.common.util.BitConverter)2 Version (io.pravega.controller.store.Version)2 ZKStoreHelper (io.pravega.controller.store.ZKStoreHelper)2 ZKHostIndex (io.pravega.controller.store.index.ZKHostIndex)2 Config (io.pravega.controller.util.Config)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionException (java.util.concurrent.CompletionException)2