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

Go to the SVN repository for this file.

1 #ifndef NETCACHE__NC_STORAGE__HPP
2 #define NETCACHE__NC_STORAGE__HPP
3 /* $Id: nc_storage.hpp 92088 2020-12-21 15:51:01Z gouriano $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Authors: Pavel Ivanov
29  */
30 
31 
32 #include "nc_utils.hpp"
33 #include "nc_db_info.hpp"
34 
35 
36 namespace intr = boost::intrusive;
37 
38 
40 
41 
42 class CNCBlobAccessor;
43 struct SNCStateStat;
44 class CNCPeerControl;
45 
46 
47 struct STimeTable_tag;
48 struct SKeyMap_tag;
49 
50 typedef intr::set_base_hook< intr::tag<STimeTable_tag>,
51  intr::optimize_size<true> > TTimeTableHook;
52 typedef intr::set_base_hook< intr::tag<SKeyMap_tag>,
53  intr::optimize_size<true> > TKeyMapHook;
54 
55 #define __NC_CACHEDATA_MONITOR 0
56 
58  public TKeyMapHook,
59  public SNCBlobSummary,
60  public CSrvRCUUser
61 {
62 public:
64  string key;
71 
72  SNCCacheData(void);
73  ~SNCCacheData(void);
74 
76  return ver_mgr;
77  }
78 
79 private:
81 
84 
85 #if __NC_CACHEDATA_MONITOR
86  void x_Register(void);
87  void x_Revoke(void);
88 #endif
89 
90  virtual void ExecuteRCU(void);
91  friend class CNCBlobVerManager;
92 };
93 
94 
95 /// Blob storage for NetCache
97 {
98 public:
99  static void GetBList(const string& mask, unique_ptr<TNCBufferType>& buffer,
100  SNCBlobFilter* filters, const string& sep);
101  static string FindBlob(Uint2 bucket, const string& mask, Uint8 cr_time_hi);
102 
103  static bool Initialize(bool do_reinit);
104  static void Finalize(void);
105 
106  static bool ReConfig(const CNcbiRegistry& new_reg, string& err_message);
107  static void WriteSetup(CSrvSocketTask& task);
108  static void WriteEnvInfo(CSrvSocketTask& task);
109  static void WriteBlobStat(CSrvSocketTask& task);
110  static void WriteBlobList(TNCBufferType& buffer, const CTempString& mask);
111  static void WriteDbInfo(TNCBufferType& sendBuff, const CTempString& mask);
112 
113  static bool IsCleanStart(void);
114  static bool NeedStopWrite(void);
115  static bool AcceptWritesFromPeers(void);
116  static void SetDraining(bool draining);
117  static bool IsDraining(void);
118  static void AbandonDB(void);
119  static bool IsAbandoned(void);
120 
121  static string PrintablePassword(const string& pass);
122  /// Acquire access to the blob identified by key, subkey and version
124  const string& key,
125  const string& password,
126  Uint2 time_bucket);
127  static Uint4 GetNewBlobId(void);
128 
129  /// Get number of files in the database
130  static size_t GetNDBFiles(void);
131  /// Get total size of database for the storage
132  static Int8 GetDBSize(void);
133  static Int8 GetDiskFree(void);
134  static Int8 GetAllowedDBSize(Int8 free_space);
135  static bool IsDBSizeAlert(void);
136  static void CheckDiskSpace(void);
137  static void MeasureDB(SNCStateStat& state);
138 
139  static int GetLatestBlobExpire(void);
140  static void GetFullBlobsList(Uint2 slot, TNCBlobSumList& blobs_lst, const CNCPeerControl* peer);
141  static Uint8 GetMaxSyncLogRecNo(void);
142  static void SaveMaxSyncLogRecNo(void);
143 
144  static string GetPurgeData(void);
145  static void SavePurgeData(void);
146 
147  static Uint8 GetMaxBlobSizeStore(void);
148 public:
149  // For internal use only
150 
151  /// Get meta information about blob with given coordinates.
152  ///
153  /// @return
154  /// TRUE if meta information exists in the database and was successfully
155  /// read. FALSE if database is corrupted.
156  static bool ReadBlobInfo(SNCBlobVerData* ver_data);
157  /// Write meta information about blob into the database.
158  static bool WriteBlobInfo(const string& blob_key,
159  SNCBlobVerData* ver_data,
160  SNCChunkMaps* maps,
161  Uint8 cnt_chunks,
162  SNCCacheData* cache_data);
163  /// Delete blob from database.
164  static void DeleteBlobInfo(const SNCBlobVerData* ver_data,
165  SNCChunkMaps* maps);
166 
167  static bool ReadChunkData(SNCBlobVerData* ver_data,
168  SNCChunkMaps* maps,
169  Uint8 chunk_num,
170  char*& buffer,
171  Uint4& buf_size);
172  static char* WriteChunkData(SNCBlobVerData* ver_data,
173  SNCChunkMaps* maps,
174  SNCCacheData* cache_data,
175  Uint8 chunk_num,
176  char* buffer,
177  Uint4 buf_size);
178 
179  static void ReferenceCacheData(SNCCacheData* cache_data);
180  static void ReleaseCacheData(SNCCacheData* cache_data);
181  static void ChangeCacheDeadTime(SNCCacheData* cache_data);
182 
183 private:
185 };
186 
187 
188 
189 //////////////////////////////////////////////////////////////////////////
190 // Inline functions
191 //////////////////////////////////////////////////////////////////////////
192 inline
194  : saved_dead_time(0),
195  time_bucket(0),
196  map_size(0),
197  chunk_size(0),
198  ver_mgr(NULL)
199 {
200 #if __NC_CACHEDATA_MONITOR
201  x_Register();
202 #endif
203 }
204 
205 inline
207 {
208 #ifdef _DEBUG
209  if (ver_mgr || !coord.empty() || ref_cnt.Get() != 0) {
210  abort();
211  }
212 #endif
213 #if __NC_CACHEDATA_MONITOR
214  x_Revoke();
215 #endif
216 }
217 
219 
220 #endif /* NETCACHE__NC_STORAGE__HPP */
ncbi::TMaskedQueryRegions mask
CAtomicCounter_WithAutoInit –.
Definition: ncbicntr.hpp:120
Mutex created to have minimum possible size (its size is 4 bytes) and to sleep using kernel capabilit...
Definition: srv_sync.hpp:193
Blob storage for NetCache.
Definition: nc_storage.hpp:97
CNCBlobStorage(void)
static void GetFullBlobsList(Uint2 slot, TNCBlobSumList &blobs_lst, const CNCPeerControl *peer)
static Int8 GetAllowedDBSize(Int8 free_space)
static bool NeedStopWrite(void)
static bool WriteBlobInfo(const string &blob_key, SNCBlobVerData *ver_data, SNCChunkMaps *maps, Uint8 cnt_chunks, SNCCacheData *cache_data)
Write meta information about blob into the database.
static void SaveMaxSyncLogRecNo(void)
static void ChangeCacheDeadTime(SNCCacheData *cache_data)
static void WriteBlobList(TNCBufferType &buffer, const CTempString &mask)
static void GetBList(const string &mask, unique_ptr< TNCBufferType > &buffer, SNCBlobFilter *filters, const string &sep)
Definition: nc_storage.cpp:353
static Int8 GetDBSize(void)
Get total size of database for the storage.
static bool ReConfig(const CNcbiRegistry &new_reg, string &err_message)
static Uint8 GetMaxSyncLogRecNo(void)
static void MeasureDB(SNCStateStat &state)
static string GetPurgeData(void)
static bool ReadBlobInfo(SNCBlobVerData *ver_data)
Get meta information about blob with given coordinates.
static void SavePurgeData(void)
static CNCBlobAccessor * GetBlobAccess(ENCAccessType access, const string &key, const string &password, Uint2 time_bucket)
Acquire access to the blob identified by key, subkey and version.
static void Finalize(void)
static void WriteDbInfo(TNCBufferType &sendBuff, const CTempString &mask)
static size_t GetNDBFiles(void)
Get number of files in the database.
static void WriteEnvInfo(CSrvSocketTask &task)
static string FindBlob(Uint2 bucket, const string &mask, Uint8 cr_time_hi)
Definition: nc_storage.cpp:305
static void ReleaseCacheData(SNCCacheData *cache_data)
static bool IsDBSizeAlert(void)
static int GetLatestBlobExpire(void)
static bool IsDraining(void)
static bool Initialize(bool do_reinit)
static Uint8 GetMaxBlobSizeStore(void)
static bool IsCleanStart(void)
static void CheckDiskSpace(void)
static void ReferenceCacheData(SNCCacheData *cache_data)
static Uint4 GetNewBlobId(void)
static void AbandonDB(void)
static void WriteSetup(CSrvSocketTask &task)
static Int8 GetDiskFree(void)
static void DeleteBlobInfo(const SNCBlobVerData *ver_data, SNCChunkMaps *maps)
Delete blob from database.
static bool AcceptWritesFromPeers(void)
static void SetDraining(bool draining)
static void WriteBlobStat(CSrvSocketTask &task)
static char * WriteChunkData(SNCBlobVerData *ver_data, SNCChunkMaps *maps, SNCCacheData *cache_data, Uint8 chunk_num, char *buffer, Uint4 buf_size)
static bool IsAbandoned(void)
static string PrintablePassword(const string &pass)
static bool ReadChunkData(SNCBlobVerData *ver_data, SNCChunkMaps *maps, Uint8 chunk_num, char *&buffer, Uint4 &buf_size)
CNcbiRegistry –.
Definition: ncbireg.hpp:913
Class to derive from to use RCU mechanism.
Definition: task_server.hpp:75
Task controlling a socket.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
Uint4 chunk_size
Definition: nc_storage.hpp:68
SNCCacheData & operator=(const SNCCacheData &)
CNCBlobVerManager * ver_mgr
Definition: nc_storage.hpp:80
virtual void ExecuteRCU(void)
Method implementing RCU job that was scheduled earlier by CallRCU().
Uint2 map_size
Definition: nc_storage.hpp:67
~SNCCacheData(void)
Definition: nc_storage.hpp:206
CAtomicCounter_WithAutoInit ref_cnt
Definition: nc_storage.hpp:69
int saved_dead_time
Definition: nc_storage.hpp:65
CNCBlobVerManager * Get_ver_mgr(void) const
Definition: nc_storage.hpp:75
CMiniMutex lock
Definition: nc_storage.hpp:70
SNCDataCoord coord
Definition: nc_storage.hpp:63
Uint2 time_bucket
Definition: nc_storage.hpp:66
SNCCacheData(const SNCCacheData &)
SNCCacheData(void)
Definition: nc_storage.hpp:193
static const int chunk_size
#define NULL
Definition: ncbistd.hpp:225
TValue Get(void) const THROWS_NONE
Get atomic counter value.
Definition: ncbicntr.hpp:168
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const struct ncbi::grid::netcache::search::fields::KEY key
intr::set_base_hook< intr::tag< STimeTable_tag >, intr::optimize_size< true > > TTimeTableHook
Definition: nc_storage.hpp:48
intr::set_base_hook< intr::tag< SKeyMap_tag >, intr::optimize_size< true > > TKeyMapHook
Definition: nc_storage.hpp:53
ENCAccessType
Type of access to NetCache blob.
Definition: nc_utils.hpp:85
void abort()
static pcre_uint8 * buffer
Definition: pcretest.c:1051
Full information about NetCache blob (excluding key)
Definition: nc_db_info.hpp:96
bool empty(void) const
Definition: nc_db_info.hpp:352
Modified on Sun Apr 14 05:28:25 2024 by modify_doxy.py rev. 669887