use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method mergeTxnSegments.
public CompletableFuture<List<Long>> mergeTxnSegments(final String scope, final String stream, final long targetSegmentId, final long sourceSegmentId, final List<UUID> txId, final String delegationToken, final long clientRequestId) {
Preconditions.checkArgument(getSegmentNumber(targetSegmentId) == getSegmentNumber(sourceSegmentId));
final Controller.NodeUri uri = getSegmentUri(scope, stream, sourceSegmentId);
final String qualifiedNameTarget = getQualifiedStreamSegmentName(scope, stream, targetSegmentId);
final List<String> transactionNames = txId.stream().map(x -> getTransactionName(scope, stream, sourceSegmentId, x)).collect(Collectors.toList());
final WireCommandType type = WireCommandType.MERGE_SEGMENTS_BATCH;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.MergeSegmentsBatch request = new WireCommands.MergeSegmentsBatch(requestId, qualifiedNameTarget, transactionNames, delegationToken);
return sendRequest(connection, clientRequestId, request).thenApply(r -> {
handleReply(clientRequestId, r, connection, qualifiedNameTarget, WireCommands.MergeSegmentsBatch.class, type);
return ((WireCommands.SegmentsBatchMerged) r).getNewTargetWriteOffset();
});
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method abortTransaction.
public CompletableFuture<TxnStatus> abortTransaction(final String scope, final String stream, final long segmentId, final UUID txId, final String delegationToken, final long clientRequestId) {
final String transactionName = getTransactionName(scope, stream, segmentId, txId);
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
final WireCommandType type = WireCommandType.DELETE_SEGMENT;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.DeleteSegment request = new WireCommands.DeleteSegment(requestId, transactionName, delegationToken);
return sendRequest(connection, clientRequestId, request).thenAccept(r -> handleReply(clientRequestId, r, connection, transactionName, WireCommands.DeleteSegment.class, type)).thenApply(v -> TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method getSegmentInfo.
public CompletableFuture<WireCommands.StreamSegmentInfo> getSegmentInfo(String qualifiedName, PravegaNodeUri uri, String delegationToken, long clientRequestId) {
final WireCommandType type = WireCommandType.GET_STREAM_SEGMENT_INFO;
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.GetStreamSegmentInfo request = new WireCommands.GetStreamSegmentInfo(requestId, qualifiedName, delegationToken);
return sendRequest(connection, clientRequestId, request).thenApply(r -> {
handleReply(clientRequestId, r, connection, qualifiedName, WireCommands.GetStreamSegmentInfo.class, type);
assert r instanceof WireCommands.StreamSegmentInfo;
return (WireCommands.StreamSegmentInfo) r;
});
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentHelper method createTableSegment.
/**
* This method sends a WireCommand to create a table segment.
*
* @param tableName Qualified table name.
* @param delegationToken The token to be presented to the segmentstore.
* @param clientRequestId Request id.
* @param sortedTableSegment Boolean flag indicating if the Table Segment should be created in sorted order.
* @param keyLength Key Length. If 0, a Hash Table Segment (Variable Key Length) will be created, otherwise
* a Fixed-Key-Length Table Segment will be created with this value for the key length.
* @param rolloverSizeBytes The rollover size of segment in LTS.
* @return A CompletableFuture that, when completed normally, will indicate the table segment creation completed
* successfully. If the operation failed, the future will be failed with the causing exception. If the exception
* can be retried then the future will be failed with {@link WireCommandFailedException}.
*/
public CompletableFuture<Void> createTableSegment(final String tableName, String delegationToken, final long clientRequestId, final boolean sortedTableSegment, final int keyLength, final long rolloverSizeBytes) {
final Controller.NodeUri uri = getTableUri(tableName);
final WireCommandType type = WireCommandType.CREATE_TABLE_SEGMENT;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
// All Controller Metadata Segments are non-sorted.
return sendRequest(connection, clientRequestId, new WireCommands.CreateTableSegment(requestId, tableName, sortedTableSegment, keyLength, delegationToken, rolloverSizeBytes)).thenAccept(rpl -> handleReply(clientRequestId, rpl, connection, tableName, WireCommands.CreateTableSegment.class, type));
}
use of io.pravega.client.connection.impl.RawClient 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;
});
}
Aggregations