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());
}
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);
});
}
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);
}
Aggregations