diff --git a/build.xml b/build.xml
index 88c2e94d78..0362eb4624 100644
--- a/build.xml
+++ b/build.xml
@@ -406,7 +406,8 @@
-->
-
+
+
@@ -460,7 +461,8 @@
-->
-
+
+
diff --git a/lib/ohc-core-0.3.4.jar b/lib/ohc-core-0.3.4.jar
deleted file mode 100644
index 0773e78af0..0000000000
Binary files a/lib/ohc-core-0.3.4.jar and /dev/null differ
diff --git a/lib/ohc-core-0.4.jar b/lib/ohc-core-0.4.jar
new file mode 100644
index 0000000000..1b1b9392c1
Binary files /dev/null and b/lib/ohc-core-0.4.jar differ
diff --git a/lib/ohc-core-j8-0.3.4.jar b/lib/ohc-core-j8-0.3.4.jar
deleted file mode 100644
index faa102fdb6..0000000000
Binary files a/lib/ohc-core-j8-0.3.4.jar and /dev/null differ
diff --git a/lib/ohc-core-j8-0.4.jar b/lib/ohc-core-j8-0.4.jar
new file mode 100644
index 0000000000..f97ddf5b81
Binary files /dev/null and b/lib/ohc-core-j8-0.4.jar differ
diff --git a/src/java/org/apache/cassandra/cache/OHCProvider.java b/src/java/org/apache/cassandra/cache/OHCProvider.java
index 46cbb8bc04..21fc7c7ea3 100644
--- a/src/java/org/apache/cassandra/cache/OHCProvider.java
+++ b/src/java/org/apache/cassandra/cache/OHCProvider.java
@@ -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
private static class KeySerializer implements org.caffinitas.ohc.CacheSerializer
{
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
private static class ValueSerializer implements org.caffinitas.ohc.CacheSerializer
{
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)
diff --git a/src/java/org/apache/cassandra/io/util/DataInputPlus.java b/src/java/org/apache/cassandra/io/util/DataInputPlus.java
index d4e25d6ea2..a0294279a5 100644
--- a/src/java/org/apache/cassandra/io/util/DataInputPlus.java
+++ b/src/java/org/apache/cassandra/io/util/DataInputPlus.java
@@ -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
*/
diff --git a/src/java/org/apache/cassandra/io/util/DataOutputPlus.java b/src/java/org/apache/cassandra/io/util/DataOutputPlus.java
index b46d23ae73..5f3f38468c 100644
--- a/src/java/org/apache/cassandra/io/util/DataOutputPlus.java
+++ b/src/java/org/apache/cassandra/io/util/DataOutputPlus.java
@@ -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 applyToChannel(Function c) throws IOException
- {
- throw new UnsupportedOperationException("IMPLEMENT ME");
- }
- }
}