void DataAggregatorActor::handleTruncateResponse(const idgs::actor::ActorMessagePtr& msg) {
  DVLOG_FIRST_N(2, 20) << "aggregator handle truncate store response";
  idgs::store::pb::TruncateResponse* response = dynamic_cast<idgs::store::pb::TruncateResponse*>(msg->getPayload().get());

  if (response->result_code() != idgs::store::pb::SRC_SUCCESS) {
    LOG(ERROR)<< "Truncate store error at member " << msg->getSourceMemberId();
    resultCode = response->result_code();
  }

  ++ responseCount;
  DVLOG_FIRST_N(2, 20) << "member " << msg->getSourceMemberId() << " response, left " << requestCount - responseCount << " members.";
  if (requestCount == responseCount) {
    DVLOG_FIRST_N(2, 20) << "all member responsed, send response to client.";

    shared_ptr<idgs::store::pb::TruncateResponse> globalResponse = make_shared<idgs::store::pb::TruncateResponse>();
    globalResponse->set_result_code(resultCode);
    sendResponse(OP_TRUNCATE_RESPONSE, globalResponse);

    terminate();
  }
}
void MigrationVerifyActor::handleVerifyResponse(const idgs::actor::ActorMessagePtr& msg) {
  auto response = dynamic_cast<pb::MigrationVerifyResponse*>(msg->getPayload().get());
  memberData.insert(std::pair<int32_t, pb::MemberMigrationData>(msg->getSourceMemberId(), response->member_data(0)));

  if (memberData.size() == memberSize) {
    auto payload = std::make_shared<pb::MigrationVerifyResponse>();
    payload->set_result_code(static_cast<int32_t>(RC_SUCCESS));
    auto it = memberData.begin();
    for (; it != memberData.end(); ++ it) {
      payload->add_member_data()->CopyFrom(it->second);
    }

    auto respMsg = clientMsg->createResponse();
    respMsg->setOperationName("VERIFY_RESPONSE");
    respMsg->setPayload(payload);

    idgs::actor::sendMessage(respMsg);

    memberData.clear();
    memberSize = 0;
  }
}
void DataAggregatorActor::handleCountResponse(const idgs::actor::ActorMessagePtr& msg) {
  DVLOG_FIRST_N(2, 20) << "receive store size of member " << msg->getSourceActorId();
  idgs::store::pb::SizeResponse* response = dynamic_cast<idgs::store::pb::SizeResponse*>(msg->getPayload().get());

  if (response->result_code() != idgs::store::pb::SRC_SUCCESS) {
    // error
    DVLOG_FIRST_N(2, 20) << "error at member " << msg->getSourceActorId();
    resultCode = response->result_code();
  }

  // collect response from all members and calculate size and then response to client.
  shared_ptr<idgs::store::pb::SizeResponse> globalResponse = make_shared<idgs::store::pb::SizeResponse>();
  dataSizeMap[msg->getSourceMemberId()] = response->size();
  if (dataSizeMap.size() == requestCount) {
    DVLOG_FIRST_N(2, 20) << "aggregate done.";
    if (resultCode != idgs::store::pb::SRC_SUCCESS) {
      globalResponse->set_result_code(resultCode);
    } else {
      // calculate size
      size_t size = 0;
      map<int32_t, size_t>::iterator it = dataSizeMap.begin();
      for (; it != dataSizeMap.end(); ++ it) {
        size += (* it).second;
      }

      globalResponse->set_result_code(idgs::store::pb::SRC_SUCCESS);
      globalResponse->set_size(size);
    }

    // response result
    DVLOG_FIRST_N(2, 20) << "response client.";
    sendResponse(OP_COUNT_RESPONSE, globalResponse);

    terminate();
  }
}