use of io.pravega.client.connection.impl.ConnectionPool in project pravega by pravega.
the class AdminCommand method instantiateAdminSegmentHelper.
@VisibleForTesting
public AdminSegmentHelper instantiateAdminSegmentHelper(CuratorFramework zkClient) {
HostControllerStore hostStore = createHostControllerStore(zkClient);
ConnectionPool pool = createConnectionPool();
return new AdminSegmentHelper(pool, hostStore, pool.getInternalExecutor());
}
use of io.pravega.client.connection.impl.ConnectionPool in project pravega by pravega.
the class LargeEventWriter method writeLargeEvent.
/**
* Write the provided list of events (atomically) to the provided segment.
*
* @param segment The segment to write to
* @param events The events to append
* @param tokenProvider A token provider
* @param config Used for retry configuration parameters
* @throws NoSuchSegmentException If the provided segment does not exit.
* @throws SegmentSealedException If the segment is sealed.
* @throws AuthenticationException If the token can't be used for this segment.
* @throws UnsupportedOperationException If the server does not support large events.
*/
public void writeLargeEvent(Segment segment, List<ByteBuffer> events, DelegationTokenProvider tokenProvider, EventWriterConfig config) throws NoSuchSegmentException, AuthenticationException, SegmentSealedException {
List<ByteBuf> payloads = createBufs(events);
int attempts = 1 + Math.max(0, config.getRetryAttempts());
Retry.withExpBackoff(config.getInitialBackoffMillis(), config.getBackoffMultiple(), attempts, config.getMaxBackoffMillis()).retryWhen(t -> {
Throwable ex = Exceptions.unwrap(t);
if (ex instanceof ConnectionFailedException) {
log.info("Connection failure while sending large event: {}. Retrying", ex.getMessage());
return true;
} else if (ex instanceof TokenExpiredException) {
tokenProvider.signalTokenExpired();
log.info("Authentication token expired while writing large event to segment {}. Retrying", segment);
return true;
} else {
return false;
}
}).run(() -> {
@Cleanup RawClient client = new RawClient(controller, connectionPool, segment);
write(segment, payloads, client, tokenProvider);
return null;
});
}
use of io.pravega.client.connection.impl.ConnectionPool in project pravega by pravega.
the class SegmentHelper method readTableEntries.
public CompletableFuture<HashTableIteratorItem<TableSegmentEntry>> readTableEntries(final String tableName, final PravegaNodeUri uri, final int suggestedEntryCount, final HashTableIteratorItem.State state, final String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.READ_TABLE_ENTRIES;
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.ReadTableEntries request = new WireCommands.ReadTableEntries(requestId, tableName, delegationToken, suggestedEntryCount, args);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTableEntries.class, type);
WireCommands.TableEntriesRead tableEntriesRead = (WireCommands.TableEntriesRead) rpl;
final HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(tableEntriesRead.getContinuationToken());
final List<TableSegmentEntry> entries = tableEntriesRead.getEntries().getEntries().stream().map(e -> {
WireCommands.TableKey k = e.getKey();
return TableSegmentEntry.versioned(k.getData(), e.getValue().getData(), k.getKeyVersion());
}).collect(Collectors.toList());
return new HashTableIteratorItem<>(newState, entries);
});
}
use of io.pravega.client.connection.impl.ConnectionPool 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);
});
}
use of io.pravega.client.connection.impl.ConnectionPool 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());
});
}
Aggregations