Merge branch 'cassandra-2.2' into cassandra-3.0 Conflicts: src/java/org/apache/cassandra/io/util/SequentialWriter.java src/java/org/apache/cassandra/utils/concurrent/Transactional.java
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/1c27abf6 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/1c27abf6 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/1c27abf6 Branch: refs/heads/trunk Commit: 1c27abf6c3f8199cd75b8b1930ce3a8285e627bb Parents: be45eb6 a3fc425 Author: Benedict Elliott Smith <bened...@apache.org> Authored: Fri Aug 21 09:58:27 2015 +0100 Committer: Benedict Elliott Smith <bened...@apache.org> Committed: Fri Aug 21 09:58:27 2015 +0100 ---------------------------------------------------------------------- .../apache/cassandra/cache/AutoSavingCache.java | 29 ++++++++++---------- .../cassandra/io/util/SequentialWriter.java | 12 +++++++- .../utils/concurrent/Transactional.java | 7 ++++- .../cassandra/io/util/DataOutputTest.java | 3 +- .../cassandra/io/util/SequentialWriterTest.java | 24 ++++++++++++++++ 5 files changed, 56 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/1c27abf6/src/java/org/apache/cassandra/cache/AutoSavingCache.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/1c27abf6/src/java/org/apache/cassandra/io/util/SequentialWriter.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/io/util/SequentialWriter.java index 905a5c6,0c39469..0375e23 --- a/src/java/org/apache/cassandra/io/util/SequentialWriter.java +++ b/src/java/org/apache/cassandra/io/util/SequentialWriter.java @@@ -170,6 -168,79 +171,12 @@@ public class SequentialWriter extends B return new CompressedSequentialWriter(new File(dataFilePath), offsetsPath, parameters, sstableMetadataCollector); } + public SequentialWriter finishOnClose() + { + finishOnClose = true; + return this; + } + - public void write(int value) throws ClosedChannelException - { - if (buffer == null) - throw new ClosedChannelException(); - - if (!buffer.hasRemaining()) - { - reBuffer(); - } - - buffer.put((byte) value); - - isDirty = true; - syncNeeded = true; - } - - public void write(byte[] buffer) throws IOException - { - write(buffer, 0, buffer.length); - } - - public void write(byte[] data, int offset, int length) throws IOException - { - if (buffer == null) - throw new ClosedChannelException(); - - int position = offset; - int remaining = length; - while (remaining > 0) - { - if (!buffer.hasRemaining()) - reBuffer(); - - int toCopy = Math.min(remaining, buffer.remaining()); - buffer.put(data, position, toCopy); - - remaining -= toCopy; - position += toCopy; - - isDirty = true; - syncNeeded = true; - } - } - - public int write(ByteBuffer src) throws IOException - { - if (buffer == null) - throw new ClosedChannelException(); - - int length = src.remaining(); - int finalLimit = src.limit(); - while (src.hasRemaining()) - { - if (!buffer.hasRemaining()) - reBuffer(); - - if (buffer.remaining() < src.remaining()) - src.limit(src.position() + buffer.remaining()); - buffer.put(src); - src.limit(finalLimit); - - isDirty = true; - syncNeeded = true; - } - return length; - } - /** * Synchronize file contents with disk. */ http://git-wip-us.apache.org/repos/asf/cassandra/blob/1c27abf6/src/java/org/apache/cassandra/utils/concurrent/Transactional.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/utils/concurrent/Transactional.java index f79a795,85c3de5..02562ce --- a/src/java/org/apache/cassandra/utils/concurrent/Transactional.java +++ b/src/java/org/apache/cassandra/utils/concurrent/Transactional.java @@@ -41,14 -41,14 +41,19 @@@ import static org.apache.cassandra.util * If everything completes normally, then on exiting the try block the auto close method will invoke cleanup * to release any temporary state/resources * - * No exceptions should be thrown during commit; if they are, it is not at all clear what the correct behaviour + * All exceptions and assertions that may be thrown should be checked and ruled out during commit preparation. + * Commit should generally never throw an exception unless there is a real correctness-affecting exception that + * cannot be moved to prepareToCommit, in which case this operation MUST be executed before any other commit + * methods in the object graph. + * + * If exceptions are generated by commit after this initial moment, it is not at all clear what the correct behaviour * of the system should be, and so simply logging the exception is likely best (since it may have been an issue - * during cleanup, say), and rollback cannot now occur. + * during cleanup, say), and rollback cannot now occur. As such all exceptions and assertions that may be thrown + * should be checked and ruled out during commit preparation. + * + * Since Transactional implementations will abort any changes they've made if calls to prepareToCommit() and commit() + * aren't made prior to calling close(), the semantics of its close() method differ significantly from + * most AutoCloseable implementations. */ public interface Transactional extends AutoCloseable {