|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.caucho.db.store.Store
public class Store
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.
| Field Summary | |
|---|---|
protected BlockManager |
_blockManager
|
protected Database |
_database
|
static int |
ALLOC_FRAGMENT
|
static int |
ALLOC_FREE
|
static int |
ALLOC_INDEX
|
static int |
ALLOC_MASK
|
static int |
ALLOC_MINI_FRAG
|
static int |
ALLOC_ROW
|
static int |
ALLOC_USED
|
static int |
BLOCK_BITS
|
static long |
BLOCK_INDEX_MASK
|
static long |
BLOCK_MASK
|
static long |
BLOCK_OFFSET_MASK
|
static int |
BLOCK_SIZE
|
static long |
DATA_START
|
static int |
FRAGMENT_PER_BLOCK
|
static int |
FRAGMENT_SIZE
|
static int |
MINI_FRAG_ALLOC_OFFSET
|
static int |
MINI_FRAG_PER_BLOCK
|
static int |
MINI_FRAG_SIZE
|
static int |
STORE_CREATE_END
|
| Constructor Summary | |
|---|---|
Store(Database database,
java.lang.String name,
Lock tableLock)
|
|
Store(Database database,
java.lang.String name,
Lock rowLock,
Path path)
Creates a new store. |
|
| Method Summary | |
|---|---|
long |
addressToBlockId(long address)
Converts from the block index to the unique block id. |
Block |
allocateBlock()
Allocates a new block for a non-row. |
long |
allocateFragment(StoreTransaction xa)
Allocates a new fragment. |
Block |
allocateIndexBlock()
Allocates a new block for an index |
long |
allocateMiniFragment(StoreTransaction xa)
Allocates a new miniFragment. |
Block |
allocateRow()
Allocates a new block for a row. |
protected void |
assertStoreActive()
Check that an allocated block is valid. |
static long |
blockIdToAddress(long blockId)
Converts from the block index to the unique block id. |
static long |
blockIdToAddress(long blockId,
int offset)
Converts from the block index to the unique block id. |
void |
close()
Closes the store. |
static java.lang.String |
codeToName(int code)
Debug names for the allocation. |
void |
create()
Creates the store. |
static Store |
create(Path path)
Creates an independent store. |
void |
deleteFragment(StoreTransaction xa,
long fragmentAddress)
Deletes a fragment. |
void |
deleteMiniFragment(StoreTransaction xa,
long fragmentAddress)
Deletes a miniFragment. |
long |
firstBlock(long blockId,
int type)
Returns the first block id which contains a row. |
long |
firstFragment(long blockId)
Returns the first block id which contains a fragment. |
long |
firstRow(long blockId)
Returns the first block id which contains a row. |
void |
flush()
Flush the store. |
protected void |
freeBlock(long blockId)
Frees a block. |
byte[] |
getAllocationTable()
Returns a copy of the allocation table. |
long |
getBlockCount()
Returns the block count. |
BlockManager |
getBlockManager()
Returns the block manager. |
long |
getFileSize()
Returns the file size. |
int |
getId()
Returns the store's id. |
Lock |
getLock()
Returns the table's lock. |
java.lang.String |
getName()
Returns the store's name. |
long |
getTotalFragmentSize()
Returns the current number of fragments used. |
void |
init()
|
boolean |
isClosed()
True if destroyed. |
boolean |
isCorrupted()
|
boolean |
isFlushDirtyBlocksOnCommit()
If true, dirty blocks are written at commit time. |
boolean |
isIndexBlock(long blockAddress)
Return true if the block is an index block. |
boolean |
isRowBlock(long blockAddress)
Return true if the block is a row block. |
Block |
readBlock(long blockAddress)
Returns the matching block. |
void |
readBlock(long blockId,
byte[] buffer,
int offset,
int length)
Reads a block into the buffer. |
int |
readBlock(long blockAddress,
int blockOffset,
byte[] buffer,
int offset,
int length)
Reads a block. |
int |
readBlock(long blockAddress,
int blockOffset,
char[] buffer,
int offset,
int length)
Reads a block for a clob. |
long |
readBlockLong(long blockAddress,
int offset)
Reads a long value from a block. |
int |
readFragment(long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
Reads a fragment. |
int |
readFragment(long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
Reads a fragment for a clob. |
long |
readFragmentLong(long fragmentAddress,
int fragmentOffset)
Reads a long value from a fragment. |
static long |
readLong(byte[] buffer,
int offset)
Reads the long. |
int |
readMiniFragment(long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
Reads a fragment. |
int |
readMiniFragment(long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
Reads a miniFragment for a clob. |
long |
readMiniFragmentLong(long fragmentAddress,
int fragmentOffset)
Reads a long value from a miniFragment. |
void |
remove()
|
void |
setCorrupted(boolean isCorrupted)
|
void |
setFlushDirtyBlocksOnCommit(boolean flushOnCommit)
If true, dirty blocks are written at commit time. |
java.lang.String |
toString()
|
protected void |
validateBlockId(long blockId)
Check that an allocated block is valid. |
void |
writeBlock(long blockAddress,
byte[] buffer,
int offset,
int length)
Saves the buffer to the database. |
void |
writeBlock(StoreTransaction xa,
long blockAddress,
int blockOffset,
byte[] buffer,
int offset,
int length)
Writes a blockfragment. |
void |
writeBlock(StoreTransaction xa,
long blockAddress,
int blockOffset,
char[] buffer,
int offset,
int length)
Writes a character based block |
void |
writeBlockLong(StoreTransaction xa,
long blockAddress,
int offset,
long value)
Writes a long value to a block |
void |
writeFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
Writes a fragment. |
void |
writeFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
Writes a character based |
void |
writeFragmentLong(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
long value)
Writes a long value to a fragment. |
static void |
writeLong(byte[] buffer,
int offset,
long v)
Writes the long. |
void |
writeMiniFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
Writes a miniFragment. |
void |
writeMiniFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
Writes a character based |
void |
writeMiniFragmentLong(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
long value)
Writes a long value to a miniFragment. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int BLOCK_BITS
public static final int BLOCK_SIZE
public static final long BLOCK_INDEX_MASK
public static final long BLOCK_MASK
public static final long BLOCK_OFFSET_MASK
public static final int ALLOC_FREE
public static final int ALLOC_ROW
public static final int ALLOC_USED
public static final int ALLOC_FRAGMENT
public static final int ALLOC_INDEX
public static final int ALLOC_MINI_FRAG
public static final int ALLOC_MASK
public static final int FRAGMENT_SIZE
public static final int FRAGMENT_PER_BLOCK
public static final int MINI_FRAG_SIZE
public static final int MINI_FRAG_PER_BLOCK
public static final int MINI_FRAG_ALLOC_OFFSET
public static final long DATA_START
public static final int STORE_CREATE_END
protected final Database _database
protected final BlockManager _blockManager
| Constructor Detail |
|---|
public Store(Database database,
java.lang.String name,
Lock tableLock)
public Store(Database database,
java.lang.String name,
Lock rowLock,
Path path)
database - the owning database.name - the store namelock - the table lockpath - the path to the files| Method Detail |
|---|
public static Store create(Path path)
throws java.io.IOException,
java.sql.SQLException
java.io.IOException
java.sql.SQLExceptionpublic void setFlushDirtyBlocksOnCommit(boolean flushOnCommit)
public boolean isFlushDirtyBlocksOnCommit()
public java.lang.String getName()
public int getId()
public Lock getLock()
public BlockManager getBlockManager()
public void setCorrupted(boolean isCorrupted)
public boolean isCorrupted()
public long getFileSize()
public long getBlockCount()
public final long addressToBlockId(long address)
public static long blockIdToAddress(long blockId)
public static long blockIdToAddress(long blockId,
int offset)
public long getTotalFragmentSize()
public void create()
throws java.io.IOException,
java.sql.SQLException
java.io.IOException
java.sql.SQLException
public void init()
throws java.io.IOException
java.io.IOException
public void remove()
throws java.sql.SQLException
java.sql.SQLException
public long firstRow(long blockId)
throws java.io.IOException
java.io.IOException
public long firstFragment(long blockId)
throws java.io.IOException
java.io.IOException
public long firstBlock(long blockId,
int type)
throws java.io.IOException
java.io.IOException
public final Block readBlock(long blockAddress)
throws java.io.IOException
java.io.IOException
public Block allocateRow()
throws java.io.IOException
java.io.IOExceptionpublic boolean isRowBlock(long blockAddress)
public Block allocateBlock()
throws java.io.IOException
java.io.IOException
public Block allocateIndexBlock()
throws java.io.IOException
java.io.IOExceptionpublic boolean isIndexBlock(long blockAddress)
protected void validateBlockId(long blockId)
throws java.lang.IllegalArgumentException,
java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.IllegalStateException
protected void assertStoreActive()
throws java.lang.IllegalStateException
java.lang.IllegalStateException
protected void freeBlock(long blockId)
throws java.io.IOException
java.io.IOException
public int readFragment(long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
fragmentAddress - the address of the fragmentfragmentOffset - the offset inside the fragment to start readingbuffer - the result bufferoffset - offset into the result bufferlength - the number of bytes to read
java.io.IOException
public int readFragment(long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
throws java.io.IOException
fragmentAddress - the address of the fragmentfragmentOffset - the offset inside the fragment to start readingbuffer - the result bufferoffset - offset into the result bufferlength - the length of the fragment in characters
java.io.IOException
public long readFragmentLong(long fragmentAddress,
int fragmentOffset)
throws java.io.IOException
java.io.IOException
public int readBlock(long blockAddress,
int blockOffset,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
blockAddress - the address of the blockblockOffset - the offset inside the block to start readingbuffer - the result bufferoffset - offset into the result bufferlength - the number of bytes to read
java.io.IOException
public int readBlock(long blockAddress,
int blockOffset,
char[] buffer,
int offset,
int length)
throws java.io.IOException
blockAddress - the address of the blockblockOffset - the offset inside the block to start readingbuffer - the result bufferoffset - offset into the result bufferlength - the length of the block in characters
java.io.IOException
public long readBlockLong(long blockAddress,
int offset)
throws java.io.IOException
java.io.IOException
public long allocateFragment(StoreTransaction xa)
throws java.io.IOException
java.io.IOException
public void deleteFragment(StoreTransaction xa,
long fragmentAddress)
throws java.io.IOException
java.io.IOException
public void writeFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
xa - the owning transactionfragmentAddress - the fragment to writefragmentOffset - the offset into the fragmentbuffer - the write bufferoffset - offset into the write bufferlength - the number of bytes to write
java.io.IOException
public void writeFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
throws java.io.IOException
fragmentAddress - the fragment to writefragmentOffset - the offset into the fragmentbuffer - the write bufferoffset - offset into the write bufferlength - the number of bytes to write
java.io.IOException
public void writeFragmentLong(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
long value)
throws java.io.IOException
java.io.IOException
public void writeBlock(StoreTransaction xa,
long blockAddress,
int blockOffset,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
xa - the owning transactionblockAddress - the block to writeblockOffset - the offset into the blockbuffer - the write bufferoffset - offset into the write bufferlength - the number of bytes to write
java.io.IOException
public void writeBlock(StoreTransaction xa,
long blockAddress,
int blockOffset,
char[] buffer,
int offset,
int length)
throws java.io.IOException
blockAddress - the fragment to writeblockOffset - the offset into the fragmentbuffer - the write bufferoffset - offset into the write bufferlength - the number of bytes to write
java.io.IOException
public void writeBlockLong(StoreTransaction xa,
long blockAddress,
int offset,
long value)
throws java.io.IOException
java.io.IOException
public int readMiniFragment(long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
fragmentAddress - the address of the fragmentfragmentOffset - the offset inside the fragment to start readingbuffer - the result bufferoffset - offset into the result bufferlength - the number of bytes to read
java.io.IOException
public int readMiniFragment(long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
throws java.io.IOException
fragmentAddress - the address of the fragmentfragmentOffset - the offset inside the fragment to start readingbuffer - the result bufferoffset - offset into the result bufferlength - the length of the fragment in characters
java.io.IOException
public long readMiniFragmentLong(long fragmentAddress,
int fragmentOffset)
throws java.io.IOException
java.io.IOException
public long allocateMiniFragment(StoreTransaction xa)
throws java.io.IOException
java.io.IOException
public void deleteMiniFragment(StoreTransaction xa,
long fragmentAddress)
throws java.io.IOException
java.io.IOException
public void writeMiniFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
xa - the owning transactionfragmentAddress - the fragment to writefragmentOffset - the offset into the fragmentbuffer - the write bufferoffset - offset into the write bufferlength - the number of bytes to write
java.io.IOException
public void writeMiniFragment(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
char[] buffer,
int offset,
int length)
throws java.io.IOException
miniFragmentAddress - the fragment to writefragmentOffset - the offset into the fragmentbuffer - the write bufferoffset - offset into the write bufferlength - the number of bytes to write
java.io.IOException
public void writeMiniFragmentLong(StoreTransaction xa,
long fragmentAddress,
int fragmentOffset,
long value)
throws java.io.IOException
java.io.IOException
public void readBlock(long blockId,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
java.io.IOException
public void writeBlock(long blockAddress,
byte[] buffer,
int offset,
int length)
throws java.io.IOException
java.io.IOExceptionpublic void flush()
public boolean isClosed()
public void close()
public byte[] getAllocationTable()
public static long readLong(byte[] buffer,
int offset)
public static void writeLong(byte[] buffer,
int offset,
long v)
public static java.lang.String codeToName(int code)
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||