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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS__PUBSEQ_GATEWAY__CACHE__PSG_CACHE_HPP_
2 #define OBJTOOLS__PUBSEQ_GATEWAY__CACHE__PSG_CACHE_HPP_
3 
4 /* $Id: psg_cache.hpp 99744 2023-05-05 15:04:59Z saprykin $
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  * Authors: Dmitri Dmitrienko
30  *
31  * File Description: PSG LMDB-based cache
32  *
33  */
34 
35 #include <corelib/ncbistd.hpp>
36 
37 #include <deque>
38 #include <memory>
39 #include <set>
40 #include <string>
41 #include <vector>
42 
48 
51 
55 
57 {
58  struct SRuntimeError {
59  explicit SRuntimeError(const string& msg)
60  : message(msg)
61  {}
62  string message;
63  };
64 
66 
67  public:
69  using TRuntimeErrorList = deque<SRuntimeError>;
70 
71  using TBioseqInfoResponse = vector<CBioseqInfoRecord>;
73 
74  using TBlobPropResponse = vector<CBlobRecord>;
76 
77  using TSi2CsiResponse = vector<CSI2CSIRecord>;
79 
80  static const size_t kRuntimeErrorLimit;
81 
83  const string& bioseq_info_file_name, const string& si2csi_file_name, const string& blob_prop_file_name);
84  virtual ~CPubseqGatewayCache();
85 
86  void Open(const set<int>& sat_ids);
87 
88  void ResetErrors();
90  {
91  return m_RuntimeErrors;
92  }
93 
100 
101  static string PackBioseqInfoKey(const string& accession, int version);
102  static string PackBioseqInfoKey(const string& accession, int version, int seq_id_type);
103  static string PackBioseqInfoKey(const string& accession, int version, int seq_id_type, int64_t gi);
104  static bool UnpackBioseqInfoKey(const char* key, size_t key_sz, int& version, int& seq_id_type, int64_t& gi);
105  static bool UnpackBioseqInfoKey(
106  const char* key, size_t key_sz, string& accession, int& version, int& seq_id_type, int64_t& gi);
107 
108  static string PackSiKey(const string& sec_seqid, int sec_seq_id_type);
109  static bool UnpackSiKey(const char* key, size_t key_sz, int& sec_seq_id_type);
110  static bool UnpackSiKey(const char* key, size_t key_sz, string& sec_seq_id, int& sec_seq_id_type);
111 
112  static string PackBlobPropKey(int32_t sat_key);
113  static string PackBlobPropKey(int32_t sat_key, int64_t last_modified);
114  static bool UnpackBlobPropKey(const char* key, size_t key_sz, int64_t& last_modified);
115  static bool UnpackBlobPropKey(const char* key, size_t key_sz, int64_t& last_modified, int32_t& sat_key);
116 
118 
119  private:
121  string m_Si2CsiPath;
123  unique_ptr<CPubseqGatewayCacheBioseqInfo> m_BioseqInfoCache;
124  unique_ptr<CPubseqGatewayCacheSi2Csi> m_Si2CsiCache;
125  unique_ptr<CPubseqGatewayCacheBlobProp> m_BlobPropCache;
127 };
128 
130 
131 #endif // OBJTOOLS__PUBSEQ_GATEWAY__CACHE__PSG_CACHE_HPP_
#define END_IDBLOB_SCOPE
Definition: IdCassScope.hpp:40
#define BEGIN_IDBLOB_SCOPE
Definition: IdCassScope.hpp:39
deque< SRuntimeError > TRuntimeErrorList
Definition: psg_cache.hpp:69
TBioseqInfoResponse FetchBioseqInfo(TBioseqInfoRequest const &request)
Definition: psg_cache.cpp:162
TBioseqInfoResponse FetchBioseqInfoLast()
Definition: psg_cache.cpp:174
const TRuntimeErrorList & GetErrors() const
Definition: psg_cache.hpp:89
static bool UnpackBlobPropKey(const char *key, size_t key_sz, int64_t &last_modified)
Definition: psg_cache.cpp:281
unique_ptr< CPubseqGatewayCacheBlobProp > m_BlobPropCache
Definition: psg_cache.hpp:125
static bool UnpackSiKey(const char *key, size_t key_sz, int &sec_seq_id_type)
Definition: psg_cache.cpp:261
CBioseqInfoFetchRequest TBioseqInfoRequest
Definition: psg_cache.hpp:72
vector< CBlobRecord > TBlobPropResponse
Definition: psg_cache.hpp:74
TSi2CsiResponse FetchSi2CsiLast()
Definition: psg_cache.cpp:220
TBlobPropResponse FetchBlobPropLast(TBlobPropRequest const &request)
Definition: psg_cache.cpp:195
CPubseqGatewayCache(const string &bioseq_info_file_name, const string &si2csi_file_name, const string &blob_prop_file_name)
Definition: psg_cache.cpp:100
TRuntimeErrorList m_RuntimeErrors
Definition: psg_cache.hpp:126
vector< CBioseqInfoRecord > TBioseqInfoResponse
Definition: psg_cache.hpp:71
static string PackSiKey(const string &sec_seqid, int sec_seq_id_type)
Definition: psg_cache.cpp:256
void Open(const set< int > &sat_ids)
Definition: psg_cache.cpp:115
void EnumerateBlobProp(int32_t sat, TBlobPropEnumerateFn fn)
Definition: psg_cache.cpp:204
vector< CSI2CSIRecord > TSi2CsiResponse
Definition: psg_cache.hpp:77
virtual ~CPubseqGatewayCache()
Definition: psg_cache.cpp:111
static string PackBlobPropKey(int32_t sat_key)
Definition: psg_cache.cpp:271
function< bool(int32_t, int64_t)> TBlobPropEnumerateFn
Definition: psg_cache.hpp:65
unique_ptr< CPubseqGatewayCacheBioseqInfo > m_BioseqInfoCache
Definition: psg_cache.hpp:123
static bool UnpackBioseqInfoKey(const char *key, size_t key_sz, int &version, int &seq_id_type, int64_t &gi)
Definition: psg_cache.cpp:244
CBlobFetchRequest TBlobPropRequest
Definition: psg_cache.hpp:75
TSi2CsiResponse FetchSi2Csi(CSi2CsiFetchRequest const &request)
Definition: psg_cache.cpp:211
static string PackBioseqInfoKey(const string &accession, int version)
Definition: psg_cache.cpp:229
unique_ptr< CPubseqGatewayCacheSi2Csi > m_Si2CsiCache
Definition: psg_cache.hpp:124
TBlobPropResponse FetchBlobProp(TBlobPropRequest const &request)
Definition: psg_cache.cpp:186
static const size_t kRuntimeErrorLimit
Definition: psg_cache.hpp:80
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define bool
Definition: bool.h:34
Int4 int32_t
Int8 int64_t
static int version
Definition: mdb_load.c:29
const struct ncbi::grid::netcache::search::fields::KEY key
BEGIN_IDBLOB_SCOPE USING_NCBI_SCOPE
Definition: psg_cache.hpp:50
SRuntimeError(const string &msg)
Definition: psg_cache.hpp:59
Modified on Wed Apr 17 13:09:39 2024 by modify_doxy.py rev. 669887