use of io.pravega.segmentstore.contracts.Attributes.ROLLOVER_SIZE in project pravega by pravega.
the class PravegaRequestProcessor method createSegment.
@Override
public void createSegment(CreateSegment createStreamSegment) {
Timer timer = new Timer();
final String operation = "createSegment";
if (createStreamSegment.getRolloverSizeBytes() < 0) {
log.warn("Segment rollover size bytes cannot be less than 0, actual is {}, fall back to default value", createStreamSegment.getRolloverSizeBytes());
}
final long rolloverSizeBytes = createStreamSegment.getRolloverSizeBytes() < 0 ? 0 : createStreamSegment.getRolloverSizeBytes();
Collection<AttributeUpdate> attributes = Arrays.asList(new AttributeUpdate(SCALE_POLICY_TYPE, AttributeUpdateType.Replace, ((Byte) createStreamSegment.getScaleType()).longValue()), new AttributeUpdate(SCALE_POLICY_RATE, AttributeUpdateType.Replace, ((Integer) createStreamSegment.getTargetRate()).longValue()), new AttributeUpdate(ROLLOVER_SIZE, AttributeUpdateType.Replace, rolloverSizeBytes), new AttributeUpdate(CREATION_TIME, AttributeUpdateType.None, System.currentTimeMillis()));
if (!verifyToken(createStreamSegment.getSegment(), createStreamSegment.getRequestId(), createStreamSegment.getDelegationToken(), operation)) {
return;
}
log.info(createStreamSegment.getRequestId(), "Creating stream segment {}.", createStreamSegment);
segmentStore.createStreamSegment(createStreamSegment.getSegment(), SegmentType.STREAM_SEGMENT, attributes, TIMEOUT).thenAccept(v -> connection.send(new SegmentCreated(createStreamSegment.getRequestId(), createStreamSegment.getSegment()))).whenComplete((res, e) -> {
if (e == null) {
statsRecorder.createSegment(createStreamSegment.getSegment(), createStreamSegment.getScaleType(), createStreamSegment.getTargetRate(), timer.getElapsed());
} else {
handleException(createStreamSegment.getRequestId(), createStreamSegment.getSegment(), operation, e);
}
});
}
Aggregations