use of io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute in project pravega by pravega.
the class SegmentMetadataClientImpl method updatePropertyAsync.
private CompletableFuture<SegmentAttributeUpdated> updatePropertyAsync(UUID attributeId, long expected, long value, String delegationToken) {
long requestId = requestIdGenerator.get();
log.trace("Updating segment attribute: {}", attributeId);
RawClient connection = getConnection();
return connection.sendRequest(requestId, new UpdateSegmentAttribute(requestId, segmentId.getScopedName(), attributeId, value, expected, delegationToken)).thenApply(r -> transformReply(r, SegmentAttributeUpdated.class));
}
use of io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute in project pravega by pravega.
the class PravegaRequestProcessor method updateSegmentAttribute.
@Override
public void updateSegmentAttribute(UpdateSegmentAttribute updateSegmentAttribute) {
long requestId = updateSegmentAttribute.getRequestId();
String segmentName = updateSegmentAttribute.getSegmentName();
AttributeId attributeId = updateSegmentAttribute.getAttributeId() == null ? null : AttributeId.fromUUID(updateSegmentAttribute.getAttributeId());
long newValue = updateSegmentAttribute.getNewValue();
long expectedValue = updateSegmentAttribute.getExpectedValue();
final String operation = "updateSegmentAttribute";
if (!verifyToken(segmentName, updateSegmentAttribute.getRequestId(), updateSegmentAttribute.getDelegationToken(), operation)) {
return;
}
long trace = LoggerHelpers.traceEnter(log, operation, updateSegmentAttribute);
val update = new AttributeUpdate(attributeId, AttributeUpdateType.ReplaceIfEquals, newValue, expectedValue);
segmentStore.updateAttributes(segmentName, AttributeUpdateCollection.from(update), TIMEOUT).whenComplete((v, e) -> {
LoggerHelpers.traceLeave(log, operation, trace, e);
final Consumer<Throwable> failureHandler = t -> {
log.error(requestId, "Error (Segment = '{}', Operation = '{}')", segmentName, "handling result of " + operation, t);
connection.close();
};
if (e == null) {
invokeSafely(connection::send, new SegmentAttributeUpdated(requestId, true), failureHandler);
} else {
if (Exceptions.unwrap(e) instanceof BadAttributeUpdateException) {
log.debug("Updating segment attribute {} failed due to: {}", update, e.getMessage());
invokeSafely(connection::send, new SegmentAttributeUpdated(requestId, false), failureHandler);
} else {
handleException(requestId, segmentName, operation, e);
}
}
});
}
use of io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute in project pravega by pravega.
the class SegmentMetadataClientImpl method updatePropertyAsync.
private CompletableFuture<SegmentAttributeUpdated> updatePropertyAsync(UUID attributeId, long expected, long value) {
log.trace("Updating segment attribute: {}", attributeId);
RawClient connection = getConnection();
long requestId = connection.getFlow().getNextSequenceNumber();
return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new UpdateSegmentAttribute(requestId, segmentId.getScopedName(), attributeId, value, expected, token))).thenApply(r -> transformReply(r, SegmentAttributeUpdated.class));
}
use of io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute in project pravega by pravega.
the class FailingRequestProcessorTest method testEverythingThrows.
@Test
public void testEverythingThrows() {
assertThrows(IllegalStateException.class, () -> rp.hello(new Hello(0, 0)));
assertThrows(IllegalStateException.class, () -> rp.setupAppend(new SetupAppend(0, null, "", "")));
assertThrows(IllegalStateException.class, () -> rp.append(new Append("", null, 0, EMPTY_EVENT, 0)));
assertThrows(IllegalStateException.class, () -> rp.readSegment(new ReadSegment("", 0, 0, "", 0)));
assertThrows(IllegalStateException.class, () -> rp.updateSegmentAttribute(new UpdateSegmentAttribute(0, "", null, 0, 0, "")));
assertThrows(IllegalStateException.class, () -> rp.getSegmentAttribute(new GetSegmentAttribute(0, "", null, "")));
assertThrows(IllegalStateException.class, () -> rp.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(0, "", "")));
assertThrows(IllegalStateException.class, () -> rp.createSegment(new CreateSegment(0, "", (byte) 0, 0, "", 0)));
assertThrows(IllegalStateException.class, () -> rp.updateSegmentPolicy(new UpdateSegmentPolicy(0, "", (byte) 0, 0, "")));
assertThrows(IllegalStateException.class, () -> rp.createTableSegment(new CreateTableSegment(0, "", false, 0, "", 0)));
assertThrows(IllegalStateException.class, () -> rp.deleteTableSegment(new DeleteTableSegment(0, "", false, "")));
assertThrows(IllegalStateException.class, () -> rp.updateTableEntries(new UpdateTableEntries(0, "", "", null, 0)));
assertThrows(IllegalStateException.class, () -> rp.removeTableKeys(new RemoveTableKeys(0, "", "", null, 0)));
assertThrows(IllegalStateException.class, () -> rp.readTable(new ReadTable(0, "", "", null)));
assertThrows(IllegalStateException.class, () -> rp.readTableKeys(new ReadTableKeys(0, "", "", 0, null)));
assertThrows(IllegalStateException.class, () -> rp.readTableEntries(new ReadTableEntries(0, "", "", 0, null)));
assertThrows(IllegalStateException.class, () -> rp.mergeSegments(new MergeSegments(0, "", "", "")));
assertThrows(IllegalStateException.class, () -> rp.sealSegment(new SealSegment(0, "", "")));
assertThrows(IllegalStateException.class, () -> rp.truncateSegment(new TruncateSegment(0, "", 0, "")));
assertThrows(IllegalStateException.class, () -> rp.deleteSegment(new DeleteSegment(0, "", "")));
assertThrows(IllegalStateException.class, () -> rp.readTableEntries(new ReadTableEntries(0, "", "", 0, null)));
assertThrows(IllegalStateException.class, () -> rp.createTableSegment(new CreateTableSegment(0, "", false, 0, "", 0)));
assertThrows(IllegalStateException.class, () -> rp.readTableEntriesDelta(new ReadTableEntriesDelta(0, "", "", 0, 0)));
assertThrows(IllegalStateException.class, () -> rp.createTransientSegment(new CreateTransientSegment(0, new UUID(0, 0), "", "")));
assertThrows(IllegalStateException.class, () -> rp.connectionDropped());
}
Aggregations