Search in sources :

Example 6 with TableSegmentKey

use of io.pravega.client.tables.impl.TableSegmentKey in project pravega by pravega.

the class SegmentHelper method readTableKeys.

public CompletableFuture<HashTableIteratorItem<TableSegmentKey>> readTableKeys(final String tableName, final PravegaNodeUri uri, final int suggestedKeyCount, final HashTableIteratorItem.State state, final String delegationToken, final long clientRequestId) {
    final WireCommandType type = WireCommandType.READ_TABLE_KEYS;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    final HashTableIteratorItem.State token = (state == null) ? HashTableIteratorItem.State.EMPTY : state;
    WireCommands.TableIteratorArgs args = new WireCommands.TableIteratorArgs(token.getToken(), Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
    WireCommands.ReadTableKeys request = new WireCommands.ReadTableKeys(requestId, tableName, delegationToken, suggestedKeyCount, args);
    return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
        handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTableKeys.class, type);
        WireCommands.TableKeysRead tableKeysRead = (WireCommands.TableKeysRead) rpl;
        final HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(tableKeysRead.getContinuationToken());
        final List<TableSegmentKey> keys = tableKeysRead.getKeys().stream().map(k -> TableSegmentKey.versioned(k.getData(), k.getKeyVersion())).collect(Collectors.toList());
        return new HashTableIteratorItem<>(newState, keys);
    });
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Unpooled(io.netty.buffer.Unpooled) TagLogger(io.pravega.common.tracing.TagLogger) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) Request(io.pravega.shared.protocol.netty.Request) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Config(io.pravega.controller.util.Config) Futures(io.pravega.common.concurrent.Futures) TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) ModelHelper(io.pravega.client.control.impl.ModelHelper) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) RawClient(io.pravega.client.connection.impl.RawClient) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) NameUtils.getQualifiedStreamSegmentName(io.pravega.shared.NameUtils.getQualifiedStreamSegmentName) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) Host(io.pravega.common.cluster.Host) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) AuthenticationException(io.pravega.auth.AuthenticationException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) WireCommand(io.pravega.shared.protocol.netty.WireCommand) AbstractMap(java.util.AbstractMap) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) NameUtils.getTransactionNameFromId(io.pravega.shared.NameUtils.getTransactionNameFromId) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) WireCommands(io.pravega.shared.protocol.netty.WireCommands) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem)

Example 7 with TableSegmentKey

use of io.pravega.client.tables.impl.TableSegmentKey in project pravega by pravega.

the class SegmentHelper method readTable.

public CompletableFuture<List<TableSegmentEntry>> readTable(final String tableName, final PravegaNodeUri uri, final List<TableSegmentKey> keys, String delegationToken, final long clientRequestId) {
    final WireCommandType type = WireCommandType.READ_TABLE;
    // the version is always NO_VERSION as read returns the latest version of value.
    List<WireCommands.TableKey> keyList = keys.stream().map(k -> new WireCommands.TableKey(k.getKey(), k.getVersion().getSegmentVersion())).collect(Collectors.toList());
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.ReadTable request = new WireCommands.ReadTable(requestId, tableName, delegationToken, keyList);
    return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
        handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTable.class, type);
        return ((WireCommands.TableRead) rpl).getEntries().getEntries().stream().map(this::convertFromWireCommand).collect(Collectors.toList());
    });
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Unpooled(io.netty.buffer.Unpooled) TagLogger(io.pravega.common.tracing.TagLogger) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) Request(io.pravega.shared.protocol.netty.Request) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Config(io.pravega.controller.util.Config) Futures(io.pravega.common.concurrent.Futures) TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) ModelHelper(io.pravega.client.control.impl.ModelHelper) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) RawClient(io.pravega.client.connection.impl.RawClient) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) NameUtils.getQualifiedStreamSegmentName(io.pravega.shared.NameUtils.getQualifiedStreamSegmentName) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) Host(io.pravega.common.cluster.Host) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) AuthenticationException(io.pravega.auth.AuthenticationException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) WireCommand(io.pravega.shared.protocol.netty.WireCommand) AbstractMap(java.util.AbstractMap) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) NameUtils.getTransactionNameFromId(io.pravega.shared.NameUtils.getTransactionNameFromId) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 8 with TableSegmentKey

use of io.pravega.client.tables.impl.TableSegmentKey in project pravega by pravega.

the class PravegaTablesScopeTest method testRemoveTagsUnderScope.

@Test(timeout = 5000)
@SuppressWarnings("unchecked")
public void testRemoveTagsUnderScope() {
    // Setup Mocks.
    GrpcAuthHelper authHelper = mock(GrpcAuthHelper.class);
    when(authHelper.retrieveMasterToken()).thenReturn("");
    SegmentHelper segmentHelper = mock(SegmentHelper.class);
    PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executorService());
    PravegaTablesScope tablesScope = spy(new PravegaTablesScope(scope, storeHelper));
    doReturn(CompletableFuture.completedFuture(indexTable)).when(tablesScope).getAllStreamTagsInScopeTableNames(stream, context);
    // Simulate an empty value being returned.
    TableSegmentEntry entry = TableSegmentEntry.versioned(tagBytes, new byte[0], 1L);
    when(segmentHelper.readTable(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(entry)));
    when(segmentHelper.updateTableEntries(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(TableSegmentKeyVersion.from(2L))));
    when(segmentHelper.removeTableKeys(eq(indexTable), any(), anyString(), anyLong())).thenAnswer(invocation -> {
        // Capture the key value sent during removeTableKeys.
        keySnapshot = (List<TableSegmentKey>) invocation.getArguments()[1];
        return CompletableFuture.completedFuture(null);
    });
    // Invoke the removeTags method.
    tablesScope.removeTagsUnderScope(stream, Set.of(tag), context).join();
    // Verify if correctly detect that the data is empty and the entry is cleaned up.
    verify(segmentHelper, times(1)).removeTableKeys(eq(indexTable), eq(keySnapshot), anyString(), anyLong());
    // Verify if the version number is as expected.
    assertEquals(2L, keySnapshot.get(0).getVersion().getSegmentVersion());
}
Also used : TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) SegmentHelper(io.pravega.controller.server.SegmentHelper) Test(org.junit.Test)

Aggregations

TableSegmentKey (io.pravega.client.tables.impl.TableSegmentKey)8 HashTableIteratorItem (io.pravega.client.tables.impl.HashTableIteratorItem)7 List (java.util.List)7 TableSegmentEntry (io.pravega.client.tables.impl.TableSegmentEntry)6 Unpooled (io.netty.buffer.Unpooled)5 TableSegmentKeyVersion (io.pravega.client.tables.impl.TableSegmentKeyVersion)5 Futures (io.pravega.common.concurrent.Futures)5 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)4 Exceptions (io.pravega.common.Exceptions)4 TagLogger (io.pravega.common.tracing.TagLogger)4 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)4 TxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)4 WireCommandType (io.pravega.shared.protocol.netty.WireCommandType)4 WireCommands (io.pravega.shared.protocol.netty.WireCommands)4 AbstractMap (java.util.AbstractMap)4 CompletableFuture (java.util.concurrent.CompletableFuture)4