48 : m_Verbose(
verbose), m_Db(
NULL), m_Timeout(timeout, 0)
64 cout <<
"Connecting to the NetStorage meta info database..."
68 cout <<
"Connected" << endl;
70 cerr <<
"Error connecting to the NetStorage meta info database" << endl;
79 cout <<
"Closing the NetStorage meta info database connection..."
83 cout <<
"Closed" << endl;
91 cout <<
"Getting the application lock..." << endl;
96 query.SetParameter(
"@Resource",
"GarbageCollectorLock");
97 query.SetParameter(
"@LockMode",
"Exclusive");
98 query.SetParameter(
"@LockOwner",
"Session");
99 query.SetParameter(
"@LockTimeout", 0);
102 int status =
query.GetStatus();
107 "sp_getapplock return code: " +
109 }
catch (
const exception & exc) {
110 cerr <<
"Error getting the application lock: " << exc.what() << endl;
113 cerr <<
"Unknown error getting the application lock "
114 "for the database" << endl;
119 cout <<
"Got" << endl;
126 cout <<
"Releasing the application lock..." << endl;
131 query.SetParameter(
"@Resource",
"GarbageCollectorLock");
132 query.SetParameter(
"@LockOwner",
"Session");
135 if (
query.GetStatus() != 0)
137 "Error releasing the application lock");
140 cerr << ex.
what() << endl;
144 cerr <<
"Exception while releasing the application lock "
145 "for the database: " << ex.
what() << endl;
147 }
catch (
const std::exception & ex) {
149 cerr <<
"Exception while releasing the application lock "
150 "for the database: " << ex.
what() << endl;
153 string msg =
"Unknown error of releasing the application lock "
161 cout <<
"Released" << endl;
168 cout <<
"Reading the NetStorage meta info "
169 "database connection parameters..." << endl;
174 "database",
"password",
178 cout <<
"Read" << endl;
194 cout <<
"Creating CDatabase (uri: " << uri <<
")..." << endl;
197 cout <<
"Created" << endl;
204 vector<string> candidates;
205 string stmt =
"SELECT object_loc FROM Objects "
206 "WHERE tm_expiration IS NOT NULL AND "
207 "tm_expiration < GETDATE()";
210 cout <<
"Retrieving the expired objects from the NetStorage meta info "
211 "database..." << endl;
218 candidates.push_back(
row[
"object_loc"].AsString());
221 cerr <<
"Error retrieving the expired objects from the NetStorage meta "
222 "info database" << endl;
227 cout <<
"Retrieved " << candidates.size()
228 <<
" expired object(s)" << endl;
236 string stmt =
"SELECT version FROM Versions "
237 "WHERE name = 'db_structure'";
241 cout <<
"Retrieving the version of the NetStorage meta info "
242 "database structure..." << endl;
250 string msg =
"Too many NetStorage meta info "
251 "database structure versions";
256 db_ver =
row[
"version"].AsInt4();
261 cerr <<
"Error retrieving the version of the NetStorage meta info "
262 "database structure..." << endl;
267 string msg =
"Cannot find the version of the NetStorage meta info "
268 "database structure";
274 cout <<
"Retrieved: " << db_ver << endl;
281 const string & hit_id)
287 cout <<
"Removing attributes of object " << locator << endl;
289 string stmt =
"DELETE FROM AttrValues WHERE object_id IN ("
290 "SELECT object_id FROM Objects WHERE object_loc='" +
299 ctx->SetHitID(hit_id);
301 .Print(
"action",
"meta_attributes_remove")
302 .Print(
"locator", locator);
307 ctx->SetRequestStatus(200);
314 ctx->SetRequestStatus(500);
319 cerr <<
"Exception while removing attributes of object "
322 }
catch (
const std::exception & ex ) {
325 ctx->SetRequestStatus(500);
330 cerr <<
"std::exception while removing attributes of object "
336 ctx->SetRequestStatus(500);
341 cerr <<
"Unknown exception while removing attributes of object "
348 cout <<
"Removing the object record for " << locator << endl;
350 stmt =
"DELETE FROM Objects WHERE object_loc='" + locator +
"'";
357 ctx->SetHitID(hit_id);
359 .Print(
"action",
"meta_object_remove")
360 .Print(
"locator", locator);
365 ctx->SetRequestStatus(200);
372 ctx->SetRequestStatus(500);
377 cerr <<
"Exception while removing the object record for "
380 }
catch (
const std::exception & ex ) {
383 ctx->SetRequestStatus(500);
388 cerr <<
"std::exception while removing the object record for "
394 ctx->SetRequestStatus(500);
399 cerr <<
"Unknown exception while removing the object record for "
Database connection object.
void Close(void)
Close database object.
void Connect(void)
Explicitly (re)connect to the database server.
CQuery NewQuery(void)
Get new CQuery object for this database.
SDbAccessInfo m_DbAccessInfo
CNetStorageGCDatabase(const CNcbiRegistry ®, bool verbose, unsigned int timeout)
void x_CreateDatabase(const CNcbiRegistry ®)
void RemoveObject(const string &locator, bool dryrun, const string &hit_id)
void x_ReadDbAccessInfo(const CNcbiRegistry ®)
void ReleaseAppLock(void)
vector< string > GetGCCandidates(void)
~CNetStorageGCDatabase(void)
int GetDBStructureVersion(void)
Object used to execute queries and stored procedures on the database server and retrieve result sets.
Convenience class to initialize database connection parameters from URL-like strings and/or applicati...
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
void PrintRequestStop(void)
Print request stop message (for request-driven applications)
CDiagContext & GetDiagContext(void)
Get diag context instance.
static void SetRequestContext(CRequestContext *ctx)
Shortcut to CDiagContextThreadData::GetThreadData().SetRequestContext()
void PrintRequestStart(const string &message)
Print request start message (for request-driven applications)
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
string GetEncryptedString(const string §ion, const string &name, TFlags flags=0, const string &password=kEmptyStr) const
Get a value that was (potentially) stored encrypted.
virtual string GetString(const string §ion, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
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.
Defines NCBI C++ diagnostic APIs, classes, and macros.
const string k_UnknownException
Defines CRequestContext class for NCBI C++ diagnostic API.
Defines NCBI C++ secure resources API.
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
#define row(bind, expected)