Search in sources :

Example 6 with StreamSegmentInformation

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;
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) ImmutableDate(io.pravega.common.util.ImmutableDate) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes)

Example 7 with StreamSegmentInformation

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);
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) ArrayList(java.util.ArrayList) StreamSegmentReadResult(io.pravega.segmentstore.server.reading.StreamSegmentReadResult) ReadResult(io.pravega.segmentstore.contracts.ReadResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) CompletableFuture(java.util.concurrent.CompletableFuture) ReadResultEntry(io.pravega.segmentstore.contracts.ReadResultEntry) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 8 with StreamSegmentInformation

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;
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) ImmutableDate(io.pravega.common.util.ImmutableDate) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes)

Example 9 with StreamSegmentInformation

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());
    }
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) FileStatus(org.apache.hadoop.fs.FileStatus) RetriesExhaustedException(io.pravega.common.util.RetriesExhaustedException) IOException(java.io.IOException)

Example 10 with StreamSegmentInformation

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;
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) SegmentInfo(io.pravega.segmentstore.server.containers.MetadataStore.SegmentInfo) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

StreamSegmentInformation (io.pravega.segmentstore.contracts.StreamSegmentInformation)13 ImmutableDate (io.pravega.common.util.ImmutableDate)4 ReadResult (io.pravega.segmentstore.contracts.ReadResult)3 IOException (java.io.IOException)3 S3ObjectMetadata (com.emc.object.s3.S3ObjectMetadata)2 AccessControlList (com.emc.object.s3.bean.AccessControlList)2 ObjectClosedException (io.pravega.common.ObjectClosedException)2 TimeoutTimer (io.pravega.common.TimeoutTimer)2 ContainerNotFoundException (io.pravega.segmentstore.contracts.ContainerNotFoundException)2 ReadResultEntry (io.pravega.segmentstore.contracts.ReadResultEntry)2 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)2 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)2 StreamSegmentTruncatedException (io.pravega.segmentstore.contracts.StreamSegmentTruncatedException)2 IllegalContainerStateException (io.pravega.segmentstore.server.IllegalContainerStateException)2 DataLogWriterNotPrimaryException (io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException)2 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)2 TimeoutException (java.util.concurrent.TimeoutException)2 Streams (com.google.common.collect.Streams)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1