From 9f959fc6ed50cc2e6398dfd2ac8b066638ba3e56 Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Mon, 9 May 2016 16:45:09 +0200 Subject: [PATCH 1/3] Add command to configure number of shards. Changed aws deployment script to automatically set the number of shards. Created tests --- bigchaindb/commands/bigchain.py | 14 ++++++++++++++ deploy-cluster-aws/awsdeploy.sh | 1 + deploy-cluster-aws/fabfile.py | 6 ++++++ docs/source/bigchaindb-cli.md | 7 +++++++ tests/test_commands.py | 22 +++++++++++++++++++++- 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/bigchaindb/commands/bigchain.py b/bigchaindb/commands/bigchain.py index b37a3812..e6b4314d 100644 --- a/bigchaindb/commands/bigchain.py +++ b/bigchaindb/commands/bigchain.py @@ -13,6 +13,7 @@ import builtins import logstats +import rethinkdb as r import bigchaindb import bigchaindb.config_utils @@ -203,6 +204,12 @@ def run_load(args): workers.start() +def run_sharding(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) + + def main(): parser = argparse.ArgumentParser( description='Control your BigchainDB node.', @@ -243,6 +250,13 @@ def main(): subparsers.add_parser('start', help='Start BigchainDB') + # parser for configuring the number of shards + sharding_parser = subparsers.add_parser('sharding', + help='Configure number of shards') + + sharding_parser.add_argument('num_shards', metavar='num_shards', type=int, default=1, + help='Number of shards') + load_parser = subparsers.add_parser('load', help='Write transactions to the backlog') diff --git a/deploy-cluster-aws/awsdeploy.sh b/deploy-cluster-aws/awsdeploy.sh index 3ce621d9..b68b0a5e 100755 --- a/deploy-cluster-aws/awsdeploy.sh +++ b/deploy-cluster-aws/awsdeploy.sh @@ -131,6 +131,7 @@ if [ "$WHAT_TO_DEPLOY" == "servers" ]; then # this will only be sent to one of the nodes, see the # definition of init_bigchaindb() in fabfile.py to see why. fab init_bigchaindb + fab configure_sharding:$NUM_NODES else # Deploying clients # The only thing to configure on clients is the api_endpoint diff --git a/deploy-cluster-aws/fabfile.py b/deploy-cluster-aws/fabfile.py index 1d481111..581a1c1b 100644 --- a/deploy-cluster-aws/fabfile.py +++ b/deploy-cluster-aws/fabfile.py @@ -166,6 +166,12 @@ def init_bigchaindb(): run('bigchaindb init', pty=False) +@task +@hosts(public_dns_names[0]) +def configure_sharding(num_shards): + run('bigchaindb sharding {}'.format(num_shards)) + + # Start BigchainDB using screen @task @parallel diff --git a/docs/source/bigchaindb-cli.md b/docs/source/bigchaindb-cli.md index 229d5b4c..43f8dbb0 100644 --- a/docs/source/bigchaindb-cli.md +++ b/docs/source/bigchaindb-cli.md @@ -43,3 +43,10 @@ This command is used to run benchmarking tests. You can learn more about it usin ```text $ bigchaindb load -h ``` + +### bigchaindb sharding + +This command is used to configure the number of shards in the underlying datastore, for example: +```text +$ bigchaindb sharding 3 +``` \ No newline at end of file diff --git a/tests/test_commands.py b/tests/test_commands.py index 99a4f466..f90bc503 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,11 +1,12 @@ import json from unittest.mock import Mock, patch from argparse import Namespace -from pprint import pprint import copy import pytest +from tests.db.conftest import setup_database + @pytest.fixture def mock_run_configure(monkeypatch): @@ -225,3 +226,22 @@ def test_start_rethinkdb_exits_when_cannot_start(mock_popen): with pytest.raises(exceptions.StartupError): utils.start_rethinkdb() + +def test_configure_sharding(b): + import rethinkdb as r + from bigchaindb.commands.bigchain import run_sharding + + # change number of shards + args = Namespace(num_shards=3) + run_sharding(args) + + # retrieve table configuration + table_config = list(r.db('rethinkdb') + .table('table_config') + .filter(r.row['db'] == b.dbname) + .run(b.conn)) + + # check shard configuration + for table in table_config: + if table['name'] in ['backlog', 'bigchain']: + assert len(table['shards']) == 3 From f09dacdd118596cf3cbe36394a647e66459a81c0 Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Mon, 9 May 2016 17:31:02 +0200 Subject: [PATCH 2/3] renamed sharding to set-shards --- bigchaindb/commands/bigchain.py | 4 ++-- tests/test_commands.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bigchaindb/commands/bigchain.py b/bigchaindb/commands/bigchain.py index e6b4314d..28831642 100644 --- a/bigchaindb/commands/bigchain.py +++ b/bigchaindb/commands/bigchain.py @@ -204,7 +204,7 @@ def run_load(args): workers.start() -def run_sharding(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) @@ -251,7 +251,7 @@ def main(): help='Start BigchainDB') # parser for configuring the number of shards - sharding_parser = subparsers.add_parser('sharding', + 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, diff --git a/tests/test_commands.py b/tests/test_commands.py index f90bc503..4b35edbb 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -229,11 +229,11 @@ def test_start_rethinkdb_exits_when_cannot_start(mock_popen): def test_configure_sharding(b): import rethinkdb as r - from bigchaindb.commands.bigchain import run_sharding + from bigchaindb.commands.bigchain import run_set_shards # change number of shards args = Namespace(num_shards=3) - run_sharding(args) + run_set_shards(args) # retrieve table configuration table_config = list(r.db('rethinkdb') From e21282818262974a9224183d9ecf607452467736 Mon Sep 17 00:00:00 2001 From: troymc Date: Mon, 9 May 2016 18:13:20 +0200 Subject: [PATCH 3/3] Updated awsdeploy, fabfile, docs, test for bigchaindb set-shards --- deploy-cluster-aws/awsdeploy.sh | 2 +- deploy-cluster-aws/fabfile.py | 5 +++-- docs/source/bigchaindb-cli.md | 6 +++--- tests/test_commands.py | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/deploy-cluster-aws/awsdeploy.sh b/deploy-cluster-aws/awsdeploy.sh index b68b0a5e..6290d01e 100755 --- a/deploy-cluster-aws/awsdeploy.sh +++ b/deploy-cluster-aws/awsdeploy.sh @@ -131,7 +131,7 @@ if [ "$WHAT_TO_DEPLOY" == "servers" ]; then # this will only be sent to one of the nodes, see the # definition of init_bigchaindb() in fabfile.py to see why. fab init_bigchaindb - fab configure_sharding:$NUM_NODES + fab set_shards:$NUM_NODES else # Deploying clients # The only thing to configure on clients is the api_endpoint diff --git a/deploy-cluster-aws/fabfile.py b/deploy-cluster-aws/fabfile.py index 581a1c1b..9e4a1d47 100644 --- a/deploy-cluster-aws/fabfile.py +++ b/deploy-cluster-aws/fabfile.py @@ -166,10 +166,11 @@ def init_bigchaindb(): run('bigchaindb init', pty=False) +# Set the number of shards (in the backlog and bigchain tables) @task @hosts(public_dns_names[0]) -def configure_sharding(num_shards): - run('bigchaindb sharding {}'.format(num_shards)) +def set_shards(num_shards): + run('bigchaindb set-shards {}'.format(num_shards)) # Start BigchainDB using screen diff --git a/docs/source/bigchaindb-cli.md b/docs/source/bigchaindb-cli.md index 43f8dbb0..ad9fd5a0 100644 --- a/docs/source/bigchaindb-cli.md +++ b/docs/source/bigchaindb-cli.md @@ -44,9 +44,9 @@ This command is used to run benchmarking tests. You can learn more about it usin $ bigchaindb load -h ``` -### bigchaindb sharding +### bigchaindb set-shards -This command is used to configure the number of shards in the underlying datastore, for example: +This command is used to set the number of shards in the underlying datastore. For example, the following command will set the number of shards to four: ```text -$ bigchaindb sharding 3 +$ bigchaindb set-shards 4 ``` \ No newline at end of file diff --git a/tests/test_commands.py b/tests/test_commands.py index 4b35edbb..12c1350e 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -227,11 +227,11 @@ def test_start_rethinkdb_exits_when_cannot_start(mock_popen): utils.start_rethinkdb() -def test_configure_sharding(b): +def test_set_shards(b): import rethinkdb as r from bigchaindb.commands.bigchain import run_set_shards - # change number of shards + # set the number of shards args = Namespace(num_shards=3) run_set_shards(args) @@ -241,7 +241,7 @@ def test_configure_sharding(b): .filter(r.row['db'] == b.dbname) .run(b.conn)) - # check shard configuration + # check that the number of shards got set to the correct value for table in table_config: if table['name'] in ['backlog', 'bigchain']: assert len(table['shards']) == 3