use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class AdminSegmentHelper method getTableSegmentInfo.
/**
* This method sends a WireCommand to get table segment info for the given table segment name.
*
* @param qualifiedName StreamSegmentName
* @param uri The uri of the Segment Store instance.
* @param delegationToken The token to be presented to the Segment Store.
* @return A CompletableFuture that will return the table segment info as a WireCommand.
*/
public CompletableFuture<WireCommands.TableSegmentInfo> getTableSegmentInfo(String qualifiedName, PravegaNodeUri uri, String delegationToken) {
final WireCommandType type = WireCommandType.GET_TABLE_SEGMENT_INFO;
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.GetTableSegmentInfo request = new WireCommands.GetTableSegmentInfo(requestId, qualifiedName, delegationToken);
return sendRequest(connection, requestId, request).thenApply(r -> {
handleReply(requestId, r, connection, qualifiedName, WireCommands.GetTableSegmentInfo.class, type);
assert r instanceof WireCommands.TableSegmentInfo;
return (WireCommands.TableSegmentInfo) r;
});
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentMetadataClientImpl method closeConnection.
private void closeConnection(Reply badReply) {
log.info("Closing connection as a result of receiving: {}", badReply);
RawClient c;
synchronized (lock) {
c = client;
client = null;
}
if (c != null) {
try {
c.close();
} catch (Exception e) {
log.warn("Exception tearing down connection: ", e);
}
}
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentMetadataClientImpl method closeConnection.
private void closeConnection(Throwable exceptionToInflightRequests) {
log.debug("Closing connection with exception: {}", exceptionToInflightRequests.getMessage());
RawClient c;
synchronized (lock) {
c = client;
client = null;
}
if (c != null) {
try {
c.close();
} catch (Exception e) {
log.warn("Exception tearing down connection: ", e);
}
}
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentMetadataClientImpl method sealSegmentAsync.
private CompletableFuture<SegmentSealed> sealSegmentAsync(Segment segment, DelegationTokenProvider tokenProvider) {
log.trace("Sealing segment: {}", segment);
RawClient connection = getConnection();
long requestId = connection.getFlow().getNextSequenceNumber();
return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new SealSegment(requestId, segment.getScopedName(), token))).thenApply(r -> transformReply(r, SegmentSealed.class));
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class ConditionalOutputStreamImpl method write.
@Override
public boolean write(ByteBuffer data, long expectedOffset) throws SegmentSealedException {
Exceptions.checkNotClosed(closed.get(), this);
synchronized (lock) {
// Used to preserver order.
long appendSequence = requestIdGenerator.get();
return retrySchedule.retryWhen(e -> {
Throwable cause = Exceptions.unwrap(e);
boolean hasTokenExpired = cause instanceof TokenExpiredException;
if (hasTokenExpired) {
this.tokenProvider.signalTokenExpired();
}
return cause instanceof Exception && (hasTokenExpired || cause instanceof ConnectionFailedException);
}).run(() -> {
if (client == null || client.isClosed()) {
client = new RawClient(controller, connectionPool, segmentId);
long requestId = client.getFlow().getNextSequenceNumber();
log.debug("Setting up appends on segment {} for ConditionalOutputStream with writer id {}", segmentId, writerId);
CompletableFuture<Reply> reply = tokenProvider.retrieveToken().thenCompose(token -> {
SetupAppend setup = new SetupAppend(requestId, writerId, segmentId.getScopedName(), token);
return client.sendRequest(requestId, setup);
});
AppendSetup appendSetup = transformAppendSetup(reply.join());
if (appendSetup.getLastEventNumber() >= appendSequence) {
return true;
}
}
long requestId = client.getFlow().getNextSequenceNumber();
val request = new ConditionalAppend(writerId, appendSequence, expectedOffset, new Event(Unpooled.wrappedBuffer(data)), requestId);
val reply = client.sendRequest(requestId, request);
return transformDataAppended(reply.join());
});
}
}
Aggregations