Page MenuHomePhabricator
Paste P95724

etcd-mirror replica index update script (assumes old-replica has converged to new-replica's state)
ActivePublic

Authored by Scott_French on Jul 30 2026, 1:17 AM.
import argparse
import etcd
from wmflib.interactive import ask_confirmation
def set_mirror_index(
old_replica: tuple[str, int],
new_replica: tuple[str, int],
prefix: str,
protocol: str,
):
old_client = etcd.Client(
host=old_replica[0], port=old_replica[1], protocol=protocol
)
replica_index = old_client.read("/").etcd_index
replica_key = f"/__replication/{prefix.lstrip('/')}"
ask_confirmation(f"Set {replica_key} to {replica_index} on {new_replica[0]}?")
new_client = etcd.Client(
host=new_replica[0], port=new_replica[1], protocol=protocol
)
new_client.write(replica_key, replica_index)
def hostport(hp: str) -> tuple[str, int]:
h, p = hp.split(":")
return h, int(p)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--protocol", default="https")
parser.add_argument("--old-replica", required=True, type=hostport)
parser.add_argument("--new-replica", required=True, type=hostport)
parser.add_argument("--prefix", required=True)
args = parser.parse_args()
set_mirror_index(args.old_replica, args.new_replica, args.prefix, args.protocol)
if __name__ == "__main__":
main()

Event Timeline

Scott_French changed the title of this paste from etcd-mirror replica index update script (assumes converged) to etcd-mirror replica index update script (assumes old-replica has converged to new-replica's state).
Scott_French updated the paste's language from autodetect to python.Jul 30 2026, 1:27 AM
Scott_French edited the content of this paste. (Show Details)