NCBI C++ ToolKit
psg_cache_base.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: psg_cache_base.cpp 99744 2023-05-05 15:04:59Z saprykin $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Dmitri Dmitrienko
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include "psg_cache_base.hpp"
33 
34 #include <string>
35 
36 #include <sys/stat.h>
37 #include <util/lmdbxx/lmdb++.h>
38 
41  static const size_t kMapSizeInit = 256UL * 1024 * 1024 * 1024;
42  static const size_t kMapSizeDelta = 16UL * 1024 * 1024 * 1024;
43  static const size_t kMaxReaders = 1024UL;
44 END_SCOPE()
45 
47 
49  : m_FileName(file_name)
50 {
51  m_Env = make_unique<lmdb::env>(lmdb::env::create());
52 }
53 
55 {
57 }
58 
60 {
61  struct stat st;
62  int stat_rv = stat(m_FileName.c_str(), &st);
63  if (stat_rv < 0) {
64  lmdb::runtime_error::raise(strerror(errno), errno);
65  }
66 
67  auto mapsize = kMapSizeInit;
68  if (st.st_size + kMapSizeDelta > mapsize) {
69  mapsize = st.st_size + kMapSizeDelta;
70  }
71 
72  m_Env->set_max_dbs(kLmdbMaxDbCount);
73  m_Env->set_max_readers(kMaxReaders);
74  m_Env->set_mapsize(mapsize);
76 }
77 
#define static
#define END_IDBLOB_SCOPE
Definition: IdCassScope.hpp:40
#define BEGIN_IDBLOB_SCOPE
Definition: IdCassScope.hpp:39
unique_ptr< lmdb::env > m_Env
CLMDBReadOnlyTxn BeginReadTxn()
static env create(const unsigned int flags=default_flags)
Creates a new LMDB environment.
Definition: lmdb++.h:1108
static void raise(const char *origin, int rc)
Throws an error based on the given LMDB return code.
Definition: lmdb++.h:211
static txn begin(MDB_env *const env, MDB_txn *const parent=nullptr, const unsigned int flags=default_flags)
Creates a new LMDB transaction.
Definition: lmdb++.h:1277
const char * file_name[]
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define MDB_NOMETASYNC
don't fsync metapage after commit
Definition: lmdb.h:293
#define MDB_NOSYNC
don't fsync after commit
Definition: lmdb.h:289
#define MDB_NOSUBDIR
no environment directory
Definition: lmdb.h:287
#define MDB_RDONLY
read only
Definition: lmdb.h:291
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
Definition: lmdb.h:241
char * strerror(int n)
Definition: pcregrep.c:835
static const size_t kMaxReaders
static const MDB_dbi kLmdbMaxDbCount
static const size_t kMapSizeDelta
static const size_t kMapSizeInit
#define const
Definition: zconf.h:232
Modified on Mon Jun 24 05:24:37 2024 by modify_doxy.py rev. 669887