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

Go to the SVN repository for this file.

1 /* $Id: vdbread.cpp 100838 2023-09-18 17:14:05Z vasilche $
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: Eugene Vasilchenko
27  *
28  * File Description:
29  * Access to SRA files
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
35 #include <common/ncbi_source_ver.h>
37 
38 #include <klib/rc.h>
39 #include <klib/log.h>
40 #include <klib/text.h>
41 #include <klib/sra-release-version.h>
42 #include <kfg/config.h>
43 #include <kdb/manager.h>
44 #include <kdb/database.h>
45 #include <kdb/kdb-priv.h>
46 #include <kns/manager.h>
47 #include <kns/http.h>
48 #include <kns/tls.h>
49 
50 #include <vfs/manager-priv.h>
51 #include <vfs/manager.h>
52 #include <vfs/path.h>
53 #include <vfs/resolver.h>
54 
55 #include <sra/sradb-priv.h>
56 
57 #include <vdb/vdb-priv.h>
58 #include <vdb/manager.h>
59 #include <vdb/database.h>
60 #include <vdb/schema.h>
61 #include <vdb/table.h>
62 #include <vdb/cursor.h>
63 
64 
65 #include <corelib/ncbimtx.hpp>
66 #include <corelib/ncbifile.hpp>
67 #include <corelib/ncbi_param.hpp>
68 #include <corelib/request_ctx.hpp>
71 #include <objects/seq/seq__.hpp>
74 #include <sra/error_codes.hpp>
75 
76 #include <cstring>
77 #include <algorithm>
78 #include <thread>
79 
81 
82 #define NCBI_USE_ERRCODE_X VDBReader
84 
86 
87 class CSeq_entry;
88 
89 
90 NCBI_PARAM_DECL(int, VDB, DIAG_HANDLER);
91 NCBI_PARAM_DEF(int, VDB, DIAG_HANDLER, 1);
92 
93 
94 static int s_GetDiagHandler(void)
95 {
96  static CSafeStatic<NCBI_PARAM_TYPE(VDB, DIAG_HANDLER)> s_Value;
97  return s_Value->Get();
98 }
99 
100 
101 
103 NCBI_PARAM_DEF_EX(int, VDB, DEBUG, 0, eParam_NoThread, VDB_DEBUG);
104 
105 
106 static int s_GetDebugLevel(void)
107 {
108  static int value = NCBI_PARAM_TYPE(VDB, DEBUG)::GetDefault();
109  return value;
110 }
111 
112 
113 
114 DEFINE_SRA_REF_TRAITS(VDBManager, const);
115 DEFINE_SRA_REF_TRAITS(VDatabase, const);
116 DEFINE_SRA_REF_TRAITS(VTable, const);
117 DEFINE_SRA_REF_TRAITS(VCursor, const);
118 DEFINE_SRA_REF_TRAITS(KIndex, const);
120 DEFINE_SRA_REF_TRAITS(KDBManager, const);
121 DEFINE_SRA_REF_TRAITS(KNSManager, );
122 DEFINE_SRA_REF_TRAITS(VFSManager, );
123 DEFINE_SRA_REF_TRAITS(VPath, const);
125 
126 //#define VDB_RANDOM_FAILS 1
127 
128 #define FAILS_VAR(name, suffix) NCBI_NAME3(VDB_, name, suffix)
129 
130 #define VDB_RESOLVE_RANDOM_FAILS 1
131 #define VDB_OPEN_RANDOM_FAILS 1
132 #define VDB_SCHEMA_RANDOM_FAILS 1
133 #define VDB_READ_RANDOM_FAILS 1
134 
135 #define VDB_RESOLVE_RANDOM_FAILS_FREQUENCY 20
136 #define VDB_RESOLVE_RANDOM_FAILS_RECOVER 10
137 #define VDB_OPEN_RANDOM_FAILS_FREQUENCY 10
138 #define VDB_OPEN_RANDOM_FAILS_RECOVER 5
139 #define VDB_SCHEMA_RANDOM_FAILS_FREQUENCY 50
140 #define VDB_SCHEMA_RANDOM_FAILS_RECOVER 100
141 #define VDB_READ_RANDOM_FAILS_FREQUENCY 20000
142 #define VDB_READ_RANDOM_FAILS_RECOVER 1000
143 
144 #if defined(VDB_RANDOM_FAILS)
145 # define SIMULATE_ERROR(name) \
146  if ( !(FAILS_VAR(name, _RANDOM_FAILS)) ) { \
147  } \
148  else { \
149  static thread_local unsigned recover_counter = 0; \
150  if ( recover_counter > 0 ) { \
151  --recover_counter; \
152  } \
153  else { \
154  if ( (rand() % (FAILS_VAR(name, _RANDOM_FAILS_FREQUENCY))) == 0 ) { \
155  recover_counter = (FAILS_VAR(name, _RANDOM_FAILS_RECOVER)); \
156  ERR_POST("VDB: Simulated " #name " failure: "<<CStackTrace()); \
157  NCBI_THROW(CSraException, eOtherError, \
158  "Simulated " #name " failure"); \
159  } \
160  } \
161  }
162 #else
163 # define SIMULATE_ERROR(name) ((void)0)
164 #endif
165 
166 #define SIMULATE_RESOLVE_ERROR() SIMULATE_ERROR(RESOLVE)
167 #define SIMULATE_OPEN_ERROR() SIMULATE_ERROR(OPEN)
168 #define SIMULATE_SCHEMA_ERROR() SIMULATE_ERROR(SCHEMA)
169 #define SIMULATE_READ_ERROR() SIMULATE_ERROR(READ)
170 
171 
172 /////////////////////////////////////////////////////////////////////////////
173 // CKConfig
174 
176 {
177  KConfig* cfg;
178  if ( rc_t rc = KConfigMake(&cfg, 0) ) {
179  *x_InitPtr() = 0;
180  NCBI_THROW2(CSraException, eInitFailed,
181  "Cannot create KConfig", rc);
182  }
183  *x_InitPtr() = cfg;
184 }
185 
186 
188 {
189  *x_InitPtr() = const_cast<KConfig*>(VFSManagerGetConfig(CVFSManager(mgr)));
190  if ( rc_t rc = KConfigAddRef(*this) ) {
191  *x_InitPtr() = 0;
192  NCBI_THROW2(CSraException, eInitFailed,
193  "Cannot get reference to KConfig", rc);
194  }
195 }
196 
197 
199 {
200  if ( rc_t rc = KConfigMake(x_InitPtr(), NULL) ) {
201  NCBI_THROW2(CSraException, eInitFailed,
202  "Cannot create KConfig singleton", rc);
203  }
204 }
205 
206 
207 void CKConfig::Commit() const
208 {
209  if ( rc_t rc = KConfigCommit(const_cast<KConfig*>(GetPointer())) ) {
210  NCBI_THROW2(CSraException, eOtherError,
211  "CKConfig: Cannot commit config changes", rc);
212  }
213 }
214 
215 
216 /////////////////////////////////////////////////////////////////////////////
217 // CVFSManager
218 
220 {
221  x_InitNew();
222 }
223 
224 
226 {
227  x_InitNew();
228 }
229 
230 
232 {
233  if ( rc_t rc = VFSManagerMake(x_InitPtr()) ) {
234  *x_InitPtr() = 0;
235  NCBI_THROW2(CSraException, eInitFailed,
236  "Cannot create VFSManager", rc);
237  }
238 }
239 
240 
242 {
243  if ( rc_t rc = KDBManagerGetVFSManager(CKDBManager(mgr), x_InitPtr()) ) {
244  *x_InitPtr() = 0;
245  NCBI_THROW2(CSraException, eInitFailed,
246  "Cannot get VFSManager", rc);
247  }
248 }
249 
250 
251 /////////////////////////////////////////////////////////////////////////////
252 // CKDBManager
253 
254 
256 {
257  if ( rc_t rc = VDBManagerGetKDBManagerRead(mgr, x_InitPtr()) ) {
258  *x_InitPtr() = 0;
259  NCBI_THROW2(CSraException, eInitFailed,
260  "Cannot get KDBManager", rc);
261  }
262 }
263 
264 
265 /////////////////////////////////////////////////////////////////////////////
266 // CKNSManager
267 
268 
270 {
271  if ( rc_t rc = KNSManagerMake(x_InitPtr()) ) {
272  *x_InitPtr() = 0;
273  NCBI_THROW2(CSraException, eInitFailed,
274  "Cannot make KNSManager", rc);
275  }
276 }
277 
278 
280 {
281  if ( rc_t rc = VFSManagerGetKNSMgr(mgr, x_InitPtr()) ) {
282  *x_InitPtr() = 0;
283  NCBI_THROW2(CSraException, eInitFailed,
284  "Cannot get KNSManager", rc);
285  }
286 }
287 
288 
289 /////////////////////////////////////////////////////////////////////////////
290 // CVPath
291 
292 CVPath::CVPath(const CVFSManager& mgr, const string& path, EType type)
293 {
294  x_Init(mgr, path, type);
295 }
296 
297 
298 CVPath::CVPath(const string& path, EType type)
299 {
301 }
302 
303 
304 void CVPath::x_Init(const CVFSManager& mgr, const string& path, EType type)
305 {
306  VPath* vpath = 0;
307  if ( type == eSys ) {
308  if ( rc_t rc = VFSManagerMakeSysPath(mgr, &vpath, path.c_str()) ) {
309  *x_InitPtr() = 0;
310  NCBI_THROW2_FMT(CSraException, eInitFailed,
311  "Cannot create sys VPath: "<<path, rc);
312  }
313  }
314  else if ( type == eAcc ) {
315  if ( rc_t rc = VFSManagerMakeAccPath(mgr, &vpath, path.c_str()) ) {
316  *x_InitPtr() = 0;
317  NCBI_THROW2_FMT(CSraException, eInitFailed,
318  "Cannot create acc VPath: "<<path, rc);
319  }
320  }
321  else {
322  if ( rc_t rc = VFSManagerMakePath(mgr, &vpath, path.c_str()) ) {
323  *x_InitPtr() = 0;
324  NCBI_THROW2_FMT(CSraException, eInitFailed,
325  "Cannot create VPath: "<<path, rc);
326  }
327  }
328  *x_InitPtr() = vpath;
329 }
330 
331 
333 {
334  char buffer[32];
335  size_t size;
336  if ( VPathReadScheme(*this, buffer, sizeof(buffer), &size) != 0 ) {
337  return false;
338  }
339  if ( size == 4 && memcmp(buffer, "file", 4) == 0 ) {
340  return true;
341  }
342  if ( size == 9 && memcmp(buffer, "ncbi-file", 9) == 0 ) {
343  return true;
344  }
345  return false;
346 }
347 
348 
350 {
351  const String* str = 0;
352  if (type == eSys && IsLocalFile()) {
353  if (rc_t rc = VPathMakeSysPath(*this, &str)) {
354  NCBI_THROW2(CSraException, eOtherError,
355  "Cannot get path from VPath", rc);
356  }
357  }
358  else {
359  if (rc_t rc = VPathMakeString(*this, &str)) {
360  NCBI_THROW2(CSraException, eOtherError,
361  "Cannot get path from VPath", rc);
362  }
363  }
364  string ret(str->addr, str->size);
365  StringWhack(str);
366  return ret;
367 }
368 
369 
370 #ifdef NCBI_OS_MSWIN
371 static inline
372 bool s_HasWindowsDriveLetter(const string& s)
373 {
374  // first symbol is letter, and second symbol is colon (':')
375  return s.length() >= 2 && isalpha(s[0]&0xff) && s[1] == ':';
376 }
377 #endif
378 
379 
380 bool CVPath::IsPlainAccession(const string& acc_or_path)
381 {
382 #ifdef NCBI_OS_MSWIN
383  return !s_HasWindowsDriveLetter(acc_or_path) &&
384  acc_or_path.find_first_of("/\\") == NPOS;
385 #else
386  return acc_or_path.find('/') == NPOS;
387 #endif
388 }
389 
390 
391 #ifdef NCBI_OS_MSWIN
392 string CVPath::ConvertSysPathToPOSIX(const string& sys_path)
393 {
394  // Convert Windows path with drive letter
395  // C:\Users\Public -> /C/Users/Public
396  if ( sys_path[0] == 'h' &&
397  (NStr::StartsWith(sys_path, "http://") ||
398  NStr::StartsWith(sys_path, "https://")) ) {
399  return sys_path;
400  }
401  try {
402  string path = CDirEntry::CreateAbsolutePath(sys_path);
403  replace(path.begin(), path.end(), '\\', '/');
404  if (s_HasWindowsDriveLetter(path)) {
405  // move drive letter from first symbol to second (in place of ':')
406  path[1] = toupper(path[0] & 0xff);
407  // add leading slash
408  path[0] = '/';
409  }
410  return path;
411  }
412  catch (exception&) {
413  // CDirEntry::CreateAbsolutePath() can fail on URL for remote access
414  return sys_path;
415  }
416 }
417 
418 
419 string CVPath::ConvertAccOrSysPathToPOSIX(const string& acc_or_path)
420 {
421  return IsPlainAccession(acc_or_path) ?
422  acc_or_path :
423  ConvertSysPathToPOSIX(acc_or_path);
424 }
425 #endif
426 
427 
428 /////////////////////////////////////////////////////////////////////////////
429 // CVResolver
430 
432  : m_Mgr(mgr)
433 {
434  if ( rc_t rc = VFSManagerGetResolver(mgr, x_InitPtr()) ) {
435  *x_InitPtr() = 0;
436  NCBI_THROW2(CSraException, eInitFailed,
437  "Cannot get VResolver", rc);
438  }
439 }
440 
441 
443  : m_Mgr(mgr)
444 {
445  if ( rc_t rc = VFSManagerMakeResolver(mgr, x_InitPtr(), cfg) ) {
446  *x_InitPtr() = 0;
447  NCBI_THROW2(CSraException, eInitFailed,
448  "Cannot create VResolver", rc);
449  }
450 }
451 
452 
453 string CVResolver::Resolve(const string& acc_or_path) const
454 {
455  if ( !CVPath::IsPlainAccession(acc_or_path) ) {
456  // already a path
457  return acc_or_path;
458  }
460  CVPath acc(m_Mgr, acc_or_path, CVPath::eAcc);
461  const VPath* path;
462  rc_t rc = VResolverLocal(*this, acc, &path);
463  if ( rc ) {
464  if ( GetRCObject(rc) == rcName &&
465  GetRCState(rc) == rcNotFound &&
466  GetRCContext(rc) == rcResolving ) {
467  // continue with other ways to resolve
468  }
469  else {
470  NCBI_THROW2_FMT(CSraException, eOtherError,
471  "VResolverLocal("<<acc_or_path<<") failed", rc);
472  }
473  rc = VResolverRemote(*this, eProtocolNone, acc, &path);
474  }
475  if ( rc ) {
476  CHECK_VDB_TIMEOUT_FMT("Cannot find acc path: "<<acc_or_path, rc);
477  if ( GetRCObject(rc) == rcName &&
478  GetRCState(rc) == rcNotFound &&
479  GetRCContext(rc) == rcResolving ) {
480  // continue with other ways to resolve
481  }
482  else {
483  NCBI_THROW2_FMT(CSraException, eOtherError,
484  "VResolverRemote("<<acc_or_path<<") failed", rc);
485  }
486  if ( CDirEntry(acc_or_path).Exists() ) {
487  // local file
488  return acc_or_path;
489  }
490  // couldnt resolve with any way
491  NCBI_THROW2_FMT(CSraException, eNotFoundDb,
492  "Cannot find acc path: "<<acc_or_path, rc);
493  }
494  return CVPath(path).ToString();
495 }
496 
497 
498 /////////////////////////////////////////////////////////////////////////////
499 // CVDBMgr
500 
502  : m_Resolver(null)
503 {
504  x_Init();
505 }
506 
507 
508 string CVDBMgr::FindAccPath(const string& acc) const
509 {
510  if ( !m_Resolver ) {
512  }
513  return m_Resolver.Resolve(acc);
514 }
515 
516 
517 string CVDBMgr::FindDereferencedAccPath(const string& acc_or_path) const
518 {
519  string path;
520  if ( CVPath::IsPlainAccession(acc_or_path) ) {
521  // resolve VDB accessions
522  path = FindAccPath(acc_or_path);
523  if ( s_GetDebugLevel() >= 2 ) {
524  LOG_POST_X(4, "CVDBMgr: resolved accession: " << acc_or_path << " -> " << path);
525  }
526  }
527  else {
528  // real path, http:, etc.
529  path = acc_or_path;
530  }
531 
532  // resolve symbolic links for correct timestamp and longer-living reference
533  CDirEntry de(path);
534  if ( de.Exists() ) {
535  de.DereferencePath();
536  if ( de.GetPath() != path ) {
537  path = de.GetPath();
538  if ( s_GetDebugLevel() >= 2 ) {
539  LOG_POST_X(5, "CVDBMgr: resolved file link: " << acc_or_path << " -> " << path);
540  }
541  }
542  }
543  return path;
544 }
545 
546 
547 CTime CVDBMgr::GetTimestamp(const string& path) const
548 {
549  CTime timestamp;
550  if ( path[0] == 'h' &&
551  (NStr::StartsWith(path, "http://") ||
552  NStr::StartsWith(path, "https://")) ) {
553  // try http:
554  timestamp = GetURLTimestamp(path);
555  }
556  else {
557  // try direct file access
558  if ( !CDirEntry(path).GetTime(&timestamp) ) {
559  NCBI_THROW_FMT(CSraException, eInitFailed,
560  "Cannot get timestamp of local path: " << path);
561  }
562  timestamp.ToUniversalTime();
563  }
564  _ASSERT(!timestamp.IsEmpty());
565  _ASSERT(timestamp.IsUniversalTime());
566  if ( s_GetDebugLevel() >= 2 ) {
567  LOG_POST_X(3, "CVDBMgr: timestamp of " << path << ": " << CTime(timestamp).ToLocalTime());
568  }
569  return timestamp;
570 }
571 
572 
573 DECLARE_SRA_REF_TRAITS(KClientHttpRequest, );
574 DECLARE_SRA_REF_TRAITS(KClientHttpResult, );
575 
576 DEFINE_SRA_REF_TRAITS(KClientHttpRequest, );
577 DEFINE_SRA_REF_TRAITS(KClientHttpResult, );
578 
580  : public CSraRef<KClientHttpRequest>
581 {
582 public:
583  CClientHttpRequest(const CKNSManager& mgr, const string& path)
584  {
585  const ver_t kHTTP_1_1 = 0x01010000;
586  if ( rc_t rc = KNSManagerMakeClientRequest(mgr, x_InitPtr(),
587  kHTTP_1_1, nullptr,
588  "%s", path.c_str()) ) {
589  *x_InitPtr() = 0;
590  CHECK_VDB_TIMEOUT("Cannot create http request", rc);
591  NCBI_THROW2(CSraException, eInitFailed,
592  "Cannot create http client request", rc);
593  }
594  }
595 
596 private:
597 };
598 
599 
601  : public CSraRef<KClientHttpResult>
602 {
603 public:
604  enum EHead {
605  eHead
606  };
607 
609  {
610  if ( rc_t rc = KClientHttpRequestHEAD(request, x_InitPtr()) ) {
611  *x_InitPtr() = 0;
612  CHECK_VDB_TIMEOUT("Cannot get http HEAD", rc);
613  NCBI_THROW2(CSraException, eInitFailed,
614  "Cannot get http HEAD", rc);
615  }
616  }
617 
618 private:
619 };
620 
621 
622 CTime CVDBMgr::GetURLTimestamp(const string& path) const
623 {
624  CVFSManager vfs(*this);
625  CKNSManager kns(vfs);
626  CClientHttpRequest request(kns, path);
628  char buffer[99];
629  size_t size;
630  if ( rc_t rc = KClientHttpResultGetHeader(result, "Last-Modified",
631  buffer, sizeof(buffer), &size) ) {
632  CHECK_VDB_TIMEOUT("No Last-Modified header in HEAD response", rc);
633  NCBI_THROW2(CSraException, eNotFoundValue,
634  "No Last-Modified header in HEAD response", rc);
635  }
637  CTimeFormat fmt("w, d b Y h:m:s Z"); // standard Last-Modified HTTP header format
638  return CTime(str, fmt);
639 }
640 
641 
642 //#define GUARD_SDK
643 #ifdef NCBI_COMPILER_MSVC
644 //# define GUARD_SDK_GET
645 #endif
646 
647 #ifdef GUARD_SDK
648 # define DECLARE_SDK_GUARD() CFastMutexGuard guard(sx_SDKMutex)
649 #else
650 # define DECLARE_SDK_GUARD()
651 #endif
652 
653 #ifdef GUARD_SDK_GET
654 # define DECLARE_SDK_GET_GUARD() CFastMutexGuard guard(sx_SDKMutex)
655 #else
656 # define DECLARE_SDK_GET_GUARD()
657 #endif
658 
659 
660 /////////////////////////////////////////////////////////////////////////////
661 // VDB library initialization code
662 // similar code is located in bamread.cpp
663 /////////////////////////////////////////////////////////////////////////////
664 
666 
667 static char s_VDBVersion[32]; // enough for 255.255.65535-dev4000000000
668 
669 static
671 {
672  if ( !s_VDBVersion[0] ) {
673  ostringstream s;
674  {{ // format VDB version string
675  SraReleaseVersion release_version;
676  SraReleaseVersionGet(&release_version);
677  s << (release_version.version>>24) << '.'
678  << ((release_version.version>>16)&0xff) << '.'
679  << (release_version.version&0xffff);
680  if ( release_version.revision != 0 ||
681  release_version.type != SraReleaseVersion::eSraReleaseVersionTypeFinal ) {
682  const char* type = "";
683  switch ( release_version.type ) {
684  case SraReleaseVersion::eSraReleaseVersionTypeDev: type = "dev"; break;
685  case SraReleaseVersion::eSraReleaseVersionTypeAlpha: type = "a"; break;
686  case SraReleaseVersion::eSraReleaseVersionTypeBeta: type = "b"; break;
687  case SraReleaseVersion::eSraReleaseVersionTypeRC: type = "RC"; break;
688  default: type = ""; break;
689  }
690  s << '-' << type << release_version.revision;
691  }
692  }}
693  string v = s.str();
694  if ( !v.empty() ) {
695  if ( v.size() >= sizeof(s_VDBVersion) ) {
696  v.resize(sizeof(s_VDBVersion)-1);
697  }
698  copy(v.begin()+1, v.end(), s_VDBVersion+1);
699  s_VDBVersion[0] = v[0];
700  }
701  }
702 }
703 
704 struct SVDBSeverityTag {
705  const char* tag;
707 };
708 static const SVDBSeverityTag kSeverityTags[] = {
709  { "err:", Error },
710  { "int:", Error },
711  { "sys:", Error },
712  { "info:", Info },
713  { "warn:", Warning },
714  { "debug:", Trace },
715  { "fatal:", Fatal },
716 };
718 {
719  if ( !token.empty() && token[token.size()-1] == ':' ) {
720  for ( auto& tag : kSeverityTags ) {
721  if ( token == tag.tag ) {
722  return &tag;
723  }
724  }
725  }
726  return 0;
727 }
728 
729 #ifndef NCBI_THREADS
730 static thread::id s_DiagCheckThreadID;
731 #endif
732 
733 static inline void s_InitDiagCheck()
734 {
735 #ifndef NCBI_THREADS
736  s_DiagCheckThreadID = this_thread::get_id();
737 #endif
738 }
739 
740 static inline bool s_DiagIsSafe()
741 {
742 #ifndef NCBI_THREADS
743  return s_DiagCheckThreadID == this_thread::get_id();
744 #else
745  return true;
746 #endif
747 }
748 
749 
750 static
751 rc_t VDBLogWriter(void* /*data*/, const char* buffer, size_t size, size_t* written)
752 {
753  CTempString msg(buffer, size);
755  CNcbiDiag::FManip sev_manip = Error;
756 
757  for ( SIZE_TYPE token_pos = 0, token_end; token_pos < msg.size(); token_pos = token_end + 1 ) {
758  token_end = msg.find(' ', token_pos);
759  if ( token_end == NPOS ) {
760  token_end = msg.size();
761  }
762  if ( auto tag = s_GetVDBSeverityTag(CTempString(msg, token_pos, token_end-token_pos)) ) {
763  sev_manip = tag->manip;
764  break;
765  }
766  }
767  if ( sev_manip == Trace ) {
768  if ( s_DiagIsSafe() ) {
769  _TRACE("VDB "<<s_VDBVersion<<": "<<msg);
770  }
771  }
772  else {
773  if ( s_DiagIsSafe() ) {
774  ERR_POST_X(2, sev_manip<<"VDB "<<s_VDBVersion<<": "<<msg);
775  }
776  }
777  *written = size;
778  return 0;
779 }
780 
781 
783 {
784  CKConfig config(null);
786  string host = app->GetConfig().GetString("CONN", "HTTP_PROXY_HOST", kEmptyStr);
787  int port = app->GetConfig().GetInt("CONN", "HTTP_PROXY_PORT", 0);
788  if ( !host.empty() && port != 0 ) {
790  string path = host + ':' + NStr::IntToString(port);
791  if ( rc_t rc = KConfigWriteString(config,
792  "/http/proxy/path", path.c_str()) ) {
793  NCBI_THROW2(CSraException, eInitFailed,
794  "Cannot set KConfig proxy path", rc);
795  }
796  if ( rc_t rc = KConfigWriteBool(config,
797  "/http/proxy/enabled", true) ) {
798  NCBI_THROW2(CSraException, eInitFailed,
799  "Cannot set KConfig proxy enabled", rc);
800  }
801  }
802  }
803  return config;
804 }
805 
806 
807 static DECLARE_TLS_VAR(const CRequestContext*, s_LastRequestContext);
808 static DECLARE_TLS_VAR(CRequestContext::TVersion, s_LastRequestContextVersion);
809 
810 /*
811 // Performance collecting code
812 static struct SReport {
813  size_t count;
814  double time;
815  SReport() : count(0), time(0) {}
816  ~SReport() {
817  LOG_POST("GetRequestContext() called "<<count<<" times, spent "<<time<<"s");
818  }
819 } dummy;
820 */
821 
822 static void s_UpdateVDBRequestContext(void)
823 {
824  // Performance collecting code
825  // CStopWatch sw(CStopWatch::eStart);
827  // Performance collecting code
828  // dummy.count += 1; dummy.time += sw.Elapsed();
829  auto req_ctx_version = req_ctx.GetVersion();
830  if ( &req_ctx == s_LastRequestContext && req_ctx_version == s_LastRequestContextVersion ) {
831  return;
832  }
833  _TRACE("CVDBMgr: Updating request context with version: "<<req_ctx_version);
834  s_LastRequestContext = &req_ctx;
835  s_LastRequestContextVersion = req_ctx_version;
837  if ( req_ctx.IsSetSessionID() ) {
838  _TRACE("CVDBMgr: Updating session ID: "<<req_ctx.GetSessionID());
839  KNSManagerSetSessionID(kns_mgr, req_ctx.GetSessionID().c_str());
840  }
841  if ( req_ctx.IsSetClientIP() ) {
842  _TRACE("CVDBMgr: Updating client IP: "<<req_ctx.GetClientIP());
843  KNSManagerSetClientIP(kns_mgr, req_ctx.GetClientIP().c_str());
844  }
845  if ( req_ctx.IsSetHitID() ) {
846  _TRACE("CVDBMgr: Updating hit ID: "<<req_ctx.GetHitID());
847  KNSManagerSetPageHitID(kns_mgr, req_ctx.GetHitID().c_str());
848  }
849 }
850 
851 
852 static void s_InitAllKNS(KNSManager* kns_mgr)
853 {
855  if ( app && app->GetConfig().GetBool("VDB", "ALLOW_ALL_CERTS", false) ) {
856  if ( rc_t rc = KNSManagerSetAllowAllCerts(kns_mgr, true) ) {
857  NCBI_THROW2(CSraException, eInitFailed,
858  "Cannot enable all HTTPS certificates in KNSManager", rc);
859  }
860  }
861  {{ // set user agent
863  if ( app ) {
864  str << app->GetAppName() << ": " << app->GetVersion().Print() << "; ";
865  }
866 #if NCBI_PACKAGE
867  str << "Package: " << NCBI_PACKAGE_NAME << ' ' <<
868  NCBI_PACKAGE_VERSION << "; ";
869 #endif
870  str << "C++ ";
871 #ifdef NCBI_PRODUCTION_VER
872  str << NCBI_PRODUCTION_VER << "/";
873 #endif
874 #ifdef NCBI_DEVELOPMENT_VER
876 #endif
878  KNSManagerSetUserAgent(kns_mgr, "%s; VDB %s",
879  prefix.c_str(),
880  s_VDBVersion);
881  }}
882 }
883 
884 
885 static void s_InitStaticKNS(KNSManager* kns_mgr)
886 {
887  s_InitAllKNS(kns_mgr);
888 }
889 
890 
891 static void s_InitLocalKNS(KNSManager* kns_mgr)
892 {
893  s_InitAllKNS(kns_mgr);
894 }
895 
896 
897 static void s_VDBInit()
898 {
899  CFastMutexGuard guard(sx_SDKMutex);
900  static bool initialized = false;
901  if ( !initialized ) {
903  // redirect VDB log to C++ Toolkit
904  if ( s_GetDiagHandler() ) {
905  KLogInit();
906  KLogLevel ask_level;
907 #ifdef _DEBUG
908  ask_level = klogDebug;
909 #else
910  ask_level = klogInfo;
911 #endif
912  s_InitDiagCheck();
913  KLogLevelSet(ask_level);
914  KLogHandlerSet(VDBLogWriter, 0);
915  KLogLibHandlerSet(VDBLogWriter, 0);
916  if ( s_GetDebugLevel() >= 2 ) {
917  const char* msg = "info: VDB initialized";
918  size_t written;
919  VDBLogWriter(0, msg, strlen(msg), &written);
920  }
921  }
924  s_InitStaticKNS(kns_mgr);
925  initialized = true;
926  }
927 }
928 
929 /////////////////////////////////////////////////////////////////////////////
930 // end of VDB library initialization code
931 /////////////////////////////////////////////////////////////////////////////
932 
933 
934 //#define UPDATE_REQUEST_CONTEXT_FINAL
935 
936 #ifndef UPDATE_REQUEST_CONTEXT_FINAL
937 static DECLARE_TLS_VAR(size_t, s_RequestContextUpdaterRecursion);
938 #endif
939 
941 public:
945 };
946 
947 
949 {
950 #ifndef UPDATE_REQUEST_CONTEXT_FINAL
951  size_t r = s_RequestContextUpdaterRecursion;
952  s_RequestContextUpdaterRecursion = r+1;
953  if ( r != 0 ) {
954  return;
955  }
958 #endif
959 }
960 
961 
963 {
964 #ifndef UPDATE_REQUEST_CONTEXT_FINAL
965  size_t r = s_RequestContextUpdaterRecursion;
966  s_RequestContextUpdaterRecursion = r+1;
967  if ( r != 0 ) {
968  return;
969  }
970 #endif
973 }
974 
975 
977 {
978 #ifndef UPDATE_REQUEST_CONTEXT_FINAL
979  size_t r = s_RequestContextUpdaterRecursion;
980  s_RequestContextUpdaterRecursion = r-1;
981 #endif
982 }
983 
984 
986 {
987 #ifndef UPDATE_REQUEST_CONTEXT_FINAL
988  size_t r = s_RequestContextUpdaterRecursion;
989  s_RequestContextUpdaterRecursion = r-1;
990 #endif
991 }
992 
993 
994 void CVDBMgr::x_Init(void)
995 {
996  s_VDBInit();
997  if ( rc_t rc = VDBManagerMakeRead(x_InitPtr(), 0) ) {
998  *x_InitPtr() = 0;
999  NCBI_THROW2(CSraException, eInitFailed,
1000  "Cannot open VDBManager", rc);
1001  }
1002  CVFSManager vfs_mgr(*this);
1003  VFSManagerLogNamesServiceErrors(vfs_mgr, false);
1004  s_InitLocalKNS(CKNSManager(vfs_mgr));
1005 }
1006 
1007 
1009 {
1010  const VPath* ret;
1011  if ( rc_t rc = VDBManagerGetCacheRoot(*this, &ret) ) {
1012  if ( GetRCObject(rc) == RCObject(rcPath) &&
1013  GetRCState(rc) == rcNotFound ) {
1014  return kEmptyStr;
1015  }
1016  NCBI_THROW2(CSraException, eOtherError,
1017  "CVDBMgr: Cannot get cache root", rc);
1018  }
1019  return CVPath(ret).ToString(CVPath::eSys);
1020 }
1021 
1022 
1023 void CVDBMgr::SetCacheRoot(const string& path)
1024 {
1025  CVPath vpath(CVFSManager(*this), path, CVPath::eSys);
1026  if ( rc_t rc = VDBManagerSetCacheRoot(*this, vpath) ) {
1027  NCBI_THROW2(CSraException, eOtherError,
1028  "CVDBMgr: Cannot set cache root", rc);
1029  }
1030 }
1031 
1032 
1034 {
1035  if ( rc_t rc = VDBManagerDeleteCacheOlderThan(*this, days) ) {
1036  NCBI_THROW2(CSraException, eOtherError,
1037  "CVDBMgr: Cannot delete old cache files", rc);
1038  }
1039 }
1040 
1041 
1043 {
1044  CKConfig(*this).Commit();
1045 }
1046 
1047 
1048 /////////////////////////////////////////////////////////////////////////////
1049 // CVDB
1050 
1051 CVDB::CVDB(const CVDBMgr& mgr, const string& acc_or_path)
1052  : m_Name(acc_or_path)
1053 {
1055  CFinalRequestContextUpdater ctx_updater;
1056  string path = CVPath::ConvertAccOrSysPathToPOSIX(acc_or_path);
1058  if ( rc_t rc = VDBManagerOpenDBRead(mgr, x_InitPtr(), 0, "%.*s",
1059  int(path.size()), path.data()) ) {
1060  *x_InitPtr() = 0;
1061  string msg = "Cannot open VDB: "+acc_or_path;
1062  CHECK_VDB_TIMEOUT(msg, rc);
1063  if ( (GetRCObject(rc) == RCObject(rcDirectory) ||
1064  GetRCObject(rc) == RCObject(rcPath) ||
1065  GetRCObject(rc) == RCObject(rcFile)) &&
1066  GetRCState(rc) == rcNotFound ) {
1067  // no VDB accession
1068  NCBI_THROW2(CSraException, eNotFoundDb, msg, rc);
1069  }
1070  else if ( GetRCObject(rc) == rcName &&
1071  GetRCState(rc) == rcNotFound &&
1072  GetRCContext(rc) == rcResolving ) {
1073  // invalid VDB database
1074  NCBI_THROW2(CSraException, eNotFoundDb, msg, rc);
1075  }
1076  else if ( GetRCObject(rc) == RCObject(rcFile) &&
1077  GetRCState(rc) == rcUnauthorized ) {
1078  // no permission to use VDB database
1079  NCBI_THROW2(CSraException, eProtectedDb, msg, rc);
1080  }
1081  else if ( GetRCObject(rc) == RCObject(rcDatabase) &&
1082  GetRCState(rc) == rcIncorrect ) {
1083  // invalid VDB database
1084  NCBI_THROW2(CSraException, eDataError, msg, rc);
1085  }
1086  else {
1087  // other errors
1088  NCBI_THROW2(CSraException, eOtherError, msg, rc);
1089  }
1090  }
1091  if ( 0 ) {
1092  const KDatabase* kdb = 0;
1093  if ( rc_t rc = VDatabaseOpenKDatabaseRead(*this, &kdb) ) {
1094  NCBI_THROW2(CSraException, eOtherError, "VDatabaseOpenKDatabaseRead() failed", rc);
1095  }
1096  const char* kdb_path = 0;
1097  if ( rc_t rc = KDatabaseGetPath(kdb, &kdb_path) ) {
1098  NCBI_THROW2(CSraException, eOtherError, "KDatabaseGetPath() failed", rc);
1099  }
1100  LOG_POST("CVDB("<<acc_or_path<<") -> "<<path<<" -> "<<kdb_path);
1101  if ( rc_t rc = KDatabaseRelease(kdb) ) {
1102  NCBI_THROW2(CSraException, eOtherError, "KDatabaseRelease() failed", rc);
1103  }
1104  }
1105 }
1106 
1107 
1109 {
1110  return out << GetName();
1111 }
1112 
1113 
1114 /////////////////////////////////////////////////////////////////////////////
1115 // CVDBTable
1116 
1117 static inline
1119 {
1120  return obj.PrintFullName(out);
1121 }
1122 
1123 
1125  const char* table_name,
1126  EMissing missing)
1127  : m_Db(db),
1128  m_Name(table_name)
1129 {
1131  CFinalRequestContextUpdater ctx_updater;
1133  if ( rc_t rc = VDatabaseOpenTableRead(db, x_InitPtr(), table_name) ) {
1134  *x_InitPtr() = 0;
1135  string msg = "Cannot open VDB: "+GetFullName();
1136  CHECK_VDB_TIMEOUT(msg, rc);
1137  RCState rc_state = GetRCState(rc);
1138  int rc_object = GetRCObject(rc);
1139  if ( rc_state == rcNotFound &&
1140  (rc_object == rcParam ||
1141  rc_object == rcPath) ) {
1142  // missing table in the DB
1143  if ( missing != eMissing_Throw ) {
1144  return;
1145  }
1146  NCBI_THROW2(CSraException, eNotFoundTable, msg, rc);
1147  }
1148  else {
1149  // other errors
1150  NCBI_THROW2(CSraException, eOtherError, msg, rc);
1151  }
1152  }
1153 }
1154 
1155 
1157  const string& acc_or_path,
1158  EMissing missing)
1159  : m_Name(acc_or_path)
1160 {
1161  *x_InitPtr() = 0;
1163  CFinalRequestContextUpdater ctx_updater;
1164  string path = CVPath::ConvertAccOrSysPathToPOSIX(acc_or_path);
1166  if ( rc_t rc = VDBManagerOpenTableRead(mgr, x_InitPtr(), 0, "%.*s",
1167  int(path.size()), path.data()) ) {
1168  *x_InitPtr() = 0;
1169  string msg = "Cannot open VDB: "+acc_or_path;
1170  CHECK_VDB_TIMEOUT(msg, rc);
1171  if ( (GetRCObject(rc) == RCObject(rcDirectory) ||
1172  GetRCObject(rc) == RCObject(rcPath)) &&
1173  GetRCState(rc) == rcNotFound ) {
1174  // no SRA accession
1175  if ( missing != eMissing_Throw ) {
1176  return;
1177  }
1178  NCBI_THROW2(CSraException, eNotFoundTable, msg, rc);
1179  }
1180  else if ( GetRCObject(rc) == RCObject(rcDatabase) &&
1181  GetRCState(rc) == rcIncorrect ) {
1182  // invalid SRA database
1183  NCBI_THROW2(CSraException, eDataError, msg, rc);
1184  }
1185  else {
1186  // other errors
1187  NCBI_THROW2(CSraException, eOtherError, msg, rc);
1188  }
1189  }
1190 }
1191 
1192 
1193 string CVDBTable::GetFullName(void) const
1194 {
1195  string ret;
1196  if ( GetDb() ) {
1197  ret = GetDb().GetFullName();
1198  ret += '.';
1199  }
1200  ret += GetName();
1201  return ret;
1202 }
1203 
1204 
1206 {
1207  if ( GetDb() ) {
1208  GetDb().PrintFullName(out) << '.';
1209  }
1210  return out << GetName();
1211 }
1212 
1213 
1214 /////////////////////////////////////////////////////////////////////////////
1215 // CVDBTableIndex
1216 
1217 static inline
1219 {
1220  return obj.PrintFullName(out);
1221 }
1222 
1223 
1225  const char* index_name,
1226  EMissing missing)
1227  : m_Table(table),
1228  m_Name(index_name)
1229 {
1230  CFinalRequestContextUpdater ctx_updater;
1232  if ( rc_t rc = VTableOpenIndexRead(table, x_InitPtr(), index_name) ) {
1233  *x_InitPtr() = 0;
1234  string msg = "Cannot open VDB table index: "+GetFullName();
1235  CHECK_VDB_TIMEOUT(msg, rc);
1236  if ( GetRCObject(rc) == RCObject(rcIndex) &&
1237  GetRCState(rc) == rcNotFound ) {
1238  // no such index
1239  if ( missing != eMissing_Throw ) {
1240  return;
1241  }
1242  NCBI_THROW2(CSraException, eNotFoundIndex, msg, rc);
1243  }
1244  else {
1245  NCBI_THROW2(CSraException, eOtherError, msg, rc);
1246  }
1247  }
1248 }
1249 
1250 
1252 {
1253  return GetTable().GetFullName()+'.'+GetName();
1254 }
1255 
1256 
1258 {
1259  return GetTable().PrintFullName(out) << '.' << GetName();
1260 }
1261 
1262 
1264 {
1266  if ( rc_t rc = KIndexFindText(*this, value.c_str(),
1267  &range.first, &range.second, 0, 0) ) {
1268  CHECK_VDB_TIMEOUT_FMT("Cannot find value in index: "<<*this<<": "<<value, rc);
1269  if ( GetRCObject(rc) == RCObject(rcString) &&
1270  GetRCState(rc) == rcNotFound ) {
1271  // no such value
1272  range.first = range.second = 0;
1273  }
1274  else {
1275  NCBI_THROW2_FMT(CSraException, eOtherError,
1276  "Cannot find value in index: "<<*this<<": "<<value, rc);
1277  }
1278  }
1279  return range;
1280 }
1281 
1282 
1283 /////////////////////////////////////////////////////////////////////////////
1284 // CVDBCursor
1285 
1286 static inline
1288 {
1289  return out << obj.GetTable();
1290 }
1291 
1292 
1294 {
1295  CFinalRequestContextUpdater ctx_updater;
1296  if ( *this ) {
1297  NCBI_THROW2(CSraException, eInvalidState,
1298  "Cannot init VDB cursor again",
1299  RC(rcApp, rcCursor, rcConstructing, rcSelf, rcOpen));
1300  }
1301  if ( !table ) { // VTableCreateCursorRead lacks check for null table argument
1302  NCBI_THROW2(CSraException, eNullPtr,
1303  "Cannot init VDB cursor",
1304  RC(rcApp, rcCursor, rcConstructing, rcTable, rcNull));
1305  }
1306  if ( rc_t rc = VTableCreateCursorRead(table, x_InitPtr()) ) {
1307  *x_InitPtr() = 0;
1308  CHECK_VDB_TIMEOUT_FMT("Cannot create VDB cursor: "<<table, rc);
1309  NCBI_THROW2_FMT(CSraException, eInitFailed,
1310  "Cannot create VDB cursor: "<<table, rc);
1311  }
1312  if ( rc_t rc = VCursorPermitPostOpenAdd(*this) ) {
1313  NCBI_THROW2_FMT(CSraException, eInitFailed,
1314  "Cannot allow VDB cursor post open column add: "<<table, rc);
1315  }
1316  if ( rc_t rc = VCursorOpen(*this) ) {
1317  CHECK_VDB_TIMEOUT_FMT("Cannot open VDB cursor: "<<table, rc);
1318  NCBI_THROW2_FMT(CSraException, eInitFailed,
1319  "Cannot open VDB cursor: "<<table, rc);
1320  }
1321  m_Table = table;
1322 }
1323 
1324 
1326 {
1327  if ( !RowIsOpened() ) {
1328  return;
1329  }
1330  if ( rc_t rc = VCursorCloseRow(*this) ) {
1331  NCBI_THROW2(CSraException, eInitFailed,
1332  "Cannot close VDB cursor row", rc);
1333  }
1334  m_RowOpened = false;
1335 }
1336 
1337 
1339 {
1340  CloseRow();
1341  CFinalRequestContextUpdater ctx_updater;
1342  if ( rc_t rc = VCursorSetRowId(*this, row_id) ) {
1343  return rc;
1344  }
1345  if ( rc_t rc = VCursorOpenRow(*this) ) {
1346  return rc;
1347  }
1348  m_RowOpened = true;
1349  return 0;
1350 }
1351 
1352 
1354 {
1355  if ( rc_t rc = OpenRowRc(row_id) ) {
1356  CHECK_VDB_TIMEOUT_FMT("Cannot open VDB cursor row: "<<*this<<": "<<row_id, rc);
1357  NCBI_THROW2_FMT(CSraException, eInitFailed,
1358  "Cannot open VDB cursor row: "<<*this<<": "<<row_id, rc);
1359  }
1360 }
1361 
1362 
1364 {
1365  TVDBRowIdRange ret;
1366  if ( rc_t rc = VCursorIdRange(*this, column, &ret.first, &ret.second) ) {
1367  CHECK_VDB_TIMEOUT_FMT("Cannot get VDB cursor row range: "<<*this<<": "<<column, rc);
1368  NCBI_THROW2_FMT(CSraException, eInitFailed,
1369  "Cannot get VDB cursor row range: "<<*this<<": "<<column, rc);
1370  }
1371  return ret;
1372 }
1373 
1374 
1376 {
1378  return range.first+range.second-1;
1379 }
1380 
1381 
1382 void CVDBCursor::SetParam(const char* name, const CTempString& value) const
1383 {
1384  CFinalRequestContextUpdater ctx_updater;
1385  if ( rc_t rc = VCursorParamsSet
1386  ((struct VCursorParams *)GetPointer(),
1387  name, "%.*s", value.size(), value.data()) ) {
1389  "Cannot set VDB cursor param: "<<*this<<": "<<name,
1390  rc);
1391  }
1392 }
1393 
1394 
1396  uint32_t elem_bits) const
1397 {
1399  CFinalRequestContextUpdater ctx_updater;
1400  uint32_t read_count, remaining_count;
1401  if ( rc_t rc = VCursorReadBitsDirect(*this, row, column.GetIndex(),
1402  elem_bits, 0, 0, 0, 0,
1403  &read_count, &remaining_count) ) {
1404  CHECK_VDB_TIMEOUT_FMT("Cannot read VDB value array size: "<<*this<<column<<
1405  '['<<row<<']', rc);
1406  NCBI_THROW2_FMT(CSraException, eNotFoundValue,
1407  "Cannot read VDB value array size: "<<*this<<column<<
1408  '['<<row<<']', rc);
1409  }
1410  return remaining_count;
1411 }
1412 
1413 
1415  uint32_t elem_bits,
1416  uint32_t start, uint32_t count,
1417  void* buffer) const
1418 {
1420  CFinalRequestContextUpdater ctx_updater;
1421  uint32_t read_count, remaining_count;
1422  if ( rc_t rc = VCursorReadBitsDirect(*this, row, column.GetIndex(),
1423  elem_bits, start, buffer, 0, count,
1424  &read_count, &remaining_count) ) {
1425  CHECK_VDB_TIMEOUT_FMT("Cannot read VDB value array: "<<*this<<column<<
1426  '['<<row<<"]["<<start<<".."<<(start+count-1)<<']', rc);
1427  NCBI_THROW2_FMT(CSraException, eNotFoundValue,
1428  "Cannot read VDB value array: "<<*this<<column<<
1429  '['<<row<<"]["<<start<<".."<<(start+count-1)<<']', rc);
1430  }
1431  if ( read_count != count ) {
1432  NCBI_THROW_FMT(CSraException, eNotFoundValue,
1433  "Cannot read VDB value array: "<<*this<<column<<
1434  '['<<row<<"]["<<start<<".."<<(start+count-1)<<
1435  "] only "<<read_count<<" elements are read");
1436  }
1437  if ( s_GetDebugLevel() >= 9 ) {
1438  LOG_POST(Info<<"VDB "<<*this<<column<<'['<<row<<"]: @"<<start<<" #"<<count);
1439  }
1440 }
1441 
1442 
1443 /////////////////////////////////////////////////////////////////////////////
1444 // CVDBObjectCache
1445 
1446 static const size_t kCacheSize = 7;
1447 
1448 
1450 {
1451  m_Objects.reserve(kCacheSize);
1452 }
1453 
1454 
1456 {
1457 }
1458 
1459 
1461 
1462 
1464 {
1465  CFastMutexGuard guard(sm_CacheMutex);
1466  m_Objects.clear();
1467 }
1468 
1469 
1471 {
1472  CFastMutexGuard guard(sm_CacheMutex);
1473  if ( m_Objects.empty() ) {
1474  return 0;
1475  }
1476  TObjects::iterator best_it;
1479  TVDBRowId slot_row = it->first;
1480  if ( slot_row >= row ) {
1481  TVDBRowId d = slot_row - row;
1482  if ( d <= best_d ) {
1483  best_d = d;
1484  best_it = it;
1485  }
1486  }
1487  else {
1488  TVDBRowId d = row - slot_row;
1489  if ( d < best_d ) {
1490  best_d = d;
1491  best_it = it;
1492  }
1493  }
1494  }
1495  CObject* obj = best_it->second.Release();
1496  *best_it = m_Objects.back();
1497  m_Objects.pop_back();
1498  _ASSERT(!obj->Referenced());
1499  return obj;
1500 }
1501 
1502 
1504 {
1505  if ( obj->Referenced() ) {
1506  return;
1507  }
1508  //row = 0;
1509  CFastMutexGuard guard(sm_CacheMutex);
1510  if ( m_Objects.size() < kCacheSize ) {
1511  m_Objects.push_back(TSlot());
1512  m_Objects.back().first = row;
1513  m_Objects.back().second = obj;
1514  }
1515  else {
1516  CRef<CObject> ref(obj); // delete the object
1517  }
1518 }
1519 
1520 
1521 /////////////////////////////////////////////////////////////////////////////
1522 // CVDBColumn
1523 
1524 static inline
1526 {
1527  return out << '.' << column.GetName();
1528 }
1529 
1530 
1531 void CVDBColumn::Init(const CVDBCursor& cursor,
1532  size_t element_bit_size,
1533  const char* name,
1534  const char* backup_name,
1535  EMissing missing)
1536 {
1538  CFinalRequestContextUpdater ctx_updater;
1539  m_Name = name;
1540  //SIMULATE_SCHEMA_ERROR();
1541  if ( rc_t rc = VCursorAddColumn(cursor, &m_Index, name) ) {
1542  CHECK_VDB_TIMEOUT_FMT("Cannot get VDB column: "<<cursor<<*this, rc);
1543  if ( backup_name &&
1544  (rc = VCursorAddColumn(cursor, &m_Index, backup_name)) == 0 ) {
1545  m_Name = backup_name;
1546  }
1547  else {
1548  CHECK_VDB_TIMEOUT_FMT("Cannot get VDB column: "<<cursor<<*this, rc);
1550  if ( missing == eMissing_Throw ) {
1551  NCBI_THROW2_FMT(CSraException, eNotFoundColumn,
1552  "Cannot get VDB column: "<<cursor<<*this,rc);
1553  }
1554  else {
1555  return;
1556  }
1557  }
1558  }
1559  if ( element_bit_size ) {
1560  VTypedesc type;
1561  if ( rc_t rc = VCursorDatatype(cursor, m_Index, 0, &type) ) {
1562  CHECK_VDB_TIMEOUT_FMT("Cannot get VDB column type: "<<cursor<<*this,rc);
1563  NCBI_THROW2_FMT(CSraException, eInvalidState,
1564  "Cannot get VDB column type: "<<cursor<<*this,rc);
1565  }
1566  size_t size = type.intrinsic_bits*type.intrinsic_dim;
1567  if ( size != element_bit_size ) {
1568  ERR_POST_X(1, "Wrong VDB column size "<<cursor<<*this<<
1569  " expected "<<element_bit_size<<" bits != "<<
1570  type.intrinsic_dim<<"*"<<type.intrinsic_bits<<" bits");
1571  NCBI_THROW2_FMT(CSraException, eInvalidState,
1572  "Wrong VDB column size: "<<cursor<<*this<<": "<<size,
1573  RC(rcApp, rcColumn, rcConstructing, rcSelf, rcIncorrect));
1574  }
1575  }
1576 }
1577 
1578 
1579 bool CVDBColumn::IsStatic(const CVDBCursor& cursor) const
1580 {
1581  bool static_value;
1582  if ( rc_t rc = VCursorIsStaticColumn(cursor, GetIndex(), &static_value) ) {
1583  NCBI_THROW2_FMT(CSraException, eInvalidState,
1584  "Cannot get static status of "<<cursor<<*this,rc);
1585  }
1586  return static_value;
1587 }
1588 
1589 
1591 {
1592  try {
1593  if ( IsStatic(cursor) && CVDBValue(cursor, 1, *this).empty() ) {
1594  // value is always empty
1595  Reset();
1596  }
1597  }
1598  catch ( CException& /*ignored*/ ) {
1599  }
1600 }
1601 
1602 
1603 /////////////////////////////////////////////////////////////////////////////
1604 // CVDBValue
1605 
1607 {
1608  if ( m_Table ) {
1610  }
1611  if ( m_Row ) {
1612  out << '[' << m_Row << ']';
1613  }
1614  if ( m_ColumnName ) {
1615  out << '.' << m_ColumnName;
1616  }
1617  return out;
1618 }
1619 
1620 
1621 static inline
1623 {
1624  return obj.PrintFullName(out);
1625 }
1626 
1627 
1628 void CVDBValue::x_Get(const CVDBCursor& cursor, const CVDBColumn& column)
1629 {
1631  CFinalRequestContextUpdater ctx_updater;
1632  uint32_t bit_offset, bit_length;
1633  if ( rc_t rc = VCursorCellData(cursor, column.GetIndex(),
1634  &bit_length, &m_Data, &bit_offset,
1635  &m_ElemCount) ) {
1636  CHECK_VDB_TIMEOUT_FMT("Cannot read VDB value: "<<cursor<<column, rc);
1637  NCBI_THROW2_FMT(CSraException, eNotFoundValue,
1638  "Cannot read VDB value: "<<cursor<<column, rc);
1639  }
1640  if ( bit_offset ) {
1641  NCBI_THROW2_FMT(CSraException, eInvalidState,
1642  "Cannot read VDB value with non-zero bit offset: "
1643  <<cursor<<column<<": "<<bit_offset,
1644  RC(rcApp, rcColumn, rcDecoding, rcOffset, rcUnsupported));
1645  }
1646  if ( s_GetDebugLevel() >= 9 ) {
1647  CNcbiOstrstream s;
1648  if ( bit_length == 8 ) {
1649  s << '"' << NStr::PrintableString(CTempString((const char*)m_Data, m_ElemCount)) << '"';
1650  }
1651  else if ( bit_length == 16 ) {
1652  for ( uint32_t i = 0; i < m_ElemCount; ++i ) {
1653  if ( i ) {
1654  s << ", ";
1655  }
1656  s << ((const int16_t*)m_Data)[i];
1657  }
1658  }
1659  else if ( bit_length == 32 ) {
1660  for ( uint32_t i = 0; i < m_ElemCount; ++i ) {
1661  if ( i ) {
1662  s << ", ";
1663  }
1664  s << ((const int32_t*)m_Data)[i];
1665  }
1666  }
1667  else if ( bit_length == 64 ) {
1668  for ( uint32_t i = 0; i < m_ElemCount; ++i ) {
1669  if ( i ) {
1670  s << ", ";
1671  }
1672  s << ((const int64_t*)m_Data)[i];
1673  }
1674  }
1675  else {
1676  s << "*** bad bit_length="<<bit_length;
1677  }
1678  LOG_POST(Info<<"VDB "<<cursor<<column<<": "<<CNcbiOstrstreamToString(s));
1679  }
1680  m_Ref.Set(cursor, 0, column);
1681 }
1682 
1683 
1684 void CVDBValue::x_Get(const CVDBCursor& cursor,
1685  TVDBRowId row,
1686  const CVDBColumn& column,
1687  EMissing missing)
1688 {
1690  CFinalRequestContextUpdater ctx_updater;
1691  uint32_t bit_offset, bit_length;
1692  if ( rc_t rc = VCursorCellDataDirect(cursor, row, column.GetIndex(),
1693  &bit_length, &m_Data, &bit_offset,
1694  &m_ElemCount) ) {
1695  CHECK_VDB_TIMEOUT_FMT("Cannot read VDB value: "<<cursor<<column<<'['<<row<<']', rc);
1696  if ( missing != eMissing_Throw ) {
1697  m_Data = 0;
1698  m_ElemCount = 0;
1699  return;
1700  }
1701  NCBI_THROW2_FMT(CSraException, eNotFoundValue,
1702  "Cannot read VDB value: "<<cursor<<column<<'['<<row<<']', rc);
1703  }
1704  if ( bit_offset ) {
1705  NCBI_THROW2_FMT(CSraException, eInvalidState,
1706  "Cannot read VDB value with non-zero bit offset: "<<
1707  cursor<<column<<'['<<row<<"]: "<<bit_offset,
1708  RC(rcApp, rcColumn, rcDecoding, rcOffset, rcUnsupported));
1709  }
1710  if ( s_GetDebugLevel() >= 9 ) {
1711  CNcbiOstrstream s;
1712  if ( bit_length == 8 ) {
1713  s << '"' << NStr::PrintableString(CTempString((const char*)m_Data, m_ElemCount)) << '"';
1714  }
1715  else if ( bit_length == 16 ) {
1716  for ( uint32_t i = 0; i < m_ElemCount; ++i ) {
1717  if ( i ) {
1718  s << ", ";
1719  }
1720  s << ((const int16_t*)m_Data)[i];
1721  }
1722  }
1723  else if ( bit_length == 32 ) {
1724  for ( uint32_t i = 0; i < m_ElemCount; ++i ) {
1725  if ( i ) {
1726  s << ", ";
1727  }
1728  s << ((const int32_t*)m_Data)[i];
1729  }
1730  }
1731  else if ( bit_length == 64 ) {
1732  for ( uint32_t i = 0; i < m_ElemCount; ++i ) {
1733  if ( i ) {
1734  s << ", ";
1735  }
1736  s << ((const int64_t*)m_Data)[i];
1737  }
1738  }
1739  else {
1740  s << "*** bad bit_length="<<bit_length;
1741  }
1742  LOG_POST(Info<<"VDB "<<cursor<<column<<'['<<row<<"]: "<<CNcbiOstrstreamToString(s));
1743  }
1744  m_Ref.Set(cursor, row, column);
1745 }
1746 
1747 
1748 void CVDBValue::x_ReportIndexOutOfBounds(size_t index) const
1749 {
1750  if ( index >= size() ) {
1751  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1752  "Invalid index for VDB value array: "<<
1753  *this<<'['<<index<<']',
1754  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1755  }
1756 }
1757 
1758 
1760 {
1761  if ( size() != 1 ) {
1762  NCBI_THROW2_FMT(CSraException, eDataError,
1763  "VDB value array doen't have single value: "<<
1764  *this<<'['<<size()<<']',
1765  RC(rcApp, rcData, rcRetrieving, rcSize, rcIncorrect));
1766  }
1767 }
1768 
1769 
1770 void CVDBValue::x_CheckRange(size_t pos, size_t len) const
1771 {
1772  if ( pos > size() ) {
1773  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1774  "Invalid index for VDB value array: "<<
1775  *this<<'['<<pos<<']',
1776  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1777  }
1778  if ( pos+len < pos ) {
1779  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1780  "Invalid length for VDB value sub-array: "<<
1781  *this<<'['<<pos<<','<<len<<']',
1782  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1783  }
1784  if ( pos+len > size() ) {
1785  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1786  "Invalid end of VDB value sub-array: "<<
1787  *this<<'['<<pos<<','<<len<<']',
1788  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1789  }
1790 }
1791 
1792 
1793 static inline
1795 {
1796  return obj.PrintFullName(out);
1797 }
1798 
1799 
1801  TVDBRowId row,
1802  const CVDBColumn& column)
1803 {
1805  CFinalRequestContextUpdater ctx_updater;
1806  uint32_t bit_offset, bit_length, elem_count;
1807  const void* data;
1808  if ( rc_t rc = VCursorCellDataDirect(cursor, row, column.GetIndex(),
1809  &bit_length, &data, &bit_offset,
1810  &elem_count) ) {
1811  CHECK_VDB_TIMEOUT_FMT("Cannot read VDB 4-bits value array: "<<
1812  cursor<<column<<'['<<row<<']', rc);
1813  NCBI_THROW2_FMT(CSraException, eNotFoundValue,
1814  "Cannot read VDB 4-bits value array: "<<
1815  cursor<<column<<'['<<row<<']', rc);
1816  }
1817  if ( bit_offset >= 8 || (bit_offset&3) ) {
1818  NCBI_THROW2_FMT(CSraException, eInvalidState,
1819  "Cannot read VDB 4-bits value array with odd bit offset"<<
1820  cursor<<column<<'['<<row<<"]: "<<bit_offset,
1821  RC(rcApp, rcColumn, rcDecoding, rcOffset, rcUnsupported));
1822  }
1823  m_RawData = static_cast<const char*>(data);
1824  m_ElemOffset = bit_offset >> 2;
1825  m_ElemCount = elem_count;
1826  if ( s_GetDebugLevel() >= 9 ) {
1827  CNcbiOstrstream s;
1828  if ( bit_length == 4 ) {
1829  for ( uint32_t i = 0; i < elem_count; ++i ) {
1830  if ( i ) {
1831  s << ", ";
1832  }
1833  s << '?';
1834  }
1835  }
1836  else {
1837  s << "*** bad bit_length="<<bit_length;
1838  }
1839  LOG_POST(Info<<"VDB "<<cursor<<column<<'['<<row<<"]: "<<CNcbiOstrstreamToString(s));
1840  }
1841  m_Ref.Set(cursor, row, column);
1842 }
1843 
1844 
1846 {
1847  if ( index >= size() ) {
1848  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1849  "Invalid index for VDB 4-bits value array: "<<
1850  *this<<'['<<index<<']',
1851  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1852  }
1853 }
1854 
1855 
1856 inline
1857 void CVDBValueFor4Bits::x_CheckRange(size_t pos, size_t len) const
1858 {
1859  if ( pos > size() ) {
1860  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1861  "Invalid index for VDB 4-bits value array: "<<
1862  *this<<'['<<pos<<']',
1863  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1864  }
1865  if ( pos+len < pos ) {
1866  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1867  "Invalid length for VDB 4-bits value sub-array: "<<
1868  *this<<'['<<pos<<','<<len<<']',
1869  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1870  }
1871  if ( pos+len > size() ) {
1872  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1873  "Invalid end of VDB 4-bits value sub-array: "<<
1874  *this<<'['<<pos<<','<<len<<']',
1875  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1876  }
1877 }
1878 
1879 
1881 {
1882  x_CheckRange(pos, len);
1883  size_t offset = m_ElemOffset + pos;
1884  const char* raw_data = m_RawData + offset/2;
1885  offset %= 2;
1886  // limits are checked above
1887  return CVDBValueFor4Bits(m_Ref, raw_data, uint32_t(offset), uint32_t(len));
1888 }
1889 
1890 
1891 static inline
1893 {
1894  return obj.PrintFullName(out);
1895 }
1896 
1897 
1899  TVDBRowId row,
1900  const CVDBColumn& column)
1901 {
1903  CFinalRequestContextUpdater ctx_updater;
1904  uint32_t bit_offset, bit_length, elem_count;
1905  const void* data;
1906  if ( rc_t rc = VCursorCellDataDirect(cursor, row, column.GetIndex(),
1907  &bit_length, &data, &bit_offset,
1908  &elem_count) ) {
1909  CHECK_VDB_TIMEOUT_FMT("Cannot read VDB 2-bits value array: "<<
1910  cursor<<column<<'['<<row<<']', rc);
1911  NCBI_THROW2_FMT(CSraException, eNotFoundValue,
1912  "Cannot read VDB 2-bits value array: "<<
1913  cursor<<column<<'['<<row<<']', rc);
1914  }
1915  if ( bit_offset >= 8 || (bit_offset&1) ) {
1916  NCBI_THROW2_FMT(CSraException, eInvalidState,
1917  "Cannot read VDB 2-bits value array with odd bit offset"<<
1918  cursor<<column<<'['<<row<<"]: "<<bit_offset,
1919  RC(rcApp, rcColumn, rcDecoding, rcOffset, rcUnsupported));
1920  }
1921  m_RawData = static_cast<const char*>(data);
1922  m_ElemOffset = bit_offset >> 1;
1923  m_ElemCount = elem_count;
1924  if ( s_GetDebugLevel() >= 9 ) {
1925  CNcbiOstrstream s;
1926  if ( bit_length == 2 ) {
1927  for ( uint32_t i = 0; i < elem_count; ++i ) {
1928  if ( i ) {
1929  s << ", ";
1930  }
1931  s << '?';
1932  }
1933  }
1934  else {
1935  s << "*** bad bit_length="<<bit_length;
1936  }
1937  LOG_POST(Info<<"VDB "<<cursor<<column<<'['<<row<<"]: "<<CNcbiOstrstreamToString(s));
1938  }
1939  m_Ref.Set(cursor, row, column);
1940 }
1941 
1942 
1944 {
1945  if ( index >= size() ) {
1946  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1947  "Invalid index for VDB 2-bits value array: "<<
1948  *this<<'['<<index<<']',
1949  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1950  }
1951 }
1952 
1953 
1954 inline
1955 void CVDBValueFor2Bits::x_CheckRange(size_t pos, size_t len) const
1956 {
1957  if ( pos > size() ) {
1958  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1959  "Invalid index for VDB 2-bits value array: "<<
1960  *this<<'['<<pos<<']',
1961  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1962  }
1963  if ( pos+len < pos ) {
1964  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1965  "Invalid length for VDB 2-bits value sub-array: "<<
1966  *this<<'['<<pos<<','<<len<<']',
1967  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1968  }
1969  if ( pos+len > size() ) {
1970  NCBI_THROW2_FMT(CSraException, eInvalidIndex,
1971  "Invalid end of VDB 2-bits value sub-array: "<<
1972  *this<<'['<<pos<<','<<len<<']',
1973  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig));
1974  }
1975 }
1976 
1977 
1979 {
1980  x_CheckRange(pos, len);
1981  size_t offset = m_ElemOffset + pos;
1982  const char* raw_data = m_RawData + offset/4;
1983  offset %= 4;
1984  // limits are checked above
1985  return CVDBValueFor2Bits(m_Ref, raw_data, uint32_t(offset), uint32_t(len));
1986 }
1987 
1988 
uint32_t rc_t
CClientHttpRequest(const CKNSManager &mgr, const string &path)
Definition: vdbread.cpp:583
CClientHttpResult(const CClientHttpRequest &request, EHead)
Definition: vdbread.cpp:608
CDirEntry –.
Definition: ncbifile.hpp:262
CFinalRequestContextUpdater(const CFinalRequestContextUpdater &)=delete
void Commit() const
Definition: vdbread.cpp:207
CKConfig(void)
Definition: vdbread.cpp:175
CKDBManager(const CVDBMgr &mgr)
Definition: vdbread.cpp:255
CKNSManager(const CVFSManager &mgr)
Definition: vdbread.cpp:279
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObject –.
Definition: ncbiobj.hpp:180
CSafeStatic<>::
Definition: Seq_entry.hpp:56
Definition: sdk.hpp:85
TObject ** x_InitPtr(void)
Definition: sdk.hpp:175
TObject * GetPointer(void) const
Definition: sdk.hpp:146
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTimeFormat –.
Definition: ncbitime.hpp:131
CTime –.
Definition: ncbitime.hpp:296
@ eMissing_Throw
Definition: vdbread.hpp:473
@ kInvalidIndex
Definition: vdbread.hpp:478
TVDBColumnIdx GetIndex(void) const
Definition: vdbread.hpp:523
const char * m_Name
Definition: vdbread.hpp:542
TVDBColumnIdx m_Index
Definition: vdbread.hpp:543
void ResetIfAlwaysEmpty(const CVDBCursor &cursor)
Definition: vdbread.cpp:1590
bool IsStatic(const CVDBCursor &cursor) const
Definition: vdbread.cpp:1579
void Init(const CVDBCursor &cursor, size_t element_bit_size, const char *name, const char *backup_name, EMissing missing)
Definition: vdbread.cpp:1531
void Reset(void)
Definition: vdbread.hpp:510
rc_t OpenRowRc(TVDBRowId row_id)
Definition: vdbread.cpp:1338
void OpenRow(TVDBRowId row_id)
Definition: vdbread.cpp:1353
bool RowIsOpened(void) const
Definition: vdbread.hpp:391
void CloseRow(void)
Definition: vdbread.cpp:1325
uint32_t GetElementCount(TVDBRowId row, const CVDBColumn &column, uint32_t elem_bits) const
Definition: vdbread.cpp:1395
const CVDBTable & GetTable(void) const
Definition: vdbread.hpp:386
void ReadElements(TVDBRowId row, const CVDBColumn &column, uint32_t elem_bits, uint32_t start, uint32_t count, void *buffer) const
Definition: vdbread.cpp:1414
bool m_RowOpened
Definition: vdbread.hpp:426
void SetParam(const char *name, const CTempString &value) const
Definition: vdbread.cpp:1382
CVDBTable m_Table
Definition: vdbread.hpp:425
void Init(const CVDBTable &table)
Definition: vdbread.cpp:1293
TVDBRowId GetMaxRowId(void) const
Definition: vdbread.cpp:1375
TVDBRowIdRange GetRowIdRange(TVDBColumnIdx column=0) const
Definition: vdbread.cpp:1363
CVDBMgr(void)
Definition: vdbread.cpp:501
void DeleteCacheOlderThan(Uint4 days)
Definition: vdbread.cpp:1033
CVResolver m_Resolver
Definition: vdbread.hpp:261
string GetCacheRoot() const
Definition: vdbread.cpp:1008
string FindDereferencedAccPath(const string &acc_or_path) const
Definition: vdbread.cpp:517
CTime GetTimestamp(const string &path) const
Definition: vdbread.cpp:547
CTime GetURLTimestamp(const string &url) const
Definition: vdbread.cpp:622
string FindAccPath(const string &acc) const
Definition: vdbread.cpp:508
void SetCacheRoot(const string &path)
Definition: vdbread.cpp:1023
void CommitConfig() const
Definition: vdbread.cpp:1042
void x_Init(void)
Definition: vdbread.cpp:994
CObject * Get(TVDBRowId row)
Definition: vdbread.cpp:1470
TObjects m_Objects
Definition: vdbread.hpp:445
void Put(CObject *curs, TVDBRowId row)
Definition: vdbread.cpp:1503
pair< TVDBRowId, CRef< CObject > > TSlot
Definition: vdbread.hpp:443
~CVDBObjectCacheBase(void)
Definition: vdbread.cpp:1455
vector< TSlot > TObjects
Definition: vdbread.hpp:444
void Clear(void)
Definition: vdbread.cpp:1463
string GetFullName(void) const
Definition: vdbread.cpp:1251
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: vdbread.cpp:1257
const char * GetName(void) const
Definition: vdbread.hpp:353
const CVDBTable & GetTable(void) const
Definition: vdbread.hpp:349
TVDBRowIdRange Find(const string &value) const
Definition: vdbread.cpp:1263
CVDBTableIndex(void)
Definition: vdbread.hpp:342
string GetFullName(void) const
Definition: vdbread.cpp:1193
@ eMissing_Throw
Definition: vdbread.hpp:298
const CVDB & GetDb(void) const
Definition: vdbread.hpp:312
CVDBTable(void)
Definition: vdbread.hpp:302
const string & GetName(void) const
Definition: vdbread.hpp:316
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: vdbread.cpp:1205
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: vdbread.hpp:881
void x_Get(const CVDBCursor &cursor, TVDBRowId row, const CVDBColumn &column)
Definition: vdbread.cpp:1898
void x_ReportIndexOutOfBounds(size_t index) const
Definition: vdbread.cpp:1943
CVDBValueFor2Bits substr(size_t pos, size_t len) const
Definition: vdbread.cpp:1978
void x_CheckRange(size_t pos, size_t len) const
Definition: vdbread.cpp:1955
void x_CheckRange(size_t pos, size_t len) const
Definition: vdbread.cpp:1857
CVDBValueFor4Bits substr(size_t pos, size_t len) const
Definition: vdbread.cpp:1880
void x_ReportIndexOutOfBounds(size_t index) const
Definition: vdbread.cpp:1845
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: vdbread.hpp:782
void x_Get(const CVDBCursor &cursor, TVDBRowId row, const CVDBColumn &column)
Definition: vdbread.cpp:1800
void x_CheckRange(size_t pos, size_t len) const
Definition: vdbread.cpp:1770
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: vdbread.hpp:691
const void * m_Data
Definition: vdbread.hpp:721
uint32_t m_ElemCount
Definition: vdbread.hpp:722
size_t size(void) const
Definition: vdbread.hpp:686
@ eMissing_Throw
Definition: vdbread.hpp:611
SSaveRef m_Ref
Definition: vdbread.hpp:720
void x_Get(const CVDBCursor &cursor, const CVDBColumn &column)
Definition: vdbread.cpp:1628
void x_ReportNotOneValue(void) const
Definition: vdbread.cpp:1759
void x_ReportIndexOutOfBounds(size_t index) const
Definition: vdbread.cpp:1748
const string & GetFullName(void) const
Definition: vdbread.hpp:278
CVDB(void)
Definition: vdbread.hpp:269
const string & GetName(void) const
Definition: vdbread.hpp:274
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: vdbread.cpp:1108
void x_InitNew(void)
Definition: vdbread.cpp:231
CVFSManager(void)
Definition: vdbread.cpp:219
@ eSys
Definition: vdbread.hpp:148
@ eAcc
Definition: vdbread.hpp:149
string ToString(EType type=eSys) const
Definition: vdbread.cpp:349
bool IsLocalFile() const
Definition: vdbread.cpp:332
static string ConvertAccOrSysPathToPOSIX(const string &acc_or_path)
Definition: vdbread.cpp:419
void x_Init(const CVFSManager &mgr, const string &path, EType type)
Definition: vdbread.cpp:304
static bool IsPlainAccession(const string &acc_or_path)
Definition: vdbread.cpp:380
static string ConvertSysPathToPOSIX(const string &sys_path)
Definition: vdbread.cpp:392
CVPath(void)
Definition: vdbread.hpp:136
CVFSManager m_Mgr
Definition: vdbread.hpp:211
CVResolver(const CVFSManager &mgr)
Definition: vdbread.cpp:431
string Resolve(const string &acc) const
Definition: vdbread.cpp:453
char value[7]
Definition: config.c:431
struct config config
std::ofstream out("events_result.xml")
main entry point for tests
static int type
Definition: getdata.c:31
static string GetAppName(EAppNameType name_type=eBaseName, int argc=0, const char *const *argv=NULL)
Definition: ncbiapp.cpp:1357
static CNcbiApplicationGuard InstanceGuard(void)
Singleton method.
Definition: ncbiapp.cpp:133
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
CVersionInfo GetVersion(void) const
Get the program version information.
Definition: ncbiapp.cpp:1164
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
@ null
Definition: ncbimisc.hpp:646
#define NULL
Definition: ncbistd.hpp:225
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define LOG_POST_X(err_subcode, message)
Definition: ncbidiag.hpp:553
const CNcbiDiag &(* FManip)(const CNcbiDiag &)
Diagnostic stream manipulator.
Definition: ncbidiag.hpp:954
string GetSessionID(void) const
Session ID.
CAtomicCounter::TValue TVersion
bool IsSetSessionID(void) const
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
Definition: ncbidiag.cpp:1901
string GetClientIP(void) const
Client IP/hostname.
bool IsSetHitID(EHitIDSource src=eHitID_Any) const
Check if there's an explicit hit id or the default one.
#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
string GetHitID(void) const
Get explicit hit id or the default one (from HTTP_NCBI_PHID etc).
TVersion GetVersion(void) const
Return version increased on every context change (hit/subhit id, client ip, session id).
#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
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
void Trace(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1179
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
void Fatal(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1209
#define NCBI_THROW2(exception_class, err_code, message, extra)
Throw exception with extra parameter.
Definition: ncbiexpt.hpp:1754
#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
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
static string CreateAbsolutePath(const string &path, ERelativeToWhat rtw=eRelativeToCwd)
Get an absolute path from some, possibly relative, path.
Definition: ncbifile.cpp:665
void DereferencePath(void)
Dereference a path.
Definition: ncbifile.cpp:2415
virtual bool Exists(void) const
Check the entry existence.
Definition: ncbifile.cpp:2325
const string & GetPath(void) const
Get entry path.
Definition: ncbifile.hpp:3910
bool Referenced(void) const THROWS_NONE
Check if object is referenced.
Definition: ncbiobj.hpp:468
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
Definition: ncbi_param.hpp:149
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
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
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
Definition: ncbistr.cpp:3949
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NPOS
Definition: ncbistr.hpp:133
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3197
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5083
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:5411
size_type find(const CTempString match, size_type pos=0) const
Find the first instance of the entire matching string within the current string, beginning at an opti...
Definition: tempstr.hpp:655
size_type size(void) const
Return the length of the represented array.
Definition: tempstr.hpp:327
bool IsUniversalTime(void) const
Is time universal (GMT/UTC/Z)?
Definition: ncbitime.hpp:2422
bool IsEmpty(void) const
Is time object empty (date and time)?
Definition: ncbitime.hpp:2378
CTime & ToUniversalTime(void)
Convert the time into universal (GMT/UTC) time.
Definition: ncbitime.hpp:2472
virtual string Print(void) const
Print version information.
Definition: version.cpp:120
#define NCBI_SRAREAD_EXPORT
Definition: ncbi_export.h:1227
#define NCBI_DEVELOPMENT_VER
#define DEBUG
Definition: config.h:32
Definition of all error codes used in SRA C++ support libraries.
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
int i
int len
range(_Ty, _Ty) -> range< _Ty >
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::SIZE size
string s_Value(TValue value)
#define NCBI_PACKAGE_NAME
#define NCBI_PACKAGE_VERSION
const char * tag
int isalpha(Uchar c)
Definition: ncbictype.hpp:61
int toupper(Uchar c)
Definition: ncbictype.hpp:73
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Multi-threading – mutexes; rw-locks; semaphore.
T max(T x_, T y_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
static const char table_name[]
Definition: bcp.c:249
static const char * prefix[]
Definition: pcregrep.c:405
static pcre_uint8 * buffer
Definition: pcretest.c:1051
@ eNotFound
Not found.
int offset
Definition: replacements.h:160
Defines CRequestContext class for NCBI C++ diagnostic API.
#define CHECK_VDB_TIMEOUT_FMT(msg, rc)
Definition: exception.hpp:186
#define CHECK_VDB_TIMEOUT(msg, rc)
Definition: exception.hpp:181
#define NCBI_THROW2_FMT(exception_class, err_code, message, extra)
Definition: exception.hpp:176
static const char * str(char *buf, int n)
Definition: stats.c:84
static const char * column
Definition: stats.c:23
signed short int16_t
Definition: stdint.h:122
signed __int64 int64_t
Definition: stdint.h:135
unsigned int uint32_t
Definition: stdint.h:126
signed int int32_t
Definition: stdint.h:123
void Set(const CVDBCursor &cursor, TVDBRowId row, const CVDBColumn &column)
Definition: vdbread.hpp:633
const CVDBTable * m_Table
Definition: vdbread.hpp:644
const char * m_ColumnName
Definition: vdbread.hpp:645
CNcbiOstream & PrintFullName(CNcbiOstream &out) const
Definition: vdbread.cpp:1606
const char * tag
Definition: bamread.cpp:529
CNcbiDiag::FManip manip
Definition: bamread.cpp:530
Definition: type.c:6
#define _ASSERT
else result
Definition: token2.c:20
static const SVDBSeverityTag kSeverityTags[]
Definition: vdbread.cpp:708
static const size_t kCacheSize
Definition: vdbread.cpp:1446
static char s_VDBVersion[32]
Definition: vdbread.cpp:667
static bool s_HasWindowsDriveLetter(const string &s)
Definition: vdbread.cpp:372
static rc_t VDBLogWriter(void *, const char *buffer, size_t size, size_t *written)
Definition: vdbread.cpp:751
DEFINE_SRA_REF_TRAITS(VDBManager, const)
static void s_InitLocalKNS(KNSManager *kns_mgr)
Definition: vdbread.cpp:891
DECLARE_SRA_REF_TRAITS(KClientHttpRequest,)
static void s_InitAllKNS(KNSManager *kns_mgr)
Definition: vdbread.cpp:852
static int s_GetDiagHandler(void)
Definition: vdbread.cpp:94
static const SVDBSeverityTag * s_GetVDBSeverityTag(CTempString token)
Definition: vdbread.cpp:717
DEFINE_STATIC_FAST_MUTEX(sx_SDKMutex)
static void s_InitVDBVersion()
Definition: vdbread.cpp:670
#define SIMULATE_RESOLVE_ERROR()
Definition: vdbread.cpp:166
static CKConfig s_InitProxyConfig()
Definition: vdbread.cpp:782
#define DECLARE_SDK_GET_GUARD()
Definition: vdbread.cpp:656
static void s_InitStaticKNS(KNSManager *kns_mgr)
Definition: vdbread.cpp:885
#define SIMULATE_SCHEMA_ERROR()
Definition: vdbread.cpp:168
static void s_VDBInit()
Definition: vdbread.cpp:897
static void s_InitDiagCheck()
Definition: vdbread.cpp:733
#define DECLARE_SDK_GUARD()
Definition: vdbread.cpp:650
static bool s_DiagIsSafe()
Definition: vdbread.cpp:740
NCBI_DEFINE_ERR_SUBCODE_X(9)
NCBI_PARAM_DEF(int, VDB, DIAG_HANDLER, 1)
static int s_GetDebugLevel(void)
Definition: vdbread.cpp:106
static void s_UpdateVDBRequestContext(void)
Definition: vdbread.cpp:822
NCBI_PARAM_DECL(int, VDB, DIAG_HANDLER)
NCBI_PARAM_DEF_EX(int, VDB, DEBUG, 0, eParam_NoThread, VDB_DEBUG)
static DECLARE_TLS_VAR(const CRequestContext *, s_LastRequestContext)
static CNcbiOstream & operator<<(CNcbiOstream &out, const CVDBTable &obj)
Definition: vdbread.cpp:1118
#define SIMULATE_OPEN_ERROR()
Definition: vdbread.cpp:167
uint32_t TVDBColumnIdx
Definition: vdbread.hpp:84
pair< TVDBRowId, TVDBRowCount > TVDBRowIdRange
Definition: vdbread.hpp:83
int64_t TVDBRowId
Definition: vdbread.hpp:79
Modified on Thu Dec 07 10:09:59 2023 by modify_doxy.py rev. 669887