You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2015/02/19 13:05:42 UTC
[1/3] cassandra git commit: Improve assertions in Memory
Repository: cassandra
Updated Branches:
refs/heads/cassandra-2.1 9d421f354 -> 5da4c4b16
refs/heads/trunk 4b16c1116 -> 65617aa0a
Improve assertions in Memory
patch by benedict; reviewed by jbellis for CASSANDRA-8792
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5da4c4b1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5da4c4b1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5da4c4b1
Branch: refs/heads/cassandra-2.1
Commit: 5da4c4b16d059f160730c2debe823b4caae082e8
Parents: 9d421f3
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Thu Feb 19 12:05:08 2015 +0000
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Thu Feb 19 12:05:08 2015 +0000
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../org/apache/cassandra/io/util/Memory.java | 40 ++++++++++----------
2 files changed, 22 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5da4c4b1/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1238173..7980855 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
2.1.4
+ * Improve assertions in Memory (CASSANDRA-8792)
* Fix SSTableRewriter cleanup (CASSANDRA-8802)
* Introduce SafeMemory for CompressionMetadata.Writer (CASSANDRA-8758)
* 'nodetool info' prints exception against older node (CASSANDRA-8796)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5da4c4b1/src/java/org/apache/cassandra/io/util/Memory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/Memory.java b/src/java/org/apache/cassandra/io/util/Memory.java
index 2e7f28f..ea78840 100644
--- a/src/java/org/apache/cassandra/io/util/Memory.java
+++ b/src/java/org/apache/cassandra/io/util/Memory.java
@@ -54,9 +54,13 @@ public class Memory implements AutoCloseable
protected Memory(long bytes)
{
+ if (bytes <= 0)
+ throw new AssertionError();
size = bytes;
peer = allocator.allocate(size);
- if (size != 0 && peer == 0)
+ // we permit a 0 peer iff size is zero, since such an allocation makes no sense, and an allocator would be
+ // justified in returning a null pointer (and permitted to do so: http://www.cplusplus.com/reference/cstdlib/malloc)
+ if (peer == 0)
throw new OutOfMemoryError();
}
@@ -78,20 +82,20 @@ public class Memory implements AutoCloseable
public void setByte(long offset, byte b)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 1);
unsafe.putByte(peer + offset, b);
}
public void setMemory(long offset, long bytes, byte b)
{
+ checkBounds(offset, offset + bytes);
// check if the last element will fit into the memory
- checkPosition(offset + bytes - 1);
unsafe.setMemory(peer + offset, bytes, b);
}
public void setLong(long offset, long l)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 8);
if (unaligned)
{
unsafe.putLong(peer + offset, l);
@@ -130,7 +134,7 @@ public class Memory implements AutoCloseable
public void setInt(long offset, int l)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 4);
if (unaligned)
{
unsafe.putInt(peer + offset, l);
@@ -165,7 +169,8 @@ public class Memory implements AutoCloseable
throw new NullPointerException();
else if (buffer.remaining() == 0)
return;
- checkPosition(memoryOffset + buffer.remaining());
+
+ checkBounds(memoryOffset, memoryOffset + buffer.remaining());
if (buffer.hasArray())
{
setBytes(memoryOffset, buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
@@ -196,22 +201,21 @@ public class Memory implements AutoCloseable
else if (count == 0)
return;
- checkPosition(memoryOffset);
long end = memoryOffset + count;
- checkPosition(end - 1);
+ checkBounds(memoryOffset, end);
unsafe.copyMemory(buffer, BYTE_ARRAY_BASE_OFFSET + bufferOffset, null, peer + memoryOffset, count);
}
public byte getByte(long offset)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 1);
return unsafe.getByte(peer + offset);
}
public long getLong(long offset)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 8);
if (unaligned) {
return unsafe.getLong(peer + offset);
} else {
@@ -243,7 +247,7 @@ public class Memory implements AutoCloseable
public int getInt(long offset)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 4);
if (unaligned) {
return unsafe.getInt(peer + offset);
} else {
@@ -282,18 +286,15 @@ public class Memory implements AutoCloseable
else if (count == 0)
return;
- checkPosition(memoryOffset);
- long end = memoryOffset + count;
- checkPosition(end - 1);
-
+ checkBounds(memoryOffset, memoryOffset + count);
FastByteOperations.UnsafeOperations.copy(null, peer + memoryOffset, buffer, bufferOffset, count);
}
@Inline
- protected void checkPosition(long offset)
+ protected void checkBounds(long start, long end)
{
assert peer != 0 : "Memory was freed";
- assert offset >= 0 && offset < size : "Illegal offset: " + offset + ", size: " + size;
+ assert start >= 0 && end <= size && start <= end : "Illegal bounds [" + start + ".." + end + "); size: " + size;
}
public void put(long trgOffset, Memory memory, long srcOffset, long size)
@@ -310,8 +311,8 @@ public class Memory implements AutoCloseable
public void free()
{
- assert peer != 0;
- allocator.free(peer);
+ if (peer != 0) allocator.free(peer);
+ else assert size == 0;
peer = 0;
}
@@ -365,4 +366,5 @@ public class Memory implements AutoCloseable
{
return String.format("Memory@[%x..%x)", peer, peer + size);
}
+
}
[3/3] cassandra git commit: Merge branch 'cassandra-2.1' into trunk
Posted by be...@apache.org.
Merge branch 'cassandra-2.1' into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/65617aa0
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/65617aa0
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/65617aa0
Branch: refs/heads/trunk
Commit: 65617aa0ac987cfe4239935b848ab84be09e3cab
Parents: 4b16c11 5da4c4b
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Thu Feb 19 12:05:29 2015 +0000
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Thu Feb 19 12:05:29 2015 +0000
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../org/apache/cassandra/io/util/Memory.java | 40 ++++++++++----------
2 files changed, 22 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/65617aa0/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 8115386,7980855..61e956f
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,63 -1,5 +1,64 @@@
+3.0
+ * Add role based access control (CASSANDRA-7653, 8650, 7216)
+ * Avoid accessing partitioner through StorageProxy (CASSANDRA-8244, 8268)
+ * Upgrade Metrics library and remove depricated metrics (CASSANDRA-5657)
+ * Serializing Row cache alternative, fully off heap (CASSANDRA-7438)
+ * Duplicate rows returned when in clause has repeated values (CASSANDRA-6707)
+ * Make CassandraException unchecked, extend RuntimeException (CASSANDRA-8560)
+ * Support direct buffer decompression for reads (CASSANDRA-8464)
+ * DirectByteBuffer compatible LZ4 methods (CASSANDRA-7039)
+ * Group sstables for anticompaction correctly (CASSANDRA-8578)
+ * Add ReadFailureException to native protocol, respond
+ immediately when replicas encounter errors while handling
+ a read request (CASSANDRA-7886)
+ * Switch CommitLogSegment from RandomAccessFile to nio (CASSANDRA-8308)
+ * Allow mixing token and partition key restrictions (CASSANDRA-7016)
+ * Support index key/value entries on map collections (CASSANDRA-8473)
+ * Modernize schema tables (CASSANDRA-8261)
+ * Support for user-defined aggregation functions (CASSANDRA-8053)
+ * Fix NPE in SelectStatement with empty IN values (CASSANDRA-8419)
+ * Refactor SelectStatement, return IN results in natural order instead
+ of IN value list order and ignore duplicate values in partition key IN restrictions (CASSANDRA-7981)
+ * Support UDTs, tuples, and collections in user-defined
+ functions (CASSANDRA-7563)
+ * Fix aggregate fn results on empty selection, result column name,
+ and cqlsh parsing (CASSANDRA-8229)
+ * Mark sstables as repaired after full repair (CASSANDRA-7586)
+ * Extend Descriptor to include a format value and refactor reader/writer
+ APIs (CASSANDRA-7443)
+ * Integrate JMH for microbenchmarks (CASSANDRA-8151)
+ * Keep sstable levels when bootstrapping (CASSANDRA-7460)
+ * Add Sigar library and perform basic OS settings check on startup (CASSANDRA-7838)
+ * Support for aggregation functions (CASSANDRA-4914)
+ * Remove cassandra-cli (CASSANDRA-7920)
+ * Accept dollar quoted strings in CQL (CASSANDRA-7769)
+ * Make assassinate a first class command (CASSANDRA-7935)
+ * Support IN clause on any partition key column (CASSANDRA-7855)
+ * Support IN clause on any clustering column (CASSANDRA-4762)
+ * Improve compaction logging (CASSANDRA-7818)
+ * Remove YamlFileNetworkTopologySnitch (CASSANDRA-7917)
+ * Do anticompaction in groups (CASSANDRA-6851)
+ * Support user-defined functions (CASSANDRA-7395, 7526, 7562, 7740, 7781, 7929,
+ 7924, 7812, 8063, 7813, 7708)
+ * Permit configurable timestamps with cassandra-stress (CASSANDRA-7416)
+ * Move sstable RandomAccessReader to nio2, which allows using the
+ FILE_SHARE_DELETE flag on Windows (CASSANDRA-4050)
+ * Remove CQL2 (CASSANDRA-5918)
+ * Add Thrift get_multi_slice call (CASSANDRA-6757)
+ * Optimize fetching multiple cells by name (CASSANDRA-6933)
+ * Allow compilation in java 8 (CASSANDRA-7028)
+ * Make incremental repair default (CASSANDRA-7250)
+ * Enable code coverage thru JaCoCo (CASSANDRA-7226)
+ * Switch external naming of 'column families' to 'tables' (CASSANDRA-4369)
+ * Shorten SSTable path (CASSANDRA-6962)
+ * Use unsafe mutations for most unit tests (CASSANDRA-6969)
+ * Fix race condition during calculation of pending ranges (CASSANDRA-7390)
+ * Fail on very large batch sizes (CASSANDRA-8011)
+ * Improve concurrency of repair (CASSANDRA-6455, 8208)
+
+
2.1.4
+ * Improve assertions in Memory (CASSANDRA-8792)
* Fix SSTableRewriter cleanup (CASSANDRA-8802)
* Introduce SafeMemory for CompressionMetadata.Writer (CASSANDRA-8758)
* 'nodetool info' prints exception against older node (CASSANDRA-8796)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/65617aa0/src/java/org/apache/cassandra/io/util/Memory.java
----------------------------------------------------------------------
[2/3] cassandra git commit: Improve assertions in Memory
Posted by be...@apache.org.
Improve assertions in Memory
patch by benedict; reviewed by jbellis for CASSANDRA-8792
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5da4c4b1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5da4c4b1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5da4c4b1
Branch: refs/heads/trunk
Commit: 5da4c4b16d059f160730c2debe823b4caae082e8
Parents: 9d421f3
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Thu Feb 19 12:05:08 2015 +0000
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Thu Feb 19 12:05:08 2015 +0000
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../org/apache/cassandra/io/util/Memory.java | 40 ++++++++++----------
2 files changed, 22 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5da4c4b1/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 1238173..7980855 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
2.1.4
+ * Improve assertions in Memory (CASSANDRA-8792)
* Fix SSTableRewriter cleanup (CASSANDRA-8802)
* Introduce SafeMemory for CompressionMetadata.Writer (CASSANDRA-8758)
* 'nodetool info' prints exception against older node (CASSANDRA-8796)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5da4c4b1/src/java/org/apache/cassandra/io/util/Memory.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/Memory.java b/src/java/org/apache/cassandra/io/util/Memory.java
index 2e7f28f..ea78840 100644
--- a/src/java/org/apache/cassandra/io/util/Memory.java
+++ b/src/java/org/apache/cassandra/io/util/Memory.java
@@ -54,9 +54,13 @@ public class Memory implements AutoCloseable
protected Memory(long bytes)
{
+ if (bytes <= 0)
+ throw new AssertionError();
size = bytes;
peer = allocator.allocate(size);
- if (size != 0 && peer == 0)
+ // we permit a 0 peer iff size is zero, since such an allocation makes no sense, and an allocator would be
+ // justified in returning a null pointer (and permitted to do so: http://www.cplusplus.com/reference/cstdlib/malloc)
+ if (peer == 0)
throw new OutOfMemoryError();
}
@@ -78,20 +82,20 @@ public class Memory implements AutoCloseable
public void setByte(long offset, byte b)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 1);
unsafe.putByte(peer + offset, b);
}
public void setMemory(long offset, long bytes, byte b)
{
+ checkBounds(offset, offset + bytes);
// check if the last element will fit into the memory
- checkPosition(offset + bytes - 1);
unsafe.setMemory(peer + offset, bytes, b);
}
public void setLong(long offset, long l)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 8);
if (unaligned)
{
unsafe.putLong(peer + offset, l);
@@ -130,7 +134,7 @@ public class Memory implements AutoCloseable
public void setInt(long offset, int l)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 4);
if (unaligned)
{
unsafe.putInt(peer + offset, l);
@@ -165,7 +169,8 @@ public class Memory implements AutoCloseable
throw new NullPointerException();
else if (buffer.remaining() == 0)
return;
- checkPosition(memoryOffset + buffer.remaining());
+
+ checkBounds(memoryOffset, memoryOffset + buffer.remaining());
if (buffer.hasArray())
{
setBytes(memoryOffset, buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
@@ -196,22 +201,21 @@ public class Memory implements AutoCloseable
else if (count == 0)
return;
- checkPosition(memoryOffset);
long end = memoryOffset + count;
- checkPosition(end - 1);
+ checkBounds(memoryOffset, end);
unsafe.copyMemory(buffer, BYTE_ARRAY_BASE_OFFSET + bufferOffset, null, peer + memoryOffset, count);
}
public byte getByte(long offset)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 1);
return unsafe.getByte(peer + offset);
}
public long getLong(long offset)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 8);
if (unaligned) {
return unsafe.getLong(peer + offset);
} else {
@@ -243,7 +247,7 @@ public class Memory implements AutoCloseable
public int getInt(long offset)
{
- checkPosition(offset);
+ checkBounds(offset, offset + 4);
if (unaligned) {
return unsafe.getInt(peer + offset);
} else {
@@ -282,18 +286,15 @@ public class Memory implements AutoCloseable
else if (count == 0)
return;
- checkPosition(memoryOffset);
- long end = memoryOffset + count;
- checkPosition(end - 1);
-
+ checkBounds(memoryOffset, memoryOffset + count);
FastByteOperations.UnsafeOperations.copy(null, peer + memoryOffset, buffer, bufferOffset, count);
}
@Inline
- protected void checkPosition(long offset)
+ protected void checkBounds(long start, long end)
{
assert peer != 0 : "Memory was freed";
- assert offset >= 0 && offset < size : "Illegal offset: " + offset + ", size: " + size;
+ assert start >= 0 && end <= size && start <= end : "Illegal bounds [" + start + ".." + end + "); size: " + size;
}
public void put(long trgOffset, Memory memory, long srcOffset, long size)
@@ -310,8 +311,8 @@ public class Memory implements AutoCloseable
public void free()
{
- assert peer != 0;
- allocator.free(peer);
+ if (peer != 0) allocator.free(peer);
+ else assert size == 0;
peer = 0;
}
@@ -365,4 +366,5 @@ public class Memory implements AutoCloseable
{
return String.format("Memory@[%x..%x)", peer, peer + size);
}
+
}