Search in sources :

Example 6 with SegmentContainer

use of io.pravega.segmentstore.server.SegmentContainer in project pravega by pravega.

the class SegmentContainerRegistryHealthContributor method doHealthCheck.

@Override
public Status doHealthCheck(Health.HealthBuilder builder) {
    for (SegmentContainer container : segmentContainerRegistry.getContainers()) {
        this.register(new SegmentContainerHealthContributor(container));
    }
    Status status = Status.DOWN;
    boolean ready = !segmentContainerRegistry.isClosed();
    if (ready) {
        status = Status.UP;
    }
    return status;
}
Also used : Status(io.pravega.shared.health.Status) SegmentContainer(io.pravega.segmentstore.server.SegmentContainer)

Example 7 with SegmentContainer

use of io.pravega.segmentstore.server.SegmentContainer in project pravega by pravega.

the class SegmentContainerCollection method invoke.

/**
 * Executes the given Function on the StreamSegmentContainer that the given Id maps to.
 *
 * @param containerId The Id to fetch the Container for.
 * @param toInvoke    A Function that will be invoked on the Container.
 * @param methodName  The name of the calling method (for logging purposes).
 * @param logArgs     (Optional) A vararg array of items to be logged.
 * @param <T>         Resulting type.
 * @return Either the result of toInvoke or a CompletableFuture completed exceptionally with a ContainerNotFoundException
 * in case the SegmentContainer that the Id maps to does not exist in this StreamSegmentService.
 */
protected <T> CompletableFuture<T> invoke(int containerId, Function<SegmentContainer, CompletableFuture<T>> toInvoke, String methodName, Object... logArgs) {
    long traceId = LoggerHelpers.traceEnter(log, methodName, logArgs);
    SegmentContainer container;
    try {
        container = this.segmentContainerRegistry.getContainer(containerId);
    } catch (ContainerNotFoundException ex) {
        return Futures.failedFuture(ex);
    }
    CompletableFuture<T> resultFuture = toInvoke.apply(container);
    if (log.isTraceEnabled()) {
        resultFuture.thenAccept(r -> LoggerHelpers.traceLeave(log, methodName, traceId, r));
    }
    return resultFuture;
}
Also used : SegmentContainer(io.pravega.segmentstore.server.SegmentContainer) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException)

Example 8 with SegmentContainer

use of io.pravega.segmentstore.server.SegmentContainer in project pravega by pravega.

the class StreamSegmentContainerRegistryTests method testGetContainer.

/**
 * Tests the getContainer method for registered and unregistered containers.
 */
@Test
public void testGetContainer() throws Exception {
    final int containerCount = 1000;
    TestContainerFactory factory = new TestContainerFactory();
    @Cleanup StreamSegmentContainerRegistry registry = new StreamSegmentContainerRegistry(factory, executorService());
    HashSet<Integer> expectedContainerIds = new HashSet<>();
    List<CompletableFuture<ContainerHandle>> handleFutures = new ArrayList<>();
    for (int containerId = 0; containerId < containerCount; containerId++) {
        handleFutures.add(registry.startContainer(containerId, TIMEOUT));
        expectedContainerIds.add(containerId);
    }
    List<ContainerHandle> handles = Futures.allOfWithResults(handleFutures).join();
    HashSet<Integer> actualHandleIds = new HashSet<>();
    for (ContainerHandle handle : handles) {
        actualHandleIds.add(handle.getContainerId());
        SegmentContainer container = registry.getContainer(handle.getContainerId());
        Assert.assertTrue("Wrong container Java type.", container instanceof TestContainer);
        Assert.assertEquals("Unexpected container Id.", handle.getContainerId(), container.getId());
        container.close();
    }
    AssertExtensions.assertContainsSameElements("Unexpected container ids registered.", expectedContainerIds, actualHandleIds);
    AssertExtensions.assertThrows("getContainer did not throw when passed an invalid container id.", () -> registry.getContainer(containerCount + 1), ex -> ex instanceof ContainerNotFoundException);
}
Also used : ArrayList(java.util.ArrayList) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) DebugSegmentContainer(io.pravega.segmentstore.server.DebugSegmentContainer) SegmentContainer(io.pravega.segmentstore.server.SegmentContainer) ContainerNotFoundException(io.pravega.segmentstore.contracts.ContainerNotFoundException) HashSet(java.util.HashSet) ContainerHandle(io.pravega.segmentstore.server.ContainerHandle) Test(org.junit.Test)

Example 9 with SegmentContainer

use of io.pravega.segmentstore.server.SegmentContainer in project pravega by pravega.

the class StreamSegmentContainerTests method testExtensions.

/**
 * Tests the ability to register extensions.
 */
@Test
public void testExtensions() throws Exception {
    String segmentName = getSegmentName(123);
    ByteArraySegment data = getAppendData(segmentName, 0);
    // Configure extension.
    val operationProcessed = new CompletableFuture<SegmentOperation>();
    AtomicInteger count = new AtomicInteger();
    val writerProcessor = new TestWriterProcessor(op -> {
        if (op.getStreamSegmentId() != EXPECTED_METADATA_SEGMENT_ID) {
            // We need to exclude any appends that come from the MetadataStore as those do not concern us.
            count.incrementAndGet();
            if (!operationProcessed.isDone()) {
                operationProcessed.complete(op);
            }
        }
    });
    val extension = new AtomicReference<TestSegmentContainerExtension>();
    SegmentContainerFactory.CreateExtensions additionalExtensions = (container, executor) -> {
        Assert.assertTrue("Already created", extension.compareAndSet(null, new TestSegmentContainerExtension(Collections.singleton(writerProcessor))));
        return Collections.singletonMap(TestSegmentContainerExtension.class, extension.get());
    };
    @Cleanup val context = new TestContext(DEFAULT_CONFIG, additionalExtensions);
    context.container.startAsync().awaitRunning();
    // Verify getExtension().
    val p = context.container.getExtension(TestSegmentContainerExtension.class);
    Assert.assertEquals("Unexpected result from getExtension().", extension.get(), p);
    // Verify Writer Segment Processors are properly wired in.
    context.container.createStreamSegment(segmentName, getSegmentType(segmentName), null, TIMEOUT).join();
    context.container.append(segmentName, data, null, TIMEOUT).join();
    val rawOp = operationProcessed.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
    Assert.assertTrue("Unexpected operation type.", rawOp instanceof CachedStreamSegmentAppendOperation);
    // Our operation has been transformed into a CachedStreamSegmentAppendOperation, which means it just points to
    // a location in the cache. We do not have access to that cache, so we can only verify its metadata.
    val appendOp = (CachedStreamSegmentAppendOperation) rawOp;
    Assert.assertEquals("Unexpected offset.", 0, appendOp.getStreamSegmentOffset());
    Assert.assertEquals("Unexpected data length.", data.getLength(), appendOp.getLength());
    Assert.assertNull("Unexpected attribute updates.", appendOp.getAttributeUpdates());
    // Verify extension is closed when the SegmentContainer is closed.
    context.container.close();
    Assert.assertTrue("Extension not closed.", extension.get().closed.get());
}
Also used : lombok.val(lombok.val) Arrays(java.util.Arrays) Storage(io.pravega.segmentstore.storage.Storage) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) ContainerEventProcessor(io.pravega.segmentstore.server.ContainerEventProcessor) Cleanup(lombok.Cleanup) StorageWriterFactory(io.pravega.segmentstore.server.writer.StorageWriterFactory) UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) Future(java.util.concurrent.Future) ContainerTableExtensionImpl(io.pravega.segmentstore.server.tables.ContainerTableExtensionImpl) InMemoryStorageFactory(io.pravega.segmentstore.storage.mocks.InMemoryStorageFactory) Duration(java.time.Duration) Map(java.util.Map) CachePolicy(io.pravega.segmentstore.server.CachePolicy) Operation(io.pravega.segmentstore.server.logs.operations.Operation) WriterFlushResult(io.pravega.segmentstore.server.WriterFlushResult) AsyncReadResultProcessor(io.pravega.segmentstore.server.reading.AsyncReadResultProcessor) ContainerReadIndexFactory(io.pravega.segmentstore.server.reading.ContainerReadIndexFactory) InMemoryDurableDataLogFactory(io.pravega.segmentstore.storage.mocks.InMemoryDurableDataLogFactory) DurableLogFactory(io.pravega.segmentstore.server.logs.DurableLogFactory) Attributes(io.pravega.segmentstore.contracts.Attributes) DurableLogConfig(io.pravega.segmentstore.server.logs.DurableLogConfig) Writer(io.pravega.segmentstore.server.Writer) StandardCharsets(java.nio.charset.StandardCharsets) Stream(java.util.stream.Stream) SegmentContainerFactory(io.pravega.segmentstore.server.SegmentContainerFactory) ContainerTableExtension(io.pravega.segmentstore.server.tables.ContainerTableExtension) ThreadPooledTestSuite(io.pravega.test.common.ThreadPooledTestSuite) SyncStorage(io.pravega.segmentstore.storage.SyncStorage) DirectMemoryCache(io.pravega.segmentstore.storage.cache.DirectMemoryCache) TestUtils(io.pravega.test.common.TestUtils) Futures(io.pravega.common.concurrent.Futures) CacheManager(io.pravega.segmentstore.server.CacheManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IllegalContainerStateException(io.pravega.segmentstore.server.IllegalContainerStateException) TooManyActiveSegmentsException(io.pravega.segmentstore.contracts.TooManyActiveSegmentsException) EntrySerializerTests(io.pravega.segmentstore.server.tables.EntrySerializerTests) Exceptions(io.pravega.common.Exceptions) StorageFactory(io.pravega.segmentstore.storage.StorageFactory) BadAttributeUpdateException(io.pravega.segmentstore.contracts.BadAttributeUpdateException) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) UpdateableContainerMetadata(io.pravega.segmentstore.server.UpdateableContainerMetadata) SegmentType(io.pravega.segmentstore.contracts.SegmentType) Runnables(com.google.common.util.concurrent.Runnables) AttributeIndexConfig(io.pravega.segmentstore.server.attributes.AttributeIndexConfig) ReadIndexConfig(io.pravega.segmentstore.server.reading.ReadIndexConfig) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) Timeout(org.junit.rules.Timeout) WriterTableProcessor(io.pravega.segmentstore.server.tables.WriterTableProcessor) ConfigurationException(io.pravega.common.util.ConfigurationException) SegmentContainerExtension(io.pravega.segmentstore.server.SegmentContainerExtension) WriterFactory(io.pravega.segmentstore.server.WriterFactory) Properties(java.util.Properties) DurableDataLog(io.pravega.segmentstore.storage.DurableDataLog) Executor(java.util.concurrent.Executor) AttributeId(io.pravega.segmentstore.contracts.AttributeId) lombok.val(lombok.val) Assert.assertTrue(org.junit.Assert.assertTrue) OperationLog(io.pravega.segmentstore.server.OperationLog) TableExtensionConfig(io.pravega.segmentstore.server.tables.TableExtensionConfig) IOException(java.io.IOException) Test(org.junit.Test) SystemJournal(io.pravega.segmentstore.storage.chunklayer.SystemJournal) Service(com.google.common.util.concurrent.Service) AtomicLong(java.util.concurrent.atomic.AtomicLong) DirectSegmentAccess(io.pravega.segmentstore.server.DirectSegmentAccess) ContainerAttributeIndex(io.pravega.segmentstore.server.attributes.ContainerAttributeIndex) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) OperationLogFactory(io.pravega.segmentstore.server.OperationLogFactory) SegmentContainer(io.pravega.segmentstore.server.SegmentContainer) Assert(org.junit.Assert) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Assert.assertEquals(org.junit.Assert.assertEquals) DynamicAttributeValue(io.pravega.segmentstore.contracts.DynamicAttributeValue) OperationPriority(io.pravega.segmentstore.server.logs.operations.OperationPriority) WriterConfig(io.pravega.segmentstore.server.writer.WriterConfig) SneakyThrows(lombok.SneakyThrows) AssertExtensions(io.pravega.test.common.AssertExtensions) BiFunction(java.util.function.BiFunction) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TimeoutException(java.util.concurrent.TimeoutException) ByteBuffer(java.nio.ByteBuffer) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) ReadIndexFactory(io.pravega.segmentstore.server.ReadIndexFactory) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) StreamSegmentSealedException(io.pravega.segmentstore.contracts.StreamSegmentSealedException) ContainerAttributeIndexFactoryImpl(io.pravega.segmentstore.server.attributes.ContainerAttributeIndexFactoryImpl) AttributeIndexFactory(io.pravega.segmentstore.server.attributes.AttributeIndexFactory) SegmentHandle(io.pravega.segmentstore.storage.SegmentHandle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferView(io.pravega.common.util.BufferView) AbstractService(com.google.common.util.concurrent.AbstractService) AttributeIdLengthMismatchException(io.pravega.segmentstore.server.logs.AttributeIdLengthMismatchException) ServiceListeners(io.pravega.segmentstore.server.ServiceListeners) ContainerOfflineException(io.pravega.segmentstore.server.ContainerOfflineException) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) ReadResultEntryType(io.pravega.segmentstore.contracts.ReadResultEntryType) UUID(java.util.UUID) DataLogWriterNotPrimaryException(io.pravega.segmentstore.storage.DataLogWriterNotPrimaryException) DynamicAttributeUpdate(io.pravega.segmentstore.contracts.DynamicAttributeUpdate) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SegmentMetadataComparer(io.pravega.segmentstore.server.SegmentMetadataComparer) List(java.util.List) ByteArraySegment(io.pravega.common.util.ByteArraySegment) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) WriterSegmentProcessor(io.pravega.segmentstore.server.WriterSegmentProcessor) DurableDataLogFactory(io.pravega.segmentstore.storage.DurableDataLogFactory) ReadResult(io.pravega.segmentstore.contracts.ReadResult) IntStream(java.util.stream.IntStream) ObjectClosedException(io.pravega.common.ObjectClosedException) Setter(lombok.Setter) Getter(lombok.Getter) AsyncStorageWrapper(io.pravega.segmentstore.storage.AsyncStorageWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) CacheStorage(io.pravega.segmentstore.storage.cache.CacheStorage) HashSet(java.util.HashSet) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) ReadResultEntry(io.pravega.segmentstore.contracts.ReadResultEntry) ExecutorService(java.util.concurrent.ExecutorService) NameUtils(io.pravega.shared.NameUtils) ExecutorServiceHelpers.newScheduledThreadPool(io.pravega.common.concurrent.ExecutorServiceHelpers.newScheduledThreadPool) TimeoutTimer(io.pravega.common.TimeoutTimer) RollingStorage(io.pravega.segmentstore.storage.rolling.RollingStorage) IntentionalException(io.pravega.test.common.IntentionalException) StreamSegmentMergedException(io.pravega.segmentstore.contracts.StreamSegmentMergedException) TestReadResultHandler(io.pravega.segmentstore.server.reading.TestReadResultHandler) SnapshotInfo(io.pravega.segmentstore.storage.chunklayer.SnapshotInfo) TestDurableDataLogFactory(io.pravega.segmentstore.server.TestDurableDataLogFactory) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) SegmentOperation(io.pravega.segmentstore.server.SegmentOperation) CachedStreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.CachedStreamSegmentAppendOperation) TypedProperties(io.pravega.common.util.TypedProperties) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) ReadIndex(io.pravega.segmentstore.server.ReadIndex) Comparator(java.util.Comparator) Collections(java.util.Collections) StreamSegmentSealOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation) InputStream(java.io.InputStream) ByteArraySegment(io.pravega.common.util.ByteArraySegment) SegmentContainerFactory(io.pravega.segmentstore.server.SegmentContainerFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) Cleanup(lombok.Cleanup) CachedStreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.CachedStreamSegmentAppendOperation) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

SegmentContainer (io.pravega.segmentstore.server.SegmentContainer)9 HashSet (java.util.HashSet)6 Cleanup (lombok.Cleanup)6 Test (org.junit.Test)6 Sets (com.google.common.collect.Sets)4 AbstractService (com.google.common.util.concurrent.AbstractService)4 Runnables (com.google.common.util.concurrent.Runnables)4 Service (com.google.common.util.concurrent.Service)4 Exceptions (io.pravega.common.Exceptions)4 ObjectClosedException (io.pravega.common.ObjectClosedException)4 TimeoutTimer (io.pravega.common.TimeoutTimer)4 ExecutorServiceHelpers.newScheduledThreadPool (io.pravega.common.concurrent.ExecutorServiceHelpers.newScheduledThreadPool)4 Futures (io.pravega.common.concurrent.Futures)4 BufferView (io.pravega.common.util.BufferView)4 ByteArraySegment (io.pravega.common.util.ByteArraySegment)4 ConfigurationException (io.pravega.common.util.ConfigurationException)4 TypedProperties (io.pravega.common.util.TypedProperties)4 AttributeId (io.pravega.segmentstore.contracts.AttributeId)4 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)4 AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)4