diff --git a/bigchaindb/backend/mongodb/changefeed.py b/bigchaindb/backend/mongodb/changefeed.py index 311ecbfe..34650df3 100644 --- a/bigchaindb/backend/mongodb/changefeed.py +++ b/bigchaindb/backend/mongodb/changefeed.py @@ -39,7 +39,9 @@ class MongoDBChangeFeed(ChangeFeed): self.connection._connect() # namespace to allow us to only listen to changes in a single # collection - namespace = '{}.{}'.format(self.connection.dbname, self.table) + dbname = self.connection.dbname + table = self.table + namespace = '{}.{}'.format(dbname, table) # last timestamp in the oplog. We only care for operations happening # in the future. last_ts = self.connection.conn.local.oplog.rs.find()\ @@ -70,9 +72,13 @@ class MongoDBChangeFeed(ChangeFeed): # on delete it only returns the id of the document self.outqueue.put(record['o']) elif is_update and (self.operation & ChangeFeed.UPDATE): - # not sure what to do here. Lets return the entire - # operation - self.outqueue.put(record) + # the oplog entry for updates only returns the update + # operations to apply to the document and not the + # document itself. So here we first read the document + # and then return it + doc = self.connection.conn[dbname][table]\ + .find_one(record['o2']) + self.outqueue.put(doc) @register_changefeed(MongoDBConnection) diff --git a/bigchaindb/backend/mongodb/query.py b/bigchaindb/backend/mongodb/query.py index bf7b7da7..2e608845 100644 --- a/bigchaindb/backend/mongodb/query.py +++ b/bigchaindb/backend/mongodb/query.py @@ -20,10 +20,15 @@ def write_transaction(conn, signed_transaction): @register_query(MongoDBConnection) def update_transaction(conn, transaction_id, doc): + # with mongodb we need to add update operators to the doc + update_doc = {'$set': { + 'assignee': doc['assignee'], + 'assignment_timestamp': doc['assignment_timestamp'] + }} return conn.db['backlog']\ - .find_one_and_update({'id': transaction_id}, - doc, - return_document=ReturnDocument.AFTER) + .find_one_and_update({'id': transaction_id}, + update_doc, + return_document=ReturnDocument.AFTER) @register_query(MongoDBConnection) diff --git a/bigchaindb/pipelines/block.py b/bigchaindb/pipelines/block.py index d5c81741..7dda6578 100644 --- a/bigchaindb/pipelines/block.py +++ b/bigchaindb/pipelines/block.py @@ -44,6 +44,8 @@ class BlockPipeline: if tx['assignee'] == self.bigchain.me: tx.pop('assignee') tx.pop('assignment_timestamp') + # required for mongodb + tx.pop('_id', None) return tx def validate_tx(self, tx): diff --git a/bigchaindb/pipelines/stale.py b/bigchaindb/pipelines/stale.py index b560f8bb..010bb8e1 100644 --- a/bigchaindb/pipelines/stale.py +++ b/bigchaindb/pipelines/stale.py @@ -48,6 +48,8 @@ class StaleTransactionMonitor: Returns: transaction """ + # NOTE: Maybe this is to verbose? + logger.info('Reassigning transaction with id %s', tx['id']) self.bigchain.reassign_transaction(tx) return tx diff --git a/bigchaindb/pipelines/vote.py b/bigchaindb/pipelines/vote.py index dd138d41..2a9b0ee5 100644 --- a/bigchaindb/pipelines/vote.py +++ b/bigchaindb/pipelines/vote.py @@ -5,10 +5,10 @@ of actions to do on transactions is specified in the ``create_pipeline`` function. """ +import logging from collections import Counter from multipipes import Pipeline, Node -from bigchaindb.common import exceptions import bigchaindb from bigchaindb import Bigchain @@ -16,6 +16,10 @@ from bigchaindb import backend from bigchaindb.backend.changefeed import ChangeFeed from bigchaindb.consensus import BaseConsensusRules from bigchaindb.models import Transaction, Block +from bigchaindb.common import exceptions + + +logger = logging.getLogger(__name__) class Vote: @@ -132,7 +136,9 @@ class Vote: Args: vote: the vote to write. """ - + validity = 'valid' if vote['vote']['is_block_valid'] else 'invalid' + logger.info("Voting '%s' for block %s", validity, + vote['vote']['voting_for_block']) self.bigchain.write_vote(vote) return vote