use of io.pravega.shared.protocol.netty.ByteBufWrapper in project pravega by pravega.
the class DirectMemoryBufferTests method read.
private BufferView read(DirectMemoryBuffer buffer, int blockId) {
val readBuffers = new ArrayList<ByteBuf>();
buffer.read(blockId, readBuffers);
ByteBuf result = readBuffers.size() == 1 ? readBuffers.get(0) : new CompositeByteBuf(this.allocator, false, readBuffers.size(), Lists.reverse(readBuffers));
return new ByteBufWrapper(result);
}
use of io.pravega.shared.protocol.netty.ByteBufWrapper in project pravega by pravega.
the class StreamSegmentStoreTestBase method createAppendDataRequests.
private ArrayList<StoreRequest> createAppendDataRequests(Collection<String> segmentNames, HashMap<String, ByteArrayOutputStream> segmentContents, HashMap<String, Long> lengths, List<ByteBuf> appendBuffers, int attributeUpdatesPerSegment, int appendsPerSegment) {
val result = new ArrayList<StoreRequest>();
val halfAttributeCount = attributeUpdatesPerSegment / 2;
for (String segmentName : segmentNames) {
if (isEmptySegment(segmentName)) {
continue;
}
// Add half the attribute updates now.
for (int i = 0; i < halfAttributeCount; i++) {
result.add(store -> store.updateAttributes(segmentName, createAttributeUpdates(), TIMEOUT));
}
// Add some appends.
for (int i = 0; i < appendsPerSegment; i++) {
byte[] appendData = getAppendData(segmentName, i);
lengths.put(segmentName, lengths.getOrDefault(segmentName, 0L) + appendData.length);
recordAppend(segmentName, appendData, segmentContents);
// Use Netty ByteBuf here - this mimics the behavior of AppendProcessor.
ByteBuf buf = Unpooled.wrappedBuffer(appendData);
result.add(store -> Futures.toVoid(store.append(segmentName, new ByteBufWrapper(buf), createAttributeUpdates(), TIMEOUT)));
if (appendBuffers != null) {
appendBuffers.add(buf);
}
}
// Add the rest of the attribute updates.
for (int i = 0; i < halfAttributeCount; i++) {
result.add(store -> store.updateAttributes(segmentName, createAttributeUpdates(), TIMEOUT));
}
}
return result;
}
use of io.pravega.shared.protocol.netty.ByteBufWrapper in project pravega by pravega.
the class PravegaRequestProcessor method updateTableEntries.
@Override
public void updateTableEntries(final WireCommands.UpdateTableEntries updateTableEntries) {
String segment = updateTableEntries.getSegment();
final String operation = "updateTableEntries";
if (!verifyToken(segment, updateTableEntries.getRequestId(), updateTableEntries.getDelegationToken(), operation)) {
updateTableEntries.release();
return;
}
log.debug(updateTableEntries.getRequestId(), "Update Table Segment Entries: Segment={}, Offset={}, Count={}.", updateTableEntries.getSegment(), updateTableEntries.getTableSegmentOffset(), updateTableEntries.getTableEntries().getEntries().size());
val entries = new ArrayList<TableEntry>(updateTableEntries.getTableEntries().getEntries().size());
val conditional = new AtomicBoolean(false);
val size = new AtomicInteger(0);
for (val e : updateTableEntries.getTableEntries().getEntries()) {
val v = TableEntry.versioned(new ByteBufWrapper(e.getKey().getData()), new ByteBufWrapper(e.getValue().getData()), e.getKey().getKeyVersion());
entries.add(v);
size.addAndGet(v.getKey().getKey().getLength() + v.getValue().getLength());
if (v.getKey().hasVersion()) {
conditional.set(true);
}
}
val timer = new Timer();
this.connection.adjustOutstandingBytes(size.get());
tableStore.put(segment, entries, updateTableEntries.getTableSegmentOffset(), TIMEOUT).thenAccept(versions -> {
connection.send(new WireCommands.TableEntriesUpdated(updateTableEntries.getRequestId(), versions));
this.tableStatsRecorder.updateEntries(updateTableEntries.getSegment(), entries.size(), conditional.get(), timer.getElapsed());
}).exceptionally(e -> handleException(updateTableEntries.getRequestId(), segment, updateTableEntries.getTableSegmentOffset(), operation, e)).whenComplete((r, ex) -> {
this.connection.adjustOutstandingBytes(-size.get());
updateTableEntries.release();
});
}
use of io.pravega.shared.protocol.netty.ByteBufWrapper in project pravega by pravega.
the class PravegaRequestProcessor method readTable.
@Override
public void readTable(final WireCommands.ReadTable readTable) {
final String segment = readTable.getSegment();
final String operation = "readTable";
if (!verifyToken(segment, readTable.getRequestId(), readTable.getDelegationToken(), operation)) {
readTable.release();
return;
}
log.debug(readTable.getRequestId(), "Get Table Segment Keys: Segment={}, Count={}.", readTable.getSegment(), readTable.getKeys());
final List<BufferView> keys = readTable.getKeys().stream().map(k -> new ByteBufWrapper(k.getData())).collect(Collectors.toList());
val timer = new Timer();
tableStore.get(segment, keys, TIMEOUT).thenAccept(values -> {
connection.send(new WireCommands.TableRead(readTable.getRequestId(), segment, getTableEntriesCommand(keys, values)));
this.tableStatsRecorder.getKeys(readTable.getSegment(), keys.size(), timer.getElapsed());
}).exceptionally(e -> handleException(readTable.getRequestId(), segment, operation, e)).whenComplete((r, ex) -> readTable.release());
}
use of io.pravega.shared.protocol.netty.ByteBufWrapper in project pravega by pravega.
the class PravegaRequestProcessor method removeTableKeys.
@Override
public void removeTableKeys(final WireCommands.RemoveTableKeys removeTableKeys) {
String segment = removeTableKeys.getSegment();
final String operation = "removeTableKeys";
if (!verifyToken(segment, removeTableKeys.getRequestId(), removeTableKeys.getDelegationToken(), operation)) {
removeTableKeys.release();
return;
}
log.debug(removeTableKeys.getRequestId(), "Remove Table Segment Keys: Segment={}, Offset={}, Count={}.", removeTableKeys.getSegment(), removeTableKeys.getTableSegmentOffset(), removeTableKeys.getKeys().size());
val keys = new ArrayList<TableKey>(removeTableKeys.getKeys().size());
val conditional = new AtomicBoolean(false);
val size = new AtomicInteger(0);
for (val k : removeTableKeys.getKeys()) {
val v = TableKey.versioned(new ByteBufWrapper(k.getData()), k.getKeyVersion());
keys.add(v);
size.addAndGet(v.getKey().getLength());
if (v.hasVersion()) {
conditional.set(true);
}
}
val timer = new Timer();
this.connection.adjustOutstandingBytes(size.get());
tableStore.remove(segment, keys, removeTableKeys.getTableSegmentOffset(), TIMEOUT).thenRun(() -> {
connection.send(new WireCommands.TableKeysRemoved(removeTableKeys.getRequestId(), segment));
this.tableStatsRecorder.removeKeys(removeTableKeys.getSegment(), keys.size(), conditional.get(), timer.getElapsed());
}).exceptionally(e -> handleException(removeTableKeys.getRequestId(), segment, removeTableKeys.getTableSegmentOffset(), operation, e)).whenComplete((r, ex) -> {
this.connection.adjustOutstandingBytes(-size.get());
removeTableKeys.release();
});
}
Aggregations