public abstract class Volume extends Object implements Closeable
MapDB abstraction over raw storage (file, disk partition, memory etc...).
Implementations needs to be thread safe (especially 'ensureAvailable') operation. However updates do not have to be atomic, it is clients responsibility to ensure two threads are not writing/reading into the same location.
Modifier and Type | Class and Description |
---|---|
static class |
Volume.ByteArrayVol |
static class |
Volume.ByteBufferVol
Abstract Volume over bunch of ByteBuffers
It leaves ByteBufferVol details (allocation, disposal) on subclasses.
|
static class |
Volume.ByteBufferVolSingle
Abstract Volume over single ByteBuffer, maximal size is 2GB (32bit limit).
|
static class |
Volume.FileChannelVol
Volume which uses FileChannel.
|
static class |
Volume.MappedFileVol |
static class |
Volume.MappedFileVolSingle |
static class |
Volume.MemoryVol |
static class |
Volume.MemoryVolSingle |
static class |
Volume.RandomAccessFileVol |
static class |
Volume.ReadOnly |
static class |
Volume.SingleByteArrayVol
Volume backed by on-heap byte[] with maximal fixed size 2GB.
|
static class |
Volume.VolumeFactory |
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected static Logger |
LOG |
static Volume.VolumeFactory |
UNSAFE_VOL_FACTORY
If
sun.misc.Unsafe is available it will use Volume based on Unsafe. |
Constructor and Description |
---|
Volume() |
Modifier and Type | Method and Description |
---|---|
void |
assertZeroes(long startOffset,
long endOffset)
Check that all bytes between given offsets are zero.
|
abstract void |
clear(long startOffset,
long endOffset)
Set all bytes between
startOffset and endOffset to zero. |
void |
clearOverlap(long startOffset,
long endOffset) |
abstract void |
close() |
void |
copyEntireVolumeTo(Volume to)
Copy content of this volume to another.
|
void |
deleteFile() |
abstract void |
ensureAvailable(long offset)
Check space allocated by Volume is bigger or equal to given offset.
|
boolean |
fileLoad()
If underlying storage is memory-mapped-file, this method will try to
load and precache all file data into disk cache.
|
protected void |
finalize() |
abstract byte |
getByte(long offset) |
abstract void |
getData(long offset,
byte[] bytes,
int bytesPos,
int size) |
abstract DataInput |
getDataInput(long offset,
int size) |
DataInput |
getDataInputOverlap(long offset,
int size) |
abstract File |
getFile()
returns underlying file if it exists
|
abstract boolean |
getFileLocked()
return true if this Volume holds exclusive lock over its file
|
abstract int |
getInt(long offset) |
abstract long |
getLong(long offset) |
long |
getLongPackBidi(long offset) |
long |
getLongPackBidiReverse(long offset,
long limitOffset) |
long |
getPackedLong(long position)
Unpack long value from the Volume.
|
long |
getSixLong(long pos) |
int |
getUnsignedByte(long offset) |
int |
getUnsignedShort(long offset) |
long |
hash(long off,
long len,
long seed)
Calculates XXHash64 from this Volume content.
|
boolean |
isClosed() |
abstract boolean |
isSliced() |
abstract long |
length() |
abstract void |
putByte(long offset,
byte value) |
abstract void |
putData(long offset,
byte[] src,
int srcPos,
int srcSize) |
abstract void |
putData(long offset,
ByteBuffer buf) |
void |
putDataOverlap(long offset,
byte[] src,
int srcPos,
int srcSize) |
abstract void |
putInt(long offset,
int value) |
abstract void |
putLong(long offset,
long value) |
int |
putLongPackBidi(long offset,
long value) |
int |
putPackedLong(long pos,
long value)
Put packed long at given position.
|
void |
putSixLong(long pos,
long value) |
void |
putUnsignedByte(long offset,
int b) |
void |
putUnsignedShort(long offset,
int value) |
abstract int |
sliceSize() |
abstract void |
sync() |
void |
transferInto(long inputOffset,
Volume target,
long targetOffset,
long size)
Transfers data from this Volume into target volume.
|
abstract void |
truncate(long size) |
static void |
volumeTransfer(long size,
Volume from,
Volume to)
transfer data from one volume to second.
|
protected static final Logger LOG
public static final Volume.VolumeFactory UNSAFE_VOL_FACTORY
sun.misc.Unsafe
is available it will use Volume based on Unsafe.
If Unsafe is not available for some reason (Android), use DirectByteBuffer instead.protected volatile boolean closed
public boolean fileLoad()
If underlying storage is memory-mapped-file, this method will try to
load and precache all file data into disk cache.
Most likely it will call MappedByteBuffer.load()
,
but could also read content of entire file etc
This method will not pin data into memory, they might be removed at any time.
public void assertZeroes(long startOffset, long endOffset) throws DBException.DataCorruption
startOffset
- endOffset
- DBException.DataCorruption
- if some byte is not zeropublic boolean isClosed()
public abstract void ensureAvailable(long offset)
offset
- public abstract void truncate(long size)
public abstract void putLong(long offset, long value)
public abstract void putInt(long offset, int value)
public abstract void putByte(long offset, byte value)
public abstract void putData(long offset, byte[] src, int srcPos, int srcSize)
public abstract void putData(long offset, ByteBuffer buf)
public void putDataOverlap(long offset, byte[] src, int srcPos, int srcSize)
public abstract long getLong(long offset)
public abstract int getInt(long offset)
public abstract byte getByte(long offset)
public abstract DataInput getDataInput(long offset, int size)
public DataInput getDataInputOverlap(long offset, int size)
public abstract void getData(long offset, byte[] bytes, int bytesPos, int size)
public abstract void close()
close
in interface Closeable
close
in interface AutoCloseable
public abstract void sync()
public abstract int sliceSize()
-1
if not slicedpublic void deleteFile()
public abstract boolean isSliced()
public abstract long length()
public void putUnsignedShort(long offset, int value)
public int getUnsignedShort(long offset)
public int getUnsignedByte(long offset)
public void putUnsignedByte(long offset, int b)
public int putLongPackBidi(long offset, long value)
public long getLongPackBidi(long offset)
public long getLongPackBidiReverse(long offset, long limitOffset)
public long getSixLong(long pos)
public void putSixLong(long pos, long value)
public int putPackedLong(long pos, long value)
value
- to be writtenpublic long getPackedLong(long position)
result & DataIO.PACK_LONG_RESULT_MASK
to remove size;position
- to read value frompublic abstract File getFile()
public abstract boolean getFileLocked()
public void transferInto(long inputOffset, Volume target, long targetOffset, long size)
inputOffset
- offset inside this Volume, ie data will be read from this offsettarget
- Volume to copy data intotargetOffset
- position in target volume where data will be copied intosize
- size of data to copypublic abstract void clear(long startOffset, long endOffset)
startOffset
and endOffset
to zero.
Area between offsets must be ready for write once clear finishes.public void clearOverlap(long startOffset, long endOffset)
public void copyEntireVolumeTo(Volume to)
public long hash(long off, long len, long seed)
Calculates XXHash64 from this Volume content.
This code comes from LZ4-Java created by Adrien Grand.
off
- offset to start calculation fromlen
- length of data to calculate hashseed
- hash seedCopyright © 2015. All Rights Reserved.