WIP: added bigchaindb set-replicas cmd w/ non-working test

This commit is contained in:
troymc 2016-06-16 14:44:57 +02:00
parent 4431815ab1
commit cc6129103f
3 changed files with 48 additions and 4 deletions

View File

@ -207,8 +207,20 @@ def run_load(args):
def run_set_shards(args):
b = bigchaindb.Bigchain()
r.table('bigchain').reconfigure(shards=args.num_shards, replicas=1).run(b.conn)
r.table('backlog').reconfigure(shards=args.num_shards, replicas=1).run(b.conn)
for table in ['bigchain', 'backlog']:
# See https://www.rethinkdb.com/api/python/config/
table_config = r.table(table).config().run(b.conn)
num_replicas = len(table_config['shards'][0]['replicas'])
r.table(table).reconfigure(shards=args.num_shards, replicas=num_replicas).run(b.conn)
def run_set_replicas(args):
b = bigchaindb.Bigchain()
for table in ['bigchain', 'backlog']:
# See https://www.rethinkdb.com/api/python/config/
table_config = r.table(table).config().run(b.conn)
num_shards = len(table_config['shards'])
r.table(table).reconfigure(shards=num_shards, replicas=args.num_replicas).run(b.conn)
def main():
@ -255,9 +267,18 @@ def main():
sharding_parser = subparsers.add_parser('set-shards',
help='Configure number of shards')
sharding_parser.add_argument('num_shards', metavar='num_shards', type=int, default=1,
sharding_parser.add_argument('num_shards', metavar='num_shards',
type=int, default=1,
help='Number of shards')
# parser for configuring the number of replicas
replicas_parser = subparsers.add_parser('set-replicas',
help='Configure number of replicas')
replicas_parser.add_argument('num_replicas', metavar='num_replicas',
type=int, default=1,
help='Number of replicas (i.e. the replication factor)')
load_parser = subparsers.add_parser('load',
help='Write transactions to the backlog')

View File

@ -50,3 +50,10 @@ This command is used to set the number of shards in the underlying datastore. Fo
```text
$ bigchaindb set-shards 4
```
### bigchaindb set-replicas
This command is used to set the number of replicas (of each shard) in the underlying datastore. For example, the following command will set the number of replicas to three (i.e. it will set the replication factor to three):
```text
$ bigchaindb set-replicas 3
```

View File

@ -245,3 +245,19 @@ def test_set_shards(b):
for table in table_config:
if table['name'] in ['backlog', 'bigchain']:
assert len(table['shards']) == 3
def test_set_replicas(b):
import rethindb as r
from bigchaindb.commands.bigchain import run_set_replicas
# set the number of replicas
args = Namespace(num_replicas=2)
run_set_replicas(args)
# check that the replication factor got set to 2 in all tables
for table in ['backlog', 'bigchain']:
# See https://www.rethinkdb.com/api/python/config/
table_config = r.table(table).config().run(b.conn)
num_replicas = len(table_config['shards'][0]['replicas'])
assert num_replicas == 2