Search in sources :

Example 1 with StreamSegmentInformation

use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.

the class ExtendedS3Storage method doOpenWrite.

private SegmentHandle doOpenWrite(String streamSegmentName) {
    long traceId = LoggerHelpers.traceEnter(log, "openWrite", streamSegmentName);
    StreamSegmentInformation info = doGetStreamSegmentInfo(streamSegmentName);
    ExtendedS3SegmentHandle retHandle;
    if (info.isSealed()) {
        retHandle = ExtendedS3SegmentHandle.getReadHandle(streamSegmentName);
    } else {
        retHandle = ExtendedS3SegmentHandle.getWriteHandle(streamSegmentName);
    }
    LoggerHelpers.traceLeave(log, "openWrite", traceId);
    return retHandle;
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation)

Example 2 with StreamSegmentInformation

use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.

the class ExtendedS3Storage method doOpenWrite.

private SegmentHandle doOpenWrite(String streamSegmentName) {
    long traceId = LoggerHelpers.traceEnter(log, "openWrite", streamSegmentName);
    StreamSegmentInformation info = doGetStreamSegmentInfo(streamSegmentName);
    ExtendedS3SegmentHandle retHandle;
    if (info.isSealed()) {
        retHandle = ExtendedS3SegmentHandle.getReadHandle(streamSegmentName);
    } else {
        retHandle = ExtendedS3SegmentHandle.getWriteHandle(streamSegmentName);
    }
    LoggerHelpers.traceLeave(log, "openWrite", traceId);
    return retHandle;
}
Also used : StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation)

Example 3 with StreamSegmentInformation

use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.

the class ExtendedS3Storage method doGetStreamSegmentInfo.

private StreamSegmentInformation doGetStreamSegmentInfo(String streamSegmentName) {
    long traceId = LoggerHelpers.traceEnter(log, "getStreamSegmentInfo", streamSegmentName);
    S3ObjectMetadata result = client.getObjectMetadata(config.getBucket(), config.getPrefix() + streamSegmentName);
    AccessControlList acls = client.getObjectAcl(config.getBucket(), config.getPrefix() + 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;
}
Also used : AccessControlList(com.emc.object.s3.bean.AccessControlList) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) ImmutableDate(io.pravega.common.util.ImmutableDate) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata)

Example 4 with StreamSegmentInformation

use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.

the class StreamSegmentStoreTestBase method checkReads.

private void checkReads(HashMap<String, ByteArrayOutputStream> segmentContents, StreamSegmentStore store) {
    for (Map.Entry<String, ByteArrayOutputStream> e : segmentContents.entrySet()) {
        String segmentName = e.getKey();
        byte[] expectedData = e.getValue().toByteArray();
        AtomicReference<StreamSegmentInformation> info = new AtomicReference<>((StreamSegmentInformation) store.getStreamSegmentInfo(segmentName, TIMEOUT).join());
        Assert.assertEquals("Unexpected Read Index length for segment " + segmentName, expectedData.length, info.get().getLength());
        AtomicLong expectedCurrentOffset = new AtomicLong(0);
        // We retry a number of times on StreamSegmentNotExists. It is possible that waitForSegmentsInStorage may have
        // returned successfully because it detected the Segment was complete there, but the internal callback to the
        // ReadIndex (completeMerge) may not yet have been executed. The ReadIndex has a mechanism to cope with this,
        // but it only retries once, after a fixed time interval, which is more than generous on any system.
        // However, on very slow systems, it is possible that that callback may take a significant amount of time to even
        // begin executing, hence the trying to read data that was merged from a Transaction may result in a spurious
        // StreamSegmentNotExistsException.
        // This is gracefully handled by retries in AppendProcessor and/or Client, but in this case, we simply have to
        // do the retries ourselves, hoping that the callback eventually executes.
        Retry.withExpBackoff(100, 2, 10, TIMEOUT.toMillis() / 5).retryWhen(ex -> Exceptions.unwrap(ex) instanceof StreamSegmentNotExistsException || info.get().getLength() != info.get().getStorageLength()).run(() -> {
            val latestInfo = (StreamSegmentInformation) store.getStreamSegmentInfo(segmentName, TIMEOUT).join();
            try {
                checkSegmentReads(segmentName, expectedCurrentOffset, info.get().getLength(), store, expectedData);
            } catch (Exception ex2) {
                log.debug("Exception during checkReads", ex2);
            }
            info.set(latestInfo);
            return null;
        });
    }
}
Also used : Storage(io.pravega.segmentstore.storage.Storage) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) WriterConfig(io.pravega.segmentstore.server.writer.WriterConfig) SneakyThrows(lombok.SneakyThrows) Retry(io.pravega.common.util.Retry) AssertExtensions(io.pravega.test.common.AssertExtensions) TimeoutException(java.util.concurrent.TimeoutException) Cleanup(lombok.Cleanup) Unpooled(io.netty.buffer.Unpooled) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferView(io.pravega.common.util.BufferView) Duration(java.time.Duration) Map(java.util.Map) ContainerConfig(io.pravega.segmentstore.server.containers.ContainerConfig) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Services(io.pravega.common.concurrent.Services) DurableLogFactory(io.pravega.segmentstore.server.logs.DurableLogFactory) Attributes(io.pravega.segmentstore.contracts.Attributes) DurableLogConfig(io.pravega.segmentstore.server.logs.DurableLogConfig) DebugStreamSegmentContainer(io.pravega.segmentstore.server.containers.DebugStreamSegmentContainer) CancellationException(java.util.concurrent.CancellationException) Collection(java.util.Collection) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) ReadResultEntryType(io.pravega.segmentstore.contracts.ReadResultEntryType) UUID(java.util.UUID) Streams(com.google.common.collect.Streams) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) Futures(io.pravega.common.concurrent.Futures) ReadResult(io.pravega.segmentstore.contracts.ReadResult) IntStream(java.util.stream.IntStream) ObjectClosedException(io.pravega.common.ObjectClosedException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IllegalContainerStateException(io.pravega.segmentstore.server.IllegalContainerStateException) Exceptions(io.pravega.common.Exceptions) DebugStreamSegmentContainerTests(io.pravega.segmentstore.server.containers.DebugStreamSegmentContainerTests) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ContainerRecoveryUtils(io.pravega.segmentstore.server.containers.ContainerRecoveryUtils) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) SegmentType(io.pravega.segmentstore.contracts.SegmentType) ByteBuf(io.netty.buffer.ByteBuf) ReadResultEntry(io.pravega.segmentstore.contracts.ReadResultEntry) ReadIndexConfig(io.pravega.segmentstore.server.reading.ReadIndexConfig) ByteBufWrapper(io.pravega.shared.protocol.netty.ByteBufWrapper) StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) TimeoutTimer(io.pravega.common.TimeoutTimer) AttributeId(io.pravega.segmentstore.contracts.AttributeId) lombok.val(lombok.val) IOException(java.io.IOException) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) SegmentToContainerMapper(io.pravega.shared.segment.SegmentToContainerMapper) OperationLogFactory(io.pravega.segmentstore.server.OperationLogFactory) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) Assert(org.junit.Assert) lombok.val(lombok.val) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) ObjectClosedException(io.pravega.common.ObjectClosedException) IllegalContainerStateException(io.pravega.segmentstore.server.IllegalContainerStateException) StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) IOException(java.io.IOException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with StreamSegmentInformation

use of io.pravega.segmentstore.contracts.StreamSegmentInformation in project pravega by pravega.

the class ExtendedS3Storage method doGetStreamSegmentInfo.

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;
}
Also used : AccessControlList(com.emc.object.s3.bean.AccessControlList) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) ImmutableDate(io.pravega.common.util.ImmutableDate) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata)

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