diff options
author | Mike Wallace <mikewallace@apache.org> | 2014-11-26 23:17:04 +0000 |
---|---|---|
committer | Mike Wallace <mikewallace@apache.org> | 2014-12-03 19:11:09 +0000 |
commit | 49f03e2be48dac56c27b220b11cd70676df50f99 (patch) | |
tree | 6b37d8f8aed1f5df01bac2f769f8d6561ac3e50a | |
parent | 126ec7682020ad3c08966e4aef03ce02e9b14f7f (diff) | |
download | couchdb-49f03e2be48dac56c27b220b11cd70676df50f99.tar.gz |
Teach dev/run to clear nodes DB
This commit makes dev/run replace the nodes DB with an empty DB
before adding the nodes doc. This changes the previous behaviour
which was to just try adding the docs and ignore conflicts.
The change makes it possible for a developer to run `dev/run -n 1`
(to spawn a single node cluster) having previously run `dev/run`
(which spawns a three node cluster). Without replacing the nodes
DB the `dev/run -n 1` single-node cluster would still have two
other nodes in the nodes DB and therefore not work correctly.
Note that we explicitly delete each node doc rather than deleting
the whole database because the cluster membership layer gets upset
when the nodes database itself is deleted/recreated.
-rwxr-xr-x | dev/run | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -17,6 +17,7 @@ import contextlib import functools import glob import inspect +import json import optparse import os import re @@ -230,6 +231,7 @@ def hashify(pwd, salt=COMMON_SALT, iterations=10, keylen=20): def startup(ctx): atexit.register(kill_processes, ctx) boot_nodes(ctx) + reset_nodes_db(ctx, "127.0.0.1") join_nodes(ctx, "127.0.0.1", 15986) @@ -295,6 +297,27 @@ def boot_node(ctx, node): return sp.Popen(cmd, stdin=sp.PIPE, stdout=log, stderr=sp.STDOUT, env=env) +@log('Reset nodes DB') +def reset_nodes_db(ctx, host): + _, port = get_ports(1) + conn = httpclient.HTTPConnection(host, port) + conn.request('GET', '/nodes/_all_docs') + resp = conn.getresponse() + if not resp.status == 200: + print('Could not read nodes DB documents', resp.reason) + exit(1) + nodes = json.loads(resp.read())['rows'] + for node in nodes: + node_id = node['id'] + rev = node['value']['rev'] + conn = httpclient.HTTPConnection(host, port) + conn.request('DELETE', '/nodes/{0}?rev={1}'.format(node_id, rev)) + resp = conn.getresponse() + if not resp.status == 200: + print('Failed to reset nodes DB', resp.reason) + exit(1) + + @log('Join nodes into cluster') def join_nodes(ctx, host, port): for node in ctx['nodes']: |