int CollectorEngine::invalidateAds(AdTypes adType, ClassAd &query) { CollectorHashTable *table=0; CollectorEngine::HashFunc func; if (!LookupByAdType(adType, table, func)) { dprintf (D_ALWAYS, "Unknown type %d\n", adType); return 0; } int count = 0; ClassAd *ad; AdNameHashKey hk; MyString hkString; (*table).startIterations(); while ((*table).iterate (ad)) { if (IsAHalfMatch(&query, ad)) { (*table).getCurrentKey(hk); hk.sprint(hkString); if ((*table).remove(hk) == -1) { dprintf(D_ALWAYS, "\t\tError while removing ad: \"%s\"\n", hkString.Value()); } else { dprintf(D_ALWAYS, "\t\t**** Invalidating ad: \"%s\"\n", hkString.Value()); delete ad; count++; } } } return count; }
int CollectorEngine::remove (AdTypes t_AddType, const ClassAd & c_query, bool *query_contains_hash_key) { int iRet = 0; AdNameHashKey hk; CollectorHashTable * table; HashFunc makeKey; MyString hkString; if( query_contains_hash_key ) { *query_contains_hash_key = false; } // making it generic so any would be invalid query can contain these params. if ( LookupByAdType (t_AddType, table, makeKey) ) { ClassAd * pAd=0; // try to create a hk from the query ad if it is possible. if ( (*makeKey) (hk, &c_query) ) { if( query_contains_hash_key ) { *query_contains_hash_key = true; } if( table->lookup(hk, pAd) != -1 ) { hk.sprint( hkString ); iRet = !table->remove(hk); dprintf (D_ALWAYS,"\t\t**** Removed(%d) ad(s): \"%s\"\n", iRet, hkString.Value() ); delete pAd; } } } return ( iRet ); }
void CollectorEngine:: cleanHashTable (CollectorHashTable &hashTable, time_t now, HashFunc makeKey) { ClassAd *ad; int timeStamp; int max_lifetime; AdNameHashKey hk; double timeDiff; MyString hkString; hashTable.startIterations (); while (hashTable.iterate (ad)) { // Read the timestamp of the ad if (!ad->LookupInteger (ATTR_LAST_HEARD_FROM, timeStamp)) { dprintf (D_ALWAYS, "\t\tError looking up time stamp on ad\n"); continue; } // how long has it been since the last update? timeDiff = difftime( now, timeStamp ); if( !ad->LookupInteger( ATTR_CLASSAD_LIFETIME, max_lifetime ) ) { max_lifetime = machineUpdateInterval; } // check if it has expired if ( timeDiff > (double) max_lifetime ) { // then remove it from the segregated table (*makeKey) (hk, ad); hk.sprint( hkString ); if( timeStamp == 0 ) { dprintf (D_ALWAYS,"\t\t**** Removing invalidated ad: \"%s\"\n", hkString.Value() ); } else { dprintf (D_ALWAYS,"\t\t**** Removing stale ad: \"%s\"\n", hkString.Value() ); /* let the off-line plug-in know we are about to expire this ad, so it can potentially mark the ad absent. if expire() returns false, then delete the ad as planned; if it return true, it was likely marked as absent, so then this ad should NOT be deleted. */ if ( CollectorDaemon::offline_plugin_.expire( *ad ) == true ) { // plugin say to not delete this ad, so continue continue; } else { dprintf (D_ALWAYS,"\t\t**** Removing stale ad: \"%s\"\n", hkString.Value() ); } } if (hashTable.remove (hk) == -1) { dprintf (D_ALWAYS, "\t\tError while removing ad\n"); } delete ad; } } }
const char* OfflineCollectorPlugin::makeOfflineKey( const ClassAd &ad, MyString & s) { AdNameHashKey hashKey; if ( !makeStartdAdHashKey ( hashKey, const_cast<ClassAd*>( &ad ) ) ) { dprintf ( D_FULLDEBUG, "OfflineCollectorPlugin::makeOfflineKey: " "failed to hash class ad. Ignoring.\n" ); return NULL; } hashKey.sprint ( s ); s.compressSpaces(); return s.Value(); }
int CollectorEngine::expire( AdTypes adType, const ClassAd & query, bool * queryContainsHashKey ) { int rVal = 0; if( queryContainsHashKey ) { * queryContainsHashKey = false; } HashFunc hFunc; CollectorHashTable * hTable; if( LookupByAdType( adType, hTable, hFunc ) ) { AdNameHashKey hKey; if( (* hFunc)( hKey, & query ) ) { if( queryContainsHashKey ) { * queryContainsHashKey = true; } ClassAd * cAd = NULL; if( hTable->lookup( hKey, cAd ) != -1 ) { cAd->Assign( ATTR_LAST_HEARD_FROM, 1 ); if( CollectorDaemon::offline_plugin_.expire( * cAd ) == true ) { return rVal; } rVal = hTable->remove( hKey ); if( rVal == -1 ) { dprintf( D_ALWAYS, "\t\t Error removing ad\n" ); return 0; } rVal = (! rVal); MyString hkString; hKey.sprint( hkString ); dprintf( D_ALWAYS, "\t\t**** Removed(%d) stale ad(s): \"%s\"\n", rVal, hkString.Value() ); delete cAd; } } } return rVal; }