Search in sources :

Example 6 with SegmentType

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

the class StreamSegmentMetadataTests method testRefreshType.

/**
 * Tests {@link StreamSegmentMetadata#getType()} and {@link StreamSegmentMetadata#refreshDerivedProperties()}.
 */
@Test
public void testRefreshType() {
    SegmentType expectedType = SegmentType.STREAM_SEGMENT;
    int expectedAttributeIdLength = -1;
    StreamSegmentMetadata metadata = new StreamSegmentMetadata(SEGMENT_NAME, SEGMENT_ID, CONTAINER_ID);
    Assert.assertEquals("Unexpected segment type for non-initialized type.", expectedType, metadata.getType());
    Assert.assertEquals("Unexpected id length for non-initialized type.", expectedAttributeIdLength, metadata.getAttributeIdLength());
    // Segment type exists in Core attributes.
    expectedType = SegmentType.builder().critical().internal().build();
    metadata.updateAttributes(Collections.singletonMap(Attributes.ATTRIBUTE_SEGMENT_TYPE, expectedType.getValue()));
    expectedAttributeIdLength = 123;
    metadata.updateAttributes(Collections.singletonMap(Attributes.ATTRIBUTE_ID_LENGTH, (long) expectedAttributeIdLength));
    metadata.refreshDerivedProperties();
    Assert.assertEquals("Unexpected segment type for single type.", expectedType, metadata.getType());
    Assert.assertEquals("Unexpected id length.", expectedAttributeIdLength, metadata.getAttributeIdLength());
    // Segment type exists in Core attributes, but other attributes indicate this is a Table Segment.
    expectedType = SegmentType.builder(expectedType).tableSegment().build();
    metadata.updateAttributes(Collections.singletonMap(TableAttributes.INDEX_OFFSET, 0L));
    metadata.refreshDerivedProperties();
    Assert.assertEquals("Unexpected value for simple table segment type.", expectedType, metadata.getType());
    Assert.assertEquals("Core attributes were not updated as a result from derived refresh.", expectedType.getValue(), (long) metadata.getAttributes().get(Attributes.ATTRIBUTE_SEGMENT_TYPE));
    // CopyFrom.
    val m2 = new StreamSegmentMetadata(metadata.getName(), metadata.getId(), metadata.getContainerId());
    metadata.setLength(0);
    metadata.setStorageLength(0);
    m2.copyFrom(metadata);
    Assert.assertEquals("copyFrom().", metadata.getType(), m2.getType());
}
Also used : SegmentType(io.pravega.segmentstore.contracts.SegmentType) lombok.val(lombok.val) Test(org.junit.Test)

Example 7 with SegmentType

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

the class TableMetadataStore method initialize.

// region MetadataStore Implementation
@Override
public CompletableFuture<Void> initialize(Duration timeout) {
    Preconditions.checkState(!this.initialized.get(), "TableMetadataStore is already initialized.");
    // Invoke submitAssignment(), which will ensure that the Metadata Segment is mapped in memory and pinned.
    // If this is the first time we initialize the TableMetadataStore for this SegmentContainer, a new id will be
    // assigned to it.
    val attributes = new HashMap<>(TableAttributes.DEFAULT_VALUES);
    // Make sure we enable rollover for this segment.
    attributes.putAll(this.config.getDefaultCompactionAttributes());
    val attributeUpdates = attributes.entrySet().stream().map(e -> new AttributeUpdate(e.getKey(), AttributeUpdateType.None, e.getValue())).collect(Collectors.toList());
    // Container Metadata Segment is a System Table Segment. It is System, Internal, and Critical.
    val segmentType = SegmentType.builder().tableSegment().system().critical().internal().build();
    return submitAssignment(SegmentInfo.newSegment(this.metadataSegmentName, segmentType, attributeUpdates), true, timeout).thenAccept(segmentId -> {
        this.initialized.set(true);
        log.info("{}: Metadata Segment pinned. Name = '{}', Id = '{}'", this.traceObjectId, this.metadataSegmentName, segmentId);
    });
}
Also used : lombok.val(lombok.val) TableAttributes(io.pravega.segmentstore.contracts.tables.TableAttributes) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) BiFunction(java.util.function.BiFunction) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) BadKeyVersionException(io.pravega.segmentstore.contracts.tables.BadKeyVersionException) ArrayView(io.pravega.common.util.ArrayView) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) SegmentType(io.pravega.segmentstore.contracts.SegmentType) Runnables(com.google.common.util.concurrent.Runnables) BufferView(io.pravega.common.util.BufferView) Duration(java.time.Duration) Charsets(com.google.common.base.Charsets) NameUtils(io.pravega.shared.NameUtils) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) TimeoutTimer(io.pravega.common.TimeoutTimer) Executor(java.util.concurrent.Executor) NonNull(lombok.NonNull) Collection(java.util.Collection) lombok.val(lombok.val) TableExtensionConfig(io.pravega.segmentstore.server.tables.TableExtensionConfig) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) ByteArraySegment(io.pravega.common.util.ByteArraySegment) StreamSegmentExistsException(io.pravega.segmentstore.contracts.StreamSegmentExistsException) Preconditions(com.google.common.base.Preconditions) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Collections(java.util.Collections) Futures(io.pravega.common.concurrent.Futures) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) HashMap(java.util.HashMap)

Example 8 with SegmentType

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

the class ContainerTableExtensionImpl method createSegment.

// endregion
// region TableStore Implementation
@Override
public CompletableFuture<Void> createSegment(@NonNull String segmentName, SegmentType segmentType, TableSegmentConfig config, Duration timeout) {
    Exceptions.checkNotClosed(this.closed.get(), this);
    // Ensure at least a TableSegment type.
    segmentType = SegmentType.builder(segmentType).tableSegment().build();
    val attributes = new HashMap<>(TableAttributes.DEFAULT_VALUES);
    attributes.putAll(selectLayout(segmentName, segmentType).getNewSegmentAttributes(config));
    val attributeUpdates = attributes.entrySet().stream().map(e -> new AttributeUpdate(e.getKey(), AttributeUpdateType.None, e.getValue())).collect(Collectors.toList());
    logRequest("createSegment", segmentName, segmentType, config);
    return this.segmentContainer.createStreamSegment(segmentName, segmentType, attributeUpdates, timeout);
}
Also used : lombok.val(lombok.val) TableAttributes(io.pravega.segmentstore.contracts.tables.TableAttributes) TableSegmentConfig(io.pravega.segmentstore.contracts.tables.TableSegmentConfig) Getter(lombok.Getter) Exceptions(io.pravega.common.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) IteratorArgs(io.pravega.segmentstore.contracts.tables.IteratorArgs) UpdateableSegmentMetadata(io.pravega.segmentstore.server.UpdateableSegmentMetadata) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) SegmentMetadata(io.pravega.segmentstore.server.SegmentMetadata) SegmentType(io.pravega.segmentstore.contracts.SegmentType) IteratorItem(io.pravega.segmentstore.contracts.tables.IteratorItem) BufferView(io.pravega.common.util.BufferView) Duration(java.time.Duration) BadSegmentTypeException(io.pravega.segmentstore.contracts.BadSegmentTypeException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) TimeoutTimer(io.pravega.common.TimeoutTimer) NonNull(lombok.NonNull) Collection(java.util.Collection) lombok.val(lombok.val) AsyncIterator(io.pravega.common.util.AsyncIterator) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) TableSegmentInfo(io.pravega.segmentstore.contracts.tables.TableSegmentInfo) SegmentContainer(io.pravega.segmentstore.server.SegmentContainer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType) WriterSegmentProcessor(io.pravega.segmentstore.server.WriterSegmentProcessor) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Collections(java.util.Collections) CacheManager(io.pravega.segmentstore.server.CacheManager) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) HashMap(java.util.HashMap)

Aggregations

SegmentType (io.pravega.segmentstore.contracts.SegmentType)8 lombok.val (lombok.val)7 Test (org.junit.Test)6 BufferView (io.pravega.common.util.BufferView)4 TableEntry (io.pravega.segmentstore.contracts.tables.TableEntry)4 SegmentMetadata (io.pravega.segmentstore.server.SegmentMetadata)4 Duration (java.time.Duration)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Collectors (java.util.stream.Collectors)4 Cleanup (lombok.Cleanup)4 Exceptions (io.pravega.common.Exceptions)3 Futures (io.pravega.common.concurrent.Futures)3 ByteArraySegment (io.pravega.common.util.ByteArraySegment)3 Runnables (com.google.common.util.concurrent.Runnables)2 TimeoutTimer (io.pravega.common.TimeoutTimer)2 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)2 AttributeUpdateType (io.pravega.segmentstore.contracts.AttributeUpdateType)2 TableAttributes (io.pravega.segmentstore.contracts.tables.TableAttributes)2