Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:4paradigm OpenMLDB Cluster Ops Commands

From Leeroopedia
Knowledge Sources
Domains Cluster_Operations, DevOps
Last Updated 2026-10-12 12:00 GMT

Overview

Command-level cluster operations implemented as Python functions for data recovery, scaling, rolling upgrades, and operation status monitoring.

Description

The Cluster_Ops_Commands module (tools/openmldb_ops.py) provides high-level cluster management functions that orchestrate multiple Executor calls to perform complex operations. Each function follows a safe pattern: disable auto-failover, assess cluster state, execute the operation, verify completion, and re-enable auto-failover. The functions handle internal databases (__INTERNAL_DB, __PRE_AGG_DB, INFORMATION_SCHEMA) alongside user databases.

Usage

Use these commands via the openmldb_ops.py CLI tool for routine cluster maintenance. Each command accepts --openmldb_bin_path, --zk_cluster, --zk_root_path, and --cmd to select the operation. Operation-specific flags like --endpoints and --statfile control behavior.

Code Reference

Source Location

  • Repository: OpenMLDB
  • File: tools/openmldb_ops.py

Signature

# Data recovery
def RecoverData(executor: Executor) -> None
def RecoverTable(executor: Executor, db: str, table_name: str) -> Status
def RecoverPartition(executor: Executor, db: str, replicas: list, endpoint_status: dict, storage: str) -> Status
def CheckTable(executor: Executor, db: str, table_name: str) -> Status

# Scaling
def ScaleOut(executor: Executor) -> None
def ScaleIn(executor: Executor, endpoints: list) -> None
def ScaleInEndpoint(executor: Executor, endpoint: str, desc_endpoints: list) -> Status
def BalanceInDatabase(executor: Executor, endpoints: list, db: str) -> Status

# Partition operations
def ChangeLeader(db: str, partition: Partition, src_endpoint: str, desc_endpoint: str, one_replica: bool, restore: bool = True) -> Status
def MigratePartition(db: str, partition: Partition, src_endpoint: str, desc_endpoint: str, one_replica: bool) -> Status

# Rolling upgrade
def PreUpgrade(executor: Executor, endpoint: str, statfile: str, allow_single_replica: bool) -> Status
def PostUpgrade(executor: Executor, endpoint: str, statfile: str) -> Status

# Status queries
def GetOpStatus(executor: Executor, db: str = None, filter: str = None, wait_done: bool = False) -> (Status, list)
def ShowTableStatus(executor: Executor, pattern: str = '%') -> (Status, list)

# Main CLI entry
def main()  # L617-687

CLI Usage

python openmldb_ops.py \
    --openmldb_bin_path=<path> \
    --zk_cluster=<zk> \
    --zk_root_path=<path> \
    --cmd=<command> \
    [--endpoints=<list>] \
    [--statfile=<path>] \
    [--allow_single_replica] \
    [--db=<name>] \
    [--filter=<status>]

Import

from openmldb_ops import (
    RecoverData, ScaleOut, ScaleIn,
    PreUpgrade, PostUpgrade,
    GetOpStatus, ShowTableStatus, CheckTable
)

I/O Contract

Inputs

Name Type Required Description
executor Executor Yes Connected Executor instance
endpoints list[str] For ScaleIn Tablet endpoints to remove
endpoint str For PreUpgrade/PostUpgrade Target tablet endpoint
statfile str For PreUpgrade/PostUpgrade State file path (default: .stat)
allow_single_replica bool For PreUpgrade Allow single-replica unavailability
db str For GetOpStatus Database name (None for all)
filter str For GetOpStatus Filter by op status
wait_done bool For GetOpStatus Block until all ops complete

Outputs

Name Type Description
Status Status Success/failure of the operation
Cluster state changes cluster Modified partition/replica distribution, state file for upgrade coordination
Op status list list Operation records with op_id, op_type, status, etc.

Usage Examples

Recover All Data

from tool import Executor
from openmldb_ops import RecoverData

executor = Executor("/work/openmldb/bin/openmldb", "127.0.0.1:6181", "/onebox")
executor.Connect()

# Disable auto-failover, recover all tables, re-enable
executor.SetAutofailover("false")
RecoverData(executor)
executor.SetAutofailover("true")

Scale Out (Add New Tablet)

# CLI: balance partitions across all healthy tablets
python tools/openmldb_ops.py \
    --openmldb_bin_path=/work/openmldb/bin/openmldb \
    --zk_cluster=127.0.0.1:6181 \
    --zk_root_path=/onebox \
    --cmd=scaleout

Rolling Upgrade

# 1. Pre-upgrade: migrate leaders away from the target tablet
python tools/openmldb_ops.py \
    --openmldb_bin_path=/work/openmldb/bin/openmldb \
    --zk_cluster=127.0.0.1:6181 \
    --zk_root_path=/onebox \
    --cmd=pre-upgrade \
    --endpoints=127.0.0.1:9520 \
    --statfile=/tmp/upgrade.stat

# 2. Stop the tablet, upgrade the binary, restart it

# 3. Post-upgrade: restore leaders to the upgraded tablet
python tools/openmldb_ops.py \
    --openmldb_bin_path=/work/openmldb/bin/openmldb \
    --zk_cluster=127.0.0.1:6181 \
    --zk_root_path=/onebox \
    --cmd=post-upgrade \
    --endpoints=127.0.0.1:9520 \
    --statfile=/tmp/upgrade.stat

Check Operation Status

# Show all pending operations across all databases
python tools/openmldb_ops.py \
    --openmldb_bin_path=/work/openmldb/bin/openmldb \
    --zk_cluster=127.0.0.1:6181 \
    --zk_root_path=/onebox \
    --cmd=showopstatus

# Show table status with pattern filter
python tools/openmldb_ops.py \
    --openmldb_bin_path=/work/openmldb/bin/openmldb \
    --zk_cluster=127.0.0.1:6181 \
    --zk_root_path=/onebox \
    --cmd=showtablestatus \
    --filter=taxi%

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment