use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.
the class FileSystemStorage method doGetStreamSegmentInfo.
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;
}
use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.
the class PravegaRequestProcessorTest method testReadSegmentTruncated.
@Test(timeout = 20000)
public void testReadSegmentTruncated() {
// Set up PravegaRequestProcessor instance to execute read segment request against
String streamSegmentName = "scope/stream/testReadSegment";
int readLength = 1000;
StreamSegmentStore store = mock(StreamSegmentStore.class);
ServerConnection connection = mock(ServerConnection.class);
PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), connection);
TestReadResultEntry entry1 = new TestReadResultEntry(ReadResultEntryType.Truncated, 0, readLength);
List<ReadResultEntry> results = new ArrayList<>();
results.add(entry1);
CompletableFuture<ReadResult> readResult = new CompletableFuture<>();
readResult.complete(new TestReadResult(0, readLength, results));
when(store.read(streamSegmentName, 0, readLength, PravegaRequestProcessor.TIMEOUT)).thenReturn(readResult);
StreamSegmentInformation info = StreamSegmentInformation.builder().name(streamSegmentName).length(1234).startOffset(123).build();
when(store.getStreamSegmentInfo(streamSegmentName, PravegaRequestProcessor.TIMEOUT)).thenReturn(CompletableFuture.completedFuture(info));
// Execute and Verify readSegment calling stack in connection and store is executed as design.
processor.readSegment(new WireCommands.ReadSegment(streamSegmentName, 0, readLength, "", requestId));
verify(store).read(streamSegmentName, 0, readLength, PravegaRequestProcessor.TIMEOUT);
verify(store).getStreamSegmentInfo(streamSegmentName, PravegaRequestProcessor.TIMEOUT);
verify(connection).send(new WireCommands.SegmentIsTruncated(requestId, streamSegmentName, info.getStartOffset(), "", 0));
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
}
use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.
the class FileSystemStorage method doGetStreamSegmentInfo.
protected 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;
}
use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.
the class HDFSStorage method getStreamSegmentInfo.
@Override
public SegmentProperties getStreamSegmentInfo(String streamSegmentName) throws StreamSegmentException {
ensureInitializedAndNotClosed();
long traceId = LoggerHelpers.traceEnter(log, "getStreamSegmentInfo", streamSegmentName);
try {
return HDFS_RETRY.run(() -> {
FileStatus last = findStatusForSegment(streamSegmentName, true);
boolean isSealed = isSealed(last.getPath());
StreamSegmentInformation result = StreamSegmentInformation.builder().name(streamSegmentName).length(last.getLen()).sealed(isSealed).build();
LoggerHelpers.traceLeave(log, "getStreamSegmentInfo", traceId, streamSegmentName, result);
return result;
});
} catch (IOException e) {
throw HDFSExceptionHelpers.convertException(streamSegmentName, e);
} catch (RetriesExhaustedException e) {
throw HDFSExceptionHelpers.convertException(streamSegmentName, e.getCause());
}
}
use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.
the class ContainerMetadataSerializer method serialize.
@Override
public ByteBuffer serialize(String value) {
ByteBuffer buf;
try {
// Convert string to map with fields and values.
Map<String, String> data = parseStringData(value);
long segmentId = Long.parseLong(getAndRemoveIfExists(data, SEGMENT_ID));
// Use the map to build SegmentProperties. The fields/keys are removed after being queried to ensure attributes
// can be handled without interference. If the field/key queried does not exist we throw an IllegalArgumentException.
StreamSegmentInformation properties = StreamSegmentInformation.builder().name(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_NAME)).sealed(Boolean.parseBoolean(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_SEALED))).startOffset(Long.parseLong(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_START_OFFSET))).length(Long.parseLong(getAndRemoveIfExists(data, SEGMENT_PROPERTIES_LENGTH))).attributes(getAttributes(data)).build();
SegmentInfo segment = SegmentInfo.builder().segmentId(segmentId).properties(properties).build();
buf = SERIALIZER.serialize(segment).asByteBuffer();
} catch (IOException e) {
throw new RuntimeException(e);
}
return buf;
}
Aggregations