mirror of
https://github.com/privacore/open-source-search-engine.git
synced 2025-07-14 02:36:06 -04:00
Hostdb: more constness
This commit is contained in:
16
Hostdb.cpp
16
Hostdb.cpp
@ -1178,7 +1178,7 @@ static int cmp (const void *v1, const void *v2) {
|
||||
|
||||
#include "Stats.h"
|
||||
|
||||
bool Hostdb::isShardDead ( int32_t shardNum ) {
|
||||
bool Hostdb::isShardDead(int32_t shardNum) const {
|
||||
// how many seconds since our main process was started?
|
||||
// i guess all nodes initially appear dead, so
|
||||
// compensate for that.
|
||||
@ -1186,7 +1186,7 @@ bool Hostdb::isShardDead ( int32_t shardNum ) {
|
||||
long elapsed = (now - g_stats.m_startTime) ;/// 1000;
|
||||
if ( elapsed < 60*1000 ) return false; // try 60 secs now
|
||||
|
||||
Host *shard = getShard ( shardNum );
|
||||
const Host *shard = getShard(shardNum);
|
||||
//Host *live = NULL;
|
||||
for ( int32_t i = 0 ; i < m_numHostsPerShard ; i++ ) {
|
||||
if(!isDead(shard[i].m_hostId))
|
||||
@ -1260,7 +1260,7 @@ Host *Hostdb::getLeastLoadedInShard ( uint32_t shardNum , char niceness ) {
|
||||
}
|
||||
|
||||
// if all are dead just return host #0
|
||||
Host *Hostdb::getFirstAliveHost ( ) {
|
||||
Host *Hostdb::getFirstAliveHost() {
|
||||
for ( int32_t i = 0 ; i < m_numHosts ; i++ )
|
||||
// if host #i is alive, return her
|
||||
if ( ! isDead ( i ) ) return getHost(i);
|
||||
@ -1268,13 +1268,13 @@ Host *Hostdb::getFirstAliveHost ( ) {
|
||||
return getHost(0);
|
||||
}
|
||||
|
||||
bool Hostdb::hasDeadHost ( ) {
|
||||
bool Hostdb::hasDeadHost() const {
|
||||
for ( int32_t i = 0 ; i < m_numHosts ; i++ )
|
||||
if ( isDead ( i ) ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int Hostdb::getNumHostsDead() {
|
||||
int Hostdb::getNumHostsDead() const {
|
||||
int count=0;
|
||||
for(int32_t i = 0; i < m_numHosts; i++)
|
||||
if(isDead(i))
|
||||
@ -1282,12 +1282,12 @@ int Hostdb::getNumHostsDead() {
|
||||
return count;
|
||||
}
|
||||
|
||||
bool Hostdb::isDead ( int32_t hostId ) {
|
||||
Host *h = getHost ( hostId );
|
||||
bool Hostdb::isDead(int32_t hostId) const {
|
||||
const Host *h = getHost(hostId);
|
||||
return isDead ( h );
|
||||
}
|
||||
|
||||
bool Hostdb::isDead(const Host *h) {
|
||||
bool Hostdb::isDead(const Host *h) const {
|
||||
if(h->m_retired)
|
||||
return true; // retired means "don't use it", so it is essentially dead
|
||||
if(g_hostdb.m_myHost == h)
|
||||
|
38
Hostdb.h
38
Hostdb.h
@ -247,16 +247,16 @@ class Hostdb {
|
||||
|
||||
// we consider the host dead if we didn't get a ping reply back
|
||||
// after 10 seconds
|
||||
bool isDead ( int32_t hostId ) ;
|
||||
bool isDead(int32_t hostId) const;
|
||||
|
||||
bool isDead(const Host *h);
|
||||
bool isDead(const Host *h) const;
|
||||
|
||||
bool hasDeadHost ( );
|
||||
int getNumHostsDead();
|
||||
bool hasDeadHost() const;
|
||||
int getNumHostsDead() const;
|
||||
|
||||
int64_t getNumGlobalRecs ( );
|
||||
|
||||
bool isShardDead ( int32_t shardNum ) ;
|
||||
bool isShardDead(int32_t shardNum) const;
|
||||
|
||||
Host *getLeastLoadedInShard ( uint32_t shardNum , char niceness );
|
||||
int32_t getHostIdWithSpideringEnabled ( uint32_t shardNum );
|
||||
@ -279,6 +279,9 @@ class Hostdb {
|
||||
if ( numHosts ) *numHosts = m_numHostsPerShard;
|
||||
return &m_hosts[shardNum * m_numHostsPerShard];
|
||||
}
|
||||
const Host *getShard( uint32_t shardNum , int32_t *numHosts = NULL) const {
|
||||
return const_cast<Hostdb*>(this)->getShard(shardNum,numHosts);
|
||||
}
|
||||
|
||||
// get the host that has this path/ip
|
||||
Host *getHost2 ( const char *cwd , int32_t *localIps ) ;
|
||||
@ -289,29 +292,32 @@ class Hostdb {
|
||||
if ( hostId < 0 ) { gbshutdownAbort(true); }
|
||||
return m_hostPtrs[hostId];
|
||||
}
|
||||
|
||||
const Host *getHost(int32_t hostId) const {
|
||||
return const_cast<Hostdb*>(this)->getHost(hostId);
|
||||
}
|
||||
|
||||
Host *getSpare ( int32_t spareId ) {
|
||||
return m_spareHosts[spareId]; }
|
||||
|
||||
Host *getProxy ( int32_t proxyId ) {
|
||||
return m_proxyHosts[proxyId]; }
|
||||
|
||||
int32_t getNumHosts() { return m_numHosts; }
|
||||
int32_t getNumProxy() { return m_numProxyHosts; }
|
||||
int32_t getNumProxies() { return m_numProxyHosts; }
|
||||
int32_t getNumGrunts() { return m_numHosts; }
|
||||
int32_t getNumHosts() const { return m_numHosts; }
|
||||
int32_t getNumProxy() const { return m_numProxyHosts; }
|
||||
int32_t getNumProxies() const { return m_numProxyHosts; }
|
||||
int32_t getNumGrunts() const { return m_numHosts; }
|
||||
|
||||
// how many of the hosts are non-dead?
|
||||
int32_t getNumHostsAlive ( ) { return m_numHostsAlive; }
|
||||
int32_t getNumProxyAlive ( ) { return m_numProxyAlive; }
|
||||
int32_t getNumShards () { return m_numShards; }
|
||||
int32_t getNumIndexSplits() { return m_indexSplits; }
|
||||
int32_t getNumHostsAlive() const { return m_numHostsAlive; }
|
||||
int32_t getNumProxyAlive() const { return m_numProxyAlive; }
|
||||
int32_t getNumShards() const { return m_numShards; }
|
||||
int32_t getNumIndexSplits() const { return m_indexSplits; }
|
||||
|
||||
// how many hosts in this group?
|
||||
int32_t getNumHostsPerShard ( ) { return m_numHostsPerShard; }
|
||||
int32_t getNumHostsPerShard() const { return m_numHostsPerShard; }
|
||||
|
||||
// goes with Host::m_stripe
|
||||
int32_t getNumStripes ( ) {
|
||||
int32_t getNumStripes() const {
|
||||
// BR 20160316: Make sure noquery hosts are not used when dividing
|
||||
// docIds for querying (Msg39)
|
||||
return m_numStripeHostsPerShard;
|
||||
|
Reference in New Issue
Block a user