ChertDatabase Class Reference

A backend designed for efficient indexing and retrieval, using compressed posting lists and a btree storage scheme. More...

#include <chert_database.h>

Inheritance diagram for ChertDatabase:

Inheritance graph
[legend]
Collaboration diagram for ChertDatabase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ChertDatabase (const string &db_dir_, int action=XAPIAN_DB_READONLY, unsigned int block_size=0u)
 Create and open a chert database.
 ~ChertDatabase ()
ChertCursorget_postlist_cursor () const
 Get a postlist table cursor (used by ChertValueList).
 XAPIAN_NORETURN (void throw_termlist_table_close_exception() const)
Xapian::doccount get_doccount () const
 Virtual methods of Database::Internal.
Xapian::docid get_lastdocid () const
 Virtual methods of Database::Internal.
totlen_t get_total_length () const
 Virtual methods of Database::Internal.
Xapian::doclength get_avlength () const
 Virtual methods of Database::Internal.
Xapian::termcount get_doclength (Xapian::docid did) const
 Virtual methods of Database::Internal.
Xapian::doccount get_termfreq (const string &tname) const
 Virtual methods of Database::Internal.
Xapian::termcount get_collection_freq (const string &tname) const
 Virtual methods of Database::Internal.
Xapian::doccount get_value_freq (Xapian::valueno slot) const
 Virtual methods of Database::Internal.
std::string get_value_lower_bound (Xapian::valueno slot) const
 Virtual methods of Database::Internal.
std::string get_value_upper_bound (Xapian::valueno slot) const
 Virtual methods of Database::Internal.
Xapian::termcount get_doclength_lower_bound () const
 Virtual methods of Database::Internal.
Xapian::termcount get_doclength_upper_bound () const
 Virtual methods of Database::Internal.
Xapian::termcount get_wdf_upper_bound (const string &term) const
 Virtual methods of Database::Internal.
bool term_exists (const string &tname) const
 Virtual methods of Database::Internal.
bool has_positions () const
 Virtual methods of Database::Internal.
LeafPostListopen_post_list (const string &tname) const
 Virtual methods of Database::Internal.
ValueListopen_value_list (Xapian::valueno slot) const
 Virtual methods of Database::Internal.
Xapian::Document::Internalopen_document (Xapian::docid did, bool lazy) const
 Virtual methods of Database::Internal.
PositionListopen_position_list (Xapian::docid did, const string &term) const
 Virtual methods of Database::Internal.
TermListopen_term_list (Xapian::docid did) const
 Virtual methods of Database::Internal.
TermListopen_allterms (const string &prefix) const
 Virtual methods of Database::Internal.
TermListopen_spelling_termlist (const string &word) const
 Virtual methods of Database::Internal.
TermListopen_spelling_wordlist () const
 Virtual methods of Database::Internal.
Xapian::doccount get_spelling_frequency (const string &word) const
 Virtual methods of Database::Internal.
TermListopen_synonym_termlist (const string &term) const
 Virtual methods of Database::Internal.
TermListopen_synonym_keylist (const string &prefix) const
 Virtual methods of Database::Internal.
string get_metadata (const string &key) const
 Virtual methods of Database::Internal.
TermListopen_metadata_keylist (const std::string &prefix) const
 Virtual methods of Database::Internal.
void write_changesets_to_fd (int fd, const string &start_revision, bool need_whole_db, Xapian::ReplicationInfo *info)
 Virtual methods of Database::Internal.
string get_revision_info () const
 Virtual methods of Database::Internal.
string get_uuid () const
 Virtual methods of Database::Internal.

Private Member Functions

bool database_exists ()
 Return true if a database exists at the path specified for this database.
void create_and_open_tables (unsigned int blocksize)
 Create new tables, and open them.
void open_tables_consistent ()
 Open all tables at most recent consistent revision.
void get_database_write_lock (bool creating)
 Get a write lock on the database, or throw an Xapian::DatabaseLockError if failure.
void open_tables (chert_revision_number_t revision)
 Open tables at specified revision number.
chert_revision_number_t get_revision_number () const
 Get an object holding the revision number which the tables are opened at.
chert_revision_number_t get_next_revision_number () const
 Get an object holding the next revision number which should be used in the tables.
void set_revision_number (chert_revision_number_t new_revision)
 Set the revision number in the tables.
void reopen ()
 Re-open tables to recover from an overwritten condition, or just get most up-to-date version.
void close ()
 Close all the tables permanently.
void modifications_failed (chert_revision_number_t old_revision, chert_revision_number_t new_revision, const std::string &msg)
 Called if a modifications fail.
void apply ()
 Apply any outstanding changes to the tables.
void cancel ()
 Cancel any outstanding changes to the tables.
void send_whole_database (RemoteConnection &conn, double end_time)
 Send a set of messages which transfer the whole database.
void get_changeset_revisions (const string &path, chert_revision_number_t *startrev, chert_revision_number_t *endrev) const
 Get the revision stored in a changeset.

Private Attributes

std::string db_dir
 Directory to store databases in.
bool readonly
 Whether the database is readonly.
ChertVersion version_file
 The file describing the Chert database.
ChertPostListTable postlist_table
 Table storing posting lists.
ChertPositionListTable position_table
 Table storing position lists.
ChertTermListTable termlist_table
 Table storing term lists.
ChertValueManager value_manager
 Value manager.
ChertSynonymTable synonym_table
 Table storing synonym data.
ChertSpellingTable spelling_table
 Table storing spelling correction data.
ChertRecordTable record_table
 Table storing records.
FlintLock lock
 Lock object.
unsigned int max_changesets
 The maximum number of changesets which should be kept in the database.
ChertDatabaseStats stats
 Database statistics.

Friends

class ChertWritableDatabase
class ChertTermList
class ChertPostList
class ChertAllTermsList
class ChertAllDocsPostList


Detailed Description

A backend designed for efficient indexing and retrieval, using compressed posting lists and a btree storage scheme.

Definition at line 52 of file chert_database.h.


Constructor & Destructor Documentation

ChertDatabase::ChertDatabase ( const string &  db_dir_,
int  action = XAPIAN_DB_READONLY,
unsigned int  block_size = 0u 
)

Create and open a chert database.

Exceptions:
Xapian::DatabaseCorruptError is thrown if there is no consistent revision available.
Xapian::DatabaseOpeningError thrown if database can't be opened.
Xapian::DatabaseVersionError thrown if database is in an unsupported format. This implies that the database was created by an older or newer version of Xapian.
Parameters:
dbdir directory holding chert tables
block_size Block size, in bytes, to use when creating tables. This is only important, and has the correct value, when the database is being created.

Definition at line 105 of file chert_database.cc.

References create_and_open_tables(), database_exists(), Xapian::DB_CREATE, Xapian::DB_CREATE_OR_OVERWRITE, db_dir, Xapian::DB_OPEN, get_database_write_lock(), ChertTable::get_latest_revision_number(), get_next_revision_number(), ChertTable::get_open_revision_number(), LOGCALL_CTOR, mkdir(), open_tables_consistent(), postlist_table, record_table, S_ISDIR, set_revision_number(), stat(), and XAPIAN_DB_READONLY.

ChertDatabase::~ChertDatabase (  ) 

Definition at line 175 of file chert_database.cc.

References LOGCALL_DTOR.


Member Function Documentation

void ChertDatabase::apply (  )  [private]

Apply any outstanding changes to the tables.

If an error occurs during this operation, this will be signalled by an exception being thrown. In this case the contents of the tables on disk will be left in an unmodified state (though possibly with increased revision numbers), and the outstanding changes will be lost.

Reimplemented in ChertWritableDatabase.

Definition at line 718 of file chert_database.cc.

References Xapian::Error::get_description(), get_next_revision_number(), get_revision_number(), ChertSpellingTable::is_modified(), ChertSynonymTable::is_modified(), ChertValueManager::is_modified(), ChertTable::is_modified(), LOGCALL_VOID, modifications_failed(), position_table, postlist_table, record_table, set_revision_number(), spelling_table, synonym_table, termlist_table, and value_manager.

void ChertDatabase::cancel (  )  [private, virtual]

void ChertDatabase::close (  )  [private, virtual]

void ChertDatabase::create_and_open_tables ( unsigned int  blocksize  )  [private]

bool ChertDatabase::database_exists (  )  [private]

Return true if a database exists at the path specified for this database.

Definition at line 181 of file chert_database.cc.

References ChertTable::exists(), LOGCALL, postlist_table, record_table, and RETURN.

Referenced by ChertDatabase(), create_and_open_tables(), and get_database_write_lock().

Xapian::doclength ChertDatabase::get_avlength (  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Definition at line 780 of file chert_database.cc.

References ChertRecordTable::get_doccount(), ChertDatabaseStats::get_total_doclen(), LOGCALL, record_table, RETURN, and stats.

void ChertDatabase::get_changeset_revisions ( const string &  path,
chert_revision_number_t startrev,
chert_revision_number_t endrev 
) const [private]

Xapian::termcount ChertDatabase::get_collection_freq ( const string &  tname  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 809 of file chert_database.cc.

References Assert, ChertPostListTable::get_collection_freq(), LOGCALL, postlist_table, and RETURN.

Referenced by get_wdf_upper_bound().

void ChertDatabase::get_database_write_lock ( bool  creating  )  [private]

Get a write lock on the database, or throw an Xapian::DatabaseLockError if failure.

Parameters:
creating true if the database is in the process of being created - if false, will throw a DatabaseOpening error if the lock can't be acquired and the database doesn't exist.

Definition at line 501 of file chert_database.cc.

References database_exists(), db_dir, FlintLock::lock(), lock, LOGCALL_VOID, FlintLock::SUCCESS, and FlintLock::UNKNOWN.

Referenced by ChertDatabase().

Xapian::doccount ChertDatabase::get_doccount (  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Definition at line 759 of file chert_database.cc.

References ChertRecordTable::get_doccount(), LOGCALL, record_table, and RETURN.

Referenced by ChertWritableDatabase::open_post_list(), and open_post_list().

Xapian::termcount ChertDatabase::get_doclength ( Xapian::docid  did  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 792 of file chert_database.cc.

References Assert, ChertPostListTable::get_doclength(), LOGCALL, postlist_table, and RETURN.

Referenced by ChertWritableDatabase::get_doclength(), and open_document().

Xapian::termcount ChertDatabase::get_doclength_lower_bound (  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 838 of file chert_database.cc.

References ChertDatabaseStats::get_doclength_lower_bound(), and stats.

Xapian::termcount ChertDatabase::get_doclength_upper_bound (  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 844 of file chert_database.cc.

References ChertDatabaseStats::get_doclength_upper_bound(), and stats.

Xapian::docid ChertDatabase::get_lastdocid (  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Definition at line 766 of file chert_database.cc.

References ChertDatabaseStats::get_last_docid(), LOGCALL, RETURN, and stats.

string ChertDatabase::get_metadata ( const string &  key  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 979 of file chert_database.cc.

References ChertTable::get_exact_entry(), LOGCALL, postlist_table, and RETURN.

chert_revision_number_t ChertDatabase::get_next_revision_number (  )  const [private]

Get an object holding the next revision number which should be used in the tables.

Returns:
the next revision number.

Definition at line 322 of file chert_database.cc.

References ChertTable::get_latest_revision_number(), LOGCALL, postlist_table, and RETURN.

Referenced by apply(), and ChertDatabase().

ChertCursor* ChertDatabase::get_postlist_cursor (  )  const [inline]

Get a postlist table cursor (used by ChertValueList).

Definition at line 246 of file chert_database.h.

References ChertTable::cursor_get(), and postlist_table.

string ChertDatabase::get_revision_info (  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 1000 of file chert_database.cc.

References get_revision_number(), LOGCALL, pack_uint(), and RETURN.

chert_revision_number_t ChertDatabase::get_revision_number (  )  const [private]

Get an object holding the revision number which the tables are opened at.

Returns:
the current revision number.

Definition at line 314 of file chert_database.cc.

References ChertTable::get_open_revision_number(), LOGCALL, postlist_table, and RETURN.

Referenced by apply(), get_revision_info(), send_whole_database(), set_revision_number(), and write_changesets_to_fd().

Xapian::doccount ChertDatabase::get_spelling_frequency ( const string &  word  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 958 of file chert_database.cc.

References ChertSpellingTable::get_word_frequency(), and spelling_table.

Xapian::doccount ChertDatabase::get_termfreq ( const string &  tname  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 801 of file chert_database.cc.

References Assert, ChertPostListTable::get_termfreq(), LOGCALL, postlist_table, and RETURN.

totlen_t ChertDatabase::get_total_length (  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Definition at line 773 of file chert_database.cc.

References ChertDatabaseStats::get_total_doclen(), LOGCALL, RETURN, and stats.

string ChertDatabase::get_uuid (  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 1009 of file chert_database.cc.

References ChertVersion::get_uuid_string(), LOGCALL, RETURN, and version_file.

Referenced by send_whole_database(), and write_changesets_to_fd().

Xapian::doccount ChertDatabase::get_value_freq ( Xapian::valueno  slot  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 817 of file chert_database.cc.

References ChertValueManager::get_value_freq(), LOGCALL, RETURN, and value_manager.

Referenced by ChertWritableDatabase::get_value_freq().

std::string ChertDatabase::get_value_lower_bound ( Xapian::valueno  slot  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 824 of file chert_database.cc.

References ChertValueManager::get_value_lower_bound(), LOGCALL, RETURN, and value_manager.

Referenced by ChertWritableDatabase::get_value_lower_bound().

std::string ChertDatabase::get_value_upper_bound ( Xapian::valueno  slot  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 831 of file chert_database.cc.

References ChertValueManager::get_value_upper_bound(), LOGCALL, RETURN, and value_manager.

Referenced by ChertWritableDatabase::get_value_upper_bound().

Xapian::termcount ChertDatabase::get_wdf_upper_bound ( const string &  term  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 850 of file chert_database.cc.

References get_collection_freq(), ChertDatabaseStats::get_wdf_upper_bound(), and stats.

bool ChertDatabase::has_positions (  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Definition at line 864 of file chert_database.cc.

References ChertTable::empty(), and position_table.

void ChertDatabase::modifications_failed ( chert_revision_number_t  old_revision,
chert_revision_number_t  new_revision,
const std::string &  msg 
) [private]

Called if a modifications fail.

Parameters:
msg is a string description of the exception that was raised when the modifications failed.

Definition at line 690 of file chert_database.cc.

References cancel(), close(), Xapian::Error::get_msg(), open_tables(), and set_revision_number().

Referenced by apply().

TermList * ChertDatabase::open_allterms ( const string &  prefix  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 935 of file chert_database.cc.

References ChertAllTermsList, LOGCALL, and RETURN.

Referenced by ChertWritableDatabase::open_allterms().

Xapian::Document::Internal * ChertDatabase::open_document ( Xapian::docid  did,
bool  lazy 
) const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 906 of file chert_database.cc.

References Assert, get_doclength(), LOGCALL, record_table, RETURN, and value_manager.

TermList * ChertDatabase::open_metadata_keylist ( const std::string &  prefix  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 990 of file chert_database.cc.

References ChertTable::cursor_get(), LOGCALL, and postlist_table.

PositionList * ChertDatabase::open_position_list ( Xapian::docid  did,
const string &  term 
) const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Definition at line 920 of file chert_database.cc.

References Assert, and position_table.

LeafPostList * ChertDatabase::open_post_list ( const string &  tname  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 870 of file chert_database.cc.

References ChertAllDocsPostList, ChertPostList, get_doccount(), ChertDatabaseStats::get_last_docid(), LOGCALL, RETURN, and stats.

TermList * ChertDatabase::open_spelling_termlist ( const string &  word  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 943 of file chert_database.cc.

References ChertSpellingTable::open_termlist(), and spelling_table.

TermList * ChertDatabase::open_spelling_wordlist (  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 949 of file chert_database.cc.

References ChertTable::cursor_get(), and spelling_table.

TermList * ChertDatabase::open_synonym_keylist ( const string &  prefix  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 970 of file chert_database.cc.

References ChertTable::cursor_get(), and synonym_table.

TermList * ChertDatabase::open_synonym_termlist ( const string &  term  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Definition at line 964 of file chert_database.cc.

References ChertSynonymTable::open_termlist(), and synonym_table.

void ChertDatabase::open_tables ( chert_revision_number_t  revision  )  [private]

void ChertDatabase::open_tables_consistent (  )  [private]

TermList * ChertDatabase::open_term_list ( Xapian::docid  did  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Definition at line 895 of file chert_database.cc.

References Assert, ChertTermList, ChertTable::is_open(), LOGCALL, RETURN, and termlist_table.

ValueList * ChertDatabase::open_value_list ( Xapian::valueno  slot  )  const [virtual]

Virtual methods of Database::Internal.

Reimplemented from Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 887 of file chert_database.cc.

References LOGCALL, and RETURN.

Referenced by ChertWritableDatabase::open_value_list().

void ChertDatabase::reopen (  )  [private, virtual]

Re-open tables to recover from an overwritten condition, or just get most up-to-date version.

Reimplemented from Xapian::Database::Internal.

Definition at line 481 of file chert_database.cc.

References LOGCALL_VOID, open_tables_consistent(), and readonly.

Referenced by write_changesets_to_fd().

void ChertDatabase::send_whole_database ( RemoteConnection conn,
double  end_time 
) [private]

void ChertDatabase::set_revision_number ( chert_revision_number_t  new_revision  )  [private]

Set the revision number in the tables.

This updates the disk tables so that the currently open revision becomes the specified revision number.

Parameters:
new_revision The new revision number to store. This must be greater than the latest revision number (see get_latest_revision_number()), or undefined behaviour will result.

Definition at line 386 of file chert_database.cc.

References CHANGES_MAGIC_STRING, CHANGES_VERSION, ChertTable::commit(), create_changeset_file(), db_dir, ChertSpellingTable::flush_db(), ChertSynonymTable::flush_db(), ChertTable::flush_db(), get_revision_number(), io_unlink(), io_write(), LOGCALL_VOID, max_changesets, ChertValueManager::merge_changes(), pack_uint(), position_table, postlist_table, record_table, spelling_table, Xapian::Internal::str(), synonym_table, termlist_table, value_manager, and ChertTable::write_changed_blocks().

Referenced by apply(), ChertDatabase(), and modifications_failed().

bool ChertDatabase::term_exists ( const string &  tname  )  const [virtual]

Virtual methods of Database::Internal.

Implements Xapian::Database::Internal.

Reimplemented in ChertWritableDatabase.

Definition at line 856 of file chert_database.cc.

References Assert, LOGCALL, postlist_table, and ChertPostListTable::term_exists().

void ChertDatabase::write_changesets_to_fd ( int  fd,
const string &  start_revision,
bool  need_whole_db,
Xapian::ReplicationInfo info 
) [virtual]

ChertDatabase::XAPIAN_NORETURN ( void throw_termlist_table_close_exception()  const  ) 


Friends And Related Function Documentation

friend class ChertAllDocsPostList [friend]

Definition at line 57 of file chert_database.h.

Referenced by ChertWritableDatabase::open_post_list(), and open_post_list().

friend class ChertAllTermsList [friend]

Definition at line 56 of file chert_database.h.

Referenced by open_allterms().

friend class ChertPostList [friend]

Definition at line 55 of file chert_database.h.

Referenced by ChertWritableDatabase::open_post_list(), and open_post_list().

friend class ChertTermList [friend]

Definition at line 54 of file chert_database.h.

Referenced by open_term_list().

friend class ChertWritableDatabase [friend]

Definition at line 53 of file chert_database.h.


Member Data Documentation

std::string ChertDatabase::db_dir [private]

Directory to store databases in.

Definition at line 61 of file chert_database.h.

Referenced by ChertDatabase(), get_database_write_lock(), send_whole_database(), set_revision_number(), and write_changesets_to_fd().

Lock object.

Definition at line 111 of file chert_database.h.

Referenced by close(), and get_database_write_lock().

unsigned int ChertDatabase::max_changesets [private]

The maximum number of changesets which should be kept in the database.

Definition at line 115 of file chert_database.h.

Referenced by set_revision_number().

bool ChertDatabase::readonly [private]

Whether the database is readonly.

Definition at line 65 of file chert_database.h.

Referenced by reopen().

Table storing records.

Whenever an update is performed, this table is the last to be updated: therefore, its most recent revision number is the most recent consistent revision available. If this table's most recent revision number is not available for all tables, there is no consistent revision available, and the database is corrupt.

Definition at line 108 of file chert_database.h.

Referenced by ChertWritableDatabase::add_document_(), apply(), cancel(), ChertDatabase(), close(), create_and_open_tables(), database_exists(), ChertWritableDatabase::delete_document(), get_avlength(), get_doccount(), open_document(), open_tables(), open_tables_consistent(), ChertWritableDatabase::replace_document(), and set_revision_number().

The file describing the Chert database.

This file has information about the format of the database which can't easily be stored in any of the individual tables.

Definition at line 71 of file chert_database.h.

Referenced by create_and_open_tables(), get_uuid(), open_tables(), and open_tables_consistent().


The documentation for this class was generated from the following files:

Documentation for Xapian (version 1.2.13).
Generated on 9 Jan 2013 by Doxygen 1.5.9.