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