Fixed mongodb queries to work with pipelines.

Added some logging to the pipeline processes
This commit is contained in:
Rodolphe Marques 2017-01-03 15:09:23 +01:00
parent 0fdcff90f9
commit 3529bf9114
5 changed files with 30 additions and 9 deletions

View File

@ -39,7 +39,9 @@ class MongoDBChangeFeed(ChangeFeed):
self.connection._connect() self.connection._connect()
# namespace to allow us to only listen to changes in a single # namespace to allow us to only listen to changes in a single
# collection # 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 # last timestamp in the oplog. We only care for operations happening
# in the future. # in the future.
last_ts = self.connection.conn.local.oplog.rs.find()\ 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 # on delete it only returns the id of the document
self.outqueue.put(record['o']) self.outqueue.put(record['o'])
elif is_update and (self.operation & ChangeFeed.UPDATE): elif is_update and (self.operation & ChangeFeed.UPDATE):
# not sure what to do here. Lets return the entire # the oplog entry for updates only returns the update
# operation # operations to apply to the document and not the
self.outqueue.put(record) # 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) @register_changefeed(MongoDBConnection)

View File

@ -20,9 +20,14 @@ def write_transaction(conn, signed_transaction):
@register_query(MongoDBConnection) @register_query(MongoDBConnection)
def update_transaction(conn, transaction_id, doc): 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']\ return conn.db['backlog']\
.find_one_and_update({'id': transaction_id}, .find_one_and_update({'id': transaction_id},
doc, update_doc,
return_document=ReturnDocument.AFTER) return_document=ReturnDocument.AFTER)

View File

@ -44,6 +44,8 @@ class BlockPipeline:
if tx['assignee'] == self.bigchain.me: if tx['assignee'] == self.bigchain.me:
tx.pop('assignee') tx.pop('assignee')
tx.pop('assignment_timestamp') tx.pop('assignment_timestamp')
# required for mongodb
tx.pop('_id', None)
return tx return tx
def validate_tx(self, tx): def validate_tx(self, tx):

View File

@ -48,6 +48,8 @@ class StaleTransactionMonitor:
Returns: Returns:
transaction transaction
""" """
# NOTE: Maybe this is to verbose?
logger.info('Reassigning transaction with id %s', tx['id'])
self.bigchain.reassign_transaction(tx) self.bigchain.reassign_transaction(tx)
return tx return tx

View File

@ -5,10 +5,10 @@ of actions to do on transactions is specified in the ``create_pipeline``
function. function.
""" """
import logging
from collections import Counter from collections import Counter
from multipipes import Pipeline, Node from multipipes import Pipeline, Node
from bigchaindb.common import exceptions
import bigchaindb import bigchaindb
from bigchaindb import Bigchain from bigchaindb import Bigchain
@ -16,6 +16,10 @@ from bigchaindb import backend
from bigchaindb.backend.changefeed import ChangeFeed from bigchaindb.backend.changefeed import ChangeFeed
from bigchaindb.consensus import BaseConsensusRules from bigchaindb.consensus import BaseConsensusRules
from bigchaindb.models import Transaction, Block from bigchaindb.models import Transaction, Block
from bigchaindb.common import exceptions
logger = logging.getLogger(__name__)
class Vote: class Vote:
@ -132,7 +136,9 @@ class Vote:
Args: Args:
vote: the vote to write. 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) self.bigchain.write_vote(vote)
return vote return vote