Ejemplo n.º 1
0
int on_connected_to_head()
{
    if (g_auto_update_flag)
    {
        // 强制检查一下更新
        if (check_update())
        {
            restart_node();
        }
    }

    DEBUG_LOG("reg NODE to HEAD, node[%u: %s], server tag: %s", g_node_id, g_node_ip_str, g_server_tag);

    head_p_node_register_in in;
    in.node_version = HEAD_VERSION;
    in.node_id = g_node_id;
    STRNCPY(in.server_tag, g_server_tag, SERVER_TAG_LEN);
    in.node_ip = g_node_ip;

    uint32_t cmd = head_p_node_register_cmd;
    head_proto_t head;
    init_head_proto_header(&head, sizeof(head_proto_t), 0, cmd, 0, g_node_id);

    return g_head->send(&head, &in);
}
Ejemplo n.º 2
0
int monitor_node_ip(void * owner, void * data)
{
    ADD_TIMER_EVENT(&g_node_event, monitor_node_ip, reinterpret_cast< void *>(1), get_now_tv()->tv_sec + MONITOR_NODE_IP_INTERVAL);

    if (data)
    {
        if (0 == get_node_ip())
        {
            // ip变了,直接重启node
            restart_node();
        }

    }

    return 0;
}
Ejemplo n.º 3
0
void ReadRestartFile::execute()
{
  Handle<mesh::Mesh> mesh = options().value< Handle<mesh::Mesh> >("mesh");
  if(is_null(mesh))
    throw common::SetupError(FromHere(), "Option mesh is not configured");

  Handle<Time> time = options().value< Handle<Time> >(solver::Tags::time());
  if(is_null(time))
    throw common::SetupError(FromHere(), "Time component not configured");
  
  const common::URI filepath = options().value<common::URI>("file");
  boost::shared_ptr<common::XML::XmlNode> input_file = common::XML::parse_file(filepath);

  common::XML::XmlNode restart_node(input_file->content->first_node("restart"));
  if(!restart_node.is_valid())
    throw common::FileFormatError(FromHere(), "File  " + filepath.path() + " has no restart node");
  
  if(options().value<bool>("read_time_step"))
  {
    time->options().set("time_step", common::from_str<Real>(restart_node.attribute_value("time_step")));
    time->options().set("current_time", common::from_str<Real>(restart_node.attribute_value("current_time")));
    time->options().set("iteration", common::from_str<Uint>(restart_node.attribute_value("iteration")));
  }

  if(common::from_str<Uint>(restart_node.attribute_value("version")) != 1)
    throw common::FileFormatError(FromHere(), "File  " + filepath.path() + " has unsupported version");

  common::PE::Comm& comm = common::PE::Comm::instance();
  if(common::from_str<Uint>(restart_node.attribute_value("nb_procs")) != comm.size())
    throw common::SetupError(FromHere(), "File  " + filepath.path() + " was made for " + restart_node.attribute_value("nb_procs") + " CPUs, but we are loading on " + common::to_str(comm.size()) + " CPUs");

  boost::shared_ptr<common::BinaryDataReader> data_reader = common::allocate_component<common::BinaryDataReader>("DataReader");
  data_reader->options().set("file", common::URI(restart_node.attribute_value("binary_file")));

  common::XML::XmlNode field_node = restart_node.content->first_node("field");
  for(; field_node.is_valid(); field_node.content = field_node.content->next_sibling("field"))
  {
    Handle<mesh::Field> field(mesh->access_component(common::URI(field_node.attribute_value("path"), common::URI::Scheme::CPATH)));
    if(is_null(field))
      throw common::SetupError(FromHere(), "Field " + field_node.attribute_value("path") + " was not found in mesh " + mesh->uri().path());

    data_reader->read_table(*field, common::from_str<Uint>(field_node.attribute_value("index")));
  }
}