dispatch_running(false),
asok_hook(NULL),
osd_compat(get_osd_compat_set()),
- state(STATE_INITIALIZING), epoch_lock(), boot_epoch(0), up_epoch(0), bind_epoch(0),
+ state_lock(), state(STATE_INITIALIZING),
+ epoch_lock(), boot_epoch(0), up_epoch(0), bind_epoch(0),
op_tp(cct, "OSD::op_tp", cct->_conf->osd_op_threads, "osd_op_threads"),
recovery_tp(cct, "OSD::recovery_tp", cct->_conf->osd_recovery_threads, "osd_recovery_threads"),
disk_tp(cct, "OSD::disk_tp", cct->_conf->osd_disk_threads, "osd_disk_threads"),
f->dump_stream("cluster_fsid") << superblock.cluster_fsid;
f->dump_stream("osd_fsid") << superblock.osd_fsid;
f->dump_unsigned("whoami", superblock.whoami);
- f->dump_string("state", get_state_name(state));
+ f->dump_string("state", get_state_name(get_state()));
f->dump_unsigned("oldest_map", superblock.oldest_map);
f->dump_unsigned("newest_map", superblock.newest_map);
{
peering_wq.drain();
dout(0) << "done with init, starting boot process" << dendl;
- state = STATE_BOOTING;
+ set_state(STATE_BOOTING);
start_boot();
return 0;
}
derr << "shutdown" << dendl;
- heartbeat_lock.Lock();
- state = STATE_STOPPING;
- heartbeat_lock.Unlock();
+ set_state(STATE_STOPPING);
// Debugging
cct->_conf->set_val("debug_osd", "100");
if (is_waiting_for_healthy()) {
if (_is_healthy()) {
dout(1) << "healthy again, booting" << dendl;
- state = STATE_BOOTING;
+ set_state(STATE_BOOTING);
start_boot();
}
}
void OSD::start_waiting_for_healthy()
{
dout(1) << "start_waiting_for_healthy" << dendl;
- state = STATE_WAITING_FOR_HEALTHY;
+ set_state(STATE_WAITING_FOR_HEALTHY);
last_heartbeat_resample = utime_t();
}
if (is_booting()) {
dout(1) << "state: booting -> active" << dendl;
- state = STATE_ACTIVE;
+ set_state(STATE_ACTIVE);
// set incarnation so that osd_reqid_t's we generate for our
// objecter requests are unique across restarts.
bool do_shutdown = false;
bool do_restart = false;
if (osdmap->get_epoch() > 0 &&
- state == STATE_ACTIVE) {
+ is_active()) {
if (!osdmap->exists(whoami)) {
dout(0) << "map says i do not exist. shutting down." << dendl;
do_shutdown = true; // don't call shutdown() while we have everything paused
}
private:
+ Spinlock state_lock; // protects access to state
int state;
Spinlock epoch_lock; // protects access to boot_epoch, up_epoch, bind_epoch
epoch_t boot_epoch; // _first_ epoch we were marked up (after this process started)
epoch_t bind_epoch; // epoch we last did a bind to new ip:ports
public:
- bool is_initializing() { return state == STATE_INITIALIZING; }
- bool is_booting() { return state == STATE_BOOTING; }
- bool is_active() { return state == STATE_ACTIVE; }
- bool is_stopping() { return state == STATE_STOPPING; }
- bool is_waiting_for_healthy() { return state == STATE_WAITING_FOR_HEALTHY; }
+ int get_state() { Spinlock::Locker l(state_lock); return state; }
+ void set_state(int s) { Spinlock::Locker l(state_lock); state = s; }
+ bool is_initializing() {
+ Spinlock::Locker l(state_lock);
+ return state == STATE_INITIALIZING;
+ }
+ bool is_booting() {
+ Spinlock::Locker l(state_lock);
+ return state == STATE_BOOTING;
+ }
+ bool is_active() {
+ Spinlock::Locker l(state_lock);
+ return state == STATE_ACTIVE;
+ }
+ bool is_stopping() {
+ Spinlock::Locker l(state_lock);
+ return state == STATE_STOPPING;
+ }
+ bool is_waiting_for_healthy() {
+ Spinlock::Locker l(state_lock);
+ return state == STATE_WAITING_FOR_HEALTHY;
+ }
private: