コード例 #1
0
void CatalogManagerReplicaSet::logAction(OperationContext* txn, const ActionLogType& actionLog) {
    if (_actionLogCollectionCreated.load() == 0) {
        BSONObj createCmd = BSON("create" << ActionLogType::ConfigNS << "capped" << true << "size"
                                          << kActionLogCollectionSize);
        auto result =
            grid.shardRegistry()->runCommandOnConfigWithNotMasterRetries("config", createCmd);
        if (!result.isOK()) {
            LOG(1) << "couldn't create actionlog collection: " << causedBy(result.getStatus());
            return;
        }

        Status commandStatus = Command::getStatusFromCommandResult(result.getValue());
        if (commandStatus.isOK() || commandStatus == ErrorCodes::NamespaceExists) {
            _actionLogCollectionCreated.store(1);
        } else {
            LOG(1) << "couldn't create actionlog collection: " << causedBy(commandStatus);
            return;
        }
    }

    Status result = insert(txn, ActionLogType::ConfigNS, actionLog.toBSON(), NULL);
    if (!result.isOK()) {
        log() << "error encountered while logging action: " << result;
    }
}
コード例 #2
0
ファイル: balance.cpp プロジェクト: DavidAlphaFox/mongodb
static void _reportRound(ActionLogType& actionLog) {
    try {
        ScopedDbConnection conn(configServer.getConnectionString(), 30);

        // send a copy of the message to the log in case it doesn't reach config.actionlog
        actionLog.setTime(jsTime());

        LOG(1) << "about to log balancer result: " << actionLog;

        // The following method is not thread safe. However, there is only one balancer
        // thread per mongos process. The create collection is a a no-op when the collection
        // already exists
        static bool createActionlog = false;
        if (!createActionlog) {
            try {
                static const int actionLogSizeBytes = 1024 * 1024 * 2;
                conn->createCollection(ActionLogType::ConfigNS, actionLogSizeBytes, true);
            } catch (const DBException& ex) {
                LOG(1) << "config.actionlog could not be created, another mongos process "
                       << "may have done so" << causedBy(ex);
            }
            createActionlog = true;
        }

        Status result = clusterInsert(
            ActionLogType::ConfigNS, actionLog.toBSON(), WriteConcernOptions::AllConfigs, NULL);

        if (!result.isOK()) {
            log() << "Error encountered while logging action from balancer " << result.reason();
        }

        conn.done();
    } catch (const DBException& ex) {
        // if we got here, it means the config change is only in the log;
        // the change didn't make it to config.actionlog
        warning() << "could not log balancer result" << causedBy(ex);
    }
}