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.Paged
Paged.FileHeader, Paged.Page, Paged.PageHeader
 
Field Summary
static long DATA_SYNC_PERIOD
           
static short FILE_FORMAT_VERSION_ID
           
 int fixedKeyLen
           
static byte FREE_LIST
           
static byte LOB
           
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
           
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
KEY_NOT_FOUND, LOG_CREATE_BNODE, LOG_INSERT_VALUE, LOG_SET_PARENT, LOG_UPDATE_PAGE, LOG_UPDATE_VALUE
 
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()
           
 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()
           
 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 put(Value, byte[], boolean), overwrite is true.
 long put(Value key, ByteArray value, boolean overwrite)
          Put a value under given key.
 void remove(Txn transaction, long p)
           
 void remove(Txn transaction, Value key)
           
 void remove(Value key)
           
 void removeAll(Txn transaction, IndexQuery query)
          Remove all entries matching the given query.
 void setLocation(java.lang.String location)
           
 long storeValue(Txn transaction, ByteArray value)
           
 long update(long p, Value key, ByteArray value)
          Update the key/value pair found at the logical address p.
 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, dump, findValue, getIndexBufferStats, open, query, query, remove, remove, removeValue, removeValue
 
Methods inherited from class org.exist.storage.btree.Paged
backupToStream, exists, getFile, getFileHeader, getPageSize, hexDump, isOpened, isReadOnly, printFreeSpaceList, setPageSize
 
Methods inherited from class java.lang.Object
equals, 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

fixedKeyLen

public int fixedKeyLen
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:
file version

getLock

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

Returns:
Lock

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 -
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(Txn transaction,
                      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 -

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 -
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 -
Throws:
java.io.IOException

get

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

Parameters:
p -
Returns:
value located at the specified address

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:
key -
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:
put(Value,byte[],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 put(Value, byte[], boolean), overwrite is 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(Txn transaction,
                   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

debugFreeList

public void debugFreeList()


Copyright (C) Wolfgang Meier. All rights reserved.