示例#1
0
 def fin():
     get_conn().repl()
     try:
         r.db(db_name).table('bigchain').delete().run()
         r.db(db_name).table('backlog').delete().run()
     except r.ReqlOpFailedError as e:
         if e.message != 'Database `{}` does not exist.'.format(db_name):
             raise
示例#2
0
 def fin():
     get_conn().repl()
     try:
         r.db(db_name).table('bigchain').delete().run()
         r.db(db_name).table('backlog').delete().run()
     except r.ReqlOpFailedError as e:
         if e.message != 'Database `{}` does not exist.'.format(db_name):
             raise
示例#3
0
    def fin():
        print('Deleting `{}` database'.format(db_name))
        get_conn().repl()
        try:
            r.db_drop(db_name).run()
        except r.ReqlOpFailedError as e:
            if e.message != 'Database `{}` does not exist.'.format(db_name):
                raise

        print('Finished deleting `{}`'.format(db_name))
示例#4
0
    def fin():
        print('Deleting `{}` database'.format(db_name))
        get_conn().repl()
        try:
            r.db_drop(db_name).run()
        except r.ReqlOpFailedError as e:
            if e.message != 'Database `{}` does not exist.'.format(db_name):
                raise

        print('Finished deleting `{}`'.format(db_name))
示例#5
0
def run_set_replicas(args):
    for table in ['bigchain', 'backlog', 'votes']:
        # See https://www.rethinkdb.com/api/python/config/
        table_config = r.table(table).config().run(db.get_conn())
        num_shards = len(table_config['shards'])
        try:
            r.table(table).reconfigure(shards=num_shards,
                                       replicas=args.num_replicas).run(
                                           db.get_conn())
        except r.ReqlOpFailedError as e:
            logger.warn(e)
示例#6
0
def setup_database(request, node_config):
    print('Initializing test db')
    db_name = node_config['database']['name']
    get_conn().repl()
    try:
        r.db_create(db_name).run()
    except r.ReqlOpFailedError as e:
        if e.message == 'Database `{}` already exists.'.format(db_name):
            r.db_drop(db_name).run()
            r.db_create(db_name).run()
        else:
            raise

    print('Finished initializing test db')

    # setup tables
    r.db(db_name).table_create('bigchain').run()
    r.db(db_name).table_create('backlog').run()
    # create the secondary indexes
    # to order blocks by timestamp
    r.db(db_name).table('bigchain').index_create(
        'block_timestamp', r.row['block']['timestamp']).run()
    # to order blocks by block number
    r.db(db_name).table('bigchain').index_create(
        'block_number', r.row['block']['block_number']).run()
    # to order transactions by timestamp
    r.db(db_name).table('backlog').index_create(
        'transaction_timestamp', r.row['transaction']['timestamp']).run()
    # compound index to read transactions from the backlog per assignee
    r.db(db_name).table('backlog')\
        .index_create('assignee__transaction_timestamp', [r.row['assignee'], r.row['transaction']['timestamp']])\
        .run()

    def fin():
        print('Deleting `{}` database'.format(db_name))
        get_conn().repl()
        try:
            r.db_drop(db_name).run()
        except r.ReqlOpFailedError as e:
            if e.message != 'Database `{}` does not exist.'.format(db_name):
                raise

        print('Finished deleting `{}`'.format(db_name))

    request.addfinalizer(fin)
示例#7
0
def run_set_replicas(args):
    for table in ['bigchain', 'backlog', 'votes']:
        # See https://www.rethinkdb.com/api/python/config/
        table_config = r.table(table).config().run(db.get_conn())
        num_shards = len(table_config['shards'])
        try:
            r.table(table).reconfigure(shards=num_shards, replicas=args.num_replicas).run(db.get_conn())
        except r.ReqlOpFailedError as e:
            logger.warn(e)
示例#8
0
def setup_database(request, node_config):
    print('Initializing test db')
    db_name = node_config['database']['name']
    get_conn().repl()
    try:
        r.db_create(db_name).run()
    except r.ReqlOpFailedError as e:
        if e.message == 'Database `{}` already exists.'.format(db_name):
            r.db_drop(db_name).run()
            r.db_create(db_name).run()
        else:
            raise

    print('Finished initializing test db')

    # setup tables
    r.db(db_name).table_create('bigchain').run()
    r.db(db_name).table_create('backlog').run()
    # create the secondary indexes
    # to order blocks by timestamp
    r.db(db_name).table('bigchain').index_create('block_timestamp', r.row['block']['timestamp']).run()
    # to order blocks by block number
    r.db(db_name).table('bigchain').index_create('block_number', r.row['block']['block_number']).run()
    # to order transactions by timestamp
    r.db(db_name).table('backlog').index_create('transaction_timestamp', r.row['transaction']['timestamp']).run()
    # compound index to read transactions from the backlog per assignee
    r.db(db_name).table('backlog')\
        .index_create('assignee__transaction_timestamp', [r.row['assignee'], r.row['transaction']['timestamp']])\
        .run()

    def fin():
        print('Deleting `{}` database'.format(db_name))
        get_conn().repl()
        try:
            r.db_drop(db_name).run()
        except r.ReqlOpFailedError as e:
            if e.message != 'Database `{}` does not exist.'.format(db_name):
                raise

        print('Finished deleting `{}`'.format(db_name))

    request.addfinalizer(fin)
示例#9
0
def start_rethinkdb():
    """Start RethinkDB as a child process and wait for it to be
    available.

    Args:
        wait_for_db (bool): wait for the database to be ready
        extra_opts (list): a list of extra options to be used when
            starting the db

    Raises:
        ``bigchaindb_common.exceptions.StartupError`` if RethinkDB cannot
        be started.
    """

    proc = subprocess.Popen(['rethinkdb', '--bind', 'all'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            universal_newlines=True)

    dbname = bigchaindb.config['database']['name']
    line = ''

    for line in proc.stdout:
        if line.startswith('Server ready'):

            # FIXME: seems like tables are not ready when the server is ready,
            #        that's why we need to query RethinkDB to know the state
            #        of the database. This code assumes the tables are ready
            #        when the database is ready. This seems a valid assumption.
            try:
                conn = db.get_conn()
                # Before checking if the db is ready, we need to query
                # the server to check if it contains that db
                if r.db_list().contains(dbname).run(conn):
                    r.db(dbname).wait().run(conn)
            except (r.ReqlOpFailedError, r.ReqlDriverError) as exc:
                raise StartupError('Error waiting for the database `{}` '
                                   'to be ready'.format(dbname)) from exc
            return proc

    # We are here when we exhaust the stdout of the process.
    # The last `line` contains info about the error.
    raise StartupError(line)
示例#10
0
def start_rethinkdb():
    """Start RethinkDB as a child process and wait for it to be
    available.

    Raises:
        :class:`~bigchaindb.common.exceptions.StartupError` if
            RethinkDB cannot be started.
    """

    proc = subprocess.Popen(['rethinkdb', '--bind', 'all'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            universal_newlines=True)

    dbname = bigchaindb.config['database']['name']
    line = ''

    for line in proc.stdout:
        if line.startswith('Server ready'):

            # FIXME: seems like tables are not ready when the server is ready,
            #        that's why we need to query RethinkDB to know the state
            #        of the database. This code assumes the tables are ready
            #        when the database is ready. This seems a valid assumption.
            try:
                conn = db.get_conn()
                # Before checking if the db is ready, we need to query
                # the server to check if it contains that db
                if r.db_list().contains(dbname).run(conn):
                    r.db(dbname).wait().run(conn)
            except (r.ReqlOpFailedError, r.ReqlDriverError) as exc:
                raise StartupError('Error waiting for the database `{}` '
                                   'to be ready'.format(dbname)) from exc
            return proc

    # We are here when we exhaust the stdout of the process.
    # The last `line` contains info about the error.
    raise StartupError(line)
示例#11
0
 def fin():
     get_conn().repl()
     r.db('bigchain_test').table('bigchain').delete().run()
     r.db('bigchain_test').table('backlog').delete().run()
示例#12
0
 def fin():
     print('Deleting `bigchain_test` database')
     get_conn().repl()
     r.db_drop('bigchain_test').run()
     print('Finished deleting `bigchain_test`')
示例#13
0
 def fin():
     get_conn().repl()
     r.db('bigchain_test').table('bigchain').delete().run()
     r.db('bigchain_test').table('backlog').delete().run()
示例#14
0
 def fin():
     print('Deleting `bigchain_test` database')
     get_conn().repl()
     r.db_drop('bigchain_test').run()
     print('Finished deleting `bigchain_test`')