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 101912 2024-03-01 15:39:23Z 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 
40 
41 #include <mutex>
42 #include <string>
43 
46 
48 
49 constexpr const char * kSettingLargeChunkSize = "LARGE_CHUNK_SZ";
50 constexpr const char * kSettingBigBlobSize = "BIG_BLOB_SZ";
51 constexpr int64_t kChunkSizeMin = 4 * 1024;
52 constexpr int64_t kChunkSizeDefault = 512 * 1024;
53 constexpr int64_t kActiveStatementsMax = 512;
54 
55 END_SCOPE()
56 
57 /** CCassBlobWaiter */
58 
59 bool CCassBlobWaiter::CheckMaxActive()
60 {
61  return (m_Conn->GetActiveStatements() < kActiveStatementsMax);
62 }
63 
64 void CCassBlobWaiter::SetQueryTimeout(std::chrono::milliseconds value)
65 {
67 }
68 
69 std::chrono::milliseconds CCassBlobWaiter::GetQueryTimeout() const
70 {
71  return m_QueryTimeout;
72 }
73 
74 shared_ptr<CCassQuery> CCassBlobWaiter::ProduceQuery() const
75 {
76  auto query = m_Conn->NewQuery();
77  if (m_QueryTimeout.count() > 0) {
78  query->SetTimeout(m_QueryTimeout.count());
79  query->UsePerRequestTimeout(true);
80  }
81  return query;
82 }
83 
84 void CCassBlobOp::GetBlobChunkSize(unsigned int timeout_ms, const string & keyspace, int64_t * chunk_size)
85 {
86  string s;
87  if (
88  !GetSetting(timeout_ms, keyspace, kSettingLargeChunkSize, s)
91  ) {
93  }
94 }
95 
96 void CCassBlobOp::GetBigBlobSizeLimit(unsigned int timeout_ms, const string & keyspace, int64_t * value)
97 {
98  string s;
99  if (!GetSetting(timeout_ms, keyspace, kSettingBigBlobSize, s) || !NStr::StringToNumeric(s, value)) {
100  *value = -1;
101  }
102 }
103 
104 bool CCassBlobOp::GetSetting(unsigned int op_timeout_ms, const string & domain, const string & name, string & value)
105 {
106  bool rslt = false;
107  CCassConnection::Perform(op_timeout_ms, nullptr, nullptr,
108  [this, domain, name, &value, &rslt]
109  (bool is_repeated)
110  {
111  auto qry = m_Conn->NewQuery();
112  qry->SetSQL("SELECT value FROM maintenance.settings WHERE domain = ? AND name = ?", 2);
113  qry->BindStr(0, domain);
114  qry->BindStr(1, name);
115  CassConsistency cons = is_repeated && m_Conn->GetFallBackRdConsistency() ?
116  CASS_CONSISTENCY_LOCAL_ONE : CASS_CONSISTENCY_LOCAL_QUORUM;
117  qry->Query(cons, false, false);
118  if (qry->NextRow() == ar_dataready) {
119  qry->FieldGetStrValue(0, value);
120  rslt = true;
121  }
122  return true;
123  }
124  );
125 
126  return rslt;
127 }
128 
#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)
std::chrono::milliseconds m_QueryTimeout
shared_ptr< CCassConnection > m_Conn
shared_ptr< CCassQuery > ProduceQuery() const
virtual std::chrono::milliseconds GetQueryTimeout() const
virtual void SetQueryTimeout(std::chrono::milliseconds value)
Experimental!!! May conflict with CCassConnection::SetQueryTimeoutRetry() when query timed out and CC...
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
Int8 int64_t
#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
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Process information in the NCBI Registry, including working with configuration files.
static string query
#define const
Definition: zconf.h:232
Modified on Sat Jun 22 10:44:24 2024 by modify_doxy.py rev. 669887