use of org.apache.cassandra.io.util.DataOutputBuffer in project cassandra by apache.
the class ColumnIndex method reuseOrAllocateBuffer.
private DataOutputBuffer reuseOrAllocateBuffer() {
// 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);
}
use of org.apache.cassandra.io.util.DataOutputBuffer in project cassandra by apache.
the class UnfilteredSerializer method serialize.
private void serialize(Row row, SerializationHeader header, DataOutputPlus out, long previousUnfilteredSize, int version) throws IOException {
int flags = 0;
int extendedFlags = 0;
boolean isStatic = row.isStatic();
Columns headerColumns = header.columns(isStatic);
LivenessInfo pkLiveness = row.primaryKeyLivenessInfo();
Row.Deletion deletion = row.deletion();
boolean hasComplexDeletion = row.hasComplexDeletion();
boolean hasAllColumns = (row.size() == headerColumns.size());
boolean hasExtendedFlags = hasExtendedFlags(row);
if (isStatic)
extendedFlags |= IS_STATIC;
if (!pkLiveness.isEmpty())
flags |= HAS_TIMESTAMP;
if (pkLiveness.isExpiring())
flags |= HAS_TTL;
if (!deletion.isLive()) {
flags |= HAS_DELETION;
if (deletion.isShadowable())
extendedFlags |= HAS_SHADOWABLE_DELETION;
}
if (hasComplexDeletion)
flags |= HAS_COMPLEX_DELETION;
if (hasAllColumns)
flags |= HAS_ALL_COLUMNS;
if (hasExtendedFlags)
flags |= EXTENSION_FLAG;
out.writeByte((byte) flags);
if (hasExtendedFlags)
out.writeByte((byte) extendedFlags);
if (!isStatic)
Clustering.serializer.serialize(row.clustering(), out, version, header.clusteringTypes());
if (header.isForSSTable()) {
try (DataOutputBuffer dob = DataOutputBuffer.scratchBuffer.get()) {
serializeRowBody(row, flags, header, dob);
out.writeUnsignedVInt(dob.position() + TypeSizes.sizeofUnsignedVInt(previousUnfilteredSize));
// We write the size of the previous unfiltered to make reverse queries more efficient (and simpler).
// This is currently not used however and using it is tbd.
out.writeUnsignedVInt(previousUnfilteredSize);
out.write(dob.getData(), 0, dob.getLength());
}
} else {
serializeRowBody(row, flags, header, out);
}
}
use of org.apache.cassandra.io.util.DataOutputBuffer in project cassandra by apache.
the class HintsWriter method create.
// HintsWriter owns channel
@SuppressWarnings("resource")
static HintsWriter create(File directory, HintsDescriptor descriptor) throws IOException {
File file = new File(directory, descriptor.fileName());
FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW);
int fd = CLibrary.getfd(channel);
CRC32 crc = new CRC32();
try (DataOutputBuffer dob = DataOutputBuffer.scratchBuffer.get()) {
// write the descriptor
descriptor.serialize(dob);
ByteBuffer descriptorBytes = dob.buffer();
updateChecksum(crc, descriptorBytes);
channel.write(descriptorBytes);
} catch (Throwable e) {
channel.close();
throw e;
}
if (descriptor.isEncrypted())
return new EncryptedHintsWriter(directory, descriptor, file, channel, fd, crc);
if (descriptor.isCompressed())
return new CompressedHintsWriter(directory, descriptor, file, channel, fd, crc);
return new HintsWriter(directory, descriptor, file, channel, fd, crc);
}
use of org.apache.cassandra.io.util.DataOutputBuffer in project cassandra by apache.
the class MessageDeliveryTask method handleFailure.
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);
}
}
use of org.apache.cassandra.io.util.DataOutputBuffer in project cassandra by apache.
the class MessageOut method serialize.
public void serialize(DataOutputPlus out, int version) throws IOException {
CompactEndpointSerializationHelper.serialize(from, out);
out.writeInt(verb.getId());
out.writeInt(parameters.size());
for (Map.Entry<String, byte[]> entry : parameters.entrySet()) {
out.writeUTF(entry.getKey());
out.writeInt(entry.getValue().length);
out.write(entry.getValue());
}
if (payload != null) {
try (DataOutputBuffer dob = DataOutputBuffer.scratchBuffer.get()) {
serializer.serialize(payload, dob, version);
int size = dob.getLength();
out.writeInt(size);
out.write(dob.getData(), 0, size);
}
} else {
out.writeInt(0);
}
}
Aggregations