/** * Creates a new instance of the BadAttributeUpdateException class. * * @param streamSegmentName The name of the StreamSegment. * @param attributeUpdate The AttributeUpdate that failed the check. * @param previousValueMissing If true, indicates that the previous value for this attempted Attribute Update was missing * and was likely the cause for the failed update. * @param errorMessage The Event Number that was given as part of the Operation. */ public BadAttributeUpdateException(String streamSegmentName, AttributeUpdate attributeUpdate, boolean previousValueMissing, String errorMessage) { super(streamSegmentName, getMessage(attributeUpdate, previousValueMissing, errorMessage)); this.previousValueMissing = previousValueMissing; this.attributeId = attributeUpdate == null ? null : attributeUpdate.getAttributeId(); }
/** * Creates a new instance of the ContainerException class. * * @param containerId The Id of the ContainerException. * @param maxSegmentCount The maximum number of active Segments per container. */ public TooManyActiveSegmentsException(int containerId, int maxSegmentCount) { super(containerId, getMessage(maxSegmentCount)); }
/** * Creates a new {@link StreamSegmentInformationBuilder} with information already populated from the given SegmentProperties. * * @param base The SegmentProperties to use as a base. * @return The Builder. */ public static StreamSegmentInformationBuilder from(SegmentProperties base) { return StreamSegmentInformation.builder() .name(base.getName()) .startOffset(base.getStartOffset()) .length(base.getLength()) .sealed(base.isSealed()) .deleted(base.isDeleted()) .lastModified(base.getLastModified()) .attributes(base.getAttributes()); }
/** * Creates a new instance of the StreamSegmentMapOperation class for a non-transaction Segment. * * @param streamSegmentProperties Information about the StreamSegment. */ public StreamSegmentMapOperation(SegmentProperties streamSegmentProperties) { this.streamSegmentId = ContainerMetadata.NO_STREAM_SEGMENT_ID; this.streamSegmentName = streamSegmentProperties.getName(); this.startOffset = streamSegmentProperties.getStartOffset(); this.length = streamSegmentProperties.getLength(); this.sealed = streamSegmentProperties.isSealed(); this.attributes = streamSegmentProperties.getAttributes(); this.pinned = false; }
@Override public CompletableFuture<SegmentProperties> getStreamSegmentInfo(String streamSegmentName, Duration timeout) { if (this.segments.contains(streamSegmentName)) { return CompletableFuture.completedFuture(StreamSegmentInformation.builder().name(streamSegmentName).build()); } else { return Futures.failedFuture(new StreamSegmentNotExistsException(streamSegmentName)); } }
private SegmentProperties getHeaderInfo(String segmentName) throws StreamSegmentException { String headerSegment = StreamSegmentNameUtils.getHeaderSegmentName(segmentName); val headerInfo = this.baseStorage.getStreamSegmentInfo(headerSegment); if (headerInfo.getLength() == 0) { // We treat empty header files as inexistent segments. throw new StreamSegmentNotExistsException(segmentName); } return headerInfo; }
@Override public synchronized SegmentProperties getSnapshot() { return StreamSegmentInformation.from(this).attributes(new HashMap<>(getAttributes())).build(); }
private void writeAttributeUpdate00(RevisionDataOutput target, AttributeUpdate au) throws IOException { target.writeUUID(au.getAttributeId()); target.writeByte(au.getUpdateType().getTypeId()); target.writeLong(au.getValue()); target.writeLong(au.getComparisonValue()); }
private AttributeUpdate readAttributeUpdate00(RevisionDataInput source) throws IOException { return new AttributeUpdate( source.readUUID(), AttributeUpdateType.get(source.readByte()), source.readLong(), source.readLong()); } }
static Collection<AttributeUpdate> createAttributes() { val result = new ArrayList<AttributeUpdate>(); long currentValue = 0; for (AttributeUpdateType ut : AttributeUpdateType.values()) { result.add(new AttributeUpdate(UUID.randomUUID(), ut, ++currentValue, currentValue)); } return result; } }
/** * Creates a new instance of the BadOffsetException class. * * @param streamSegmentName The name of the StreamSegment. * @param expectedOffset The expected offset for the Operation. * @param givenOffset The offset that was given as part of the operation. */ public BadOffsetException(String streamSegmentName, long expectedOffset, long givenOffset) { super(streamSegmentName, getMessage(expectedOffset, givenOffset)); this.expectedOffset = expectedOffset; this.givenOffset = givenOffset; }
/** * Creates a new instance of the BadSegmentTypeException class. * * @param streamSegmentName The name of the Segment. * @param expectedType The expected type for the Segment. * @param actualType The actual type. */ public BadSegmentTypeException(String streamSegmentName, String expectedType, String actualType) { super(streamSegmentName, getMessage(expectedType, actualType)); }
@Override public SegmentProperties getStreamSegmentInfo(String segmentName) throws StreamSegmentException { val handle = (RollingSegmentHandle) openRead(segmentName); return StreamSegmentInformation .builder() .name(handle.getSegmentName()) .sealed(handle.isSealed()) .length(handle.length()) .build(); }
private void write00(SegmentInfo s, RevisionDataOutput output) throws IOException { output.writeLong(s.getSegmentId()); SegmentProperties sp = s.getProperties(); output.writeUTF(sp.getName()); output.writeLong(sp.getLength()); output.writeLong(sp.getStartOffset()); output.writeBoolean(sp.isSealed()); // We only serialize Core Attributes. Extended Attributes can be retrieved from the AttributeIndex. output.writeMap(Attributes.getCoreNonNullAttributes(sp.getAttributes()), RevisionDataOutput::writeUUID, RevisionDataOutput::writeLong); }
private void writeAttributeUpdate00(RevisionDataOutput target, AttributeUpdate au) throws IOException { target.writeUUID(au.getAttributeId()); target.writeByte(au.getUpdateType().getTypeId()); target.writeLong(au.getValue()); target.writeLong(au.getComparisonValue()); }
private AttributeUpdate readAttributeUpdate00(RevisionDataInput source) throws IOException { return new AttributeUpdate( source.readUUID(), AttributeUpdateType.get(source.readByte()), source.readLong(), source.readLong()); } }
private void read00(RevisionDataInput input, SegmentInfo.SegmentInfoBuilder builder) throws IOException { builder.segmentId(input.readLong()); val infoBuilder = StreamSegmentInformation .builder() .name(input.readUTF()) .length(input.readLong()) .startOffset(input.readLong()) .sealed(input.readBoolean()); infoBuilder.attributes(input.readMap(RevisionDataInput::readUUID, RevisionDataInput::readLong)); builder.properties(infoBuilder.build()); } }
private StreamSegmentMapOperation createMap(String name) { return new StreamSegmentMapOperation(StreamSegmentInformation.builder() .name(name) .length(SEGMENT_LENGTH) .startOffset(SEGMENT_LENGTH / 2) .sealed(true) .attributes(createAttributes()) .build()); }