mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-3.0' into trunk
This commit is contained in:
commit
cdaba04d31
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -115,12 +115,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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue