xapian-core  1.4.27
chert_table.h
Go to the documentation of this file.
1 
4 /* Copyright 1999,2000,2001 BrightStation PLC
5  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2012,2015,2016 Olly Betts
6  * Copyright 2008 Lemur Consulting Ltd
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21  * USA
22  */
23 
24 #ifndef OM_HGUARD_CHERT_TABLE_H
25 #define OM_HGUARD_CHERT_TABLE_H
26 
27 #include <xapian/error.h>
28 
29 #include "chert_types.h"
30 #include "chert_btreebase.h"
31 #include "chert_cursor.h"
32 
33 #include "noreturn.h"
34 #include "omassert.h"
35 #include "str.h"
36 #include "stringutils.h"
37 #include "wordaccess.h"
38 
39 #include <algorithm>
40 #include <string>
41 
42 #include <zlib.h>
43 
44 // FIXME: 65536 in Asserts below is the max chert block size. We should
45 // abstract this out, and use the current block_size to catch overruns better.
46 inline int
47 getint1(const unsigned char *p, int c)
48 {
49  AssertRel(c, >=, 0);
50  AssertRel(c, <, 65536);
51  return p[c];
52 }
53 
54 inline void
55 setint1(unsigned char *p, int c, int x)
56 {
57  AssertRel(c, >=, 0);
58  AssertRel(c, <, 65536);
59  p[c] = x;
60 }
61 
62 inline int
63 getint2(const unsigned char *p, int c)
64 {
65  AssertRel(c, >=, 0);
66  AssertRel(c, <, 65536 - 1);
67  return unaligned_read2(p + c);
68 }
69 
70 inline void
71 setint2(unsigned char *p, int c, int x)
72 {
73  AssertRel(c, >=, 0);
74  AssertRel(c, <, 65536 - 1);
75  unaligned_write2(p + c, uint16_t(x));
76 }
77 
78 inline int
79 getint4(const unsigned char *p, int c)
80 {
81  AssertRel(c, >=, 0);
82  AssertRel(c, <, 65536 - 3);
83  return unaligned_read4(p + c);
84 }
85 
86 inline void
87 setint4(unsigned char *p, int c, int x)
88 {
89  AssertRel(c, >=, 0);
90  AssertRel(c, <, 65536 - 3);
91  unaligned_write4(p + c, uint32_t(x));
92 }
93 
94 const int DONT_COMPRESS = -1;
95 
101 #define CHERT_BTREE_MAX_KEY_LEN 252
102 
105 const size_t BLOCK_CAPACITY = 4;
106 
107 // FIXME: This named constant probably isn't used everywhere it should be...
109 
110 /* The B-tree blocks have a number of internal lengths and offsets held in 1, 2
111  or 4 bytes. To make the coding a little clearer,
112  we use for
113  ------ ---
114  K1 the 1 byte length of key
115  I2 the 2 byte length of an item (key-tag pair)
116  D2 the 2 byte offset to the item from the directory
117  C2 the 2 byte counter that ends each key and begins each tag
118 */
119 
120 const int K1 = 1;
121 const int I2 = 2;
122 const int D2 = 2;
123 const int C2 = 2;
124 
125 /* and when getting K1 or setting D2, we use getK, setD defined as: */
126 
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); }
129 
130 /* if you've been reading the comments from the top, the next four procedures
131  will not cause any headaches.
132 
133  Recall that item has this form:
134 
135  i k
136  | |
137  I K key x C tag
138  <--K-->
139  <------I------>
140 
141 
142  item_of(p, c) returns i, the address of the item at block address p,
143  directory offset c,
144 
145  component_of(p, c) returns the number marked 'x' above,
146 
147  components_of(p, c) returns the number marked 'C' above,
148 */
149 
150 inline unsigned REVISION(const uint8_t * b) { return aligned_read4(b); }
151 inline int GET_LEVEL(const uint8_t * b) { return getint1(b, 4); }
152 inline int MAX_FREE(const uint8_t * b) { return getint2(b, 5); }
153 inline int TOTAL_FREE(const uint8_t * b) { return getint2(b, 7); }
154 inline int DIR_END(const uint8_t * b) { return getint2(b, 9); }
155 const int DIR_START = 11;
156 
157 inline void SET_REVISION(uint8_t * b, uint4 rev) { aligned_write4(b, rev); }
158 inline void SET_LEVEL(uint8_t * b, int x) { setint1(b, 4, x); }
159 inline void SET_MAX_FREE(uint8_t * b, int x) { setint2(b, 5, x); }
160 inline void SET_TOTAL_FREE(uint8_t * b, int x) { setint2(b, 7, x); }
161 inline void SET_DIR_END(uint8_t * b, int x) { setint2(b, 9, x); }
162 
163 // The item size is stored in 2 bytes, but the top bit is used to store a flag
164 // for "is the tag data compressed".
165 const size_t CHERT_MAX_ITEM_SIZE = 0x7fff;
166 
167 class Key {
168  const uint8_t *p;
169 public:
170  explicit Key(const uint8_t * p_) : p(p_) { }
171  const uint8_t * get_address() const { return p; }
172  void read(std::string * key) const {
173  key->assign(reinterpret_cast<const char *>(p + K1), length());
174  }
175  bool operator==(Key key2) const;
176  bool operator!=(Key key2) const { return !(*this == key2); }
177  bool operator<(Key key2) const;
178  bool operator>=(Key key2) const { return !(*this < key2); }
179  bool operator>(Key key2) const { return key2 < *this; }
180  bool operator<=(Key key2) const { return !(key2 < *this); }
181  int length() const {
182  AssertRel(getK(p, 0),>=,3);
183  return getK(p, 0) - C2 - K1;
184  }
185  char operator[](size_t i) const {
186  AssertRel(i,<,(size_t)length());
187  return p[i + K1];
188  }
189 };
190 
191 // Item_wr wants to be "Item with non-const p and more methods" - we can't
192 // achieve that nicely with inheritance, so we use a template base class.
193 template <class T> class Item_base {
194 protected:
195  T p;
196 public:
197  /* Item from block address and offset to item pointer */
198  Item_base(T p_, int c) : p(p_ + getint2(p_, c)) { }
199  explicit Item_base(T p_) : p(p_) { }
200  T get_address() const { return p; }
202  int size() const {
203  int item_size = getint2(p, 0) & CHERT_MAX_ITEM_SIZE;
204  AssertRel(item_size,>=,5);
205  return item_size;
206  }
207  bool get_compressed() const { return *p & 0x80; }
208  int component_of() const {
209  return getint2(p, getK(p, I2) + I2 - C2);
210  }
211  int components_of() const {
212  return getint2(p, getK(p, I2) + I2);
213  }
214  Key key() const { return Key(p + I2); }
215  void append_chunk(std::string * tag) const {
216  /* number of bytes to extract from current component */
217  int cd = getK(p, I2) + I2 + C2;
218  int l = size() - cd;
219  tag->append(reinterpret_cast<const char *>(p + cd), l);
220  }
226  return getint4(p, size() - BYTES_PER_BLOCK_NUMBER);
227  }
228 };
229 
230 class Item : public Item_base<const uint8_t *> {
231 public:
232  /* Item from block address and offset to item pointer */
233  Item(const uint8_t * p_, int c) : Item_base<const uint8_t *>(p_, c) { }
234  explicit Item(const uint8_t * p_) : Item_base<const uint8_t *>(p_) { }
235 };
236 
237 class Item_wr : public Item_base<uint8_t *> {
238  void set_key_len(int x) { setint1(p, I2, x); }
239 public:
240  /* Item_wr from block address and offset to item pointer */
241  Item_wr(uint8_t * p_, int c) : Item_base<uint8_t *>(p_, c) { }
242  explicit Item_wr(uint8_t * p_) : Item_base<uint8_t *>(p_) { }
243  void set_component_of(int i) {
244  setint2(p, getK(p, I2) + I2 - C2, i);
245  }
246  void set_components_of(int m) {
247  setint2(p, getK(p, I2) + I2, m);
248  }
249  // Takes size as we may be truncating newkey.
250  void set_key_and_block(Key newkey, int truncate_size, uint4 n) {
251  int i = truncate_size;
252  // Read the length now because we may be copying the key over itself.
253  // FIXME that's stupid! sort this out
254  int newkey_len = newkey.length();
255  AssertRel(i,<=,newkey_len);
256  int newsize = I2 + K1 + i + C2;
257  // Item size (BYTES_PER_BLOCK_NUMBER since tag contains block number)
258  setint2(p, 0, newsize + BYTES_PER_BLOCK_NUMBER);
259  // Key size
260  setint1(p, I2, newsize - I2);
261  // Copy the main part of the key, possibly truncating.
262  std::memmove(p + I2 + K1, newkey.get_address() + K1, i);
263  // Copy the count part.
264  std::memmove(p + I2 + K1 + i, newkey.get_address() + K1 + newkey_len, C2);
265  // Set tag contents to block number
266 // set_block_given_by(n);
267  setint4(p, newsize, n);
268  }
269 
274  setint4(p, size() - BYTES_PER_BLOCK_NUMBER, n);
275  }
276  void set_size(int l) {
277  AssertRel(l,>=,5);
278  // We should never be able to pass too large a size here, but don't
279  // corrupt the database if this somehow happens.
280  if (rare(l &~ CHERT_MAX_ITEM_SIZE))
281  throw Xapian::DatabaseError("item too large!");
282  setint2(p, 0, l);
283  }
287  setint4(p, I2 + K1, n);
288  set_key_len(K1); /* null key */
289  set_size(I2 + K1 + BYTES_PER_BLOCK_NUMBER); /* total length */
290  }
291  void form_key(const std::string & key_) {
292  std::string::size_type key_len = key_.length();
293  if (key_len > CHERT_BTREE_MAX_KEY_LEN) {
294  // We check term length when a term is added to a document but
295  // chert doubles zero bytes, so this can still happen for terms
296  // which contain one or more zero bytes.
297  std::string msg("Key too long: length was ");
298  msg += str(key_len);
299  msg += " bytes, maximum length of a key is "
301  throw Xapian::InvalidArgumentError(msg);
302  }
303 
304  set_key_len(key_len + K1 + C2);
305  std::memmove(p + I2 + K1, key_.data(), key_len);
306  set_component_of(1);
307  }
308  // FIXME passing cd here is icky
309  void set_tag(int cd, const char *start, int len, bool compressed) {
310  std::memmove(p + cd, start, len);
311  set_size(cd + len);
312  if (compressed) *p |= 0x80;
313  }
314  void fake_root_item() {
315  set_key_len(K1 + C2); // null key length
316  set_size(I2 + K1 + 2 * C2); // length of the item
317  set_component_of(1);
318  set_components_of(1);
319  }
320 };
321 
322 // Allow for BTREE_CURSOR_LEVELS levels in the B-tree.
323 // With 10, overflow is practically impossible
324 // FIXME: but we want it to be completely impossible...
325 const int BTREE_CURSOR_LEVELS = 10;
326 
347 class ChertTable {
348  friend class ChertCursor; /* Should probably fix this. */
349  private:
351  ChertTable(const ChertTable &);
352 
354  ChertTable & operator=(const ChertTable &);
355 
357  bool really_empty() const;
358 
359  public:
376  ChertTable(const char * tablename_, const std::string & path_,
377  bool readonly_, int compress_strategy_ = DONT_COMPRESS,
378  bool lazy = false);
379 
385  ~ChertTable();
386 
392  void close(bool permanent = false);
393 
394  bool readahead_key(const string &key) const;
395 
398  bool exists() const;
399 
408  void open();
409 
427  bool open(chert_revision_number_t revision_);
428 
433  bool is_open() const { return handle >= 0; }
434 
440  void flush_db();
441 
458  void commit(chert_revision_number_t revision, int changes_fd = -1,
459  const std::string * changes_tail = NULL);
460 
465  void write_changed_blocks(int changes_fd);
466 
472  void cancel();
473 
488  bool get_exact_entry(const std::string & key, std::string & tag) const;
489 
501  bool key_exists(const std::string &key) const;
502 
511  bool read_tag(Cursor * C_, std::string *tag, bool keep_compressed) const;
512 
529  void add(const std::string &key, std::string tag, bool already_compressed = false);
530 
546  bool del(const std::string &key);
547 
549  void erase();
550 
555  void set_block_size(unsigned int block_size_);
556 
559  unsigned int get_block_size() const { return block_size; }
560 
584  void create_and_open(unsigned int blocksize);
585 
586  void set_full_compaction(bool parity);
587 
599  return latest_revision_number;
600  }
601 
611  return revision_number;
612  }
613 
624  return item_count;
625  }
626 
628  bool empty() const {
629  // Prior to 1.1.4/1.0.18, item_count was stored in 32 bits, so we
630  // can't trust it as there could be more than 1<<32 entries.
631  //
632  // In theory it should wrap, so if non-zero the table isn't empty,
633  // but the table this was first noticed in wasn't off by a multiple
634  // of 1<<32.
635 
636  // An empty table will always have level == 0, and most non-empty
637  // tables will have more levels, so use that as a short-cut.
638  return (level == 0) && really_empty();
639  }
640 
646  ChertCursor * cursor_get() const;
647 
653  bool is_modified() const { return Btree_modified; }
654 
660  void set_max_item_size(size_t block_capacity) {
661  if (block_capacity > BLOCK_CAPACITY) block_capacity = BLOCK_CAPACITY;
662  max_item_size = (block_size - DIR_START - block_capacity * D2)
663  / block_capacity;
664  // Make sure we don't exceed the limit imposed by the format.
665  if (max_item_size > CHERT_MAX_ITEM_SIZE)
666  max_item_size = CHERT_MAX_ITEM_SIZE;
667  }
668 
670  XAPIAN_NORETURN(static void throw_database_closed());
671 
672  string get_path() const {
673  return name;
674  }
675 
676  protected:
677 
682  bool do_open_to_read(bool revision_supplied, chert_revision_number_t revision_);
683 
688  bool do_open_to_write(bool revision_supplied,
689  chert_revision_number_t revision_,
690  bool create_db = false);
691  bool basic_open(bool revision_supplied, chert_revision_number_t revision);
692 
693  bool find(Cursor *) const;
694  int delete_kt();
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;
699  void alter();
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);
707  void read_root();
708  void split_root(uint4 split_n);
709  void form_key(const std::string & key) const;
710 
711  char other_base_letter() const {
712  return (base_letter == 'A') ? 'B' : 'A';
713  }
714 
716  const char * tablename;
717 
719  void lazy_alloc_deflate_zstream() const;
720 
722  void lazy_alloc_inflate_zstream() const;
723 
726 
729 
731  unsigned int block_size;
732 
737 
742  mutable bool both_bases;
743 
746 
752 
757 
765  int handle;
766 
768  int level;
769 
772 
774  mutable Item_wr kt;
775 
777  uint8_t * buffer;
778 
781 
783  std::string name;
784 
789 
792 
796 
799 
801  mutable bool Btree_modified;
802 
805 
807  bool writable;
808 
811 
813  unsigned long cursor_version;
814 
815  /* B-tree navigation functions */
816  bool prev(Cursor *C_, int j) const {
817  if (sequential) return prev_for_sequential(C_, j);
818  return prev_default(C_, j);
819  }
820 
821  bool next(Cursor *C_, int j) const {
822  if (sequential) return next_for_sequential(C_, j);
823  return next_default(C_, j);
824  }
825 
826  /* Default implementations. */
827  bool prev_default(Cursor *C_, int j) const;
828  bool next_default(Cursor *C_, int j) const;
829 
830  /* Implementations for sequential mode. */
831  bool prev_for_sequential(Cursor *C_, int dummy) const;
832  bool next_for_sequential(Cursor *C_, int dummy) const;
833 
834  static int find_in_block(const uint8_t * p, Key key, bool leaf, int c);
835 
839  static uint4 block_given_by(const uint8_t * p, int c);
840 
842 
848  uint8_t * split_p;
849 
853 
855  mutable z_stream *deflate_zstream;
856 
858  mutable z_stream *inflate_zstream;
859 
861  bool lazy;
862 
865 
866  /* Debugging methods */
867 // void report_block_full(int m, int n, const uint8_t * p);
868 };
869 
870 #endif /* OM_HGUARD_CHERT_TABLE_H */
int close(FD &fd)
Definition: fd.h:63
char other_base_letter() const
Definition: chert_table.h:711
Define the XAPIAN_NORETURN macro.
int DIR_END(const uint8_t *b)
Definition: chert_table.h:154
bool both_bases
set to true if baseA and baseB both exist as valid bases.
Definition: chert_table.h:742
void setint4(unsigned char *p, int c, int x)
Definition: chert_table.h:87
bool operator<=(Key key2) const
Definition: chert_table.h:180
unsigned int get_block_size() const
Get the block size.
Definition: chert_table.h:559
A cursor pointing to a position in a Btree table, for reading several entries in order, or finding approximate matches.
Definition: chert_cursor.h:66
Key key() const
Definition: chert_table.h:214
z_stream * inflate_zstream
Zlib state object for inflating.
Definition: chert_table.h:858
XAPIAN_REVISION_TYPE rev
Revision number of a database.
Definition: types.h:133
Key(const uint8_t *p_)
Definition: chert_table.h:170
chert_tablesize_t get_entry_count() const
Return a count of the number of entries in the table.
Definition: chert_table.h:623
T get_address() const
Definition: chert_table.h:200
int length() const
Definition: chert_table.h:181
#define AssertRel(A, REL, B)
Definition: omassert.h:123
const int BYTES_PER_BLOCK_NUMBER
Definition: chert_table.h:108
void unaligned_write4(unsigned char *ptr, T value)
Definition: wordaccess.h:177
int getint4(const unsigned char *p, int c)
Definition: chert_table.h:79
int level
The value of level in the Btree structure.
Definition: chert_cursor.h:107
uint16_t unaligned_read2(const unsigned char *ptr)
Definition: wordaccess.h:163
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...
Definition: chert_table.h:105
const int C2
Definition: chert_table.h:123
void set_components_of(int m)
Definition: chert_table.h:246
const char * tablename
The name of the table (used when writing changesets).
Definition: chert_table.h:716
const int I2
Definition: chert_table.h:121
Class managing a Btree table in a Chert database.
Definition: chert_table.h:347
bool faked_root_block
true if the root block is faked (not written to disk).
Definition: chert_table.h:751
Btree base file implementation.
uint4 root
the root block of the B-tree
Definition: chert_table.h:771
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database.
Definition: dbfactory.h:104
Item_wr kt
buffer of size block_size for making up key-tag items
Definition: chert_table.h:774
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
Definition: stringutils.h:36
void append_chunk(std::string *tag) const
Definition: chert_table.h:215
int component_of() const
Definition: chert_table.h:208
Convert types to std::string.
bool is_open() const
Return true if this table is open.
Definition: chert_table.h:433
chert_tablesize_t item_count
keeps a count of the number of items in the B-tree.
Definition: chert_table.h:728
int revision()
Report the revision of the library which the program is linked with.
Definition: xapian.h:142
static void throw_database_closed()
Item(const uint8_t *p_, int c)
Definition: chert_table.h:233
int getK(const unsigned char *p, int c)
Definition: chert_table.h:127
unsigned long cursor_version
Version count for tracking when cursors need to rebuild.
Definition: chert_table.h:813
#define rare(COND)
Definition: config.h:575
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.
Definition: chert_types.h:40
const int DIR_START
Definition: chert_table.h:155
void aligned_write4(unsigned char *ptr, T value)
Definition: wordaccess.h:170
void setint2(unsigned char *p, int c, int x)
Definition: chert_table.h:71
void set_component_of(int i)
Definition: chert_table.h:243
uint8_t * split_p
Buffer used when splitting a block.
Definition: chert_table.h:848
Hierarchy of classes which Xapian can throw as exceptions.
const char * dummy[]
Definition: version_h.cc:7
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Definition: error.h:241
uint32_t uint4
Definition: internaltypes.h:32
chert_revision_number_t get_open_revision_number() const
Get the revision number at which this table is currently open.
Definition: chert_table.h:610
functions for reading and writing different width words
int size() const
I in diagram above.
Definition: chert_table.h:202
void form_null_key(uint4 n)
Form an item with a null key and with block number n in the tag.
Definition: chert_table.h:286
bool is_modified() const
Determine whether the object contains uncommitted modifications.
Definition: chert_table.h:653
void set_block_given_by(uint4 n)
Set this item&#39;s tag to point to block n (this block should not be at level 0).
Definition: chert_table.h:273
unsigned long long chert_tablesize_t
A type used to store the number of entries in a table.
Definition: chert_types.h:46
Interface to Btree cursors.
bool next(Cursor *C_, int j) const
Definition: chert_table.h:821
std::string name
The path name of the B tree.
Definition: chert_table.h:783
ChertCursor & operator=(const ChertCursor &)
Assignment not allowed.
void SET_LEVEL(uint8_t *b, int x)
Definition: chert_table.h:158
int GET_LEVEL(const uint8_t *b)
Definition: chert_table.h:151
bool operator<(Key key2) const
Compares this key with key2.
chert_revision_number_t revision_number
revision number of the opened B-tree.
Definition: chert_table.h:725
uint32_t aligned_read4(const unsigned char *ptr)
Definition: wordaccess.h:145
bool operator!=(Key key2) const
Definition: chert_table.h:176
string str(int value)
Convert int to std::string.
Definition: str.cc:90
bool empty() const
Return true if there are no entries in the table.
Definition: chert_table.h:628
void SET_DIR_END(uint8_t *b, int x)
Definition: chert_table.h:161
Item_base(T p_, int c)
Definition: chert_table.h:198
bool writable
Set to true when the database is opened to write.
Definition: chert_table.h:807
const int K1
Definition: chert_table.h:120
void set_max_item_size(size_t block_capacity)
Set the maximum item size given the block capacity.
Definition: chert_table.h:660
void setD(unsigned char *p, int c, int x)
Definition: chert_table.h:128
bool sequential
true iff the data has been written in a single write in sequential order.
Definition: chert_table.h:756
char operator[](size_t i) const
Definition: chert_table.h:185
z_stream * deflate_zstream
Zlib state object for deflating.
Definition: chert_table.h:855
bool full_compaction
set to true when full compaction is to be achieved
Definition: chert_table.h:804
uint4 changed_n
the last block to be changed by an addition
Definition: chert_table.h:791
uint4 block_given_by() const
Get this item&#39;s tag as a block number (this block should not be at level 0).
Definition: chert_table.h:224
void fake_root_item()
Definition: chert_table.h:314
size_t max_item_size
maximum size of an item (key-tag pair)
Definition: chert_table.h:798
bool get_compressed() const
Definition: chert_table.h:207
Item_base(T p_)
Definition: chert_table.h:199
int MAX_FREE(const uint8_t *b)
Definition: chert_table.h:152
string get_path() const
Definition: chert_table.h:672
int seq_count
count of the number of successive instances of purely sequential addition, starting at SEQ_START_POIN...
Definition: chert_table.h:788
void unaligned_write2(unsigned char *ptr, T value)
Definition: wordaccess.h:191
char name[9]
Definition: dbcheck.cc:55
void form_key(const std::string &key_)
Definition: chert_table.h:291
bool Btree_modified
Set to true the first time the B-tree is modified.
Definition: chert_table.h:801
void set_tag(int cd, const char *start, int len, bool compressed)
Definition: chert_table.h:309
#define CHERT_BTREE_MAX_KEY_LEN
The largest possible value of a key_len.
Definition: chert_table.h:101
const int DONT_COMPRESS
Definition: chert_table.h:94
int getint2(const unsigned char *p, int c)
Definition: chert_table.h:63
chert_revision_number_t get_latest_revision_number() const
Get the latest revision number stored in this table.
Definition: chert_table.h:598
int components_of() const
Definition: chert_table.h:211
char base_letter
the value &#39;A&#39; or &#39;B&#39; of the current base
Definition: chert_table.h:745
bool operator>(Key key2) const
Definition: chert_table.h:179
chert_revision_number_t latest_revision_number
Revision number of the other base, or zero if there is only one base file.
Definition: chert_table.h:736
unsigned int block_size
block size of the B tree in bytes
Definition: chert_table.h:731
int changed_c
directory offset corresponding to last block to be changed by an addition
Definition: chert_table.h:795
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.
Definition: chert_table.h:765
const int D2
Definition: chert_table.h:122
const int BTREE_CURSOR_LEVELS
Definition: chert_table.h:325
int getint1(const unsigned char *p, int c)
Definition: chert_table.h:47
Various handy helpers which std::string really should provide.
void set_size(int l)
Definition: chert_table.h:276
unsigned REVISION(const uint8_t *b)
Definition: chert_table.h:150
ChertTable_base base
For writing back as file baseA or baseB.
Definition: chert_table.h:780
bool operator==(Key key2) const
bool cursor_created_since_last_modification
Flag for tracking when cursors need to rebuild.
Definition: chert_table.h:810
void setint1(unsigned char *p, int c, int x)
Definition: chert_table.h:55
Various assertion macros.
DatabaseError indicates some sort of database related error.
Definition: error.h:367
void set_key_len(int x)
Definition: chert_table.h:238
bool prev(Cursor *C_, int j) const
Definition: chert_table.h:816
uint8_t * buffer
buffer of size block_size for reforming blocks
Definition: chert_table.h:777
const size_t CHERT_MAX_ITEM_SIZE
Definition: chert_table.h:165
void SET_REVISION(uint8_t *b, uint4 rev)
Definition: chert_table.h:157
int level
number of levels, counting from 0
Definition: chert_table.h:768
Item_wr(uint8_t *p_)
Definition: chert_table.h:242
void SET_MAX_FREE(uint8_t *b, int x)
Definition: chert_table.h:159
bool lazy
If true, don&#39;t create the table until it&#39;s needed.
Definition: chert_table.h:861
void set_key_and_block(Key newkey, int truncate_size, uint4 n)
Definition: chert_table.h:250
bool operator>=(Key key2) const
Definition: chert_table.h:178
const uint8_t * p
Definition: chert_table.h:168
void read(std::string *key) const
Definition: chert_table.h:172
Item_wr(uint8_t *p_, int c)
Definition: chert_table.h:241
int TOTAL_FREE(const uint8_t *b)
Definition: chert_table.h:153
#define C(X)
uint4 last_readahead
Last block readahead_key() preread.
Definition: chert_table.h:864
void SET_TOTAL_FREE(uint8_t *b, int x)
Definition: chert_table.h:160
uint32_t unaligned_read4(const unsigned char *ptr)
Definition: wordaccess.h:151
Item(const uint8_t *p_)
Definition: chert_table.h:234
const uint8_t * get_address() const
Definition: chert_table.h:171
int compress_strategy
DONT_COMPRESS or Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE.
Definition: chert_table.h:852