147 string log_pfx(
"Bad configuration: ");
251 bool isReconf = prevMirrorCfg !=
NULL;
252 vector<Uint2> self_slots;
256 bool found_self =
false;
257 for (
int srv_idx = 0; ; ++srv_idx) {
260 if (reg_value.empty())
263 string srv_name = reg_value;
264 list<CTempString> srv_fields;
265 ncbi_NStr_Split(reg_value,
":", srv_fields);
266 if (srv_fields.size() != 3) {
267 err_message = srv_name +
": Invalid peer server specification";
270 list<CTempString>::const_iterator it_fields = srv_fields.begin();
271 string grp_name = *it_fields;
273 string host_str = *it_fields;
276 string port_str = *it_fields;
278 if (host == 0 || port == 0) {
279 err_message = srv_name +
": Host not found";
283 Uint8 trustlevel = 0;
286 if (!reg_value.empty()) {
291 string peer_str = host_str +
":" + port_str;
294 err_message = srv_name +
": Host described twice";
301 err_message = srv_name +
": Changes in self description prohibited (group or name)";
311 err_message = srv_name + +
": Described twice";
314 mirrorCfg->
s_Peers[srv_id] = peer_str;
321 if (reg_value.empty()) {
322 err_message = srv_name +
": No slots for server";
327 ncbi_NStr_Split(reg_value,
",", values);
328 ITERATE(list<string>, it, values) {
332 err_message = srv_name +
": Bad slot number: " +
string(*it);
336 if (find(srvs.begin(), srvs.end(), srv_id) != srvs.end()) {
337 err_message = srv_name +
": Slot listed twice: " +
string(*it);
341 vector<Uint2>& slots = isReconf ? self_slots :
s_SelfSlots;
342 if (find(slots.begin(), slots.end(), slot) != slots.end()) {
343 err_message = srv_name +
": Slot listed twice: " +
string(*it);
346 slots.push_back(slot);
348 srvs.push_back(srv_id);
372 if (isReconf && !self_slots.empty()) {
374 err_message =
s_SelfName +
": Changes in self description prohibited (slots)";
380 Uint8 srv_id = it_peer->first;
381 vector<Uint2>& common_slots = mirrorCfg->
s_CommonSlots[srv_id];
383 Uint2 slot = it_slot->first;
387 if (find(srvs.begin(), srvs.end(), srv_id) != srvs.end()) {
388 common_slots.push_back(it_slot->first);
422 string value_name,
value;
424 for (srv_idx = 0; ; ++srv_idx) {
435 for (srv_idx = 0; ; ++srv_idx) {
449 for(pn = new_peers.
begin(); pn != new_peers.
end(); ++pn) {
450 po = old_peers.
find(pn->first);
451 if (po != old_peers.
end()) {
452 if (pn->second.
size() != po->second.
size() ||
453 !std::equal(pn->second.
begin(), pn->second.
end(), po->second.
begin())) {
454 err_message = pn->first +
": Slot lists differ in old and new configurations";
459 for(po = old_peers.
begin(); po != old_peers.
end(); ++po) {
460 pn = new_peers.
find(po->first);
461 if (pn != new_peers.
end()) {
462 if (po->second.
size() != pn->second.
size() ||
463 !std::equal(po->second.
begin(), po->second.
end(), pn->second.
begin())) {
464 err_message = po->first +
": Slot lists differ in old and new configurations";
472 for(pn = new_peers.
begin(); pn != new_peers.
end(); ++pn) {
473 po = old_peers.
find(pn->first);
474 if (po != old_peers.
end()) {
478 for(po = old_peers.
begin(); po != old_peers.
end(); ++po) {
479 pn = new_peers.
find(po->first);
480 if (pn != new_peers.
end()) {
497 string is(
"\": "),iss(
"\": \""), eol(
",\n\""),
str(
"_str"), eos(
"\"");
525 Uint8 srv_id = p->first;
529 Uint2 slot = it_slot->first;
531 if (find(srvs.begin(), srvs.end(), srv_id) != srvs.end()) {
532 slots.push_back(slot);
536 ITERATE( vector<Uint2>, s, slots) {
537 if (s != slots.begin()) {
583 string is(
"\": "),iss(
"\": \""), eol(
",\n\""),
str(
"_str"), eos(
"\"");
602 shuffle(srvs.begin(), srvs.end(), mt);
604 for (
size_t i = 0;
i < srvs.size(); ++
i) {
606 lst.push_back(srvs[
i].srv_id);
608 for (
size_t i = 0;
i < srvs.size(); ++
i) {
610 lst.push_back(srvs[
i].srv_id);
629 const vector<Uint2>& srv_slots(
631 for(
const Uint2 s : srv_slots) {
680 if (peers.
find(srv_id) != peers.
end()) {
681 name = peers.
find(srv_id)->second;
694 name =
"unknown_server";
718 lst.push_back(it_peer->first);
734 Uint2 index = rnd_num / piece_share;
735 rnd_num -= index * piece_share;
765 unsigned key_rnd = 0;
767 #define SKIP_UNDERSCORE(key, ind) \
768 ind = key.find('_', ind + 1); \
769 if (ind == string::npos) \
772 SKIP_UNDERSCORE(
key, ind);
773 SKIP_UNDERSCORE(
key, ind);
774 SKIP_UNDERSCORE(
key, ind);
775 SKIP_UNDERSCORE(
key, ind);
776 SKIP_UNDERSCORE(
key, ind);
777 SKIP_UNDERSCORE(
key, ind);
779 ind =
key.rfind(
'_');
780 if (ind == string::npos) {
788 if (key_rnd == 0 && errno != 0) {
813 crc32.AddChars(
key.RawKey().data(),
key.RawKey().size());
815 crc32.AddChars(
key.PackedKey().data(),
key.PackedKey().size());
861 if (
key.IsICacheKey()) {
864 return (
key.KeyVersion() == 3) ?
873 if (
key.KeyVersion() == 3) {
874 Uint4 alias =
key.GetHostPortCRC32();
878 const string& host_str(
key.GetHost());
1105 cur_time, create_server, write_server, cur_time - create_time);
Uint4 GetDefaultTaskPriority(void)
Checksum and hash calculation classes.
CChecksum – Checksum calculator.
Mutex created to have minimum possible size (its size is 4 bytes) and to sleep using kernel capabilit...
void Unlock(void)
Unlock the mutex.
void Lock(void)
Lock the mutex.
const CTempString & RawKey(void) const
const CTempString & SubKey(void) const
const CTempString & Cache(void) const
void Assign(const CTempString &cache_name, const CTempString &blob_key, const CTempString &blob_subkey)
static void GenerateBlobKey(Uint2 local_port, string &key, Uint2 &slot, Uint2 &time_bucket, unsigned int ver=1)
static Uint2 GetMaxPeerBGConns(void)
static const TNCPeerList & GetPeers(void)
static bool IsThisServerKey(const string &packed_key)
static bool IsServedLocally(Uint2 slot)
static Uint2 GetMaxMirrorQueueSize(void)
static Uint8 GetPeriodicSyncInterval(void)
static bool GetSlotByNetCacheKey(const string &key, Uint2 &slot, Uint2 &time_bucket)
static Uint8 GetPeriodicSyncTailTime(void)
static Uint1 GetMaxSyncsOneServer(void)
static void GetSlotByRnd(Uint4 key_rnd, Uint2 &slot, Uint2 &time_bucket)
static void Finalize(void)
static Uint4 GetSyncPriority(void)
static const vector< Uint2 > & GetSelfSlots(void)
static Uint8 GetSmallBlobBoundary(void)
static bool ReConfig(const CNcbiRegistry &new_reg, string &err_message)
static string GetPeerNameOrEmpty(Uint8 srv_id)
static Uint2 GetMaxPeerTotalConns(void)
static string GetPeerName(Uint8 srv_id)
static size_t CountServersForSlot(Uint2 slot)
static string GetFullPeerName(Uint8 srv_id)
static const vector< Uint2 > & GetSlotsForServer(Uint8 srv_id)
static Uint4 GetMainSrvIP(const CNCBlobKey &key)
static Uint8 GetNetworkErrorTimeout(void)
static Uint2 GetCntErrorsToThrottle(void)
static Uint1 GetBlobListTimeout(void)
static void AddServerSlots(set< Uint2 > &slots, Uint8 srv_id)
static Uint8 GetPeriodicSyncTimeout(void)
static Uint4 GetMaxCleanLogBatch(void)
static Uint8 GetMainSrvId(const CNCBlobKey &key)
static Uint8 GetSelfTrustLevel(void)
static Uint2 GetMaxSlotNumber(void)
static void GetPeerServers(TServersList &lst)
static bool GetBlobUpdateHotline(void)
static Uint8 GetPeerThrottlePeriod(void)
static bool GetSlotByKey(const string &key, Uint2 &slot, Uint2 &time_bucket)
static Uint2 GetCntSlotBuckets(void)
static const string & GetSyncLogFileName(void)
static bool GetWarnBlobSizeSync(void)
static const TServersList & GetRawServersForSlot(Uint2 slot)
static void GetSlotByICacheKey(const CNCBlobKeyLight &key, Uint2 &slot, Uint2 &time_bucket)
static Uint8 GetFailedSyncRetryDelay(void)
static bool InitMirrorConfig(const CNcbiRegistry ®, string &err_message)
static const string & GetPeriodicLogFile(void)
static void PrintBlobCopyStat(Uint8 create_time, Uint8 create_server, Uint8 write_server)
static Uint4 CreateHostAlias(Uint4 ip, Uint4 port)
static Uint8 GetMaxBlobSizeSync(void)
static bool HasCommonSlots(Uint8 server)
static Uint1 GetCntActiveSyncs(void)
static Uint2 GetCntThrottlesToIpchange(void)
static bool HasPeers(void)
static const string & GetMirroringSizeFile(void)
static Uint2 GetCntTimeBuckets(void)
static const vector< Uint2 > & GetCommonSlots(Uint8 server)
static Uint8 GetSelfID(void)
static void WriteEnvInfo(CSrvSocketTask &task)
static Uint8 GetSrvIdByIP(Uint4 ip)
static Uint4 GetMaxSlotLogEvents(void)
static void GetServersForSlot(Uint2 slot, TServersList &lst)
static Uint4 GetCleanAttemptInterval(void)
static bool Initialize(Uint2 control_port)
static Uint8 GetMinForcedCleanPeriod(void)
static Uint8 GetPeriodicSyncHeadTime(void)
static Uint1 GetPeerTimeout(void)
static void WriteSetup(CSrvSocketTask &task)
static Uint4 GetCleanLogReserve(void)
static Uint4 FindIPbyName(const string &alias)
Uint8 GetRawTrustLevel(void) const
void SetHostProtocol(Uint8 ver)
static string GetPeerNameOrEmpty(Uint8 srv_id)
static CNCPeerControl * Peer(Uint8 srv_id)
static Uint4 FindIPbyAlias(Uint4 alias)
void SetTrustLevel(Uint8 trust)
static bool IsInitiallySynced(void)
Task controlling a socket.
CSrvSocketTask & WriteText(CTempString message)
Write text into socket.
CSrvSocketTask & WriteNumber(NumType num)
Write number into socket as string, i.e.
CSrvSocketTask & WriteBool(bool b)
static CSrvTime Current(void)
Exact current time with precision up to nanoseconds.
Uint8 AsUSec(void) const
Converts object's value to microseconds since epoch.
static const CNcbiRegistry & GetConfRegistry(void)
Obtains reference to registry read from application's ini-file.
static CNcbiRegistry & SetConfRegistry(void)
Used to modify original registry (to reflect RECONF modifications)
static const string & GetHostName(void)
Returns name of server this application is executing on.
static string IPToString(Uint4 ip)
Converts 4-byte encoded IP address into its string representation.
static Uint4 GetIPByHost(const string &host)
Converts server name (or IP address written as string) to encoded 4-byte IP address.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
const_iterator begin() const
const_iterator end() const
const_iterator find(const key_type &key) const
iterator_bool insert(const value_type &val)
static const char * kNCReg_NCPoolSection
static Uint2 s_MaxPeerBGConns
static string s_SyncLogFileName
static string kNCReg_NCServerTrustPrefix
static CRandom s_KeyRnd(CRandom::TValue(time(NULL)))
static Uint8 s_PeriodicSyncTimeout
static string s_PeriodicLogFile
static string s_SelfGroup
static bool s_BlobUpdateHotline
static Uint8 s_PeriodicSyncInterval
static string kNCReg_NCServerPrefix
static Uint2 s_MaxSlotNumber
static Uint4 s_MaxCleanLogBatch
static string s_MirroringSizeFile
static Uint4 s_SlotRndShare
map< Uint8, vector< Uint2 > > TSrv2SlotMap
static string s_SelfHostIP
static CMiniMutex s_KeyRndLock
static CAtomicCounter s_BlobId
static string s_CopyDelayLogFile
static Uint1 s_MaxSyncsOneServer
static SSrvMirrorInfo * s_MirrorConf
static bool s_WarnBlobSizeSync
static Uint4 s_TimeRndShare
static Uint2 s_MaxPeerTotalConns
static Uint8 s_FailedSyncRetryDelay
static Uint4 s_CleanAttemptInterval
static string kNCReg_NCServerSlotsPrefix
static Uint2 s_CntTimeBuckets
static Uint2 s_CntThrottlesToIpchange
static FILE * s_CopyDelayLog
static Uint2 s_CntSlotBuckets
static Uint1 s_BlobListTimeout
static Uint8 s_SmallBlobBoundary
static Uint2 s_CntErrorsToThrottle
map< Uint2, TSrvGroupsList > TSrvGroupsMap
static Uint1 s_CntActiveSyncs
static Uint8 s_NetworkErrorTimeout
static Uint8 s_MaxBlobSizeSync
static Uint4 s_MaxSlotLogEvents
vector< SSrvGroupInfo > TSrvGroupsList
static bool s_SlotByRawkey
static Uint4 s_CleanLogReserve
static Uint8 s_PeerThrottlePeriod
static Uint1 s_PeerTimeout
static vector< Uint2 > s_SelfSlots
map< Uint2, TServersList > TSlot2SrvMap
static Uint2 s_MaxMirrorQueueSize
static Uint4 s_TaskPrioritySync
static Uint8 s_MinForcedCleanPeriod
static const char * str(char *buf, int n)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
void Set(TValue new_value) THROWS_NONE
Set atomic counter value.
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
void Critical(CExceptionArgs_Base &args)
void Error(CExceptionArgs_Base &args)
static Uint4 CalculateChecksum(const string &host, unsigned short port)
Calculate and return the CRC32 checksum generated from the string "host:port".
static void GenerateBlobKey(string *key, unsigned int id, const string &host, unsigned short port, unsigned int ver, unsigned int rnd_num, time_t creation_time=0)
Generate blob key string.
static bool ParseBlobKey(const char *key_str, size_t key_len, CNetCacheKey *key_obj, CCompoundIDPool::TInstance id_pool=NULL)
Parse blob key string into a CNetCacheKey structure.
uint8_t Uint1
1-byte (8-bit) unsigned integer
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define NCBI_UINT8_FORMAT_SPEC
Uint4 TValue
Type of the generated integer value and/or the seed value.
TValue GetRand(void)
Get the next random number in the interval [0..GetMax()] (inclusive)
static TValue GetMax(void)
The max. value GetRand() returns.
virtual bool GetBool(const string §ion, const string &name, bool default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get boolean value of specified parameter name.
virtual const string & Get(const string §ion, const string &name, TFlags flags=0) const
Get the parameter value.
virtual int GetInt(const string §ion, const string &name, int default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get integer value of specified parameter name.
virtual string GetString(const string §ion, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
bool Set(const string §ion, const string &name, const string &value, TFlags flags=0, const string &comment=kEmptyStr)
Set the configuration parameter value.
@ fPersistent
Persistent – saved when file is written.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static Uint8 StringToUInt8_DataSize(const CTempString str, TStringToNumFlags flags=0)
Convert string that can contain "software" qualifiers to Uint8.
const char * data(void) const
Return a pointer to the array represented.
static string UInt8ToString_DataSize(Uint8 value, TNumToStringFlags flags=0, unsigned int max_digits=3)
Convert UInt8 to string using "software" qualifiers.
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
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.
size_type size(void) const
Return the length of the represented array.
static string UInt8ToString(Uint8 value, TNumToStringFlags flags=0, int base=10)
Convert UInt8 to string.
@ fAllowTrailingSpaces
Ignore trailing whitespace characters.
@ fConvErr_NoThrow
Do not throw an exception on error.
@ fAllowTrailingSymbols
Ignore trailing non-numerics characters.
@ fAllowLeadingSpaces
Ignore leading whitespace characters in converted string.
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
vector< Uint8 > TServersList
Process information in the NCBI Registry, including working with configuration files.
#define SRV_LOG(sev, msg)
Macro to be used for printing log messages.
#define ACCESS_ONCE(x)
Purpose of this macro is to force compiler to access variable exactly at the place it's written (no m...
bool AtomicCAS(T volatile &var, T old_value, T new_value)
Meaningful information encoded in the NetCache key.
SSrvGroupInfo(Uint8 srv, const string &group)
TSlot2SrvMap s_RawSlot2Servers
TSrv2SlotMap s_CommonSlots
map< Uint4, Uint8 > s_IpToId
TSrv2SlotMap s_Servers2Slots
TSrvGroupsMap s_Slot2Servers
map< Uint8, Uint8 > s_SrvTrust