56 m_SessionID(
"s" + x_GenerateGUID()),
58 m_DataPath(
"./data." +
NStr::NumericToString(
m_Port)),
60 m_AnybodyCanReconfigure(
false),
61 m_NeedDecryptCacheReset(
false),
62 m_LastDecryptCacheReset(0.0)
106 vector<string> added;
107 vector<string> deleted;
113 set_difference(new_admins.
begin(), new_admins.
end(),
115 inserter(added, added.begin()));
117 new_admins.
begin(), new_admins.
end(),
118 inserter(deleted, deleted.begin()));
154 diff.
SetByKey(
"log_timing_nst_api", values);
165 diff.
SetByKey(
"log_timing_client_socket", values);
176 diff.
SetByKey(
"network_timeout", values);
198 diff.
SetByKey(
"max_connections", values);
204 if (!added.empty() || !deleted.empty())
252 const string & message)
269 Int8 current_time = time(0);
277 vector<string> & config_warnings)
287 vector<string> added;
288 vector<string> deleted;
289 vector<string> common;
290 vector<string> changed;
293 string key = it.GetKey();
296 common.push_back(
key);
298 deleted.push_back(
key);
302 string key = it.GetKey();
305 added.push_back(
key);
310 for (vector<string>::const_iterator k = common.begin();
311 k != common.end(); ++k) {
315 if (old_params != new_params)
316 changed.push_back(*k);
320 if (added.empty() && deleted.empty() && changed.empty())
326 if (!added.empty()) {
328 for (vector<string>::const_iterator k = added.begin();
329 k != added.end(); ++k)
331 diff.
SetByKey(
"AddedServices", added_services);
334 if (!deleted.empty()) {
336 for (vector<string>::const_iterator k = deleted.begin();
337 k != deleted.end(); ++k)
339 diff.
SetByKey(
"DeletedServices", deleted_services);
342 if (!changed.empty()) {
344 for (vector<string>::const_iterator k = changed.begin();
345 k != changed.end(); ++k)
347 diff.
SetByKey(
"ChangedServices", changed_services);
367 vector<string> admins;
389 const string & message)
427 const string & service,
432 service, individual_obj_ttl, prolong_on_read);
438 const string & service,
443 service, individual_obj_ttl, prolong_on_write);
491 const vector<string> & deleted)
const
495 if (!added.empty()) {
497 for (vector<string>::const_iterator k = added.begin();
498 k != added.end(); ++k)
503 if (!deleted.empty()) {
505 for (vector<string>::const_iterator k = deleted.begin();
506 k != deleted.end(); ++k)
535 "The server did not stop gracefully last time");
539 if (!
error.empty()) {
546 if (!
error.empty()) {
558 bool dir_created =
true;
561 " does not exist. It is OK if it is a first time "
562 "server start. Otherwise someone may have removed the "
563 "directory and this may mask the previous instance "
572 msg =
"Error creating the data path directory " +
m_DataPath;
577 }
catch (
const exception & ex) {
578 msg =
"Error while creating the data path directory (" +
584 msg =
"Unknown error while creating the data path directory (" +
595 if (!
error.empty()) {
607 if (!crash_file.
Exists()) {
614 }
catch (
const exception & ex) {
615 return "Error while creating the start-after-crash detection "
618 return "Unknown error while creating the start-after-crash "
631 }
catch (
const exception & ex) {
632 return "Error while removing the start-after-crash detection "
634 "\nWhen the server restarts with the same data path it will "
635 "set the 'StartAfterCrash' alert";
637 return "Unknown error while removing the start-after-crash detection "
639 "restarts with the same data path it will set the "
640 "'StartAfterCrash' alert";
Class for support low level input/output for files.
Iterator for JSON arrays and objects.
static CJsonNode NewArrayNode()
Create a new JSON array node.
bool HasKey(const string &key) const
Check if an object node has an element accessible by the specified key.
string Repr(TReprFlags flags=0) const
Return a string representation of this node.
SJsonIteratorImpl * Iterate(EIterationMode mode=eNatural) const
For a container node (that is, either an array or an object), begin iteration over its elements.
void AppendString(const string &value)
For an array node, add a string node at the end of the array.
static CJsonNode NewBooleanNode(bool value)
Create a new JSON boolean 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 NewIntegerNode(Int8 value)
Create a new JSON integer node.
static CJsonNode NewStringNode(const string &value)
Create a new JSON string node.
static CJsonNode NewObjectNode()
Create a new JSON object node.
CJsonNode GetByKey(const string &key) const
For a JSON object node, return the value associated with the specified key.
static CJsonNode NewNullNode()
Create a new JSON null node.
enum EAlertAckResult Acknowledge(const string &alert_id, const string &user)
void Register(enum EAlertType alert_type, const string &message)
CJsonNode Serialize(void) const
static CNSTPreciseTime Current(void)
bool GetTTL(const string &service, TNSTDBValue< CTimeSpan > &ttl) const
bool GetProlongOnRead(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_read) const
CJsonNode Serialize(void) const
bool GetServiceProperties(const string &service, CNSTServiceProperties &props) const
bool GetProlongOnWrite(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_write) const
CJsonNode ReadConfiguration(const IRegistry ®)
EServiceMetadataPresence IsKnown(const string &service) const
static void Reload(void)
Re-read key file locations and domain paths, reload encryption keys.
CNSTServiceRegistry m_MetadataServiceRegistry
CJsonNode SetParameters(const SNetStorageServerParameters &new_params, bool reconfigure)
CJsonNode GetBackendConfDiff(const CJsonNode &conf) const
unsigned int m_NetworkTimeout
unique_ptr< CNSTDatabase > m_Db
CNSTDatabase & GetDb(void)
CJsonNode x_diffInJson(const vector< string > &added, const vector< string > &deleted) const
void ResetDecryptCacheIfNeed(void)
string x_GetCrashFlagFileName(void) const
virtual ~CNetStorageServer()
void RunServiceThread(void)
enum EAlertAckResult AcknowledgeAlert(const string &id, const string &user)
CRef< CNetStorageServiceThread > m_ServiceThread
void RegisterNetStorageAPIDecryptError(const string &message)
bool x_DoesCrashFlagFileExist(void) const
void AddDefaultListener(IServer_ConnectionFactory *factory)
bool m_NeedDecryptCacheReset
CJsonNode SerializeAlerts(void) const
void ReportNetStorageAPIDecryptSuccess(void)
void RegisterAlert(EAlertType alert_type, const string &messge)
virtual void Exit()
Cleanup the server.
bool IsAdminClientName(const string &name) const
void StopServiceThread(void)
static CNetStorageServer * GetInstance(void)
string CreateCrashFlagFile(void)
set< string > m_AdminClientNames
virtual bool ShutdownRequested(void)
Runs synchronously between iterations.
CFastMutex m_AdminClientNamesLock
void CheckStartAfterCrash(void)
set< string > x_GetAdminClientNames(const string &client_names)
CNSTPreciseTime m_LastDecryptCacheReset
bool m_LogTimingClientSocket
EServiceMetadataPresence InMetadataServices(const string &service) const
bool GetServiceProperties(const string &service, CNSTServiceProperties &service_props) const
bool GetServiceTTL(const string &service, TNSTDBValue< CTimeSpan > &ttl) const
CJsonNode m_BackendConfiguration
static CNetStorageServer * sm_netstorage_server
CJsonNode ReadMetadataConfiguration(const IRegistry ®)
string x_GenerateGUID(void) const
string RemoveCrashFlagFile(void)
bool GetServiceProlongOnRead(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_read) const
CJsonNode SerializeMetadataInfo(void) const
void SetShutdownFlag(int signum=0)
void UpdateBackendConfiguration(const IRegistry ®, vector< string > &config_warnings)
bool GetServiceProlongOnWrite(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_write) const
void RequestStop()
Schedule thread Stop.
IServer_ConnectionFactory::
const_iterator begin() const
const_iterator find(const key_type &key) const
const_iterator end() const
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
bool CreatePath(TCreateFlags flags=fCreate_Default) const
Create the directory path recursively possibly more than one at a time.
virtual bool Remove(TRemoveFlags flags=eRecursive) const
Remove a directory entry.
static string MakePath(const string &dir=kEmptyStr, const string &base=kEmptyStr, const string &ext=kEmptyStr)
Assemble a path from basic components.
virtual bool Exists(void) const
Check existence of file.
@ eReadWrite
File can be read and written.
@ eCreate
Create a new file, or truncate an existing one.
void Reset(void)
Reset reference object.
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
int64_t Int8
8-byte (64-bit) signed integer
static TPid GetPid(void)
Get process identifier (pid) for the current process.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
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.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
void GetParameters(SServer_Parameters *params)
void AddListener(IServer_ConnectionFactory *factory, unsigned short port)
Register a listener.
unsigned short m_Port
TCP port to listen on.
void SetParameters(const SServer_Parameters &new_params)
unsigned int max_connections
Maximum # of open connections.
bool Run(TRunMode flags=fRunDefault)
Run the thread.
void Join(void **exit_data=0)
Wait for the thread termination.
const struct ncbi::grid::netcache::search::fields::KEY key
@ eDecryptInNetStorageAPI
@ eCrashSignalFileCreation
CJsonNode NSTGetBackendConfiguration(const IRegistry ®, CNetStorageServer *server, vector< string > &warnings)
const bool default_log_timing_nst_api
const bool default_log_timing_client_socket
const string kCrashFlagFileName("CRASH_FLAG")
Defines NCBI C++ secure resources API.
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
bool log_timing_client_socket
unsigned int network_timeout
string admin_client_names