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

Go to the SVN repository for this file.

1 /* $Id: cass_blob_op.cpp 99662 2023-04-27 17:46:59Z saprykin $
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: Dmitri Dmitrienko
27  *
28  * File Description:
29  *
30  * cassandra high-level functionality around blobs
31  *
32  */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbireg.hpp>
36 
44 
45 #include <algorithm>
46 #include <mutex>
47 #include <atomic>
48 #include <fstream>
49 #include <vector>
50 #include <list>
51 #include <utility>
52 #include <memory>
53 #include <string>
54 
57 
59 
60 constexpr const char * kSettingLargeChunkSize = "LARGE_CHUNK_SZ";
61 constexpr const char * kSettingBigBlobSize = "BIG_BLOB_SZ";
62 constexpr int64_t kChunkSizeMin = 4 * 1024;
63 constexpr int64_t kChunkSizeDefault = 512 * 1024;
64 constexpr int64_t kActiveStatementsMax = 512;
65 
66 END_SCOPE()
67 
68 /** CCassBlobWaiter */
69 
70 bool CCassBlobWaiter::CheckMaxActive()
71 {
72  return (m_Conn->GetActiveStatements() < kActiveStatementsMax);
73 }
74 
75 void CCassBlobOp::GetBlobChunkSize(unsigned int timeout_ms, const string & keyspace, int64_t * chunk_size)
76 {
77  string s;
78  if (
79  !GetSetting(timeout_ms, keyspace, kSettingLargeChunkSize, s)
82  ) {
84  }
85 }
86 
87 void CCassBlobOp::GetBigBlobSizeLimit(unsigned int timeout_ms, const string & keyspace, int64_t * value)
88 {
89  string s;
90  if (!GetSetting(timeout_ms, keyspace, kSettingBigBlobSize, s) || !NStr::StringToNumeric(s, value)) {
91  *value = -1;
92  }
93 }
94 
95 bool CCassBlobOp::GetSetting(unsigned int op_timeout_ms, const string & domain, const string & name, string & value)
96 {
97  bool rslt = false;
98  CCassConnection::Perform(op_timeout_ms, nullptr, nullptr,
99  [this, domain, name, &value, &rslt]
100  (bool is_repeated)
101  {
102  auto qry = m_Conn->NewQuery();
103  qry->SetSQL("SELECT value FROM maintenance.settings WHERE domain = ? AND name = ?", 2);
104  qry->BindStr(0, domain);
105  qry->BindStr(1, name);
106  CassConsistency cons = is_repeated && m_Conn->GetFallBackRdConsistency() ?
107  CASS_CONSISTENCY_LOCAL_ONE : CASS_CONSISTENCY_LOCAL_QUORUM;
108  qry->Query(cons, false, false);
109  if (qry->NextRow() == ar_dataready) {
110  qry->FieldGetStrValue(0, value);
111  rslt = true;
112  }
113  return true;
114  }
115  );
116 
117  return rslt;
118 }
119 
#define END_IDBLOB_SCOPE
Definition: IdCassScope.hpp:40
#define BEGIN_IDBLOB_SCOPE
Definition: IdCassScope.hpp:39
constexpr const char * kSettingBigBlobSize
constexpr int64_t kChunkSizeDefault
constexpr int64_t kChunkSizeMin
BEGIN_IDBLOB_SCOPE USING_NCBI_SCOPE
constexpr int64_t kActiveStatementsMax
constexpr const char * kSettingLargeChunkSize
@ ar_dataready
Definition: cass_driver.hpp:70
void GetBigBlobSizeLimit(unsigned int timeout_ms, const string &keyspace, int64_t *value)
bool GetSetting(unsigned int op_timeout_ms, const string &domain, const string &name, string &value)
shared_ptr< CCassConnection > m_Conn
void GetBlobChunkSize(unsigned int timeout_ms, const string &keyspace, int64_t *chunk_size)
static void Perform(unsigned int optimeoutms, const std::function< bool()> &PreLoopCB, const std::function< void(const CCassandraException &)> &DbExceptCB, const std::function< bool(bool)> &OpCB)
static const int chunk_size
char value[7]
Definition: config.c:431
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
static TNumeric StringToNumeric(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to a numeric value.
Definition: ncbistr.hpp:330
Process information in the NCBI Registry, including working with configuration files.
signed __int64 int64_t
Definition: stdint.h:135
#define const
Definition: zconf.h:230
Modified on Wed Dec 06 07:15:49 2023 by modify_doxy.py rev. 669887