NCBI C++ ToolKit
bdb_file.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef BDB_FILE_HPP__
2 #define BDB_FILE_HPP__
3 
4 /* $Id: bdb_file.hpp 77790 2017-05-08 13:31:07Z ivanov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Anatoliy Kuznetsov
30  *
31  * File Description: Berkeley DB File classes.
32  *
33  */
34 
35 /// @file bdb_file.hpp
36 /// BDB File management.
37 
38 #include <corelib/ncbistre.hpp>
39 #include <util/itransaction.hpp>
41 #include <db/bdb/bdb_types.hpp>
42 #include <stdio.h>
43 
44 
46 
47 /** @addtogroup BDB_Files
48  *
49  * @{
50  */
51 
52 
53 /// BDB Return codes
54 ///
55 
56 
63 };
64 
65 
66 class CBDB_Env;
67 class CBDB_Transaction;
68 
69 
70 /// Raw file class wraps up basic Berkeley DB operations.
71 ///
73 {
74 public:
75  static const char kDefaultDatabase[]; // = "_table"
76 
77  /// BDB file open mode
78  enum EOpenMode {
81  eCreate, //!< implies 'eReadWrite' too
82  eReadWriteCreate //!< read-write, create if it doesn't exist
83  };
84 
85  /// Berkeley DB database type
86  enum EDBType {
89  eHash
90  };
91 
92  /// BLOB read mode, controld data buffer reallocation when
93  /// there is not enough space in buffer
94  ///
95  enum EReallocMode {
97  eReallocForbidden
98  };
99 
100  /// Control key duplicates in Btree
103  eDuplicatesEnable
104  };
105 
108  eThrowOnError
109  };
110 
111  /// BerkeleyDB compaction methods and flags
112  enum ECompact {
113 
114  //< Do not attempt to free any pages from the underlying file
116 
117  //< Free only pages that already exist as free pages in the file
119 
120  //< Return all free pages to the file system after compaction
121  eCompactFreeAll
122  };
123 
124  /// typedef for raw buffer operations
126 
127 public:
128  CBDB_RawFile(EDuplicateKeys dup_keys = eDuplicatesDisable,
129  EDBType db_type = eBtree);
130  virtual ~CBDB_RawFile();
131 
132  /// Associate file with environment. Should be called before
133  /// file opening.
134  void SetEnv(CBDB_Env& env);
135 
136  /// Get pointer on file environment
137  /// Return NULL if no environment has been set
138  CBDB_Env* GetEnv() { return m_Env; }
139 
140  /// Open file with specified access mode
141  void Open(const string& filename,
142  EOpenMode open_mode,
143  bool support_dirty_read = false,
144  unsigned rec_len = 0);
145  /// Open file with specified filename and database name.
146  /// (Berkeley DB supports having several database tables in one file.)
147  void Open(const string& filename,
148  const string& database,
149  EOpenMode open_mode,
150  bool support_dirty_read = false,
151  unsigned rec_len = 0);
152  /// Attach class to external BerkeleyDB file instance.
153  /// Note: Should be already open.
154  void Attach(CBDB_RawFile& bdb_file);
155  /// Close file
156  void Close();
157  /// Reopen database file. (Should be already open).
158  void Reopen(EOpenMode open_mode,
159  bool support_dirty_read = false,
160  unsigned rec_len = 0);
161 
162  /// Remove the database specified by the filename and database arguments
163  void Remove(const string& filename, const string& database = kEmptyStr);
164  /// Empty the database. Return number of records removed.
165  unsigned int Truncate();
166  /// Workaround for truncate of large databases. Executes out of transaction,
167  /// and as such cannot be rolled back/
168  unsigned int SafeTruncate();
169  /// Rename a database. NOTE: This cannot be called on an opened file.
170  void Rename(const string& fname,
171  const string& old_name,
172  const string& new_name);
173 
174  /// Compact the database. The target fill percent per page can be
175  /// supplied, to allow for known expansion
176  void Compact(ECompact compact_type = eCompactNoFree,
177  int target_fill_pct = 0);
178 
179  /// Extended version of compact
180  /// This version performs iterative compacting and uses a callback
181  /// to request an exit
182  typedef bool (*FContinueCompact)(void);
183  void CompactEx(FContinueCompact compact_callback,
184  ECompact compact_type = eCompactNoFree,
185  int target_fill_pct = 0);
186 
187  // Set Berkeley DB page size value. By default OS default is used.
188  void SetPageSize(unsigned int page_size);
189 
190  // Get Berkeley DB page size value. By default OS default is used.
191  unsigned int GetPageSize();
192 
193  /// Set Berkeley DB memory cache size for the file (default is 256K).
194  void SetCacheSize(unsigned int cache_size);
195 
196  /// Turn OFF reverse splitting
197  void RevSplitOff();
198 
199  /// Disable BTREE comparison override
200  void DisableCmpOverride() { m_CmpOverride = false; }
201 
202  /// Set the priority for this database's pages in the buffer cache
203  /// This is generally a temporary advisement, and works only if an
204  /// environment is used.
210  eCache_Highest
211  };
212  void SetCachePriority(ECachePriority priority);
213 
214  const string& FileName() const;
215  const string& Database() const;
216 
217  /// Set comparison function. Default implementation installs bdb_types based
218  /// function. Can be overloaded for some specific cases.
219  virtual void SetCmp(DB*) = 0;
220 
221  /// Set hash function. Default implementation installs bdb_types based
222  /// function. Can be overloaded for some specific cases.
223  virtual void SetHash(DB*);
224 
225  /// Return TRUE if the file is open
226  bool IsOpen() const;
227 
228  // Return TRUE if the file is attached to some other BDB file
229  bool IsAttached() const;
230 
231  /// Return TRUE if the if the underlying database files were created
232  /// on an architecture of the different byte order
233  bool IsByteSwapped() const { return m_ByteSwapped; }
234 
235  /// Return TRUE if file can contain duplicate keys
236  bool DuplicatesAllowed() const { return m_DuplicateKeys == eDuplicatesEnable; }
237 
238  /// Return the key duplicate mode value
239  EDuplicateKeys GetDupKeysMode() const { return m_DuplicateKeys; }
240 
241  /// Return file name
242  const string& GetFileName() const { return m_FileName; }
243 
244  /// Return the file open mode
245  EOpenMode GetOpenMode() const { return m_OpenMode; }
246 
247  /// Flush any cached information to disk
248  void Sync();
249 
250  /// Compute database statistic, return number of records.
251  /// (Can be time consuming)
252  unsigned CountRecs(bool bFast = false);
253 
254  /// Print database statistics
255  void PrintStat(CNcbiOstream & out);
256 
257  // ITransactional:
258 
259  virtual void SetTransaction(ITransaction* trans);
260  virtual void RemoveTransaction(ITransaction* trans);
261  virtual ITransaction* GetTransaction();
262 
263  /// Get current transaction
264  CBDB_Transaction* GetBDBTransaction() { return m_Trans; }
265 
266  /// Get record length
267  /// Works for fixed length record DBs only (Queue)
268  unsigned GetRecLen() const;
269 
270  /// Set hash table density (fill factor)
271  void SetHashFillFactor(unsigned h_ffactor);
272 
273  /// Set an estimate of hash table final size
274  void SetHashNelem(unsigned h_nelem);
275 
276  /// Disable hash method override
277  /// (Berkeley DB will use it's own default hashing method)
278  void DisableHashOverride() { m_CmpOverride = false; }
279 
280  /// Set the minimum number of keys per page (BTREE access methods only)
281  void SetBtreeMinKeysPerPage(unsigned int keys_per_page);
282  unsigned int GetBtreeMinKeysPerPage();
283 
284 
285  /// Set record compressor
286  ///
287  /// Record compression should only be used if we do not
288  /// use partial record storage and retrieval.
289  ///
290  void SetCompressor(ICompression* compressor,
291  EOwnership own = eTakeOwnership);
292 
293 private:
294  /// forbidden
296  CBDB_RawFile& operator= (const CBDB_RawFile&);
297 
298 protected:
299  void x_Open(const char* filename, const char* database,
300  EOpenMode open_mode,
301  bool support_dirty_read,
302  unsigned rec_len);
303  void x_Create(const char* filename, const char* database);
304 
305  void x_Close(EIgnoreError close_mode);
306 
307  /// Create m_DB member, set page, cache parameters
308  ///
309  /// @param rec_len
310  /// record length (must be non zero for Queue type)
311  void x_CreateDB(unsigned rec_len);
312 
313 
314  /// Set current transaction
315  void x_SetTransaction(CBDB_Transaction* trans);
316 
317  void x_RemoveTransaction(CBDB_Transaction* trans);
318 
319  /// Get transaction handler.
320  ///
321  /// Function returns NULL if no transaction has been set.
322  ///
323  /// @sa SetTransaction
324  DB_TXN* GetTxn();
325 
326  /// Create DB cursor
327  DBC* CreateCursor(CBDB_Transaction* trans = 0,
328  unsigned int flags = 0) const;
329 
330 
331  /// Internal override for DB->get(...)
332  /// This method overrides destination buffer and uses compressor:
333  /// Should only be used with DB_DBT_USERMEM flag.
334  ///
335  int x_DB_Fetch(DBT *key,
336  DBT *data,
337  unsigned flags);
338 
339 
340  /// Internal override for DBC->c_get(...)
341  /// This method overrides destination buffer and uses compressor:
342  /// Should only be used with DB_DBT_USERMEM flag.
343  ///
344  int x_DBC_Fetch(DBC* dbc,
345  DBT *key,
346  DBT *data,
347  unsigned flags);
348 
349  /// Override for DB->put(...)
350  /// Handles compression.
351  ///
352  int x_DB_Put(DBT *key,
353  DBT *data,
354  unsigned flags);
355 
356  /// Override for DBC->c_put(...)
357  /// Handles compression.
358  ///
359  int x_DB_CPut(DBC* dbc,
360  DBT *key,
361  DBT *data,
362  unsigned flags);
363 
364 
365  int x_FetchBufferDecompress(DBT *data, void* usr_data);
366 
367  /// Set byte order swapping. Can be overloaded on derived classes
368  /// @note When overloading DO call parent::x_SetByteSwapped
369  virtual void x_SetByteSwapped(bool bswp);
370 
371 
372 protected:
380  unsigned m_RecLen;
381  unsigned m_H_ffactor;
382  unsigned m_H_nelem;
383  unsigned m_BT_minkey;
384 
385  AutoPtr<ICompression> m_Compressor; ///< Record compressor
387 
388 private:
389  bool m_DB_Attached; //!< TRUE if m_DB doesn't belong here
390  bool m_ByteSwapped; //!< TRUE if file created on a diff.arch.
391  bool m_RevSplitOff; //!< TRUE if reverse splitting is off
392  bool m_CmpOverride; //!< TRUE - NCBI BDB sets its own cmp
393  string m_FileName; //!< filename
394  string m_Database; //!< db name in file (optional)
395  unsigned m_PageSize;
396  unsigned m_CacheSize;
399 
400  static const int kOpenFileMask;
401 
402  friend class CBDB_FileCursor;
403 };
404 
405 
406 /// Multirow buffer for reading many rows in one call
407 ///
408 
410 {
411 public:
412  CBDB_MultiRowBuffer(size_t buf_size);
414 
415  /// Get data buffer pointer from last cursor read
416  const void* GetLastDataPtr() const { return m_LastData; }
417  /// Get BLOB length from last cursor read
418  size_t GetLastDataLen() const { return m_LastDataLen; }
419 protected:
420  void InitDBT();
421  void MultipleInit();
422 private:
425 protected:
426  DBT* m_Data_DBT; ///< Temp DBT for multiple fetch
427  void* m_Buf; ///< Multiple row buffer
428  size_t m_BufSize; ///< buffer size
429  void* m_BufPtr; ///< current buffer position
430  void* m_LastKey; ///< Last key pointer returned by DB_MULTIPLE_KEY_NEXT
431  void* m_LastData; ///< Last data pointer returned by DB_MULTIPLE_KEY_NEXT
432  size_t m_LastKeyLen;
434 
435 friend class CBDB_File;
436 };
437 
438 
439 
440 /// Berkeley DB file class.
441 /// Implements primary key and fields functionality.
442 ///
443 
445 {
446 public:
447  CBDB_File(EDuplicateKeys dup_keys = eDuplicatesDisable,
448  EDBType db_type = eBtree);
449 
450  /// Open file with specified access mode
451  void Open(const string& filename,
452  EOpenMode open_mode,
453  bool support_dirty_read = false,
454  unsigned rec_len = 0);
455 
456  /// Open file with specified filename and database name.
457  /// (Berkeley DB supports having several database tables in one file.)
458  void Open(const string& filename,
459  const string& database,
460  EOpenMode open_mode,
461  bool support_dirty_read = false,
462  unsigned rec_len = 0);
463  /// Reopen the db file
464  void Reopen(EOpenMode open_mode, bool support_dirty_read = false);
465 
466  /// Attach external Berkeley DB file.
467  /// Note: Should be already open.
468  void Attach(CBDB_File& db_file);
469 
470  /// Fetches the record corresponding to the current key value.
471  EBDB_ErrCode Fetch() { return x_Fetch(0); }
472 
473  /// Fetche the record corresponding to the current key value.
474  /// Acquire write lock instead of read lock when doing the retrieval.
475  /// Meaningful only in the presence of transactions.
476  EBDB_ErrCode FetchForUpdate();
477 
478  enum EAfterWrite {
479  eKeepData, //!< Keep the inserted data for a while
480  eDiscardData //!< Invalidate the inserted data immediately after write
481  };
482 
483  /// Insert new record
484  EBDB_ErrCode Insert(EAfterWrite write_flag = eDiscardData);
485 
486  /// Append record to the queue
487  /// (works only for DB_QUEUE database type)
488  ///
489  /// @return record number (auto increment)
490  unsigned Append(EAfterWrite write_flag = eDiscardData);
491 
492  /// Delete record corresponding to the current key value.
493  EBDB_ErrCode Delete(EIgnoreError on_error=eThrowOnError);
494 
495  /// Update record corresponding to the current key value. If record does not exist
496  /// it will be inserted.
497  EBDB_ErrCode UpdateInsert(EAfterWrite write_flag = eDiscardData);
498 
499 
500  void BindKey (const char* field_name,
501  CBDB_Field* key_field,
502  size_t buf_size = 0);
503 
504  void BindData(const char* field_name,
505  CBDB_Field* data_field,
506  size_t buf_size = 0,
507  ENullable is_null = eNullable);
508 
509  /// Create the same fieldset as in dbf and bind them to the current file
510  void DuplicateStructure(const CBDB_File& dbf);
511 
512  /// Get Buffer manager for key section of the file
513  const CBDB_BufferManager* GetKeyBuffer() const { return m_KeyBuf.get(); }
514 
515  /// Get Buffer manager for data section of the file
516  const CBDB_BufferManager* GetDataBuffer() const { return m_DataBuf.get(); }
517 
518  /// Get Buffer manager for key section of the file
519  CBDB_BufferManager* GetKeyBuffer() { return m_KeyBuf.get(); }
520 
521  /// Get Buffer manager for data section of the file
522  CBDB_BufferManager* GetDataBuffer() { return m_DataBuf.get(); }
523 
524  /// Sets maximum number of key fields participating in comparison
525  /// Should be less than total number of key fields
526  void SetFieldCompareLimit(unsigned int n_fields);
527 
528  /// Create new copy of m_DBT_Key.
529  /// Caller is responsible for proper deletion. See also: DestroyDBT_Clone
530  DBT* CloneDBT_Key();
531 
532  /// Free the DBT structure created by CloneDBT_Key.
533  static void DestroyDBT_Clone(DBT* dbt);
534 
535  /// Set C-str detection
536  void SetLegacyStringsCheck(bool value);
537 
538  /// CBDB_File keeps data in two buffers (key buffer and data buffer).
539  /// TUnifiedFieldIndex is used to address fields in a non-ambigiuos manner.
540  /// Negative index addresses fields in the key buffer, positive - data buffer
541  /// Numbers are 1 based, 0 - means non-existing field
542  typedef int TUnifiedFieldIndex;
543 
544  /// Get field index by name.
545  /// @param
546  /// name field name to find (case insensitive)
547  /// @return
548  /// Field index (0 if not found)
549  /// @sa TUnifiedFieldIndex
550  TUnifiedFieldIndex GetFieldIdx(const string& name) const;
551 
552  /// Return field by field index
553  /// @param
554  /// idx field index
555  /// @return field reference
556  const CBDB_Field& GetField(TUnifiedFieldIndex idx) const;
557  CBDB_Field& GetField(TUnifiedFieldIndex idx);
558 
559  /// Fields deletion is managed by the class when own_fields is TRUE
560  void SetFieldOwnership(bool own_fields);
561 
562  /// Return fields ownership flag
563  bool IsOwnFields() const { return m_OwnFields; }
564 
565  /// Copy record (fields) from another BDB file
566  /// (MUST have the same structure)
567  void CopyFrom(const CBDB_File& dbf);
568 
569  /// Run database verification (DB->verify)
570  void Verify(const char* filename, const char* database, FILE* backup);
571 
572  /// Turn ON prefix compression.
573  /// Should be turned on for string based keys. (not LString)
574  void EnablePrefixCompression() { m_PrefixCompress = true; }
575 
576 protected:
577  /// Unpack internal record buffers
578  void Discard();
579 
580  /// Set comparison function. Default implementation installs bdb_types based
581  /// function. Can be overloaded for some specific cases.
582  virtual void SetCmp(DB*);
583 
584  /// Read DB cursor
585  EBDB_ErrCode ReadCursor(DBC* dbc, unsigned int bdb_flag);
586 
587  /// Read DB cursor (BLOB)
588  EBDB_ErrCode ReadCursor(DBC* dbc, unsigned int bdb_flag,
589  void** buf,
590  size_t buf_size,
591  EReallocMode allow_realloc);
592  /// Read DB cursor (BLOB)
593  EBDB_ErrCode ReadCursor(DBC* dbc, unsigned int bdb_flag,
594  TBuffer* buf);
595 
596 
597  /// Multiple-row read into a buffer
598  /// Buffer is to be traversed using DB_MULTIPLE_KEY_NEXT (BerkeleyDB)
599  ///
600  /// @param multirow_only
601  /// Fetch only in multirow buffer, method returns eBDB_MultiRowEnd
602  /// when the buffer is over
603  EBDB_ErrCode ReadCursor(DBC* dbc,
604  unsigned int bdb_flag,
605  CBDB_MultiRowBuffer* multirow_buf,
606  bool multirow_only);
607 
608 
609  /// Write DB cursor
610  EBDB_ErrCode WriteCursor(DBC* dbc, unsigned int bdb_flag,
611  EAfterWrite write_flag);
612 
613  /// Write BLOB to DB cursor
614  EBDB_ErrCode WriteCursor(const void* data,
615  size_t size,
616  DBC* dbc, unsigned int bdb_flag,
617  EAfterWrite write_flag);
618 
619  /// Delete DB cursor
620  EBDB_ErrCode DeleteCursor(DBC* dbc, EIgnoreError);
621 
622  /// Check if all NOT NULL fields are assigned.
623  /// Throw an exception if constraint check failed.
624  void CheckNullDataConstraint() const;
625 
626  /// Function disables processing of m_DBT_data.
627  /// This function can be used when creating custom BDB file
628  /// data structures (BLOB storage, etc.) Caller takes full
629  /// responsibility for filling m_DBT_Data with correct values.
630  void DisableDataBufProcessing() { m_DataBufDisabled = true; }
631 
632  /// Disable NULL/not NULL in data fields
633  /// (Performance tweak, call before BindData)
634  void DisableNull() { m_DisabledNull = true; }
635 
636  /// Disable packing of variable length fields in the data buffer
637  /// (Call after BindData)
638  void DisableDataPacking();
639 
640  /// Wrapper around get operation.
641  EBDB_ErrCode x_Fetch(unsigned int flags);
642 
643  virtual void x_SetByteSwapped(bool bswp);
644 
645 private:
646  /// forbidden
648  CBDB_File& operator= (const CBDB_File&);
649 
650  /// Record reading prolog function
651  void x_StartRead();
652  /// Record reading epilog function
653  void x_EndRead();
654 
655  EBDB_ErrCode x_Write(unsigned int flags, EAfterWrite write_flag,
656  DBC * dbc = 0);
657 
658  void x_CheckConstructBuffers();
659 
660  void x_ConstructKeyBuf();
661  void x_ConstructDataBuf();
662 
663  static int x_CompareShim(DB* db, const DBT* dbt1, const DBT* dbt2,
664  size_t* locp);
665 
666 private:
667  unique_ptr<CBDB_BufferManager> m_KeyBuf;
668  unique_ptr<CBDB_BufferManager> m_DataBuf;
675  bool m_PrefixCompress; //!< TRUE if prefix compression ON
676 
677  friend class CBDB_FileCursor;
678 };
679 
680 
681 
682 /// Berkeley DB file class optimized to work with
683 /// tables having int as the primary key.
684 ///
685 
687 {
688 public:
690 
691 public:
692  CBDB_IdFile();
693  virtual void SetCmp(DB* db);
694 };
695 
696 
697 
698 /* @} */
699 
700 
701 /////////////////////////////////////////////////////////////////////////////
702 // IMPLEMENTATION of INLINE functions
703 /////////////////////////////////////////////////////////////////////////////
704 
705 
706 /// Make field index in CBDB_File format
707 ///
708 /// @internal
709 inline
711 {
712  _ASSERT(fidx >= 0);
713  ++fidx;
714  return key ? (-fidx) : (fidx);
715 }
716 
717 
718 /////////////////////////////////////////////////////////////////////////////
719 // CBDB_RawFile::
720 //
721 
722 
723 inline
725  const string& filename, EOpenMode open_mode,
726  bool support_dirty_read,
727  unsigned rec_len)
728 {
729  Open(filename, kEmptyStr, open_mode, support_dirty_read, rec_len);
730 }
731 
732 inline
733 unsigned CBDB_RawFile::GetRecLen() const
734 {
736  return m_RecLen;
737 }
738 
739 inline
740 const string& CBDB_RawFile::FileName() const
741 {
742  return m_FileName;
743 }
744 
745 
746 inline
747 const string& CBDB_RawFile::Database() const
748 {
749  return m_Database;
750 }
751 
752 
753 inline
755 {
756  return !m_FileName.empty();
757 }
758 
759 inline
761 {
762  return m_DB_Attached;
763 }
764 
765 
766 /////////////////////////////////////////////////////////////////////////////
767 //
768 // CBDB_File::
769 //
770 
771 
772 
773 inline
775  const string& filename, EOpenMode open_mode,
776  bool support_dirty_read, unsigned rec_len)
777 {
778  Open(filename, "", open_mode, support_dirty_read, rec_len);
779 }
780 
781 
782 inline
784 {
785  if ( !m_DisabledNull && m_DataBuf.get() )
786  m_DataBuf->CheckNullConstraint();
787 }
788 
789 inline
790 void CBDB_File::SetFieldCompareLimit(unsigned int n_fields)
791 {
792  m_KeyBuf->SetFieldCompareLimit(n_fields);
793 }
794 
795 
797 
798 #endif
struct __dbc DBC
Definition: bdb_types.hpp:53
struct __db DB
Definition: bdb_types.hpp:52
struct __db_txn DB_TXN
Definition: bdb_types.hpp:55
struct __db_dbt DBT
Definition: bdb_types.hpp:51
BDB Data Field Buffer manager class.
Definition: bdb_types.hpp:1768
BDB environment object a collection including support for some or all of caching, locking,...
Definition: bdb_env.hpp:61
Int4 field type.
Definition: bdb_types.hpp:827
Base class for constructing BDB fields.
Definition: bdb_types.hpp:297
Berkeley DB file cursor class.
Definition: bdb_cursor.hpp:95
Berkeley DB file class.
Definition: bdb_file.hpp:445
Berkeley DB file class optimized to work with tables having int as the primary key.
Definition: bdb_file.hpp:687
Multirow buffer for reading many rows in one call.
Definition: bdb_file.hpp:410
Raw file class wraps up basic Berkeley DB operations.
Definition: bdb_file.hpp:73
BDB transaction object.
Definition: bdb_trans.hpp:63
Reallocable memory buffer (no memory copy overhead) Mimics vector<>, without the overhead of explicit...
Transaction interface.
Interface for transactional objects.
static uch flags
std::ofstream out("events_result.xml")
main entry point for tests
#define bool
Definition: bool.h:34
static HENV env
Definition: transaction2.c:38
static HDBC dbc
Definition: transaction2.c:39
char data[12]
Definition: iconv.c:80
ENullable
Whether a value is nullable.
Definition: ncbimisc.hpp:113
@ eNullable
Value can be null.
Definition: ncbimisc.hpp:114
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
string m_Database
db name in file (optional)
Definition: bdb_file.hpp:394
EOpenMode m_OpenMode
Definition: bdb_file.hpp:398
EDuplicateKeys GetDupKeysMode() const
Return the key duplicate mode value.
Definition: bdb_file.hpp:239
bool m_DataBufDisabled
Definition: bdb_file.hpp:671
CBDB_Env * m_Env
Definition: bdb_file.hpp:377
CBDB_MultiRowBuffer(const CBDB_MultiRowBuffer &)
unsigned m_CacheSize
Definition: bdb_file.hpp:396
size_t GetLastDataLen() const
Get BLOB length from last cursor read.
Definition: bdb_file.hpp:418
CBDB_Transaction * m_Trans
Definition: bdb_file.hpp:378
CBDB_MultiRowBuffer & operator=(const CBDB_MultiRowBuffer &)
CBDB_FieldInt4 IdKey
Definition: bdb_file.hpp:689
bool m_BufsCreated
Definition: bdb_file.hpp:670
unsigned m_PageSize
Definition: bdb_file.hpp:395
bool m_LegacyString
Definition: bdb_file.hpp:672
size_t m_BufSize
buffer size
Definition: bdb_file.hpp:428
void * m_LastData
Last data pointer returned by DB_MULTIPLE_KEY_NEXT.
Definition: bdb_file.hpp:431
unsigned m_H_ffactor
Definition: bdb_file.hpp:381
AutoPtr< ICompression > m_Compressor
Record compressor.
Definition: bdb_file.hpp:385
bool IsOpen() const
Return TRUE if the file is open.
Definition: bdb_file.hpp:754
virtual void SetCmp(DB *)=0
Set comparison function.
ECompact
BerkeleyDB compaction methods and flags.
Definition: bdb_file.hpp:112
DBT * m_Data_DBT
Temp DBT for multiple fetch.
Definition: bdb_file.hpp:426
void DisableHashOverride()
Disable hash method override (Berkeley DB will use it's own default hashing method)
Definition: bdb_file.hpp:278
bool m_OwnFields
Definition: bdb_file.hpp:673
EOpenMode
BDB file open mode.
Definition: bdb_file.hpp:78
EDBType m_DB_Type
Definition: bdb_file.hpp:373
void * m_Buf
Multiple row buffer.
Definition: bdb_file.hpp:427
bool IsByteSwapped() const
Return TRUE if the if the underlying database files were created on an architecture of the different ...
Definition: bdb_file.hpp:233
void Open(const string &filename, EOpenMode open_mode, bool support_dirty_read=false, unsigned rec_len=0)
Open file with specified access mode.
Definition: bdb_file.hpp:774
void DisableCmpOverride()
Disable BTREE comparison override.
Definition: bdb_file.hpp:200
unsigned m_RecLen
Definition: bdb_file.hpp:380
const string & Database() const
Definition: bdb_file.hpp:747
CBDB_Transaction * GetBDBTransaction()
Get current transaction.
Definition: bdb_file.hpp:264
bool m_DisabledNull
Definition: bdb_file.hpp:674
void DisableDataBufProcessing()
Function disables processing of m_DBT_data.
Definition: bdb_file.hpp:630
CBDB_File::TUnifiedFieldIndex BDB_GetUFieldIdx(int fidx, bool key)
Make field index in CBDB_File format.
Definition: bdb_file.hpp:710
bool IsOwnFields() const
Return fields ownership flag.
Definition: bdb_file.hpp:563
CBDB_RawFile(const CBDB_RawFile &)
forbidden
bool m_CmpOverride
TRUE - NCBI BDB sets its own cmp.
Definition: bdb_file.hpp:392
unique_ptr< CBDB_BufferManager > m_DataBuf
Definition: bdb_file.hpp:668
bool m_RevSplitOff
TRUE if reverse splitting is off.
Definition: bdb_file.hpp:391
EDBType
Berkeley DB database type.
Definition: bdb_file.hpp:86
EDuplicateKeys m_DuplicateKeys
Definition: bdb_file.hpp:397
string m_FileName
filename
Definition: bdb_file.hpp:393
void SetFieldCompareLimit(unsigned int n_fields)
Sets maximum number of key fields participating in comparison Should be less than total number of key...
Definition: bdb_file.hpp:790
CBDB_Env * GetEnv()
Get pointer on file environment Return NULL if no environment has been set.
Definition: bdb_file.hpp:138
const string & GetFileName() const
Return file name.
Definition: bdb_file.hpp:242
unsigned m_BT_minkey
Definition: bdb_file.hpp:383
void * m_LastKey
Last key pointer returned by DB_MULTIPLE_KEY_NEXT.
Definition: bdb_file.hpp:430
bool m_BufsAttached
Definition: bdb_file.hpp:669
unsigned m_H_nelem
Definition: bdb_file.hpp:382
int TUnifiedFieldIndex
CBDB_File keeps data in two buffers (key buffer and data buffer).
Definition: bdb_file.hpp:542
int m_TransAssociation
Definition: bdb_file.hpp:379
CBDB_BufferManager * GetKeyBuffer()
Get Buffer manager for key section of the file.
Definition: bdb_file.hpp:519
EDuplicateKeys
Control key duplicates in Btree.
Definition: bdb_file.hpp:101
void DisableNull()
Disable NULL/not NULL in data fields (Performance tweak, call before BindData)
Definition: bdb_file.hpp:634
EOpenMode GetOpenMode() const
Return the file open mode.
Definition: bdb_file.hpp:245
CSimpleBuffer TBuffer
typedef for raw buffer operations
Definition: bdb_file.hpp:125
static int x_CompareShim(DB *db, const DBT *dbt1, const DBT *dbt2, size_t *locp)
bool m_ByteSwapped
TRUE if file created on a diff.arch.
Definition: bdb_file.hpp:390
EReallocMode
BLOB read mode, controld data buffer reallocation when there is not enough space in buffer.
Definition: bdb_file.hpp:95
const CBDB_BufferManager * GetKeyBuffer() const
Get Buffer manager for key section of the file.
Definition: bdb_file.hpp:513
TBuffer m_CompressBuffer
Definition: bdb_file.hpp:386
void EnablePrefixCompression()
Turn ON prefix compression.
Definition: bdb_file.hpp:574
ECachePriority
Set the priority for this database's pages in the buffer cache This is generally a temporary adviseme...
Definition: bdb_file.hpp:205
void Open(const string &filename, EOpenMode open_mode, bool support_dirty_read=false, unsigned rec_len=0)
Open file with specified access mode.
Definition: bdb_file.hpp:724
const void * GetLastDataPtr() const
Get data buffer pointer from last cursor read.
Definition: bdb_file.hpp:416
static const int kOpenFileMask
Definition: bdb_file.hpp:400
const string & FileName() const
Definition: bdb_file.hpp:740
EBDB_ErrCode
BDB Return codes.
Definition: bdb_file.hpp:57
const CBDB_BufferManager * GetDataBuffer() const
Get Buffer manager for data section of the file.
Definition: bdb_file.hpp:516
void * m_BufPtr
current buffer position
Definition: bdb_file.hpp:429
CBDB_BufferManager * GetDataBuffer()
Get Buffer manager for data section of the file.
Definition: bdb_file.hpp:522
void CheckNullDataConstraint() const
Check if all NOT NULL fields are assigned.
Definition: bdb_file.hpp:783
bool m_PrefixCompress
TRUE if prefix compression ON.
Definition: bdb_file.hpp:675
unique_ptr< CBDB_BufferManager > m_KeyBuf
Definition: bdb_file.hpp:667
bool DuplicatesAllowed() const
Return TRUE if file can contain duplicate keys.
Definition: bdb_file.hpp:236
DBT * m_DBT_Key
Definition: bdb_file.hpp:375
unsigned GetRecLen() const
Get record length Works for fixed length record DBs only (Queue)
Definition: bdb_file.hpp:733
CBDB_File(const CBDB_File &)
forbidden
bool m_DB_Attached
TRUE if m_DB doesn't belong here.
Definition: bdb_file.hpp:389
DBT * m_DBT_Data
Definition: bdb_file.hpp:376
bool IsAttached() const
Definition: bdb_file.hpp:760
EBDB_ErrCode Fetch()
Fetches the record corresponding to the current key value.
Definition: bdb_file.hpp:471
@ eKeepData
Keep the inserted data for a while.
Definition: bdb_file.hpp:479
@ eCompactFreeExisting
Definition: bdb_file.hpp:118
@ eCreate
implies 'eReadWrite' too
Definition: bdb_file.hpp:81
@ eDuplicatesDisable
Definition: bdb_file.hpp:102
@ eBDB_MultiRowEnd
Definition: bdb_file.hpp:62
@ eBDB_KeyDup
Definition: bdb_file.hpp:60
@ eBDB_Ok
Definition: bdb_file.hpp:58
@ eBDB_KeyEmpty
Definition: bdb_file.hpp:61
@ eBDB_NotFound
Definition: bdb_file.hpp:59
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
CTime Truncate(const CTime &t)
Definition: ncbitime.hpp:2194
virtual void SetTransaction(ITransaction *trans)=0
Establish transaction association.
virtual ITransaction * GetTransaction()=0
Get current transaction.
virtual void RemoveTransaction(ITransaction *trans)=0
Remove transaction association (must be established by SetTransaction.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
#define NCBI_BDB_EXPORT
Definition: ncbi_export.h:272
use only n Cassandra database for the lookups</td > n</tr > n< tr > n< td > yes</td > n< td > do not use tables BIOSEQ_INFO and BLOB_PROP in the Cassandra database
char * buf
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
static void x_Close(SHttpConnector *uuu)
static SERV_ITER x_Open(const char *service, int ismask, TSERV_Type types, unsigned int preferred_host, unsigned short preferred_port, double preference, const SConnNetInfo *net_info, SSERV_InfoCPtr skip[], size_t n_skip, int external, const char *arg, const char *val, SSERV_Info **info, HOST_INFO *host_info)
Definition: ncbi_service.c:253
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
#define _ASSERT
@ eHash
Hash Index.
Modified on Fri Sep 20 14:57:39 2024 by modify_doxy.py rev. 669887