void Balancer::run(){ { // init stuff, don't want to do at static init StringBuilder buf; buf << ourHostname << ":" << cmdLine.port; _myid = buf.str(); log(1) << "balancer myid: " << _myid << endl; _started = time(0); Shard::reloadShardInfo(); } _ping(); _checkOIDs(); while ( ! inShutdown() ){ sleepsecs( 10 ); try { ScopedDbConnection conn( configServer.getPrimary() ); _ping( conn.conn() ); if ( ! _checkOIDs() ){ uassert( 13258 , "oids broken after resetting!" , _checkOIDs() ); } vector<CandidateChunkPtr> candidateChunks; if ( _shouldIBalance( conn.conn() ) ){ log(1) << "balancer: start balancing round" << endl; candidateChunks.clear(); _doBalanceRound( conn.conn() , &candidateChunks ); if ( candidateChunks.size() == 0 ) { log(1) << "balancer: no need to move any chunk" << endl; } else { _balancedLastTime = _moveChunks( &candidateChunks ); log(1) << "balancer: end balancing round" << endl; } } conn.done(); } catch ( std::exception& e ){ log() << "caught exception while doing balance: " << e.what() << endl; // It's possible this shard was removed Shard::reloadShardInfo(); continue; } } }
int main (int argc, char **argv) { if (argc < 2) { g_printerr ("Usage:i\n"); g_printerr (" %s addr IP:PORT\n", argv[0]); g_printerr (" %s cid OIOURL\n", argv[0]); g_printerr (" %s hash [PREFIX]\n", argv[0]); g_printerr (" %s ping IP:PORT [TIMEOUT]\n", argv[0]); g_printerr (" %s stat [path]...\n", argv[0]); return 2; } oio_ext_set_random_reqid (); if (!strcmp("addr", argv[1])) { for (int i=2; i<argc ;++i) _dump_addr (argv[i]); return 0; } else if (!strcmp("cid", argv[1])) { for (int i=2; i<argc ;++i) _dump_cid (argv[i]); return 0; } else if (!strcmp("hash", argv[1])) { if (argc < 2 || argc > 4) { g_printerr ("Usage: %s hash ACCOUNT [PREFIX]\n", argv[0]); return 1; } _same_hash (argv[2], argc==4 ? argv[3] : ""); return 0; } else if (!strcmp("ping", argv[1])) { if (argc > 3) return _ping(argv[2], argv[3]); else return _ping(argv[2], "10.0"); } else if (!strcmp("stat", argv[1])) { _sysstat (argv+2); return 0; } return 1; }
void Balancer::_ping(){ assert( _myid.size() && _started ); try { ScopedDbConnection conn( configServer.getPrimary() ); _ping( conn.conn() ); conn.done(); } catch ( std::exception& e ){ log() << "bare ping failed: " << e.what() << endl; } }
main() { char buffer[100]; longword seq,ping_who,tmp_seq,time_out; float mavg_txrate, mavg_rxrate; float avg_txrate, avg_rxrate; float txrate, rxrate; int gather; brdInit(); //initialize board for this demo // Configure IO channels as digital outputs (sinking type outputs) setDigOut (LED1, 1); // Configure LED1 as sinking type output setDigOut (LED2, 1); // Configure LED2 as sinking type output // Set the initial state of the LED's digOut(LED1, LEDOFF); digOut(LED2, LEDOFF); seq=0; mavg_txrate = mavg_rxrate = 0.0; avg_txrate = avg_rxrate = 0.0; // Start network and wait until associated sock_init_or_exit(1); /* * Get the binary ip address for the target of our * pinging. */ #ifdef PING_WHO /* Ping a specific IP addr: */ ping_who=resolve(PING_WHO); if(ping_who==0) { printf("ERROR: unable to resolve %s\n",PING_WHO); exit(2); } #else /* Examine our configuration, and ping the default router: */ tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END ); if( tmp_seq != 0 ) { printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq ); exit(2); } if(ping_who==0) { printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n"); exit(2); } #endif #ifdef VERBOSE printf("\n"); printf("Note: RSSI = Receive Signal Strength Indicator\n"); printf("The last display line shows a filtered rate estimate.\n"); printf("Every %u samples (at %u ms intervals) these rates will be\n", GATHER_INTERVAL, PING_DELAY); printf(" set to the average over the last %u ms, and the next\n", GATHER_INTERVAL * PING_DELAY); printf(" line is started.\n"); #ifdef GRAPHICAL printf("Bar graphs are * == 1Mbit/sec and # == 4Mbit/sec\n"); printf("\n\n"); printf("\tRx rate (Kbit)\t\tTx rate (Kbit)\t\tRSSI (dB)\n"); printf("Seq\tLast\tFilt.\t\tLast\tFilt.\t\tFilt.\n"); printf("------- ------- --------------- ------- --------------- -------\n"); #else printf("\n\n"); printf("\tRx rate (Kbit)\tTx rate (Kbit)\tRSSI (dB)\n"); printf("Seq\tLast\tFilt.\tLast\tFilt.\tFilt.\n"); printf("------- ------- ------- ------- ------- -------\n"); #endif #endif for(;;) { /* * It is important to call tcp_tick here because * ping packets will not get processed otherwise. * */ tcp_tick(NULL); /* * Send one ping every PING_DELAY ms. */ costate { waitfor(DelayMs(PING_DELAY)); _ping(ping_who,seq++); pingoutled(LEDON); // flash transmit LED waitfor(DelayMs(50)); pingoutled(LEDOFF); } /* * Has a ping come in? time_out!=0xfffffff->yes. */ costate { time_out=_chk_ping(ping_who,&tmp_seq); if(time_out!=0xffffffff) { // Here is where we gather the statistics... // Note that if you get a compile error here, it is because you are not running // this sample on a Wifi-equipped board. ifconfig (IF_WIFI0, IFG_WIFI_STATUS, &wstatus, IFS_END); txrate = wstatus.tx_rate * 100.0; // Convert to Kbit/sec rxrate = wstatus.rx_rate * 100.0; mavg_txrate = mavg_txrate * ((MOVING_AVERAGE - 1.0)/MOVING_AVERAGE) + txrate * (1.0/MOVING_AVERAGE); mavg_rxrate = mavg_rxrate * ((MOVING_AVERAGE - 1.0)/MOVING_AVERAGE) + rxrate * (1.0/MOVING_AVERAGE); avg_txrate += txrate; avg_rxrate += rxrate; gather = tmp_seq % GATHER_INTERVAL == 0; #ifdef VERBOSE #ifdef GRAPHICAL printf("%7lu %7u %15.15s %7u %15.15s %7d %c", tmp_seq, (word)rxrate, graph(rxgraph, gather ? (word)(avg_rxrate / GATHER_INTERVAL) : (word)mavg_rxrate), (word)txrate, graph(txgraph, gather ? (word)(avg_txrate / GATHER_INTERVAL) : (word)mavg_txrate), wstatus.rx_signal >> _WIFI_RSSI_SCALE_SHIFT, gather ? '\n' : '\r' ); #else printf("%7lu %7u %7u %7u %7u %7d %c", tmp_seq, (word)rxrate, gather ? (word)(avg_rxrate / GATHER_INTERVAL) : (word)mavg_rxrate, (word)txrate, gather ? (word)(avg_txrate / GATHER_INTERVAL) : (word)mavg_txrate, wstatus.rx_signal >> _WIFI_RSSI_SCALE_SHIFT, gather ? '\n' : '\r' ); #endif #endif if (gather) avg_txrate = avg_rxrate = 0.0; pinginled(LEDON); // flash receive LED waitfor(DelayMs(50)); pinginled(LEDOFF); } } }
void Balancer::run() { Client::initThread("Balancer"); // This is the body of a BackgroundJob so if we throw here we're basically ending the balancer // thread prematurely. while (!inShutdown()) { auto txn = cc().makeOperationContext(); if (!_init(txn.get())) { log() << "will retry to initialize balancer in one minute"; sleepsecs(60); continue; } break; } Seconds balanceRoundInterval(kBalanceRoundDefaultInterval); while (!inShutdown()) { auto txn = cc().makeOperationContext(); BalanceRoundDetails roundDetails; try { // ping has to be first so we keep things in the config server in sync _ping(txn.get(), false); MONGO_FAIL_POINT_BLOCK(balancerRoundIntervalSetting, scopedBalancerRoundInterval) { const BSONObj& data = scopedBalancerRoundInterval.getData(); balanceRoundInterval = Seconds(data["sleepSecs"].numberInt()); } // Use fresh shard state and balancer settings Grid::get(txn.get())->shardRegistry()->reload(txn.get()); auto balancerConfig = Grid::get(txn.get())->getBalancerConfiguration(); Status refreshStatus = balancerConfig->refreshAndCheck(txn.get()); if (!refreshStatus.isOK()) { warning() << "Skipping balancing round" << causedBy(refreshStatus); sleepFor(balanceRoundInterval); continue; } // now make sure we should even be running if (!balancerConfig->isBalancerActive() || MONGO_FAIL_POINT(skipBalanceRound)) { LOG(1) << "skipping balancing round because balancing is disabled"; // Ping again so scripts can determine if we're active without waiting _ping(txn.get(), true); sleepFor(balanceRoundInterval); continue; } uassert(13258, "oids broken after resetting!", _checkOIDs(txn.get())); { auto scopedDistLock = grid.catalogManager(txn.get()) ->distLock(txn.get(), "balancer", "doing balance round", DistLockManager::kSingleLockAttemptTimeout); if (!scopedDistLock.isOK()) { LOG(1) << "skipping balancing round" << causedBy(scopedDistLock.getStatus()); // Ping again so scripts can determine if we're active without waiting _ping(txn.get(), true); sleepFor(balanceRoundInterval); // no need to wake up soon continue; } LOG(1) << "*** start balancing round. " << "waitForDelete: " << balancerConfig->waitForDelete() << ", secondaryThrottle: " << balancerConfig->getSecondaryThrottle().toBSON(); OCCASIONALLY warnOnMultiVersion( uassertStatusOK(_clusterStats->getStats(txn.get()))); Status status = _enforceTagRanges(txn.get()); if (!status.isOK()) { warning() << "Failed to enforce tag ranges" << causedBy(status); } else { LOG(1) << "Done enforcing tag range boundaries."; } const auto candidateChunks = uassertStatusOK( _chunkSelectionPolicy->selectChunksToMove(txn.get(), _balancedLastTime)); if (candidateChunks.empty()) { LOG(1) << "no need to move any chunk"; _balancedLastTime = 0; } else { _balancedLastTime = _moveChunks(txn.get(), candidateChunks, balancerConfig->getSecondaryThrottle(), balancerConfig->waitForDelete()); roundDetails.setSucceeded(static_cast<int>(candidateChunks.size()), _balancedLastTime); grid.catalogManager(txn.get()) ->logAction(txn.get(), "balancer.round", "", roundDetails.toBSON()); } LOG(1) << "*** End of balancing round"; } // Ping again so scripts can determine if we're active without waiting _ping(txn.get(), true); sleepFor(_balancedLastTime ? kShortBalanceRoundInterval : balanceRoundInterval); } catch (const std::exception& e) { log() << "caught exception while doing balance: " << e.what(); // Just to match the opening statement if in log level 1 LOG(1) << "*** End of balancing round"; // This round failed, tell the world! roundDetails.setFailed(e.what()); grid.catalogManager(txn.get()) ->logAction(txn.get(), "balancer.round", "", roundDetails.toBSON()); // Sleep a fair amount before retrying because of the error sleepFor(balanceRoundInterval); } } }
debug void main() { longword host, timer, new_rcvd; longword tot_timeout, itts, send_timeout; word i; word sequence_mode, is_new_line; word debug_on; static unsigned char tempbuffer[255]; word arping; auto char ip[16], netmask[16]; auto int status; sent=received=tot_delays=last_rcvd=0L; tot_timeout=itts=send_timeout=0L; debug_on=0; is_new_line=1; arping = 1; // Start network and wait for interface to come up (or error exit). printf("Starting/joining ad-hoc network...\n"); sock_init_or_exit(1); name=PINGWHO; itts=0; // 0 == continuous if (!(host = resolve( name ))) { printf("Unable to resolve '%s'\n", name ); exit( 3 ); } if ( isaddr( name )) printf("Pinging [%s]",inet_ntoa(tempbuffer, host)); else printf("Pinging '%s' [%s]",name, inet_ntoa(tempbuffer, host)); if (!itts) itts = 1000000L; printf(" %lu times\n", itts); tot_timeout = _SET_TIMEOUT((itts + 2)*1000L); send_timeout = _SET_TIMEOUT(0); do { /* once per second - do all this */ if ( chk_timeout( send_timeout )) { send_timeout = _SET_TIMEOUT(1000L); if (chk_timeout( tot_timeout )) { stats(); break; } if (arping) { if (!_arp_resolve( host, (eth_address *)tempbuffer, 0 )) printf("Could not resolve hardware address (maybe other host not up yet)\n"); else { arping = 0; printf("Hardware address resolved to %02x:%02x:%02x:%02x:%02x:%02x\n", (int)tempbuffer[0],(int)tempbuffer[1],(int)tempbuffer[2],(int)tempbuffer[3], (int)tempbuffer[4],(int)tempbuffer[5]); } } if (!arping && sent < itts) { sent++; if (_ping( host , sent )) stats(); if (!is_new_line) printf("\n"); printf("sent PING # %lu ", sent ); is_new_line = 0; } } if ( kbhit() ) { getchar(); /* trash the character */ stats(); } tcp_tick(NULL); if (arping) continue; if ((timer = _chk_ping( host , &new_rcvd)) != 0xffffffffL) { tot_delays += timer; ++received; if ( new_rcvd != last_rcvd + 1 ) { if (!is_new_line) printf("\n"); printf("PING receipt received out of order!\n"); is_new_line = 1; } last_rcvd = new_rcvd; if (!is_new_line) printf(", "); printf("PING receipt # %lu : response time %lu ms\n", received, timer); is_new_line = 1; if ( received == itts ) stats(); } } while (1); }
main() { longword seq,ping_who,tmp_seq,time_out; char buffer[100]; brdInit(); //initialize board for this demo seq=0; // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); /* * Get the binary ip address for the target of our * pinging. */ #ifdef PING_WHO /* Ping a specific IP addr: */ ping_who=resolve(PING_WHO); if(ping_who==0) { printf("ERROR: unable to resolve %s\n",PING_WHO); exit(2); } #else /* Examine our configuration, and ping the default router: */ tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END ); if( tmp_seq != 0 ) { printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq ); exit(2); } if(ping_who==0) { printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n"); exit(2); } #endif for(;;) { /* * It is important to call tcp_tick here because * ping packets will not get processed otherwise. * */ tcp_tick(NULL); /* * Send one ping every PING_DELAY ms. */ costate { waitfor(DelayMs(PING_DELAY)); _ping(ping_who,seq++); pingoutled(LEDON); // flash transmit LED waitfor(DelayMs(50)); pingoutled(LEDOFF); } /* * Has a ping come in? time_out!=0xfffffff->yes. */ costate { time_out=_chk_ping(ping_who,&tmp_seq); if(time_out!=0xffffffff) { #ifdef VERBOSE printf("received ping: %ld\n", tmp_seq); #endif pinginled(LEDON); // flash receive LED waitfor(DelayMs(50)); pinginled(LEDOFF); } } } }
void Balancer::run() { // this is the body of a BackgroundJob so if we throw here we're basically ending the balancer thread prematurely while ( ! inShutdown() ) { if ( ! _init() ) { log() << "will retry to initialize balancer in one minute" << endl; sleepsecs( 60 ); continue; } break; } int sleepTime = 30; // getConnectioString and dist lock constructor does not throw, which is what we expect on while // on the balancer thread ConnectionString config = configServer.getConnectionString(); DistributedLock balanceLock( config , "balancer" ); while ( ! inShutdown() ) { try { scoped_ptr<ScopedDbConnection> connPtr( ScopedDbConnection::getInternalScopedDbConnection( config.toString() ) ); ScopedDbConnection& conn = *connPtr; // ping has to be first so we keep things in the config server in sync _ping( conn.conn() ); // use fresh shard state Shard::reloadShardInfo(); // refresh chunk size (even though another balancer might be active) Chunk::refreshChunkSize(); BSONObj balancerConfig; // now make sure we should even be running if ( ! grid.shouldBalance( "", &balancerConfig ) ) { LOG(1) << "skipping balancing round because balancing is disabled" << endl; // Ping again so scripts can determine if we're active without waiting _ping( conn.conn(), true ); conn.done(); sleepsecs( sleepTime ); continue; } sleepTime = balancerConfig["_nosleep"].trueValue() ? 30 : 6; uassert( 13258 , "oids broken after resetting!" , _checkOIDs() ); { dist_lock_try lk( &balanceLock , "doing balance round" ); if ( ! lk.got() ) { LOG(1) << "skipping balancing round because another balancer is active" << endl; // Ping again so scripts can determine if we're active without waiting _ping( conn.conn(), true ); conn.done(); sleepsecs( sleepTime ); // no need to wake up soon continue; } LOG(1) << "*** start balancing round" << endl; vector<CandidateChunkPtr> candidateChunks; _doBalanceRound( conn.conn() , &candidateChunks ); if ( candidateChunks.size() == 0 ) { LOG(1) << "no need to move any chunk" << endl; _balancedLastTime = 0; } else { _balancedLastTime = _moveChunks( &candidateChunks, balancerConfig["_secondaryThrottle"].trueValue() ); } LOG(1) << "*** end of balancing round" << endl; } // Ping again so scripts can determine if we're active without waiting _ping( conn.conn(), true ); conn.done(); sleepsecs( _balancedLastTime ? sleepTime / 6 : sleepTime ); } catch ( std::exception& e ) { log() << "caught exception while doing balance: " << e.what() << endl; // Just to match the opening statement if in log level 1 LOG(1) << "*** End of balancing round" << endl; sleepsecs( sleepTime ); // sleep a fair amount b/c of error continue; } } }
void Balancer::run() { // this is the body of a BackgroundJob so if we throw here we're basically ending the balancer thread prematurely while ( ! inShutdown() ) { if ( ! _init() ) { log() << "will retry to initialize balancer in one minute" << endl; sleepsecs( 60 ); continue; } break; } int sleepTime = 10; // getConnectioString and dist lock constructor does not throw, which is what we expect on while // on the balancer thread ConnectionString config = configServer.getConnectionString(); DistributedLock balanceLock( config , "balancer" ); while ( ! inShutdown() ) { try { ScopedDbConnection conn(config.toString(), 30); // ping has to be first so we keep things in the config server in sync _ping(); // use fresh shard state Shard::reloadShardInfo(); // refresh chunk size (even though another balancer might be active) Chunk::refreshChunkSize(); SettingsType balancerConfig; string errMsg; if (!grid.getBalancerSettings(&balancerConfig, &errMsg)) { warning() << errMsg; return ; } // now make sure we should even be running if ((balancerConfig.isKeySet() && // balancer config doc exists !grid.shouldBalance(balancerConfig)) || MONGO_FAIL_POINT(skipBalanceRound)) { LOG(1) << "skipping balancing round because balancing is disabled" << endl; // Ping again so scripts can determine if we're active without waiting _ping( true ); conn.done(); sleepsecs( sleepTime ); continue; } uassert( 13258 , "oids broken after resetting!" , _checkOIDs() ); { dist_lock_try lk( &balanceLock , "doing balance round" ); if ( ! lk.got() ) { LOG(1) << "skipping balancing round because another balancer is active" << endl; // Ping again so scripts can determine if we're active without waiting _ping( true ); conn.done(); sleepsecs( sleepTime ); // no need to wake up soon continue; } if ( !isConfigServerConsistent() ) { conn.done(); warning() << "Skipping balancing round because data inconsistency" << " was detected amongst the config servers." << endl; sleepsecs( sleepTime ); continue; } const bool waitForDelete = (balancerConfig.isWaitForDeleteSet() ? balancerConfig.getWaitForDelete() : false); scoped_ptr<WriteConcernOptions> writeConcern; if (balancerConfig.isKeySet()) { // if balancer doc exists. StatusWith<WriteConcernOptions*> extractStatus = balancerConfig.extractWriteConcern(); if (extractStatus.isOK()) { writeConcern.reset(extractStatus.getValue()); } else { warning() << extractStatus.toString(); } } LOG(1) << "*** start balancing round. " << "waitForDelete: " << waitForDelete << ", secondaryThrottle: " << (writeConcern.get() ? writeConcern->toBSON().toString() : "default") << endl; vector<CandidateChunkPtr> candidateChunks; _doBalanceRound( conn.conn() , &candidateChunks ); if ( candidateChunks.size() == 0 ) { LOG(1) << "no need to move any chunk" << endl; _balancedLastTime = 0; } else { _balancedLastTime = _moveChunks(&candidateChunks, writeConcern.get(), waitForDelete ); } LOG(1) << "*** end of balancing round" << endl; } // Ping again so scripts can determine if we're active without waiting _ping( true ); conn.done(); sleepsecs( _balancedLastTime ? sleepTime / 10 : sleepTime ); } catch ( std::exception& e ) { log() << "caught exception while doing balance: " << e.what() << endl; // Just to match the opening statement if in log level 1 LOG(1) << "*** End of balancing round" << endl; sleepsecs( sleepTime ); // sleep a fair amount b/c of error continue; } } }
void Balancer::run() { Client::initThread("Balancer"); // This is the body of a BackgroundJob so if we throw here we're basically ending the balancer // thread prematurely. while (!inShutdown()) { auto txn = cc().makeOperationContext(); if (!_init(txn.get())) { log() << "will retry to initialize balancer in one minute"; sleepsecs(60); continue; } break; } Seconds balanceRoundInterval(kBalanceRoundDefaultInterval); while (!inShutdown()) { auto txn = cc().makeOperationContext(); BalanceRoundDetails roundDetails; try { // ping has to be first so we keep things in the config server in sync _ping(txn.get()); MONGO_FAIL_POINT_BLOCK(balancerRoundIntervalSetting, scopedBalancerRoundInterval) { const BSONObj& data = scopedBalancerRoundInterval.getData(); balanceRoundInterval = Seconds(data["sleepSecs"].numberInt()); } BSONObj balancerResult; // use fresh shard state grid.shardRegistry()->reload(txn.get()); // refresh chunk size (even though another balancer might be active) Chunk::refreshChunkSize(txn.get()); auto balSettingsResult = grid.catalogManager(txn.get())->getGlobalSettings( txn.get(), SettingsType::BalancerDocKey); const bool isBalSettingsAbsent = balSettingsResult.getStatus() == ErrorCodes::NoMatchingDocument; if (!balSettingsResult.isOK() && !isBalSettingsAbsent) { warning() << balSettingsResult.getStatus(); return; } const SettingsType& balancerConfig = isBalSettingsAbsent ? SettingsType{} : balSettingsResult.getValue(); // now make sure we should even be running if ((!isBalSettingsAbsent && !Chunk::shouldBalance(balancerConfig)) || MONGO_FAIL_POINT(skipBalanceRound)) { LOG(1) << "skipping balancing round because balancing is disabled"; // Ping again so scripts can determine if we're active without waiting _ping(txn.get(), true); sleepFor(balanceRoundInterval); continue; } uassert(13258, "oids broken after resetting!", _checkOIDs(txn.get())); { auto scopedDistLock = grid.catalogManager(txn.get()) ->distLock(txn.get(), "balancer", "doing balance round", DistLockManager::kSingleLockAttemptTimeout); if (!scopedDistLock.isOK()) { LOG(1) << "skipping balancing round" << causedBy(scopedDistLock.getStatus()); // Ping again so scripts can determine if we're active without waiting _ping(txn.get(), true); sleepFor(balanceRoundInterval); // no need to wake up soon continue; } const bool waitForDelete = (balancerConfig.isWaitForDeleteSet() ? balancerConfig.getWaitForDelete() : false); MigrationSecondaryThrottleOptions secondaryThrottle( MigrationSecondaryThrottleOptions::create( MigrationSecondaryThrottleOptions::kDefault)); if (balancerConfig.isKeySet()) { secondaryThrottle = uassertStatusOK(MigrationSecondaryThrottleOptions::createFromBalancerConfig( balancerConfig.toBSON())); } LOG(1) << "*** start balancing round. " << "waitForDelete: " << waitForDelete << ", secondaryThrottle: " << secondaryThrottle.toBSON(); const auto candidateChunks = uassertStatusOK(_getCandidateChunks(txn.get())); if (candidateChunks.empty()) { LOG(1) << "no need to move any chunk"; _balancedLastTime = 0; } else { _balancedLastTime = _moveChunks(txn.get(), candidateChunks, secondaryThrottle, waitForDelete); roundDetails.setSucceeded(static_cast<int>(candidateChunks.size()), _balancedLastTime); grid.catalogManager(txn.get()) ->logAction(txn.get(), "balancer.round", "", roundDetails.toBSON()); } LOG(1) << "*** End of balancing round"; } // Ping again so scripts can determine if we're active without waiting _ping(txn.get(), true); sleepFor(_balancedLastTime ? kShortBalanceRoundInterval : balanceRoundInterval); } catch (const std::exception& e) { log() << "caught exception while doing balance: " << e.what(); // Just to match the opening statement if in log level 1 LOG(1) << "*** End of balancing round"; // This round failed, tell the world! roundDetails.setFailed(e.what()); grid.catalogManager(txn.get()) ->logAction(txn.get(), "balancer.round", "", roundDetails.toBSON()); // Sleep a fair amount before retrying because of the error sleepFor(balanceRoundInterval); } } }
void Balancer::run() { // this is the body of a BackgroundJob so if we throw here we're basically ending the balancer thread prematurely while ( ! inShutdown() ) { if ( ! _init() ) { log() << "will retry to initialize balancer in one minute" << endl; sleepsecs( 60 ); continue; } break; } // getConnectioString and dist lock constructor does not throw, which is what we expect on while // on the balancer thread ConnectionString config = configServer.getConnectionString(); DistributedLock balanceLock( config , "balancer" ); while ( ! inShutdown() ) { try { ScopedDbConnection conn( config ); // ping has to be first so we keep things in the config server in sync _ping( conn.conn() ); // now make sure we should even be running if ( ! grid.shouldBalance() ) { LOG(1) << "skipping balancing round because balancing is disabled" << endl; conn.done(); sleepsecs( 30 ); continue; } uassert( 13258 , "oids broken after resetting!" , _checkOIDs() ); // use fresh shard state Shard::reloadShardInfo(); { dist_lock_try lk( &balanceLock , "doing balance round" ); if ( ! lk.got() ) { LOG(1) << "skipping balancing round because another balancer is active" << endl; conn.done(); sleepsecs( 30 ); // no need to wake up soon continue; } LOG(1) << "*** start balancing round" << endl; vector<CandidateChunkPtr> candidateChunks; _doBalanceRound( conn.conn() , &candidateChunks ); if ( candidateChunks.size() == 0 ) { LOG(1) << "no need to move any chunk" << endl; } else { _balancedLastTime = _moveChunks( &candidateChunks ); } LOG(1) << "*** end of balancing round" << endl; } conn.done(); sleepsecs( _balancedLastTime ? 5 : 10 ); } catch ( std::exception& e ) { log() << "caught exception while doing balance: " << e.what() << endl; // Just to match the opening statement if in log level 1 LOG(1) << "*** End of balancing round" << endl; sleepsecs( 30 ); // sleep a fair amount b/c of error continue; } } }
debug void main() { longword host, timer, new_rcvd; longword tot_timeout, itts, send_timeout; word i; word sequence_mode, is_new_line; word debug_on; static unsigned char tempbuffer[255]; sent=received=tot_delays=last_rcvd=0L; tot_timeout=itts=send_timeout=0L; sequence_mode=debug_on=0; is_new_line=1; // Start network and wait for interface to come up (or error exit). sock_init_or_exit(1); name=PINGWHO; itts=10; if (!(host = resolve( name ))) { printf("Unable to resolve '%s'\n", name ); exit( 3 ); } if ( isaddr( name )) printf("Pinging [%s]",inet_ntoa(tempbuffer, host)); else printf("Pinging '%s' [%s]",name, inet_ntoa(tempbuffer, host)); if (itts) printf(" %u times", itts); else itts = sequence_mode ? 0xffffffffL : 1; if (sequence_mode) printf(" once per_second"); printf("\n"); if (!_arp_resolve( host, (eth_address *)tempbuffer, 0 )) { /* resolve it before timer starts */ printf("Could not resolve hardware address\n"); exit(2); } tot_timeout = _SET_TIMEOUT((itts + 2)*1000L); if ( debug_on ) printf("ETH -> %02x:%02x:%02x:%02x:%02x:%02x\n", (int)tempbuffer[0],(int)tempbuffer[1],(int)tempbuffer[2],(int)tempbuffer[3], (int)tempbuffer[4],(int)tempbuffer[5]); send_timeout = _SET_TIMEOUT(0); do { /* once per second - do all this */ if ( chk_timeout( send_timeout )) { send_timeout = _SET_TIMEOUT(1000L); if (chk_timeout( tot_timeout )) { stats(); break; } if ( sent < itts ) { sent++; if (_ping( host , sent )) stats(); if (!is_new_line) printf("\n"); printf("sent PING # %lu ", sent ); is_new_line = 0; } } if ( kbhit() ) { getchar(); /* trash the character */ stats(); } tcp_tick(NULL); if ((timer = _chk_ping( host , &new_rcvd)) != 0xffffffffL) { tot_delays += timer; ++received; if ( new_rcvd != last_rcvd + 1 ) { if (!is_new_line) printf("\n"); printf("PING receipt received out of order!\n"); is_new_line = 1; } last_rcvd = new_rcvd; if (!is_new_line) printf(", "); printf("PING receipt # %lu : response time %lu ms\n", received, timer); is_new_line = 1; if ( received == itts ) stats(); } } while (1); }
main() { longword seq,ping_who,tmp_seq,time_out; char buffer[100]; auto wifi_region region_info; auto char index[10]; auto int option; auto char tmpbuf[64]; auto int updateRegion; auto int country; auto int configured; brdInit(); //initialize board for this demo seq=0; sock_init(); // Initial wifi interface // Make sure wifi IF is down to do ifconfig's functions printf("\nBringing interface down (disassociate)...\n"); ifdown(IF_WIFI0); while (ifpending(IF_WIFI0) != IF_DOWN) { printf("."); tcp_tick(NULL); } printf("...Done.\n"); configured = FALSE; updateRegion = FALSE; do { country = get_stored_region(®ion_info); // Check if the region has been previously set. if(country < 0 || updateRegion) { // Populate structure with region info, then display ifconfig (IF_WIFI0, IFG_WIFI_REGION_INFO, ®ion_info, IFS_END); printf("\nCurrent region setting:\n"); display_info(®ion_info); // Select Region and write value to userblock country = wifi_config_region(®ion_info); updateRegion = FALSE; } else { // Set Region from previously saved value read from the userblock, this // will set the runtime limits to be used by the wifi driver. ifconfig (IF_WIFI0, IFS_WIFI_REGION, country, IFG_WIFI_REGION_INFO, ®ion_info, IFS_END); printf("\nRuntime region setting now being used by wifi driver:\n"); display_info(®ion_info); // Region has already been set at runtime, check if it needs to // be changed due to country to country roaming. printf("\nRegion already set, select option to continue"); printf("\n1. Continue."); printf("\n2. Select new region."); printf("\nSelect > "); do { option = atoi(gets(tmpbuf)); } while (!((option >= 1) && (option <= 2))); if(option == 2) updateRegion = TRUE; else configured = TRUE; } }while(!configured); // If you are not going to use the defaulted channel and/or power level, // then you can use the following functions to set channel and/or the // power level. This needs to be done after setting the region/country // to meet wifi driver requirements. //ifconfig (IF_WIFI0, IFS_WIFI_CHANNEL, 0, IFS_END); // Scan all channels //ifconfig (IF_WIFI0, IFS_WIFI_TX_POWER, 8, IFS_END); // Set to Pwr level 8 // Startup the wireless interface here... printf("Bringing interface back up (associate)...\n"); ifup(IF_WIFI0); while (ifpending(IF_WIFI0) == IF_COMING_UP) { tcp_tick(NULL); } printf("...Done.\n"); if (ifpending(IF_WIFI0) != IF_UP) { printf("Unfortunately, it failed to associate :-(\n"); exit(1); } // End of regional setting section, from this point on do standard tcp/ip // protocol. /* // Here is where we gather the statistics... // Note that if you get a compile error here, it is because you are not running // this sample on a Wifi-equipped board. /* Print who we are... */ printf( "My IP address is %s\n\n", inet_ntoa(buffer, gethostid()) ); /* * Get the binary ip address for the target of our * pinging. */ #ifdef PING_WHO /* Ping a specific IP addr: */ ping_who=resolve(PING_WHO); if(ping_who==0) { printf("ERROR: unable to resolve %s\n",PING_WHO); exit(2); } #else /* Examine our configuration, and ping the default router: */ tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END ); if( tmp_seq != 0 ) { printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq ); exit(2); } if(ping_who==0) { printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n"); exit(2); } #endif for(;;) { /* * It is important to call tcp_tick here because * ping packets will not get processed otherwise. * */ tcp_tick(NULL); /* * Send one ping every PING_DELAY ms. */ costate { waitfor(DelayMs(PING_DELAY)); _ping(ping_who,seq++); pingoutled(LEDON); // flash transmit LED waitfor(DelayMs(50)); pingoutled(LEDOFF); } /* * Has a ping come in? time_out!=0xfffffff->yes. */ costate { time_out=_chk_ping(ping_who,&tmp_seq); if(time_out!=0xffffffff) { #ifdef VERBOSE printf("received ping: %ld\n", tmp_seq); #endif pinginled(LEDON); // flash receive LED waitfor(DelayMs(50)); pinginled(LEDOFF); } } } }
main() { longword seq,ping_who,tmp_seq,time_out; char buffer[100]; brdInit(); //initialize board for this demo seq=0; sock_init(); // Initialize wifi interface // Make sure wifi IF is down to do ifconfig's functions printf("\nBringing interface down (disassociate)...\n"); ifdown(IF_WIFI0); while (ifpending(IF_WIFI0) != IF_DOWN) { printf("."); tcp_tick(NULL); } printf("...Done.\n"); // Enable 802.11d country information capability // Note: Access Point must have 802.11d enabled with proper country selected ifconfig(IF_WIFI0, IFS_WIFI_MULTI_DOMAIN, 1, IFS_END); // Startup the wireless interface here... printf("Bringing interface back up (associate)...\n"); ifup(IF_WIFI0); while (ifpending(IF_WIFI0) == IF_COMING_UP) { tcp_tick(NULL); } printf("...Done.\n"); if (ifpending(IF_WIFI0) != IF_UP) { printf("Unfortunately, it failed to associate :-(\n"); exit(1); } // End of regional setting section, from this point on do standard tcp/ip // protocol. /* // Here is where we gather the statistics... // Note that if you get a compile error here, it is because you are not running // this sample on a Wifi-equipped board. /* Print who we are... */ printf( "My IP address is %s\n\n", inet_ntoa(buffer, gethostid()) ); /* * Get the binary ip address for the target of our * pinging. */ #ifdef PING_WHO /* Ping a specific IP addr: */ ping_who=resolve(PING_WHO); if(ping_who==0) { printf("ERROR: unable to resolve %s\n",PING_WHO); exit(2); } #else /* Examine our configuration, and ping the default router: */ tmp_seq = ifconfig( IF_ANY, IFG_ROUTER_DEFAULT, & ping_who, IFS_END ); if( tmp_seq != 0 ) { printf( "ERROR: ifconfig() failed --> %d\n", (int) tmp_seq ); exit(2); } if(ping_who==0) { printf("ERROR: unable to resolve IFG_ROUTER_DEFAULT\n"); exit(2); } #endif for(;;) { /* * It is important to call tcp_tick here because * ping packets will not get processed otherwise. * */ tcp_tick(NULL); /* * Send one ping every PING_DELAY ms. */ costate { waitfor(DelayMs(PING_DELAY)); pingoutled(LEDON); // flash transmit LED waitfor(DelayMs(50)); pingoutled(LEDOFF); _ping(ping_who,seq++); } /* * Has a ping come in? time_out!=0xfffffff->yes. */ costate { time_out=_chk_ping(ping_who,&tmp_seq); if(time_out!=0xffffffff) { #ifdef VERBOSE printf("received ping: %ld\n", tmp_seq); #endif pinginled(LEDON); // flash receive LED waitfor(DelayMs(50)); pinginled(LEDOFF); #if RCM5600W_SERIES waitfor(DelayMs(250)); pinginled(LEDON); // flash receive LED again waitfor(DelayMs(50)); pinginled(LEDOFF); #endif } } } }