Search in sources :

Example 6 with HashTableIteratorItem

use of io.pravega.client.tables.impl.HashTableIteratorItem 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)

Aggregations

HashTableIteratorItem (io.pravega.client.tables.impl.HashTableIteratorItem)6 List (java.util.List)6 TableSegmentKey (io.pravega.client.tables.impl.TableSegmentKey)5 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)5 TableSegmentEntry (io.pravega.client.tables.impl.TableSegmentEntry)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Preconditions (com.google.common.base.Preconditions)3 Unpooled (io.netty.buffer.Unpooled)3 CommandArgs (io.pravega.cli.admin.CommandArgs)3 AdminSegmentHelper (io.pravega.cli.admin.utils.AdminSegmentHelper)3 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)3 TableSegmentKeyVersion (io.pravega.client.tables.impl.TableSegmentKeyVersion)3 Futures (io.pravega.common.concurrent.Futures)3 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)3 TxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)3 WireCommandType (io.pravega.shared.protocol.netty.WireCommandType)3 WireCommands (io.pravega.shared.protocol.netty.WireCommands)3 Cleanup (lombok.Cleanup)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3