50 : m_Server(server), m_Db(
NULL), m_Connected(
false),
51 m_RestoreConnectionThread(
NULL),
87 }
catch (
const exception & ex) {
90 ERR_POST(
"Exception while connecting to the database: " <<
95 ERR_POST(
"Unknown exception while connecting to the database");
121 double new_timeout = reg.
GetDouble(
"database",
122 "execute_sp_timeout",
125 if (current_timeout == new_timeout)
133 diff.
SetByKey(
"execute_sp_timeout", values);
144 const string proc_name =
"CreateClient";
163 client_id =
query.GetParameter(
"@client_id").AsInt8();
171 }
catch (
const std::exception & ex) {
192 const string proc_name =
"CreateUser";
212 user_id =
query.GetParameter(
"@user_id").AsInt8();
220 }
catch (
const std::exception & ex) {
240 const string & object_key,
241 const string & object_loc,
Int8 size,
244 bool & size_was_null)
248 const string proc_name =
"CreateObjectWithClientID_v2";
249 const string proc_name_for_perf_log =
"CreateObjectWithClientID";
262 query.SetParameter(
"@object_key", object_key);
263 query.SetParameter(
"@object_create_tm",
265 query.SetParameter(
"@object_loc", object_loc);
266 query.SetParameter(
"@object_size",
size);
267 query.SetParameter(
"@client_id", client_id);
268 query.SetParameter(
"@user_id", user_id);
274 query.SetParameter(
"@object_expiration",
286 size_was_null = (
query.
287 GetParameter(
"@size_was_null").
291 }
catch (
const std::exception & ex) {
311 const string & object_key,
312 const string & object_loc,
Int8 size,
317 bool & size_was_null)
328 exp_record_found, exp_record_not_found);
330 const string proc_name =
"UpdateObjectOnWrite";
340 query.SetParameter(
"@object_key", object_key);
341 query.SetParameter(
"@object_loc", object_loc);
342 query.SetParameter(
"@object_size",
size);
343 query.SetParameter(
"@client_id", client_id);
344 query.SetParameter(
"@user_id", user_id);
345 query.SetParameter(
"@current_time", current_time);
349 query.SetNullParameter(
"@object_exp_if_found",
352 query.SetParameter(
"@object_exp_if_found",
355 query.SetNullParameter(
"@object_exp_if_not_found",
358 query.SetParameter(
"@object_exp_if_not_found",
370 size_was_null = (
query.
371 GetParameter(
"@size_was_null").
375 }
catch (
const std::exception & ex) {
395 const string & object_key,
410 exp_record_found, exp_record_not_found);
412 const string proc_name =
"UpdateUserKeyObjectOnWrite";
422 query.SetParameter(
"@object_key", object_key);
423 query.SetParameter(
"@object_loc", object_loc);
424 query.SetParameter(
"@object_size",
size);
425 query.SetParameter(
"@client_id", client_id);
426 query.SetParameter(
"@current_time", current_time);
429 query.SetNullParameter(
"@object_exp_if_found",
432 query.SetParameter(
"@object_exp_if_found",
435 query.SetNullParameter(
"@object_exp_if_not_found",
438 query.SetParameter(
"@object_exp_if_not_found",
449 }
catch (
const std::exception & ex) {
469 const string & object_key,
470 const string & object_loc,
475 bool & size_was_null)
486 exp_record_found, exp_record_not_found);
488 const string proc_name =
"UpdateObjectOnRead";
491 size_was_null =
true;
500 query.SetParameter(
"@object_key", object_key);
501 query.SetParameter(
"@object_loc", object_loc);
502 query.SetParameter(
"@object_size",
size);
503 query.SetParameter(
"@client_id", client_id);
504 query.SetParameter(
"@current_time", current_time);
508 query.SetNullParameter(
"@object_exp_if_found",
511 query.SetParameter(
"@object_exp_if_found",
514 query.SetNullParameter(
"@object_exp_if_not_found",
517 query.SetParameter(
"@object_exp_if_not_found",
529 size_was_null = (
query.
530 GetParameter(
"@size_was_null").
534 }
catch (
const std::exception & ex) {
554 const string & object_key,
555 const string & object_loc,
Int8 client_id,
569 exp_record_found, exp_record_not_found);
571 const string proc_name =
"UpdateObjectOnRelocate";
581 query.SetParameter(
"@object_key", object_key);
582 query.SetParameter(
"@object_loc", object_loc);
583 query.SetParameter(
"@client_id", client_id);
584 query.SetParameter(
"@current_time", current_time);
587 query.SetNullParameter(
"@object_exp_if_found",
590 query.SetParameter(
"@object_exp_if_found",
593 query.SetNullParameter(
"@object_exp_if_not_found",
596 query.SetParameter(
"@object_exp_if_not_found",
607 }
catch (
const std::exception & ex) {
627 const string & object_key,
641 exp_record_found, exp_record_not_found);
643 const string proc_name =
"SetObjectExpiration";
653 query.SetParameter(
"@object_key", object_key);
658 query.SetParameter(
"@expiration", exp_record_found.
m_Value);
675 }
catch (
const std::exception & ex) {
697 const string proc_name =
"UpdateUserIDForObject";
706 query.SetParameter(
"@object_key", object_key);
707 query.SetParameter(
"@u_id", user_id);
717 }
catch (
const std::exception & ex) {
738 const string proc_name =
"RemoveObject";
748 query.SetParameter(
"@object_key", object_key);
758 }
catch (
const std::exception & ex) {
779 bool create_if_not_found,
780 const string & object_loc,
784 const string proc_name =
"SetObjectExpiration";
794 query.SetParameter(
"@object_key", object_key);
802 query.SetParameter(
"@ttl",
805 query.SetParameter(
"@create_if_not_found", create_if_not_found,
807 query.SetParameter(
"@object_loc", object_loc);
808 query.SetParameter(
"@client_id", client_id);
820 object_size.
m_Value =
query.GetParameter(
"@object_size").
828 }
catch (
const std::exception & ex) {
848 const string & object_loc,
849 const string & attr_name,
850 const string & attr_value,
852 bool create_if_not_found,
855 const string proc_name =
"AddAttribute";
865 query.SetParameter(
"@object_key", object_key);
866 query.SetParameter(
"@attr_name", attr_name);
868 query.SetParameter(
"@client_id", client_id);
869 query.SetParameter(
"@create_if_not_found", create_if_not_found,
871 query.SetParameter(
"@object_loc", object_loc);
876 query.SetParameter(
"@object_expiration",
887 }
catch (
const std::exception & ex) {
907 vector<string> & attr_names)
909 const string proc_name =
"GetAttributeNames";
919 query.SetParameter(
"@object_key", object_key);
926 attr_names.push_back(qit[
"name"].AsString());
935 }
catch (
const std::exception & ex) {
955 const string & attr_name,
959 const string proc_name =
"GetAttribute";
969 query.SetParameter(
"@object_key", object_key);
970 query.SetParameter(
"@attr_name", attr_name);
971 query.SetParameter(
"@need_update", need_update,
980 value =
query.GetParameter(
"@attr_value").AsString();
987 }
catch (
const std::exception & ex) {
1007 const string & attr_name)
1009 const string proc_name =
"DelAttribute";
1019 query.SetParameter(
"@object_key", object_key);
1020 query.SetParameter(
"@attr_name", attr_name);
1030 }
catch (
const std::exception & ex) {
1050 const string & object_key,
1065 const string proc_name =
"GetObjectFixedAttributes";
1075 query.SetParameter(
"@object_key", object_key);
1097 expiration.
m_Value =
query.GetParameter(
"@expiration").
1099 creation.
m_IsNull =
query.GetParameter(
"@creation").IsNull();
1103 obj_read.
m_IsNull =
query.GetParameter(
"@obj_read").IsNull();
1107 obj_write.
m_IsNull =
query.GetParameter(
"@obj_write").IsNull();
1111 attr_read.
m_IsNull =
query.GetParameter(
"@attr_read").IsNull();
1118 attr_write.
m_Value =
query.GetParameter(
"@attr_write").
1120 read_count.
m_IsNull =
query.GetParameter(
"@read_cnt").IsNull();
1127 write_count.
m_Value =
query.GetParameter(
"@write_cnt").
1132 client_name.
m_Value =
query.GetParameter(
"@client_name").
1134 user_namespace.
m_IsNull =
query.GetParameter(
"@user_namespace").
1138 GetParameter(
"@user_namespace").
1156 }
catch (
const std::exception & ex) {
1176 const string & object_key,
1180 const string proc_name =
"GetObjectExpiration";
1190 query.SetParameter(
"@object_key", object_key);
1202 expiration.
m_Value =
query.GetParameter(
"@expiration").
1204 individual_object_ttl.
m_IsNull =
query.GetParameter(
"@ttl").
1206 if (!individual_object_ttl.
m_IsNull)
1207 individual_object_ttl.
m_Value =
query.GetParameter(
"@ttl").
1214 }
catch (
const std::exception & ex) {
1236 const string proc_name =
"sp_spaceused";
1251 for (
size_t k = 1; k <= qit.GetTotalColumns(); ++k) {
1252 string columnName = qit.GetColumnName(k);
1253 result[columnName] = qit[k].AsString();
1262 }
catch (
const std::exception & ex) {
1284 const string proc_name =
"GetStatInfo";
1296 for (
size_t k = 1; k <= qit.GetTotalColumns(); ++k) {
1297 string columnName = qit.GetColumnName(k);
1298 result[columnName] = qit[k].AsString();
1307 }
catch (
const std::exception & ex) {
1329 vector<string> & locators)
1331 const string proc_name =
"GetClientObjects";
1341 query.SetParameter(
"@client_name", client_name);
1353 locators.push_back(qit[
"object_loc"].AsString());
1356 if (!
query.GetParameter(
"@total_object_cnt").IsNull())
1357 total =
query.GetParameter(
"@total_object_cnt").AsInt8();
1365 }
catch (
const std::exception & ex) {
1385 const string & user_name_space,
1388 vector<string> & locators)
1390 const string proc_name =
"GetUserObjects";
1400 query.SetParameter(
"@user_name", user_name);
1401 query.SetParameter(
"@user_name_space", user_name_space);
1413 locators.push_back(qit[
"object_loc"].AsString());
1416 if (!
query.GetParameter(
"@total_object_cnt").IsNull())
1417 total =
query.GetParameter(
"@total_object_cnt").AsInt8();
1425 }
catch (
const std::exception & ex) {
1446 const string proc_name =
"GetClients";
1462 names.push_back(qit[
"name"].AsString());
1471 }
catch (
const std::exception & ex) {
1492 const string proc_name =
"GetUsers";
1508 users.push_back(make_pair(qit[
"name"].AsString(),
1509 qit[
"name_space"].AsString()));
1518 }
catch (
const std::exception & ex) {
1539 const string proc_name =
"DoesObjectExist";
1549 query.SetParameter(
"@object_key", object_key);
1559 }
catch (
const std::exception & ex) {
1579 const string & object_key,
1583 const string proc_name =
"GetObjectSizeAndLocator";
1592 query.SetParameter(
"@object_key", object_key);
1602 GetParameter(
"@object_size").IsNull();
1605 GetParameter(
"@object_size").AsInt8();
1607 GetParameter(
"@object_locator").IsNull();
1610 GetParameter(
"@object_locator").AsString();
1617 }
catch (
const std::exception & ex) {
1639 const string proc_name =
"GetObjectSize";
1649 query.SetParameter(
"@object_key", object_key);
1660 object_size.
m_Value =
query.GetParameter(
"@object_size").
1668 }
catch (
const std::exception & ex) {
1690 const string proc_name =
"UpdateObjectSizeIfNULL";
1700 query.SetParameter(
"@object_key", object_key);
1711 object_size.
m_Value =
query.GetParameter(
"@object_size").
1719 }
catch (
const std::exception & ex) {
1748 "There is no connection to metadata information database");
1787 const string & procedure)
1789 int status =
query.GetStatus();
1792 "Error executing " + procedure +
" stored "
1794 "). See MS SQL log for details.");
1809 "execute_sp_timeout",
1819 if (is_initialization) {
1851 const CTime & current_time,
1864 exp_record_not_found.
m_IsNull =
true;
1876 exp_record_not_found.
m_IsNull =
true;
1878 exp_record_not_found.
m_IsNull =
false;
1890 exp_record_not_found.
m_IsNull =
true;
1892 exp_record_not_found.
m_IsNull =
false;
1901 exp_record_not_found.
m_IsNull =
true;
1903 exp_record_not_found.
m_IsNull =
false;
1904 if (ttl.
m_Value > prolong_val)
1907 exp_record_not_found.
m_Value = current_time + prolong_val;
1911 if (object_expiration.
m_Value > current_time + prolong_val)
1914 exp_record_found.
m_Value = current_time + prolong_val;
1921 exp_record_not_found.
m_IsNull =
true;
1923 exp_record_not_found.
m_IsNull =
false;
1924 if (ttl.
m_Value > prolong_val)
1927 exp_record_not_found.
m_Value = current_time + prolong_val;
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.
CDatabase Clone(void)
Clone database object.
bool IsConnected(EConnectionCheckMethod check_method=eNoCheck)
Check if database object was already connected to database server.
static CJsonNode NewDoubleNode(double value)
Create a new JSON double node.
void SetByKey(const string &key, CJsonNode::TInstance value)
For a JSON object node, insert a new element or update an existing element.
static CJsonNode NewObjectNode()
Create a new JSON object node.
static CJsonNode NewNullNode()
Create a new JSON null node.
map< string, string > ExecSP_GetGeneralDBInfo(void)
int ExecSP_GetAttribute(const string &object_key, const string &attr_name, bool need_update, string &value)
int ExecSP_GetObjectExpiration(const string &object_key, TNSTDBValue< CTime > &expiration, TNSTDBValue< Int8 > &individual_object_ttl)
friend class CNSTDBConnectionThread
bool x_ReadDbAccessInfo(bool is_initialization)
int x_CheckStatus(CQuery &query, const string &procedure)
int ExecSP_GetClientObjects(const string &client_name, TNSTDBValue< Int8 > limit, Int8 &total, vector< string > &locators)
int ExecSP_UpdateObjectOnRead(const string &object_key, const string &object_loc, Int8 size, Int8 client_id, const TNSTDBValue< CTimeSpan > &ttl, const TNSTDBValue< CTimeSpan > &prolong_on_read, const TNSTDBValue< CTime > &object_expiration, bool &size_was_null)
int ExecSP_SetExpiration(const string &object_key, const TNSTDBValue< CTimeSpan > &ttl, bool create_if_not_found, const string &object_loc, Int8 client_id, TNSTDBValue< Int8 > &object_size)
CRef< CNSTDBConnectionThread > m_RestoreConnectionThread
int ExecSP_GetUsers(vector< pair< string, string > > &users)
int ExecSP_UpdateUserIDForObject(const string &object_key, Int8 user_id)
int ExecSP_UpdateUserKeyObjectOnWrite(const string &object_key, const string &object_loc, Int8 size, Int8 client_id, const TNSTDBValue< CTimeSpan > &ttl, const TNSTDBValue< CTimeSpan > &prolong_on_write, const TNSTDBValue< CTime > &object_expiration)
int ExecSP_GetClients(vector< string > &names)
int ExecSP_UpdateObjectOnRelocate(const string &object_key, const string &object_loc, Int8 client_id, const TNSTDBValue< CTimeSpan > &ttl, const TNSTDBValue< CTimeSpan > &prolong_on_relocate, const TNSTDBValue< CTime > &object_expiration)
int ExecSP_CreateClient(const string &client, Int8 &client_id)
map< string, string > ExecSP_GetStatDBInfo(void)
int ExecSP_GetUserObjects(const string &user_name, const string &user_name_space, TNSTDBValue< Int8 > limit, Int8 &total, vector< string > &locators)
int ExecSP_UpdateObjectOnWrite(const string &object_key, const string &object_loc, Int8 size, Int8 client_id, Int8 user_id, const TNSTDBValue< CTimeSpan > &ttl, const TNSTDBValue< CTimeSpan > &prolong_on_write, const TNSTDBValue< CTime > &object_expiration, bool &size_was_null)
int ExecSP_AddAttribute(const string &object_key, const string &object_loc, const string &attr_name, const string &attr_value, Int8 client_id, bool create_if_not_found, const TNSTDBValue< CTimeSpan > &ttl)
void x_CreateDatabase(bool is_initialization)
int UpdateExpirationIfExists(const string &object_key, const TNSTDBValue< CTimeSpan > &ttl, const TNSTDBValue< CTimeSpan > &prolong_on_read, const TNSTDBValue< CTime > &object_expiration)
int ExecSP_CreateObjectWithClientID(const string &object_key, const string &object_loc, Int8 size, Int8 client_id, Int8 user_id, const TNSTDBValue< CTimeSpan > ttl, bool &size_was_null)
void InitialConnect(void)
CNetStorageServer * m_Server
int ExecSP_DoesObjectExist(const string &object_key)
int ExecSP_GetObjectFixedAttributes(const string &object_key, TNSTDBValue< CTime > &expiration, TNSTDBValue< CTime > &creation, TNSTDBValue< CTime > &obj_read, TNSTDBValue< CTime > &obj_write, TNSTDBValue< CTime > &attr_read, TNSTDBValue< CTime > &attr_write, TNSTDBValue< Int8 > &read_count, TNSTDBValue< Int8 > &write_count, TNSTDBValue< string > &client_name, TNSTDBValue< string > &user_namespace, TNSTDBValue< string > &user_name, TNSTDBValue< Int8 > &obj_ttl)
SDbAccessInfo m_DbAccessInfo
int ExecSP_GetObjectSize(const string &object_key, TNSTDBValue< Int8 > &object_size)
CNSTDatabase(CNetStorageServer *server)
CFastMutex m_SPTimeoutMutex
CTimeout GetExecuteSPTimeout(void)
int ExecSP_GetObjectSizeAndLocator(const string &object_key, TNSTDBValue< Int8 > &object_size, TNSTDBValue< string > &object_locator)
int ExecSP_RemoveObject(const string &object_key)
int ExecSP_GetAttributeNames(const string &object_key, vector< string > &attr_names)
int ExecSP_DelAttribute(const string &object_key, const string &attr_name)
void x_PreCheckConnection(void)
CJsonNode SetParameters(const IRegistry ®)
void x_PostCheckConnection(void)
int ExecSP_UpdateObjectSizeIfNULL(const string &object_key, TNSTDBValue< Int8 > &object_size)
void x_CalculateExpiration(const CTime ¤t_time, const TNSTDBValue< CTimeSpan > &ttl, const TNSTDBValue< CTimeSpan > &prolong, const TNSTDBValue< CTime > &object_expiration, TNSTDBValue< CTime > &exp_record_found, TNSTDBValue< CTime > &exp_record_not_found)
int ExecSP_CreateUser(const CNSTUserID &user, Int8 &user_id)
static CNSTPreciseTime Current(void)
string GetName(void) const
string GetNamespace(void) const
static CNcbiApplication * Instance(void)
Singleton method.
CTime GetCreationTime() const
void RegisterAlert(EAlertType alert_type, const string &messge)
CCompoundIDPool GetCompoundIDPool(void) const
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...
CTimeout – Timeout interval.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const struct name_t names[]
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
@ e500_InternalServerError
void Critical(CExceptionArgs_Base &args)
#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).
void Reset(void)
Reset reference object.
int64_t Int8
8-byte (64-bit) signed integer
virtual double GetDouble(const string §ion, const string &name, double default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get double value of specified parameter name.
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.
@ eReturn
Return default value.
@ eDecryptionFailed
Value looked encrypted, but decryption failed.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
TErrCode GetErrCode(void) const
Get error code.
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.
bool Run(TRunMode flags=fRunDefault)
Run the thread.
void Join(void **exit_data=0)
Wait for the thread termination.
bool IsEmpty(void) const
Return TRUE is an object keep zero time span.
double GetAsDouble(void) const
Return time span as number of seconds.
double GetAsDouble(void) const
Get as number of seconds (fractional value).
void Set(EType type)
Set special value.
@ eCurrent
Use current time. See also CCurrentTime.
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
void g_DoPerfLogging(const CQueue &queue, const CJob &job, int status)
const Int8 k_UndefinedClientID
const double default_execute_sp_timeout
const Int8 k_UndefinedUserID
Defines NCBI C++ secure resources API.
@ eSDB_String
Like Transact-SQL VARCHAR(N)
@ eSDB_DateTime
Like Transact-SQL DATETIME.
@ eSDB_Int4
Like Transact-SQL INT (signed 32-bit integer)
@ eSDB_Binary
Like Transact-SQL VARBINARY(N)
@ eSDB_Int8
Like Transact-SQL BIGINT (signed 64-bit integer)
static CNamedPipeClient * client