⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ft_replicationmanagerfaultanalyzer.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  PortableGroup::ObjectGroup_ptr iogr,
  const PortableGroup::Location & location,
  int & object_is_primary)
{

  // To determine if this was a primary that faulted:
  // Get the TagFTGroupTaggedComponent from the IOGR and search
  // for the primary, using the TAO_FT_IOGR_Property helper class.
  // Then, compare the TypeId and Location of the failed object with
  // those of the primary.  If they match, it was a primary fault.

  int result = 0;
  object_is_primary = 0;

  ACE_TRY_NEW_ENV
  {
    // Create an "empty" TAO_FT_IOGR_Property and use it to get the
    // tagged component.
    TAO_FT_IOGR_Property temp_ft_prop;
    FT::TagFTGroupTaggedComponent ft_group_tagged_component;
    CORBA::Boolean got_tagged_component =
      temp_ft_prop.get_tagged_component (
          iogr, ft_group_tagged_component ACE_ENV_ARG_PARAMETER);
    ACE_TRY_CHECK;
    if (got_tagged_component)
    {
      // Create a new TAO_FT_IOGR_Property with the tagged
      // component.
      TAO_FT_IOGR_Property ft_prop (ft_group_tagged_component);

      // Check to see if a primary is set.
      CORBA::Boolean primary_is_set = ft_prop.is_primary_set (
        iogr ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      if (primary_is_set)
      {
        // Get the primary object.
        CORBA::Object_var primary_obj = ft_prop.get_primary (
          iogr ACE_ENV_ARG_PARAMETER);
        ACE_TRY_CHECK;
        if (CORBA::is_nil (primary_obj.in()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
            ACE_TEXT (
              "TAO::FT_ReplicationManagerFaultAnalyzer::is_primary_member: "
              "Could not get primary IOR from IOGR.\n")),
            -1);
        }

        // Get the object reference of the failed member.
        CORBA::Object_var failed_obj =
          this->replication_manager_->get_member_ref (
            iogr, location ACE_ENV_ARG_PARAMETER);
        ACE_TRY_CHECK;
        if (CORBA::is_nil (failed_obj.in()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
            ACE_TEXT (
              "TAO::FT_ReplicationManagerFaultAnalyzer::is_primary_member: "
              "Could not get IOR of failed member from IOGR.\n")),
            -1);
        }

        // Are the two object refs (primary and failed) equivalent?
        CORBA::Boolean equiv = primary_obj->_is_equivalent (
          failed_obj.in() ACE_ENV_ARG_PARAMETER);
        ACE_TRY_CHECK;
        if (equiv)
        {
          object_is_primary = 1;
          result = 0;
        }
      }
      else  // primary is not set
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::is_primary_member: "
            "Primary is not set on IOGR.\n")
        ));
        result = -1;
      }
    }
    else // could not get tagged component
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_ReplicationManagerFaultAnalyzer::is_primary_member: "
          "Could not get tagged component from IOGR.\n")
      ));
      result = -1;
    }
  }
  ACE_CATCHANY
  {
    ACE_PRINT_EXCEPTION (
      ACE_ANY_EXCEPTION,
      ACE_TEXT (
        "TAO::FT_ReplicationManagerFaultAnalyzer::is_primary_member: ")
    );
    result = -1;
  }
  ACE_ENDTRY;

  return result;
}

// Handle a single replica failure.
int TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure (
  TAO::FT_FaultEventDescriptor & fault_event_desc)
{
  int result = 0;
  PortableGroup::ObjectGroup_var the_object_group = PortableGroup::ObjectGroup::_nil();
  PortableGroup::Properties_var properties;

  ACE_TRY_NEW_ENV
  {
    // Get the object group reference based on the ObjectGroupId.
    the_object_group =
      this->replication_manager_->get_object_group_ref_from_id (
        fault_event_desc.object_group_id
        ACE_ENV_ARG_PARAMETER);
    ACE_TRY_CHECK;

    // This should not happen, but let us be safe.
    if (CORBA::is_nil (the_object_group.in()))
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
          "Could not get ObjectGroup reference from ObjectGroupId: <%Q>.\n"),
          fault_event_desc.object_group_id
      ));
      ACE_TRY_THROW (PortableGroup::ObjectGroupNotFound ());
    }

    // Get the properties associated with this ObjectGroup.
    properties = this->replication_manager_->get_properties (
      the_object_group.in()
      ACE_ENV_ARG_PARAMETER);
    ACE_TRY_CHECK;
  }
  ACE_CATCHANY
  {
    ACE_PRINT_EXCEPTION (
      ACE_ANY_EXCEPTION,
      ACE_TEXT (
        "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: ")
    );
    result = -1;
  }
  ACE_ENDTRY;

  if (result == 0)
  {
    // Get the MembershipStyle property.
    PortableGroup::MembershipStyleValue membership_style;
    result = this->get_membership_style (properties.in(), membership_style);
    if (result != 0)
    {
      //@@ it seems a shame to fail here.  We should at least remove the failed replica from the group.
      ACE_ERROR_RETURN ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
          "Could not extract MembershipStyle from properties on "
          "ObjectGroup with id <%Q>.\n"),
        fault_event_desc.object_group_id),
        -1);
    }
    else
    {
      fault_event_desc.membership_style = membership_style;
      if (TAO_debug_level > 6)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "MembershipStyleValue = <%d>"),
            fault_event_desc.membership_style
        ));
      }
    }

    // Get the ReplicationStyle property.
    FT::ReplicationStyleValue replication_style;
    result = this->get_replication_style (properties.in(), replication_style);
    if (result != 0)
    {
      //@@ it seems a shame to fail here.  We should at least remove the failed replica from the group.
      ACE_ERROR_RETURN ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
          "Could not extract ReplicationStyle from properties on "
          "ObjectGroup with id <%Q>.\n"),
        fault_event_desc.object_group_id),
        -1);
    }
    else
    {
      fault_event_desc.replication_style = replication_style;
      if (TAO_debug_level > 6)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "ReplicationStyleValue = <%d>"),
            fault_event_desc.replication_style
        ));
      }
    }

    // Get the MinimumNumberMembers property.
    PortableGroup::MinimumNumberMembersValue minimum_number_members;
    result = this->get_minimum_number_members (
      properties.in(), minimum_number_members);
    if (result != 0)
    {
      // This is not a fatal error.  It may be App Controlled.
      result = 0;
      if (TAO_debug_level > 3)
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "Could not extract MinimumNumberMembers from properties on "
            "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id));
      }
    }
    else
    {
      fault_event_desc.minimum_number_members = minimum_number_members;
      if (TAO_debug_level > 6)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "MinimumNumberMembers = <%d>"),
            fault_event_desc.minimum_number_members
        ));
      }
    }

    // Get the InitialNumberMembers property.
    PortableGroup::InitialNumberMembersValue initial_number_members;
    result = this->get_initial_number_members (
      properties.in(), initial_number_members);
    if (result != 0)
    {
      // This is not a fatal error.  It may be App Controlled.
      result = 0;
      if (TAO_debug_level > 3)
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "Could not extract InitialNumberMembers from properties on "
            "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id));
      }
    }
    else
    {
      fault_event_desc.initial_number_members = initial_number_members;
      if (TAO_debug_level > 6)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "InitialNumberMembers = <%d>"),
            fault_event_desc.initial_number_members
        ));
      }
    }

    // Get the Factories property.
    result = this->get_factories (
      properties.in(),
      fault_event_desc.factories.out());
    if (result != 0)
    {
      // This is not a fatal error.  It may be App Controlled.
      result = 0;
      if (TAO_debug_level > 3)
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "Could not extract Factories from properties on "
            "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id));
       }
    }
    else
    {
      if (TAO_debug_level > 6)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "Got Factories from properties on "
            "ObjectGroup with id <%Q>.\n"),
            fault_event_desc.object_group_id
        ));
      }
    }

  }

  // If the ReplicationStyle is COLD_PASSIVE, WARM_PASSIVE, or
  // SEMI_ACTIVE, we can see if it was the primary replica that
  // failed.
  if ((result == 0) &&
      (fault_event_desc.replication_style == FT::COLD_PASSIVE ||
       fault_event_desc.replication_style == FT::WARM_PASSIVE ||
       fault_event_desc.replication_style == FT::SEMI_ACTIVE))
  {
    if (TAO_debug_level > 6)
    {
      ACE_DEBUG ((LM_DEBUG,
        ACE_TEXT (
          "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
          "Checking to see if failed replica was the primary for "
          "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id
      ));
    }
    result = this->is_primary_member (
      the_object_group.in(),
      fault_event_desc.location.in(),
      fault_event_desc.object_is_primary);
  }

  // If the MembershipStyle is FT::MEMB_INF_CTRL (infrastructure
  // controlled) and the primary has faulted, establish a new primary.
  // We get back a new object group.
  if ((result == 0) &&
      (fault_event_desc.membership_style == FT::MEMB_INF_CTRL))
  {

    PortableGroup::ObjectGroup_var new_object_group;
    result = this->remove_failed_member (
        the_object_group.in(),
        fault_event_desc,
        new_object_group.out());
    if (result == 0)
    {
      the_object_group = new_object_group;
    }

    if (fault_event_desc.object_is_primary == 1)
    {
      if (TAO_debug_level > 6)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "TAO::FT_ReplicationManagerFaultAnalyzer::single_replica_failure: "
            "Setting new primary for "
            "ObjectGroup with id <%Q>.\n"),
            fault_event_desc.object_group_id
        ));
      }
      result = this->set_new_primary (
        the_object_group.in(),
        fault_event_desc,
        new_object_group.out());
      if (result == 0)
      {
        the_object_group = new_object_group;
      }
    }
  }

#if 0 // According to the FT CORBA specification, this will be handled by the ObjectGroupManager::remove_member method
  // If the MembershipStyle is FT::MEMB_INF_CTRL (infrastructure
  // controlled) and the number of remaining members is less than
  // the MinimumNumberMembers property, add new members.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -