xapian-core
1.4.27
|
Class managing a Btree table in a Glass database. More...
#include <glass_table.h>
Public Member Functions | |
GlassTable (const char *tablename_, const std::string &path_, bool readonly_, bool lazy=false) | |
Create a new Btree object. More... | |
GlassTable (const char *tablename_, int fd, off_t offset_, bool readonly_, bool lazy=false) | |
~GlassTable () | |
Close the Btree. More... | |
void | close (bool permanent=false) |
Close the Btree. More... | |
bool | readahead_key (const string &key) const |
bool | exists () const |
Determine whether the btree exists on disk. More... | |
void | open (int flags_, const RootInfo &root_info, glass_revision_number_t rev) |
Open the btree. More... | |
bool | is_open () const |
Return true if this table is open. More... | |
bool | is_writable () const |
Return true if this table is writable. More... | |
void | flush_db () |
Flush any outstanding changes to the DB file of the table. More... | |
void | commit (glass_revision_number_t revision, RootInfo *root_info) |
Commit any outstanding changes to the table. More... | |
bool | sync () |
void | cancel (const RootInfo &root_info, glass_revision_number_t rev) |
Cancel any outstanding changes. More... | |
bool | get_exact_entry (const std::string &key, std::string &tag) const |
Read an entry from the table, if and only if it is exactly that being asked for. More... | |
bool | key_exists (const std::string &key) const |
Check if a key exists in the Btree. More... | |
bool | read_tag (Glass::Cursor *C_, std::string *tag, bool keep_compressed) const |
Read the tag value for the key pointed to by cursor C_. More... | |
void | add (const std::string &key, const std::string &tag, bool already_compressed=false) |
Add a key/tag pair to the table, replacing any existing pair with the same key. More... | |
bool | del (const std::string &key) |
Delete an entry from the table. More... | |
int | get_flags () const |
void | create_and_open (int flags_, const RootInfo &root_info) |
Create a new empty btree structure on disk and open it at the initial revision. More... | |
void | set_full_compaction (bool parity) |
glass_revision_number_t | get_open_revision_number () const |
Get the revision number at which this table is currently open. More... | |
glass_tablesize_t | get_entry_count () const |
Return a count of the number of entries in the table. More... | |
bool | empty () const |
Return true if there are no entries in the table. More... | |
GlassCursor * | cursor_get () const |
Get a cursor for reading from the table. More... | |
bool | is_modified () const |
Determine whether the object contains uncommitted modifications. More... | |
void | set_max_item_size (size_t block_capacity) |
Set the maximum item size given the block capacity. More... | |
void | set_changes (GlassChanges *changes) |
Set the GlassChanges object to write changed blocks to. More... | |
string | get_path () const |
Static Public Member Functions | |
static void | throw_database_closed () |
Throw an exception indicating that the database is closed. More... | |
Protected Member Functions | |
bool | find (Glass::Cursor *) const |
find(C_) searches for the key of B->kt in the B-tree. More... | |
int | delete_kt () |
void | read_block (uint4 n, uint8_t *p) const |
read_block(n, p) reads block n of the DB file to address p. More... | |
void | write_block (uint4 n, const uint8_t *p, bool appending=false) const |
write_block(n, p, appending) writes block n in the DB file from address p. More... | |
void | set_overwritten () const |
void | block_to_cursor (Glass::Cursor *C_, int j, uint4 n) const |
void | alter () |
Btree::alter(); is called when the B-tree is to be altered. More... | |
void | compact (uint8_t *p) |
compact(p) compact the block at p by shuffling all the items up to the end. More... | |
void | enter_key_above_leaf (Glass::LeafItem previtem, Glass::LeafItem newitem) |
enter_key_above_leaf(previtem, newitem) is called after a leaf block split. More... | |
void | enter_key_above_branch (int j, Glass::BItem newitem) |
enter_key_above_branch(j, newkey) is called after a branch block split. More... | |
int | mid_point (uint8_t *p) const |
mid_point(p) finds the directory entry in c that determines the approximate mid point of the data in the block at p. More... | |
void | add_item_to_leaf (uint8_t *p, Glass::LeafItem kt, int c) |
add_item_to_leaf(p, kt_, c) adds item kt_ to the leaf block at p. More... | |
void | add_item_to_branch (uint8_t *p, Glass::BItem kt, int c) |
add_item_to_branch(p, kt_, c) adds item kt_ to the branch block at p. More... | |
void | add_leaf_item (Glass::LeafItem kt) |
GlassTable::add_leaf_item(kt_) adds item kt_ to the leaf block. More... | |
void | add_branch_item (Glass::BItem kt, int j) |
GlassTable::add_item(kt_, j) adds item kt_ to the block at cursor level C[j]. More... | |
void | delete_leaf_item (bool repeatedly) |
GlassTable::delete_leaf_item(repeatedly) is (almost) the converse of add_leaf_item. More... | |
void | delete_branch_item (int j) |
GlassTable::delete_branch_item(j, repeatedly) is (almost) the converse of add_branch_item. More... | |
int | add_kt (bool found) |
add_kt(found) adds the item (key-tag pair) at B->kt into the B-tree, using cursor C. More... | |
void | read_root () |
void | split_root (uint4 split_n) |
Btree needs to gain a new level to insert more items: so split root block and construct a new one. More... | |
void | form_key (const std::string &key) const |
bool | single_file () const |
bool | prev (Glass::Cursor *C_, int j) const |
bool | next (Glass::Cursor *C_, int j) const |
bool | prev_default (Glass::Cursor *C_, int j) const |
bool | next_default (Glass::Cursor *C_, int j) const |
bool | prev_for_sequential (Glass::Cursor *C_, int dummy) const |
bool | next_for_sequential (Glass::Cursor *C_, int dummy) const |
Static Protected Member Functions | |
static int | find_in_leaf (const uint8_t *p, Glass::LeafItem item, int c, bool &exact) |
find_in_leaf(p, key, c, exact) searches for the key in the leaf block at p. More... | |
static int | find_in_branch (const uint8_t *p, Glass::LeafItem item, int c) |
static int | find_in_branch (const uint8_t *p, Glass::BItem item, int c) |
static uint4 | block_given_by (const uint8_t *p, int c) |
block_given_by(p, c) finds the item at block address p, directory offset c, and returns its tag value as an integer. More... | |
Protected Attributes | |
const char * | tablename |
The name of the table (used when writing changesets). More... | |
glass_revision_number_t | revision_number |
revision number of the opened B-tree. More... | |
glass_tablesize_t | item_count |
keeps a count of the number of items in the B-tree. More... | |
unsigned int | block_size |
block size of the B tree in bytes More... | |
int | flags |
Flags like DB_NO_SYNC and DB_DANGEROUS. More... | |
bool | faked_root_block |
true if the root block is faked (not written to disk). More... | |
bool | sequential |
true iff the data has been written in a single write in sequential order. More... | |
int | handle |
File descriptor of the table. More... | |
int | level |
number of levels, counting from 0 More... | |
uint4 | root |
the root block of the B-tree More... | |
Glass::LeafItem_wr | kt |
buffer of size block_size for making up key-tag items More... | |
uint8_t * | buffer |
buffer of size block_size for reforming blocks More... | |
GlassFreeList | free_list |
List of free blocks. More... | |
std::string | name |
The path name of the B tree. More... | |
int | seq_count |
count of the number of successive instances of purely sequential addition, starting at SEQ_START_POINT (neg) and going up to zero. More... | |
uint4 | changed_n |
the last block to be changed by an addition More... | |
int | changed_c |
directory offset corresponding to last block to be changed by an addition More... | |
size_t | max_item_size |
maximum size of an item (key-tag pair) More... | |
bool | Btree_modified |
Set to true the first time the B-tree is modified. More... | |
bool | full_compaction |
set to true when full compaction is to be achieved More... | |
bool | writable |
Set to true when the database is opened to write. More... | |
bool | cursor_created_since_last_modification |
Flag for tracking when cursors need to rebuild. More... | |
unsigned long | cursor_version |
Version count for tracking when cursors need to rebuild. More... | |
GlassChanges * | changes_obj |
The GlassChanges object to write block changes to. More... | |
Glass::Cursor | C [GLASS_BTREE_CURSOR_LEVELS] |
uint8_t * | split_p |
Buffer used when splitting a block. More... | |
uint4 | compress_min |
Minimum size tag to try compressing (0 for no compression). More... | |
CompressionStream | comp_stream |
bool | lazy |
If true, don't create the table until it's needed. More... | |
uint4 | last_readahead |
Last block readahead_key() preread. More... | |
off_t | offset |
offset to start of table in file. More... | |
Private Member Functions | |
GlassTable (const GlassTable &) | |
Copying not allowed. More... | |
GlassTable & | operator= (const GlassTable &) |
Assignment not allowed. More... | |
void | basic_open (const RootInfo *root_info, glass_revision_number_t rev) |
void | do_open_to_read (const RootInfo *root_info, glass_revision_number_t rev) |
Perform the opening operation to read. More... | |
void | do_open_to_write (const RootInfo *root_info, glass_revision_number_t rev=0) |
Perform the opening operation to write. More... | |
Friends | |
class | GlassCursor |
class | GlassFreeList |
Class managing a Btree table in a Glass database.
A table is a store holding a set of key/tag pairs.
A key is used to access a block of data in a glass table.
Keys are of limited length.
Keys may not be empty (each Btree has a special empty key for internal use).
A tag is a piece of data associated with a given key. The contents of the tag are opaque to the Btree.
Tags may be of arbitrary length (the Btree imposes a very large limit). Note though that they will be loaded into memory in their entirety, so should not be permitted to grow without bound in normal usage.
Tags which are null strings are valid, and are different from a tag simply not being in the table.
Definition at line 425 of file glass_table.h.
|
private |
Copying not allowed.
GlassTable::GlassTable | ( | const char * | tablename_, |
const std::string & | path_, | ||
bool | readonly_, | ||
bool | lazy = false |
||
) |
Create a new Btree object.
This does not create the table on disk - the create_and_open() method must be called to create the table on disk.
This also does not open the table - either the create_and_open() or open() methods must be called before use is made of the table.
tablename_ | The name of the table (used in changesets). |
path_ | Path at which the table is stored. |
readonly_ | whether to open the table for read only access. |
lazy | If true, don't create the table until it's needed. |
Definition at line 1698 of file glass_table.cc.
References LOGCALL_CTOR.
GlassTable::GlassTable | ( | const char * | tablename_, |
int | fd, | ||
off_t | offset_, | ||
bool | readonly_, | ||
bool | lazy = false |
||
) |
Definition at line 1733 of file glass_table.cc.
References LOGCALL_CTOR.
GlassTable::~GlassTable | ( | ) |
Close the Btree.
Any outstanding changes (ie, changes made without commit() having subsequently been called) will be lost.
Definition at line 1807 of file glass_table.cc.
References close(), and LOGCALL_DTOR.
void GlassTable::add | ( | const std::string & | key, |
const std::string & | tag, | ||
bool | already_compressed = false |
||
) |
Add a key/tag pair to the table, replacing any existing pair with the same key.
If an error occurs during the operation, an exception will be thrown.
If key is empty, then the null item is replaced.
e.g. btree.add("TODAY", "Mon 9 Oct 2000");
key | The key to store in the table. |
tag | The tag to store in the table. |
already_compressed | true if tag is already compressed, for example because it is being opaquely copied (default: false). |
Definition at line 1279 of file glass_table.cc.
References Assert, AssertEq, BYTE_PAIR_RANGE, C, Glass::D2, Glass::I2, Glass::RootInfo::init(), Glass::K1, LOGCALL_VOID, throw_database_closed(), Glass::TOTAL_FREE(), and Glass::X2.
Referenced by GlassDocDataTable::add_document_data(), Glass::PostlistChunkWriter::flush(), GlassCompact::merge_docid_keyed(), GlassCompact::merge_positions(), GlassCompact::merge_postlists(), GlassCompact::merge_spellings(), GlassCompact::merge_synonyms(), GlassDocDataTable::replace_document_data(), GlassWritableDatabase::set_metadata(), and Glass::ValueUpdater::write_tag().
|
protected |
GlassTable::add_item(kt_, j) adds item kt_ to the block at cursor level C[j].
If there is not enough room the block splits and the item is then added to the appropriate half.
Definition at line 942 of file glass_table.cc.
References Assert, AssertRel, Glass::BItem_base< T >::block_given_by(), C, Glass::D2, Glass::DIR_END(), Glass::DIR_START, Glass::BItem_wr::form_null_key(), Glass::BItem_base< T >::key(), Glass::Key::length(), LOGCALL_VOID, Glass::MAX_FREE(), Glass::SET_DIR_END(), Glass::SET_TOTAL_FREE(), Glass::BItem_base< T >::size(), and Glass::TOTAL_FREE().
|
protected |
add_item_to_branch(p, kt_, c) adds item kt_ to the branch block at p.
c is the offset in the directory that needs to be expanded to accommodate the new entry for the item. We know before this is called that there is enough contiguous room for the item in the block, so it's just a matter of shuffling up any directory entries after where we're inserting and copying in the item.
Definition at line 811 of file glass_table.cc.
References Assert, AssertRel, Glass::D2, Glass::DIR_END(), Glass::DIR_START, Glass::BItem_base< T >::get_address(), LOGCALL_VOID, Glass::MAX_FREE(), Glass::SET_DIR_END(), Glass::SET_MAX_FREE(), Glass::SET_TOTAL_FREE(), Glass::BItem_wr::setD(), Glass::BItem_base< T >::size(), and Glass::TOTAL_FREE().
|
protected |
add_item_to_leaf(p, kt_, c) adds item kt_ to the leaf block at p.
c is the offset in the directory that needs to be expanded to accommodate the new entry for the item. We know before this is called that there is enough contiguous room for the item in the block, so it's just a matter of shuffling up any directory entries after where we're inserting and copying in the item.
Definition at line 771 of file glass_table.cc.
References Assert, AssertRel, Glass::D2, Glass::DIR_END(), Glass::DIR_START, Glass::LeafItem_base< T >::get_address(), LOGCALL_VOID, Glass::MAX_FREE(), Glass::SET_DIR_END(), Glass::SET_MAX_FREE(), Glass::SET_TOTAL_FREE(), Glass::LeafItem_wr::setD(), Glass::LeafItem_base< T >::size(), and Glass::TOTAL_FREE().
|
protected |
add_kt(found) adds the item (key-tag pair) at B->kt into the B-tree, using cursor C.
found == find() is handed over as a parameter from Btree::add. Btree::alter() prepares for the alteration to the B-tree. Then there are a number of cases to consider:
If an item with the same key is in the B-tree (found is true), the new kt replaces it.
If then kt is smaller, or the same size as, the item it replaces, kt is put in the same place as the item it replaces, and the TOTAL_FREE measure is reduced.
If kt is larger than the item it replaces it is put in the MAX_FREE space if there is room, and the directory entry and space counts are adjusted accordingly.
If the key of kt is not in the B-tree (found is false), the new kt is added in with add_item.
Returns: 0 : added kt 1 : replaced kt 2 : replaced kt and it was the final one
Definition at line 1149 of file glass_table.cc.
References Assert, AssertRel, C, Glass::D2, Glass::DIR_END(), Glass::DIR_START, Glass::LeafItem_base< T >::get_address(), Glass::LeafItem_base< T >::last_component(), LOGCALL, Glass::MAX_FREE(), RETURN, SEQ_START_POINT, Glass::SET_MAX_FREE(), Glass::SET_TOTAL_FREE(), Glass::LeafItem_wr::setD(), Glass::LeafItem_base< T >::size(), and Glass::TOTAL_FREE().
|
protected |
GlassTable::add_leaf_item(kt_) adds item kt_ to the leaf block.
If there is not enough room the block splits and the item is then added to the appropriate half.
Definition at line 847 of file glass_table.cc.
References Assert, AssertRel, C, Glass::D2, Glass::DIR_END(), Glass::DIR_START, LOGCALL_VOID, Glass::MAX_FREE(), Glass::SET_DIR_END(), Glass::LeafItem_base< T >::size(), and Glass::TOTAL_FREE().
|
protected |
Btree::alter(); is called when the B-tree is to be altered.
It causes new blocks to be forced for the current set of blocks in the cursor.
The point is that if a block at level 0 is to be altered it may get a new number. Then the pointer to this block from level 1 will need changing. So the block at level 1 needs altering and may get a new block number. Then the pointer to this block from level 2 will need changing ... and so on back to the root.
The clever bit here is spotting the cases when we can make an early exit from this process. If C[j].rewrite is true, C[j+k].rewrite will be true for k = 1,2 ... We have been through all this before, and there is no need to do it again. If C[j].n was free at the start of the transaction, we can copy it back to the same place without violating the integrity of the B-tree. We don't then need a new n and can return. The corresponding C[j].rewrite may be true or false in that case.
Definition at line 374 of file glass_table.cc.
References Assert, C, Xapian::DB_DANGEROUS, LOGCALL_VOID, Glass::REVISION(), Glass::BItem_wr::set_block_given_by(), and Glass::SET_REVISION().
|
private |
Definition at line 1577 of file glass_table.cc.
References Glass::BLOCK_CAPACITY, C, Glass::RootInfo::get_compress_min(), Glass::RootInfo::get_free_list(), Glass::RootInfo::get_level(), Glass::RootInfo::get_num_entries(), Glass::RootInfo::get_root(), Glass::RootInfo::get_root_is_fake(), Glass::RootInfo::get_sequential(), LOGCALL_VOID, and zeroed_new().
Referenced by do_open_to_read().
|
staticprotected |
block_given_by(p, c) finds the item at block address p, directory offset c, and returns its tag value as an integer.
Referenced by next_default(), and prev_default().
|
protected |
Definition at line 310 of file glass_table.cc.
References Assert, C, Glass::Cursor::clone(), Glass::GET_LEVEL(), Glass::Cursor::init(), LOGCALL_VOID, rare, Glass::REVISION(), Glass::Cursor::rewrite, Glass::Cursor::set_n(), and Xapian::Internal::str().
Referenced by next_default(), and prev_default().
void GlassTable::cancel | ( | const RootInfo & | root_info, |
glass_revision_number_t | rev | ||
) |
Cancel any outstanding changes.
This will discard any modifications which haven't been committed by calling commit().
Definition at line 1927 of file glass_table.cc.
References Assert, block_size, Btree_modified, C, changed_c, changed_n, cursor_created_since_last_modification, cursor_version, Xapian::DB_DANGEROUS, DIR_START, faked_root_block, flags, free_list, Glass::RootInfo::get_blocksize(), Glass::RootInfo::get_free_list(), Glass::RootInfo::get_level(), Glass::RootInfo::get_num_entries(), Glass::RootInfo::get_root(), Glass::RootInfo::get_root_is_fake(), Glass::RootInfo::get_sequential(), handle, Glass::Cursor::init(), item_count, level, LOGCALL_VOID, read_root(), GlassFreeList::reset(), revision_number, Glass::Cursor::rewrite, root, seq_count, SEQ_START_POINT, sequential, throw_database_closed(), GlassFreeList::unpack(), and writable.
Referenced by GlassSynonymTable::cancel(), GlassSpellingTable::cancel(), and GlassDatabase::cancel().
void GlassTable::close | ( | bool | permanent = false | ) |
Close the Btree.
This closes and frees any of the btree structures which have been created and opened.
permanent | If true, the Btree will not reopen on demand. |
Definition at line 1812 of file glass_table.cc.
References buffer, C, Glass::Cursor::destroy(), Glass::LeafItem_base< T >::get_address(), handle, kt, level, LOGCALL_VOID, single_file(), and split_p.
Referenced by GlassDatabase::close(), commit(), create_and_open(), open(), and ~GlassTable().
void GlassTable::commit | ( | glass_revision_number_t | revision, |
RootInfo * | root_info | ||
) |
Commit any outstanding changes to the table.
Commit changes made by calling add() and del() to the Btree.
If an error occurs during the operation, this will be signalled by an exception. In case of error, changes made will not be committed to the Btree - they will be discarded.
new_revision | The new revision number to store. This must be greater than the current revision number. FIXME: If we support rewinding to a previous revision, maybe this needs to be greater than any previously used revision. |
root_info | Information about the root is returned in this. |
Definition at line 1866 of file glass_table.cc.
References Assert, block_size, Btree_modified, C, changed_c, changed_n, close(), GlassFreeList::commit(), DIR_START, faked_root_block, free_list, Glass::Cursor::get_n(), handle, Glass::Cursor::init(), item_count, level, LOGCALL_VOID, GlassFreeList::pack(), read_root(), Xapian::revision(), revision_number, root, seq_count, SEQ_START_POINT, sequential, Glass::RootInfo::set_blocksize(), Glass::RootInfo::set_free_list(), Glass::RootInfo::set_level(), Glass::RootInfo::set_num_entries(), GlassFreeList::set_revision(), Glass::RootInfo::set_root(), Glass::RootInfo::set_root_is_fake(), Glass::RootInfo::set_sequential(), throw_database_closed(), and writable.
Referenced by GlassDatabase::compact(), GlassCompact::multimerge_postlists(), and GlassDatabase::set_revision_number().
|
protected |
compact(p) compact the block at p by shuffling all the items up to the end.
MAX_FREE(p) is then maximized, and is equal to TOTAL_FREE(p).
Definition at line 563 of file glass_table.cc.
References Assert, Glass::D2, Glass::DIR_END(), Glass::DIR_START, Glass::LeafItem_base< T >::get_address(), Glass::BItem_base< T >::get_address(), Glass::GET_LEVEL(), LOGCALL_VOID, Glass::SET_MAX_FREE(), Glass::SET_TOTAL_FREE(), Glass::LeafItem_wr::setD(), Glass::BItem_wr::setD(), Glass::LeafItem_base< T >::size(), and Glass::BItem_base< T >::size().
void GlassTable::create_and_open | ( | int | flags_, |
const RootInfo & | root_info | ||
) |
Create a new empty btree structure on disk and open it at the initial revision.
The table must be writable - it doesn't make sense to create a table that is read-only!
The block size must be less than 64K, where K = 1024. It is unwise to use a small block size (less than 1024 perhaps), so we enforce a minimum block size of 2K.
Example:
// File will be "X." + GLASS_TABLE_EXTENSION (i.e. "X.glass") Btree btree("X."); btree.create_and_open(0, root_info);
root_info | RootInfo object |
Xapian::DatabaseCreateError | if the table can't be created. |
Xapian::InvalidArgumentError | if the requested blocksize is unsuitable. |
Definition at line 1776 of file glass_table.cc.
References Assert, block_size, BYTE_PAIR_RANGE, close(), compress_min, do_open_to_write(), flags, Glass::RootInfo::get_blocksize(), Glass::RootInfo::get_compress_min(), GLASS_TABLE_EXTENSION, handle, io_unlink(), lazy, LOGCALL_VOID, throw_database_closed(), and writable.
Referenced by GlassDatabase::compact(), GlassDatabase::create_and_open_tables(), and GlassCompact::multimerge_postlists().
GlassCursor * GlassTable::cursor_get | ( | ) | const |
Get a cursor for reading from the table.
The cursor is owned by the caller - it is the caller's responsibility to ensure that it is deleted.
Definition at line 1562 of file glass_table.cc.
References LOGCALL, RETURN, and throw_database_closed().
Referenced by Glass::PostlistChunkWriter::flush(), GlassDatabase::get_postlist_cursor(), GlassAllTermsList::next(), GlassDatabase::open_metadata_keylist(), GlassDatabase::open_spelling_wordlist(), GlassDatabase::open_synonym_keylist(), GlassPositionList::read_data(), GlassAllTermsList::skip_to(), and Glass::ValueUpdater::update().
bool GlassTable::del | ( | const std::string & | key | ) |
Delete an entry from the table.
The entry will be removed from the table, if it exists. If it does not exist, no action will be taken. The item with an empty key can't be removed, and false is returned.
If an error occurs during the operation, this will be signalled by an exception.
e.g. bool deleted = btree.del("TODAY")
key | The key to remove from the table. |
Definition at line 1394 of file glass_table.cc.
References Assert, GLASS_BTREE_MAX_KEY_LEN, LOGCALL, RETURN, and throw_database_closed().
Referenced by GlassDocDataTable::delete_document_data(), Glass::PostlistChunkWriter::flush(), GlassWritableDatabase::set_metadata(), and Glass::ValueUpdater::write_tag().
|
protected |
GlassTable::delete_branch_item(j, repeatedly) is (almost) the converse of add_branch_item.
The process repeats at the next level when a block has been completely emptied, freeing the block and taking out the pointer to it. Emptied root blocks are also removed, which reduces the number of levels in the B-tree.
Definition at line 1074 of file glass_table.cc.
References Assert, AssertRel, BLK_UNUSED, Glass::BItem_base< T >::block_given_by(), C, Glass::D2, Glass::DIR_END(), Glass::DIR_START, LOGCALL_VOID, Glass::MAX_FREE(), Glass::SET_DIR_END(), Glass::SET_MAX_FREE(), Glass::SET_TOTAL_FREE(), Glass::BItem_base< T >::size(), and Glass::TOTAL_FREE().
|
protected |
Definition at line 1222 of file glass_table.cc.
References Assert, C, Glass::LeafItem_base< T >::last_component(), LOGCALL, RETURN, and SEQ_START_POINT.
|
protected |
GlassTable::delete_leaf_item(repeatedly) is (almost) the converse of add_leaf_item.
If repeatedly is true, the process repeats at the next level when a block has been completely emptied, freeing the block and taking out the pointer to it. Emptied root blocks are also removed, which reduces the number of levels in the B-tree.
Definition at line 1039 of file glass_table.cc.
References Assert, AssertRel, BLK_UNUSED, C, Glass::D2, Glass::DIR_END(), Glass::DIR_START, LOGCALL_VOID, Glass::MAX_FREE(), Glass::SET_DIR_END(), Glass::SET_MAX_FREE(), Glass::SET_TOTAL_FREE(), Glass::LeafItem_base< T >::size(), and Glass::TOTAL_FREE().
|
private |
Perform the opening operation to read.
Definition at line 1980 of file glass_table.cc.
References basic_open(), GLASS_TABLE_EXTENSION, handle, io_open_block_rd(), lazy, LOGCALL, name, read_root(), revision_number, single_file(), and throw_database_closed().
Referenced by open().
|
private |
Perform the opening operation to write.
Definition at line 1659 of file glass_table.cc.
References Glass::DIR_START, GLASS_TABLE_EXTENSION, io_open_block_wr(), LOGCALL_VOID, name, SEQ_START_POINT, throw_database_closed(), and zeroed_new().
Referenced by create_and_open(), and open().
|
inline |
Return true if there are no entries in the table.
Definition at line 681 of file glass_table.h.
Referenced by GlassDatabase::compact(), GlassDatabase::has_positions(), main(), GlassCompact::merge_docid_keyed(), GlassCompact::merge_positions(), GlassCompact::merge_postlists(), GlassCompact::merge_spellings(), and GlassCompact::merge_synonyms().
|
protected |
enter_key_above_branch(j, newkey) is called after a branch block split.
It enters in the block at level C[j] a separating key for the block at level C[j - 1]. The key itself is newkey.
This code looks longer than it really is. If j exceeds the number of B-tree levels the root block has split and we have to construct a new one, but this is a rare event.
The key is constructed in b, with block number C[j - 1].n as tag, and this is added in with add_item. add_item may itself cause a block split, with a further call to enter_key. Hence the recursion.
Definition at line 703 of file glass_table.cc.
References Assert, AssertEq, AssertRel, Glass::BYTES_PER_BLOCK_NUMBER, C, Glass::D2, Glass::K1, Glass::BItem_base< T >::key(), LOGCALL_VOID, Glass::BItem_wr::set_key_and_block(), and Glass::X2.
|
protected |
enter_key_above_leaf(previtem, newitem) is called after a leaf block split.
It enters in the block at level C[1] a separating key for the block at level C[0]. The key itself is newitem.key(). previtem is the preceding item, and at level 1 newitem.key() can be trimmed down to the first point of difference to previtem.key() for entry in C[j].
This code looks longer than it really is. If j exceeds the number of B-tree levels the root block has split and we have to construct a new one, but this is a rare event.
The key is constructed in b, with block number C[0].n as tag, and this is added in with add_item. add_item may itself cause a block split, with a further call to enter_key. Hence the recursion.
Definition at line 647 of file glass_table.cc.
References Assert, AssertEq, AssertRel, Glass::BYTES_PER_BLOCK_NUMBER, C, Glass::compare(), Glass::LeafItem_base< T >::component_of(), Glass::D2, Glass::K1, Glass::LeafItem_base< T >::key(), Glass::Key::length(), LOGCALL_VOID, Glass::BItem_wr::set_truncated_key_and_block(), and Glass::X2.
bool GlassTable::exists | ( | ) | const |
Determine whether the btree exists on disk.
Definition at line 1769 of file glass_table.cc.
References file_exists(), GLASS_TABLE_EXTENSION, LOGCALL, and single_file().
Referenced by GlassDatabase::database_exists().
|
protected |
find(C_) searches for the key of B->kt in the B-tree.
Result is true if found, false otherwise. When false, the B_tree cursor is positioned at the last key in the B-tree <= the search key. Goes to first (null) item in B-tree when key length == 0.
Definition at line 530 of file glass_table.cc.
|
staticprotected |
Definition at line 509 of file glass_table.cc.
References find_in_branch_(), Glass::LeafItem_base< T >::get_address(), LOGCALL_STATIC, and RETURN.
|
staticprotected |
Definition at line 516 of file glass_table.cc.
References find_in_branch_(), Glass::BItem_base< T >::get_address(), LOGCALL_STATIC, and RETURN.
|
staticprotected |
find_in_leaf(p, key, c, exact) searches for the key in the leaf block at p.
What we get is the directory entry to the last key <= the key being searched for.
The lookup is by binary chop, with i and j set to the left and right ends of the search area. In sequential addition, c will often be the answer, so we test the keys round c and move i and j towards c if possible.
exact is set to true if the match was exact (otherwise exact is unchanged).
Definition at line 418 of file glass_table.cc.
References Assert, AssertRel, Glass::compare(), Glass::D2, Glass::DIR_END(), Glass::DIR_START, Glass::LeafItem_base< T >::get_address(), LOGCALL_STATIC, and RETURN.
void GlassTable::flush_db | ( | ) |
Flush any outstanding changes to the DB file of the table.
This must be called before commit, to ensure that the DB file is ready to be switched to a new version by the commit.
Definition at line 1845 of file glass_table.cc.
References Assert, C, faked_root_block, handle, level, LOGCALL_VOID, throw_database_closed(), writable, and write_block().
Referenced by GlassDatabase::compact(), GlassSynonymTable::flush_db(), GlassSpellingTable::flush_db(), GlassCompact::multimerge_postlists(), and GlassDatabase::set_revision_number().
|
protected |
Definition at line 1249 of file glass_table.cc.
References LOGCALL_VOID.
|
inline |
Return a count of the number of entries in the table.
The count does not include the ever-present item with null key.
Use empty() if you only want to know if the table is empty or not.
Definition at line 676 of file glass_table.h.
Referenced by Inverter::has_positions(), and main().
bool GlassTable::get_exact_entry | ( | const std::string & | key, |
std::string & | tag | ||
) | const |
Read an entry from the table, if and only if it is exactly that being asked for.
If the key is found in the table, then the tag is copied to tag. If the key is not found tag is left unchanged.
The result is true iff the specified key is found in the Btree.
key | The key to look for in the table. |
tag | A tag object to fill with the value if found. |
Definition at line 1473 of file glass_table.cc.
References Assert, C, GLASS_BTREE_MAX_KEY_LEN, LOGCALL, RETURN, and throw_database_closed().
Referenced by Glass::PostlistChunkWriter::flush(), GlassDocDataTable::get_document_data(), GlassPostListTable::get_freqs(), GlassDatabase::get_metadata(), GlassTermList::GlassTermList(), and Inverter::store_positions().
|
inline |
Definition at line 626 of file glass_table.h.
Referenced by GlassDatabase::apply(), GlassDatabase::modifications_failed(), and GlassDatabase::reopen().
|
inline |
Get the revision number at which this table is currently open.
It is possible that there are other, more recent or older revisions available.
Definition at line 663 of file glass_table.h.
|
inline |
Definition at line 728 of file glass_table.h.
References GLASS_TABLE_EXTENSION, Glass::Key::p, GlassFreeList::read_block(), and GlassFreeList::write_block().
Referenced by GlassDatabase::compact().
|
inline |
Determine whether the object contains uncommitted modifications.
Definition at line 697 of file glass_table.h.
Referenced by GlassDatabase::apply(), GlassDatabase::compact(), GlassWritableDatabase::has_uncommitted_changes(), GlassSynonymTable::is_modified(), and GlassSpellingTable::is_modified().
|
inline |
Return true if this table is open.
NB If the table is lazy and doesn't yet exist, returns false.
Definition at line 506 of file glass_table.h.
Referenced by GlassWritableDatabase::add_document_(), GlassWritableDatabase::delete_document(), GlassDatabase::open_tables(), GlassDatabase::open_term_list(), GlassWritableDatabase::replace_document(), and GlassDatabase::throw_termlist_table_close_exception().
|
inline |
Return true if this table is writable.
Definition at line 509 of file glass_table.h.
References GlassFreeList::commit(), and Xapian::revision().
Referenced by GlassPostList::open_nearby_postlist().
bool GlassTable::key_exists | ( | const std::string & | key | ) | const |
Check if a key exists in the Btree.
This is just like get_exact_entry() except it doesn't read the tag value so is more efficient if you only want to check that the key exists.
key | The key to look for in the table. |
Definition at line 1496 of file glass_table.cc.
References Assert, C, GLASS_BTREE_MAX_KEY_LEN, LOGCALL, and RETURN.
|
protected |
mid_point(p) finds the directory entry in c that determines the approximate mid point of the data in the block at p.
Definition at line 734 of file glass_table.cc.
References Assert, Glass::D2, Glass::DIR_END(), Glass::DIR_START, Glass::GET_LEVEL(), LOGCALL, RETURN, Glass::LeafItem_base< T >::size(), Glass::BItem_base< T >::size(), and Glass::TOTAL_FREE().
|
inlineprotected |
Definition at line 860 of file glass_table.h.
References dummy.
Referenced by Glass::PostlistChunkReader::is_at_end().
|
protected |
Definition at line 2163 of file glass_table.cc.
References AssertRel, block_given_by(), block_size, block_to_cursor(), Glass::Cursor::c, D2, DIR_END(), DIR_START, Glass::Cursor::get_p(), level, LOGCALL, and RETURN.
|
protected |
Definition at line 2082 of file glass_table.cc.
References Assert, AssertRel, block_size, Glass::Cursor::c, C, Glass::Cursor::clone(), D2, DIR_END(), DIR_START, free_list, GlassFreeList::get_first_unused_block(), GET_LEVEL(), Glass::Cursor::get_n(), Glass::Cursor::get_p(), Glass::Cursor::init(), level, LOGCALL, read_block(), RETURN, REVISION(), revision_number, Glass::Cursor::set_n(), set_overwritten(), and writable.
void GlassTable::open | ( | int | flags_, |
const RootInfo & | root_info, | ||
glass_revision_number_t | rev | ||
) |
Open the btree.
flags_ | flags for opening |
root_info | root block info |
Xapian::DatabaseCorruptError | will be thrown if the table is in a corrupt state. |
Xapian::DatabaseOpeningError | will be thrown if the table cannot be opened (but is not corrupt - eg, permission problems, not present, etc). |
Definition at line 2010 of file glass_table.cc.
References block_size, close(), do_open_to_read(), do_open_to_write(), flags, Glass::RootInfo::get_blocksize(), Glass::RootInfo::get_root(), LOGCALL_VOID, root, and writable.
Referenced by GlassDatabase::compact(), main(), GlassDatabase::modifications_failed(), GlassPostListTable::open(), and GlassDatabase::open_tables().
|
private |
Assignment not allowed.
|
inlineprotected |
Definition at line 854 of file glass_table.h.
|
protected |
Definition at line 2139 of file glass_table.cc.
References AssertRel, block_given_by(), block_size, block_to_cursor(), Glass::Cursor::c, D2, DIR_END(), DIR_START, Glass::Cursor::get_p(), level, LOGCALL, and RETURN.
|
protected |
Definition at line 2029 of file glass_table.cc.
References AssertRel, block_size, Glass::Cursor::c, C, Glass::Cursor::clone(), D2, DIR_END(), DIR_START, GET_LEVEL(), Glass::Cursor::get_n(), Glass::Cursor::init(), level, LOGCALL, read_block(), RETURN, REVISION(), revision_number, Glass::Cursor::set_n(), set_overwritten(), and writable.
|
protected |
read_block(n, p) reads block n of the DB file to address p.
Definition at line 160 of file glass_table.cc.
References AssertRel, Glass::DIR_END(), Glass::DIR_START, Glass::GET_LEVEL(), io_read_block(), Glass::LEVEL_FREELIST, LOGCALL_VOID, rare, Xapian::Internal::str(), and throw_database_closed().
Referenced by next_for_sequential(), prev_for_sequential(), and GlassFreeList::read_block().
|
protected |
Definition at line 1614 of file glass_table.cc.
References Assert, C, Glass::D2, Glass::DIR_START, Glass::LeafItem_wr::fake_root_item(), Glass::I2, Glass::K1, LOGCALL_VOID, Glass::REVISION(), Glass::SET_DIR_END(), Glass::SET_LEVEL(), Glass::SET_MAX_FREE(), Glass::SET_REVISION(), Glass::SET_TOTAL_FREE(), and Glass::LeafItem_wr::setD().
Referenced by cancel(), commit(), and do_open_to_read().
bool GlassTable::read_tag | ( | Glass::Cursor * | C_, |
std::string * | tag, | ||
bool | keep_compressed | ||
) | const |
Read the tag value for the key pointed to by cursor C_.
keep_compressed | Don't uncompress the tag - e.g. useful if it's just being opaquely copied. |
Definition at line 1509 of file glass_table.cc.
References Glass::LeafItem_base< T >::append_chunk(), Glass::LeafItem_base< T >::decompress_chunk(), Glass::LeafItem_base< T >::get_compressed(), Glass::LeafItem_base< T >::last_component(), LOGCALL, and RETURN.
bool GlassTable::readahead_key | ( | const string & | key | ) | const |
Definition at line 1430 of file glass_table.cc.
References Assert, Glass::BItem_base< T >::block_given_by(), C, GLASS_BTREE_MAX_KEY_LEN, io_readahead_block(), LOGCALL, and RETURN.
Referenced by GlassDocDataTable::readahead_for_document(), and GlassDatabase::readahead_for_query().
|
inline |
Set the GlassChanges object to write changed blocks to.
The GlassChanges object is not owned by the table, so the table must not delete it.
Definition at line 721 of file glass_table.h.
References throw_database_closed().
Referenced by GlassDatabase::apply(), GlassDatabase::modifications_failed(), and GlassDatabase::open_tables().
void GlassTable::set_full_compaction | ( | bool | parity | ) |
Definition at line 1553 of file glass_table.cc.
References Assert, and LOGCALL_VOID.
Referenced by GlassDatabase::compact().
|
inline |
Set the maximum item size given the block capacity.
At least this many items of maximum size must fit into a block. The default is BLOCK_CAPACITY (which is currently 4).
Definition at line 704 of file glass_table.h.
References Glass::BLOCK_CAPACITY, Glass::D2, Glass::DIR_START, and Glass::MAX_ITEM_SIZE.
Referenced by GlassDatabase::compact().
|
protected |
Definition at line 289 of file glass_table.cc.
References LOGCALL_VOID.
Referenced by next_for_sequential(), and prev_for_sequential().
|
inlineprotected |
Definition at line 849 of file glass_table.h.
Referenced by close(), do_open_to_read(), and exists().
|
protected |
Btree needs to gain a new level to insert more items: so split root block and construct a new one.
Definition at line 600 of file glass_table.cc.
References C, Glass::DIR_START, Glass::BItem_wr::form_null_key(), GLASS_BTREE_CURSOR_LEVELS, LOGCALL_VOID, Glass::SET_DIR_END(), Glass::SET_LEVEL(), Glass::SET_REVISION(), and STRINGIZE.
|
inline |
Definition at line 535 of file glass_table.h.
References Xapian::DB_NO_SYNC, and io_sync().
Referenced by GlassDatabase::compact(), and GlassDatabase::set_revision_number().
|
static |
Throw an exception indicating that the database is closed.
Definition at line 2195 of file glass_table.cc.
Referenced by add(), cancel(), commit(), create_and_open(), cursor_get(), del(), do_open_to_read(), do_open_to_write(), flush_db(), GlassValueManager::get_all_values(), get_exact_entry(), GlassDatabase::open_tables(), read_block(), and GlassDatabase::throw_termlist_table_close_exception().
write_block(n, p, appending) writes block n in the DB file from address p.
If appending is true (not specified it defaults to false), then this indicates that we've added data to a block in space which was previously unused, and are writing the block back in place - we use this to add free list entries (the information about where the freelist data for a revision begins and ends is stored in the "iamglass" file). We don't currently use this flag for much, but it signifies that we don't risk invalidating any existing revisions, which may be useful information.
Definition at line 191 of file glass_table.cc.
References Assert, AssertEqParanoid, AssertRel, Xapian::DB_DANGEROUS, Glass::DOCDATA, io_write_block(), LOGCALL_VOID, pack_uint(), Glass::POSITION, Glass::POSTLIST, Glass::REVISION(), Glass::SPELLING, Glass::SYNONYM, and Glass::TERMLIST.
Referenced by flush_db(), and GlassFreeList::write_block().
|
friend |
Definition at line 426 of file glass_table.h.
|
friend |
Definition at line 427 of file glass_table.h.
|
protected |
block size of the B tree in bytes
Definition at line 767 of file glass_table.h.
Referenced by cancel(), commit(), create_and_open(), next_default(), next_for_sequential(), open(), prev_default(), and prev_for_sequential().
|
mutableprotected |
Set to true the first time the B-tree is modified.
Definition at line 829 of file glass_table.h.
|
protected |
buffer of size block_size for reforming blocks
Definition at line 802 of file glass_table.h.
Referenced by close().
|
mutableprotected |
Definition at line 884 of file glass_table.h.
Referenced by cancel(), close(), commit(), flush_db(), next_for_sequential(), and prev_for_sequential().
|
protected |
directory offset corresponding to last block to be changed by an addition
Definition at line 823 of file glass_table.h.
|
protected |
the last block to be changed by an addition
Definition at line 819 of file glass_table.h.
|
protected |
The GlassChanges object to write block changes to.
If NULL, no changes will be written.
Definition at line 847 of file glass_table.h.
|
mutableprotected |
Definition at line 896 of file glass_table.h.
|
protected |
Minimum size tag to try compressing (0 for no compression).
Definition at line 894 of file glass_table.h.
Referenced by create_and_open().
|
mutableprotected |
Flag for tracking when cursors need to rebuild.
Definition at line 838 of file glass_table.h.
Referenced by cancel().
|
protected |
Version count for tracking when cursors need to rebuild.
Definition at line 841 of file glass_table.h.
Referenced by cancel().
|
protected |
true if the root block is faked (not written to disk).
false otherwise. This is true when the btree hasn't been modified yet.
Definition at line 776 of file glass_table.h.
Referenced by cancel(), commit(), and flush_db().
|
protected |
Flags like DB_NO_SYNC and DB_DANGEROUS.
Definition at line 770 of file glass_table.h.
Referenced by cancel(), create_and_open(), and open().
|
protected |
List of free blocks.
Definition at line 805 of file glass_table.h.
Referenced by cancel(), commit(), and next_for_sequential().
|
protected |
set to true when full compaction is to be achieved
Definition at line 832 of file glass_table.h.
|
protected |
File descriptor of the table.
If close() has been called, this will be -2.
If the table is lazily created and doesn't yet exist, this will be -1 (for a multi-file database) or -3-fd (for a single-file database).
Definition at line 790 of file glass_table.h.
Referenced by cancel(), close(), commit(), create_and_open(), do_open_to_read(), and flush_db().
|
protected |
keeps a count of the number of items in the B-tree.
Definition at line 764 of file glass_table.h.
|
mutableprotected |
buffer of size block_size for making up key-tag items
Definition at line 799 of file glass_table.h.
Referenced by close().
|
mutableprotected |
Last block readahead_key() preread.
Definition at line 902 of file glass_table.h.
|
protected |
If true, don't create the table until it's needed.
Definition at line 899 of file glass_table.h.
Referenced by create_and_open(), and do_open_to_read().
|
protected |
number of levels, counting from 0
Definition at line 793 of file glass_table.h.
Referenced by cancel(), close(), commit(), flush_db(), next_default(), next_for_sequential(), prev_default(), and prev_for_sequential().
|
protected |
maximum size of an item (key-tag pair)
Definition at line 826 of file glass_table.h.
|
protected |
The path name of the B tree.
For a single-file database, this will be empty.
Definition at line 811 of file glass_table.h.
Referenced by do_open_to_read().
|
protected |
offset to start of table in file.
Definition at line 905 of file glass_table.h.
|
protected |
revision number of the opened B-tree.
Definition at line 761 of file glass_table.h.
Referenced by cancel(), commit(), do_open_to_read(), next_for_sequential(), and prev_for_sequential().
|
protected |
the root block of the B-tree
Definition at line 796 of file glass_table.h.
|
protected |
count of the number of successive instances of purely sequential addition, starting at SEQ_START_POINT (neg) and going up to zero.
Definition at line 816 of file glass_table.h.
|
protected |
true iff the data has been written in a single write in sequential order.
Definition at line 781 of file glass_table.h.
|
protected |
Buffer used when splitting a block.
This buffer holds the split off part of the block. It's only used when updating (in GlassTable::add_item().
Definition at line 891 of file glass_table.h.
Referenced by close().
|
protected |
The name of the table (used when writing changesets).
Definition at line 758 of file glass_table.h.
|
protected |
Set to true when the database is opened to write.
Definition at line 835 of file glass_table.h.
Referenced by cancel(), commit(), create_and_open(), flush_db(), next_for_sequential(), open(), and prev_for_sequential().