Shard::CommandResponse TransactionRouter::_commitWithRecoveryToken( OperationContext* opCtx, const TxnRecoveryToken& recoveryToken) { const auto shardRegistry = Grid::get(opCtx)->shardRegistry(); const auto& coordinatorId = recoveryToken.getShardId(); auto coordinateCommitCmd = [&] { CoordinateCommitTransaction coordinateCommitCmd; coordinateCommitCmd.setDbName("admin"); coordinateCommitCmd.setParticipants({}); auto rawCoordinateCommit = coordinateCommitCmd.toBSON( BSON(WriteConcernOptions::kWriteConcernField << opCtx->getWriteConcern().toBSON())); auto existingParticipant = getParticipant(coordinatorId); auto coordinatorParticipant = existingParticipant ? existingParticipant : &_createParticipant(coordinatorId); return coordinatorParticipant->attachTxnFieldsIfNeeded(rawCoordinateCommit, false); }(); _initiatedTwoPhaseCommit = true; auto coordinatorShard = uassertStatusOK(shardRegistry->getShard(opCtx, coordinatorId)); return uassertStatusOK(coordinatorShard->runCommandWithFixedRetryAttempts( opCtx, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, "admin", coordinateCommitCmd, Shard::RetryPolicy::kIdempotent)); }
pair<string, partDetails> connectionMsgBlock::getParticipantStr() { pair<long long, partDetails> t = getParticipant(); stringstream code; code << t.first; return pair<string, partDetails>(code.str(), t.second); }
BSONObj TransactionRouter::attachTxnFieldsIfNeeded(const ShardId& shardId, const BSONObj& cmdObj) { if (auto txnPart = getParticipant(shardId)) { LOG(4) << _txnIdToString() << " Sending transaction fields to existing participant: " << shardId; return txnPart->attachTxnFieldsIfNeeded(cmdObj, false); } auto txnPart = _createParticipant(shardId); LOG(4) << _txnIdToString() << " Sending transaction fields to new participant: " << shardId; return txnPart.attachTxnFieldsIfNeeded(cmdObj, true); }
Trade* MarketLimitRule::processRule(OrderBook*& orderBook, Order*& order) { Order* matchedOrder = NULL; Trade* trade = NULL; std::list<Order> orders; if (order->isBuy()) orders = orderBook->getSellOrders(); else orders = orderBook->getBuyOrders(); matchedOrder = &orders.front(); auto it = orders.begin(); while (matchedOrder->getParticipant() == order->getParticipant()) { if (it->getParticipant() != order->getParticipant() && it->isLimit() && order->isMarket()) { matchedOrder = &*it; break; } it++; if (it == orders.end()) return NULL; } int size = matchedOrder->getSize(); double price = matchedOrder->getPrice(); if (matchedOrder->getSize() > order->getSize()) size = order->getSize(); trade = new Trade(*matchedOrder, *order, price, size, orderBook->getTime()); orderBook->updateOrderSize(order, (order->getSize() - size)); orderBook->updateOrderSize(matchedOrder, (matchedOrder->getSize() - size)); orderBook->setLastPrice(price); matchedOrder = NULL; delete matchedOrder; return trade; }