Search in sources :

Example 21 with AttributeUpdateCollection

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

the class StorageWriterTests method generateAttributeUpdates.

private AttributeUpdateCollection generateAttributeUpdates(UpdateableSegmentMetadata segmentMetadata) {
    long coreAttributeValue = segmentMetadata.getAttributes().getOrDefault(CORE_ATTRIBUTE_ID, 0L) + 1;
    val attributeUpdates = new AttributeUpdateCollection();
    attributeUpdates.add(new AttributeUpdate(CORE_ATTRIBUTE_ID, AttributeUpdateType.Accumulate, coreAttributeValue));
    for (int i = 0; i < EXTENDED_ATTRIBUTE_IDS.size(); i++) {
        AttributeId id = EXTENDED_ATTRIBUTE_IDS.get(i);
        long extendedAttributeValue = segmentMetadata.getAttributes().getOrDefault(id, 0L) + 13 + i;
        attributeUpdates.add(new AttributeUpdate(id, AttributeUpdateType.Replace, extendedAttributeValue));
    }
    segmentMetadata.updateAttributes(attributeUpdates.stream().collect(Collectors.toMap(AttributeUpdate::getAttributeId, AttributeUpdate::getValue)));
    return attributeUpdates;
}
Also used : lombok.val(lombok.val) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) AttributeId(io.pravega.segmentstore.contracts.AttributeId)

Example 22 with AttributeUpdateCollection

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

the class AttributeAggregatorTests method generateUpdateAttributesAndUpdateMetadata.

private UpdateAttributesOperation generateUpdateAttributesAndUpdateMetadata(int attributeCount, TestContext context) {
    Assert.assertTrue(attributeCount <= EXTENDED_ATTRIBUTE_IDS.size());
    long coreAttributeValue = context.segmentMetadata.getAttributes().getOrDefault(CORE_ATTRIBUTE_ID, 0L) + 1;
    val attributeUpdates = new AttributeUpdateCollection();
    // Always add a Core Attribute - this should be ignored.
    attributeUpdates.add(new AttributeUpdate(CORE_ATTRIBUTE_ID, AttributeUpdateType.Accumulate, coreAttributeValue));
    val usedIndices = new HashSet<Integer>();
    for (int i = 0; i < attributeCount; i++) {
        int attributeIndex;
        do {
            attributeIndex = context.random.nextInt(EXTENDED_ATTRIBUTE_IDS.size());
        } while (usedIndices.contains(attributeIndex));
        usedIndices.add(attributeIndex);
        attributeUpdates.add(new AttributeUpdate(EXTENDED_ATTRIBUTE_IDS.get(attributeIndex), AttributeUpdateType.Replace, context.random.nextLong()));
    }
    context.segmentMetadata.updateAttributes(attributeUpdates.stream().collect(Collectors.toMap(AttributeUpdate::getAttributeId, AttributeUpdate::getValue)));
    UpdateAttributesOperation op = new UpdateAttributesOperation(context.segmentMetadata.getId(), attributeUpdates);
    op.setSequenceNumber(context.containerMetadata.nextOperationSequenceNumber());
    return op;
}
Also used : lombok.val(lombok.val) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) UpdateAttributesOperation(io.pravega.segmentstore.server.logs.operations.UpdateAttributesOperation) HashSet(java.util.HashSet)

Example 23 with AttributeUpdateCollection

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

the class StorageWriterTests method appendData.

private void appendData(UpdateableSegmentMetadata segmentMetadata, int appendId, int writeId, HashMap<Long, ByteArrayOutputStream> segmentContents, TestContext context) {
    byte[] data = getAppendData(segmentMetadata.getName(), segmentMetadata.getId(), appendId, writeId);
    // Make sure we increase the Length prior to appending; the Writer checks for this.
    long offset = segmentMetadata.getLength();
    segmentMetadata.setLength(offset + data.length);
    AttributeUpdateCollection attributeUpdates = generateAttributeUpdates(segmentMetadata);
    StreamSegmentAppendOperation op = new StreamSegmentAppendOperation(segmentMetadata.getId(), new ByteArraySegment(data), attributeUpdates);
    op.setStreamSegmentOffset(offset);
    context.dataSource.recordAppend(op);
    context.dataSource.add(new CachedStreamSegmentAppendOperation(op));
    recordAppend(segmentMetadata.getId(), data, segmentContents);
}
Also used : AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) ByteArraySegment(io.pravega.common.util.ByteArraySegment) CachedStreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.CachedStreamSegmentAppendOperation) StreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.StreamSegmentAppendOperation) CachedStreamSegmentAppendOperation(io.pravega.segmentstore.server.logs.operations.CachedStreamSegmentAppendOperation)

Example 24 with AttributeUpdateCollection

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

the class StreamSegmentAppendOperationTests method createAttributes.

static AttributeUpdateCollection createAttributes() {
    val result = new AttributeUpdateCollection();
    long currentValue = 0;
    for (AttributeUpdateType ut : AttributeUpdateType.values()) {
        result.add(new AttributeUpdate(AttributeId.uuid(Attributes.CORE_ATTRIBUTE_ID_PREFIX, ut.getTypeId()), ut, ++currentValue, currentValue));
        result.add(new AttributeUpdate(AttributeId.random(AttributeId.Variable.MAX_LENGTH), ut, ++currentValue, currentValue));
    }
    return result;
}
Also used : lombok.val(lombok.val) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) AttributeUpdateType(io.pravega.segmentstore.contracts.AttributeUpdateType)

Example 25 with AttributeUpdateCollection

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

the class FixedKeyLengthTableSegmentLayout method remove.

@Override
CompletableFuture<Void> remove(@NonNull DirectSegmentAccess segment, @NonNull Collection<TableKey> keys, long tableSegmentOffset, TimeoutTimer timer) {
    val segmentInfo = segment.getInfo();
    ensureSegmentType(segmentInfo.getName(), segmentInfo.getType());
    val segmentKeyLength = getSegmentKeyLength(segmentInfo);
    ensureValidKeyLength(segmentInfo.getName(), segmentKeyLength);
    val attributeUpdates = new AttributeUpdateCollection();
    boolean isConditional = false;
    for (val key : keys) {
        Preconditions.checkArgument(key.getKey().getLength() == segmentKeyLength, "Key Length for key `%s` incompatible with segment '%s' which requires key lengths of %s.", key, segmentInfo.getName(), segmentKeyLength);
        attributeUpdates.add(createIndexRemoval(key));
        isConditional |= key.hasVersion();
    }
    logRequest("remove", segmentInfo.getName(), isConditional, tableSegmentOffset, keys.size());
    val result = tableSegmentOffset == NO_OFFSET ? segment.updateAttributes(attributeUpdates, timer.getRemaining()) : segment.append(BufferView.empty(), attributeUpdates, tableSegmentOffset, timer.getRemaining());
    return handleConditionalUpdateException(result, segmentInfo).thenRun(() -> this.compactionService.process(new CompactionCandidate(segment)));
}
Also used : lombok.val(lombok.val) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection)

Aggregations

AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)33 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)28 lombok.val (lombok.val)23 AttributeId (io.pravega.segmentstore.contracts.AttributeId)18 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)16 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)15 CompletableFuture (java.util.concurrent.CompletableFuture)15 AttributeUpdateType (io.pravega.segmentstore.contracts.AttributeUpdateType)14 Test (org.junit.Test)14 Map (java.util.Map)13 Attributes (io.pravega.segmentstore.contracts.Attributes)12 Exceptions (io.pravega.common.Exceptions)11 Futures (io.pravega.common.concurrent.Futures)11 BufferView (io.pravega.common.util.BufferView)11 BadAttributeUpdateException (io.pravega.segmentstore.contracts.BadAttributeUpdateException)11 SegmentType (io.pravega.segmentstore.contracts.SegmentType)11 UpdateableSegmentMetadata (io.pravega.segmentstore.server.UpdateableSegmentMetadata)11 Operation (io.pravega.segmentstore.server.logs.operations.Operation)11 StreamSegmentSealOperation (io.pravega.segmentstore.server.logs.operations.StreamSegmentSealOperation)11