cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject cassandra git commit: Rename DataOutputBuffer.getFilePointer() to position()
Date Tue, 15 Sep 2015 22:44:41 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.0 a54589e12 -> 753a94332


Rename DataOutputBuffer.getFilePointer() to position()

patch by Robert Stupp; reviewed by Benedict for CASSANDRA-10349


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/753a9433
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/753a9433
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/753a9433

Branch: refs/heads/cassandra-3.0
Commit: 753a9433228cb4579f0602b9292dd16944339607
Parents: a54589e
Author: Robert Stupp <snazy@snazy.de>
Authored: Wed Sep 16 00:43:11 2015 +0200
Committer: Robert Stupp <snazy@snazy.de>
Committed: Wed Sep 16 00:43:11 2015 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/db/ColumnIndex.java    |  6 +++---
 .../org/apache/cassandra/db/RowIndexEntry.java  |  6 +++---
 .../io/sstable/format/big/BigTableWriter.java   | 12 +++++------
 .../cassandra/io/util/DataOutputBuffer.java     |  4 ++--
 .../cassandra/io/util/DataOutputPlus.java       | 21 ++++++++++++++++----
 .../cassandra/io/util/SequentialWriter.java     |  6 +++---
 .../apache/cassandra/db/RowIndexEntryTest.java  |  4 ++--
 .../io/util/BufferedRandomAccessFileTest.java   | 10 +++++-----
 .../compression/CompressedInputStreamTest.java  |  2 +-
 9 files changed, 42 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/src/java/org/apache/cassandra/db/ColumnIndex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/ColumnIndex.java b/src/java/org/apache/cassandra/db/ColumnIndex.java
index 6b2ef59..add5fa7 100644
--- a/src/java/org/apache/cassandra/db/ColumnIndex.java
+++ b/src/java/org/apache/cassandra/db/ColumnIndex.java
@@ -91,7 +91,7 @@ public class ColumnIndex
             this.writer = writer;
             this.header = header;
             this.version = version;
-            this.initialPosition = writer.getFilePointer();
+            this.initialPosition = writer.position();
         }
 
         private void writePartitionHeader(UnfilteredRowIterator iterator) throws IOException
@@ -105,7 +105,7 @@ public class ColumnIndex
         public ColumnIndex build() throws IOException
         {
             writePartitionHeader(iterator);
-            this.headerLength = writer.getFilePointer() - initialPosition;
+            this.headerLength = writer.position() - initialPosition;
 
             while (iterator.hasNext())
                 add(iterator.next());
@@ -115,7 +115,7 @@ public class ColumnIndex
 
         private long currentPosition()
         {
-            return writer.getFilePointer() - initialPosition;
+            return writer.position() - initialPosition;
         }
 
         private void addIndexBlock()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/src/java/org/apache/cassandra/db/RowIndexEntry.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/RowIndexEntry.java b/src/java/org/apache/cassandra/db/RowIndexEntry.java
index 6cd6542..43dc80c 100644
--- a/src/java/org/apache/cassandra/db/RowIndexEntry.java
+++ b/src/java/org/apache/cassandra/db/RowIndexEntry.java
@@ -142,15 +142,15 @@ public class RowIndexEntry<T> implements IMeasurableMemory
 
                 int[] offsets = new int[rie.columnsIndex().size()];
 
-                if (out.hasFilePointer())
+                if (out.hasPosition())
                 {
                     // Out is usually a SequentialWriter, so using the file-pointer is fine
to generate the offsets.
                     // A DataOutputBuffer also works.
-                    long start = out.getFilePointer();
+                    long start = out.position();
                     int i = 0;
                     for (IndexHelper.IndexInfo info : rie.columnsIndex())
                     {
-                        offsets[i] = i == 0 ? 0 : (int)(out.getFilePointer() - start);
+                        offsets[i] = i == 0 ? 0 : (int)(out.position() - start);
                         i++;
                         idxSerializer.serialize(info, out);
                     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java b/src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java
index 089ae6f..3d68a74 100644
--- a/src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java
+++ b/src/java/org/apache/cassandra/io/sstable/format/big/BigTableWriter.java
@@ -107,7 +107,7 @@ public class BigTableWriter extends SSTableWriter
         assert decoratedKey != null : "Keys must not be null"; // empty keys ARE allowed
b/c of indexed column values
         //if (lastWrittenKey != null && lastWrittenKey.compareTo(decoratedKey) >=
0)
         //    throw new RuntimeException("Last written key " + lastWrittenKey + " >= current
key " + decoratedKey + " writing into " + getFilename());
-        return (lastWrittenKey == null) ? 0 : dataFile.getFilePointer();
+        return (lastWrittenKey == null) ? 0 : dataFile.position();
     }
 
     private void afterAppend(DecoratedKey decoratedKey, long dataEnd, RowIndexEntry index)
throws IOException
@@ -153,7 +153,7 @@ public class BigTableWriter extends SSTableWriter
 
             RowIndexEntry entry = RowIndexEntry.create(startPosition, iterator.partitionLevelDeletion(),
index);
 
-            long endPosition = dataFile.getFilePointer();
+            long endPosition = dataFile.position();
             long rowSize = endPosition - startPosition;
             maybeLogLargePartitionWarning(key, rowSize);
             metadataCollector.addPartitionSizeInBytes(rowSize);
@@ -352,7 +352,7 @@ public class BigTableWriter extends SSTableWriter
 
     public long getFilePointer()
     {
-        return dataFile.getFilePointer();
+        return dataFile.position();
     }
 
     public long getOnDiskFilePointer()
@@ -403,7 +403,7 @@ public class BigTableWriter extends SSTableWriter
         public void append(DecoratedKey key, RowIndexEntry indexEntry, long dataEnd) throws
IOException
         {
             bf.add(key);
-            long indexStart = indexFile.getFilePointer();
+            long indexStart = indexFile.position();
             try
             {
                 ByteBufferUtil.writeWithShortLength(key.getKey(), indexFile);
@@ -413,7 +413,7 @@ public class BigTableWriter extends SSTableWriter
             {
                 throw new FSWriteError(e, indexFile.getPath());
             }
-            long indexEnd = indexFile.getFilePointer();
+            long indexEnd = indexFile.position();
 
             if (logger.isTraceEnabled())
                 logger.trace("wrote index entry: {} at {}", indexEntry, indexStart);
@@ -462,7 +462,7 @@ public class BigTableWriter extends SSTableWriter
             flushBf();
 
             // truncate index file
-            long position = iwriter.indexFile.getFilePointer();
+            long position = iwriter.indexFile.position();
             iwriter.indexFile.setDescriptor(descriptor).prepareToCommit();
             FileUtils.truncate(iwriter.indexFile.getPath(), position);
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java b/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
index c4d6f54..4ba5546 100644
--- a/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
+++ b/src/java/org/apache/cassandra/io/util/DataOutputBuffer.java
@@ -114,12 +114,12 @@ public class DataOutputBuffer extends BufferedDataOutputStreamPlus
         return buffer.position();
     }
 
-    public boolean hasFilePointer()
+    public boolean hasPosition()
     {
         return true;
     }
 
-    public long getFilePointer()
+    public long position()
     {
         return getLength();
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/src/java/org/apache/cassandra/io/util/DataOutputPlus.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/DataOutputPlus.java b/src/java/org/apache/cassandra/io/util/DataOutputPlus.java
index 551d386..60a5727 100644
--- a/src/java/org/apache/cassandra/io/util/DataOutputPlus.java
+++ b/src/java/org/apache/cassandra/io/util/DataOutputPlus.java
@@ -22,10 +22,10 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.WritableByteChannel;
 
-import org.apache.cassandra.utils.vint.VIntCoding;
-
 import com.google.common.base.Function;
 
+import org.apache.cassandra.utils.vint.VIntCoding;
+
 /**
  * Extension to DataOutput that provides for writing ByteBuffer and Memory, potentially with
an efficient
  * implementation that is zero copy or at least has reduced bounds checking overhead.
@@ -60,12 +60,25 @@ public interface DataOutputPlus extends DataOutput
         VIntCoding.writeUnsignedVInt(i, this);
     }
 
-    default long getFilePointer()
+    /**
+     * Returns the current position of the underlying target like a file-pointer
+     * or the position withing a buffer. Not every implementation may support this
+     * functionality. Whether or not this functionality is supported can be checked
+     * via the {@link #hasPosition()}.
+     *
+     * @throws UnsupportedOperationException if the implementation does not support
+     *                                       position
+     */
+    default long position()
     {
         throw new UnsupportedOperationException();
     }
 
-    default boolean hasFilePointer()
+    /**
+     * If the implementation supports providing a position, this method returns
+     * {@code true}, otherwise {@code false}.
+     */
+    default boolean hasPosition()
     {
         return false;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/src/java/org/apache/cassandra/io/util/SequentialWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/util/SequentialWriter.java b/src/java/org/apache/cassandra/io/util/SequentialWriter.java
index 1814aca..6000f95 100644
--- a/src/java/org/apache/cassandra/io/util/SequentialWriter.java
+++ b/src/java/org/apache/cassandra/io/util/SequentialWriter.java
@@ -253,12 +253,12 @@ public class SequentialWriter extends BufferedDataOutputStreamPlus implements
Tr
             runPostFlush.run();
     }
 
-    public boolean hasFilePointer()
+    public boolean hasPosition()
     {
         return true;
     }
 
-    public long getFilePointer()
+    public long position()
     {
         return current();
     }
@@ -274,7 +274,7 @@ public class SequentialWriter extends BufferedDataOutputStreamPlus implements
Tr
      */
     public long getOnDiskFilePointer()
     {
-        return getFilePointer();
+        return position();
     }
 
     public long length()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java b/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java
index d004d45..25baa4e 100644
--- a/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java
+++ b/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java
@@ -155,12 +155,12 @@ public class RowIndexEntryTest extends CQLTester
         // test with an output stream that doesn't support a file-pointer
         buffer = new DataOutputBuffer()
         {
-            public boolean hasFilePointer()
+            public boolean hasPosition()
             {
                 return false;
             }
 
-            public long getFilePointer()
+            public long position()
             {
                 throw new UnsupportedOperationException();
             }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java b/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
index 364ea71..c3a4539 100644
--- a/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
+++ b/test/unit/org/apache/cassandra/io/util/BufferedRandomAccessFileTest.java
@@ -46,7 +46,7 @@ public class BufferedRandomAccessFileTest
         byte[] data = "Hello".getBytes();
         w.write(data);
         assertEquals(data.length, w.length());
-        assertEquals(data.length, w.getFilePointer());
+        assertEquals(data.length, w.position());
 
         w.sync();
 
@@ -67,9 +67,9 @@ public class BufferedRandomAccessFileTest
         for (int i = 0; i < bigData.length; i++)
             bigData[i] = 'd';
 
-        long initialPosition = w.getFilePointer();
+        long initialPosition = w.position();
         w.write(bigData); // writing data
-        assertEquals(w.getFilePointer(), initialPosition + bigData.length);
+        assertEquals(w.position(), initialPosition + bigData.length);
         assertEquals(w.length(), initialPosition + bigData.length); // file size should equals
to last position
 
         w.sync();
@@ -285,10 +285,10 @@ public class BufferedRandomAccessFileTest
     {
         final SequentialWriter w = createTempFile("brafGetFilePointer");
 
-        assertEquals(w.getFilePointer(), 0); // initial position should be 0
+        assertEquals(w.position(), 0); // initial position should be 0
 
         w.write(generateByteArray(20));
-        assertEquals(w.getFilePointer(), 20); // position 20 after writing 20 bytes
+        assertEquals(w.position(), 20); // position 20 after writing 20 bytes
 
         w.sync();
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/753a9433/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java
b/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java
index fea6d2b..30670fb 100644
--- a/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java
+++ b/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java
@@ -70,7 +70,7 @@ public class CompressedInputStreamTest
         Map<Long, Long> index = new HashMap<Long, Long>();
         for (long l = 0L; l < 1000; l++)
         {
-            index.put(l, writer.getFilePointer());
+            index.put(l, writer.position());
             writer.writeLong(l);
         }
         writer.finish();


Mime
View raw message