public class Database
extends java.lang.Object
Some terminology is used throughout this class: A block is a variable-size piece of contiguous memory returned by malloc. A chunk is a fixed-size piece of contiguous memory that is the atomic unit for paging, caching, reads, and writes. A free block is contiguous variable-length piece of memory that is created by free and is potentially usable by malloc. Most chunks contain multiple blocks and free blocks, but it is possible for a single block to use multiple chunks. Such blocks are referred to as "large blocks". A free block is always smaller than a chunk.
| Modifier and Type | Class and Description |
|---|---|
static class |
Database.ChunkStats |
| Modifier and Type | Field and Description |
|---|---|
static int |
BLOCK_HEADER_SIZE |
static int |
BLOCK_SIZE_DELTA |
static int |
BLOCK_SIZE_DELTA_BITS |
static int |
BYTE_SIZE |
static int |
CHAR_SIZE |
static int |
CHUNK_SIZE |
static int |
DATA_AREA_OFFSET |
static boolean |
DEBUG_FREE_SPACE
True iff large chunk self-diagnostics should be enabled.
|
static boolean |
DEBUG_PAGE_CACHE |
static int |
DOUBLE_SIZE |
static int |
FLOAT_SIZE |
org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk |
fMostRecentlyFetchedChunk |
static int |
FREE_BLOCK_OFFSET |
static int |
INT_SIZE |
static int |
LONG_SIZE |
static int |
MALLOC_STATS_OFFSET |
static int |
MALLOC_TABLE_OFFSET |
static int |
MAX_BLOCK_DELTAS |
static long |
MAX_DB_SIZE |
static long |
MAX_MALLOC_SIZE |
static int |
MAX_SINGLE_BLOCK_MALLOC_SIZE |
static int |
MIN_BLOCK_DELTAS |
static double |
MIN_BYTES_PER_MILLISECOND |
static int |
NUM_HEADER_CHUNKS |
static int |
OFFSET_IN_CHUNK_MASK |
static short |
POOL_BTREE |
static short |
POOL_DB_PROPERTIES |
static short |
POOL_FIRST_NODE_TYPE
Id for the first node type.
|
static short |
POOL_GROWABLE_ARRAY |
static short |
POOL_LINKED_LIST |
static short |
POOL_MISC
Misc pool -- may be used for any purpose that doesn't fit the IDs below.
|
static short |
POOL_STRING_LONG |
static short |
POOL_STRING_SET |
static short |
POOL_STRING_SHORT |
static int |
PTR_SIZE |
static int |
SHORT_SIZE |
static int |
STRING_SIZE |
static int |
VERSION_OFFSET |
static int |
WRITE_NUMBER_OFFSET |
| Constructor and Description |
|---|
Database(java.io.File location,
ChunkCache cache,
int version,
boolean openReadOnly)
Construct a new Database object, creating a backing file if necessary.
|
| Modifier and Type | Method and Description |
|---|---|
void |
assertLocked() |
boolean |
clear(int version)
Empty the contents of the Database, make it ready to start again.
|
void |
clearBytes(long offset,
int byteCount) |
void |
clearRange(long startAddress,
long bytesToClear)
Clears all the bytes in the given range by setting them to zero.
|
void |
close()
Closes the database.
|
IndexExceptionBuilder |
describeProblem() |
boolean |
flush() |
static java.lang.String |
formatByteString(long valueInBytes) |
void |
free(long address,
short poolId)
Free an allocated block.
|
int |
get3ByteUnsignedInt(long offset) |
double |
getAverageReadBytesPerMs() |
double |
getAverageWriteBytesPerMs() |
byte |
getByte(long offset) |
void |
getBytes(long offset,
byte[] data) |
void |
getBytes(long offset,
byte[] data,
int dataPos,
int len) |
long |
getBytesAllocated()
Returns the number of bytes allocated by
malloc(long, short) since this Database instance was
instantiated. |
long |
getBytesFreed()
Returns the number of bytes freed by
free(long, short) since this Database instance was
instantiated. |
long |
getBytesRead() |
static long |
getBytesThatFitInChunks(int numChunks)
Returns the number of bytes that can fit in the payload of the given number of chunks.
|
long |
getBytesWritten() |
ChunkCache |
getCache() |
long |
getCacheHits() |
long |
getCacheMisses() |
char |
getChar(long offset) |
org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk |
getChunk(long offset)
Return the Chunk that contains the given offset.
|
ChunkCache |
getChunkCache()
Returns the cache used for this database.
|
int |
getChunkCount() |
static int |
getChunksNeededForBytes(long datasize)
Returns the number of chunks needed to fit the given number of bytes of payload.
|
Database.ChunkStats |
getChunkStats() |
long |
getCumulativeFlushTimeMs() |
long |
getDatabaseSize() |
int |
getDirtyChunkCount() |
double |
getDouble(long offset) |
float |
getFloat(long offset) |
int |
getInt(long offset) |
java.io.File |
getLocation()
This method is public for testing purposes only.
|
ModificationLog |
getLog() |
long |
getLong(long offset) |
MemoryStats |
getMemoryStats() |
static long |
getRecPtr(byte[] buffer,
int idx)
A Record Pointer is a pointer as returned by Database.malloc().
|
long |
getRecPtr(long offset) |
short |
getShort(long offset) |
long |
getSizeBytes() |
IString |
getString(long offset) |
int |
getVersion() |
void |
giveUpExclusiveLock() |
long |
malloc(long datasize,
short poolId)
Allocate a block out of the database.
|
void |
memcpy(long dest,
long source,
int numBytes)
Copies numBytes from source to destination
|
IString |
newString(char[] chars) |
IString |
newString(java.lang.String string) |
void |
put3ByteUnsignedInt(long offset,
int value) |
void |
putByte(long offset,
byte value) |
void |
putBytes(long offset,
byte[] data,
int len) |
void |
putBytes(long offset,
byte[] data,
int dataPos,
int len) |
void |
putChar(long offset,
char value) |
void |
putDouble(long offset,
double value) |
void |
putFloat(long offset,
float value) |
void |
putInt(long offset,
int value) |
void |
putLong(long offset,
long value) |
static void |
putRecPtr(long value,
byte[] buffer,
int idx)
A Record Pointer is a pointer as returned by Database.malloc().
|
void |
putRecPtr(long offset,
long value) |
void |
putShort(long offset,
short value) |
void |
reportFreeBlocks()
For debugging purposes, only.
|
void |
resetCacheCounters() |
void |
setExclusiveLock()
Asserts that database is used by one thread exclusively.
|
void |
setLocked(boolean val) |
void |
setVersion(int version) |
void |
transferTo(java.nio.channels.FileChannel target) |
void |
validateFreeSpace() |
public static final int CHAR_SIZE
public static final int BYTE_SIZE
public static final int SHORT_SIZE
public static final int INT_SIZE
public static final int LONG_SIZE
public static final int CHUNK_SIZE
public static final int OFFSET_IN_CHUNK_MASK
public static final int BLOCK_HEADER_SIZE
public static final int BLOCK_SIZE_DELTA_BITS
public static final int BLOCK_SIZE_DELTA
public static final int MIN_BLOCK_DELTAS
public static final int MAX_BLOCK_DELTAS
public static final int MAX_SINGLE_BLOCK_MALLOC_SIZE
public static final int PTR_SIZE
public static final int STRING_SIZE
public static final int FLOAT_SIZE
public static final int DOUBLE_SIZE
public static final long MAX_DB_SIZE
public static final long MAX_MALLOC_SIZE
public static final int VERSION_OFFSET
public static final int MALLOC_TABLE_OFFSET
public static final int FREE_BLOCK_OFFSET
public static final int WRITE_NUMBER_OFFSET
public static final int MALLOC_STATS_OFFSET
public static final int DATA_AREA_OFFSET
public static final int NUM_HEADER_CHUNKS
public static final short POOL_MISC
public static final short POOL_BTREE
public static final short POOL_DB_PROPERTIES
public static final short POOL_STRING_LONG
public static final short POOL_STRING_SHORT
public static final short POOL_LINKED_LIST
public static final short POOL_STRING_SET
public static final short POOL_GROWABLE_ARRAY
public static final short POOL_FIRST_NODE_TYPE
public static boolean DEBUG_FREE_SPACE
public static boolean DEBUG_PAGE_CACHE
public org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk fMostRecentlyFetchedChunk
public static final double MIN_BYTES_PER_MILLISECOND
public Database(java.io.File location,
ChunkCache cache,
int version,
boolean openReadOnly)
throws IndexException
location - the local file path for the databasecache - the cache to be used optimizationversion - the version number to store in the database (only applicable for new databases)openReadOnly - whether this Database object will ever need writing toIndexExceptionpublic ModificationLog getLog()
public void transferTo(java.nio.channels.FileChannel target)
throws java.io.IOException
java.io.IOExceptionpublic int getVersion()
public void setVersion(int version)
throws IndexException
IndexExceptionpublic boolean clear(int version)
throws IndexException
Thread.interrupt() won't interrupt the write. Returns true iff the thread was interrupted
with Thread.interrupt().IndexExceptionpublic org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk getChunk(long offset)
throws IndexException
IndexExceptionpublic void assertLocked()
public void memcpy(long dest,
long source,
int numBytes)
public long malloc(long datasize,
short poolId)
throws IndexException
IndexExceptionpublic void clearRange(long startAddress,
long bytesToClear)
startAddress - first address to clearbytesToClear - number of addresses to clearpublic void validateFreeSpace()
public void free(long address,
short poolId)
throws IndexException
address - memory address to be freedpoolId - the same ID that was previously passed into malloc when allocating this memory addressIndexExceptionpublic void putByte(long offset,
byte value)
throws IndexException
IndexExceptionpublic byte getByte(long offset)
throws IndexException
IndexExceptionpublic void putInt(long offset,
int value)
throws IndexException
IndexExceptionpublic int getInt(long offset)
throws IndexException
IndexExceptionpublic void putRecPtr(long offset,
long value)
throws IndexException
IndexExceptionpublic long getRecPtr(long offset)
throws IndexException
IndexExceptionpublic void put3ByteUnsignedInt(long offset,
int value)
throws IndexException
IndexExceptionpublic int get3ByteUnsignedInt(long offset)
throws IndexException
IndexExceptionpublic void putShort(long offset,
short value)
throws IndexException
IndexExceptionpublic short getShort(long offset)
throws IndexException
IndexExceptionpublic void putLong(long offset,
long value)
throws IndexException
IndexExceptionpublic void putDouble(long offset,
double value)
throws IndexException
IndexExceptionpublic void putFloat(long offset,
float value)
throws IndexException
IndexExceptionpublic long getLong(long offset)
throws IndexException
IndexExceptionpublic double getDouble(long offset)
throws IndexException
IndexExceptionpublic float getFloat(long offset)
throws IndexException
IndexExceptionpublic void putChar(long offset,
char value)
throws IndexException
IndexExceptionpublic char getChar(long offset)
throws IndexException
IndexExceptionpublic void clearBytes(long offset,
int byteCount)
throws IndexException
IndexExceptionpublic void putBytes(long offset,
byte[] data,
int len)
throws IndexException
IndexExceptionpublic void putBytes(long offset,
byte[] data,
int dataPos,
int len)
throws IndexException
IndexExceptionpublic void getBytes(long offset,
byte[] data)
throws IndexException
IndexExceptionpublic void getBytes(long offset,
byte[] data,
int dataPos,
int len)
throws IndexException
IndexExceptionpublic IString newString(java.lang.String string) throws IndexException
IndexExceptionpublic IString newString(char[] chars) throws IndexException
IndexExceptionpublic IString getString(long offset) throws IndexException
IndexExceptionpublic long getDatabaseSize()
public long getBytesFreed()
free(long, short) since this Database instance was
instantiated. Intended for use in unit tests.public long getBytesAllocated()
malloc(long, short) since this Database instance was
instantiated. Intended for use in unit tests.public void reportFreeBlocks()
throws IndexException
IndexExceptionpublic void close()
throws IndexException
The behavior of any further calls to the Database is undefined
IndexExceptionpublic java.io.File getLocation()
public ChunkCache getChunkCache()
public void setExclusiveLock()
public void setLocked(boolean val)
public void giveUpExclusiveLock()
public boolean flush()
throws IndexException
IndexExceptionpublic void resetCacheCounters()
public long getBytesWritten()
public double getAverageReadBytesPerMs()
public double getAverageWriteBytesPerMs()
public long getBytesRead()
public long getCacheHits()
public long getCacheMisses()
public long getCumulativeFlushTimeMs()
public long getSizeBytes()
throws java.io.IOException
java.io.IOExceptionpublic int getChunkCount()
public static void putRecPtr(long value,
byte[] buffer,
int idx)
public static long getRecPtr(byte[] buffer,
int idx)
public MemoryStats getMemoryStats()
public static long getBytesThatFitInChunks(int numChunks)
public static int getChunksNeededForBytes(long datasize)
public ChunkCache getCache()
public int getDirtyChunkCount()
public static java.lang.String formatByteString(long valueInBytes)
public Database.ChunkStats getChunkStats()
public IndexExceptionBuilder describeProblem()