@Override public ImmutableDate getLastModified() { return new ImmutableDate(); }
/** * Creates a new instance of the StreamSegmentMetadata class for a StreamSegment. * * @param streamSegmentName The name of the StreamSegment. * @param streamSegmentId The Id of the StreamSegment. * @param containerId The Id of the Container this StreamSegment belongs to. * @throws IllegalArgumentException If either of the arguments are invalid. */ public StreamSegmentMetadata(String streamSegmentName, long streamSegmentId, int containerId) { Exceptions.checkNotNullOrEmpty(streamSegmentName, "streamSegmentName"); Preconditions.checkArgument(streamSegmentId != ContainerMetadata.NO_STREAM_SEGMENT_ID, "streamSegmentId"); Preconditions.checkArgument(containerId >= 0, "containerId"); this.traceObjectId = String.format("StreamSegment[%d]", streamSegmentId); this.name = streamSegmentName; this.streamSegmentId = streamSegmentId; this.containerId = containerId; this.sealed = false; this.sealedInStorage = false; this.deleted = false; this.deletedInStorage = false; this.merged = false; this.startOffset = 0; this.storageLength = -1; this.length = -1; this.coreAttributes = new HashMap<>(); this.extendedAttributes = new HashMap<>(); this.lastModified = new ImmutableDate(); this.lastUsed = 0; this.active = true; }
/** * Creates a new instance of the StreamSegmentInformation class. * * @param name The name of the StreamSegment. * @param startOffset The first available offset in this StreamSegment. * @param length The length of the StreamSegment. * @param sealed Whether the StreamSegment is sealed (for modifications). * @param deleted Whether the StreamSegment is deleted (does not exist). * @param attributes The attributes of this StreamSegment. * @param lastModified The last time the StreamSegment was modified. */ @Builder private StreamSegmentInformation(String name, long startOffset, long length, boolean sealed, boolean deleted, Map<UUID, Long> attributes, ImmutableDate lastModified) { Preconditions.checkArgument(startOffset >= 0, "startOffset must be a non-negative number."); Preconditions.checkArgument(length >= startOffset, "length must be a non-negative number and greater than startOffset."); this.name = Exceptions.checkNotNullOrEmpty(name, "name"); this.startOffset = startOffset; this.length = length; this.sealed = sealed; this.deleted = deleted; this.lastModified = lastModified == null ? new ImmutableDate() : lastModified; this.attributes = createAttributes(attributes); }
private SegmentProperties doGetStreamSegmentInfo(String streamSegmentName) throws IOException { long traceId = LoggerHelpers.traceEnter(log, "getStreamSegmentInfo", streamSegmentName); PosixFileAttributes attrs = Files.readAttributes(Paths.get(config.getRoot(), streamSegmentName), PosixFileAttributes.class); StreamSegmentInformation information = StreamSegmentInformation.builder() .name(streamSegmentName) .length(attrs.size()) .sealed(!(attrs.permissions().contains(OWNER_WRITE))) .lastModified(new ImmutableDate(attrs.creationTime().toMillis())) .build(); LoggerHelpers.traceLeave(log, "getStreamSegmentInfo", traceId, streamSegmentName); return information; }
private StreamSegmentInformation doGetStreamSegmentInfo(String streamSegmentName) { long traceId = LoggerHelpers.traceEnter(log, "getStreamSegmentInfo", streamSegmentName); S3ObjectMetadata result = client.getObjectMetadata(config.getBucket(), config.getRoot() + streamSegmentName); AccessControlList acls = client.getObjectAcl(config.getBucket(), config.getRoot() + streamSegmentName); boolean canWrite = acls.getGrants().stream().anyMatch(grant -> grant.getPermission().compareTo(Permission.WRITE) >= 0); StreamSegmentInformation information = StreamSegmentInformation.builder() .name(streamSegmentName) .length(result.getContentLength()) .sealed(!canWrite) .lastModified(new ImmutableDate(result.getLastModified().toInstant().toEpochMilli())) .build(); LoggerHelpers.traceLeave(log, "getStreamSegmentInfo", traceId, streamSegmentName); return information; }
ImmutableDate lastModified = new ImmutableDate(input.readLong()); metadata.setLastModified(lastModified); metadata.setStartOffset(input.readLong());
private void testCopyFrom(StreamSegmentMetadata baseMetadata) { baseMetadata.setStorageLength(1233); baseMetadata.updateAttributes(generateAttributes(new Random(0))); baseMetadata.setLastModified(new ImmutableDate()); baseMetadata.markDeleted(); baseMetadata.markDeletedInStorage(); baseMetadata.markInactive(); baseMetadata.setLastUsed(1545895); baseMetadata.markPinned(); // Normal metadata copy. StreamSegmentMetadata newMetadata = new StreamSegmentMetadata(baseMetadata.getName(), baseMetadata.getId(), baseMetadata.getContainerId()); newMetadata.copyFrom(baseMetadata); Assert.assertTrue("copyFrom copied the Active flag too.", newMetadata.isActive()); SegmentMetadataComparer.assertEquals("Metadata copy:", baseMetadata, newMetadata); Assert.assertEquals("Metadata copy: getLastUsed differs.", baseMetadata.getLastUsed(), newMetadata.getLastUsed()); // Verify we cannot copy from different StreamSegments. AssertExtensions.assertThrows( "copyFrom allowed copying from a metadata with a different Segment Name", () -> new StreamSegmentMetadata("foo", SEGMENT_ID, CONTAINER_ID).copyFrom(baseMetadata), ex -> ex instanceof IllegalArgumentException); AssertExtensions.assertThrows( "copyFrom allowed copying from a metadata with a different Segment Id", () -> new StreamSegmentMetadata(SEGMENT_NAME, -SEGMENT_ID, CONTAINER_ID).copyFrom(baseMetadata), ex -> ex instanceof IllegalArgumentException); }