Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / high_availability / config.py: 94%
18 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-12-05 05:12 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-12-05 05:12 +0800
1# Copyright 2026 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15"""User-facing switch and optional rank-zero Controller endpoint."""
17from dataclasses import dataclass, field
18from typing import Optional
21@dataclass(frozen=True)
22class WorkerRecoveryConfig:
23 """Enable replica recovery with a rank-zero or TaskD-hosted Controller.
25 Args:
26 enable: Enable process recovery; disabled by default.
27 controller_ip: Rank zero's reachable address; omit to use TaskD.
28 controller_port: Rank-zero listening port; defaults to 8000 when an IP is supplied.
29 mirror_metadata: Mirror rank-specific state each step. Disable only when replica
30 RNG, data state, buffers and extra state are interchangeable.
31 """
33 enable: bool = False
34 controller_ip: str = ""
35 controller_port: Optional[int] = None
36 mirror_metadata: bool = True
38 def __post_init__(self) -> None:
39 """Distinguish omitted endpoints from explicitly hosted Controllers."""
40 if self.controller_ip and self.controller_port is None:
41 object.__setattr__(self, "controller_port", 8000)
42 if self.controller_port is not None and not self.controller_ip:
43 raise ValueError("controller_port requires controller_ip; omit both to use TaskD")
44 if self.controller_port is not None and not 0 < self.controller_port < 65536:
45 raise ValueError("controller_port must be between 1 and 65535")
48@dataclass(frozen=True)
49class HighAvailabilityConfig:
50 """Group independently enabled high availability features."""
52 worker_recovery: WorkerRecoveryConfig = field(default_factory=WorkerRecoveryConfig)