美文网首页
一种状态机转换写法

一种状态机转换写法

作者: 你不懂的1234 | 来源:发表于2018-09-21 16:13 被阅读0次

    kudu中tablet replica的状态机为:

    // NOT_INITIALIZED -> INITIALIZED -> BOOTSTRAPPING -> RUNNING -> STOPPING -> STOPPED -> SHUTDOWN
    //             |              |                |                  ^ ^ ^
    //             |              |                |                  | | |
    //             |              |                +------------------+ | |
    //             |              +-------------------------------------+ |
    //             +------------------------------------------------------+
    

    代码如下:

    void TabletReplica::set_state(TabletStatePB new_state) {
      switch (new_state) {
        case NOT_INITIALIZED:
          LOG(FATAL) << "Cannot transition to NOT_INITIALIZED state";
          return;
        case INITIALIZED:
          CHECK_EQ(NOT_INITIALIZED, state_);
          break;
        case BOOTSTRAPPING:
          CHECK_EQ(INITIALIZED, state_);
          break;
        case RUNNING:
          CHECK_EQ(BOOTSTRAPPING, state_);
          break;
        case STOPPING:
          CHECK_NE(STOPPED, state_);
          CHECK_NE(SHUTDOWN, state_);
          break;
        case STOPPED:
          CHECK_EQ(STOPPING, state_);
          break;
        case SHUTDOWN: FALLTHROUGH_INTENDED;
        case FAILED:
          CHECK_EQ(STOPPED, state_) << TabletStatePB_Name(state_);
          break;
        default:
          break;
      }
      state_ = new_state;
    }
    

    相关文章

      网友评论

          本文标题:一种状态机转换写法

          本文链接:https://www.haomeiwen.com/subject/tffznftx.html