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

Go to the SVN repository for this file.

1 /* $Id: netcache_api.cpp 90047 2020-05-06 16:16:59Z sadyrovr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Anatoliy Kuznetsov, Maxim Didenko, Dmitry Kazimirov
27  *
28  * File Description:
29  * Implementation of the NetCache client API.
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #ifdef _MSC_VER
36 // Disable warning C4191: 'type cast' :
37 // unsafe conversion from 'ncbi::CDll::FEntryPoint'
38 // to 'void (__cdecl *)(...)' [comes from plugin_manager.hpp]
39 #pragma warning (disable: 4191)
40 #endif
41 
42 #include "netschedule_api_impl.hpp"
43 #include "netcache_api_impl.hpp"
44 
48 
50 
51 #include <corelib/ncbitime.hpp>
52 #include <corelib/ncbi_system.hpp>
53 #include <corelib/request_ctx.hpp>
56 #include <corelib/rwstream.hpp>
57 
58 #include <memory>
59 
60 
61 #define NCBI_USE_ERRCODE_X ConnServ_NetCache
62 
63 
65 
67 {
69 
70  static const TAddress* Get()
71  {
72  static const TAddress address(Init());
73  return address.host ? &address : nullptr;
74  }
75 
76 private:
77  static TAddress Init();
78 };
79 
81 {
82  try {
83  return TAddress::Parse(TCGI_NetCacheFallbackServer::GetDefault());
84  } catch (...) {
85  }
86 
87  return TAddress(0, 0);
88 }
89 
91 {
92  return [] { return new SNetCacheServerProperties; };
93 }
94 
96 {
97  return new CNetCacheServerListener(*this);
98 }
99 
101 {
103 
104  if (m_Service->GetClientName().length() < 3) {
106  eAuthenticationError, "Client name is too short or empty");
107  }
108 
109  m_TempDir = registry.Get(sections, { "tmp_dir", "tmp_path" }, ".");
110  m_CacheInput = registry.Get(sections, "cache_input", false);
111  m_CacheOutput = registry.Get(sections, "cache_output", false);
112  const bool prolong_on_write = registry.Get(sections, "prolong_blob_lifetime_on_write", true);
113  const bool create_on_write = registry.Get(sections, "create_blob_on_write", true);
114 
115  m_DefaultParameters.SetMirroringMode( registry.Get(sections, "enable_mirroring", kEmptyStr));
116  m_DefaultParameters.SetServerCheck( registry.Get(sections, "server_check", kEmptyStr));
117  m_DefaultParameters.SetServerCheckHint(registry.Get(sections, "server_check_hint", kEmptyStr));
118  m_DefaultParameters.SetUseCompoundID( registry.Get(sections, "use_compound_id", false));
119 
120  const auto allowed_services = registry.Get(sections, "allowed_services", kEmptyStr);
121 
122  m_FlagsOnWrite = (prolong_on_write ? 0 : 1) | (create_on_write ? 0 : 2);
123 
124  if (allowed_services.empty()) return;
125 
127 
128  vector<string> services;
129  NStr::Split(allowed_services, ", ", services,
131 
132  for (auto& service : services) {
133  // Do not add configured service, it is always allowed
134  if (NStr::CompareNocase(service,
136  m_ServiceMap.AddToAllowed(service);
137  }
138  }
139 }
140 
142 {
143  auto server_props = connection->m_Server->Get<SNetCacheServerProperties>();
144 
145  CFastMutexGuard guard(server_props->m_Mutex);
146 
147  if (server_props->mirroring_checked) {
148  guard.Release();
149  connection->WriteLine(m_Auth);
150  } else {
151  string version_info(connection.Exec(m_Auth + "\r\nVERSION", false));
152 
153  server_props->mirroring_checked = true;
154 
155  try {
156  CUrlArgs url_parser(version_info);
157 
158  ITERATE(CUrlArgs::TArgs, field, url_parser.GetArgs()) {
159  if (field->name == "mirrored" && field->value == "true")
160  server_props->mirrored = true;
161  }
162  }
163  catch (CException&) {
164  }
165  }
166 }
167 
168 void CNetCacheServerListener::OnErrorImpl(const string& err_msg, CNetServer& server)
169 {
170  static const char s_BlobNotFoundMsg[] = "BLOB not found";
171  if (NStr::strncmp(err_msg.c_str(), s_BlobNotFoundMsg,
172  sizeof(s_BlobNotFoundMsg) - 1) == 0) {
173  if (strstr(err_msg.c_str(), "AGE=") != NULL) {
175  server, err_msg);
176  } else {
177  CONNSERV_THROW_FMT(CNetCacheException, eBlobNotFound,
178  server, err_msg);
179  }
180  }
181 
182  static const char s_AccessDenied[] = "Access denied";
183  if (NStr::strncmp(err_msg.c_str(), s_AccessDenied,
184  sizeof(s_AccessDenied) - 1) == 0)
185  CONNSERV_THROW_FMT(CNetCacheException, eAccessDenied, server, err_msg);
186 
187  static const char s_UnknownCommandMsg[] = "Unknown command";
188  if (NStr::strncmp(err_msg.c_str(), s_UnknownCommandMsg,
189  sizeof(s_UnknownCommandMsg) - 1) == 0)
190  CONNSERV_THROW_FMT(CNetCacheException, eUnknownCommand, server, err_msg);
191 
192  CONNSERV_THROW_FMT(CNetCacheException, eServerError, server, err_msg);
193 }
194 
195 void CNetCacheServerListener::OnWarningImpl(const string& warn_msg,
196  CNetServer& server)
197 {
198  ERR_POST(Warning << "NetCache server at "
199  << server->m_ServerInPool->m_Address.AsString() <<
200  ": WARNING: " << warn_msg);
201 }
202 
203 const char* const kNetCacheAPIDriverName = "netcache_api";
204 
205 SNetCacheAPIImpl::SNetCacheAPIImpl(CSynRegistryBuilder registry_builder, const string& section,
206  const string& service, const string& client_name,
208  m_NetScheduleAPI(ns_api),
209  m_DefaultParameters(eVoid)
210 {
211  SRegSynonyms sections{ section, kNetCacheAPIDriverName, "netcache_client", "netcache" };
212 
213  string ns_client_name;
214 
215  if (ns_api) {
216  ns_client_name = ns_api->m_Service->GetClientName();
217 
218  CNetScheduleConfigLoader loader(registry_builder, sections, false);
219  loader(ns_api);
220  }
221 
222  m_Service = SNetServiceImpl::Create("NetCacheAPI", service, client_name,
224  registry_builder, sections, ns_client_name);
225  Init(registry_builder, sections);
226 }
227 
229  m_DefaultParameters(eVoid)
230 {
231 }
232 
234  SNetCacheAPIImpl* parent) :
235  m_Service(SNetServiceImpl::Clone(server, parent->m_Service)),
236  m_ServiceMap(parent->m_ServiceMap),
237  m_TempDir(parent->m_TempDir),
238  m_CacheInput(parent->m_CacheInput),
239  m_CacheOutput(parent->m_CacheOutput),
240  m_NetScheduleAPI(parent->m_NetScheduleAPI),
241  m_DefaultParameters(parent->m_DefaultParameters)
242 {
243 }
244 
246 {
247  _ASSERT(cmd);
248 
249  // XXX: A workaround for IP always required
250  // TODO: Remove after all NetCache servers upgraded to include CXX-9580 and CXX-9720
251  if (!req.IsSetClientIP()) *cmd += " ip=\"\"";
252 
254 }
255 
257  const CNetCacheAPIParameters* parameters)
258 {
259  _ASSERT(cmd);
260 
263 
264  string password(parameters->GetPassword());
265  if (!password.empty()) {
266  cmd->append(" pass=\"");
267  cmd->append(NStr::PrintableString(password));
268  cmd->append(1, '\"');
269  }
270 
271  unsigned max_age = parameters->GetMaxBlobAge();
272  if (max_age > 0) {
273  cmd->append(" age=");
274  cmd->append(NStr::NumericToString(max_age));
275  }
276 
277  AppendHitID(cmd, req);
278 }
279 
281 {
282  _ASSERT(cmd);
283 
284  g_AppendHitID(*cmd, req);
285 }
286 
288 {
291  AppendHitID(cmd, req);
292 }
293 
294 string SNetCacheAPIImpl::MakeCmd(const char* cmd_base, const CNetCacheKey& key,
295  const CNetCacheAPIParameters* parameters)
296 {
297  string result(cmd_base + key.StripKeyExtensions());
299  return result;
300 }
301 
303  const CNetServer::SExecResult& exec_result, const char* cmd_name)
304 {
305  string::size_type pos = exec_result.response.find("AGE=");
306 
307  if (pos == string::npos) {
308  CONNSERV_THROW_FMT(CNetCacheException, eInvalidServerResponse,
309  exec_result.conn->m_Server,
310  "No AGE field in " << cmd_name <<
311  " output: \"" << exec_result.response << "\"");
312  }
313 
314  return NStr::StringToUInt(exec_result.response.c_str() + pos +
315  sizeof("AGE=") - 1, NStr::fAllowTrailingSymbols);
316 }
317 
319 {
322 
323  m_Iterator = NULL;
324  return m_PrimaryServer;
325 }
326 
328 {
329  if (!m_Iterator) {
331  CNetServer first_server = *m_Iterator;
332  if (first_server->m_ServerInPool != m_PrimaryServer->m_ServerInPool)
333  return first_server;
334  }
335  return ++m_Iterator ? *m_Iterator : CNetServer();
336 }
337 
339  const CNetCacheKey& key, const string& cmd,
340  bool multiline_output,
341  const CNetCacheAPIParameters* parameters,
343 {
344  const string& key_service_name = key.GetServiceName();
345 
346  bool key_has_service_name = !key_service_name.empty();
347 
348  CNetService service(m_Service);
349 
350  if (key_has_service_name && key_service_name != service.GetServiceName()) {
351  // NB: Configured service is always allowed
352 
353  if (!m_ServiceMap.IsAllowed(key_service_name)) {
354  NCBI_THROW_FMT(CNetCacheException, eAccessDenied, "Service " <<
355  key_service_name << " is not in the allowed services");
356  }
357 
358  service = m_ServiceMap.GetServiceByName(key_service_name, m_Service);
359  }
360 
361  bool mirroring_allowed =
364 
365  if (key.GetVersion() == 3) {
366  /* Version 3 - no server address, only CRC32 of it: */
367  if (!service.IsLoadBalanced()) {
368  NCBI_THROW_FMT(CNetSrvConnException, eLBNameNotFound,
369  key.GetKey() << ": NetCache key version 3 "
370  "requires an LBSM service name.");
371  }
372 
373  Uint4 crc32 = key.GetHostPortCRC32();
374 
376  it; ++it) {
377  CNetServer server(*it);
378 
380  CSocketAPI::ntoa(server.GetHost()),
381  server.GetPort()) == crc32) {
382  // The server with the checksum from the key
383  // has been found in the service.
384 
385  // TODO: cache the calculated checksums to resolve
386  // them into host:port immediately.
387 
388  if (!mirroring_allowed)
389  return server.ExecWithRetry(cmd, multiline_output);
390 
391  CNetServer::SExecResult exec_result;
392 
393  SNetCacheMirrorTraversal mirror_traversal(service,
394  server, eOff /* turn off server check since
395  the server is discovered
396  through this service */);
397 
398  service->IterateUntilExecOK(cmd, multiline_output,
399  exec_result, &mirror_traversal, error_handling);
400 
401  return exec_result;
402  }
403  }
404 
405  if (mirroring_allowed) {
406  // Original server either is down or has a different port (thus crc32 mismatch),
407  // will use any server from this service
408  return service->FindServerAndExec(cmd, multiline_output);
409  }
410 
411  NCBI_THROW_FMT(CNetSrvConnException, eServerNotInService,
412  key.GetKey() << ": unable to find a NetCache server "
413  "by the checksum from this key.");
414  }
415 
416  CNetServer primary_server(service.GetServer(key.GetHost(), key.GetPort()));
417 
418  ESwitch server_check = eDefault;
419  parameters->GetServerCheck(&server_check);
420  if (server_check == eDefault)
421  server_check = key.GetFlag(CNetCacheKey::fNCKey_NoServerCheck) ?
422  eOff : eOn;
423 
424  if (key_has_service_name && mirroring_allowed) {
425  CNetServer::SExecResult exec_result;
426 
427  SNetCacheMirrorTraversal mirror_traversal(service,
428  primary_server, server_check);
429 
430  service->IterateUntilExecOK(cmd, multiline_output, exec_result,
431  &mirror_traversal, error_handling);
432 
433  return exec_result;
434  }
435 
436  // If enabled, check if the server belongs to the selected service
437  if (server_check != eOff && !service->IsInService(primary_server)) {
438 
439  // Service name is known, no need to check other services
440  if (key_has_service_name) {
441  NCBI_THROW_FMT(CNetSrvConnException, eServerNotInService,
442  key.GetKey() << ": NetCache server " <<
443  primary_server.GetServerAddress() << " could not be "
444  "accessed because it is not registered for the service.");
445 
446  // Service name is not known,
447  // check if the server belongs to one of the explicitly allowed services
448  } else if (!m_ServiceMap.IsAllowed(primary_server, m_Service)) {
449  NCBI_THROW_FMT(CNetCacheException, eAccessDenied,
450  key.GetKey() << ": NetCache server " <<
451  primary_server.GetServerAddress() << " could not be "
452  "accessed because it is not registered for the allowed "
453  "services.");
454  }
455 
456  }
457 
458  return primary_server.ExecWithRetry(cmd, multiline_output);
459 }
460 
462  const string& conf_section /* = kEmptyStr */,
464  m_Impl(new SNetCacheAPIImpl(NULL, conf_section,
465  kEmptyStr, kEmptyStr, ns_api))
466 {
467 }
468 
469 CNetCacheAPI::CNetCacheAPI(const IRegistry& reg, const string& conf_section,
471  m_Impl(new SNetCacheAPIImpl(reg, conf_section,
472  kEmptyStr, kEmptyStr, ns_api))
473 {
474 }
475 
476 CNetCacheAPI::CNetCacheAPI(CConfig* conf, const string& conf_section,
478  m_Impl(new SNetCacheAPIImpl(conf, conf_section,
479  kEmptyStr, kEmptyStr, ns_api))
480 {
481 }
482 
483 CNetCacheAPI::CNetCacheAPI(const string& client_name,
485  m_Impl(new SNetCacheAPIImpl(NULL,
486  kEmptyStr, kEmptyStr, client_name, ns_api))
487 {
488 }
489 
490 CNetCacheAPI::CNetCacheAPI(const string& service_name,
491  const string& client_name, CNetScheduleAPI::TInstance ns_api) :
492  m_Impl(new SNetCacheAPIImpl(NULL,
493  kEmptyStr, service_name, client_name, ns_api))
494 {
495 }
496 
498 {
499  m_Impl->m_DefaultParameters.LoadNamedParameters(parameters);
500 }
501 
502 string CNetCacheAPI::PutData(const void* buf, size_t size,
503  const CNamedParameterList* optional)
504 {
505  return PutData(kEmptyStr, buf, size, optional);
506 }
507 
509  CNetCacheWriter* nc_writer, const CNetCacheAPIParameters* parameters)
510 {
511  string cmd("PUT3 ");
512  cmd.append(NStr::IntToString(parameters->GetTTL()));
513 
514  const string& blob_id(nc_writer->GetBlobID());
515 
516  const bool write_existing_blob = !blob_id.empty();
518  string stripped_blob_id;
519 
520  if (write_existing_blob) {
521  key.Assign(blob_id, m_CompoundIDPool);
522  cmd.push_back(' ');
523  stripped_blob_id = key.StripKeyExtensions();
524  cmd.append(stripped_blob_id);
525  }
526 
528  if (m_FlagsOnWrite) cmd.append(" flags=").append(to_string(m_FlagsOnWrite));
529 
530  CNetServer::SExecResult exec_result;
531 
532  if (write_existing_blob)
533  exec_result = ExecMirrorAware(key, cmd, false, parameters,
535  else {
536  try {
537  exec_result = m_Service.FindServerAndExec(cmd, false);
538  } catch (CNetSrvConnException& e) {
539  const SSocketAddress* backup = SFallbackServer::Get();
540 
541  if (backup == NULL) {
542  LOG_POST(Info << "Fallback server address is not configured.");
543  throw;
544  }
545 
546  ERR_POST_X(3, "Could not connect to " <<
547  m_Service.GetServiceName() << ":" << e.what() <<
548  ". Connecting to backup server " << backup->AsString() << ".");
549 
550  exec_result =
551  m_Service->GetServer(*backup).ExecWithRetry(cmd, false);
552  }
553  }
554 
555  if (NStr::FindCase(exec_result.response, "ID:") != 0) {
556  // Answer is not in the "ID:....." format
557  exec_result.conn->Abort();
558  CONNSERV_THROW_FMT(CNetServiceException, eCommunicationError,
559  exec_result.conn->m_Server,
560  "Unexpected server response: " << exec_result.response);
561  }
562  exec_result.response.erase(0, 3);
563 
564  if (exec_result.response.empty()) {
565  exec_result.conn->Abort();
566  CONNSERV_THROW_FMT(CNetServiceException, eCommunicationError,
567  exec_result.conn->m_Server,
568  "Invalid server response. Empty key.");
569  }
570 
571  if (write_existing_blob) {
572  if (exec_result.response != stripped_blob_id) {
573  exec_result.conn->Abort();
574  CONNSERV_THROW_FMT(CNetCacheException, eInvalidServerResponse,
575  exec_result.conn->m_Server,
576  "Server created " << exec_result.response <<
577  " in response to PUT3 \"" << stripped_blob_id << "\"");
578  }
579  } else {
580  if (m_Service.IsLoadBalanced()) {
581  CNetCacheKey::TNCKeyFlags key_flags = 0;
582 
583  switch (parameters->GetMirroringMode()) {
586  break;
588  break;
589  default:
590  if (!exec_result.conn->m_Server->Get<SNetCacheServerProperties>()->mirrored)
592  }
593 
594  bool server_check_hint = true;
595  parameters->GetServerCheckHint(&server_check_hint);
596  if (!server_check_hint)
598 
600  m_Service.GetServiceName(), key_flags);
601  }
602 
603  if (parameters->GetUseCompoundID())
605  exec_result.response, m_CompoundIDPool);
606 
607  nc_writer->SetBlobID(exec_result.response);
608  }
609 
610  return exec_result.conn;
611 }
612 
613 
614 string CNetCacheAPI::PutData(const string& key,
615  const void* buf,
616  size_t size,
617  const CNamedParameterList* optional)
618 {
619  string actual_key(key);
620 
621  CNetCacheAPIParameters parameters(&m_Impl->m_DefaultParameters);
622 
623  parameters.LoadNamedParameters(optional);
624  parameters.SetCachingMode(eCaching_Disable);
625 
626  CNetCacheWriter writer(m_Impl, &actual_key, kEmptyStr,
627  eNetCache_Wait, &parameters);
628 
629  writer.WriteBufferAndClose(reinterpret_cast<const char*>(buf), size);
630 
631  return actual_key;
632 }
633 
635  const CNamedParameterList* optional)
636 {
637  return new CWStream(PutData(&key, optional), 0, NULL,
639 }
640 
642  const CNamedParameterList* optional)
643 {
644  CNetCacheAPIParameters parameters(&m_Impl->m_DefaultParameters);
645 
646  parameters.LoadNamedParameters(optional);
647 
648  return new CNetCacheWriter(m_Impl, key, kEmptyStr,
649  eNetCache_Wait, &parameters);
650 }
651 
652 
653 bool CNetCacheAPI::HasBlob(const string& blob_id,
654  const CNamedParameterList* optional)
655 {
656  CNetCacheKey key(blob_id, m_Impl->m_CompoundIDPool);
657 
658  CNetCacheAPIParameters parameters(&m_Impl->m_DefaultParameters);
659 
660  parameters.LoadNamedParameters(optional);
661 
662  return m_Impl->ExecMirrorAware(key,
663  m_Impl->MakeCmd("HASB ", key, &parameters),
664  false,
665  &parameters).response[0] == '1';
666 }
667 
668 
669 size_t CNetCacheAPI::GetBlobSize(const string& blob_id,
670  const CNamedParameterList* optional)
671 {
672  CNetCacheKey key(blob_id, m_Impl->m_CompoundIDPool);
673 
674  CNetCacheAPIParameters parameters(&m_Impl->m_DefaultParameters);
675 
676  parameters.LoadNamedParameters(optional);
677 
679  m_Impl->ExecMirrorAware(key,
680  m_Impl->MakeCmd("GSIZ ", key, &parameters),
681  false,
682  &parameters).response));
683 }
684 
685 
686 void CNetCacheAPI::Remove(const string& blob_id,
687  const CNamedParameterList* optional)
688 {
689  CNetCacheAPIParameters parameters(&m_Impl->m_DefaultParameters);
690 
691  parameters.LoadNamedParameters(optional);
692 
693  CNetCacheKey key(blob_id, m_Impl->m_CompoundIDPool);
694 
695  try {
696  m_Impl->ExecMirrorAware(key,
697  m_Impl->MakeCmd("RMV2 ", key, &parameters),
698  false,
699  &parameters);
700  }
701  catch (std::exception& e) {
702  ERR_POST("Could not remove blob \"" << blob_id << "\": " << e.what());
703  }
704  catch (...) {
705  ERR_POST("Could not remove blob \"" << blob_id << "\"");
706  }
707 }
708 
710  const CNamedParameterList* optional)
711 {
712  CNetCacheKey key(blob_id, m_Impl->m_CompoundIDPool);
713 
714  string cmd("GETMETA " + key.StripKeyExtensions());
715  cmd.append(m_Impl->m_Service->m_ServerPool->m_EnforcedServer.host == 0 ?
716  " 0" : " 1");
717 
718  CNetCacheAPIParameters parameters(&m_Impl->m_DefaultParameters);
719 
720  parameters.LoadNamedParameters(optional);
721 
722  m_Impl->AppendClientIPSessionIDHitID(&cmd);
723 
725  cmd, true, &parameters));
726 
727  output->SetNetCacheCompatMode();
728 
729  return output;
730 }
731 
732 void CNetCacheAPI::PrintBlobInfo(const string& blob_key,
733  const CNamedParameterList* optional)
734 {
735  CNetServerMultilineCmdOutput output(GetBlobInfo(blob_key, optional));
736 
737  string line;
738 
739  if (output.ReadLine(line)) {
740  if (!NStr::StartsWith(line, "SIZE="))
741  NcbiCout << line << NcbiEndl;
742  while (output.ReadLine(line))
743  NcbiCout << line << NcbiEndl;
744  }
745 }
746 
747 void CNetCacheAPI::ProlongBlobLifetime(const string& blob_key, unsigned ttl,
748  const CNamedParameterList* optional)
749 {
750  CNetCacheKey key_obj(blob_key, m_Impl->m_CompoundIDPool);
751 
752  string cmd("PROLONG \"\" " + key_obj.StripKeyExtensions());
753 
754  cmd += " \"\" ttl=";
755  cmd += NStr::NumericToString(ttl);
756 
757  CNetCacheAPIParameters parameters(&m_Impl->m_DefaultParameters);
758 
759  parameters.LoadNamedParameters(optional);
760 
761  m_Impl->AppendClientIPSessionIDPasswordAgeHitID(&cmd, &parameters);
762 
763  m_Impl->ExecMirrorAware(key_obj, cmd, false, &parameters);
764 }
765 
766 IReader* CNetCacheAPI::GetReader(const string& key, size_t* blob_size,
767  const CNamedParameterList* optional)
768 {
769  return m_Impl->GetPartReader(key, 0, 0, blob_size, optional);
770 }
771 
773  size_t offset, size_t part_size, size_t* blob_size,
774  const CNamedParameterList* optional)
775 {
776  return m_Impl->GetPartReader(key, offset, part_size,
777  blob_size, optional);
778 }
779 
780 void CNetCacheAPI::ReadData(const string& key, string& buffer,
781  const CNamedParameterList* optional)
782 {
783  ReadPart(key, 0, 0, buffer, optional);
784 }
785 
786 void CNetCacheAPI::ReadPart(const string& key,
787  size_t offset, size_t part_size, string& buffer,
788  const CNamedParameterList* optional)
789 {
790  size_t blob_size;
791  unique_ptr<IReader> reader(GetPartReader(key, offset, part_size,
792  &blob_size, optional));
793 
794  buffer.resize(blob_size);
795 
796  m_Impl->ReadBuffer(*reader, const_cast<char*>(buffer.data()),
797  blob_size, NULL, blob_size);
798 }
799 
800 IReader* CNetCacheAPI::GetData(const string& key, size_t* blob_size,
801  const CNamedParameterList* optional)
802 {
803  try {
804  return GetReader(key, blob_size, optional);
805  }
807  return NULL;
808  }
809  catch (CNetCacheException& e) {
810  switch (e.GetErrCode()) {
813  return NULL;
814  }
815  throw;
816  }
817 }
818 
820  size_t offset, size_t part_size,
821  size_t* blob_size_ptr, const CNamedParameterList* optional)
822 {
824 
825  string stripped_blob_id(key.StripKeyExtensions());
826 
827  const char* cmd_name;
828  string cmd;
829 
830  if (offset == 0 && part_size == 0) {
831  cmd_name = "GET2 ";
832  cmd = cmd_name + stripped_blob_id;
833  } else {
834  cmd_name = "GETPART ";
835  cmd = cmd_name + stripped_blob_id + ' ' +
836  NStr::UInt8ToString((Uint8) offset) + ' ' +
837  NStr::UInt8ToString((Uint8) part_size);
838  }
839 
841 
842  parameters.LoadNamedParameters(optional);
843 
845 
846  unsigned max_age = parameters.GetMaxBlobAge();
847  if (max_age > 0) {
848  cmd += " age=";
849  cmd += NStr::NumericToString(max_age);
850  }
851 
852  CNetServer::SExecResult exec_result;
853 
854  try {
855  exec_result = ExecMirrorAware(key, cmd, false, &parameters);
856  }
857  catch (CNetCacheException& e) {
859  e.AddToMessage(", ID=");
860  e.AddToMessage(blob_id);
861  }
862  throw;
863  }
864 
865  unsigned* actual_age_ptr = parameters.GetActualBlobAgePtr();
866  if (max_age > 0 && actual_age_ptr != NULL)
867  *actual_age_ptr = x_ExtractBlobAge(exec_result, cmd_name);
868 
869  return new CNetCacheReader(this, blob_id,
870  exec_result, blob_size_ptr, &parameters);
871 }
872 
874  void* buf,
875  size_t buf_size,
876  size_t* n_read,
877  size_t* blob_size,
878  const CNamedParameterList* optional)
879 {
880  _ASSERT(buf && buf_size);
881 
882  size_t x_blob_size = 0;
883 
884  unique_ptr<IReader> reader(GetData(key, &x_blob_size, optional));
885  if (reader.get() == 0)
886  return eNotFound;
887 
888  if (blob_size)
889  *blob_size = x_blob_size;
890 
891  return m_Impl->ReadBuffer(*reader,
892  (char*) buf, buf_size, n_read, x_blob_size);
893 }
894 
896  const string& key, CSimpleBuffer& buffer,
897  const CNamedParameterList* optional)
898 {
899  size_t x_blob_size = 0;
900 
901  unique_ptr<IReader> reader(GetData(key, &x_blob_size, optional));
902  if (reader.get() == 0)
903  return eNotFound;
904 
905  buffer.resize_mem(x_blob_size);
906  return m_Impl->ReadBuffer(*reader,
907  (char*) buffer.data(), x_blob_size, NULL, x_blob_size);
908 }
909 
910 CNcbiIstream* CNetCacheAPI::GetIStream(const string& key, size_t* blob_size,
911  const CNamedParameterList* optional)
912 {
913  return new CRStream(GetReader(key, blob_size, optional), 0, NULL,
915 }
916 
918 {
919  return new SNetCacheAdminImpl(m_Impl);
920 }
921 
923 {
924  return m_Impl->m_Service;
925 }
926 
928 {
929  return new SNetCacheAPIImpl(server->m_ServerInPool, m_Impl);
930 }
931 
933 {
934  return m_Impl->m_CompoundIDPool;
935 }
936 
938  CCompoundIDPool::TInstance compound_id_pool)
939 {
940  m_Impl->m_CompoundIDPool = compound_id_pool;
941 }
942 
943 /* static */
945  IReader& reader,
946  char* buf_ptr,
947  size_t buf_size,
948  size_t* n_read,
949  size_t blob_size)
950 {
951  size_t bytes_read;
952  size_t total_bytes_read = 0;
953 
954  while (buf_size > 0) {
955  ERW_Result rw_res = reader.Read(buf_ptr, buf_size, &bytes_read);
956  if (rw_res == eRW_Success) {
957  total_bytes_read += bytes_read;
958  buf_ptr += bytes_read;
959  buf_size -= bytes_read;
960  } else if (rw_res == eRW_Eof) {
961  break;
962  } else {
963  NCBI_THROW(CNetServiceException, eCommunicationError,
964  "Error while reading BLOB");
965  }
966  }
967 
968  if (n_read != NULL)
969  *n_read = total_bytes_read;
970 
971  return total_bytes_read == blob_size ?
973 }
974 
975 
976 ///////////////////////////////////////////////////////////////////////////////
977 
978 /// @internal
979 class CNetCacheAPICF : public IClassFactory<SNetCacheAPIImpl>
980 {
981 public:
982 
985  typedef IFace TInterface;
989 
990  /// Construction
991  ///
992  /// @param driver_name
993  /// Driver name string
994  /// @param patch_level
995  /// Patch level implemented by the driver.
996  /// By default corresponds to interface patch level.
997  CNetCacheAPICF(const string& driver_name = kNetCacheAPIDriverName,
998  int patch_level = -1)
1000  (ncbi::CInterfaceVersion<IFace>::eMajor,
1001  ncbi::CInterfaceVersion<IFace>::eMinor,
1002  patch_level >= 0 ?
1003  patch_level : ncbi::CInterfaceVersion<IFace>::ePatchLevel),
1004  m_DriverName(driver_name)
1005  {
1006  _ASSERT(!m_DriverName.empty());
1007  }
1008 
1009  /// Create instance of TDriver
1010  virtual TInterface*
1011  CreateInstance(const string& driver = kEmptyStr,
1013  const TPluginManagerParamTree* params = 0) const
1014  {
1015  if (params && (driver.empty() || driver == m_DriverName) &&
1018  CConfig config(params);
1019  return new SNetCacheAPIImpl(&config, m_DriverName,
1021  }
1022  return NULL;
1023  }
1024 
1025  void GetDriverVersions(TDriverList& info_list) const
1026  {
1027  info_list.push_back(TDriverInfo(m_DriverName, m_DriverVersionInfo));
1028  }
1029 protected:
1032 
1033 };
1034 
1035 
1039 {
1041 }
1042 
1043 //////////////////////////////////////////////////////////////////////////////
1044 //
1045 
1047 {
1048  _ASSERT(0 && "Cannot create an unitialized CBlobStorage_NetCache object.");
1049 }
1050 
1051 
1053 {
1054  try {
1055  Reset();
1056  }
1057  NCBI_CATCH_ALL("CBlobStorage_NetCache_Impl::~CBlobStorage_NetCache()");
1058 }
1059 
1061 {
1063 }
1064 
1066  size_t* blob_size,
1067  ELockMode /*lockMode*/)
1068 {
1069  m_IStream.reset(m_NCClient.GetIStream(key, blob_size));
1070  return *m_IStream;
1071 }
1072 
1073 string CBlobStorage_NetCache::GetBlobAsString(const string& data_id)
1074 {
1075  string buf;
1076  m_NCClient.ReadData(data_id, buf);
1077  return buf;
1078 }
1079 
1081  ELockMode /*lockMode*/)
1082 {
1084  return *m_OStream;
1085 }
1086 
1088 {
1089  return m_NCClient.PutData((const void*) NULL, 0);
1090 }
1091 
1092 void CBlobStorage_NetCache::DeleteBlob(const string& data_id)
1093 {
1094  m_NCClient.Remove(data_id);
1095 }
1096 
1098 {
1099  m_IStream.reset();
1100  m_OStream.reset();
1101 }
1102 
Pool of recycled CCompoundID objects.
CInterfaceVersion<> –.
TParent::TDriverList TDriverList
CNetCacheAPICF(const string &driver_name=kNetCacheAPIDriverName, int patch_level=-1)
Construction.
SNetCacheAPIImpl TDriver
SNetCacheAPIImpl IFace
void GetDriverVersions(TDriverList &info_list) const
Versions of the interface exported by the factory.
virtual TInterface * CreateInstance(const string &driver=kEmptyStr, CVersionInfo version=NCBI_INTERFACE_VERSION(IFace), const TPluginManagerParamTree *params=0) const
Create instance of TDriver.
IClassFactory< SNetCacheAPIImpl > TParent
TParent::SDriverInfo TDriverInfo
CVersionInfo m_DriverVersionInfo
Exception thrown when the requested blob is older than the requested age.
NetCache internal exception.
void OnWarningImpl(const string &warn_msg, CNetServer &server) override
void OnErrorImpl(const string &err_msg, CNetServer &server) override
TPropCreator GetPropCreator() const override
void OnConnected(CNetServerConnection &connection) override
void SetAuthString(const string &auth)
INetServerConnectionListener * Clone() override
string Exec(const string &cmd, bool multiline_output=false, const STimeout *timeout=NULL)
Execute remote command 'cmd', wait for the reply, check that it starts with 'OK:',...
unsigned short GetPort() const
SExecResult ExecWithRetry(const string &cmd, bool multiline_output=false)
Execute remote command 'cmd', wait for the reply, check if it starts with 'OK:', and return the remai...
string GetServerAddress() const
unsigned GetHost() const
Net Service exception.
const string & GetServiceName() const
CNetServer GetServer(unsigned host, unsigned short port)
CNetServer::SExecResult FindServerAndExec(const string &cmd, bool multiline_output=false)
bool IsLoadBalanced() const
CNetServiceIterator Iterate(EIterationMode mode=eSortByLoad)
Net Service exception.
Note about the "buf_size" parameter for streams in this API.
Definition: rwstream.hpp:122
@ fLeakExceptions
Exceptions leaked out.
Definition: rwstreambuf.hpp:72
@ fOwnReader
Own the underlying reader.
Definition: rwstreambuf.hpp:66
@ fOwnWriter
Own the underlying writer.
Definition: rwstreambuf.hpp:67
Reallocable memory buffer (no memory copy overhead) Mimics vector<>, without the overhead of explicit...
definition of a Culling tree
Definition: ncbi_tree.hpp:100
CUrlArgs::
Definition: ncbi_url.hpp:240
CVersionInfo –.
Writer-based output stream.
Definition: rwstream.hpp:171
IClassFactory<> –.
A very basic data-read interface.
IRegistry –.
Definition: ncbireg.hpp:73
virtual CNetServer BeginIteration()
CNetServer::TInstance m_PrimaryServer
virtual CNetServer NextServer()
CNetServiceIterator m_Iterator
static CMemoryRegistry registry
Definition: cn3d_tools.cpp:81
struct config config
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static SQLCHAR output[256]
Definition: print.c:5
static const char * str(char *buf, int n)
Definition: stats.c:84
int offset
Definition: replacements.h:160
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
@ eOn
Definition: ncbi_types.h:111
#define NULL
Definition: ncbistd.hpp:225
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
Definition: ncbidiag.cpp:1901
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
bool IsSetClientIP(void) const
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
void AddToMessage(const string &add_msg)
Definition: ncbiexpt.cpp:288
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
#define NCBI_CATCH_ALL(message)
This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:587
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
static Uint4 CalculateChecksum(const string &host, unsigned short port)
Calculate and return the CRC32 checksum generated from the string "host:port".
void SetUseCompoundID(bool use_compound_id)
IReader * GetPartReader(const string &key, size_t offset, size_t part_size, size_t *blob_size=NULL, const CNamedParameterList *optional=NULL)
Get a pointer to the IReader interface to read a portion of the blob contents.
unsigned * GetActualBlobAgePtr() const
virtual void Reset()
Close all streams and connections.
static string KeyToCompoundID(const string &key_str, CCompoundIDPool id_pool)
unsigned TNCKeyFlags
Binary OR of ENCKeyFlag.
CNetCacheAPI::EMirroringMode GetMirroringMode() const
const string & GetBlobID() const
CNcbiOstream * CreateOStream(string &key, const CNamedParameterList *optional=NULL)
Create a stream object for sending data to a blob.
void SetServerCheck(ESwitch server_check)
virtual bool IsKeyValid(const string &str)
Check if a given string is a valid key.
std::string GetPassword() const
void SetMirroringMode(CNetCacheAPI::EMirroringMode mirroring_mode)
const char *const kNetCacheAPIDriverName
size_t GetBlobSize(const string &blob_id, const CNamedParameterList *optional=NULL)
Returns the size of the BLOB identified by the "key" parameter.
void ReadPart(const string &key, size_t offset, size_t part_size, string &buffer, const CNamedParameterList *optional=NULL)
Read a part of the blob pointed to by "key" and store its contents in "buffer".
unique_ptr< CNcbiOstream > m_OStream
virtual void DeleteBlob(const string &data_id)
Delete a blob.
CCompoundIDPool GetCompoundIDPool()
void NCBI_EntryPoint_xnetcacheapi(CPluginManager< SNetCacheAPIImpl >::TDriverInfoList &info_list, CPluginManager< SNetCacheAPIImpl >::EEntryPointRequest method)
CNetRef< SNetCacheAPIImpl > m_Impl
static bool IsValidKey(const char *key_str, size_t key_len, CCompoundIDPool::TInstance id_pool=NULL)
virtual string GetBlobAsString(const string &data_id)
Get a blob content as a string.
bool GetServerCheck(ESwitch *server_check) const
void SetCompoundIDPool(CCompoundIDPool::TInstance compound_id_pool)
void Remove(const string &blob_id, const CNamedParameterList *optional=NULL)
Remove BLOB by key.
EAppRegistry
Defines how this object must be initialized.
unique_ptr< CNcbiIstream > m_IStream
CNetServerMultilineCmdOutput GetBlobInfo(const string &blob_id, const CNamedParameterList *optional=NULL)
Return a CNetServerMultilineCmdOutput object for reading meta information about the specified blob.
string PutData(const void *buf, size_t size, const CNamedParameterList *optional=NULL)
Put BLOB to server.
bool HasBlob(const string &blob_id, const CNamedParameterList *optional=NULL)
Check if the BLOB identified by the key "key" exists.
void PrintBlobInfo(const string &blob_key, const CNamedParameterList *optional=NULL)
Print meta information about the specified blob.
void LoadNamedParameters(const CNamedParameterList *optional)
size_t CheckBlobSize(Uint8 blob_size)
Definition: netcache_rw.hpp:58
void WriteBufferAndClose(const char *buf_ptr, size_t buf_size)
virtual ~CBlobStorage_NetCache()
CNcbiIstream * GetIStream(const string &key, size_t *blob_size=NULL, const CNamedParameterList *optional=NULL)
Create an istream object for reading blob data.
virtual CNcbiOstream & CreateOStream(string &data_id, ELockMode lock_mode=eLockNoWait)
Get an output stream to a blob.
virtual CNcbiIstream & GetIStream(const string &data_id, size_t *blob_size_ptr=0, ELockMode lock_mode=eLockWait)
Get an input stream to a blob.
void SetDefaultParameters(const CNamedParameterList *parameters)
Override defaults used by this object.
unsigned GetMaxBlobAge() const
void ProlongBlobLifetime(const string &blob_key, unsigned ttl, const CNamedParameterList *optional=NULL)
IReader * GetReader(const string &key, size_t *blob_size=NULL, const CNamedParameterList *optional=NULL)
Get a pointer to the IReader interface to read blob contents.
virtual string CreateEmptyBlob()
Create an new blob.
IReader * GetData(const string &key, size_t *blob_size=NULL, const CNamedParameterList *optional=NULL)
Retrieve BLOB from server by key.
CNetService GetService()
EReadResult
Status of GetData() call.
void SetBlobID(const string &blob_id)
void ReadData(const string &key, string &buffer, const CNamedParameterList *optional=NULL)
Read the blob pointed to by "key" and store its contents in "buffer".
string StripKeyExtensions() const
If the blob key has been parsed successfully, this method returns a trimmed "base" version of the key...
CNetCacheAdmin GetAdmin()
void SetServerCheckHint(bool server_check_hint)
bool GetServerCheckHint(bool *server_check_hint) const
void SetCachingMode(CNetCacheAPI::ECachingMode caching_mode)
static void AddExtensions(string &blob_id, const string &service_name, TNCKeyFlags flags, unsigned ver=1)
Unconditionally append a service name to the specified string.
@ fNCKey_NoServerCheck
Disable the check for whether the server IP is still in service.
@ fNCKey_SingleServer
Mark this blob as not mirrored.
@ eNetCache_Wait
@ eReadPart
Read part of the BLOB (buffer capacity)
@ eNotFound
BLOB not found or error.
@ eReadComplete
The whole BLOB has been read.
@ eAccessDenied
Blob could not be read completely.
@ eBlobNotFound
Access denied.
static void NCBI_EntryPointImpl(TDriverInfoList &info_list, EEntryPointRequest method)
Entry point implementation.
#define NCBI_INTERFACE_VERSION(iface)
Macro to construct CVersionInfo class using interface name (relies on CInterfaceVersion class)
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string ntoa(unsigned int host)
BSD-like API. NB: when int, "host" must be in network byte order.
ERW_Result
Result codes for I/O operations.
#define NcbiEndl
Definition: ncbistre.hpp:548
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NcbiCout
Definition: ncbistre.hpp:543
virtual ERW_Result Read(void *buf, size_t count, size_t *bytes_read=0)=0
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
@ eRW_Eof
End of data, should be considered permanent.
@ eRW_Success
Everything is okay, I/O completed.
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
Definition: ncbistr.cpp:3953
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static SIZE_TYPE FindCase(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 sensitive search.
Definition: ncbistr.hpp:5490
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:5412
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
Definition: ncbistr.cpp:873
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
Definition: ncbistr.cpp:642
static int strncmp(const char *s1, const char *s2, size_t n)
String compare up to specified number of characters.
Definition: ncbistr.hpp:5214
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
static string UInt8ToString(Uint8 value, TNumToStringFlags flags=0, int base=10)
Convert UInt8 to string.
Definition: ncbistr.hpp:5168
@ fAllowTrailingSymbols
Ignore trailing non-numerics characters.
Definition: ncbistr.hpp:298
@ fSplit_Truncate
Definition: ncbistr.hpp:2501
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2498
const TArgs & GetArgs(void) const
Get the const list of arguments.
Definition: ncbi_url.hpp:300
list< TArg > TArgs
Definition: ncbi_url.hpp:276
enum ENcbiSwitch ESwitch
Aux.
@ eNonCompatible
major, minor does not match
#define NCBI_XCONNECT_EXPORT
Definition of all error codes used in connect services library (xconnserv.lib and others).
char * buf
static int version
Definition: mdb_load.c:29
const struct ncbi::grid::netcache::search::fields::SIZE size
const struct ncbi::grid::netcache::search::fields::KEY key
Magic spell ;-) needed for some weird compilers... very empiric.
Static variables safety - create on demand, destroy on application termination.
Defines: CTimeFormat - storage class for time format.
@ eVoid
To create a void (uninitialized) instance of a component.
void g_AppendClientIPAndSessionID(string &cmd, const CRequestContext &req)
void g_AppendHitID(string &cmd, CRequestContext &req)
#define CONNSERV_THROW_FMT(exception_class, err_code, server, message)
static pcre_uint8 * buffer
Definition: pcretest.c:1051
Helper classes and templates to implement plugins.
Defines CRequestContext class for NCBI C++ diagnostic API.
Reader-writer based streams.
CNetCacheAPIExt GetServer(CNetServer::TInstance server)
Meaningful information encoded in the NetCache key.
CNetServerConnection conn
function< INetServerProperties *()> TPropCreator
static const TAddress * Get()
SSocketAddress TAddress
static TAddress Init()
void AppendClientIPSessionIDHitID(string *cmd)
void AppendClientIPSessionID(string *cmd, CRequestContext &req)
CNetCacheServerListener * GetListener()
void AppendClientIPSessionIDPasswordAgeHitID(string *cmd, const CNetCacheAPIParameters *parameters)
CNetCacheAPIParameters m_DefaultParameters
void AppendHitID(string *cmd, CRequestContext &req)
CNetCacheReader * GetPartReader(const string &blob_id, size_t offset, size_t part_size, size_t *blob_size, const CNamedParameterList *optional)
string MakeCmd(const char *cmd_base, const CNetCacheKey &key, const CNetCacheAPIParameters *parameters)
SNetServiceMap m_ServiceMap
unsigned x_ExtractBlobAge(const CNetServer::SExecResult &exec_result, const char *cmd_name)
CNetServer::SExecResult ExecMirrorAware(const CNetCacheKey &key, const string &cmd, bool multiline_output, const CNetCacheAPIParameters *parameters, SNetServiceImpl::EServerErrorHandling error_handling=SNetServiceImpl::eRethrowServerErrors)
static CNetCacheAPI::EReadResult ReadBuffer(IReader &reader, char *buf_ptr, size_t buf_size, size_t *n_read, size_t blob_size)
CCompoundIDPool m_CompoundIDPool
void Init(CSynRegistry &registry, const SRegSynonyms &sections)
virtual CNetServerConnection InitiateWriteCmd(CNetCacheWriter *nc_writer, const CNetCacheAPIParameters *parameters)
void WriteLine(const string &line)
CRef< SNetServerInPool > m_ServerInPool
CRef< TProperties > Get()
CNetServer GetServer(SSocketAddress server_address)
static SNetServiceImpl * Create(const string &api_name, const string &service_name, const string &client_name, INetServerConnectionListener *listener, CSynRegistry &registry, SRegSynonyms &sections, const string &ns_client_name=kEmptyStr)
CNetServer::SExecResult FindServerAndExec(const string &cmd, bool multiline_output)
const string & GetClientName() const
void IterateUntilExecOK(const string &cmd, bool multiline_output, CNetServer::SExecResult &exec_result, IServiceTraversal *service_traversal, EServerErrorHandling error_handling)
bool IsInService(CNetServer::TInstance server)
bool IsAllowed(const string &service_name) const
void AddToAllowed(const string &service_name)
CNetService GetServiceByName(const string &service_name, SNetServiceImpl *prototype)
string AsString() const
static SSocketAddress Parse(const string &address, SHost::EName name=SHost::EName::eResolved)
#define _ASSERT
else result
Definition: token2.c:20
#define crc32
Definition: zconf_cf.h:43
Modified on Thu May 23 12:32:11 2024 by modify_doxy.py rev. 669887