TNSBitVector CNSClientsRegistry::GetWaitAffinities(const CNSClientId & client, ECommandGroup cmd_group) const { if (!client.IsComplete()) return kEmptyBitVector; return GetWaitAffinities(client.GetNode(), cmd_group); }
bool CNSClientsRegistry::CancelWaiting(const CNSClientId & client, ECommandGroup cmd_group) { // Check if it is an old-style client if (client.IsComplete()) return CancelWaiting(client.GetNode(), cmd_group); return false; }
void CNSClientsRegistry::AddBlacklistedJobs( const CNSClientId & client, ECommandGroup cmd_group, TNSBitVector & bv) const { if (client.IsComplete()) AddBlacklistedJobs(client.GetNode(), cmd_group, bv); }
void CNSClientsRegistry::SetLastScope(const CNSClientId & client) { // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator cl = m_Clients.find(client.GetNode()); if (cl != m_Clients.end()) cl->second.SetLastScope(client.GetScope()); }
void CNSClientsRegistry::MarkAsAdmin(const CNSClientId & client) { // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator admin = m_Clients.find(client.GetNode()); if (admin != m_Clients.end()) admin->second.MarkAsAdmin(); }
void CNSClientsRegistry::AppendType(const CNSClientId & client, unsigned int type_to_append) { // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator cl = m_Clients.find(client.GetNode()); if (cl != m_Clients.end()) cl->second.AppendType(type_to_append); }
void CNSClientsRegistry::SetPreferredAffinities(const CNSClientId & client, const TNSBitVector & aff_to_set, ECommandGroup cmd_group) { if (!client.IsComplete()) return; string client_name = client.GetNode(); CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator found = m_Clients.find(client_name); if (found == m_Clients.end()) NCBI_THROW(CNetScheduleException, eInternalError, "Cannot find client '" + client.GetNode() + "' to update preferred affinities"); TNSBitVector curr_affs = found->second.GetPreferredAffinities(cmd_group); TNSBitVector aff_to_add = aff_to_set - curr_affs; TNSBitVector aff_to_del = curr_affs - aff_to_set; if (aff_to_add.any()) m_AffRegistry->AddClientToAffinities(client.GetID(), aff_to_add, cmd_group); if (aff_to_del.any()) m_AffRegistry->RemoveClientFromAffinities(client.GetID(), aff_to_del, cmd_group); found->second.SetPreferredAffinities(aff_to_set, cmd_group); // Update the union bit vector with WN/reader affinities if (aff_to_del.any()) x_BuildAffinities(cmd_group); else { if (aff_to_add.any()) { if (cmd_group == eGet) m_WNodeAffinities |= aff_to_add; else m_ReaderAffinities |= aff_to_add; } } // Remove the client from the GC collected, because it affects affinities // only which are re-set here anyway if (cmd_group == eGet) m_GCWNodeClients.erase(client_name); else m_GCReaderClients.erase(client_name); }
// Updates the submitter job. // No need to check session id, it's done in Touch() void CNSClientsRegistry::AddToSubmitted(const CNSClientId & client, size_t count) { // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator submitter = m_Clients.find(client.GetNode()); if (submitter != m_Clients.end()) submitter->second.RegisterSubmittedJobs(count); }
bool CNSClientsRegistry::WasGarbageCollected(const CNSClientId & client, ECommandGroup cmd_group) const { if (!client.IsComplete()) return false; CMutexGuard guard(m_Lock); if (cmd_group == eGet) return m_GCWNodeClients.find(client.GetNode()) != m_GCWNodeClients.end(); return m_GCReaderClients.find(client.GetNode()) != m_GCReaderClients.end(); }
// Moves the client job into a blacklist. // No need to check session id, it's done in Touch() void CNSClientsRegistry::MoveJobToBlacklist(const CNSClientId & client, unsigned int job_id, ECommandGroup cmd_group) { // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator cl = m_Clients.find(client.GetNode()); if (cl != m_Clients.end()) cl->second.MoveJobToBlacklist(job_id, cmd_group); }
bool CNSClientsRegistry::UpdatePreferredAffinities(const CNSClientId & client, unsigned int aff_to_add, unsigned int aff_to_del, ECommandGroup cmd_group) { if (aff_to_add + aff_to_del == 0) return false; if (!client.IsComplete()) return false; bool aff_added = false; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator found = m_Clients.find(client.GetNode()); if (found == m_Clients.end()) NCBI_THROW(CNetScheduleException, eInternalError, "Cannot find client '" + client.GetNode() + "' to update preferred affinities"); if (aff_to_add != 0) { m_AffRegistry->AddClientToAffinity(client.GetID(), aff_to_add, cmd_group); aff_added = found->second.AddPreferredAffinity(aff_to_add, cmd_group); } if (aff_to_del != 0) { m_AffRegistry->RemoveClientFromAffinities(client.GetID(), aff_to_del, cmd_group); found->second.RemovePreferredAffinity(aff_to_del, cmd_group); } // Update the union bit vector with WN/reader affinities if (aff_to_del != 0) x_BuildAffinities(cmd_group); else { if (aff_added) { if (cmd_group == eGet) m_WNodeAffinities.set_bit(aff_to_add); else m_ReaderAffinities.set_bit(aff_to_add); } } return aff_added; }
bool CNSClientsRegistry::GetAffinityReset(const CNSClientId & client, ECommandGroup cmd_group) const { if (!client.IsComplete()) return false; CMutexGuard guard(m_Lock); map< string, CNSClient >::const_iterator found = m_Clients.find(client.GetNode()); if (found == m_Clients.end()) return false; return found->second.GetAffinityReset(cmd_group); }
// Called before any command is issued by the client void CNSClientsRegistry::Touch(CNSClientId & client, TNSBitVector & running_jobs, TNSBitVector & reading_jobs, bool & client_was_found, bool & session_was_reset, string & old_session, bool & had_wn_pref_affs, bool & had_reader_pref_affs) { client_was_found = false; session_was_reset = false; old_session.clear(); had_wn_pref_affs = false; had_reader_pref_affs = false; // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator known_client = m_Clients.find(client.GetNode()); if (known_client == m_Clients.end()) { // The client is not known yet CNSClient new_ns_client(client, &m_BlacklistTimeout, &m_ReadBlacklistTimeout); unsigned int client_id = x_GetNextID(); new_ns_client.SetID(client_id); client.SetID(client_id); m_Clients[ client.GetNode() ] = new_ns_client; m_RegisteredClients.set_bit(client_id); return; } client_was_found = true; // The client has connected before client.SetID(known_client->second.GetID()); old_session = known_client->second.GetSession(); if (client.GetSession() != old_session) { session_was_reset = true; ClearClient(client, running_jobs, reading_jobs, client_was_found, old_session, had_wn_pref_affs, had_reader_pref_affs); } known_client->second.Touch(client); // The 'reset' client type must not reset the collected types when the next // command is issued if (client.GetType() == eClaimedReset) client.SetClientType(eClaimedAutodetect); }
// Used in the following situations: // - CLRN // - new session // - GC for a client (it is not strictly required because it may happened only // for inactive clients, i.e. timeouted or after CLRN void CNSClientsRegistry::ClearClient(const CNSClientId & client, TNSBitVector & running_jobs, TNSBitVector & reading_jobs, bool & client_was_found, string & old_session, bool & had_wn_pref_affs, bool & had_reader_pref_affs) { client_was_found = false; // Check if it is an old-style client if (client.IsComplete()) ClearClient(client.GetNode(), running_jobs, reading_jobs, client_was_found, old_session, had_wn_pref_affs, had_reader_pref_affs); }
CNSClient::CNSClient(const CNSClientId & client_id, CNSPreciseTime * blacklist_timeout, CNSPreciseTime * read_blacklist_timeout) : m_State(eActive), m_Type(0), m_ClaimedType(client_id.GetType()), m_Addr(client_id.GetAddress()), m_ControlPort(client_id.GetControlPort()), m_ClientHost(client_id.GetClientHost()), m_RegistrationTime(0, 0), m_SessionStartTime(0, 0), m_SessionResetTime(0, 0), m_LastAccess(0, 0), m_Session(client_id.GetSession()), m_ID(0), m_NumberOfSubmitted(0), m_NumberOfSockErrors(0), m_ClientDataVersion(0), m_WNData(blacklist_timeout), m_ReaderData(read_blacklist_timeout), m_LastScope(client_id.GetScope()) { if (!client_id.IsComplete()) NCBI_THROW(CNetScheduleException, eInternalError, "Creating client information object for old style clients"); m_RegistrationTime = CNSPreciseTime::Current(); m_SessionStartTime = m_RegistrationTime; m_LastAccess = m_RegistrationTime; // It does not make any sense at the time of creation to have 'reset' // client type if (m_ClaimedType == eClaimedReset) m_ClaimedType = eClaimedAutodetect; }
// Updates the client blacklisted jobs list. // No need to check session id, it's done in Touch() void CNSClientsRegistry::RegisterBlacklistedJob(const CNSClientId & client, unsigned int job_id, ECommandGroup cmd_group) { // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator cl = m_Clients.find(client.GetNode()); if (cl == m_Clients.end()) NCBI_THROW(CNetScheduleException, eInternalError, "Cannot find client '" + client.GetNode() + "' to set blacklisted job"); cl->second.RegisterBlacklistedJob(job_id, cmd_group); }
int CNSClientsRegistry::SetClientData(const CNSClientId & client, const string & data, int data_version) { // Check if it is an old-style client if (!client.IsComplete()) NCBI_THROW(CNetScheduleException, eInvalidParameter, "only non-anonymous clients may set their data"); CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator found = m_Clients.find(client.GetNode()); if (found == m_Clients.end()) NCBI_THROW(CNetScheduleException, eInternalError, "Cannot find client '" + client.GetNode() + "' to set client data"); return found->second.SetClientData(data, data_version); }
// It updates running and reading job vectors // only in case if the client session has been changed void CNSClient::Touch(const CNSClientId & client_id) { m_LastAccess = CNSPreciseTime::Current(); m_State = eActive; m_ControlPort = client_id.GetControlPort(); m_ClientHost = client_id.GetClientHost(); m_Addr = client_id.GetAddress(); EClaimedClientType claimed_client_type = client_id.GetType(); if (claimed_client_type == eClaimedReset) { m_Type = 0; m_ClaimedType = eClaimedAutodetect; } else if (claimed_client_type != eClaimedNotProvided) m_ClaimedType = claimed_client_type; // Check the session id if (m_Session == client_id.GetSession()) return; // It's still the same session, nothing to check m_SessionStartTime = m_LastAccess; m_SessionResetTime = m_LastAccess; m_Session = client_id.GetSession(); // Affinity members are handled in the upper level of Touch() // There is no need to do anything with the blacklisted jobs. If there are // some jobs there they should stay in the list. m_WNData.m_AffReset = false; m_ReaderData.m_AffReset = false; }
void CNSClientsRegistry::UpdatePreferredAffinities(const CNSClientId & client, const TNSBitVector & aff_to_add, const TNSBitVector & aff_to_del, ECommandGroup cmd_group) { if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator found = m_Clients.find(client.GetNode()); if (found == m_Clients.end()) NCBI_THROW(CNetScheduleException, eInternalError, "Cannot find client '" + client.GetNode() + "' to update preferred affinities"); m_AffRegistry->AddClientToAffinities(client.GetID(), aff_to_add, cmd_group); m_AffRegistry->RemoveClientFromAffinities(client.GetID(), aff_to_del, cmd_group); found->second.AddPreferredAffinities(aff_to_add, cmd_group); found->second.RemovePreferredAffinities(aff_to_del, cmd_group); // Update the union bit vector with WN/reader affinities if (aff_to_del.any()) x_BuildAffinities(cmd_group); else { if (aff_to_add.any()) { if (cmd_group == eGet) m_WNodeAffinities |= aff_to_add; else m_ReaderAffinities |= aff_to_add; } } }
void CNSClientsRegistry::SetNodeWaiting(const CNSClientId & client, unsigned short port, const TNSBitVector & aff_ids, ECommandGroup cmd_group) { // Check if it is an old-style client if (!client.IsComplete()) return; CMutexGuard guard(m_Lock); map< string, CNSClient >::iterator node = m_Clients.find(client.GetNode()); if (node == m_Clients.end()) NCBI_THROW(CNetScheduleException, eInternalError, "Cannot find client '" + client.GetNode() + "' to set waiting attributes"); node->second.SetWaitPort(port, cmd_group); node->second.SetWaitAffinities(aff_ids, cmd_group); m_AffRegistry->SetWaitClientForAffinities(node->second.GetID(), aff_ids, cmd_group); }