org.exist.storage.index
Class BFile

java.lang.Object
  extended byorg.exist.storage.btree.Paged
      extended byorg.exist.storage.btree.BTree
          extended byorg.exist.storage.index.BFile
Direct Known Subclasses:
CollectionStore

public class BFile
extends BTree

Data store for variable size values. This class maps keys to values of variable size. Keys are stored in the b+-tree. B+-tree values are pointers to the logical storage address of the value in the data section. The pointer consists of the page number and a logical tuple identifier. If a value is larger than the internal page size (4K), it is split into overflow pages. Appending data to a overflow page is very fast. Only the first and the last data page are loaded. Data pages are buffered.

Author:
Wolfgang Meier

Nested Class Summary
static interface BFile.PageInputStream
           
 
Nested classes inherited from class org.exist.storage.btree.BTree
BTree.BTreeFileHeader, BTree.BTreeNode, BTree.BTreePageHeader
 
Nested classes inherited from class org.exist.storage.btree.Paged
Paged.FileHeader, Paged.Page, Paged.PageHeader
 
Field Summary
static long DATA_SYNC_PERIOD
           
protected  Cache dataCache
           
static short FILE_FORMAT_VERSION_ID
           
protected  org.exist.storage.index.BFile.BFileHeader fileHeader
           
 int fixedKeyLen
           
static byte FREE_LIST
           
static byte LOB
           
protected  Lock lock
           
static byte LOG_CREATE_PAGE
           
static byte LOG_OVERFLOW_APPEND
           
static byte LOG_OVERFLOW_CREATE
           
static byte LOG_OVERFLOW_CREATE_PAGE
           
static byte LOG_OVERFLOW_MODIFIED
           
static byte LOG_OVERFLOW_REMOVE
           
static byte LOG_OVERFLOW_STORE
           
static byte LOG_REMOVE_PAGE
           
static byte LOG_REMOVE_VALUE
           
static byte LOG_STORE_VALUE
           
protected  int maxValueSize
           
protected  int minFree
           
static byte MULTI_PAGE
           
static int PAGE_MIN_FREE
           
static byte RECORD
           
static long UNKNOWN_ADDRESS
           
 
Fields inherited from class org.exist.storage.btree.BTree
BRANCH, buffers, cache, cacheManager, fileId, growthThreshold, isTransactional, KEY_NOT_FOUND, LEAF, LOG_CREATE_BNODE, LOG_INSERT_VALUE, LOG_SET_PARENT, LOG_UPDATE_PAGE, LOG_UPDATE_VALUE, logManager
 
Fields inherited from class org.exist.storage.btree.Paged
DELETED, LOG, OVERFLOW, PAGE_SIZE, UNUSED
 
Constructor Summary
BFile(BrokerPool pool, byte fileId, boolean transactional, java.io.File file, CacheManager cacheManager, double cacheGrowth, double thresholdBTree, double thresholdData)
           
 
Method Summary
 long append(Txn transaction, Value key, ByteArray value)
           
 long append(Value key, ByteArray value)
          Append the given data fragment to the value associated with the key.
 boolean close()
          Close the BFile.
 void closeAndRemove()
          Completely close down the instance and all underlying resources and caches.
 boolean containsKey(Value key)
          Check, if key is contained in BFile.
 boolean create()
           
 Paged.FileHeader createFileHeader()
          createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.
 Paged.FileHeader createFileHeader(boolean read)
          createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.
 Paged.FileHeader createFileHeader(long pageCount)
          createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.
 Paged.FileHeader createFileHeader(long pageCount, int pageSize)
          createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.
 Paged.PageHeader createPageHeader()
          createPageHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a PageHeader.
 void debugFreeList()
           
 void find(IndexQuery query, IndexCallback callback)
           
 java.util.ArrayList findEntries(IndexQuery query)
           
 java.util.ArrayList findKeys(IndexQuery query)
           
 boolean flush()
           
protected  Value get(org.exist.storage.index.BFile.DataPage page, long p)
          Retrieve value at logical address p from page
 Value get(long p)
          Returns the value located at the specified address.
 Value get(Value key)
          Get the value data associated with the specified key or null if the key could not be found.
 VariableByteInput getAsStream(long pointer)
          Get the value located at the specified address as a variable byte encoded input stream.
 VariableByteInput getAsStream(Value key)
          Get the value data for the given key as a variable byte encoded input stream.
 BufferStats getDataBufferStats()
           
protected  long getDataSyncPeriod()
           
 java.util.ArrayList getEntries()
           
 short getFileVersion()
           
 java.util.ArrayList getKeys()
           
 Lock getLock()
          Returns the Lock object responsible for this BFile.
 java.util.ArrayList getValues()
           
 boolean open()
           
 void printStatistics()
           
 long put(Txn transaction, Value key, byte[] data, boolean overwrite)
           
 long put(Txn transaction, Value key, ByteArray value, boolean overwrite)
           
 long put(Value key, byte[] data, boolean overwrite)
          Put data under given key.
 long put(Value key, ByteArray value)
          Convinience method for BFile#put(Value, byte[], true).
 long put(Value key, ByteArray value, boolean overwrite)
          Put a value under given key.
protected  void redoAppendOverflow(OverflowAppendLoggable loggable)
           
protected  void redoCreateOverflow(OverflowCreateLoggable loggable)
           
protected  void redoCreateOverflowPage(OverflowCreatePageLoggable loggable)
           
protected  void redoCreatePage(CreatePageLoggable loggable)
           
protected  void redoModifiedOverflow(OverflowModifiedLoggable loggable)
           
protected  void redoRemoveOverflow(OverflowRemoveLoggable loggable)
           
protected  void redoRemovePage(RemoveEmptyPageLoggable loggable)
           
protected  void redoRemoveValue(RemoveValueLoggable loggable)
           
protected  void redoStoreOverflow(OverflowStoreLoggable loggable)
           
protected  void redoStoreValue(StoreValueLoggable loggable)
           
 void remove(long p)
           
 void remove(Txn transaction, Value key)
           
 void remove(Value key)
           
 void removeAll(IndexQuery query)
          Remove all entries matching the given query.
 void setLocation(java.lang.String location)
           
 long storeValue(Txn transaction, ByteArray value)
           
protected  void undoAppendOverflow(OverflowAppendLoggable loggable)
           
protected  void undoCreateOverflow(OverflowCreateLoggable loggable)
           
protected  void undoCreateOverflowPage(OverflowCreatePageLoggable loggable)
           
protected  void undoCreatePage(CreatePageLoggable loggable)
           
protected  void undoModifiedOverflow(OverflowModifiedLoggable loggable)
           
protected  void undoRemoveOverflow(OverflowRemoveLoggable loggable)
           
protected  void undoRemovePage(RemoveEmptyPageLoggable loggable)
           
protected  void undoRemoveValue(RemoveValueLoggable loggable)
           
protected  void undoStoreValue(StoreValueLoggable loggable)
           
 long update(long p, Value key, ByteArray value)
          Update the key/value pair found at the logical address p.
protected  long update(Txn transaction, long p, org.exist.storage.index.BFile.DataPage page, Value key, ByteArray value)
          Update the key/value pair with logical address p and stored in page.
 long update(Txn transaction, long p, Value key, ByteArray value)
           
 long update(Value key, ByteArray value)
          Update a key/value pair.
 
Methods inherited from class org.exist.storage.btree.BTree
addValue, addValue, create, createRootNode, dump, dumpValue, findValue, getIndexBufferStats, getRootNode, open, query, query, redoCreateBTNode, redoInsertValue, redoRemoveValue, redoSetParent, redoUpdatePage, redoUpdateValue, remove, remove, removeValue, removeValue, requiresRedo, setRootNode, undoInsertValue, undoRemoveValue, undoUpdateValue
 
Methods inherited from class org.exist.storage.btree.Paged
backupToStream, exists, getFile, getFileHeader, getFreePage, getPage, getPageSize, hexDump, isOpened, isReadOnly, printFreeSpaceList, reuseDeleted, setFile, setPageSize, unlinkPages, unlinkPages, writeValue, writeValue, writeValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_FORMAT_VERSION_ID

public static final short FILE_FORMAT_VERSION_ID
See Also:
Constant Field Values

UNKNOWN_ADDRESS

public static final long UNKNOWN_ADDRESS
See Also:
Constant Field Values

DATA_SYNC_PERIOD

public static final long DATA_SYNC_PERIOD
See Also:
Constant Field Values

PAGE_MIN_FREE

public static final int PAGE_MIN_FREE
See Also:
Constant Field Values

RECORD

public static final byte RECORD
See Also:
Constant Field Values

LOB

public static final byte LOB
See Also:
Constant Field Values

FREE_LIST

public static final byte FREE_LIST
See Also:
Constant Field Values

MULTI_PAGE

public static final byte MULTI_PAGE
See Also:
Constant Field Values

LOG_CREATE_PAGE

public static final byte LOG_CREATE_PAGE
See Also:
Constant Field Values

LOG_STORE_VALUE

public static final byte LOG_STORE_VALUE
See Also:
Constant Field Values

LOG_REMOVE_VALUE

public static final byte LOG_REMOVE_VALUE
See Also:
Constant Field Values

LOG_REMOVE_PAGE

public static final byte LOG_REMOVE_PAGE
See Also:
Constant Field Values

LOG_OVERFLOW_APPEND

public static final byte LOG_OVERFLOW_APPEND
See Also:
Constant Field Values

LOG_OVERFLOW_STORE

public static final byte LOG_OVERFLOW_STORE
See Also:
Constant Field Values

LOG_OVERFLOW_CREATE

public static final byte LOG_OVERFLOW_CREATE
See Also:
Constant Field Values

LOG_OVERFLOW_MODIFIED

public static final byte LOG_OVERFLOW_MODIFIED
See Also:
Constant Field Values

LOG_OVERFLOW_CREATE_PAGE

public static final byte LOG_OVERFLOW_CREATE_PAGE
See Also:
Constant Field Values

LOG_OVERFLOW_REMOVE

public static final byte LOG_OVERFLOW_REMOVE
See Also:
Constant Field Values

fileHeader

protected org.exist.storage.index.BFile.BFileHeader fileHeader

minFree

protected int minFree

dataCache

protected Cache dataCache

lock

protected Lock lock

fixedKeyLen

public int fixedKeyLen

maxValueSize

protected int maxValueSize
Constructor Detail

BFile

public BFile(BrokerPool pool,
             byte fileId,
             boolean transactional,
             java.io.File file,
             CacheManager cacheManager,
             double cacheGrowth,
             double thresholdBTree,
             double thresholdData)
      throws DBException
Method Detail

getFileVersion

public short getFileVersion()
Overrides:
getFileVersion in class Paged
Returns:

getLock

public Lock getLock()
Returns the Lock object responsible for this BFile.

Returns:
Lock

getDataSyncPeriod

protected long getDataSyncPeriod()

append

public long append(Value key,
                   ByteArray value)
            throws ReadOnlyException,
                   java.io.IOException
Append the given data fragment to the value associated with the key. A new entry is created if the key does not yet exist in the database.

Parameters:
key -
value -
Returns:
Throws:
ReadOnlyException
java.io.IOException

append

public long append(Txn transaction,
                   Value key,
                   ByteArray value)
            throws ReadOnlyException,
                   java.io.IOException
Throws:
ReadOnlyException
java.io.IOException

close

public boolean close()
              throws DBException
Close the BFile.

Overrides:
close in class BTree
Returns:
always true
Throws:
DBException

containsKey

public boolean containsKey(Value key)
Check, if key is contained in BFile.

Parameters:
key - key to look for
Returns:
true, if key exists

create

public boolean create()
               throws DBException
Overrides:
create in class Paged
Throws:
DBException

closeAndRemove

public void closeAndRemove()
Description copied from class: Paged
Completely close down the instance and all underlying resources and caches.

Overrides:
closeAndRemove in class BTree

createFileHeader

public Paged.FileHeader createFileHeader()
Description copied from class: Paged
createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.

Overrides:
createFileHeader in class BTree
See Also:
Paged.createFileHeader()

createFileHeader

public Paged.FileHeader createFileHeader(boolean read)
                                  throws java.io.IOException
Description copied from class: Paged
createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.

Overrides:
createFileHeader in class BTree
Throws:
java.io.IOException
See Also:
Paged.createFileHeader(boolean)

createFileHeader

public Paged.FileHeader createFileHeader(long pageCount)
Description copied from class: Paged
createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.

Overrides:
createFileHeader in class BTree
See Also:
Paged.createFileHeader(long)

createFileHeader

public Paged.FileHeader createFileHeader(long pageCount,
                                         int pageSize)
Description copied from class: Paged
createFileHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a FileHeader.

Overrides:
createFileHeader in class BTree
See Also:
Paged.createFileHeader(long, int)

createPageHeader

public Paged.PageHeader createPageHeader()
Description copied from class: Paged
createPageHeader must be implemented by a Paged implementation in order to create an appropriate subclass instance of a PageHeader.

Overrides:
createPageHeader in class BTree
See Also:
Paged.createPageHeader()

removeAll

public void removeAll(IndexQuery query)
               throws java.io.IOException,
                      BTreeException
Remove all entries matching the given query.

Parameters:
query -
Throws:
java.io.IOException
BTreeException

findEntries

public java.util.ArrayList findEntries(IndexQuery query)
                                throws java.io.IOException,
                                       BTreeException,
                                       TerminatedException
Throws:
java.io.IOException
BTreeException
TerminatedException

findKeys

public java.util.ArrayList findKeys(IndexQuery query)
                             throws java.io.IOException,
                                    BTreeException,
                                    TerminatedException
Throws:
java.io.IOException
BTreeException
TerminatedException

find

public void find(IndexQuery query,
                 IndexCallback callback)
          throws java.io.IOException,
                 BTreeException,
                 TerminatedException
Throws:
java.io.IOException
BTreeException
TerminatedException

flush

public boolean flush()
              throws DBException
Overrides:
flush in class BTree
Throws:
DBException

getDataBufferStats

public BufferStats getDataBufferStats()

printStatistics

public void printStatistics()
Overrides:
printStatistics in class BTree

get

public Value get(Value key)
Get the value data associated with the specified key or null if the key could not be found.

Parameters:
key -
Returns:

getAsStream

public VariableByteInput getAsStream(Value key)
                              throws java.io.IOException
Get the value data for the given key as a variable byte encoded input stream.

Parameters:
key -
Returns:
Throws:
java.io.IOException

getAsStream

public VariableByteInput getAsStream(long pointer)
                              throws java.io.IOException
Get the value located at the specified address as a variable byte encoded input stream.

Parameters:
pointer -
Returns:
Throws:
java.io.IOException

get

public Value get(long p)
Returns the value located at the specified address.

Parameters:
p -
Returns:

get

protected Value get(org.exist.storage.index.BFile.DataPage page,
                    long p)
             throws BTreeException,
                    java.io.IOException
Retrieve value at logical address p from page

Throws:
BTreeException
java.io.IOException

getEntries

public java.util.ArrayList getEntries()
                               throws java.io.IOException,
                                      BTreeException,
                                      TerminatedException
Throws:
java.io.IOException
BTreeException
TerminatedException

getKeys

public java.util.ArrayList getKeys()
                            throws java.io.IOException,
                                   BTreeException,
                                   TerminatedException
Throws:
java.io.IOException
BTreeException
TerminatedException

getValues

public java.util.ArrayList getValues()
                              throws java.io.IOException,
                                     BTreeException,
                                     TerminatedException
Throws:
java.io.IOException
BTreeException
TerminatedException

open

public boolean open()
             throws DBException
Throws:
DBException

put

public long put(Value key,
                byte[] data,
                boolean overwrite)
         throws ReadOnlyException
Put data under given key.

Parameters:
data - the data (value) to update
overwrite - overwrite if set to true, value will be overwritten if it already exists
Returns:
on success the address of the stored value, else UNKNOWN_ADDRESS
Throws:
ReadOnlyException
See Also:
{@link BFile#put(Value, ByteArray, boolean)}

put

public long put(Txn transaction,
                Value key,
                byte[] data,
                boolean overwrite)
         throws ReadOnlyException
Throws:
ReadOnlyException

put

public long put(Value key,
                ByteArray value)
         throws ReadOnlyException
Convinience method for BFile#put(Value, byte[], true).

Parameters:
key - with which the data is updated
value - value to update
Returns:
on success the address of the stored value, else UNKNOWN_ADDRESS
Throws:
ReadOnlyException

put

public long put(Value key,
                ByteArray value,
                boolean overwrite)
         throws ReadOnlyException
Put a value under given key. The difference of this method and append(Value, ByteArray) is, that the value gets updated and not stored.

Parameters:
key - with which the data is updated
value - value to update
overwrite - if set to true, value will be overwritten if it already exists
Returns:
on success the address of the stored value, else UNKNOWN_ADDRESS
Throws:
ReadOnlyException

put

public long put(Txn transaction,
                Value key,
                ByteArray value,
                boolean overwrite)
         throws ReadOnlyException
Throws:
ReadOnlyException

remove

public void remove(Value key)
            throws ReadOnlyException
Throws:
ReadOnlyException

remove

public void remove(Txn transaction,
                   Value key)
            throws ReadOnlyException
Throws:
ReadOnlyException

remove

public void remove(long p)
            throws ReadOnlyException
Throws:
ReadOnlyException

setLocation

public void setLocation(java.lang.String location)
                 throws DBException
Throws:
DBException

storeValue

public long storeValue(Txn transaction,
                       ByteArray value)
                throws java.io.IOException,
                       ReadOnlyException
Throws:
java.io.IOException
ReadOnlyException

update

public long update(Value key,
                   ByteArray value)
            throws ReadOnlyException
Update a key/value pair.

Parameters:
key - Description of the Parameter
value - Description of the Parameter
Returns:
Description of the Return Value
Throws:
ReadOnlyException

update

public long update(long p,
                   Value key,
                   ByteArray value)
            throws ReadOnlyException
Update the key/value pair found at the logical address p.

Parameters:
p - Description of the Parameter
key - Description of the Parameter
value - Description of the Parameter
Returns:
Description of the Return Value
Throws:
ReadOnlyException

update

public long update(Txn transaction,
                   long p,
                   Value key,
                   ByteArray value)
            throws ReadOnlyException
Throws:
ReadOnlyException

update

protected long update(Txn transaction,
                      long p,
                      org.exist.storage.index.BFile.DataPage page,
                      Value key,
                      ByteArray value)
               throws BTreeException,
                      java.io.IOException,
                      ReadOnlyException
Update the key/value pair with logical address p and stored in page.

Parameters:
p - Description of the Parameter
page - Description of the Parameter
key - Description of the Parameter
value - Description of the Parameter
Throws:
BTreeException - Description of the Exception
java.io.IOException - Description of the Exception
ReadOnlyException

debugFreeList

public void debugFreeList()

redoStoreValue

protected void redoStoreValue(StoreValueLoggable loggable)

undoStoreValue

protected void undoStoreValue(StoreValueLoggable loggable)

redoCreatePage

protected void redoCreatePage(CreatePageLoggable loggable)

undoCreatePage

protected void undoCreatePage(CreatePageLoggable loggable)

redoRemoveValue

protected void redoRemoveValue(RemoveValueLoggable loggable)

undoRemoveValue

protected void undoRemoveValue(RemoveValueLoggable loggable)

redoRemovePage

protected void redoRemovePage(RemoveEmptyPageLoggable loggable)

undoRemovePage

protected void undoRemovePage(RemoveEmptyPageLoggable loggable)

redoCreateOverflow

protected void redoCreateOverflow(OverflowCreateLoggable loggable)

undoCreateOverflow

protected void undoCreateOverflow(OverflowCreateLoggable loggable)

redoCreateOverflowPage

protected void redoCreateOverflowPage(OverflowCreatePageLoggable loggable)

undoCreateOverflowPage

protected void undoCreateOverflowPage(OverflowCreatePageLoggable loggable)

redoAppendOverflow

protected void redoAppendOverflow(OverflowAppendLoggable loggable)

undoAppendOverflow

protected void undoAppendOverflow(OverflowAppendLoggable loggable)

redoStoreOverflow

protected void redoStoreOverflow(OverflowStoreLoggable loggable)

redoModifiedOverflow

protected void redoModifiedOverflow(OverflowModifiedLoggable loggable)

undoModifiedOverflow

protected void undoModifiedOverflow(OverflowModifiedLoggable loggable)

redoRemoveOverflow

protected void redoRemoveOverflow(OverflowRemoveLoggable loggable)

undoRemoveOverflow

protected void undoRemoveOverflow(OverflowRemoveLoggable loggable)


<oXygen/> XML Editor provides support for editing and debugging XQuery expressions against the eXist XML Database.