| java.lang.Object com.caucho.db.store.Store
All known Subclasses: com.caucho.db.table.Table,
Store | public class Store (Code) | | The store manages the block-based persistent store file. Each table
will have its own store file, table.db.
The store is block-based, where each block is 64k. Block allocation
is tracked by a free block, block 0. Each block is represented as a
two-byte value. The first byte is the allocation code: free, row,
or used. The second byte is a fragment allocation mask.
Since 64k stores 32k entries, the allocation block can handle
a 2G database size. If the database is larger, another free block
occurs at block 32k handling another 2G.
The blocks are marked as free (00), row (01), used (10) or fragment(11).
Row-blocks are table rows, so a table iterator will only look at
the row blocks. Used blocks are for special blocks like the
free list. Fragments are for blobs.
Each store has a unique id in the database. The store id is merged with
the block number in the store to create a unique block id. There are
64k allowed stores (and therefore 64k tables), leaving 64 - 16 = 48 bits
for the blocks in a table, i.e. 2 ^ 48 blocks = 256T blocks.
block index: the block number in the file.
address: the address of a byte within the store, treating the file as a
flat file.
block id: the unique id of the block in the database.
Blobs and fragments
Fragments are stored in 8k chunks with a single byte prefix indicating
its use.
Transactions
Fragments are not associated with transactions. The rollback is
associated with a transaction.
|
Inner Class :static class RandomAccessWrapper | |
Method Summary | |
final public long | addressToBlockId(long address) Converts from the block index to the unique block id. | public Block | allocateBlock() Allocates a new block for a non-row. | public long | allocateFragment(StoreTransaction xa) Allocates a new fragment. | public Block | allocateIndexBlock() | public long | allocateMiniFragment(StoreTransaction xa) Allocates a new miniFragment. | public Block | allocateRow() Allocates a new block for a row. | protected void | assertStoreActive() Check that an allocated block is valid. | public static long | blockIdToAddress(long blockId) Converts from the block index to the unique block id. | public static long | blockIdToAddress(long blockId, int offset) Converts from the block index to the unique block id. | public void | close() Closes the store. | public static String | codeToName(int code) Debug names for the allocation. | public static Store | create(Path path) Creates an independent store. | public void | create() Creates the store. | public void | deleteFragment(StoreTransaction xa, long fragmentAddress) Deletes a fragment. | public void | deleteMiniFragment(StoreTransaction xa, long fragmentAddress) Deletes a miniFragment. | public long | firstBlock(long blockId, int type) Returns the first block id which contains a row. | public long | firstFragment(long blockId) Returns the first block id which contains a fragment. | public long | firstRow(long blockId) Returns the first block id which contains a row. | public void | flush() Flush the store. | protected void | freeBlock(long blockId) Frees a block. | public byte[] | getAllocationTable() Returns a copy of the allocation table. | public long | getBlockCount() Returns the block count. | public BlockManager | getBlockManager() Returns the block manager. | public long | getFileSize() Returns the file size. | public int | getId() Returns the store's id. | public Lock | getLock() Returns the table's lock. | public String | getName() Returns the store's name. | public long | getTotalFragmentSize() Returns the current number of fragments used. | public void | init() | public boolean | isClosed() True if destroyed. | public boolean | isFlushDirtyBlocksOnCommit() If true, dirty blocks are written at commit time. | public boolean | isIndexBlock(long blockAddress) Return true if the block is an index block. | public boolean | isRowBlock(long blockAddress) Return true if the block is a row block. | final public Block | readBlock(long blockAddress) Returns the matching block. | public int | readBlock(long blockAddress, int blockOffset, byte[] buffer, int offset, int length) Reads a block. | public int | readBlock(long blockAddress, int blockOffset, char[] buffer, int offset, int length) Reads a block for a clob. | public void | readBlock(long blockId, byte[] buffer, int offset, int length) Reads a block into the buffer. | public long | readBlockLong(long blockAddress, int offset) Reads a long value from a block. | public int | readFragment(long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) Reads a fragment. | public int | readFragment(long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) Reads a fragment for a clob. | public long | readFragmentLong(long fragmentAddress, int fragmentOffset) Reads a long value from a fragment. | public static long | readLong(byte[] buffer, int offset) Reads the long. | public int | readMiniFragment(long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) Reads a fragment. | public int | readMiniFragment(long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) Reads a miniFragment for a clob. | public long | readMiniFragmentLong(long fragmentAddress, int fragmentOffset) Reads a long value from a miniFragment. | public void | remove() | void | saveAllocation() Sets the allocation for a block. | public void | setFlushDirtyBlocksOnCommit(boolean flushOnCommit) If true, dirty blocks are written at commit time. | public String | toString() | protected void | validateBlockId(long blockId) Check that an allocated block is valid. | public void | writeBlock(StoreTransaction xa, long blockAddress, int blockOffset, byte[] buffer, int offset, int length) Writes a blockfragment. | public void | writeBlock(StoreTransaction xa, long blockAddress, int blockOffset, char[] buffer, int offset, int length) | public void | writeBlock(long blockAddress, byte[] buffer, int offset, int length) Saves the buffer to the database. | public void | writeBlockLong(StoreTransaction xa, long blockAddress, int offset, long value) | public void | writeFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) Writes a fragment. | public void | writeFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) | public void | writeFragmentLong(StoreTransaction xa, long fragmentAddress, int fragmentOffset, long value) Writes a long value to a fragment. | public static void | writeLong(byte[] buffer, int offset, long v) Writes the long. | public void | writeMiniFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) Writes a miniFragment. | public void | writeMiniFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) | public void | writeMiniFragmentLong(StoreTransaction xa, long fragmentAddress, int fragmentOffset, long value) Writes a long value to a miniFragment. |
ALLOC_FRAGMENT | final public static int ALLOC_FRAGMENT(Code) | | |
ALLOC_FREE | final public static int ALLOC_FREE(Code) | | |
ALLOC_INDEX | final public static int ALLOC_INDEX(Code) | | |
ALLOC_MASK | final public static int ALLOC_MASK(Code) | | |
ALLOC_MINI_FRAG | final public static int ALLOC_MINI_FRAG(Code) | | |
ALLOC_ROW | final public static int ALLOC_ROW(Code) | | |
ALLOC_USED | final public static int ALLOC_USED(Code) | | |
BLOCK_BITS | final public static int BLOCK_BITS(Code) | | |
BLOCK_INDEX_MASK | final public static long BLOCK_INDEX_MASK(Code) | | |
BLOCK_MASK | final public static long BLOCK_MASK(Code) | | |
BLOCK_OFFSET_MASK | final public static long BLOCK_OFFSET_MASK(Code) | | |
BLOCK_SIZE | final public static int BLOCK_SIZE(Code) | | |
DATA_START | final public static long DATA_START(Code) | | |
FRAGMENT_PER_BLOCK | final public static int FRAGMENT_PER_BLOCK(Code) | | |
FRAGMENT_SIZE | final public static int FRAGMENT_SIZE(Code) | | |
MINI_FRAG_ALLOC_OFFSET | final public static int MINI_FRAG_ALLOC_OFFSET(Code) | | |
MINI_FRAG_PER_BLOCK | final public static int MINI_FRAG_PER_BLOCK(Code) | | |
MINI_FRAG_SIZE | final public static int MINI_FRAG_SIZE(Code) | | |
STORE_CREATE_END | final public static int STORE_CREATE_END(Code) | | |
Store | public Store(Database database, String name, Lock rowLock, Path path)(Code) | | Creates a new store.
Parameters: database - the owning database. Parameters: name - the store name Parameters: lock - the table lock Parameters: path - the path to the files |
addressToBlockId | final public long addressToBlockId(long address)(Code) | | Converts from the block index to the unique block id.
|
allocateBlock | public Block allocateBlock() throws IOException(Code) | | Allocates a new block for a non-row.
the block id of the allocated block. |
allocateIndexBlock | public Block allocateIndexBlock() throws IOException(Code) | | Allocates a new block for an index
the block id of the allocated block. |
allocateRow | public Block allocateRow() throws IOException(Code) | | Allocates a new block for a row.
the block id of the allocated block. |
blockIdToAddress | public static long blockIdToAddress(long blockId)(Code) | | Converts from the block index to the unique block id.
|
blockIdToAddress | public static long blockIdToAddress(long blockId, int offset)(Code) | | Converts from the block index to the unique block id.
|
close | public void close()(Code) | | Closes the store.
|
codeToName | public static String codeToName(int code)(Code) | | Debug names for the allocation.
|
firstBlock | public long firstBlock(long blockId, int type) throws IOException(Code) | | Returns the first block id which contains a row.
the block id of the first row block |
firstFragment | public long firstFragment(long blockId) throws IOException(Code) | | Returns the first block id which contains a fragment.
the block id of the first row block |
firstRow | public long firstRow(long blockId) throws IOException(Code) | | Returns the first block id which contains a row.
the block id of the first row block |
flush | public void flush()(Code) | | Flush the store.
|
freeBlock | protected void freeBlock(long blockId) throws IOException(Code) | | Frees a block.
the block id of the allocated block. |
getAllocationTable | public byte[] getAllocationTable()(Code) | | Returns a copy of the allocation table.
|
getBlockCount | public long getBlockCount()(Code) | | Returns the block count.
|
getFileSize | public long getFileSize()(Code) | | Returns the file size.
|
getId | public int getId()(Code) | | Returns the store's id.
|
getLock | public Lock getLock()(Code) | | Returns the table's lock.
|
getName | public String getName()(Code) | | Returns the store's name.
|
getTotalFragmentSize | public long getTotalFragmentSize()(Code) | | Returns the current number of fragments used.
|
isClosed | public boolean isClosed()(Code) | | True if destroyed.
|
isFlushDirtyBlocksOnCommit | public boolean isFlushDirtyBlocksOnCommit()(Code) | | If true, dirty blocks are written at commit time.
|
isIndexBlock | public boolean isIndexBlock(long blockAddress)(Code) | | Return true if the block is an index block.
|
isRowBlock | public boolean isRowBlock(long blockAddress)(Code) | | Return true if the block is a row block.
|
readBlock | public int readBlock(long blockAddress, int blockOffset, byte[] buffer, int offset, int length) throws IOException(Code) | | Reads a block.
Parameters: blockAddress - the address of the block Parameters: blockOffset - the offset inside the block to start reading Parameters: buffer - the result buffer Parameters: offset - offset into the result buffer Parameters: length - the number of bytes to read the number of bytes read |
readBlock | public int readBlock(long blockAddress, int blockOffset, char[] buffer, int offset, int length) throws IOException(Code) | | Reads a block for a clob.
Parameters: blockAddress - the address of the block Parameters: blockOffset - the offset inside the block to start reading Parameters: buffer - the result buffer Parameters: offset - offset into the result buffer Parameters: length - the length of the block in characters the number of characters read |
readBlock | public void readBlock(long blockId, byte[] buffer, int offset, int length) throws IOException(Code) | | Reads a block into the buffer.
|
readBlockLong | public long readBlockLong(long blockAddress, int offset) throws IOException(Code) | | Reads a long value from a block.
the long value |
readFragment | public int readFragment(long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) throws IOException(Code) | | Reads a fragment.
Parameters: fragmentAddress - the address of the fragment Parameters: fragmentOffset - the offset inside the fragment to start reading Parameters: buffer - the result buffer Parameters: offset - offset into the result buffer Parameters: length - the number of bytes to read the number of bytes read |
readFragment | public int readFragment(long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) throws IOException(Code) | | Reads a fragment for a clob.
Parameters: fragmentAddress - the address of the fragment Parameters: fragmentOffset - the offset inside the fragment to start reading Parameters: buffer - the result buffer Parameters: offset - offset into the result buffer Parameters: length - the length of the fragment in characters the number of characters read |
readFragmentLong | public long readFragmentLong(long fragmentAddress, int fragmentOffset) throws IOException(Code) | | Reads a long value from a fragment.
the long value |
readLong | public static long readLong(byte[] buffer, int offset)(Code) | | Reads the long.
|
readMiniFragment | public int readMiniFragment(long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) throws IOException(Code) | | Reads a fragment.
Parameters: fragmentAddress - the address of the fragment Parameters: fragmentOffset - the offset inside the fragment to start reading Parameters: buffer - the result buffer Parameters: offset - offset into the result buffer Parameters: length - the number of bytes to read the number of bytes read |
readMiniFragment | public int readMiniFragment(long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) throws IOException(Code) | | Reads a miniFragment for a clob.
Parameters: fragmentAddress - the address of the fragment Parameters: fragmentOffset - the offset inside the fragment to start reading Parameters: buffer - the result buffer Parameters: offset - offset into the result buffer Parameters: length - the length of the fragment in characters the number of characters read |
readMiniFragmentLong | public long readMiniFragmentLong(long fragmentAddress, int fragmentOffset) throws IOException(Code) | | Reads a long value from a miniFragment.
the long value |
saveAllocation | void saveAllocation() throws IOException(Code) | | Sets the allocation for a block.
|
setFlushDirtyBlocksOnCommit | public void setFlushDirtyBlocksOnCommit(boolean flushOnCommit)(Code) | | If true, dirty blocks are written at commit time.
|
writeBlock | public void writeBlock(StoreTransaction xa, long blockAddress, int blockOffset, byte[] buffer, int offset, int length) throws IOException(Code) | | Writes a blockfragment.
Parameters: xa - the owning transaction Parameters: blockAddress - the block to write Parameters: blockOffset - the offset into the block Parameters: buffer - the write buffer Parameters: offset - offset into the write buffer Parameters: length - the number of bytes to write the fragment id |
writeBlock | public void writeBlock(StoreTransaction xa, long blockAddress, int blockOffset, char[] buffer, int offset, int length) throws IOException(Code) | | Writes a character based block
Parameters: blockAddress - the fragment to write Parameters: blockOffset - the offset into the fragment Parameters: buffer - the write buffer Parameters: offset - offset into the write buffer Parameters: length - the number of bytes to write |
writeBlock | public void writeBlock(long blockAddress, byte[] buffer, int offset, int length) throws IOException(Code) | | Saves the buffer to the database.
|
writeBlockLong | public void writeBlockLong(StoreTransaction xa, long blockAddress, int offset, long value) throws IOException(Code) | | Writes a long value to a block
the long value |
writeFragment | public void writeFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) throws IOException(Code) | | Writes a fragment.
Parameters: xa - the owning transaction Parameters: fragmentAddress - the fragment to write Parameters: fragmentOffset - the offset into the fragment Parameters: buffer - the write buffer Parameters: offset - offset into the write buffer Parameters: length - the number of bytes to write the fragment id |
writeFragment | public void writeFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) throws IOException(Code) | | Writes a character based
Parameters: fragmentAddress - the fragment to write Parameters: fragmentOffset - the offset into the fragment Parameters: buffer - the write buffer Parameters: offset - offset into the write buffer Parameters: length - the number of bytes to write |
writeFragmentLong | public void writeFragmentLong(StoreTransaction xa, long fragmentAddress, int fragmentOffset, long value) throws IOException(Code) | | Writes a long value to a fragment.
the long value |
writeLong | public static void writeLong(byte[] buffer, int offset, long v)(Code) | | Writes the long.
|
writeMiniFragment | public void writeMiniFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, byte[] buffer, int offset, int length) throws IOException(Code) | | Writes a miniFragment.
Parameters: xa - the owning transaction Parameters: fragmentAddress - the fragment to write Parameters: fragmentOffset - the offset into the fragment Parameters: buffer - the write buffer Parameters: offset - offset into the write buffer Parameters: length - the number of bytes to write the fragment id |
writeMiniFragment | public void writeMiniFragment(StoreTransaction xa, long fragmentAddress, int fragmentOffset, char[] buffer, int offset, int length) throws IOException(Code) | | Writes a character based
Parameters: miniFragmentAddress - the fragment to write Parameters: fragmentOffset - the offset into the fragment Parameters: buffer - the write buffer Parameters: offset - offset into the write buffer Parameters: length - the number of bytes to write |
writeMiniFragmentLong | public void writeMiniFragmentLong(StoreTransaction xa, long fragmentAddress, int fragmentOffset, long value) throws IOException(Code) | | Writes a long value to a miniFragment.
the long value |
|
|