def text_search(conn, search, *, language='english', case_sensitive=False, diacritic_sensitive=False, text_score=False, limit=0, table=None): """Return all the assets that match the text search. The results are sorted by text score. For more information about the behavior of text search on MongoDB see https://docs.mongodb.com/manual/reference/operator/query/text/#behavior Args: search (str): Text search string to query the text index language (str, optional): The language for the search and the rules for stemmer and tokenizer. If the language is ``None`` text search uses simple tokenization and no stemming. case_sensitive (bool, optional): Enable or disable case sensitive search. diacritic_sensitive (bool, optional): Enable or disable case sensitive diacritic search. text_score (bool, optional): If ``True`` returns the text score with each document. limit (int, optional): Limit the number of returned documents. Returns: :obj:`list` of :obj:`dict`: a list of assets Raises: OperationError: If the backend does not support text search """ raise OperationError('This query is only supported when running ' 'BigchainDB with MongoDB as the backend.')
def remove_replicas(connection, replicas): """Remove a set of replicas from the replicaset Args: connection (:class:`~bigchaindb.backend.connection.Connection`): A connection to the database. replicas (:obj:`list` of :obj:`str`): replica addresses in the form "hostname:port". Raises: OperationError: If the reconfiguration fails due to a MongoDB :exc:`OperationFailure` """ # get the current configuration conf = connection.conn.admin.command('replSetGetConfig') # remove the nodes from the members list in the replica set conf['config']['members'] = list( filter(lambda member: member['host'] not in replicas, conf['config']['members'])) # increase the configuration version number conf['config']['version'] += 1 # apply new configuration try: connection.conn.admin.command('replSetReconfig', conf['config']) except OperationFailure as exc: raise OperationError(exc.details['errmsg'])
def text_search_object(conn, search, text_score=False, limit=0): """Return all the assets that match the text search. The results are sorted by text score. For more information about the behavior of text search on MongoDB see https://docs.mongodb.com/manual/reference/operator/query/text/#behavior Args: search (str): Text search string to query the text index text_score (bool, optional): If ``True`` returns the text score with each document. limit (int, optional): Limit the number of returned documents. Returns: :obj:`list` of :obj:`dict`: a list of assets Raises: OperationError: If the backend does not support text search """ raise OperationError('This query is only supported when running ' 'BigchainDB with MongoDB as the backend.')
def add_replicas(connection, replicas): """Add a set of replicas to the replicaset Args: connection (:class:`~bigchaindb.backend.connection.Connection`): A connection to the database. replicas (:obj:`list` of :obj:`str`): replica addresses in the form "hostname:port". Raises: OperationError: If the reconfiguration fails due to a MongoDB :exc:`OperationFailure` """ # get current configuration conf = connection.conn.admin.command('replSetGetConfig') # MongoDB does not automatically add an id for the members so we need # to choose one that does not exist yet. The safest way is to use # incrementing ids, so we first check what is the highest id already in # the set and continue from there. cur_id = max([member['_id'] for member in conf['config']['members']]) # add the nodes to the members list of the replica set for replica in replicas: cur_id += 1 conf['config']['members'].append({'_id': cur_id, 'host': replica}) # increase the configuration version number # when reconfiguring, mongodb expects a version number higher than the one # it currently has conf['config']['version'] += 1 # apply new configuration try: connection.conn.admin.command('replSetReconfig', conf['config']) except OperationFailure as exc: raise OperationError(exc.details['errmsg'])
def reconfigure(connection, *, table, shards, replicas, primary_replica_tag=None, dry_run=False, nonvoting_replica_tags=None): """Reconfigures the given table. Args: connection (:class:`~bigchaindb.backend.connection.Connection`): A connection to the database. table (str): The name of the table to reconfigure. shards (int): The number of shards, an integer from 1-64. replicas (:obj:`int` | :obj:`dict`): * If replicas is an integer, it specifies the number of replicas per shard. Specifying more replicas than there are servers will return an error. * If replicas is a dictionary, it specifies key-value pairs of server tags and the number of replicas to assign to those servers:: {'africa': 2, 'asia': 4, 'europe': 2, ...} primary_replica_tag (str): The primary server specified by its server tag. Required if ``replicas`` is a dictionary. The tag must be in the ``replicas`` dictionary. This must not be specified if ``replicas`` is an integer. Defaults to ``None``. dry_run (bool): If ``True`` the generated configuration will not be applied to the table, only returned. Defaults to ``False``. nonvoting_replica_tags (:obj:`list` of :obj:`str`): Replicas with these server tags will be added to the ``nonvoting_replicas`` list of the resulting configuration. Defaults to ``None``. Returns: dict: A dictionary with possibly three keys: * ``reconfigured``: the number of tables reconfigured. This will be ``0`` if ``dry_run`` is ``True``. * ``config_changes``: a list of new and old table configuration values. * ``status_changes``: a list of new and old table status values. For more information please consult RethinkDB's documentation `ReQL command: reconfigure <https://rethinkdb.com/api/python/reconfigure/>`_. Raises: OperationError: If the reconfiguration fails due to a RethinkDB :exc:`ReqlOpFailedError` or :exc:`ReqlQueryLogicError`. """ params = { 'shards': shards, 'replicas': replicas, 'dry_run': dry_run, } if primary_replica_tag: params.update( primary_replica_tag=primary_replica_tag, nonvoting_replica_tags=nonvoting_replica_tags, ) try: return connection.run(r.table(table).reconfigure(**params)) except (r.ReqlOpFailedError, r.ReqlQueryLogicError) as e: raise OperationError('Failed to reconfigure tables.') from e
def kv_search(conn, key, value, limit=0, table='assets'): raise OperationError('This query is only supported when running ' 'BigchainDB with MongoDB as the backend.')