0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · 강의

네트워크 분할 처리

시스템 무결성을 유지하면서 분산 Erlang 클러스터의 네트워크 분할과 병합을 원활하게 처리하는 전략을 살펴봅니다.

네트워크 분할 처리은(는) CoddyKit의 무료 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Understanding Network Partitions

In distributed systems, a network partition happens when parts of the system can no longer communicate with each other due to network failures. Think of it like a bridge collapsing, splitting a city into disconnected districts.

This can lead to a "split-brain" scenario, where different parts of your Erlang cluster believe they are the only active ones. This often results in data inconsistency and service disruption.

Erlang Node Connectivity

Erlang nodes communicate by forming a distributed system. They connect to each other using a process called net_kernel. When a node starts, it tries to find and connect to other known nodes.

  • Use -sname for short names (local network).
  • Use -name for full names (across networks).
  • All nodes must share the same magic cookie for security.

Here's a simple module. Compile it and run MyNode.get_name(). in the Erlang shell after starting with erl -sname mynode:

-module(my_node).
-export([get_name/0]).

get_name() ->
    node().

Monitoring Node Status

Erlang provides built-in mechanisms to detect when a node disconnects. The monitor_node/2 function allows a process to receive messages when the status of another node changes (e.g., up or down).

This is crucial for reacting to unexpected node failures or network issues. Let's see how a process can monitor another node:

-module(node_monitor).
-export([start/1]).

start(OtherNode) ->
    Pid = spawn(fun() -> init(OtherNode) end),
    {ok, Pid}.

init(OtherNode) ->
    io:format("~p monitoring ~p~n", [self(), OtherNode]),
    erlang:monitor_node(OtherNode, true),
    receive
        {nodeup, Node} ->
            io:format("Node ~p is UP~n", [Node]);
        {nodedown, Node} ->
            io:format("Node ~p is DOWN!~n", [Node])
    end,
    io:format("Monitor process ~p exiting.~n", [self()]).

Beyond Simple Disconnection

While monitor_node is powerful, it primarily tells you if a TCP connection to a node has dropped. This might not always mean a full "partition".

Short network blips or a slow network can cause temporary disconnections, leading to false positives. A true partition implies a sustained inability to communicate between groups of nodes.

  • Network lag can delay detection.
  • Brief outages might not warrant full system reaction.
  • Application-level health checks are often needed.

Quorum and Majority Wins

To avoid "split-brain" in a network partition, distributed systems often use quorum. A quorum is the minimum number of nodes that must agree on an operation (or simply be reachable) for it to be considered valid.

The "majority wins" strategy is a common quorum approach:

  • Only the partition containing more than half of the total nodes is allowed to continue operations.
  • Other partitions (minority) should halt or become read-only.

This prevents conflicting updates and ensures data consistency.

Tracking Active Membership

To implement "majority wins," each node needs to know the total cluster size and which nodes are currently reachable. This creates a "membership oracle".

While a full implementation is complex, we can simulate a basic reachability check by having each node periodically "ping" its known peers. If a node can reach a majority of its peers, it considers itself "active".

Here's a conceptual module for a node to ping others:

-module(ping_checker).
-export([start/2, ping_peers/1]).

start(KnownPeers, Interval) ->
    Pid = spawn(fun() -> init(KnownPeers, Interval) end),
    {ok, Pid}.

init(KnownPeers, Interval) ->
    ping_peers(KnownPeers),
    timer:sleep(Interval),
    init(KnownPeers, Interval).

ping_peers(Peers) ->
    io:format("~p: Pinging peers: ~p~n", [node(), Peers]),
    ActivePeers = lists:filter(fun(Peer) ->
        case net_adm:ping(Peer) of
            pong -> true;
            pang -> false
        end
    end, Peers),
    io:format("~p: Reachable peers: ~p~n", [node(), ActivePeers]),
    TotalNodes = length(Peers) + 1, % Include self
    ReachableCount = length(ActivePeers) + 1,
    if
        ReachableCount > TotalNodes / 2 ->
            io:format("~p: I am in the MAJORITY partition!~n", [node()]);
        true ->
            io:format("~p: I am in the MINORITY partition or isolated.~n", [node()])
    end.

Fencing for Safety

When a network partition occurs and a minority partition is identified, it's crucial to prevent it from causing harm (e.g., writing conflicting data). This process is called fencing.

Fencing ensures that only the "winning" (majority) partition can continue to operate and modify shared state. Common fencing actions include:

  • Shutting down services in the minority partition.
  • Disabling write operations.
  • Isolating resources (e.g., database access).

The goal is to prevent "split-brain" from corrupting data.

Reconciling Divergent States

After a network partition heals and nodes reconnect, their states might have diverged. This is because the active partition continued operations while the isolated ones were inactive or performing different actions.

Data reconciliation is the process of resolving these conflicts and bringing all nodes back to a consistent state. Common strategies include:

  • Last Write Wins (LWW): The most recent update (based on timestamp) is chosen.
  • Conflict Resolution Functions: Application-specific logic to merge data.

Designing for eventual consistency is key.

Partition Strategy Check

Consider a 5-node Erlang cluster. A network partition occurs, splitting it into two groups: Node A, B (Group 1) and Node C, D, E (Group 2). Which of the following statements about handling this partition are generally TRUE to maintain data integrity and availability?

Recap: Resilient Partitions

We've explored how to handle network partitions, a critical aspect of building resilient distributed Erlang applications. Key takeaways include:

  • Detection: Beyond simple disconnections, using application-level health checks.
  • Quorum: Employing strategies like "majority wins" to ensure only one active partition.
  • Fencing: Preventing minority partitions from causing data inconsistencies.
  • Reconciliation: Strategies for merging divergent states when partitions heal.

These principles help your Erlang systems remain available and consistent even in the face of network instability.

자주 묻는 질문

“네트워크 분할 처리” 강의는 무료인가요?

네 — “네트워크 분할 처리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.

“네트워크 분할 처리”에서 뭘 배우나요?

시스템 무결성을 유지하면서 분산 Erlang 클러스터의 네트워크 분할과 병합을 원활하게 처리하는 전략을 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Erlang OTP: Distributed & Fault-Tolerant Systems Programming을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Erlang OTP: Distributed & Fault-Tolerant Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“네트워크 분할 처리” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Erlang OTP: Distributed & Fault-Tolerant Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 네트워크 분할 처리
  2. ETS 및 Mnesia를 활용한 분산 데이터
  3. 확장성 및 복원력을 위한 설계
  4. 노드 간 부하 분산과 장애 조치
← Erlang OTP: Distributed & Fault-Tolerant Systems Programming(으)로 돌아가기