public ByteBuffer build() { try { DataOutputBuffer out = new DataOutputBuffer(serializedSize); if (isStatic) out.writeShort(STATIC_MARKER); for (int i = 0; i < components.size(); i++) { ByteBufferUtil.writeWithShortLength(components.get(i), out); out.write(endOfComponents[i]); } return ByteBuffer.wrap(out.getData(), 0, out.getLength()); } catch (IOException e) { throw new RuntimeException(e); } }
private static ByteBuffer getSerializedMutations(int version, Collection<Mutation> mutations) { try (DataOutputBuffer buf = new DataOutputBuffer()) { buf.writeInt(mutations.size()); for (Mutation mutation : mutations) Mutation.serializer.serialize(mutation, buf, version); return buf.buffer(); } catch (IOException e) { throw new RuntimeException(e); } } }
protected void reallocate(long count) { if (count <= 0) return; ByteBuffer newBuffer = ByteBuffer.allocate(checkedArraySizeCast(calculateNewSize(count))); buffer.flip(); newBuffer.put(buffer); buffer = newBuffer; }
@VisibleForTesting long validateReallocation(long newSize) { int saturatedSize = saturatedArraySizeCast(newSize); if (saturatedSize <= capacity()) throw new RuntimeException(); return saturatedSize; }
public ByteBuffer serialize(Clustering clustering, int version, List<AbstractType<?>> types) { try (DataOutputBuffer buffer = new DataOutputBuffer((int)serializedSize(clustering, version, types))) { serialize(clustering, buffer, version, types); return buffer.buffer(); } catch (IOException e) { throw new RuntimeException("Writting to an in-memory buffer shouldn't trigger an IOException", e); } }
try(DataOutputBuffer out = new DataOutputBuffer()) out.writeInt(targets.size() - 1); while (iter.hasNext()) handler.consistencyLevel, true); out.writeInt(id); logger.trace("Adding FWD message to {}@{}", id, destination); message = message.withParameter(Mutation.FORWARD_TO, out.getData());
private static Map<UUID, ByteBuffer> truncationAsMapEntry(ColumnFamilyStore cfs, long truncatedAt, ReplayPosition position) { DataOutputBuffer out = new DataOutputBuffer(); try { ReplayPosition.serializer.serialize(position, out); out.writeLong(truncatedAt); } catch (IOException e) { throw new RuntimeException(e); } return Collections.<UUID, ByteBuffer>singletonMap(cfs.metadata.cfId, ByteBuffer.wrap(out.getData(), 0, out.getLength())); }
public ByteBuffer serialize(ProtocolVersion protocolVersion) { assert rowMark == null || protocolVersion == rowMark.protocolVersion; try (DataOutputBuffer out = new DataOutputBufferFixed(serializedSize(protocolVersion))) { ByteBuffer pk = partitionKey == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : partitionKey; ByteBuffer mark = rowMark == null ? ByteBufferUtil.EMPTY_BYTE_BUFFER : rowMark.mark; if (protocolVersion.isSmallerOrEqualTo(ProtocolVersion.V3)) { ByteBufferUtil.writeWithShortLength(pk, out); ByteBufferUtil.writeWithShortLength(mark, out); out.writeInt(remaining); out.writeInt(remainingInPartition); } else { ByteBufferUtil.writeWithVIntLength(pk, out); ByteBufferUtil.writeWithVIntLength(mark, out); out.writeUnsignedVInt(remaining); out.writeUnsignedVInt(remainingInPartition); } return out.buffer(); } catch (IOException e) { throw new RuntimeException(e); } }
public ByteBuffer toBytes() { DataOutputBuffer out = new DataOutputBuffer(); serializer.serialize(this, out, MessagingService.current_version); return ByteBuffer.wrap(out.getData(), 0, out.getLength()); }
private void handleFailure(Throwable t) { if (message.doCallbackOnFailure()) { MessageOut response = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE) .withParameter(MessagingService.FAILURE_RESPONSE_PARAM, MessagingService.ONE_BYTE); if (t instanceof TombstoneOverwhelmingException) { try (DataOutputBuffer out = new DataOutputBuffer()) { out.writeShort(RequestFailureReason.READ_TOO_MANY_TOMBSTONES.code); response = response.withParameter(MessagingService.FAILURE_REASON_PARAM, out.getData()); } catch (IOException ex) { throw new RuntimeException(ex); } } MessagingService.instance().sendReply(response, id, message.from); } }
private DataOutputBuffer reuseOrAllocateBuffer() { // Check whether a reusable DataOutputBuffer already exists for this // ColumnIndex instance and return it. if (reusableBuffer != null) { DataOutputBuffer buffer = reusableBuffer; buffer.clear(); return buffer; } // don't use the standard RECYCLER as that only recycles up to 1MB and requires proper cleanup return new DataOutputBuffer(DatabaseDescriptor.getColumnIndexCacheSize() * 2); }
@VisibleForTesting long calculateNewSize(long count) { long capacity = capacity(); //Both sides of this max expression need to use long arithmetic to avoid integer overflow //count and capacity are longs so that ensures it right now. long newSize = capacity + count; //For large buffers don't double, increase by 50% if (capacity > 1024L * 1024L * DOUBLING_THRESHOLD) newSize = Math.max((capacity * 3L) / 2L, newSize); else newSize = Math.max(capacity * 2L, newSize); return validateReallocation(newSize); }
private static ByteBuffer serializeMutations(Collection<Mutation> mutations, int version) { DataOutputBuffer buf = new DataOutputBuffer(); try { buf.writeInt(mutations.size()); for (Mutation mutation : mutations) Mutation.serializer.serialize(mutation, buf, version); } catch (IOException e) { throw new AssertionError(); // cannot happen. } return buf.asByteBuffer(); }
public ByteBuffer buffer() { return buffer != null ? buffer.buffer() : null; }
private static Map<UUID, ByteBuffer> truncationAsMapEntry(ColumnFamilyStore cfs, long truncatedAt, CommitLogPosition position) { try (DataOutputBuffer out = DataOutputBuffer.scratchBuffer.get()) { CommitLogPosition.serializer.serialize(position, out); out.writeLong(truncatedAt); return singletonMap(cfs.metadata.cfId, out.asNewBuffer()); } catch (IOException e) { throw new RuntimeException(e); } }
public static void serializeOffsets(DataOutputBuffer out, int[] indexOffsets, int columnIndexCount) throws IOException { for (int i = 0; i < columnIndexCount; i++) out.writeInt(indexOffsets[i]); } }
DataOutputBuffer buffer = new DataOutputBuffer(size); StreamInitMessage.serializer.serialize(this, buffer, version); bytes = buffer.getData();
/** * Serialize a partition update as a byte buffer. * * @param update the partition update to serialize. * @param version the version to serialize the update into. * * @return a newly allocated byte buffer containing the serialized update. */ public static ByteBuffer toBytes(PartitionUpdate update, int version) { try (DataOutputBuffer out = new DataOutputBuffer()) { serializer.serialize(update, out, version); return out.asNewBuffer(); } catch (IOException e) { throw new RuntimeException(e); } }