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

Go to the SVN repository for this file.

1 /* $Id: netcached.cpp 93346 2021-04-05 17:19:35Z grichenk $
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  * Author: Pavel Ivanov
27  *
28  * File Description: Network cache daemon
29  *
30  */
31 
32 #include "nc_pch.hpp"
33 
34 #include <corelib/ncbireg.hpp>
35 #include <corelib/ncbi_process.hpp>
36 #include <corelib/ncbifile.hpp>
37 #include <corelib/ncbistr.hpp>
39 
40 #include "task_server.hpp"
41 
42 #include "netcached.hpp"
43 #include "message_handler.hpp"
44 #include "netcache_version.hpp"
45 #include "nc_stat.hpp"
46 #include "distribution_conf.hpp"
47 #include "sync_log.hpp"
48 #include "peer_control.hpp"
49 #include "nc_storage.hpp"
50 #include "active_handler.hpp"
51 #include "periodic_sync.hpp"
52 #include "nc_storage_blob.hpp"
53 
54 #include "logging.hpp"
55 #include "server_core.hpp"
56 
57 #ifdef NCBI_OS_LINUX
58 # include <sys/resource.h>
59 #endif
60 
61 // this must be 0 in release builds
62 #define MAKE_TEST_BUILD 0
63 
64 #if MAKE_TEST_BUILD
65 #include <util/random_gen.hpp>
66 #include <random>
67 void s_InitTests(void);
68 #endif
69 
71 
72 
73 static const char* kNCReg_ServerSection = "netcache";
74 static const char* kNCReg_Ports = "ports";
75 static const char* kNCReg_CtrlPort = "control_port";
76 static const char* kNCReg_AdminClient = "admin_client_name";
77 static const char* kNCReg_DefAdminClient = "netcache_control";
78 static const char* kNCReg_SpecPriority = "app_setup_priority";
79 static const char* kNCReg_DefSpecPriority = "cache,port";
80 //static const char* kNCReg_NetworkTimeout = "network_timeout";
81 static const char* kNCReg_DisableClient = "disable_client";
82 //static const char* kNCReg_CommandTimeout = "cmd_timeout";
83 static const char* kNCReg_LifespanTTL = "lifespan_ttl";
84 static const char* kNCReg_MaxTTL = "max_ttl";
85 static const char* kNCReg_BlobTTL = "blob_ttl";
86 static const char* kNCReg_VerTTL = "ver_ttl";
87 static const char* kNCReg_TTLUnit = "ttl_unit";
88 static const char* kNCReg_ProlongOnRead = "prolong_on_read";
89 static const char* kNCReg_SearchOnRead = "search_on_read";
90 static const char* kNCReg_Quorum = "quorum";
91 static const char* kNCReg_FastOnMain = "fast_quorum_on_main";
92 static const char* kNCReg_PassPolicy = "blob_password_policy";
93 static const char* kNCReg_AppSetupPrefix = "app_setup_";
94 static const char* kNCReg_AppSetupValue = "setup";
95 
96 
98 typedef vector<string> TSpecKeysList;
100  string key;
102 
103  SSpecParamsEntry(const string& key, CObject* value);
104 };
105 struct SSpecParamsSet : public CObject {
106  vector<SSpecParamsEntry> entries;
107 
108  virtual ~SSpecParamsSet(void);
109 };
110 
111 
112 /// Port where server runs
115 /// Name of client that should be used for administrative commands
116 static string s_AdminClient;
119 //static unsigned int s_DefConnTimeout;
120 static int s_DefBlobTTL;
121 static bool s_DebugMode = false;
122 static bool s_InitiallySynced = false;
123 static bool s_CachingComplete = false;
126 static string s_PidFile;
127 static string s_HostRole;
128 static string s_HostLocation;
129 static string s_AppPath;
130 static string s_CmdLineArgs;
131 
132 static void s_StoreStartupParams(int argc, const char* argv[])
133 {
134  s_AppPath = argv[0];
137  }
138  for (int i = 1; i < argc; ++i) {
139  s_CmdLineArgs += argv[i];
140  if (i+1 < argc) {
141  s_CmdLineArgs.append(1, ' ');
142  }
143  }
144 }
145 
147 {
148  m_PackedKey.assign(packed_key.data(), packed_key.size());
149  UnpackBlobKey();
150  m_KeyVersion = 0;
151  return *this;
152 }
153 
154 unsigned int CNCBlobKeyLight::KeyVersion(void) const
155 {
156  if (m_KeyVersion == 0) {
159  return tmp.GetVersion();
160  }
161  }
162  return m_KeyVersion;
163 }
164 
166 {
167  if (this != &another) {
168  m_PackedKey = another.m_PackedKey;
169  UnpackBlobKey();
170  m_KeyVersion = another.m_KeyVersion;
171  }
172  return *this;
173 }
175 {
176  m_PackedKey.clear();
177  m_Cachename.clear();
178  m_RawKey.clear();
179  m_SubKey.clear();
180  m_KeyVersion = 0;
181 }
182 
184  const CTempString& blob_key, const CTempString& blob_subkey)
185 {
186  m_PackedKey.reserve(cache_name.size() + blob_key.size()
187  + blob_subkey.size() + 2);
188  m_PackedKey.assign(cache_name.data(), cache_name.size());
189  m_PackedKey.append(1, '\1');
190  m_PackedKey.append(blob_key.data(), blob_key.size());
191  m_PackedKey.append(1, '\1');
192  m_PackedKey.append(blob_subkey.data(), blob_subkey.size());
193 }
194 
196 {
197  // cache
198  const char* cache_str = m_PackedKey.data();
199  size_t cache_size = m_PackedKey.find('\1', 0);
200  m_Cachename.assign(cache_str, cache_size);
201  // key
202  const char* key_str = cache_str + cache_size + 1;
203  size_t key_size = m_PackedKey.find('\1', cache_size + 1)
204  - cache_size - 1;
205  m_RawKey.assign(key_str, key_size);
206  // subkey
207  const char* subkey_str = key_str + key_size + 1;
208  size_t subkey_size = m_PackedKey.size() - cache_size - key_size - 2;
209  m_SubKey.assign(subkey_str, subkey_size);
210 }
211 
212 string CNCBlobKeyLight::KeyForLogs(void) const
213 {
214  string result;
215  result.append("'");
216  result.append(m_RawKey.data(), m_RawKey.size());
217  result.append("'");
218  if (!m_Cachename.empty() || !m_SubKey.empty()) {
219  result.append(", '");
220  result.append(m_SubKey.data(), m_SubKey.size());
221  result.append("' from cache '");
222  result.append(m_Cachename.data(), m_Cachename.size());
223  result.append("'");
224  }
225  return result;
226 }
227 
228 void CNCBlobKey::Assign( const CTempString& cache_name,
229  const CTempString& blob_key,
230  const CTempString& blob_subkey)
231 {
232  if (blob_key.empty() && cache_name.empty()) {
233  Clear();
234  return;
235  }
236  string rawKey = blob_key;
237  if (CNetCacheKey::ParseBlobKey(blob_key.data(), blob_key.size(), this)) {
238  // If key is given and it's NetCache key (not ICache key) then we need
239  // to strip service name from it. It's necessary for the case when new
240  // CNetCacheAPI with enabled_mirroring=true passes key to an old CNetCacheAPI
241  // which doesn't even know about mirroring.
242  if (cache_name.empty() && HasExtensions()) {
243  rawKey = StripKeyExtensions();
244  }
245  } else if (cache_name.empty()) {
246  SRV_LOG(Warning, "CNetCacheKey failed to parse blob key: " << blob_key);
247  Clear();
248  return;
249  }
250  PackBlobKey(cache_name, rawKey, blob_subkey);
251  UnpackBlobKey();
252  SetKeyVersion(max((unsigned int)1,GetVersion()));
253 }
254 
255 
257 {
258 #if __NC_TASKS_MONITOR
259  m_TaskName = "CNCHeartBeat";
260 #endif
261 }
262 
264 {}
265 
267 {
268  static time_t modified = 0;
269  CFile cfg(GetConfName());
270  if (modified == 0) {
271  if (cfg.Exists()) {
272  cfg.GetTimeT(&modified);
273  }
274  return;
275  }
276  if (!cfg.Exists()) {
277  if (modified != 1) {
279  }
280  modified = 1;
281  return;
282  }
283  time_t mod = 0;
284  cfg.GetTimeT(&mod);
285  if (mod == modified) {
286  return;
287  }
288  modified = mod;
289  string msg(GetConfName() + ": modified on ");
290  CTime tm;
291  if (cfg.GetTime(&tm)) {
292  msg += tm.AsString();
293  } else {
294  msg += " GetTime() failed";
295  }
297 }
298 
299 void
301 {
303  return;
304 
305 // save server state into statistics
306  CheckConfFile();
311 
312  RunAfter(1);
313 }
314 
315 
316 static inline int
317 s_CompareStrings(const string& left, const string& right)
318 {
319  if (left.size() != right.size())
320  return int(left.size()) - int(right.size());
321  else
322  return left.compare(right);
323 }
324 
325 
327 {}
328 
329 
330 inline
332  CObject* value)
333  : key(key),
334  value(value)
335 {}
336 
337 
339 {}
340 
341 
342 static void
344  const string& section,
345  SNCSpecificParams* params, vector<string>& keys)
346 {
347  string key(NStr::Join(keys, "\",\""));
349  params->disable = reg.GetBool(section, kNCReg_DisableClient, false);
350  params->source[kNCReg_DisableClient] = section;
351  params->keys[kNCReg_DisableClient] = key;
352  }
353  if (reg.HasEntry(section, kNCReg_BlobTTL, IRegistry::fCountCleared)) {
354  params->blob_ttl = reg.GetInt(section, kNCReg_BlobTTL, 3600);
355  params->source[kNCReg_BlobTTL] = section;
356  params->keys[kNCReg_BlobTTL] = key;
357  }
359  params->lifespan_ttl = reg.GetInt(section, kNCReg_LifespanTTL, 0);
360  params->source[kNCReg_LifespanTTL] = section;
361  params->keys[kNCReg_LifespanTTL] = key;
362  }
363  if (reg.HasEntry(section, kNCReg_MaxTTL, IRegistry::fCountCleared)) {
364  Uint4 one_month = 2592000; //30 days: 3600 x 24 x 30
365  params->max_ttl = reg.GetInt(section, kNCReg_MaxTTL, max( 10 * params->blob_ttl, one_month));
366  params->source[kNCReg_MaxTTL] = section;
367  params->keys[kNCReg_MaxTTL] = key;
368  }
369 
370  if (reg.HasEntry(section, kNCReg_VerTTL, IRegistry::fCountCleared)) {
371  params->ver_ttl = reg.GetInt(section, kNCReg_VerTTL, 3600);
372  params->source[kNCReg_VerTTL] = section;
373  params->keys[kNCReg_VerTTL] = key;
374  }
375  if (reg.HasEntry(section, kNCReg_TTLUnit, IRegistry::fCountCleared)) {
376  params->ttl_unit = reg.GetInt(section, kNCReg_TTLUnit, 300);
377  params->source[kNCReg_TTLUnit] = section;
378  params->keys[kNCReg_TTLUnit] = key;
379  }
381  params->prolong_on_read = reg.GetBool(section, kNCReg_ProlongOnRead, true);
382  params->source[kNCReg_ProlongOnRead] = section;
383  params->keys[kNCReg_ProlongOnRead] = key;
384  }
386  params->srch_on_read = reg.GetBool(section, kNCReg_SearchOnRead, true);
387  params->source[kNCReg_SearchOnRead] = section;
388  params->keys[kNCReg_SearchOnRead] = key;
389  }
390  if (reg.HasEntry(section, kNCReg_Quorum, IRegistry::fCountCleared)) {
391  params->quorum = reg.GetInt(section, kNCReg_Quorum, 2);
392  params->source[kNCReg_Quorum] = section;
393  params->keys[kNCReg_Quorum] = key;
394  }
396  params->fast_on_main = reg.GetBool(section, kNCReg_FastOnMain, true);
397  params->source[kNCReg_FastOnMain] = section;
398  params->keys[kNCReg_FastOnMain] = key;
399  }
401  string pass_policy = reg.GetString(section, kNCReg_PassPolicy, "any");
402  params->source[kNCReg_PassPolicy] = section;
403  params->keys[kNCReg_PassPolicy] = key;
404  if (pass_policy == "no_password") {
406  }
407  else if (pass_policy == "with_password") {
408  params->pass_policy = eNCOnlyWithPass;
409  }
410  else {
411  if (pass_policy != "any") {
412  SRV_LOG(Error, "Incorrect value of '" << kNCReg_PassPolicy
413  << "' parameter: '" << pass_policy
414  << "', assuming 'any'");
415  }
416  params->pass_policy = eNCBlobPassAny;
417  }
418  }
419 }
420 
421 static inline void
423  unsigned int best_index,
424  const SSpecParamsEntry& entry)
425 {
426  params_set->entries.insert(params_set->entries.begin() + best_index, entry);
427 }
428 
429 static SSpecParamsSet*
431  const string& key,
432  unsigned int& best_index)
433 {
434  unsigned int low = 1;
435  unsigned int high = Uint4(cur_set->entries.size());
436  while (low < high) {
437  unsigned int mid = (low + high) / 2;
438  const SSpecParamsEntry& entry = cur_set->entries[mid];
439  int comp_res = s_CompareStrings(key, entry.key);
440  if (comp_res == 0) {
441  best_index = mid;
442  return static_cast<SSpecParamsSet*>(entry.value.GetNCPointer());
443  }
444  else if (comp_res > 0)
445  low = mid + 1;
446  else
447  high = mid;
448  }
449  best_index = high;
450  return NULL;
451 }
452 
453 static void
455  SSpecParamsSet* prev_set,
456  Uint1 depth,
457  SSpecParamsSet* deflt)
458 {
459  if (depth == 0) {
460  if (cur_set->entries.size() == 0) {
461  cur_set->entries.push_back(deflt->entries[0]);
462  }
463  }
464  else {
465  SSpecParamsSet* this_deflt = NULL;
466  if (deflt)
467  this_deflt = (SSpecParamsSet*)deflt->entries[0].value.GetPointer();
468  for (size_t i = 0; i < cur_set->entries.size(); ++i) {
469  s_CheckDefClientConfig((SSpecParamsSet*)cur_set->entries[i].value.GetPointer(),
470  cur_set, depth - 1, this_deflt);
471  this_deflt = (SSpecParamsSet*)cur_set->entries[0].value.GetPointer();
472  }
473  }
474 }
475 
476 static void
478 {
480  if (NStr::FindNoCase(spec_prty,"disable") != NPOS) {
481  spec_prty.clear();
482  }
483  ncbi_NStr_Tokenize(spec_prty, ", \t\r\n", s_SpecPriority, NStr::eMergeDelims);
484  vector<string> keys;
485 
486  SNCSpecificParams* main_params = new SNCSpecificParams;
487  main_params->disable = false;
488  //main_params->cmd_timeout = 600;
489  //main_params->conn_timeout = 10;
490  main_params->lifespan_ttl = 0;
491  main_params->max_ttl = 2592000;
492  main_params->blob_ttl = 3600;
493  main_params->ver_ttl = 3600;
494  main_params->ttl_unit = 300;
495  main_params->prolong_on_read = true;
496  main_params->srch_on_read = true;
497  main_params->pass_policy = eNCBlobPassAny;
498  main_params->quorum = 2;
499  main_params->fast_on_main = true;
500  keys.push_back("default");
501  s_ReadSpecificParams(reg, kNCReg_ServerSection, main_params, keys);
502  //s_DefConnTimeout = main_params->conn_timeout;
503  s_DefBlobTTL = main_params->blob_ttl;
504  SSpecParamsSet* params_set = new SSpecParamsSet();
505  params_set->entries.push_back(SSpecParamsEntry(kEmptyStr, main_params));
506  for (unsigned int i = 0; i < s_SpecPriority.size(); ++i) {
507  SSpecParamsSet* next_set = new SSpecParamsSet();
508  next_set->entries.push_back(SSpecParamsEntry(kEmptyStr, params_set));
509  params_set = next_set;
510  }
511  s_SpecParams = params_set;
512 
513  if (s_SpecPriority.size() != 0) {
514  list<string> conf_sections;
515  reg.EnumerateSections(&conf_sections);
516  ITERATE(list<string>, sec_it, conf_sections) {
517  const string& section = *sec_it;
519  continue;
520  keys.clear();
521  SSpecParamsSet* cur_set = s_SpecParams;
523  const string& key_name = *prty_it;
524  if (reg.HasEntry(section, key_name, IRegistry::fCountCleared)) {
525  keys.push_back(key_name);
526  const string& key_value = reg.Get(section, key_name);
527  unsigned int next_ind = 0;
528  SSpecParamsSet* next_set
529  = s_FindNextParamsSet(cur_set, key_value, next_ind);
530  if (!next_set) {
531  if (cur_set->entries.size() == 0) {
532  cur_set->entries.push_back(SSpecParamsEntry(kEmptyStr, new SSpecParamsSet()));
533  ++next_ind;
534  }
535  next_set = new SSpecParamsSet();
536  s_PutNewParams(cur_set, next_ind,
537  SSpecParamsEntry(key_value, next_set));
538  }
539  cur_set = next_set;
540  }
541  else {
542  if (cur_set->entries.size() == 0) {
543  cur_set->entries.push_back(SSpecParamsEntry(kEmptyStr, new SSpecParamsSet()));
544  }
545  cur_set = (SSpecParamsSet*)cur_set->entries[0].value.GetPointer();
546  }
547  }
548  if (cur_set->entries.size() != 0) {
549  SRV_LOG(Error, "Section '" << section << "' in configuration file is "
550  "a duplicate of another section - ignoring it.");
551  continue;
552  }
553  SNCSpecificParams* params = new SNCSpecificParams(*main_params);
554  if (reg.HasEntry(section, kNCReg_AppSetupValue)) {
555  s_ReadSpecificParams(reg, reg.Get(section, kNCReg_AppSetupValue),
556  params, keys);
557  }
558  cur_set->entries.push_back(SSpecParamsEntry(kEmptyStr, params));
559  }
560 
561 // some branches will not have default
562 // GetAppSetup will take care of it
563 // s_CheckDefClientConfig(s_SpecParams, NULL, Uint1(s_SpecPriority.size()), NULL);
564  }
565 }
566 
567 static bool
569 {
571 
572  string ports_str = reg.Get(kNCReg_ServerSection, kNCReg_Ports);
573  list<string> split_ports;
574  ncbi_NStr_Split(ports_str, ", \t\r\n", split_ports);
575  ITERATE(list<string>, it, split_ports) {
576  try {
578  }
579  catch (CStringException& ex) {
580  SRV_LOG(Critical, "Error reading port number from '"
581  << *it << "': " << ex);
582  return false;
583  }
584  }
585  if (s_Ports.size() == 0) {
586  SRV_LOG(Critical, "No listening client ports were configured.");
587  return false;
588  }
589 
590  try {
594  s_DebugMode = reg.GetBool(kNCReg_ServerSection, "debug_mode", false);
595 
597  }
598  catch (CStringException& ex) {
599  SRV_LOG(Critical, "Error in configuration: " << ex);
600  return false;
601  }
602 
603  return true;
604 }
605 
606 static bool
607 s_Initialize(bool do_reinit)
608 {
612 
614  return false;
616 
617  if (!CNCBlobStorage::Initialize(do_reinit))
618  return false;
619 
621  SRV_LOG(Critical, "Bad configuration: max_blob_size_sync ("
623  << ") is greater than max_blob_size_store ("
625  return false;
626  }
627 
629  s_HeartBeat = new CNCHeartBeat();
630 
632  string forget = CNCBlobStorage::GetPurgeData();
633  INFO("Initial Purge data: " << forget);
634  CNCBlobAccessor::UpdatePurgeData( forget, ';' );
636 
638  return false;
639 
640  if (s_Ports.find(s_CtrlPort) == s_Ports.end()) {
641  Uint4 port = s_CtrlPort;
642  if (s_DebugMode)
643  port += 10;
644  INFO("Opening control port: " << port);
646  return false;
647  }
648  string ports_str;
649  ITERATE(TPortsList, it, s_Ports) {
650  unsigned int port = *it;
651  if (s_DebugMode)
652  port += 10;
654  return false;
655  ports_str.append(NStr::IntToString(port));
656  ports_str.append(", ", 2);
657  }
658  ports_str.resize(ports_str.size() - 2);
659  INFO("Opening client ports: " << ports_str);
660 
661 
662 #if MAKE_TEST_BUILD
663  s_InitTests();
664 #endif
665 
666  return true;
667 }
668 
669 static void
671 {
672  INFO("NetCache server is finalizing.");
674 
682 }
683 
684 const SNCSpecificParams*
685 CNCServer::GetAppSetup(const TStringMap& client_params)
686 {
687 #if 0
688  const SSpecParamsSet* cur_set = s_SpecParams;
690  TStringMap::const_iterator it = client_params.find(*key_it);
691  const SSpecParamsSet* next_set = NULL;
692  if (it != client_params.end()) {
693  const string& value = it->second;
694  unsigned int best_index = 0;
695  next_set = s_FindNextParamsSet(cur_set, value, best_index);
696  }
697  if (!next_set) {
698  next_set = static_cast<const SSpecParamsSet*>(cur_set->entries[0].value.GetPointer());
699  }
700  cur_set = next_set;
701  }
702  return static_cast<const SNCSpecificParams*>(cur_set->entries[0].value.GetPointer());
703 #else
704 // if I do not set default for some branches, I need two passes sometimes
705  size_t rank = 0;
706  size_t rank2 = 0;
707  const SSpecParamsSet* cur_set = s_SpecParams;
709  TStringMap::const_iterator it = client_params.find(*key_it);
710  const SSpecParamsSet* next_set = NULL;
711  if (it != client_params.end()) {
712  const string& value = it->second;
713  unsigned int best_index = 0;
714  next_set = s_FindNextParamsSet(cur_set, value, best_index);
715  }
716  if (!next_set) {
717  next_set = static_cast<const SSpecParamsSet*>(cur_set->entries[0].value.GetPointer());
718  }
719  cur_set = next_set;
720  if (!cur_set->entries.empty()) {
721  ++rank;
722  }
723  }
724  if (rank < s_SpecPriority.size()) {
725  bool first = true;
726  const SSpecParamsSet* cur_set_2 = s_SpecParams;
728  TStringMap::const_iterator it = client_params.find(*key_it);
729  const SSpecParamsSet* next_set = NULL;
730  if (!first && it != client_params.end()) {
731  const string& value = it->second;
732  unsigned int best_index = 0;
733  next_set = s_FindNextParamsSet(cur_set_2, value, best_index);
734  }
735  if (!next_set) {
736  next_set = static_cast<const SSpecParamsSet*>(cur_set_2->entries[0].value.GetPointer());
737  }
738  cur_set_2 = next_set;
739  if (!cur_set_2->entries.empty()) {
740  ++rank2;
741  }
742  first = false;
743  }
744  if (rank2 > rank) {
745  cur_set = cur_set_2;
746  }
747  }
748  return static_cast<const SNCSpecificParams*>(cur_set->entries[0].value.GetPointer());
749 #endif
750 }
751 
752 // similar to s_CheckDefClientConfig
753 static void
755  SSpecParamsSet* prev_set,
756  Uint1 depth,
757  SSpecParamsSet* deflt,
758  vector<string>& keys)
759 {
760  if (depth != 0) {
761  SSpecParamsSet* this_deflt = NULL;
762  if (deflt)
763  this_deflt = (SSpecParamsSet*)deflt->entries[0].value.GetPointer();
764  for (size_t i = 0; i < cur_set->entries.size(); ++i) {
765  keys.push_back(cur_set->entries[i].key);
766  s_CollectClientConfigKeys((SSpecParamsSet*)cur_set->entries[i].value.GetPointer(),
767  cur_set, depth - 1, this_deflt, keys);
768  this_deflt = (SSpecParamsSet*)cur_set->entries[0].value.GetPointer();
769  }
770  }
771 }
772 
774 {
775  set<string> all_ports;
776  ITERATE(TPortsList, it, s_Ports) {
777  all_ports.insert(NStr::NumericToString(*it));
778  }
780  all_ports.insert("");
781 
782  set<string> ports;
783  if (client.find("port") != client.end()) {
784  ports.insert(client.at("port"));
785  } else {
786  ports = all_ports;
787  }
788 
789  list<string> caches;
790  if (client.find("cache") != client.end()) {
791  caches.push_back(client.at("cache"));
792  } else {
793  vector<string> keys;
795  ITERATE(vector<string>, k, keys) {
796  if (k->empty() || all_ports.find(*k) != all_ports.end()) {
797  continue;
798  }
799  caches.push_back(*k);
800  }
801  caches.sort();
802  caches.unique();
803  caches.push_front("");
804  }
805 
806  string is("\": "), iss("\": \""), eol(",\n\""), eos("\"");
808  task.WriteText(eol).WriteText("setup\": [\n");
809  bool is_first = true;
810  ITERATE(list<string>, c, caches) {
811  ITERATE(set<string>, p, ports) {
812  if (!is_first) {
813  task.WriteText(",");
814  }
815  is_first = false;
816  task.WriteText("{\n");
817 
819  task.WriteText("\"").WriteText("cache");
820  if (!c->empty()) {
821  client["cache"] = *c;
822  task.WriteText(iss).WriteText(*c).WriteText(eos);
823  } else {
824  task.WriteText(is).WriteText("null");
825  }
826  task.WriteText(eol).WriteText("port").WriteText(is);
827  if (!p->empty()) {
828  client["port"] = *p;
829  task.WriteText(*p);
830  } else {
831  task.WriteText("null");
832  }
834  task.WriteText("\n}");
835  }
836  }
837  task.WriteText("]");
838 }
839 
841 {
843  map<string,string> keys(params->keys);
844  string eol(",\n\""), is("\": "), isv("\": { \"value\": "),
845  iss(", \"source\": \""), eos("\""),
846  isk(", \"keys\": [\""), eok("\"]}");
848  WriteText(isv).WriteText(NStr::BoolToString(params->disable)).
849  WriteText(iss).WriteText(source[kNCReg_DisableClient]).WriteText(eos).
850  WriteText(isk).WriteText(keys[kNCReg_DisableClient]).WriteText(eok);
852  WriteText(isv).WriteText(NStr::BoolToString(params->prolong_on_read)).
853  WriteText(iss).WriteText(source[kNCReg_ProlongOnRead]).WriteText(eos).
854  WriteText(isk).WriteText(keys[kNCReg_ProlongOnRead]).WriteText(eok);
856  WriteText(isv).WriteText(NStr::BoolToString(params->srch_on_read)).
857  WriteText(iss).WriteText(source[kNCReg_SearchOnRead]).WriteText(eos).
858  WriteText(isk).WriteText(keys[kNCReg_SearchOnRead]).WriteText(eok);
860  WriteText(isv).WriteText(NStr::BoolToString(params->fast_on_main)).
861  WriteText(iss).WriteText(source[kNCReg_FastOnMain]).WriteText(eos).
862  WriteText(isk).WriteText(keys[kNCReg_FastOnMain]).WriteText(eok);
864  task.WriteText("\"");
865  switch (params->pass_policy) {
866  case eNCOnlyWithoutPass: task.WriteText("no_password"); break;
867  case eNCOnlyWithPass: task.WriteText("with_password"); break;
868  case eNCBlobPassAny: task.WriteText("any"); break;
869  }
870  task.WriteText("\"").
871  WriteText(iss).WriteText(source[kNCReg_PassPolicy]).WriteText(eos).
872  WriteText(isk).WriteText(keys[kNCReg_PassPolicy]).WriteText(eok);
874  WriteText(isv).WriteNumber(params->lifespan_ttl).
875  WriteText(iss).WriteText(source[kNCReg_LifespanTTL]).WriteText(eos).
876  WriteText(isk).WriteText(keys[kNCReg_LifespanTTL]).WriteText(eok);
877  task.WriteText(eol).WriteText(kNCReg_MaxTTL ).
878  WriteText(isv).WriteNumber(params->max_ttl).
879  WriteText(iss).WriteText(source[kNCReg_MaxTTL]).WriteText(eos).
880  WriteText(isk).WriteText(keys[kNCReg_MaxTTL]).WriteText(eok);
881  task.WriteText(eol).WriteText(kNCReg_BlobTTL ).
882  WriteText(isv).WriteNumber(params->blob_ttl).
883  WriteText(iss).WriteText(source[kNCReg_BlobTTL]).WriteText(eos).
884  WriteText(isk).WriteText(keys[kNCReg_BlobTTL]).WriteText(eok);
885  task.WriteText(eol).WriteText(kNCReg_VerTTL ).
886  WriteText(isv).WriteNumber(params->ver_ttl).
887  WriteText(iss).WriteText(source[kNCReg_VerTTL]).WriteText(eos).
888  WriteText(isk).WriteText(keys[kNCReg_VerTTL]).WriteText(eok);
889  task.WriteText(eol).WriteText(kNCReg_TTLUnit ).
890  WriteText(isv).WriteNumber(params->ttl_unit).
891  WriteText(iss).WriteText(source[kNCReg_TTLUnit]).WriteText(eos).
892  WriteText(isk).WriteText(keys[kNCReg_TTLUnit]).WriteText(eok);
893  task.WriteText(eol).WriteText(kNCReg_Quorum ).
894  WriteText(isv).WriteNumber(params->quorum).
895  WriteText(iss).WriteText(source[kNCReg_Quorum]).WriteText(eos).
896  WriteText(isk).WriteText(keys[kNCReg_Quorum]).WriteText(eok);
897 }
898 
900 {
901  string is("\": "),iss("\": \""), eol(",\n\""), eos("\"");
902  task.WriteText(eol).WriteText("hostname" ).WriteText(iss).WriteText( CTaskServer::GetHostName()).WriteText(eos);
903  task.WriteText(eol).WriteText("exe_path" ).WriteText(iss).WriteText( s_AppPath).WriteText(eos);
904  task.WriteText(eol).WriteText("cmdline_args").WriteText(iss).WriteText( s_CmdLineArgs).WriteText(eos);
905  task.WriteText(eol).WriteText("config_path" ).WriteText(iss).WriteText( GetConfName()).WriteText(eos);
906  task.WriteText(eol).WriteText("workdir" ).WriteText(iss).WriteText( CDir::GetCwd()).WriteText(eos);
907  task.WriteText(eol).WriteText("logfile" ).WriteText(iss).WriteText( GetLogFileName()).WriteText(eos);
908  task.WriteText(eol).WriteText("pidfile" ).WriteText(iss).WriteText( s_PidFile).WriteText(eos);
911  task.WriteText(eol).WriteText("logfile_size").WriteText(iss).WriteText(
913  task.WriteText(eol).WriteText("ncbi_role" ).WriteText(iss).WriteText( GetHostRole()).WriteText(eos);
914  task.WriteText(eol).WriteText("ncbi_location").WriteText(iss).WriteText( GetHostLocation()).WriteText(eos);
915 }
916 
917 bool
919 {
920  return s_InitiallySynced;
921 }
922 
923 void
925 {
926  INFO("Initial synchronization complete");
927  s_InitiallySynced = true;
929 }
930 
931 void
933 {
934  INFO("Initial synchronization required");
935  s_InitiallySynced = false;
936 }
937 
938 void
940 {
941  s_CachingComplete = true;
945 }
946 
947 bool
949 {
950  return s_CachingComplete;
951 }
952 
953 bool
955 {
956  return s_DebugMode;
957 }
958 /*
959 unsigned int
960 CNCServer::GetDefConnTimeout(void)
961 {
962  return s_DefConnTimeout;
963 }
964 */
965 int
967 {
968  return s_DefBlobTTL;
969 }
970 
971 const string&
973 {
974  return s_AdminClient;
975 }
976 
978 {
979  if (s_HostRole.empty())
980  {
981  CNcbiIfstream in("/etc/ncbi/role");
982  if ( in.good() ) {
983  getline(in, s_HostRole);
984  }
985  }
986  return s_HostRole;
987 }
988 
990 {
991  if (s_HostLocation.empty())
992  {
993  CNcbiIfstream in("/etc/ncbi/location");
994  if ( in.good() ) {
995  getline(in, s_HostLocation);
996  }
997  }
998  return s_HostLocation;
999 }
1000 
1001 int
1003 {
1004  CSrvTime cur_time = CSrvTime::Current();
1005  cur_time -= CTaskServer::GetStartTime();
1006  return int(cur_time.Sec());
1007 }
1008 
1009 void
1011 {
1014  state.sync_log_size = CNCSyncLog::GetLogSize();
1016 }
1017 
1018 bool s_ReportPid(const string& pid_file)
1019 {
1020  s_PidFile = pid_file;
1021  CNcbiOfstream ofs(pid_file.c_str(), IOS_BASE::out | IOS_BASE::trunc );
1022  if (!ofs.is_open()) {
1023  return false;
1024  }
1025  ofs << CCurrentProcess::GetPid() << endl;
1026  return true;
1027 }
1028 
1029 
1031 
1032 
1034 
1035 
1036 int main(int argc, const char* argv[])
1037 {
1038  for (int i = 1; i < argc; ++i) {
1039  string param(argv[i]);
1040  if (param == "-version") {
1041  cout << NETCACHED_VERSION << endl;
1042  return 0;
1043  } else if (param == "-help") {
1044  cout << "Network data storage server" << endl;
1045  cout << "Arguments:" << endl;
1046  cout << "-conffile name - configuration file, default = netcached.ini" << endl;
1047  cout << "-logfile name - log file, default = netcached.log" << endl;
1048  cout << "-pidfile name - report process ID into this file" << endl;
1049  cout << "-reinit - reinitialize database, cleaning all data from it" << endl;
1050  cout << "-nodaemon - do not enter UNIX daemon mode" << endl;
1051  return 0;
1052  }
1053  }
1054 
1055  // Defaults that should be always set for NetCache
1056 #ifdef NCBI_OS_LINUX
1057  struct rlimit rlim;
1058  if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
1059  rlim.rlim_cur = RLIM_INFINITY;
1060  setrlimit(RLIMIT_CORE, &rlim);
1061  }
1062 #endif
1063 
1064  s_StoreStartupParams(argc, argv);
1067  if (!CTaskServer::Initialize(argc, argv) || !s_ReadServerParams()) {
1068  cerr << "Failed to initialize: conffile: " << GetConfName() << ", logfile: " << GetLogFileName() << endl;
1070  return 100;
1071  }
1072 
1074 
1075  bool is_daemon = true;
1076  bool is_reinit = false;
1077  string pid_file;
1078 
1079  for (int i = 1; i < argc; ++i) {
1080  string param(argv[i]);
1081  if (param == "-nodaemon") {
1082  is_daemon = false;
1083  } else if (param == "-reinit") {
1084  is_reinit = true;
1085  } else if (param == "-pidfile") {
1086  bool ok=false;
1087  if (i + 1 < argc) {
1088  pid_file = argv[++i];
1089  ok = !pid_file.empty() && pid_file[0] != '-' && s_ReportPid(pid_file);
1090  if (!ok) {
1091  CNCAlerts::Register(CNCAlerts::ePidFileFailed, pid_file + ": cannot write into");
1092  cerr << "Cannot write into pidfile: " << pid_file << endl;
1093  ERR_POST(Critical << "Cannot write into pidfile: " << pid_file);
1094  }
1095  }
1096  else {
1097  cerr << "Parameter -pidfile misses file name" << endl;
1098  ERR_POST(Critical << "Parameter -pidfile misses file name");
1099  }
1100  if (!ok) {
1102  return 122;
1103  }
1104  } else {
1105  cerr << "Unknown parameter: " << param << endl;
1106  ERR_POST(Critical << "Unknown parameter: " << param);
1108  return 150;
1109  }
1110  }
1111 
1112 #ifdef NCBI_OS_LINUX
1113  if (is_daemon) {
1114  cout << "Entering UNIX daemon mode..." << endl;
1115  INFO("Entering UNIX daemon mode...");
1116  // Here's workaround for SQLite3 bug: if stdin is closed in forked
1117  // process then 0 file descriptor is returned to SQLite after open().
1118  // But there's assert there which prevents fd to be equal to 0. So
1119  // we keep descriptors 0, 1 and 2 in child process open. Latter two -
1120  // just in case somebody will try to write to them.
1121  bool is_good = CProcess::Daemonize(kEmptyCStr,
1123  | CProcess::fKeepStdout) != 0;
1124  if (!is_good) {
1125  cerr << "Error during daemonization" << endl;
1126  SRV_LOG(Critical, "Error during daemonization");
1127  return 200;
1128  }
1129  }
1130 #endif
1131 
1132  if (!pid_file.empty()) {
1133  s_ReportPid(pid_file);
1134  }
1135  if (s_Initialize(is_reinit))
1136  CTaskServer::Run();
1137  s_Finalize();
1139 
1140  return 0;
1141 }
1142 
1143 /////////////////////////////////////////////////////////////////////////////
1144 // tests
1145 
1146 // Task generates and puts a lot of blobs into storage
1147 // Sort of, controlled environment...
1148 // no sockets, no communications, just a flood of data
1149 
1150 #if MAKE_TEST_BUILD
1151 
1152 static Uint4 MAKE_TEST_TASKS = 100;
1153 static Uint8 MAKE_TEST_MAXSIZE = 1000000;
1154 
1155 static Uint4 MAKE_TEST_DELAY = 1;
1156 static Uint4 MAKE_TEST_INTERVAL = 10;
1157 
1158 class CTest_BlobStorage : public CSrvStatesTask<CTest_BlobStorage>
1159 {
1160 public:
1161  CTest_BlobStorage(Uint4 id);
1162  virtual ~CTest_BlobStorage(void);
1163 
1164  State x_Start(void);
1165  State x_WaitForBlobAccess(void);
1166  State x_PutBegin(void);
1167  State x_PutBlobChunk(void);
1168  State x_PutEnd(void);
1169  State x_Remove(void);
1170  State x_Finalize(void);
1171  State x_Next(void);
1172  State x_Stop(void);
1173 
1174 private:
1175  void Reset(void);
1176  size_t PutData(void* buf, size_t size);
1177 
1178  bool IsTaskPaused(void);
1179  void PrintStat(void);
1180 
1181  bool m_Paused;
1182  Uint4 m_Id;
1183  Uint4 m_Counter;
1184  vector<string> m_Keys;
1185  Uint2 m_LocalPort;
1186  Uint2 m_BlobSlot;
1187  Uint2 m_TimeBucket;
1188 
1189  Uint8 m_DataSize;
1190  Uint8 m_BlobSize;
1191  Uint4 m_ChunkLen;
1192 
1193  CNCBlobAccessor* m_BlobAccess;
1194  string m_RawKey;
1195  CNCBlobKey m_BlobKey;
1196  size_t m_Command;
1197  CSrvTime m_CmdStartTime;
1198 
1199  const SNCSpecificParams* m_AppSetup;
1200 
1201  static CMiniMutex ms_RndLock;
1202  static CRandom ms_Rnd;
1203  static const char* ms_Commands[];
1204 
1205  friend void s_InitTests(void);
1206 };
1207 
1208 CMiniMutex CTest_BlobStorage::ms_RndLock;
1209 CRandom CTest_BlobStorage::ms_Rnd;
1210 const char* CTest_BlobStorage::ms_Commands[] = {"UNKNOWN", "PUT3", "REMO"};
1211 static const size_t s_Noop = 0;
1212 static const size_t s_Put3 = 1;
1213 static const size_t s_Remove = 2;
1214 
1215 static Uint4 s_CounterPut = 0;
1216 static Uint4 s_CounterRem = 0;
1217 static Uint8 s_SizePut = 0;
1218 static Uint8 s_SizeRem = 0;
1219 static CFutex s_ftxStop;
1220 static CFutex s_ftxCounter;
1221 
1222 /////////////////////////////////////////////////////////////////////////////
1223 
1224 void s_InitTests(void)
1225 {
1227  CTest_BlobStorage::ms_Rnd.SetSeed(seed);
1228  INFO("s_InitTests, seed: " << seed);
1229 
1230  for (Uint4 i=0; i < MAKE_TEST_TASKS; ++i) {
1231  new CTest_BlobStorage(i);
1232  }
1233 }
1234 
1235 /////////////////////////////////////////////////////////////////////////////
1236 
1237 CTest_BlobStorage::CTest_BlobStorage(Uint4 id)
1238 {
1239  m_Paused = false;
1240  m_Id = id;
1241  m_Counter = 0;
1242  m_AppSetup = CNCServer::GetAppSetup(TStringMap());
1243  Reset();
1244  SetState(&Me::x_Start);
1245  SetRunnable();
1246 }
1247 CTest_BlobStorage::~CTest_BlobStorage(void)
1248 {
1249 }
1250 
1251 void CTest_BlobStorage::Reset(void)
1252 {
1253  ++m_Counter;
1254 
1255  m_LocalPort = 9999;
1256  m_BlobSlot = 0;
1257  m_TimeBucket = 0;
1258 
1259  m_BlobAccess = nullptr;
1260  m_RawKey.clear();
1261  m_BlobKey.Clear();
1262  m_Command = 0;
1263 
1264  ms_RndLock.Lock();
1265  Uint4 rand1 = ms_Rnd.GetRand(0, MAKE_TEST_MAXSIZE);
1266  Uint4 rand2 = max( ms_Rnd.GetRand(1, (rand1+3)/4 + 1), rand1/100);
1267 #if 1
1268  if (m_Keys.size() > 10) {
1269  if (ms_Rnd.GetRand(1, 2) == 2) {
1270  shuffle(m_Keys.begin(), m_Keys.end(), default_random_engine());
1271  m_BlobKey.Assign( *m_Keys.begin());
1272  m_Keys.erase(m_Keys.begin());
1273  }
1274  }
1275 #else
1276  if (m_Counter == 2) {
1277  m_BlobKey = *m_Keys.begin();
1278  m_Keys.erase(m_Keys.begin());
1279  }
1280 #endif
1281  ms_RndLock.Unlock();
1282 
1283  m_DataSize = rand1;
1284  m_ChunkLen = rand2;
1285  m_BlobSize = 0;
1286 
1287  if (!m_BlobKey.IsValid()) {
1288  m_Command = s_Put3;
1289  } else {
1290  m_Command = s_Remove;
1291  }
1292 
1293 #if 0
1294  if (m_Counter > 2) {
1295  m_Command = s_Noop;
1296  }
1297 #endif
1298 }
1299 
1300 size_t CTest_BlobStorage::PutData(void* buf, size_t size)
1301 {
1302  memset(buf, 1, size);
1303  return size;
1304 }
1305 
1306 bool CTest_BlobStorage::IsTaskPaused(void)
1307 {
1308  if (m_Id == 0) {
1309  // "primary" task
1310  // stops all other test task
1311  // waits for them to stop
1312  // prints statistics
1313  // lets other tasks go
1314  if ((m_Counter % MAKE_TEST_INTERVAL) == 0) {
1315 
1316  // raise Stop sign
1317  if (!s_ftxStop.ChangeValue(0,1)) {
1318  abort();
1319  }
1320  int count=0;
1321  s_ftxCounter.AddValue(1);
1322  CSrvTime to;
1323 #ifdef NCBI_OS_LINUX
1324  to.tv_sec = 10;
1325 #endif
1326  // wait for other tasks
1327  while (s_ftxCounter.WaitValueChange(count, to) != CFutex::eTimedOut) {
1328  count = s_ftxCounter.GetValue();
1329  if (count == MAKE_TEST_TASKS) {
1330  break;
1331  }
1332  }
1333 /*
1334  if (count != MAKE_TEST_TASKS) {
1335 cout << "timeout" << endl;
1336  return false;
1337  }
1338 */
1339 
1340  PrintStat();
1341 
1342  // let'em go
1343  s_ftxCounter.ChangeValue(MAKE_TEST_TASKS, 0);
1344  s_ftxStop.ChangeValue(1,0);
1345 // s_ftxStop.WakeUpWaiters(MAKE_TEST_TASKS);
1346  }
1347  return false;
1348  }
1349  // "secondary" tasks
1350  // check Stop sign
1351  if (s_ftxStop.WaitValueChange(0, CSrvTime()) == CFutex::eTimedOut) {
1352  if (m_Paused) {
1353  m_Paused = false;
1354  }
1355  return m_Paused;
1356  }
1357  // Stop sign is there, report and stop
1358  if (!m_Paused) {
1359  m_Paused = true;
1360  s_ftxCounter.AddValue(1);
1361  s_ftxCounter.WakeUpWaiters(1);
1362  }
1363  return m_Paused;
1364 }
1365 
1366 void CTest_BlobStorage::PrintStat(void)
1367 {
1371 
1372 cout << endl;
1373 cout << "===============" << endl;
1374 cout << "s_CounterPut = " << s_CounterPut << endl;
1375 cout << "s_CounterRem = " << s_CounterRem << endl;
1376 cout << "blob expected = " << (s_CounterPut - s_CounterRem) << endl;
1377 cout << "s_SizePut = " << s_SizePut << endl;
1378 cout << "s_SizeRem = " << s_SizeRem << endl;
1379 cout << "size expected = " << (s_SizePut - s_SizeRem) << endl;
1380 cout << "===============" << endl;
1381 cout << "db_files = " << state.db_files << endl;
1382 cout << "cnt_blobs = " << state.cnt_blobs << endl;
1383 cout << "cnt_keys = " << state.cnt_keys << endl;
1384 
1385 cout << "state_time = " << CSrvTime::CurSecs() << endl;
1386 cout << "min_dead_time = " << state.min_dead_time << endl;
1387 
1388 cout << "db_size = " << state.db_size << endl;
1389 cout << "db_garb = " << state.db_garb << endl;
1390 cout << "inuse = " << state.db_size - state.db_garb << endl;
1391 cout << "wb_size = " << state.wb_size << endl;
1392 cout << "wb_releasable = " << state.wb_releasable << endl;
1393 cout << "wb_releasing = " << state.wb_releasing << endl;
1394 cout << "===============" << endl;
1395 }
1396 
1397 CTest_BlobStorage::State
1398 CTest_BlobStorage::x_Start(void)
1399 {
1400  m_CmdStartTime = CSrvTime::Current();
1401  CNCStat::CmdStarted(ms_Commands[m_Command]);
1402 
1403  if (m_Command == s_Put3) {
1404  CNCDistributionConf::GenerateBlobKey(m_LocalPort, m_RawKey, m_BlobSlot, m_TimeBucket);
1405  m_BlobKey.Assign(m_RawKey);
1406  m_Keys.push_back(m_RawKey);
1407  } else {
1408  CNCDistributionConf::GetSlotByRnd(m_BlobKey.GetRandomPart(), m_BlobSlot, m_TimeBucket);
1409  }
1410 
1411  m_BlobAccess = CNCBlobStorage::GetBlobAccess( eNCCreate, m_BlobKey.PackedKey(), "", m_TimeBucket);
1412  m_BlobAccess->RequestMetaInfo(this);
1413  return &CTest_BlobStorage::x_WaitForBlobAccess;
1414 }
1415 
1416 CTest_BlobStorage::State
1417 CTest_BlobStorage::x_WaitForBlobAccess(void)
1418 {
1419  if (!m_BlobAccess->IsMetaInfoReady()) {
1420  return NULL;
1421  }
1422  if (m_Command == s_Put3) {
1423  return &CTest_BlobStorage::x_PutBegin;
1424  }
1425  return &CTest_BlobStorage::x_Remove;
1426 }
1427 
1428 CTest_BlobStorage::State
1429 CTest_BlobStorage::x_PutBegin(void)
1430 {
1431  m_BlobAccess->SetBlobTTL(m_AppSetup->blob_ttl);
1432  m_BlobAccess->SetVersionTTL(0);
1433  m_BlobAccess->SetBlobVersion(0);
1434  return &CTest_BlobStorage::x_PutBlobChunk;
1435 }
1436 
1437 CTest_BlobStorage::State
1438 CTest_BlobStorage::x_PutBlobChunk(void)
1439 {
1440  Uint4 read_len = Uint4(m_BlobAccess->GetWriteMemSize());
1441  if (m_BlobAccess->HasError()) {
1442  abort();
1443  }
1444  if (read_len > m_ChunkLen) {
1445  read_len = m_ChunkLen;
1446  }
1447  if (read_len > m_DataSize) {
1448  read_len = (Uint4)m_DataSize;
1449  }
1450 
1451  Uint4 n_read = Uint4(PutData(m_BlobAccess->GetWriteMemPtr(), read_len));
1452  m_BlobAccess->MoveWritePos(n_read);
1453  m_DataSize -= n_read;
1454  m_BlobSize += n_read;
1455  CNCStat::ClientDataWrite(n_read);
1456 
1457  if (m_DataSize != 0) {
1458  SetRunnable();
1459  return NULL;
1460  }
1461  return &CTest_BlobStorage::x_PutEnd;
1462 }
1463 
1464 CTest_BlobStorage::State
1465 CTest_BlobStorage::x_PutEnd(void)
1466 {
1467  CSrvTime cur_srv_time = CSrvTime::Current();
1468  Uint8 cur_time = cur_srv_time.AsUSec();
1469  int cur_secs = int(cur_srv_time.Sec());
1470  m_BlobAccess->SetBlobCreateTime(cur_time);
1471  if (m_BlobAccess->GetNewBlobExpire() == 0)
1472  m_BlobAccess->SetNewBlobExpire(cur_secs + m_BlobAccess->GetNewBlobTTL());
1473  m_BlobAccess->SetNewVerExpire(cur_secs + m_BlobAccess->GetNewVersionTTL());
1474  m_BlobAccess->SetCreateServer(
1476  if (m_BlobAccess->HasError()) {
1477  abort();
1478  }
1480 }
1481 
1482 CTest_BlobStorage::State
1483 CTest_BlobStorage::x_Remove(void)
1484 {
1485  if (m_BlobAccess->IsBlobExists() && !m_BlobAccess->IsCurBlobExpired())
1486  {
1487  m_BlobSize = m_BlobAccess->GetCurBlobSize();
1488 
1489 // from
1490 // CNCMessageHandler::x_DoCmd_Remove
1491 #if 0
1492  m_BlobAccess->SetBlobTTL(m_AppSetup->blob_ttl);
1493 #else
1494  bool is_mirrored = CNCDistributionConf::CountServersForSlot(m_BlobSlot) != 0;
1496  unsigned int mirrored_ttl = is_good ? min(Uint4(300), m_AppSetup->blob_ttl) : m_AppSetup->blob_ttl;
1497  unsigned int local_ttl = 5;
1498  m_BlobAccess->SetBlobTTL( is_mirrored ? mirrored_ttl : local_ttl);
1499 #endif
1500 
1501  m_BlobAccess->SetBlobVersion(0);
1502  int expire = CSrvTime::CurSecs() - 1;
1503  unsigned int ttl = m_BlobAccess->GetNewBlobTTL();
1504 #if 0
1505  if (m_BlobAccess->IsBlobExists() && m_BlobAccess->GetCurBlobTTL() > ttl)
1506  ttl = m_BlobAccess->GetCurBlobTTL();
1507 #endif
1508  m_BlobAccess->SetNewBlobExpire(expire, expire + ttl + 1);
1509 
1510 // from
1511 // CNCMessageHandler::x_FinishReadingBlob
1512  CSrvTime cur_srv_time = CSrvTime::Current();
1513  Uint8 cur_time = cur_srv_time.AsUSec();
1514  int cur_secs = int(cur_srv_time.Sec());
1515  m_BlobAccess->SetBlobCreateTime(cur_time);
1516  if (m_BlobAccess->GetNewBlobExpire() == 0)
1517  m_BlobAccess->SetNewBlobExpire(cur_secs + m_BlobAccess->GetNewBlobTTL());
1518  m_BlobAccess->SetNewVerExpire(cur_secs + m_BlobAccess->GetNewVersionTTL());
1519  m_BlobAccess->SetCreateServer(CNCDistributionConf::GetSelfID(),
1521  }
1523 }
1524 
1525 CTest_BlobStorage::State
1527 {
1528  if (m_Command == s_Put3) {
1529  AtomicAdd(s_CounterPut, 1);
1530  AtomicAdd(s_SizePut, m_BlobSize);
1531  } else {
1532  AtomicAdd(s_CounterRem, 1);
1533  AtomicAdd(s_SizeRem, m_DataSize);
1534  }
1535 
1536  m_BlobAccess->Finalize();
1537  m_BlobAccess->Release();
1538  m_BlobAccess = NULL;
1539 
1540  CSrvTime cmd_len = CSrvTime::Current();
1541  cmd_len -= m_CmdStartTime;
1542  Uint8 len_usec = cmd_len.AsUSec();
1543  CNCStat::CmdFinished(ms_Commands[m_Command], len_usec, eStatus_OK);
1544  CNCStat::ClientBlobWrite(m_BlobSize, len_usec);
1545 
1546  return &CTest_BlobStorage::x_Next;
1547 }
1548 
1549 CTest_BlobStorage::State
1550 CTest_BlobStorage::x_Next(void)
1551 {
1552  if (CTaskServer::IsInShutdown()) {
1553  return &CTest_BlobStorage::x_Stop;
1554  }
1555  if (IsTaskPaused()) {
1556  SetRunnable();
1557  return NULL;
1558  }
1559  Reset();
1560  if (m_Command != s_Noop) {
1561  SetState(&Me::x_Start);
1562  if (MAKE_TEST_DELAY != 0) {
1563  RunAfter(MAKE_TEST_DELAY);
1564  } else {
1565  SetRunnable();
1566  }
1567  }
1568  return NULL;
1569 }
1570 
1571 CTest_BlobStorage::State
1572 CTest_BlobStorage::x_Stop(void)
1573 {
1574  Terminate();
1575  return NULL;
1576 }
1577 
1578 #endif //MAKE_TEST_BUILD
1579 
CFile –.
Definition: ncbifile.hpp:1605
Wrapper around Linux's futex.
Definition: srv_sync.hpp:141
EWaitResult WaitValueChange(int old_value)
Wait for futex's value to change (with and without timeout).
Definition: srv_sync.cpp:44
int GetValue(void)
Read value of the futex.
Definition: srv_sync.hpp:238
@ eTimedOut
Method returned because total waiting time exceeded given timeout.
Definition: srv_sync.hpp:169
bool ChangeValue(int old_value, int new_value)
Atomically change value of the futex.
Definition: srv_sync.hpp:244
int WakeUpWaiters(int cnt_to_wake)
Wake up some threads waiting on this futex.
Definition: srv_sync.cpp:98
int AddValue(int cnt_to_add)
Atomically add some amount to futex's value.
Definition: srv_sync.hpp:250
Mutex created to have minimum possible size (its size is 4 bytes) and to sleep using kernel capabilit...
Definition: srv_sync.hpp:193
static void Initialize(void)
static void Register(EAlertType alert_type, const string &message)
Definition: nc_utils.cpp:188
@ ePidFileFailed
Reporting Pid failed.
Definition: nc_utils.hpp:187
@ eStartupConfigChanged
Configuration file changed.
Definition: nc_utils.hpp:186
static bool UpdatePurgeData(const string &data, char separator='\n')
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
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
void Clear(void)
Definition: netcached.cpp:174
void UnpackBlobKey(void)
Definition: netcached.cpp:195
void SetKeyVersion(unsigned int v)
Definition: netcached.hpp:200
void Assign(const CTempString &cache_name, const CTempString &blob_key, const CTempString &blob_subkey)
Definition: netcached.cpp:228
static void SaveMaxSyncLogRecNo(void)
static Uint8 GetMaxSyncLogRecNo(void)
static void MeasureDB(SNCStateStat &state)
static string GetPurgeData(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 bool Initialize(bool do_reinit)
static Uint8 GetMaxBlobSizeStore(void)
static bool IsCleanStart(void)
static void CheckDiskSpace(void)
static Uint4 GetNewBlobId(void)
static void GenerateBlobKey(Uint2 local_port, string &key, Uint2 &slot, Uint2 &time_bucket, unsigned int ver=1)
static void GetSlotByRnd(Uint4 key_rnd, Uint2 &slot, Uint2 &time_bucket)
static void Finalize(void)
static size_t CountServersForSlot(Uint2 slot)
static Uint8 GetMaxBlobSizeSync(void)
static Uint8 GetSelfID(void)
static bool Initialize(Uint2 control_port)
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
static void Finalize(void)
static bool HasPeerInThrottle(void)
static bool Initialize(void)
static void ReadCurState(SNCStateStat &state)
static void Finalize(void)
static bool Initialize(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
static void CmdFinished(const char *cmd, Uint8 len_usec, int status)
Definition: nc_stat.cpp:474
static void SaveCurStateStat(const SNCStateStat &state)
Definition: nc_stat.cpp:610
static void CmdStarted(const char *cmd)
Definition: nc_stat.cpp:464
static void DumpAllStats(void)
Definition: nc_stat.cpp:1108
static void ClientBlobWrite(Uint8 blob_size, Uint8 len_usec)
Definition: nc_stat.cpp:507
static void ClientDataWrite(size_t data_size)
Definition: nc_stat.cpp:495
static void Initialize(void)
Definition: nc_stat.cpp:197
static void Initialize(bool need_read_saved, Uint8 start_log_rec_no)
Definition: sync_log.cpp:450
static bool Finalize(void)
Definition: sync_log.cpp:522
static Uint8 GetLogSize(void)
Definition: sync_log.cpp:772
CNcbiRegistry –.
Definition: ncbireg.hpp:913
CObject –.
Definition: ncbiobj.hpp:180
CRandom::
Definition: random_gen.hpp:66
static void Initialize(void)
Initialization of SQLite and tuning some default parameters.
static void Finalize(void)
Finish all SQLite operations.
Task controlling a socket.
CSrvSocketTask & WriteText(CTempString message)
Write text into socket.
CSrvSocketTask & WriteNumber(NumType num)
Write number into socket as string, i.e.
Special task which executes as finite state machine.
Definition: srv_tasks.hpp:283
void RunAfter(Uint4 delay_sec)
This call is basically equivalent to SetRunnable() but with guarantee that task will be scheduled for...
Definition: timers.cpp:216
void SetRunnable(bool boost=false)
Set this task "runnable", i.e.
Definition: scheduler.cpp:618
Class incorporating convenient methods to work with struct timespec.
Definition: srv_time.hpp:61
static int CurSecs(void)
Current time in seconds since epoch (time_t).
time_t & Sec(void)
Read/set number of seconds since epoch stored in the object.
static CSrvTime Current(void)
Exact current time with precision up to nanoseconds.
Uint8 AsUSec(void) const
Converts object's value to microseconds since epoch.
CStringException –.
Definition: ncbistr.hpp:4508
static const CNcbiRegistry & GetConfRegistry(void)
Obtains reference to registry read from application's ini-file.
static const string & GetHostName(void)
Returns name of server this application is executing on.
static void RequestShutdown(ESrvShutdownType shutdown_type)
Asks server to start shutdown procedures.
static bool AddListeningPort(Uint2 port, CSrvSocketFactory *factory)
Adds port for TaskServer to listen to.
static CSrvTime GetStartTime(void)
Returns time when this server application was started (when Initialize() method was called).
static void Finalize(void)
Finalizes TaskServer infrastructure.
static bool IsInShutdown(void)
Checks if TaskServer received request to shutdown.
static bool Initialize(int &argc, const char **argv)
Initializes TaskServer infrastructure from given command line arguments.
static void Run(void)
Run all TaskServer machinery.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTime –.
Definition: ncbitime.hpp:296
static void Initialize(void)
static void ReadState(SNCStateStat &state)
IRegistry –.
Definition: ncbireg.hpp:73
TNCBufferType & WriteNumber(NumType num)
Definition: nc_utils.hpp:75
TNCBufferType & WriteText(const char *buf)
Definition: nc_utils.hpp:66
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
size_type size() const
Definition: set.hpp:132
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
The NCBI C++ standard methods for dealing with std::string.
static unsigned char depth[2 *(256+1+29)+1]
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static int trunc
Definition: array_out.c:8
static char tmp[3200]
Definition: utf8.c:42
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void Critical(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1203
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
static string NormalizePath(const string &path, EFollowLinks follow_links=eIgnoreLinks)
Normalize a path.
Definition: ncbifile.cpp:820
static bool IsAbsolutePath(const string &path)
Check if a "path" is absolute for the current OS.
Definition: ncbifile.cpp:508
Int8 GetLength(void) const
Get size of file.
Definition: ncbifile.cpp:3204
bool GetTimeT(time_t *modification, time_t *last_access=0, time_t *creation=0) const
Get time stamp(s) of a directory entry (time_t version).
Definition: ncbifile.cpp:2017
static string ConcatPath(const string &first, const string &second)
Concatenate two parts of the path for the current OS.
Definition: ncbifile.cpp:776
static string GetCwd(void)
Get the current working directory.
Definition: ncbifile.cpp:3708
bool GetTime(CTime *modification, CTime *last_access=0, CTime *creation=0) const
Get time stamp(s) of a directory entry.
Definition: ncbifile.cpp:1840
virtual bool Exists(void) const
Check existence of file.
Definition: ncbifile.hpp:4039
static bool ParseBlobKey(const char *key_str, size_t key_len, CNetCacheKey *key_obj, CCompoundIDPool::TInstance id_pool=NULL)
Parse blob key string into a CNetCacheKey structure.
bool HasExtensions() const
unsigned GetVersion() const
string StripKeyExtensions() const
If the blob key has been parsed successfully, this method returns a trimmed "base" version of the key...
TObjectType * GetNCPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1174
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
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
static TPid Daemonize(const char *logfile=0, TDaemonFlags flags=0)
Go daemon.
static TPid GetPid(void)
Get process identifier (pid) for the current process.
Uint4 TValue
Type of the generated integer value and/or the seed value.
Definition: random_gen.hpp:69
void SetSeed(TValue seed)
Seed the random number generator with "seed".
Definition: random_gen.cpp:287
virtual bool GetBool(const string &section, const string &name, bool default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get boolean value of specified parameter name.
Definition: ncbireg.cpp:391
virtual void EnumerateSections(list< string > *sections, TFlags flags=fAllLayers) const
Enumerate section names.
Definition: ncbireg.cpp:497
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
virtual int GetInt(const string &section, const string &name, int default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get integer value of specified parameter name.
Definition: ncbireg.cpp:362
virtual bool HasEntry(const string &section, const string &name=kEmptyStr, TFlags flags=0) const
Definition: ncbireg.cpp:290
virtual string GetString(const string &section, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
Definition: ncbireg.cpp:321
@ fCountCleared
Let explicitly cleared entries stand.
Definition: ncbireg.hpp:94
#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::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
#define kEmptyStr
Definition: ncbistr.hpp:123
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
Definition: ncbistr.cpp:2984
#define NPOS
Definition: ncbistr.hpp:133
CTempString & assign(const char *src_str, size_type len)
Assign new values to the content of the a string.
Definition: tempstr.hpp:733
static const string BoolToString(bool value)
Convert bool to string.
Definition: ncbistr.cpp:2806
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5086
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2699
const char * data(void) const
Return a pointer to the array represented.
Definition: tempstr.hpp:313
static string UInt8ToString_DataSize(Uint8 value, TNumToStringFlags flags=0, unsigned int max_digits=3)
Convert UInt8 to string using "software" qualifiers.
Definition: ncbistr.hpp:5179
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5414
void clear(void)
Clears the string.
Definition: tempstr.hpp:351
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
Definition: ncbistr.cpp:68
size_type size(void) const
Return the length of the represented array.
Definition: tempstr.hpp:327
@ eMergeDelims
Definition: ncbistr.hpp:2517
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1512
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
char * buf
int i
int len
string GetLogFileName(void)
Definition: logging.cpp:146
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
const CharType(& source)[N]
Definition: pointer.h:1149
void SetWBInitialSyncComplete(void)
void InitClientMessages(void)
Initializes maps between status codes and error texts sent to client to explain these codes.
Definition: nc_utils.cpp:74
map< string, string > TStringMap
Definition: nc_utils.hpp:59
@ eStatus_OK
Command is ok and execution is good.
Definition: nc_utils.hpp:115
@ eNCCreate
Create blob or re-write its contents.
Definition: nc_utils.hpp:89
static void x_Finalize(SERV_ITER iter)
Definition: ncbi_lbdns.c:1148
Defines process management classes.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Process information in the NCBI Registry, including working with configuration files.
#define NETCACHED_FULL_VERSION
#define NETCACHED_VERSION
static const char * kNCReg_Quorum
Definition: netcached.cpp:90
static const char * kNCReg_SearchOnRead
Definition: netcached.cpp:89
static const char * kNCReg_FastOnMain
Definition: netcached.cpp:91
static const char * kNCReg_VerTTL
Definition: netcached.cpp:86
static const char * kNCReg_SpecPriority
Definition: netcached.cpp:78
static const char * kNCReg_ServerSection
Definition: netcached.cpp:73
static const char * kNCReg_AppSetupValue
Definition: netcached.cpp:94
static bool s_DebugMode
Definition: netcached.cpp:121
static void s_StoreStartupParams(int argc, const char *argv[])
Definition: netcached.cpp:132
set< unsigned int > TPortsList
Definition: netcached.cpp:97
static const char * kNCReg_TTLUnit
Definition: netcached.cpp:87
static Uint4 s_CtrlPort
Definition: netcached.cpp:114
static void s_Finalize(void)
Definition: netcached.cpp:670
static const char * kNCReg_LifespanTTL
Definition: netcached.cpp:83
static const char * kNCReg_ProlongOnRead
Definition: netcached.cpp:88
static int s_CompareStrings(const string &left, const string &right)
Definition: netcached.cpp:317
static const char * kNCReg_BlobTTL
Definition: netcached.cpp:85
static bool s_ReadServerParams(void)
Definition: netcached.cpp:568
static const char * kNCReg_DefAdminClient
Definition: netcached.cpp:77
static string s_PidFile
Definition: netcached.cpp:126
static CNCMsgHandler_Factory s_MsgHandlerFactory
Definition: netcached.cpp:124
static void s_ReadPerClientConfig(const CNcbiRegistry &reg)
Definition: netcached.cpp:477
static const char * kNCReg_MaxTTL
Definition: netcached.cpp:84
static int s_DefBlobTTL
Definition: netcached.cpp:120
static void s_ReadSpecificParams(const IRegistry &reg, const string &section, SNCSpecificParams *params, vector< string > &keys)
Definition: netcached.cpp:343
static const char * kNCReg_DefSpecPriority
Definition: netcached.cpp:79
static void s_CollectClientConfigKeys(SSpecParamsSet *cur_set, SSpecParamsSet *prev_set, Uint1 depth, SSpecParamsSet *deflt, vector< string > &keys)
Definition: netcached.cpp:754
static const char * kNCReg_DisableClient
Definition: netcached.cpp:81
bool s_ReportPid(const string &pid_file)
Definition: netcached.cpp:1018
static const char * kNCReg_PassPolicy
Definition: netcached.cpp:92
static CSrvRef< SSpecParamsSet > s_SpecParams
Definition: netcached.cpp:118
static TPortsList s_Ports
Port where server runs.
Definition: netcached.cpp:113
static bool s_CachingComplete
Definition: netcached.cpp:123
static CNCHeartBeat * s_HeartBeat
Definition: netcached.cpp:125
static string s_AdminClient
Name of client that should be used for administrative commands.
Definition: netcached.cpp:116
static SSpecParamsSet * s_FindNextParamsSet(const SSpecParamsSet *cur_set, const string &key, unsigned int &best_index)
Definition: netcached.cpp:430
vector< string > TSpecKeysList
Definition: netcached.cpp:98
static string s_CmdLineArgs
Definition: netcached.cpp:130
static const char * kNCReg_AppSetupPrefix
Definition: netcached.cpp:93
static TSpecKeysList s_SpecPriority
Definition: netcached.cpp:117
static void s_CheckDefClientConfig(SSpecParamsSet *cur_set, SSpecParamsSet *prev_set, Uint1 depth, SSpecParamsSet *deflt)
Definition: netcached.cpp:454
static const char * kNCReg_CtrlPort
Definition: netcached.cpp:75
int main(int argc, const char *argv[])
Definition: netcached.cpp:1036
static string s_AppPath
Definition: netcached.cpp:129
static void s_PutNewParams(SSpecParamsSet *params_set, unsigned int best_index, const SSpecParamsEntry &entry)
Definition: netcached.cpp:422
USING_NCBI_SCOPE
Definition: netcached.cpp:1033
static string s_HostRole
Definition: netcached.cpp:127
static string s_HostLocation
Definition: netcached.cpp:128
static bool s_Initialize(bool do_reinit)
Definition: netcached.cpp:607
static bool s_InitiallySynced
Definition: netcached.cpp:122
static const char * kNCReg_Ports
Definition: netcached.cpp:74
static const char * kNCReg_AdminClient
Definition: netcached.cpp:76
@ 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
T max(T x_, T y_)
T min(T x_, T y_)
Int mod(Int i, Int j)
Definition: njn_integer.hpp:67
std::istream & in(std::istream &in_, double &x_)
void abort()
string GetConfName(void)
static CNamedPipeClient * client
#define INFO(msg)
Macro to be used for printing informational messages.
Definition: srv_diag.hpp:182
#define SRV_LOG(sev, msg)
Macro to be used for printing log messages.
Definition: srv_diag.hpp:162
T AtomicAdd(T volatile &var, T add_value)
Definition: srv_sync.hpp:69
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
virtual ~SNCSpecificParams(void)
Definition: netcached.cpp:326
SSpecParamsEntry(const string &key, CObject *value)
Definition: netcached.cpp:331
CSrvRef< CObject > value
Definition: netcached.cpp:101
vector< SSpecParamsEntry > entries
Definition: netcached.cpp:106
virtual ~SSpecParamsSet(void)
Definition: netcached.cpp:338
Uint2 TSrvThreadNum
Type for thread number in TaskServer.
Definition: task_server.hpp:42
@ eSrvFastShutdown
static int seed
Definition: test_table.cpp:132
else result
Definition: token2.c:20
Modified on Tue Jul 16 13:23:28 2024 by modify_doxy.py rev. 669887