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

Go to the SVN repository for this file.

1 #ifndef NETCACHED__HPP
2 #define NETCACHED__HPP
3 
4 /* $Id: netcached.hpp 84337 2018-11-02 14:40:17Z gouriano $
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: Pavel Ivanov
30  *
31  * File Description: Network cache daemon
32  *
33  */
34 
35 
36 #include "nc_utils.hpp"
37 
38 
40 
41 
42 struct SNCStateStat;
43 
44 
45 /// Policy for accepting passwords for reading and writing blobs
47  eNCBlobPassAny, ///< Both blobs with password and without are accepted
48  eNCOnlyWithPass, ///< Only blobs with password are accepted
49  eNCOnlyWithoutPass ///< Only blobs without password are accepted
50 };
51 
52 
53 struct SNCSpecificParams : public CObject
54 {
57  bool disable;
62  //Uint4 conn_timeout;
63  //Uint4 cmd_timeout;
70 
74  {
75  }
81  quorum(o.quorum)
82  {
83  }
84  virtual ~SNCSpecificParams(void);
85 };
86 
87 /////////////////////////////////////////////////////////////////////////////
88 // CNCBlobKeyLight
90 {
91 public:
92  CNCBlobKeyLight(void);
93  CNCBlobKeyLight(const CNCBlobKeyLight& another);
94  CNCBlobKeyLight& operator=(const CNCBlobKeyLight& another);
95  CNCBlobKeyLight(const string& packed_key);
96  CNCBlobKeyLight& operator=(const string& packed_key);
97  CNCBlobKeyLight(const CTempString& packed_key);
98  CNCBlobKeyLight& operator=(const CTempString& packed_key);
99 
100  CNCBlobKeyLight& Copy(const CNCBlobKeyLight& another);
101 
102  void Clear(void);
103  bool IsValid(void) const;
104 
105  unsigned int KeyVersion(void) const;
106  bool IsICacheKey(void) const;
107  const string& PackedKey(void) const;
108  const CTempString& RawKey(void) const;
109  const CTempString& SubKey(void) const;
110  const CTempString& Cache(void) const;
111  string KeyForLogs(void) const;
112 
113 protected:
114  void PackBlobKey(const CTempString& cache_name,
115  const CTempString& blob_key,
116  const CTempString& blob_subkey);
117  void UnpackBlobKey(void);
118  void SetKeyVersion(unsigned int v);
119 
120 private:
121  string m_PackedKey;
125  unsigned int m_KeyVersion;
126 };
127 
128 /////////////////////////////////////////////////////////////////////////////
129 // CNCBlobKey
131  public CNetCacheKey
132 {
133 public:
134  CNCBlobKey(void);
135  void Assign( const CTempString& cache_name,
136  const CTempString& blob_key,
137  const CTempString& blob_subkey);
138  void Assign( const CTempString& blob_key);
139 
140 private:
141  CNCBlobKey(const CNCBlobKey& another);
142  CNCBlobKey& operator=(const CNCBlobKey& another);
143  CNCBlobKey(const string& packed_key);
144  CNCBlobKey& operator=(const string& packed_key);
145  CNCBlobKey(const CTempString& packed_key);
146  CNCBlobKey& operator=(const CTempString& packed_key);
147  CNCBlobKey& Copy(const CNCBlobKey& another);
148 };
149 
150 /////////////////////////////////////////////////////////////////////////////
151 inline
153  Clear();
154 }
155 inline
157  Copy(another);
158 }
159 inline
161  return Copy(another);
162 }
163 inline
164 CNCBlobKeyLight::CNCBlobKeyLight(const string& packed_key) {
165  *this = CTempString(packed_key);
166 }
167 inline
168 CNCBlobKeyLight& CNCBlobKeyLight::operator=(const string& packed_key) {
169  return *this = CTempString(packed_key);
170 }
171 inline
173  *this = packed_key;
174 }
175 inline
177  return !m_Cachename.empty();
178 }
179 inline
180 const string& CNCBlobKeyLight::PackedKey(void) const {
181  return m_PackedKey;
182 }
183 inline
185  return m_RawKey;
186 }
187 inline
189  return m_SubKey;
190 }
191 inline
193  return m_Cachename;
194 }
195 inline
196 bool CNCBlobKeyLight::IsValid(void) const {
197  return !RawKey().empty();
198 }
199 inline
200 void CNCBlobKeyLight::SetKeyVersion(unsigned int v) {
201  m_KeyVersion = v;
202 }
203 inline
205 }
206 inline
207 void CNCBlobKey::Assign( const CTempString& blob_key) {
208  Assign( CTempString(), blob_key, CTempString());
209 }
210 
211 /////////////////////////////////////////////////////////////////////////////
212 /// Netcache server
214 {
215 public:
216  static const SNCSpecificParams* GetAppSetup(const TStringMap& client_params);
217  static void WriteAppSetup(TNCBufferType& task, const TStringMap& client);
218  static void WriteAppSetup(TNCBufferType& task, const SNCSpecificParams* app);
219  static void WriteEnvInfo(CSrvSocketTask& task);
220 
221  /// Get inactivity timeout for each connection
222  //static unsigned GetDefConnTimeout(void);
223  static int GetDefBlobTTL(void);
224  /// Get name of client that should be used for administrative commands
225  static const string& GetAdminClient(void);
226 
227  static string GetHostRole(void);
228  static string GetHostLocation(void);
229 
230  /// Get total number of seconds the server is running
231  static int GetUpTime(void);
232  static void CachingCompleted(void);
233  static bool IsInitiallySynced(void);
234  static void InitialSyncComplete(void);
235  static void InitialSyncRequired(void);
236  static bool IsCachingComplete(void);
237  static bool IsDebugMode(void);
238 
239  static void ReadCurState(SNCStateStat& state);
240 
241 private:
242  CNCServer(void);
243 };
244 
245 
246 class CNCHeartBeat : public CSrvTask
247 {
248 public:
249  CNCHeartBeat(void);
250  virtual ~CNCHeartBeat(void);
251 
252  static void CheckConfFile(void);
253 private:
254  virtual void ExecuteSlice(TSrvThreadNum thr_num);
255 };
256 
257 
259 
260 #endif /* NETCACHED__HPP */
const string & PackedKey(void) const
Definition: netcached.hpp:180
CNCBlobKeyLight(void)
Definition: netcached.hpp:152
const CTempString & RawKey(void) const
Definition: netcached.hpp:184
unsigned int m_KeyVersion
Definition: netcached.hpp:125
void PackBlobKey(const CTempString &cache_name, const CTempString &blob_key, const CTempString &blob_subkey)
Definition: netcached.cpp:183
CNCBlobKeyLight & operator=(const CNCBlobKeyLight &another)
Definition: netcached.hpp:160
CTempString m_SubKey
Definition: netcached.hpp:124
string m_PackedKey
Definition: netcached.hpp:121
CTempString m_Cachename
Definition: netcached.hpp:122
string KeyForLogs(void) const
Definition: netcached.cpp:212
const CTempString & SubKey(void) const
Definition: netcached.hpp:188
bool IsValid(void) const
Definition: netcached.hpp:196
unsigned int KeyVersion(void) const
Definition: netcached.cpp:154
CTempString m_RawKey
Definition: netcached.hpp:123
CNCBlobKeyLight & Copy(const CNCBlobKeyLight &another)
Definition: netcached.cpp:165
const CTempString & Cache(void) const
Definition: netcached.hpp:192
bool IsICacheKey(void) const
Definition: netcached.hpp:176
void Clear(void)
Definition: netcached.cpp:174
void UnpackBlobKey(void)
Definition: netcached.cpp:195
void SetKeyVersion(unsigned int v)
Definition: netcached.hpp:200
CNCBlobKey & Copy(const CNCBlobKey &another)
CNCBlobKey & operator=(const CTempString &packed_key)
CNCBlobKey & operator=(const CNCBlobKey &another)
void Assign(const CTempString &cache_name, const CTempString &blob_key, const CTempString &blob_subkey)
Definition: netcached.cpp:228
CNCBlobKey & operator=(const string &packed_key)
CNCBlobKey(const CTempString &packed_key)
CNCBlobKey(const CNCBlobKey &another)
CNCBlobKey(void)
Definition: netcached.hpp:204
CNCBlobKey(const string &packed_key)
virtual void ExecuteSlice(TSrvThreadNum thr_num)
This is the main method to do all work this task should do.
Definition: netcached.cpp:300
CNCHeartBeat(void)
Definition: netcached.cpp:256
static void CheckConfFile(void)
Definition: netcached.cpp:266
virtual ~CNCHeartBeat(void)
Definition: netcached.cpp:263
Netcache server.
Definition: netcached.hpp:214
CNCServer(void)
static const SNCSpecificParams * GetAppSetup(const TStringMap &client_params)
Definition: netcached.cpp:685
static void ReadCurState(SNCStateStat &state)
Definition: netcached.cpp:1010
static const string & GetAdminClient(void)
Get name of client that should be used for administrative commands.
Definition: netcached.cpp:972
static bool IsDebugMode(void)
Definition: netcached.cpp:954
static bool IsCachingComplete(void)
Definition: netcached.cpp:948
static void WriteAppSetup(TNCBufferType &task, const TStringMap &client)
Definition: netcached.cpp:773
static int GetDefBlobTTL(void)
Get inactivity timeout for each connection.
Definition: netcached.cpp:966
static string GetHostLocation(void)
Definition: netcached.cpp:989
static int GetUpTime(void)
Get total number of seconds the server is running.
Definition: netcached.cpp:1002
static void WriteEnvInfo(CSrvSocketTask &task)
Definition: netcached.cpp:899
static bool IsInitiallySynced(void)
Definition: netcached.cpp:918
static void InitialSyncRequired(void)
Definition: netcached.cpp:932
static string GetHostRole(void)
Definition: netcached.cpp:977
static void CachingCompleted(void)
Definition: netcached.cpp:939
static void InitialSyncComplete(void)
Definition: netcached.cpp:924
CObject –.
Definition: ncbiobj.hpp:180
Task controlling a socket.
Main working entity in TaskServer.
Definition: srv_tasks.hpp:88
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
#define false
Definition: bool.h:36
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
ENCBlobPassPolicy
Policy for accepting passwords for reading and writing blobs.
Definition: netcached.hpp:46
@ eNCBlobPassAny
Both blobs with password and without are accepted.
Definition: netcached.hpp:47
@ eNCOnlyWithoutPass
Only blobs without password are accepted.
Definition: netcached.hpp:49
@ eNCOnlyWithPass
Only blobs with password are accepted.
Definition: netcached.hpp:48
static CNamedPipeClient * client
Meaningful information encoded in the NetCache key.
map< string, string > keys
Definition: netcached.hpp:56
ENCBlobPassPolicy pass_policy
Definition: netcached.hpp:61
map< string, string > source
Definition: netcached.hpp:55
SNCSpecificParams(const SNCSpecificParams &o)
Definition: netcached.hpp:76
virtual ~SNCSpecificParams(void)
Definition: netcached.cpp:326
Uint2 TSrvThreadNum
Type for thread number in TaskServer.
Definition: task_server.hpp:42
Modified on Fri Sep 20 14:58:23 2024 by modify_doxy.py rev. 669887