mirror of https://github.com/apache/cassandra
For CASSANDRA-9499, update to OHC 0.4 that allow deserialization directly from ByteBuffers
This commit is contained in:
parent
4cea221f95
commit
177e0dcbe4
|
|
@ -406,7 +406,8 @@
|
|||
<dependency groupId="com.datastax.cassandra" artifactId="cassandra-driver-core" version="2.1.5" classifier="shaded" />
|
||||
-->
|
||||
<dependency groupId="org.eclipse.jdt.core.compiler" artifactId="ecj" version="4.4.2" />
|
||||
<dependency groupId="org.caffinitas.ohc" artifactId="ohc-core" version="0.3.4" />
|
||||
<dependency groupId="org.caffinitas.ohc" artifactId="ohc-core" version="0.4" />
|
||||
<dependency groupId="org.caffinitas.ohc" artifactId="ohc-core-j8" version="0.4" />
|
||||
<dependency groupId="net.ju-n.compile-command-annotations" artifactId="compile-command-annotations" version="1.2.0" />
|
||||
<dependency groupId="org.fusesource" artifactId="sigar" version="1.6.4">
|
||||
<exclusion groupId="log4j" artifactId="log4j"/>
|
||||
|
|
@ -460,7 +461,8 @@
|
|||
<dependency groupId="com.datastax.cassandra" artifactId="cassandra-driver-core" classifier="shaded"/>
|
||||
-->
|
||||
<dependency groupId="org.eclipse.jdt.core.compiler" artifactId="ecj"/>
|
||||
<dependency groupId="org.caffinitas.ohc" artifactId="ohc-core"/>
|
||||
<dependency groupId="org.caffinitas.ohc" artifactId="ohc-core" version="0.4" />
|
||||
<dependency groupId="org.caffinitas.ohc" artifactId="ohc-core-j8" version="0.4" />
|
||||
<dependency groupId="org.openjdk.jmh" artifactId="jmh-core"/>
|
||||
<dependency groupId="org.openjdk.jmh" artifactId="jmh-generator-annprocess"/>
|
||||
<dependency groupId="net.ju-n.compile-command-annotations" artifactId="compile-command-annotations"/>
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -17,18 +17,16 @@
|
|||
*/
|
||||
package org.apache.cassandra.cache;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.db.TypeSizes;
|
||||
import org.apache.cassandra.db.partitions.CachedPartition;
|
||||
import org.apache.cassandra.io.util.DataInputPlus.DataInputPlusAdapter;
|
||||
import org.apache.cassandra.io.util.DataOutputPlus;
|
||||
import org.apache.cassandra.io.util.DataOutputBufferFixed;
|
||||
import org.apache.cassandra.io.util.NIODataInputStream;
|
||||
import org.caffinitas.ohc.OHCache;
|
||||
import org.caffinitas.ohc.OHCacheBuilder;
|
||||
|
||||
|
|
@ -123,20 +121,20 @@ public class OHCProvider implements CacheProvider<RowCacheKey, IRowCacheEntry>
|
|||
private static class KeySerializer implements org.caffinitas.ohc.CacheSerializer<RowCacheKey>
|
||||
{
|
||||
private static KeySerializer instance = new KeySerializer();
|
||||
public void serialize(RowCacheKey rowCacheKey, DataOutput dataOutput) throws IOException
|
||||
public void serialize(RowCacheKey rowCacheKey, ByteBuffer buf)
|
||||
{
|
||||
dataOutput.writeLong(rowCacheKey.cfId.getMostSignificantBits());
|
||||
dataOutput.writeLong(rowCacheKey.cfId.getLeastSignificantBits());
|
||||
dataOutput.writeInt(rowCacheKey.key.length);
|
||||
dataOutput.write(rowCacheKey.key);
|
||||
buf.putLong(rowCacheKey.cfId.getMostSignificantBits());
|
||||
buf.putLong(rowCacheKey.cfId.getLeastSignificantBits());
|
||||
buf.putInt(rowCacheKey.key.length);
|
||||
buf.put(rowCacheKey.key);
|
||||
}
|
||||
|
||||
public RowCacheKey deserialize(DataInput dataInput) throws IOException
|
||||
public RowCacheKey deserialize(ByteBuffer buf)
|
||||
{
|
||||
long msb = dataInput.readLong();
|
||||
long lsb = dataInput.readLong();
|
||||
byte[] key = new byte[dataInput.readInt()];
|
||||
dataInput.readFully(key);
|
||||
long msb = buf.getLong();
|
||||
long lsb = buf.getLong();
|
||||
byte[] key = new byte[buf.getInt()];
|
||||
buf.get(key);
|
||||
return new RowCacheKey(new UUID(msb, lsb), key);
|
||||
}
|
||||
|
||||
|
|
@ -149,23 +147,40 @@ public class OHCProvider implements CacheProvider<RowCacheKey, IRowCacheEntry>
|
|||
private static class ValueSerializer implements org.caffinitas.ohc.CacheSerializer<IRowCacheEntry>
|
||||
{
|
||||
private static ValueSerializer instance = new ValueSerializer();
|
||||
public void serialize(IRowCacheEntry entry, DataOutput out) throws IOException
|
||||
public void serialize(IRowCacheEntry entry, ByteBuffer buf)
|
||||
{
|
||||
assert entry != null; // unlike CFS we don't support nulls, since there is no need for that in the cache
|
||||
boolean isSentinel = entry instanceof RowCacheSentinel;
|
||||
out.writeBoolean(isSentinel);
|
||||
if (isSentinel)
|
||||
out.writeLong(((RowCacheSentinel) entry).sentinelId);
|
||||
else
|
||||
CachedPartition.cacheSerializer.serialize((CachedPartition)entry, new DataOutputPlus.DataOutputPlusAdapter(out));
|
||||
DataOutputBufferFixed out = new DataOutputBufferFixed(buf);
|
||||
try
|
||||
{
|
||||
boolean isSentinel = entry instanceof RowCacheSentinel;
|
||||
out.writeBoolean(isSentinel);
|
||||
if (isSentinel)
|
||||
out.writeLong(((RowCacheSentinel) entry).sentinelId);
|
||||
else
|
||||
CachedPartition.cacheSerializer.serialize((CachedPartition)entry, out);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public IRowCacheEntry deserialize(DataInput in) throws IOException
|
||||
@SuppressWarnings("resource")
|
||||
public IRowCacheEntry deserialize(ByteBuffer buf)
|
||||
{
|
||||
boolean isSentinel = in.readBoolean();
|
||||
if (isSentinel)
|
||||
return new RowCacheSentinel(in.readLong());
|
||||
return CachedPartition.cacheSerializer.deserialize(new DataInputPlusAdapter(in));
|
||||
try
|
||||
{
|
||||
NIODataInputStream in = new NIODataInputStream(buf, false);
|
||||
boolean isSentinel = in.readBoolean();
|
||||
if (isSentinel)
|
||||
return new RowCacheSentinel(in.readLong());
|
||||
return CachedPartition.cacheSerializer.deserialize(in);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int serializedSize(IRowCacheEntry entry)
|
||||
|
|
|
|||
|
|
@ -47,114 +47,6 @@ public interface DataInputPlus extends DataInput
|
|||
return VIntCoding.readUnsignedVInt(this);
|
||||
}
|
||||
|
||||
public static class ForwardingDataInput implements DataInput
|
||||
{
|
||||
protected final DataInput in;
|
||||
|
||||
public ForwardingDataInput(DataInput in)
|
||||
{
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFully(byte[] b) throws IOException
|
||||
{
|
||||
in.readFully(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFully(byte[] b, int off, int len) throws IOException
|
||||
{
|
||||
in.readFully(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skipBytes(int n) throws IOException
|
||||
{
|
||||
return in.skipBytes(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readBoolean() throws IOException
|
||||
{
|
||||
return in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte() throws IOException
|
||||
{
|
||||
return in.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedByte() throws IOException
|
||||
{
|
||||
return in.readUnsignedByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort() throws IOException
|
||||
{
|
||||
return in.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedShort() throws IOException
|
||||
{
|
||||
return in.readUnsignedShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char readChar() throws IOException
|
||||
{
|
||||
return in.readChar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt() throws IOException
|
||||
{
|
||||
return in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong() throws IOException
|
||||
{
|
||||
return in.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat() throws IOException
|
||||
{
|
||||
return in.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble() throws IOException
|
||||
{
|
||||
return in.readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readLine() throws IOException
|
||||
{
|
||||
return in.readLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readUTF() throws IOException
|
||||
{
|
||||
return in.readUTF();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DataInputPlusAdapter extends ForwardingDataInput implements DataInputPlus
|
||||
{
|
||||
public DataInputPlusAdapter(DataInput in)
|
||||
{
|
||||
super(in);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around an InputStream that provides no buffering but can decode varints
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -60,112 +60,4 @@ public interface DataOutputPlus extends DataOutput
|
|||
VIntCoding.writeUnsignedVInt(i, this);
|
||||
}
|
||||
|
||||
|
||||
public static class ForwardingDataOutput implements DataOutput
|
||||
{
|
||||
protected final DataOutput out;
|
||||
|
||||
public ForwardingDataOutput(DataOutput out)
|
||||
{
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException
|
||||
{
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException
|
||||
{
|
||||
out.write(b, off, len);
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException
|
||||
{
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
public void writeBoolean(boolean v) throws IOException
|
||||
{
|
||||
out.writeBoolean(v);
|
||||
}
|
||||
|
||||
public void writeByte(int v) throws IOException
|
||||
{
|
||||
out.writeByte(v);
|
||||
}
|
||||
|
||||
public void writeBytes(String s) throws IOException
|
||||
{
|
||||
out.writeBytes(s);
|
||||
}
|
||||
|
||||
public void writeChar(int v) throws IOException
|
||||
{
|
||||
out.writeChar(v);
|
||||
}
|
||||
|
||||
public void writeChars(String s) throws IOException
|
||||
{
|
||||
out.writeChars(s);
|
||||
}
|
||||
|
||||
public void writeDouble(double v) throws IOException
|
||||
{
|
||||
out.writeDouble(v);
|
||||
}
|
||||
|
||||
public void writeFloat(float v) throws IOException
|
||||
{
|
||||
out.writeFloat(v);
|
||||
}
|
||||
|
||||
public void writeInt(int v) throws IOException
|
||||
{
|
||||
out.writeInt(v);
|
||||
}
|
||||
|
||||
public void writeLong(long v) throws IOException
|
||||
{
|
||||
out.writeLong(v);
|
||||
}
|
||||
|
||||
public void writeShort(int v) throws IOException
|
||||
{
|
||||
out.writeShort(v);
|
||||
}
|
||||
|
||||
public void writeUTF(String s) throws IOException
|
||||
{
|
||||
out.writeUTF(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DataOutputPlusAdapter extends ForwardingDataOutput implements DataOutputPlus
|
||||
{
|
||||
|
||||
public DataOutputPlusAdapter(DataOutput out)
|
||||
{
|
||||
super(out);
|
||||
}
|
||||
|
||||
public void write(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
if (buffer.hasArray())
|
||||
out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
|
||||
else
|
||||
throw new UnsupportedOperationException("IMPLEMENT ME");
|
||||
}
|
||||
|
||||
public void write(Memory memory, long offset, long length) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException("IMPLEMENT ME");
|
||||
}
|
||||
|
||||
public <R> R applyToChannel(Function<WritableByteChannel, R> c) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException("IMPLEMENT ME");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue