|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.metanotion.io.appenddb.AppendBlockIO
public final class AppendBlockIO
This implements a block device tied to a random access file. This is the "third" version of this idea I have implemented. Also, this is an evolution of ideas expressed in the low level SQLite file format. The chief advancement this represents over my previous attempts is to use an "immutable" in memory structure and file writes that only append to the file. "Atomic Appends" has allowed me to dispense entirely with the notion of "fixed" page sizes and makes all "block" numbers a logical address, rather than physical. Also, this style makes transactions easier to implement, as there is no "write-ahead-logging". Instead, a cache of the "last" version of a block is stored in a B-Tree(also immutable) stored at the end of the file. In the event that this tree is not there, it is assumed that the file needs to be recovered, and it is "replayed" to get the current state. The only real issue with this structure is that failure recovery could be time-consuming (as the whole file has to be replayed), and that the file will always grow. The growing file issue can be solved with multiple AppendBlockIO files. Basically, a compaction is started on the current file into the new file, with a reset transaction counter. This functionality has not been implemented yet.
| Field Summary | |
|---|---|
protected RandomAccess |
appendFile
Handle to the file backing this device. |
protected |
cache
Block cache. |
protected Object |
commitSync
Synchronzie's transaction commits. |
protected AtomicBoolean |
isOpen
|
static long |
MAGIC
Magic bytes identifying the file format. |
protected AtomicInteger |
nextFreeBlock
|
protected AtomicInteger |
nextXID
|
protected Map<Long,BlockKey> |
offsetToBlocks
|
protected AtomicReference<net.metanotion.io.appenddb.BlockRootMap> |
root
|
| Constructor Summary | |
|---|---|
AppendBlockIO(RandomAccess appendFile,
long maxBytes)
Create a n Append BlockIO device with given file and transaction log. |
|
| Method Summary | |
|---|---|
void |
abort(Transaction t)
Abandon a transaction in progress. |
Integer |
allocBlock()
|
Integer |
allocBlock(Transaction t)
Allocate a block # for the application to use. |
Transaction |
begin()
Begin a transaction. |
Transaction |
begin(Transaction t)
Start a nested transaction. |
void |
close()
|
void |
commit(Transaction t)
Attempt to commit the transaction. |
void |
compact(RandomAccess outfile)
Compact this block device to outfile. |
void |
flush()
|
void |
freeBlock(Integer block)
|
void |
freeBlock(Integer block,
Transaction t)
|
BlockHandle<byte[]> |
getBlock(Integer block)
|
BlockHandle<byte[]> |
getBlock(Integer block,
Transaction t)
|
byte[] |
getBytes(int block)
|
boolean |
hasTransactions()
This device supports transactions, and will always return true. |
protected net.metanotion.io.appenddb.Block |
load(long offset)
Load a block from the file. |
void |
setBytes(int block,
byte[] d)
|
protected long |
writeBlock(net.metanotion.io.appenddb.Block block)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long MAGIC
protected final RandomAccess appendFile
protected finalcache
protected final Map<Long,BlockKey> offsetToBlocks
protected final AtomicBoolean isOpen
protected final AtomicInteger nextFreeBlock
protected final AtomicInteger nextXID
protected final AtomicReference<net.metanotion.io.appenddb.BlockRootMap> root
protected final Object commitSync
| Constructor Detail |
|---|
public AppendBlockIO(RandomAccess appendFile,
long maxBytes)
throws RecoveryException
appendFile - File to store blocks in.maxBytes - Size of read/write cache in bytes(this is approximate).
RecoveryException - to indicate the need to run "recovery mode" on the index.
Please see the RecoverDB.recover static method.| Method Detail |
|---|
protected net.metanotion.io.appenddb.Block load(long offset)
offset - The file offset to load the block from.public byte[] getBytes(int block)
getBytes in interface ByteGet
public void setBytes(int block,
byte[] d)
setBytes in interface ByteGetprotected long writeBlock(net.metanotion.io.appenddb.Block block)
public void flush()
flush in interface Flushableflush in interface BlockIO<Integer,byte[],Transaction>public void close()
close in interface Closeableclose in interface BlockIO<Integer,byte[],Transaction>public void compact(RandomAccess outfile)
outfile - File to store the compacted file into.public Integer allocBlock(Transaction t)
allocBlock in interface BlockIO<Integer,byte[],Transaction>t - Transaction Handle.
public void freeBlock(Integer block,
Transaction t)
freeBlock in interface BlockIO<Integer,byte[],Transaction>
public BlockHandle<byte[]> getBlock(Integer block,
Transaction t)
getBlock in interface BlockIO<Integer,byte[],Transaction>public Integer allocBlock()
allocBlock in interface BlockIO<Integer,byte[],Transaction>public BlockHandle<byte[]> getBlock(Integer block)
getBlock in interface BlockIO<Integer,byte[],Transaction>public void freeBlock(Integer block)
freeBlock in interface BlockIO<Integer,byte[],Transaction>public boolean hasTransactions()
hasTransactions in interface BlockIO<Integer,byte[],Transaction>public Transaction begin()
begin in interface BlockIO<Integer,byte[],Transaction>
public Transaction begin(Transaction t)
throws UnsupportedOperationException
begin in interface BlockIO<Integer,byte[],Transaction>t - Parent transaction.
UnsupportedOperationException - to indicate this operation is not supported.public void abort(Transaction t)
abort in interface BlockIO<Integer,byte[],Transaction>t - Transaction handle to abandon. This handle will be unusable after this call.public void commit(Transaction t)
commit in interface BlockIO<Integer,byte[],Transaction>t - Transaction Handle to commit.
CommitException - if the transaction was aborted.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||