24 #ifndef OM_HGUARD_CHERT_TABLE_H 25 #define OM_HGUARD_CHERT_TABLE_H 101 #define CHERT_BTREE_MAX_KEY_LEN 252 127 inline int getK(
const unsigned char *p,
int c) {
return getint1(p, c); }
128 inline void setD(
unsigned char *p,
int c,
int x) {
setint2(p, c, x); }
170 explicit Key(
const uint8_t * p_) : p(p_) { }
172 void read(std::string * key)
const {
173 key->assign(reinterpret_cast<const char *>(p +
K1),
length());
219 tag->append(reinterpret_cast<const char *>(p + cd), l);
251 int i = truncate_size;
254 int newkey_len = newkey.
length();
256 int newsize =
I2 +
K1 + i +
C2;
292 std::string::size_type key_len = key_.length();
297 std::string msg(
"Key too long: length was ");
299 msg +=
" bytes, maximum length of a key is " 304 set_key_len(key_len +
K1 +
C2);
305 std::memmove(
p +
I2 +
K1, key_.data(), key_len);
309 void set_tag(
int cd,
const char *start,
int len,
bool compressed) {
310 std::memmove(
p + cd, start, len);
312 if (compressed) *
p |= 0x80;
315 set_key_len(
K1 +
C2);
316 set_size(
I2 +
K1 + 2 *
C2);
318 set_components_of(1);
357 bool really_empty()
const;
376 ChertTable(
const char * tablename_,
const std::string & path_,
392 void close(
bool permanent =
false);
394 bool readahead_key(
const string &key)
const;
459 const std::string * changes_tail = NULL);
465 void write_changed_blocks(
int changes_fd);
488 bool get_exact_entry(
const std::string & key, std::string & tag)
const;
501 bool key_exists(
const std::string &key)
const;
511 bool read_tag(
Cursor * C_, std::string *tag,
bool keep_compressed)
const;
529 void add(
const std::string &key, std::string tag,
bool already_compressed =
false);
546 bool del(
const std::string &key);
555 void set_block_size(
unsigned int block_size_);
584 void create_and_open(
unsigned int blocksize);
586 void set_full_compaction(
bool parity);
599 return latest_revision_number;
611 return revision_number;
638 return (
level == 0) && really_empty();
662 max_item_size = (block_size -
DIR_START - block_capacity *
D2)
688 bool do_open_to_write(
bool revision_supplied,
690 bool create_db =
false);
693 bool find(
Cursor *)
const;
695 void read_block(
uint4 n, uint8_t *
p)
const;
696 void write_block(
uint4 n,
const uint8_t *p)
const;
697 XAPIAN_NORETURN(
void set_overwritten()
const);
698 void block_to_cursor(
Cursor *C_,
int j,
uint4 n)
const;
700 void compact(uint8_t *p);
701 void enter_key(
int j,
Key prevkey,
Key newkey);
702 int mid_point(uint8_t *p)
const;
703 void add_item_to_block(uint8_t *p,
Item_wr kt,
int c);
704 void add_item(
Item_wr kt,
int j);
705 void delete_item(
int j,
bool repeatedly);
706 int add_kt(
bool found);
708 void split_root(
uint4 split_n);
709 void form_key(
const std::string & key)
const;
712 return (base_letter ==
'A') ?
'B' :
'A';
719 void lazy_alloc_deflate_zstream()
const;
722 void lazy_alloc_inflate_zstream()
const;
817 if (sequential)
return prev_for_sequential(C_, j);
818 return prev_default(C_, j);
822 if (sequential)
return next_for_sequential(C_, j);
823 return next_default(C_, j);
827 bool prev_default(
Cursor *C_,
int j)
const;
828 bool next_default(
Cursor *C_,
int j)
const;
831 bool prev_for_sequential(
Cursor *C_,
int dummy)
const;
832 bool next_for_sequential(
Cursor *C_,
int dummy)
const;
834 static int find_in_block(
const uint8_t * p,
Key key,
bool leaf,
int c);
839 static uint4 block_given_by(
const uint8_t * p,
int c);
char other_base_letter() const
Define the XAPIAN_NORETURN macro.
int DIR_END(const uint8_t *b)
bool both_bases
set to true if baseA and baseB both exist as valid bases.
void setint4(unsigned char *p, int c, int x)
bool operator<=(Key key2) const
unsigned int get_block_size() const
Get the block size.
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
z_stream * inflate_zstream
Zlib state object for inflating.
XAPIAN_REVISION_TYPE rev
Revision number of a database.
chert_tablesize_t get_entry_count() const
Return a count of the number of entries in the table.
#define AssertRel(A, REL, B)
const int BYTES_PER_BLOCK_NUMBER
void unaligned_write4(unsigned char *ptr, T value)
int getint4(const unsigned char *p, int c)
int level
The value of level in the Btree structure.
uint16_t unaligned_read2(const unsigned char *ptr)
const size_t BLOCK_CAPACITY
Even for items of at maximum size, it must be possible to get this number of items in a block...
void set_components_of(int m)
const char * tablename
The name of the table (used when writing changesets).
Class managing a Btree table in a Chert database.
bool faked_root_block
true if the root block is faked (not written to disk).
Btree base file implementation.
uint4 root
the root block of the B-tree
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database.
Item_wr kt
buffer of size block_size for making up key-tag items
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
void append_chunk(std::string *tag) const
Convert types to std::string.
bool is_open() const
Return true if this table is open.
chert_tablesize_t item_count
keeps a count of the number of items in the B-tree.
int revision()
Report the revision of the library which the program is linked with.
static void throw_database_closed()
Item(const uint8_t *p_, int c)
int getK(const unsigned char *p, int c)
unsigned long cursor_version
Version count for tracking when cursors need to rebuild.
Types used by chert backend and the Btree manager.
unsigned int chert_revision_number_t
A type used to store a revision number for a table.
void aligned_write4(unsigned char *ptr, T value)
void setint2(unsigned char *p, int c, int x)
void set_component_of(int i)
uint8_t * split_p
Buffer used when splitting a block.
Hierarchy of classes which Xapian can throw as exceptions.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
chert_revision_number_t get_open_revision_number() const
Get the revision number at which this table is currently open.
functions for reading and writing different width words
int size() const
I in diagram above.
void form_null_key(uint4 n)
Form an item with a null key and with block number n in the tag.
bool is_modified() const
Determine whether the object contains uncommitted modifications.
void set_block_given_by(uint4 n)
Set this item's tag to point to block n (this block should not be at level 0).
unsigned long long chert_tablesize_t
A type used to store the number of entries in a table.
Interface to Btree cursors.
bool next(Cursor *C_, int j) const
std::string name
The path name of the B tree.
ChertCursor & operator=(const ChertCursor &)
Assignment not allowed.
void SET_LEVEL(uint8_t *b, int x)
int GET_LEVEL(const uint8_t *b)
bool operator<(Key key2) const
Compares this key with key2.
chert_revision_number_t revision_number
revision number of the opened B-tree.
uint32_t aligned_read4(const unsigned char *ptr)
bool operator!=(Key key2) const
string str(int value)
Convert int to std::string.
bool empty() const
Return true if there are no entries in the table.
void SET_DIR_END(uint8_t *b, int x)
bool writable
Set to true when the database is opened to write.
void set_max_item_size(size_t block_capacity)
Set the maximum item size given the block capacity.
void setD(unsigned char *p, int c, int x)
bool sequential
true iff the data has been written in a single write in sequential order.
char operator[](size_t i) const
z_stream * deflate_zstream
Zlib state object for deflating.
bool full_compaction
set to true when full compaction is to be achieved
uint4 changed_n
the last block to be changed by an addition
uint4 block_given_by() const
Get this item's tag as a block number (this block should not be at level 0).
size_t max_item_size
maximum size of an item (key-tag pair)
bool get_compressed() const
int MAX_FREE(const uint8_t *b)
int seq_count
count of the number of successive instances of purely sequential addition, starting at SEQ_START_POIN...
void unaligned_write2(unsigned char *ptr, T value)
void form_key(const std::string &key_)
bool Btree_modified
Set to true the first time the B-tree is modified.
void set_tag(int cd, const char *start, int len, bool compressed)
#define CHERT_BTREE_MAX_KEY_LEN
The largest possible value of a key_len.
int getint2(const unsigned char *p, int c)
chert_revision_number_t get_latest_revision_number() const
Get the latest revision number stored in this table.
int components_of() const
char base_letter
the value 'A' or 'B' of the current base
bool operator>(Key key2) const
chert_revision_number_t latest_revision_number
Revision number of the other base, or zero if there is only one base file.
unsigned int block_size
block size of the B tree in bytes
int changed_c
directory offset corresponding to last block to be changed by an addition
bool read_tag(bool keep_compressed=false)
Read the tag from the table and store it in current_tag.
int handle
File descriptor of the table.
const int BTREE_CURSOR_LEVELS
int getint1(const unsigned char *p, int c)
Various handy helpers which std::string really should provide.
unsigned REVISION(const uint8_t *b)
ChertTable_base base
For writing back as file baseA or baseB.
bool operator==(Key key2) const
bool cursor_created_since_last_modification
Flag for tracking when cursors need to rebuild.
void setint1(unsigned char *p, int c, int x)
Various assertion macros.
DatabaseError indicates some sort of database related error.
bool prev(Cursor *C_, int j) const
uint8_t * buffer
buffer of size block_size for reforming blocks
const size_t CHERT_MAX_ITEM_SIZE
void SET_REVISION(uint8_t *b, uint4 rev)
int level
number of levels, counting from 0
void SET_MAX_FREE(uint8_t *b, int x)
bool lazy
If true, don't create the table until it's needed.
void set_key_and_block(Key newkey, int truncate_size, uint4 n)
bool operator>=(Key key2) const
void read(std::string *key) const
Item_wr(uint8_t *p_, int c)
int TOTAL_FREE(const uint8_t *b)
uint4 last_readahead
Last block readahead_key() preread.
void SET_TOTAL_FREE(uint8_t *b, int x)
uint32_t unaligned_read4(const unsigned char *ptr)
const uint8_t * get_address() const
int compress_strategy
DONT_COMPRESS or Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE.