summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/bson/bson_validate_test.cpp21
-rw-r--r--src/mongo/bson/bsonelement.cpp3
-rw-r--r--src/mongo/bson/bsonobj.cpp7
-rw-r--r--src/mongo/bson/bsonobjbuilder.cpp5
-rw-r--r--src/mongo/bson/json.cpp12
-rw-r--r--src/mongo/client/authenticate.cpp6
-rw-r--r--src/mongo/client/connection_string_connect.cpp14
-rw-r--r--src/mongo/client/connpool.cpp22
-rw-r--r--src/mongo/client/dbclient_base.cpp14
-rw-r--r--src/mongo/client/dbclient_connection.cpp48
-rw-r--r--src/mongo/client/dbclient_cursor.cpp11
-rw-r--r--src/mongo/client/dbclient_cursor_test.cpp6
-rw-r--r--src/mongo/client/dbclient_rs.cpp184
-rw-r--r--src/mongo/client/mongo_uri_test.cpp25
-rw-r--r--src/mongo/client/remote_command_retry_scheduler_test.cpp8
-rw-r--r--src/mongo/client/remote_command_targeter_rs.cpp13
-rw-r--r--src/mongo/client/replica_set_change_notifier.cpp16
-rw-r--r--src/mongo/client/replica_set_monitor.cpp139
-rw-r--r--src/mongo/client/replica_set_monitor_manager.cpp10
-rw-r--r--src/mongo/client/replica_set_monitor_scan_test.cpp11
-rw-r--r--src/mongo/client/replica_set_monitor_test_concurrent.cpp19
-rw-r--r--src/mongo/client/sasl_client_authenticate_impl.cpp11
-rw-r--r--src/mongo/client/sdam/sdam_json_test_runner.cpp77
-rw-r--r--src/mongo/client/sdam/topology_description_test.cpp9
-rw-r--r--src/mongo/client/sdam/topology_manager.cpp11
-rw-r--r--src/mongo/client/sdam/topology_state_machine.cpp45
-rw-r--r--src/mongo/db/auth/authorization_manager_impl.cpp43
-rw-r--r--src/mongo/db/auth/authorization_session_impl.cpp59
-rw-r--r--src/mongo/db/auth/authz_session_external_state_server_common.cpp7
-rw-r--r--src/mongo/db/auth/sasl_commands.cpp25
-rw-r--r--src/mongo/db/auth/sasl_mechanism_registry.cpp6
-rw-r--r--src/mongo/db/auth/sasl_scram_test.cpp5
-rw-r--r--src/mongo/db/auth/security_key.cpp29
-rw-r--r--src/mongo/db/auth/user_cache_invalidator_job.cpp54
-rw-r--r--src/mongo/db/catalog/catalog_control.cpp32
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp3
-rw-r--r--src/mongo/db/catalog/collection_catalog.cpp27
-rw-r--r--src/mongo/db/catalog/collection_compact.cpp13
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp49
-rw-r--r--src/mongo/db/catalog/collection_validation.cpp72
-rw-r--r--src/mongo/db/catalog/create_collection.cpp19
-rw-r--r--src/mongo/db/catalog/database_holder_impl.cpp5
-rw-r--r--src/mongo/db/catalog/database_impl.cpp104
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp15
-rw-r--r--src/mongo/db/catalog/drop_database.cpp58
-rw-r--r--src/mongo/db/catalog/drop_indexes.cpp6
-rw-r--r--src/mongo/db/catalog/index_build_block.cpp6
-rw-r--r--src/mongo/db/catalog/index_builds_manager.cpp27
-rw-r--r--src/mongo/db/catalog/index_catalog_entry_impl.cpp23
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp129
-rw-r--r--src/mongo/db/catalog/index_timestamp_helper.cpp15
-rw-r--r--src/mongo/db/catalog/multi_index_block.cpp65
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp61
-rw-r--r--src/mongo/db/catalog/validate_adaptor.cpp3
-rw-r--r--src/mongo/db/catalog/validate_state.cpp46
-rw-r--r--src/mongo/db/catalog_raii_test.cpp3
-rw-r--r--src/mongo/db/cloner.cpp68
-rw-r--r--src/mongo/db/collection_index_builds_tracker.cpp7
-rw-r--r--src/mongo/db/commands.cpp41
-rw-r--r--src/mongo/db/commands/authentication_commands.cpp28
-rw-r--r--src/mongo/db/commands/create_indexes.cpp68
-rw-r--r--src/mongo/db/commands/dbcheck.cpp3
-rw-r--r--src/mongo/db/commands/dbcommands_d.cpp11
-rw-r--r--src/mongo/db/commands/dbhash.cpp5
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp5
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp15
-rw-r--r--src/mongo/db/commands/fsync.cpp43
-rw-r--r--src/mongo/db/commands/generic_servers.cpp3
-rw-r--r--src/mongo/db/commands/get_last_error.cpp10
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp17
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp12
-rw-r--r--src/mongo/db/commands/kill_op.cpp3
-rw-r--r--src/mongo/db/commands/mr.cpp51
-rw-r--r--src/mongo/db/commands/oplog_note.cpp3
-rw-r--r--src/mongo/db/commands/parameters.cpp8
-rw-r--r--src/mongo/db/commands/resize_oplog.cpp3
-rw-r--r--src/mongo/db/commands/rwc_defaults_commands.cpp5
-rw-r--r--src/mongo/db/commands/server_status.cpp3
-rw-r--r--src/mongo/db/commands/set_feature_compatibility_version_command.cpp9
-rw-r--r--src/mongo/db/commands/sleep_command.cpp3
-rw-r--r--src/mongo/db/commands/test_commands.cpp5
-rw-r--r--src/mongo/db/commands/traffic_recording_cmds.cpp8
-rw-r--r--src/mongo/db/commands/txn_cmds.cpp17
-rw-r--r--src/mongo/db/commands/user_management_commands.cpp31
-rw-r--r--src/mongo/db/commands/validate.cpp8
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp11
-rw-r--r--src/mongo/db/concurrency/deferred_writer.cpp13
-rw-r--r--src/mongo/db/concurrency/flow_control_ticketholder.cpp11
-rw-r--r--src/mongo/db/concurrency/lock_manager.cpp7
-rw-r--r--src/mongo/db/concurrency/lock_state.cpp5
-rw-r--r--src/mongo/db/curop.cpp18
-rw-r--r--src/mongo/db/cursor_manager.cpp15
-rw-r--r--src/mongo/db/database_index_builds_tracker.cpp7
-rw-r--r--src/mongo/db/db.cpp195
-rw-r--r--src/mongo/db/db_raii.cpp13
-rw-r--r--src/mongo/db/db_raii_test.cpp3
-rw-r--r--src/mongo/db/exec/cached_plan.cpp73
-rw-r--r--src/mongo/db/exec/collection_scan.cpp3
-rw-r--r--src/mongo/db/exec/document_value/document_value_test.cpp8
-rw-r--r--src/mongo/db/exec/inclusion_projection_executor_test.cpp8
-rw-r--r--src/mongo/db/exec/multi_plan.cpp60
-rw-r--r--src/mongo/db/exec/projection_executor_builder_test.cpp8
-rw-r--r--src/mongo/db/exec/subplan.cpp32
-rw-r--r--src/mongo/db/exec/trial_stage.cpp6
-rw-r--r--src/mongo/db/exec/update_stage.cpp3
-rw-r--r--src/mongo/db/exhaust_cursor_currentop_integration_test.cpp19
-rw-r--r--src/mongo/db/free_mon/free_mon_controller.cpp7
-rw-r--r--src/mongo/db/free_mon/free_mon_controller_test.cpp9
-rw-r--r--src/mongo/db/free_mon/free_mon_processor.cpp47
-rw-r--r--src/mongo/db/ftdc/controller.cpp12
-rw-r--r--src/mongo/db/ftdc/file_manager.cpp34
-rw-r--r--src/mongo/db/ftdc/file_manager_test.cpp9
-rw-r--r--src/mongo/db/ftdc/util.cpp44
-rw-r--r--src/mongo/db/geo/r2_region_coverer.cpp17
-rw-r--r--src/mongo/db/geo/r2_region_coverer_test.cpp15
-rw-r--r--src/mongo/db/index/2d_key_generator_test.cpp13
-rw-r--r--src/mongo/db/index/btree_key_generator_test.cpp16
-rw-r--r--src/mongo/db/index/duplicate_key_tracker.cpp20
-rw-r--r--src/mongo/db/index/hash_key_generator_test.cpp13
-rw-r--r--src/mongo/db/index/haystack_access_method.cpp9
-rw-r--r--src/mongo/db/index/index_access_method.cpp53
-rw-r--r--src/mongo/db/index/index_access_method_factory_impl.cpp5
-rw-r--r--src/mongo/db/index/index_build_interceptor.cpp29
-rw-r--r--src/mongo/db/index/s2_key_generator_test.cpp13
-rw-r--r--src/mongo/db/index/wildcard_key_generator_test.cpp13
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp227
-rw-r--r--src/mongo/db/initialize_server_global_state.cpp11
-rw-r--r--src/mongo/db/introspect.cpp31
-rw-r--r--src/mongo/db/keys_collection_client_direct.cpp10
-rw-r--r--src/mongo/db/keys_collection_manager.cpp3
-rw-r--r--src/mongo/db/kill_sessions_common.cpp7
-rw-r--r--src/mongo/db/kill_sessions_local.cpp105
-rw-r--r--src/mongo/db/log_process_details.cpp27
-rw-r--r--src/mongo/db/logical_clock.cpp6
-rw-r--r--src/mongo/db/logical_session_cache_impl.cpp27
-rw-r--r--src/mongo/db/logical_time_validator.cpp7
-rw-r--r--src/mongo/db/matcher/rewrite_expr.cpp16
-rw-r--r--src/mongo/db/matcher/schema/json_schema_parser.cpp14
-rw-r--r--src/mongo/db/mongod_options.cpp35
-rw-r--r--src/mongo/db/operation_context.cpp7
-rw-r--r--src/mongo/db/operation_killer.cpp3
-rw-r--r--src/mongo/db/ops/update_result.cpp3
-rw-r--r--src/mongo/db/ops/write_ops_exec.cpp40
-rw-r--r--src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp22
-rw-r--r--src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp16
-rw-r--r--src/mongo/db/pipeline/document_source_cursor.cpp4
-rw-r--r--src/mongo/db/pipeline/document_source_exchange.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_exchange_test.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_match_test.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_merge.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_out.cpp9
-rw-r--r--src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp7
-rw-r--r--src/mongo/db/pipeline/sharded_agg_helpers.cpp22
-rw-r--r--src/mongo/db/query/collection_query_info.cpp6
-rw-r--r--src/mongo/db/query/find.cpp59
-rw-r--r--src/mongo/db/query/find_common.cpp6
-rw-r--r--src/mongo/db/query/get_executor.cpp96
-rw-r--r--src/mongo/db/query/index_bounds_builder.cpp19
-rw-r--r--src/mongo/db/query/plan_cache.cpp98
-rw-r--r--src/mongo/db/query/plan_enumerator.cpp8
-rw-r--r--src/mongo/db/query/plan_executor_impl.cpp6
-rw-r--r--src/mongo/db/query/plan_ranker.cpp45
-rw-r--r--src/mongo/db/query/planner_access.cpp9
-rw-r--r--src/mongo/db/query/planner_analysis.cpp18
-rw-r--r--src/mongo/db/query/planner_ixselect.cpp18
-rw-r--r--src/mongo/db/query/planner_wildcard_helpers.cpp12
-rw-r--r--src/mongo/db/query/query_planner.cpp112
-rw-r--r--src/mongo/db/query/query_planner_test_fixture.cpp3
-rw-r--r--src/mongo/db/read_concern_mongod.cpp79
-rw-r--r--src/mongo/db/read_write_concern_defaults.cpp5
-rw-r--r--src/mongo/db/repair_database.cpp17
-rw-r--r--src/mongo/db/repair_database_and_check_version.cpp133
-rw-r--r--src/mongo/db/repl/abstract_oplog_fetcher.cpp42
-rw-r--r--src/mongo/db/repl/abstract_oplog_fetcher_test.cpp28
-rw-r--r--src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp12
-rw-r--r--src/mongo/db/repl/all_database_cloner.cpp38
-rw-r--r--src/mongo/db/repl/all_database_cloner_test.cpp10
-rw-r--r--src/mongo/db/repl/apply_ops.cpp3
-rw-r--r--src/mongo/db/repl/base_cloner.cpp82
-rw-r--r--src/mongo/db/repl/bgsync.cpp228
-rw-r--r--src/mongo/db/repl/collection_bulk_loader_impl.cpp9
-rw-r--r--src/mongo/db/repl/collection_cloner.cpp62
-rw-r--r--src/mongo/db/repl/data_replicator_external_state_impl.cpp23
-rw-r--r--src/mongo/db/repl/database_cloner.cpp17
-rw-r--r--src/mongo/db/repl/drop_pending_collection_reaper.cpp41
-rw-r--r--src/mongo/db/repl/idempotency_test.cpp9
-rw-r--r--src/mongo/db/repl/initial_syncer.cpp222
-rw-r--r--src/mongo/db/repl/insert_group.cpp5
-rw-r--r--src/mongo/db/repl/isself.cpp42
-rw-r--r--src/mongo/db/repl/member_data.cpp38
-rw-r--r--src/mongo/db/repl/noop_writer.cpp26
-rw-r--r--src/mongo/db/repl/oplog.cpp110
-rw-r--r--src/mongo/db/repl/oplog_applier.cpp12
-rw-r--r--src/mongo/db/repl/oplog_applier_impl.cpp64
-rw-r--r--src/mongo/db/repl/oplog_batcher.cpp7
-rw-r--r--src/mongo/db/repl/oplog_fetcher.cpp90
-rw-r--r--src/mongo/db/repl/repl_client_info.cpp17
-rw-r--r--src/mongo/db/repl/repl_set_commands.cpp37
-rw-r--r--src/mongo/db/repl/replication_consistency_markers_impl.cpp74
-rw-r--r--src/mongo/db/repl/replication_coordinator_external_state_impl.cpp33
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp606
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp79
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp111
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp89
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp25
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp59
-rw-r--r--src/mongo/db/repl/replication_coordinator_test_fixture.cpp68
-rw-r--r--src/mongo/db/repl/replication_process.cpp28
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp192
-rw-r--r--src/mongo/db/repl/reporter.cpp32
-rw-r--r--src/mongo/db/repl/roll_back_local_operations.cpp6
-rw-r--r--src/mongo/db/repl/roll_back_local_operations_test.cpp13
-rw-r--r--src/mongo/db/repl/rollback_impl.cpp348
-rw-r--r--src/mongo/db/repl/rollback_impl_test.cpp28
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp580
-rw-r--r--src/mongo/db/repl/scatter_gather_runner.cpp7
-rw-r--r--src/mongo/db/repl/storage_interface_impl.cpp21
-rw-r--r--src/mongo/db/repl/storage_interface_mock.cpp7
-rw-r--r--src/mongo/db/repl/sync_source_feedback.cpp39
-rw-r--r--src/mongo/db/repl/sync_source_resolver.cpp117
-rw-r--r--src/mongo/db/repl/task_runner.cpp5
-rw-r--r--src/mongo/db/repl/topology_coordinator.cpp395
-rw-r--r--src/mongo/db/repl/topology_coordinator_v1_test.cpp8
-rw-r--r--src/mongo/db/repl/transaction_oplog_application.cpp38
-rw-r--r--src/mongo/db/s/balancer/balancer.cpp110
-rw-r--r--src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp20
-rw-r--r--src/mongo/db/s/balancer/balancer_policy.cpp83
-rw-r--r--src/mongo/db/s/balancer/cluster_statistics_impl.cpp9
-rw-r--r--src/mongo/db/s/balancer/migration_manager.cpp41
-rw-r--r--src/mongo/db/s/balancer/scoped_migration_request.cpp27
-rw-r--r--src/mongo/db/s/chunk_splitter.cpp69
-rw-r--r--src/mongo/db/s/cleanup_orphaned_cmd.cpp31
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp17
-rw-r--r--src/mongo/db/s/config/configsvr_add_shard_command.cpp7
-rw-r--r--src/mongo/db/s/config/configsvr_move_primary_command.cpp10
-rw-r--r--src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp5
-rw-r--r--src/mongo/db/s/config/configsvr_remove_shard_command.cpp3
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp66
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp11
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp31
-rw-r--r--src/mongo/db/s/database_sharding_state.cpp9
-rw-r--r--src/mongo/db/s/flush_database_cache_updates_command.cpp6
-rw-r--r--src/mongo/db/s/flush_routing_table_cache_updates_command.cpp4
-rw-r--r--src/mongo/db/s/merge_chunks_command.cpp8
-rw-r--r--src/mongo/db/s/metadata_manager.cpp52
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp45
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp71
-rw-r--r--src/mongo/db/s/migration_destination_manager_legacy_commands.cpp5
-rw-r--r--src/mongo/db/s/migration_source_manager.cpp40
-rw-r--r--src/mongo/db/s/migration_util.cpp150
-rw-r--r--src/mongo/db/s/move_primary_source_manager.cpp27
-rw-r--r--src/mongo/db/s/periodic_balancer_config_refresher.cpp5
-rw-r--r--src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp22
-rw-r--r--src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp18
-rw-r--r--src/mongo/db/s/set_shard_version_command.cpp9
-rw-r--r--src/mongo/db/s/shard_filtering_metadata_refresh.cpp49
-rw-r--r--src/mongo/db/s/shard_metadata_util.cpp16
-rw-r--r--src/mongo/db/s/shard_server_catalog_cache_loader.cpp44
-rw-r--r--src/mongo/db/s/sharded_connection_info.cpp3
-rw-r--r--src/mongo/db/s/sharding_initialization_mongod.cpp70
-rw-r--r--src/mongo/db/s/sharding_logging.cpp22
-rw-r--r--src/mongo/db/s/sharding_state.cpp5
-rw-r--r--src/mongo/db/s/sharding_state_recovery.cpp40
-rw-r--r--src/mongo/db/s/shardsvr_shard_collection.cpp17
-rw-r--r--src/mongo/db/s/split_chunk_command.cpp3
-rw-r--r--src/mongo/db/s/split_chunk_test.cpp5
-rw-r--r--src/mongo/db/s/split_vector.cpp75
-rw-r--r--src/mongo/db/s/transaction_coordinator.cpp25
-rw-r--r--src/mongo/db/s/transaction_coordinator_catalog.cpp33
-rw-r--r--src/mongo/db/s/transaction_coordinator_futures_util.cpp7
-rw-r--r--src/mongo/db/s/transaction_coordinator_service.cpp20
-rw-r--r--src/mongo/db/s/transaction_coordinator_test.cpp22
-rw-r--r--src/mongo/db/s/transaction_coordinator_util.cpp119
-rw-r--r--src/mongo/db/s/txn_two_phase_commit_cmds.cpp34
-rw-r--r--src/mongo/db/s/wait_for_majority_service.cpp3
-rw-r--r--src/mongo/db/server_options_server_helpers.cpp5
-rw-r--r--src/mongo/db/service_entry_point_common.cpp131
-rw-r--r--src/mongo/db/service_entry_point_mongod.cpp18
-rw-r--r--src/mongo/db/session_catalog.cpp6
-rw-r--r--src/mongo/db/session_catalog_mongod.cpp20
-rw-r--r--src/mongo/db/sessions_collection_config_server.cpp9
-rw-r--r--src/mongo/db/sorter/sorter_test.cpp10
-rw-r--r--src/mongo/db/startup_warnings_common.cpp139
-rw-r--r--src/mongo/db/startup_warnings_mongod.cpp227
-rw-r--r--src/mongo/db/stats/counters.cpp3
-rw-r--r--src/mongo/db/storage/durable_catalog_impl.cpp54
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp6
-rw-r--r--src/mongo/db/storage/flow_control.cpp94
-rw-r--r--src/mongo/db/storage/key_string_test.cpp57
-rw-r--r--src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp27
-rw-r--r--src/mongo/db/storage/oplog_cap_maintainer_thread.cpp9
-rw-r--r--src/mongo/db/storage/recovery_unit.cpp11
-rw-r--r--src/mongo/db/storage/storage_engine_impl.cpp132
-rw-r--r--src/mongo/db/storage/storage_engine_init.cpp29
-rw-r--r--src/mongo/db/storage/storage_engine_lock_file_posix.cpp30
-rw-r--r--src/mongo/db/storage/storage_engine_lock_file_windows.cpp5
-rw-r--r--src/mongo/db/storage/storage_engine_metadata.cpp28
-rw-r--r--src/mongo/db/storage/storage_file_util.cpp6
-rw-r--r--src/mongo/db/storage/storage_repair_observer_test.cpp10
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp14
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp38
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp244
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp12
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp41
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp13
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp10
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp133
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp47
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp13
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp27
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp6
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp58
-rw-r--r--src/mongo/db/system_index.cpp16
-rw-r--r--src/mongo/db/transaction_participant.cpp73
-rw-r--r--src/mongo/db/ttl.cpp74
-rw-r--r--src/mongo/db/views/durable_view_catalog.cpp13
-rw-r--r--src/mongo/db/views/view_catalog.cpp12
-rw-r--r--src/mongo/db/write_concern.cpp19
-rw-r--r--src/mongo/dbtests/framework_options.cpp5
-rw-r--r--src/mongo/dbtests/jsobjtests.cpp6
-rw-r--r--src/mongo/dbtests/jsontests.cpp21
-rw-r--r--src/mongo/dbtests/repltests.cpp9
-rw-r--r--src/mongo/dbtests/storage_timestamp_tests.cpp38
-rw-r--r--src/mongo/dbtests/threadedtests.cpp3
-rw-r--r--src/mongo/dbtests/wildcard_multikey_persistence_test.cpp8
-rw-r--r--src/mongo/embedded/embedded.cpp21
-rw-r--r--src/mongo/embedded/mongoc_embedded/mongoc_embedded_test.cpp5
-rw-r--r--src/mongo/executor/connection_pool.cpp144
-rw-r--r--src/mongo/executor/connection_pool_tl.cpp13
-rw-r--r--src/mongo/executor/network_interface_integration_fixture.cpp5
-rw-r--r--src/mongo/executor/network_interface_mock.cpp13
-rw-r--r--src/mongo/executor/network_interface_perf_test.cpp3
-rw-r--r--src/mongo/executor/network_interface_tl.cpp40
-rw-r--r--src/mongo/executor/thread_pool_mock.cpp11
-rw-r--r--src/mongo/executor/thread_pool_task_executor.cpp14
-rw-r--r--src/mongo/platform/decimal128_bson_test.cpp5
-rw-r--r--src/mongo/platform/random_test.cpp17
-rw-r--r--src/mongo/platform/shared_library_posix.cpp7
-rw-r--r--src/mongo/platform/shared_library_windows.cpp11
-rw-r--r--src/mongo/platform/source_location_test.cpp38
-rw-r--r--src/mongo/rpc/op_msg.cpp18
-rw-r--r--src/mongo/rpc/op_msg_integration_test.cpp8
-rw-r--r--src/mongo/rpc/op_msg_test.cpp19
-rw-r--r--src/mongo/s/balancer_configuration.cpp15
-rw-r--r--src/mongo/s/catalog/replset_dist_lock_manager.cpp186
-rw-r--r--src/mongo/s/catalog/sharding_catalog_client_impl.cpp12
-rw-r--r--src/mongo/s/catalog_cache.cpp38
-rw-r--r--src/mongo/s/chunk_manager_index_bounds_test.cpp8
-rw-r--r--src/mongo/s/client/parallel.cpp238
-rw-r--r--src/mongo/s/client/shard.cpp28
-rw-r--r--src/mongo/s/client/shard_connection.cpp19
-rw-r--r--src/mongo/s/client/shard_registry.cpp79
-rw-r--r--src/mongo/s/client/shard_remote.cpp9
-rw-r--r--src/mongo/s/client/sharding_connection_hook.cpp3
-rw-r--r--src/mongo/s/client/version_manager.cpp30
-rw-r--r--src/mongo/s/commands/cluster_coll_stats_cmd.cpp5
-rw-r--r--src/mongo/s/commands/cluster_collection_mod_cmd.cpp7
-rw-r--r--src/mongo/s/commands/cluster_create_indexes_cmd.cpp7
-rw-r--r--src/mongo/s/commands/cluster_drop_indexes_cmd.cpp7
-rw-r--r--src/mongo/s/commands/cluster_get_last_error_cmd.cpp12
-rw-r--r--src/mongo/s/commands/cluster_get_shard_version_cmd.cpp3
-rw-r--r--src/mongo/s/commands/cluster_kill_op.cpp3
-rw-r--r--src/mongo/s/commands/cluster_move_chunk_cmd.cpp3
-rw-r--r--src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp3
-rw-r--r--src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp8
-rw-r--r--src/mongo/s/commands/cluster_split_cmd.cpp13
-rw-r--r--src/mongo/s/commands/cluster_write_cmd.cpp3
-rw-r--r--src/mongo/s/commands/document_shard_key_update_util.cpp3
-rw-r--r--src/mongo/s/commands/flush_router_config_cmd.cpp7
-rw-r--r--src/mongo/s/commands/strategy.cpp89
-rw-r--r--src/mongo/s/grid.cpp12
-rw-r--r--src/mongo/s/query/cluster_aggregation_planner.cpp10
-rw-r--r--src/mongo/s/query/cluster_cursor_manager.cpp9
-rw-r--r--src/mongo/s/query/cluster_find.cpp21
-rw-r--r--src/mongo/s/server.cpp108
-rw-r--r--src/mongo/s/service_entry_point_mongos.cpp26
-rw-r--r--src/mongo/s/shard_util.cpp17
-rw-r--r--src/mongo/s/sharding_task_executor.cpp34
-rw-r--r--src/mongo/s/sharding_uptime_reporter.cpp12
-rw-r--r--src/mongo/s/transaction_router.cpp148
-rw-r--r--src/mongo/s/version_mongos.cpp5
-rw-r--r--src/mongo/s/write_ops/batch_write_exec.cpp89
-rw-r--r--src/mongo/s/write_ops/chunk_manager_targeter.cpp31
-rw-r--r--src/mongo/scripting/engine.cpp17
-rw-r--r--src/mongo/scripting/mozjs/cursor_handle.cpp6
-rw-r--r--src/mongo/scripting/mozjs/engine.cpp25
-rw-r--r--src/mongo/scripting/mozjs/implscope.cpp15
-rw-r--r--src/mongo/scripting/mozjs/session.cpp6
-rw-r--r--src/mongo/shell/bench.cpp60
-rw-r--r--src/mongo/shell/shell_options.cpp10
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp67
-rw-r--r--src/mongo/tools/bridge.cpp48
-rw-r--r--src/mongo/transport/message_compressor_manager.cpp48
-rw-r--r--src/mongo/transport/service_entry_point_impl.cpp49
-rw-r--r--src/mongo/transport/service_entry_point_utils.cpp11
-rw-r--r--src/mongo/transport/service_executor_adaptive.cpp49
-rw-r--r--src/mongo/transport/service_executor_adaptive_test.cpp37
-rw-r--r--src/mongo/transport/service_executor_reserved.cpp12
-rw-r--r--src/mongo/transport/service_executor_synchronous.cpp5
-rw-r--r--src/mongo/transport/service_executor_test.cpp7
-rw-r--r--src/mongo/transport/service_state_machine.cpp47
-rw-r--r--src/mongo/transport/service_state_machine_test.cpp51
-rw-r--r--src/mongo/transport/transport_layer_asio.cpp71
-rw-r--r--src/mongo/transport/transport_layer_asio_integration_test.cpp9
-rw-r--r--src/mongo/transport/transport_layer_asio_test.cpp39
-rw-r--r--src/mongo/unittest/benchmark_main.cpp8
-rw-r--r--src/mongo/unittest/integration_test_main.cpp5
-rw-r--r--src/mongo/unittest/temp_dir.cpp12
-rw-r--r--src/mongo/unittest/unittest.cpp54
-rw-r--r--src/mongo/util/alarm_test.cpp7
-rw-r--r--src/mongo/util/assert_util.cpp111
-rw-r--r--src/mongo/util/background.cpp17
-rw-r--r--src/mongo/util/concurrency/thread_name.cpp9
-rw-r--r--src/mongo/util/concurrency/thread_pool.cpp100
-rw-r--r--src/mongo/util/concurrency/ticketholder.cpp7
-rw-r--r--src/mongo/util/concurrency/with_lock_test.cpp6
-rw-r--r--src/mongo/util/diagnostic_info.cpp19
-rw-r--r--src/mongo/util/exception_filter_win32.cpp35
-rw-r--r--src/mongo/util/exit.cpp15
-rw-r--r--src/mongo/util/file.cpp126
-rw-r--r--src/mongo/util/heap_profiler.cpp24
-rw-r--r--src/mongo/util/latch_analyzer.cpp9
-rw-r--r--src/mongo/util/log.cpp12
-rw-r--r--src/mongo/util/net/hostname_canonicalization.cpp14
-rw-r--r--src/mongo/util/net/openssl_init.cpp12
-rw-r--r--src/mongo/util/net/sock.cpp161
-rw-r--r--src/mongo/util/net/sockaddr.cpp12
-rw-r--r--src/mongo/util/net/socket_utils.cpp27
-rw-r--r--src/mongo/util/net/ssl_manager.cpp46
-rw-r--r--src/mongo/util/net/ssl_manager_apple.cpp21
-rw-r--r--src/mongo/util/net/ssl_manager_openssl.cpp164
-rw-r--r--src/mongo/util/net/ssl_manager_test.cpp18
-rw-r--r--src/mongo/util/net/ssl_manager_windows.cpp56
-rw-r--r--src/mongo/util/net/ssl_options_server.cpp11
-rw-r--r--src/mongo/util/ntservice.cpp134
-rw-r--r--src/mongo/util/options_parser/options_parser.cpp29
-rw-r--r--src/mongo/util/periodic_runner_impl.cpp5
-rw-r--r--src/mongo/util/platform_init.cpp14
-rw-r--r--src/mongo/util/processinfo.cpp18
-rw-r--r--src/mongo/util/processinfo_freebsd.cpp33
-rw-r--r--src/mongo/util/processinfo_linux.cpp22
-rw-r--r--src/mongo/util/processinfo_openbsd.cpp37
-rw-r--r--src/mongo/util/processinfo_osx.cpp21
-rw-r--r--src/mongo/util/processinfo_solaris.cpp33
-rw-r--r--src/mongo/util/procparser_test.cpp13
-rw-r--r--src/mongo/util/progress_meter.cpp3
-rw-r--r--src/mongo/util/signal_handlers.cpp56
-rw-r--r--src/mongo/util/stacktrace_test.cpp28
-rw-r--r--src/mongo/util/stacktrace_threads.cpp28
-rw-r--r--src/mongo/util/version.cpp22
-rw-r--r--src/mongo/watchdog/watchdog.cpp170
-rw-r--r--src/mongo/watchdog/watchdog_test.cpp9
452 files changed, 11580 insertions, 5155 deletions
diff --git a/src/mongo/bson/bson_validate_test.cpp b/src/mongo/bson/bson_validate_test.cpp
index e7d8e14ad70..547ff21572e 100644
--- a/src/mongo/bson/bson_validate_test.cpp
+++ b/src/mongo/bson/bson_validate_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/base/data_view.h"
#include "mongo/bson/bson_validate.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -94,9 +95,12 @@ TEST(BSONValidate, RandomData) {
delete[] x;
}
- log() << "RandomData: didn't crash valid/total: " << numValid << "/" << numToRun
- << " (want few valid ones)"
- << " jsonSize: " << jsonSize << endl;
+ LOGV2(20104,
+ "RandomData: didn't crash valid/total: {numValid}/{numToRun} (want few valid ones) "
+ "jsonSize: {jsonSize}",
+ "numValid"_attr = numValid,
+ "numToRun"_attr = numToRun,
+ "jsonSize"_attr = jsonSize);
}
TEST(BSONValidate, MuckingData1) {
@@ -140,14 +144,17 @@ TEST(BSONValidate, MuckingData1) {
}
}
- log() << "MuckingData1: didn't crash valid/total: " << numValid << "/" << numToRun
- << " (want few valid ones) "
- << " jsonSize: " << jsonSize << endl;
+ LOGV2(20105,
+ "MuckingData1: didn't crash valid/total: {numValid}/{numToRun} (want few valid ones) "
+ "jsonSize: {jsonSize}",
+ "numValid"_attr = numValid,
+ "numToRun"_attr = numToRun,
+ "jsonSize"_attr = jsonSize);
}
TEST(BSONValidate, Fuzz) {
int64_t seed = time(nullptr);
- log() << "BSONValidate Fuzz random seed: " << seed << endl;
+ LOGV2(20106, "BSONValidate Fuzz random seed: {seed}", "seed"_attr = seed);
PseudoRandom randomSource(seed);
BSONObj original =
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 667b5eeb079..2c33e55d8b7 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -43,6 +43,7 @@
#include "mongo/bson/generator_extended_relaxed_2_0_0.h"
#include "mongo/bson/generator_legacy_strict.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/strnlen.h"
#include "mongo/util/base64.h"
#include "mongo/util/duration.h"
@@ -893,7 +894,7 @@ std::string BSONElement::_asCode() const {
return std::string(codeWScopeCode(),
ConstDataView(valuestr()).read<LittleEndian<int>>() - 1);
default:
- log() << "can't convert type: " << (int)(type()) << " to code" << std::endl;
+ LOGV2(20100, "can't convert type: {int_type} to code", "int_type"_attr = (int)(type()));
}
uassert(10062, "not code", 0);
return "";
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp
index 994cbde6070..dc37c075b5a 100644
--- a/src/mongo/bson/bsonobj.cpp
+++ b/src/mongo/bson/bsonobj.cpp
@@ -120,8 +120,11 @@ BSONObj BSONObj::copy() const {
// that the memory we are reading has changed, and we must exit immediately to avoid further
// undefined behavior.
if (int sizeAfter = objsize(); sizeAfter != size) {
- severe() << "BSONObj::copy() - size " << sizeAfter
- << " differs from previously observed size " << size;
+ LOGV2_FATAL(
+ 20103,
+ "BSONObj::copy() - size {sizeAfter} differs from previously observed size {size}",
+ "sizeAfter"_attr = sizeAfter,
+ "size"_attr = size);
fassertFailed(31323);
}
memcpy(storage.get(), objdata(), size);
diff --git a/src/mongo/bson/bsonobjbuilder.cpp b/src/mongo/bson/bsonobjbuilder.cpp
index 13133acf5c8..6487c93f932 100644
--- a/src/mongo/bson/bsonobjbuilder.cpp
+++ b/src/mongo/bson/bsonobjbuilder.cpp
@@ -34,6 +34,7 @@
#include <boost/lexical_cast.hpp>
#include "mongo/bson/timestamp.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -105,7 +106,7 @@ BSONObjBuilder& BSONObjBuilder::appendMinForType(StringData fieldName, int t) {
appendCodeWScope(fieldName, "", BSONObj());
return *this;
};
- log() << "type not supported for appendMinElementForType: " << t;
+ LOGV2(20101, "type not supported for appendMinElementForType: {t}", "t"_attr = t);
uassert(10061, "type not supported for appendMinElementForType", false);
}
@@ -173,7 +174,7 @@ BSONObjBuilder& BSONObjBuilder::appendMaxForType(StringData fieldName, int t) {
appendMinForType(fieldName, MaxKey);
return *this;
}
- log() << "type not supported for appendMaxElementForType: " << t;
+ LOGV2(20102, "type not supported for appendMaxElementForType: {t}", "t"_attr = t);
uassert(14853, "type not supported for appendMaxElementForType", false);
}
diff --git a/src/mongo/bson/json.cpp b/src/mongo/bson/json.cpp
index b6fbdf94541..7bdafb4f17a 100644
--- a/src/mongo/bson/json.cpp
+++ b/src/mongo/bson/json.cpp
@@ -36,6 +36,7 @@
#include "mongo/base/parse_number.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/decimal128.h"
#include "mongo/platform/strtoll.h"
#include "mongo/util/base64.h"
@@ -53,9 +54,14 @@ using std::unique_ptr;
using namespace fmt::literals;
#if 0
-#define MONGO_JSON_DEBUG(message) \
- log() << "JSON DEBUG @ " << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << ": " \
- << message << endl;
+#define MONGO_JSON_DEBUG(message) \
+ LOGV2(20107, \
+ "JSON DEBUG @ {FILE_}:{LINE_} {FUNCTION_}{}{message}", \
+ "FILE_"_attr = __FILE__, \
+ "LINE_"_attr = __LINE__, \
+ "FUNCTION_"_attr = __FUNCTION__, \
+ ""_attr = ": " \, \
+ "message"_attr = message);
#else
#define MONGO_JSON_DEBUG(message)
#endif
diff --git a/src/mongo/client/authenticate.cpp b/src/mongo/client/authenticate.cpp
index 71c9aa3cbc6..9136aa19ac7 100644
--- a/src/mongo/client/authenticate.cpp
+++ b/src/mongo/client/authenticate.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/auth/authorization_manager.h"
#include "mongo/db/auth/sasl_command_constants.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/op_msg_rpc_impls.h"
@@ -150,8 +151,9 @@ Future<void> authenticateClient(const BSONObj& params,
auto errorHandler = [](Status status) {
if (serverGlobalParams.transitionToAuth && !ErrorCodes::isNetworkError(status)) {
// If auth failed in transitionToAuth, just pretend it succeeded.
- log() << "Failed to authenticate in transitionToAuth, falling back to no "
- "authentication.";
+ LOGV2(20108,
+ "Failed to authenticate in transitionToAuth, falling back to no "
+ "authentication.");
return Status::OK();
}
diff --git a/src/mongo/client/connection_string_connect.cpp b/src/mongo/client/connection_string_connect.cpp
index c60770e2f3f..229495c3a0e 100644
--- a/src/mongo/client/connection_string_connect.cpp
+++ b/src/mongo/client/connection_string_connect.cpp
@@ -38,6 +38,7 @@
#include "mongo/client/dbclient_rs.h"
#include "mongo/client/mongo_uri.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -61,11 +62,12 @@ std::unique_ptr<DBClientBase> ConnectionString::connect(StringData applicationNa
auto c = std::make_unique<DBClientConnection>(true, 0, newURI);
c->setSoTimeout(socketTimeout);
- LOG(1) << "creating new connection to:" << server;
+ LOGV2_DEBUG(
+ 20109, 1, "creating new connection to:{server}", "server"_attr = server);
if (!c->connect(server, applicationName, errmsg)) {
continue;
}
- LOG(1) << "connected connection!";
+ LOGV2_DEBUG(20110, 1, "connected connection!");
return std::move(c);
}
return nullptr;
@@ -96,8 +98,12 @@ std::unique_ptr<DBClientBase> ConnectionString::connect(StringData applicationNa
// Double-checked lock, since this will never be active during normal operation
auto replacementConn = _connectHook->connect(*this, errmsg, socketTimeout);
- log() << "replacing connection to " << this->toString() << " with "
- << (replacementConn ? replacementConn->getServerAddress() : "(empty)");
+ LOGV2(20111,
+ "replacing connection to {this} with "
+ "{replacementConn_replacementConn_getServerAddress_empty}",
+ "this"_attr = this->toString(),
+ "replacementConn_replacementConn_getServerAddress_empty"_attr =
+ (replacementConn ? replacementConn->getServerAddress() : "(empty)"));
return replacementConn;
}
diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp
index cdb9115b40b..7c035961eb4 100644
--- a/src/mongo/client/connpool.cpp
+++ b/src/mongo/client/connpool.cpp
@@ -44,6 +44,7 @@
#include "mongo/client/global_conn_pool.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/executor/connection_pool_stats.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/chrono.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -267,8 +268,10 @@ public:
PoolForHost& p = _this->_pools[PoolKey(host, timeout)];
if (p.openConnections() >= _this->_maxInUse) {
- log() << "Too many in-use connections; waiting until there are fewer than "
- << _this->_maxInUse;
+ LOGV2(20112,
+ "Too many in-use connections; waiting until there are fewer than "
+ "{this_maxInUse}",
+ "this_maxInUse"_attr = _this->_maxInUse);
p.waitForFreeConnection(timeout, lk);
} else {
// Drop the lock here, so we can connect without holding it.
@@ -352,9 +355,13 @@ DBClientBase* DBConnectionPool::_finishCreate(const string& ident,
throw;
}
- log() << "Successfully connected to " << ident << " (" << openConnections(ident, socketTimeout)
- << " connections now open to " << ident << " with a " << socketTimeout
- << " second timeout)";
+ LOGV2(20113,
+ "Successfully connected to {ident} ({openConnections_ident_socketTimeout} connections "
+ "now open to {ident2} with a {socketTimeout} second timeout)",
+ "ident"_attr = ident,
+ "openConnections_ident_socketTimeout"_attr = openConnections(ident, socketTimeout),
+ "ident2"_attr = ident,
+ "socketTimeout"_attr = socketTimeout);
return conn;
}
@@ -472,7 +479,7 @@ void DBConnectionPool::flush() {
void DBConnectionPool::clear() {
stdx::lock_guard<Latch> L(_mutex);
- LOG(2) << "Removing connections on all pools owned by " << _name << endl;
+ LOGV2_DEBUG(20114, 2, "Removing connections on all pools owned by {name}", "name"_attr = _name);
for (PoolMap::iterator iter = _pools.begin(); iter != _pools.end(); ++iter) {
iter->second.clear();
}
@@ -480,7 +487,8 @@ void DBConnectionPool::clear() {
void DBConnectionPool::removeHost(const string& host) {
stdx::lock_guard<Latch> L(_mutex);
- LOG(2) << "Removing connections from all pools for host: " << host << endl;
+ LOGV2_DEBUG(
+ 20115, 2, "Removing connections from all pools for host: {host}", "host"_attr = host);
for (PoolMap::iterator i = _pools.begin(); i != _pools.end(); ++i) {
const string& poolHost = i->first.ident;
if (!serverNameCompare()(host, poolHost) && !serverNameCompare()(poolHost, host)) {
diff --git a/src/mongo/client/dbclient_base.cpp b/src/mongo/client/dbclient_base.cpp
index 3654b2f89cc..5ba32922a6f 100644
--- a/src/mongo/client/dbclient_base.cpp
+++ b/src/mongo/client/dbclient_base.cpp
@@ -56,6 +56,7 @@
#include "mongo/db/wire_version.h"
#include "mongo/executor/remote_command_request.h"
#include "mongo/executor/remote_command_response.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/factory.h"
#include "mongo/rpc/get_status_from_command_result.h"
@@ -469,7 +470,7 @@ Status DBClientBase::authenticateInternalUser() {
ScopedMetadataWriterRemover remover{this};
if (!auth::isInternalAuthSet()) {
if (!serverGlobalParams.quiet.load()) {
- log() << "ERROR: No authentication parameters set for internal user";
+ LOGV2(20116, "ERROR: No authentication parameters set for internal user");
}
return {ErrorCodes::AuthenticationFailed,
"No authentication parameters set for internal user"};
@@ -491,8 +492,10 @@ Status DBClientBase::authenticateInternalUser() {
}
if (serverGlobalParams.quiet.load()) {
- log() << "can't authenticate to " << toString()
- << " as internal user, error: " << status.reason();
+ LOGV2(20117,
+ "can't authenticate to {} as internal user, error: {status_reason}",
+ ""_attr = toString(),
+ "status_reason"_attr = status.reason());
}
return status;
@@ -892,7 +895,10 @@ void DBClientBase::dropIndex(const string& ns, const string& indexName) {
if (!runCommand(nsToDatabase(ns),
BSON("dropIndexes" << nsToCollectionSubstring(ns) << "index" << indexName),
info)) {
- LOG(_logLevel) << "dropIndex failed: " << info << endl;
+ LOGV2_DEBUG(20118,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "dropIndex failed: {info}",
+ "info"_attr = info);
uassert(10007, "dropIndex failed", 0);
}
}
diff --git a/src/mongo/client/dbclient_connection.cpp b/src/mongo/client/dbclient_connection.cpp
index 5a9d29859cc..c7e2a18021c 100644
--- a/src/mongo/client/dbclient_connection.cpp
+++ b/src/mongo/client/dbclient_connection.cpp
@@ -65,6 +65,7 @@
#include "mongo/db/wire_version.h"
#include "mongo/executor/remote_command_request.h"
#include "mongo/executor/remote_command_response.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/client_metadata.h"
@@ -341,7 +342,9 @@ Status DBClientConnection::connect(const HostAndPort& serverAddress, StringData
auto validateStatus =
rpc::validateWireVersion(WireSpec::instance().outgoing, swProtocolSet.getValue().version);
if (!validateStatus.isOK()) {
- warning() << "remote host has incompatible wire version: " << validateStatus;
+ LOGV2_WARNING(20126,
+ "remote host has incompatible wire version: {validateStatus}",
+ "validateStatus"_attr = validateStatus);
return validateStatus;
}
@@ -424,7 +427,7 @@ Status DBClientConnection::connectSocketOnly(const HostAndPort& serverAddress) {
_lastConnectivityCheck = Date_t::now();
_session->setTimeout(_socketTimeout);
_session->setTags(_tagMask);
- LOG(1) << "connected to server " << toString();
+ LOGV2_DEBUG(20119, 1, "connected to server {}", ""_attr = toString());
return Status::OK();
}
@@ -551,12 +554,19 @@ void DBClientConnection::_checkConnection() {
// Don't hammer reconnects, backoff if needed
sleepFor(_autoReconnectBackoff.nextSleep());
- LOG(_logLevel) << "trying reconnect to " << toString() << endl;
+ LOGV2_DEBUG(20120,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "trying reconnect to {}",
+ ""_attr = toString());
string errmsg;
auto connectStatus = connect(_serverAddress, _applicationName);
if (!connectStatus.isOK()) {
_markFailed(kSetFlag);
- LOG(_logLevel) << "reconnect " << toString() << " failed " << errmsg << endl;
+ LOGV2_DEBUG(20121,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "reconnect {} failed {errmsg}",
+ ""_attr = toString(),
+ "errmsg"_attr = errmsg);
if (connectStatus == ErrorCodes::IncompatibleCatalogManager) {
uassertStatusOK(connectStatus); // Will always throw
} else {
@@ -564,7 +574,8 @@ void DBClientConnection::_checkConnection() {
}
}
- LOG(_logLevel) << "reconnect " << toString() << " ok" << endl;
+ LOGV2_DEBUG(
+ 20122, logSeverityV1toV2(_logLevel).toInt(), "reconnect {} ok", ""_attr = toString());
if (_internalAuthOnReconnect) {
uassertStatusOK(authenticateInternalUser());
} else {
@@ -572,10 +583,16 @@ void DBClientConnection::_checkConnection() {
try {
DBClientConnection::_auth(kv.second);
} catch (ExceptionFor<ErrorCodes::AuthenticationFailed>& ex) {
- LOG(_logLevel) << "reconnect: auth failed "
- << kv.second[auth::getSaslCommandUserDBFieldName()]
- << kv.second[auth::getSaslCommandUserFieldName()] << ' ' << ex.what()
- << std::endl;
+ LOGV2_DEBUG(20123,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "reconnect: auth failed "
+ "{kv_second_auth_getSaslCommandUserDBFieldName}{kv_second_auth_"
+ "getSaslCommandUserFieldName} {ex_what}",
+ "kv_second_auth_getSaslCommandUserDBFieldName"_attr =
+ kv.second[auth::getSaslCommandUserDBFieldName()],
+ "kv_second_auth_getSaslCommandUserFieldName"_attr =
+ kv.second[auth::getSaslCommandUserFieldName()],
+ "ex_what"_attr = ex.what());
}
}
}
@@ -728,8 +745,10 @@ bool DBClientConnection::call(Message& toSend,
auto sinkStatus = _session->sinkMessage(swm.getValue());
if (!sinkStatus.isOK()) {
- log() << "DBClientConnection failed to send message to " << getServerAddress() << " - "
- << redact(sinkStatus);
+ LOGV2(20124,
+ "DBClientConnection failed to send message to {getServerAddress} - {sinkStatus}",
+ "getServerAddress"_attr = getServerAddress(),
+ "sinkStatus"_attr = redact(sinkStatus));
return maybeThrow(sinkStatus);
}
@@ -737,8 +756,11 @@ bool DBClientConnection::call(Message& toSend,
if (swm.isOK()) {
response = std::move(swm.getValue());
} else {
- log() << "DBClientConnection failed to receive message from " << getServerAddress() << " - "
- << redact(swm.getStatus());
+ LOGV2(20125,
+ "DBClientConnection failed to receive message from {getServerAddress} - "
+ "{swm_getStatus}",
+ "getServerAddress"_attr = getServerAddress(),
+ "swm_getStatus"_attr = redact(swm.getStatus()));
return maybeThrow(swm.getStatus());
}
diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp
index 7639abe1ec6..4fa665c5e14 100644
--- a/src/mongo/client/dbclient_cursor.cpp
+++ b/src/mongo/client/dbclient_cursor.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/getmore_request.h"
#include "mongo/db/query/query_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/factory.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata.h"
@@ -203,13 +204,13 @@ bool DBClientCursor::init() {
_client->call(toSend, reply, true, &_originalHost);
} catch (const DBException&) {
// log msg temp?
- log() << "DBClientCursor::init call() failed" << endl;
+ LOGV2(20127, "DBClientCursor::init call() failed");
// We always want to throw on network exceptions.
throw;
}
if (reply.empty()) {
// log msg temp?
- log() << "DBClientCursor::init message from call() was empty" << endl;
+ LOGV2(20128, "DBClientCursor::init message from call() was empty");
return false;
}
dataReceived(reply);
@@ -235,9 +236,11 @@ bool DBClientCursor::initLazyFinish(bool& retry) {
// If we get a bad response, return false
if (!recvStatus.isOK() || reply.empty()) {
if (!recvStatus.isOK())
- log() << "DBClientCursor::init lazy say() failed: " << redact(recvStatus) << endl;
+ LOGV2(20129,
+ "DBClientCursor::init lazy say() failed: {recvStatus}",
+ "recvStatus"_attr = redact(recvStatus));
if (reply.empty())
- log() << "DBClientCursor::init message from say() was empty" << endl;
+ LOGV2(20130, "DBClientCursor::init message from say() was empty");
_client->checkResponse({}, true, &retry, &_lazyHost);
diff --git a/src/mongo/client/dbclient_cursor_test.cpp b/src/mongo/client/dbclient_cursor_test.cpp
index cf4864e70f3..41641170333 100644
--- a/src/mongo/client/dbclient_cursor_test.cpp
+++ b/src/mongo/client/dbclient_cursor_test.cpp
@@ -27,11 +27,15 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/client/dbclient_connection.h"
#include "mongo/client/dbclient_cursor.h"
#include "mongo/db/query/cursor_response.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace {
@@ -78,7 +82,7 @@ public:
// No-op.
void killCursor(const NamespaceString& ns, long long cursorID) override {
- unittest::log() << "Killing cursor in DBClientConnectionForTest";
+ LOGV2(20131, "Killing cursor in DBClientConnectionForTest");
}
void setSupportedProtocols(rpc::ProtocolSet protocols) {
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp
index 25fd973fc8f..b71f63fa2ec 100644
--- a/src/mongo/client/dbclient_rs.cpp
+++ b/src/mongo/client/dbclient_rs.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/auth/sasl_command_constants.h"
#include "mongo/db/dbmessage.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -158,9 +159,10 @@ ReplicaSetMonitorPtr DBClientReplicaSet::_getMonitor() {
// This can't throw an exception because it is called in the destructor of ScopedDbConnection
string DBClientReplicaSet::getServerAddress() const {
if (!_rsm) {
- warning() << "Trying to get server address for DBClientReplicaSet, but no "
- "ReplicaSetMonitor exists for "
- << _setName;
+ LOGV2_WARNING(20147,
+ "Trying to get server address for DBClientReplicaSet, but no "
+ "ReplicaSetMonitor exists for {setName}",
+ "setName"_attr = _setName);
return str::stream() << _setName << "/";
}
return _rsm->getServerAddress();
@@ -358,7 +360,10 @@ void DBClientReplicaSet::_authConnection(DBClientConnection* conn) {
if (_internalAuthRequested) {
auto status = conn->authenticateInternalUser();
if (!status.isOK()) {
- warning() << "cached auth failed for set " << _setName << ": " << status;
+ LOGV2_WARNING(20148,
+ "cached auth failed for set {setName}: {status}",
+ "setName"_attr = _setName,
+ "status"_attr = status);
}
return;
}
@@ -367,9 +372,15 @@ void DBClientReplicaSet::_authConnection(DBClientConnection* conn) {
try {
conn->auth(i->second);
} catch (const AssertionException&) {
- warning() << "cached auth failed for set: " << _setName
- << " db: " << i->second[saslCommandUserDBFieldName].str()
- << " user: " << i->second[saslCommandUserFieldName].str() << endl;
+ LOGV2_WARNING(20149,
+ "cached auth failed for set: {setName} db: "
+ "{i_second_saslCommandUserDBFieldName_str} user: "
+ "{i_second_saslCommandUserFieldName_str}",
+ "setName"_attr = _setName,
+ "i_second_saslCommandUserDBFieldName_str"_attr =
+ i->second[saslCommandUserDBFieldName].str(),
+ "i_second_saslCommandUserFieldName_str"_attr =
+ i->second[saslCommandUserFieldName].str());
}
}
}
@@ -381,8 +392,11 @@ void DBClientReplicaSet::logoutAll(DBClientConnection* conn) {
try {
conn->logout(i->first, response);
} catch (const AssertionException& ex) {
- warning() << "Failed to logout: " << conn->getServerAddress() << " on db: " << i->first
- << causedBy(redact(ex));
+ LOGV2_WARNING(20150,
+ "Failed to logout: {conn_getServerAddress} on db: {i_first}{causedBy_ex}",
+ "conn_getServerAddress"_attr = conn->getServerAddress(),
+ "i_first"_attr = i->first,
+ "causedBy_ex"_attr = causedBy(redact(ex)));
}
}
}
@@ -416,7 +430,10 @@ Status DBClientReplicaSet::_runAuthLoop(Authenticate authCb) {
const auto readPref =
std::make_shared<ReadPreferenceSetting>(ReadPreference::PrimaryPreferred, TagSet());
- LOG(3) << "dbclient_rs authentication of " << _getMonitor()->getName();
+ LOGV2_DEBUG(20132,
+ 3,
+ "dbclient_rs authentication of {getMonitor_getName}",
+ "getMonitor_getName"_attr = _getMonitor()->getName());
// NOTE that we retry MAX_RETRY + 1 times, since we're always primary preferred we don't
// fallback to the primary.
@@ -533,14 +550,19 @@ unique_ptr<DBClientCursor> DBClientReplicaSet::query(const NamespaceStringOrUUID
invariant(nsOrUuid.nss());
const string ns = nsOrUuid.nss()->ns();
if (_isSecondaryQuery(ns, query.obj, *readPref)) {
- LOG(3) << "dbclient_rs query using secondary or tagged node selection in "
- << _getMonitor()->getName() << ", read pref is " << readPref->toString()
- << " (primary : "
- << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]")
- << ", lastTagged : "
- << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
- : "[not cached]")
- << ")" << endl;
+ LOGV2_DEBUG(20133,
+ 3,
+ "dbclient_rs query using secondary or tagged node selection in "
+ "{getMonitor_getName}, read pref is {readPref} (primary : "
+ "{master_get_nullptr_master_getServerAddress_not_cached}, lastTagged : "
+ "{lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached})",
+ "getMonitor_getName"_attr = _getMonitor()->getName(),
+ "readPref"_attr = readPref->toString(),
+ "master_get_nullptr_master_getServerAddress_not_cached"_attr =
+ (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]"),
+ "lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached"_attr =
+ (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
+ : "[not cached]"));
string lastNodeErrMsg;
@@ -573,7 +595,10 @@ unique_ptr<DBClientCursor> DBClientReplicaSet::query(const NamespaceStringOrUUID
uasserted(16370, assertMsg.str());
}
- LOG(3) << "dbclient_rs query to primary node in " << _getMonitor()->getName() << endl;
+ LOGV2_DEBUG(20134,
+ 3,
+ "dbclient_rs query to primary node in {getMonitor_getName}",
+ "getMonitor_getName"_attr = _getMonitor()->getName());
return checkMaster()->query(
nsOrUuid, query, nToReturn, nToSkip, fieldsToReturn, queryOptions, batchSize);
@@ -585,14 +610,19 @@ BSONObj DBClientReplicaSet::findOne(const string& ns,
int queryOptions) {
shared_ptr<ReadPreferenceSetting> readPref(_extractReadPref(query.obj, queryOptions));
if (_isSecondaryQuery(ns, query.obj, *readPref)) {
- LOG(3) << "dbclient_rs findOne using secondary or tagged node selection in "
- << _getMonitor()->getName() << ", read pref is " << readPref->toString()
- << " (primary : "
- << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]")
- << ", lastTagged : "
- << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
- : "[not cached]")
- << ")" << endl;
+ LOGV2_DEBUG(20135,
+ 3,
+ "dbclient_rs findOne using secondary or tagged node selection in "
+ "{getMonitor_getName}, read pref is {readPref} (primary : "
+ "{master_get_nullptr_master_getServerAddress_not_cached}, lastTagged : "
+ "{lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached})",
+ "getMonitor_getName"_attr = _getMonitor()->getName(),
+ "readPref"_attr = readPref->toString(),
+ "master_get_nullptr_master_getServerAddress_not_cached"_attr =
+ (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]"),
+ "lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached"_attr =
+ (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
+ : "[not cached]"));
string lastNodeErrMsg;
@@ -622,7 +652,10 @@ BSONObj DBClientReplicaSet::findOne(const string& ns,
uasserted(16379, assertMsg.str());
}
- LOG(3) << "dbclient_rs findOne to primary node in " << _getMonitor()->getName() << endl;
+ LOGV2_DEBUG(20136,
+ 3,
+ "dbclient_rs findOne to primary node in {getMonitor_getName}",
+ "getMonitor_getName"_attr = _getMonitor()->getName());
return checkMaster()->findOne(ns, query, fieldsToReturn, queryOptions);
}
@@ -682,7 +715,10 @@ void DBClientReplicaSet::isntSecondary() {
DBClientConnection* DBClientReplicaSet::selectNodeUsingTags(
shared_ptr<ReadPreferenceSetting> readPref) {
if (checkLastHost(readPref.get())) {
- LOG(3) << "dbclient_rs selecting compatible last used node " << _lastSlaveOkHost;
+ LOGV2_DEBUG(20137,
+ 3,
+ "dbclient_rs selecting compatible last used node {lastSlaveOkHost}",
+ "lastSlaveOkHost"_attr = _lastSlaveOkHost);
return _lastSlaveOkConn.get();
}
@@ -691,8 +727,11 @@ DBClientConnection* DBClientReplicaSet::selectNodeUsingTags(
auto selectedNodeStatus = monitor->getHostOrRefresh(*readPref).getNoThrow();
if (!selectedNodeStatus.isOK()) {
- LOG(3) << "dbclient_rs no compatible node found"
- << causedBy(redact(selectedNodeStatus.getStatus()));
+ LOGV2_DEBUG(20138,
+ 3,
+ "dbclient_rs no compatible node found{causedBy_selectedNodeStatus_getStatus}",
+ "causedBy_selectedNodeStatus_getStatus"_attr =
+ causedBy(redact(selectedNodeStatus.getStatus())));
return nullptr;
}
@@ -712,7 +751,10 @@ DBClientConnection* DBClientReplicaSet::selectNodeUsingTags(
if (monitor->isPrimary(selectedNode)) {
checkMaster();
- LOG(3) << "dbclient_rs selecting primary node " << selectedNode << endl;
+ LOGV2_DEBUG(20139,
+ 3,
+ "dbclient_rs selecting primary node {selectedNode}",
+ "selectedNode"_attr = selectedNode);
_lastSlaveOkConn = _master;
@@ -748,7 +790,10 @@ DBClientConnection* DBClientReplicaSet::selectNodeUsingTags(
// Mongos pooled connections are authenticated through ShardingConnectionHook::onCreate()
}
- LOG(3) << "dbclient_rs selecting node " << _lastSlaveOkHost << endl;
+ LOGV2_DEBUG(20140,
+ 3,
+ "dbclient_rs selecting node {lastSlaveOkHost}",
+ "lastSlaveOkHost"_attr = _lastSlaveOkHost);
return _lastSlaveOkConn.get();
}
@@ -766,14 +811,20 @@ void DBClientReplicaSet::say(Message& toSend, bool isRetry, string* actualServer
shared_ptr<ReadPreferenceSetting> readPref(_extractReadPref(qm.query, qm.queryOptions));
if (_isSecondaryQuery(qm.ns, qm.query, *readPref)) {
- LOG(3) << "dbclient_rs say using secondary or tagged node selection in "
- << _getMonitor()->getName() << ", read pref is " << readPref->toString()
- << " (primary : "
- << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]")
- << ", lastTagged : "
- << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
- : "[not cached]")
- << ")" << endl;
+ LOGV2_DEBUG(
+ 20141,
+ 3,
+ "dbclient_rs say using secondary or tagged node selection in {getMonitor_getName}, "
+ "read pref is {readPref} (primary : "
+ "{master_get_nullptr_master_getServerAddress_not_cached}, lastTagged : "
+ "{lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached})",
+ "getMonitor_getName"_attr = _getMonitor()->getName(),
+ "readPref"_attr = readPref->toString(),
+ "master_get_nullptr_master_getServerAddress_not_cached"_attr =
+ (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]"),
+ "lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached"_attr =
+ (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
+ : "[not cached]"));
string lastNodeErrMsg;
@@ -818,7 +869,10 @@ void DBClientReplicaSet::say(Message& toSend, bool isRetry, string* actualServer
}
}
- LOG(3) << "dbclient_rs say to primary node in " << _getMonitor()->getName() << endl;
+ LOGV2_DEBUG(20142,
+ 3,
+ "dbclient_rs say to primary node in {getMonitor_getName}",
+ "getMonitor_getName"_attr = _getMonitor()->getName());
DBClientConnection* master = checkMaster();
if (actualServer)
@@ -840,8 +894,10 @@ Status DBClientReplicaSet::recv(Message& m, int lastRequestId) {
try {
return _lazyState._lastClient->recv(m, lastRequestId);
} catch (DBException& e) {
- log() << "could not receive data from " << _lazyState._lastClient->toString()
- << causedBy(redact(e));
+ LOGV2(20143,
+ "could not receive data from {lazyState_lastClient}{causedBy_e}",
+ "lazyState_lastClient"_attr = _lazyState._lastClient->toString(),
+ "causedBy_e"_attr = causedBy(redact(e)));
return e.toStatus();
}
}
@@ -891,17 +947,20 @@ void DBClientReplicaSet::checkResponse(const std::vector<BSONObj>& batch,
} else if (_lazyState._lastClient == _master.get()) {
isntMaster();
} else {
- warning() << "passed " << redact(dataObj) << " but last rs client "
- << _lazyState._lastClient->toString() << " is not master or secondary"
- << endl;
+ LOGV2_WARNING(20151,
+ "passed {dataObj} but last rs client {lazyState_lastClient} is not "
+ "master or secondary",
+ "dataObj"_attr = redact(dataObj),
+ "lazyState_lastClient"_attr = _lazyState._lastClient->toString());
}
if (_lazyState._retries < static_cast<int>(MAX_RETRY)) {
_lazyState._retries++;
*retry = true;
} else {
- log() << "too many retries (" << _lazyState._retries
- << "), could not get data from replica set" << endl;
+ LOGV2(20144,
+ "too many retries ({lazyState_retries}), could not get data from replica set",
+ "lazyState_retries"_attr = _lazyState._retries);
}
}
} else if (_lazyState._lastOp == dbQuery) {
@@ -997,14 +1056,20 @@ bool DBClientReplicaSet::call(Message& toSend,
shared_ptr<ReadPreferenceSetting> readPref(_extractReadPref(qm.query, qm.queryOptions));
if (_isSecondaryQuery(ns, qm.query, *readPref)) {
- LOG(3) << "dbclient_rs call using secondary or tagged node selection in "
- << _getMonitor()->getName() << ", read pref is " << readPref->toString()
- << " (primary : "
- << (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]")
- << ", lastTagged : "
- << (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
- : "[not cached]")
- << ")" << endl;
+ LOGV2_DEBUG(
+ 20145,
+ 3,
+ "dbclient_rs call using secondary or tagged node selection in "
+ "{getMonitor_getName}, read pref is {readPref} (primary : "
+ "{master_get_nullptr_master_getServerAddress_not_cached}, lastTagged : "
+ "{lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached})",
+ "getMonitor_getName"_attr = _getMonitor()->getName(),
+ "readPref"_attr = readPref->toString(),
+ "master_get_nullptr_master_getServerAddress_not_cached"_attr =
+ (_master.get() != nullptr ? _master->getServerAddress() : "[not cached]"),
+ "lastSlaveOkConn_get_nullptr_lastSlaveOkConn_getServerAddress_not_cached"_attr =
+ (_lastSlaveOkConn.get() != nullptr ? _lastSlaveOkConn->getServerAddress()
+ : "[not cached]"));
for (size_t retry = 0; retry < MAX_RETRY; retry++) {
try {
@@ -1034,7 +1099,10 @@ bool DBClientReplicaSet::call(Message& toSend,
}
}
- LOG(3) << "dbclient_rs call to primary node in " << _getMonitor()->getName() << endl;
+ LOGV2_DEBUG(20146,
+ 3,
+ "dbclient_rs call to primary node in {getMonitor_getName}",
+ "getMonitor_getName"_attr = _getMonitor()->getName());
DBClientConnection* m = checkMaster();
if (actualServer)
diff --git a/src/mongo/client/mongo_uri_test.cpp b/src/mongo/client/mongo_uri_test.cpp
index e80abbf5e6b..badc6cf3a96 100644
--- a/src/mongo/client/mongo_uri_test.cpp
+++ b/src/mongo/client/mongo_uri_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <fstream>
@@ -39,6 +41,8 @@
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/logv2/log.h"
+#include "mongo/util/log.h"
#include <boost/filesystem/operations.hpp>
#include <boost/optional.hpp>
#include <boost/optional/optional_io.hpp>
@@ -84,11 +88,16 @@ void compareOptions(size_t lineNumber,
for (std::size_t i = 0; i < std::min(options.size(), expectedOptions.size()); ++i) {
if (options[i] != expectedOptions[i]) {
- unittest::log() << "Option: \"tolower(" << options[i].first.original()
- << ")=" << options[i].second << "\" doesn't equal: \"tolower("
- << expectedOptions[i].first.original()
- << ")=" << expectedOptions[i].second << "\""
- << " data on line: " << lineNumber << std::endl;
+ LOGV2(
+ 20152,
+ "Option: \"tolower({options_i_first_original})={options_i_second}\" doesn't equal: "
+ "\"tolower({expectedOptions_i_first_original})={expectedOptions_i_second}\" data "
+ "on line: {lineNumber}",
+ "options_i_first_original"_attr = options[i].first.original(),
+ "options_i_second"_attr = options[i].second,
+ "expectedOptions_i_first_original"_attr = expectedOptions[i].first.original(),
+ "expectedOptions_i_second"_attr = expectedOptions[i].second,
+ "lineNumber"_attr = lineNumber);
std::cerr << "Failing URI: \"" << uri << "\""
<< " data on line: " << lineNumber << std::endl;
ASSERT(false);
@@ -594,7 +603,7 @@ std::string returnStringFromElementOrNull(BSONElement element) {
// Helper method to take a valid test case, parse() it, and assure the output is correct
void testValidURIFormat(URITestCase testCase) {
- unittest::log() << "Testing URI: " << testCase.URI << '\n';
+ LOGV2(20153, "Testing URI: {testCase_URI}", "testCase_URI"_attr = testCase.URI);
std::string errMsg;
const auto cs_status = MongoURI::parse(testCase.URI);
ASSERT_OK(cs_status);
@@ -622,7 +631,7 @@ TEST(MongoURI, InvalidURIs) {
for (size_t i = 0; i != numCases; ++i) {
const InvalidURITestCase testCase = invalidCases[i];
- unittest::log() << "Testing URI: " << testCase.URI << '\n';
+ LOGV2(20154, "Testing URI: {testCase_URI}", "testCase_URI"_attr = testCase.URI);
auto cs_status = MongoURI::parse(testCase.URI);
ASSERT_NOT_OK(cs_status);
if (testCase.code) {
@@ -704,7 +713,7 @@ TEST(MongoURI, specTests) {
if (!valid) {
// This uri string is invalid --> parse the uri and ensure it fails
const InvalidURITestCase testCase = InvalidURITestCase{uri};
- unittest::log() << "Testing URI: " << testCase.URI << '\n';
+ LOGV2(20155, "Testing URI: {testCase_URI}", "testCase_URI"_attr = testCase.URI);
auto cs_status = MongoURI::parse(testCase.URI);
ASSERT_NOT_OK(cs_status);
} else {
diff --git a/src/mongo/client/remote_command_retry_scheduler_test.cpp b/src/mongo/client/remote_command_retry_scheduler_test.cpp
index fa887a6eb9d..03bcbd44fe8 100644
--- a/src/mongo/client/remote_command_retry_scheduler_test.cpp
+++ b/src/mongo/client/remote_command_retry_scheduler_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <memory>
@@ -39,9 +41,11 @@
#include "mongo/executor/remote_command_response.h"
#include "mongo/executor/task_executor.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/task_executor_proxy.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/log.h"
#include "mongo/util/net/hostandport.h"
namespace {
@@ -555,7 +559,9 @@ TEST_F(RemoteCommandRetrySchedulerTest,
request,
[&result,
sharedCallbackData](const executor::TaskExecutor::RemoteCommandCallbackArgs& rcba) {
- unittest::log() << "setting result to " << rcba.response.status;
+ LOGV2(20156,
+ "setting result to {rcba_response_status}",
+ "rcba_response_status"_attr = rcba.response.status);
result = rcba.response.status;
},
std::move(policy));
diff --git a/src/mongo/client/remote_command_targeter_rs.cpp b/src/mongo/client/remote_command_targeter_rs.cpp
index 97eae89da0d..d5640d3a4ae 100644
--- a/src/mongo/client/remote_command_targeter_rs.cpp
+++ b/src/mongo/client/remote_command_targeter_rs.cpp
@@ -38,6 +38,7 @@
#include "mongo/client/read_preference.h"
#include "mongo/client/replica_set_monitor.h"
#include "mongo/db/operation_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/net/hostandport.h"
@@ -52,9 +53,15 @@ RemoteCommandTargeterRS::RemoteCommandTargeterRS(const std::string& rsName,
std::set<HostAndPort> seedServers(seedHosts.begin(), seedHosts.end());
_rsMonitor = ReplicaSetMonitor::createIfNeeded(rsName, seedServers);
- LOG(1) << "Started targeter for "
- << ConnectionString::forReplicaSet(
- rsName, std::vector<HostAndPort>(seedServers.begin(), seedServers.end()));
+ LOGV2_DEBUG(
+ 20157,
+ 1,
+ "Started targeter for "
+ "{ConnectionString_forReplicaSet_rsName_std_vector_HostAndPort_seedServers_begin_"
+ "seedServers_end}",
+ "ConnectionString_forReplicaSet_rsName_std_vector_HostAndPort_seedServers_begin_seedServers_end"_attr =
+ ConnectionString::forReplicaSet(
+ rsName, std::vector<HostAndPort>(seedServers.begin(), seedServers.end())));
}
ConnectionString RemoteCommandTargeterRS::connectionString() {
diff --git a/src/mongo/client/replica_set_change_notifier.cpp b/src/mongo/client/replica_set_change_notifier.cpp
index 3f23418c08e..b0a35057dd9 100644
--- a/src/mongo/client/replica_set_change_notifier.cpp
+++ b/src/mongo/client/replica_set_change_notifier.cpp
@@ -33,6 +33,7 @@
#include "mongo/client/replica_set_change_notifier.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/stacktrace.h"
@@ -54,7 +55,7 @@ void ReplicaSetChangeNotifier::_removeListener(Listener* listener) {
}
void ReplicaSetChangeNotifier::onFoundSet(const std::string& name) noexcept {
- LOG(2) << "Signaling found set " << name;
+ LOGV2_DEBUG(20158, 2, "Signaling found set {name}", "name"_attr = name);
stdx::unique_lock<Latch> lk(_mutex);
@@ -69,7 +70,10 @@ void ReplicaSetChangeNotifier::onFoundSet(const std::string& name) noexcept {
}
void ReplicaSetChangeNotifier::onPossibleSet(ConnectionString connectionString) noexcept {
- LOG(2) << "Signaling possible set " << connectionString;
+ LOGV2_DEBUG(20159,
+ 2,
+ "Signaling possible set {connectionString}",
+ "connectionString"_attr = connectionString);
const auto& name = connectionString.getSetName();
@@ -96,7 +100,11 @@ void ReplicaSetChangeNotifier::onPossibleSet(ConnectionString connectionString)
void ReplicaSetChangeNotifier::onConfirmedSet(ConnectionString connectionString,
HostAndPort primary,
std::set<HostAndPort> passives) noexcept {
- LOG(2) << "Signaling confirmed set " << connectionString << " with primary " << primary;
+ LOGV2_DEBUG(20160,
+ 2,
+ "Signaling confirmed set {connectionString} with primary {primary}",
+ "connectionString"_attr = connectionString,
+ "primary"_attr = primary);
const auto& name = connectionString.getSetName();
stdx::unique_lock<Latch> lk(_mutex);
@@ -121,7 +129,7 @@ void ReplicaSetChangeNotifier::onConfirmedSet(ConnectionString connectionString,
}
void ReplicaSetChangeNotifier::onDroppedSet(const std::string& name) noexcept {
- LOG(2) << "Signaling dropped set " << name;
+ LOGV2_DEBUG(20161, 2, "Signaling dropped set {name}", "name"_attr = name);
stdx::unique_lock<Latch> lk(_mutex);
diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp
index 1098b74b047..e5604439330 100644
--- a/src/mongo/client/replica_set_monitor.cpp
+++ b/src/mongo/client/replica_set_monitor.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/bson_extract_optime.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/platform/mutex.h"
#include "mongo/stdx/condition_variable.h"
@@ -195,7 +196,8 @@ ReplicaSetMonitor::ReplicaSetMonitor(const MongoURI& uri)
void ReplicaSetMonitor::init() {
if (areRefreshRetriesDisabledForTest.load()) {
// This is for MockReplicaSet. Those tests want to control when scanning happens.
- warning() << "*** Not starting background refresh because refresh retries are disabled.";
+ LOGV2_WARNING(20180,
+ "*** Not starting background refresh because refresh retries are disabled.");
return;
}
@@ -245,7 +247,10 @@ void ReplicaSetMonitor::SetState::rescheduleRefresh(SchedulingStrategy strategy)
}
if (isDropped) { // already removed so no need to refresh
- LOG(1) << "Stopping refresh for replica set " << name << " because it's removed";
+ LOGV2_DEBUG(20162,
+ 1,
+ "Stopping refresh for replica set {name} because it's removed",
+ "name"_attr = name);
return;
}
@@ -270,7 +275,10 @@ void ReplicaSetMonitor::SetState::rescheduleRefresh(SchedulingStrategy strategy)
}
nextScanTime = possibleNextScanTime;
- LOG(1) << "Next replica set scan scheduled for " << nextScanTime;
+ LOGV2_DEBUG(20163,
+ 1,
+ "Next replica set scan scheduled for {nextScanTime}",
+ "nextScanTime"_attr = nextScanTime);
auto swHandle = scheduleWorkAt(nextScanTime, [this](const CallbackArgs& cbArgs) {
if (cbArgs.myHandle != refresherHandle)
return; // We've been replaced!
@@ -286,13 +294,18 @@ void ReplicaSetMonitor::SetState::rescheduleRefresh(SchedulingStrategy strategy)
});
if (ErrorCodes::isShutdownError(swHandle.getStatus().code())) {
- LOG(1) << "Cant schedule refresh for " << name << ". Executor shutdown in progress";
+ LOGV2_DEBUG(20164,
+ 1,
+ "Cant schedule refresh for {name}. Executor shutdown in progress",
+ "name"_attr = name);
return;
}
if (!swHandle.isOK()) {
- severe() << "Can't continue refresh for replica set " << name << " due to "
- << redact(swHandle.getStatus());
+ LOGV2_FATAL(20184,
+ "Can't continue refresh for replica set {name} due to {swHandle_getStatus}",
+ "name"_attr = name,
+ "swHandle_getStatus"_attr = redact(swHandle.getStatus()));
fassertFailed(40140);
}
@@ -552,8 +565,11 @@ void Refresher::scheduleNetworkRequests() {
}
if (!swHandle.isOK()) {
- severe() << "Can't continue scan for replica set " << _set->name << " due to "
- << redact(swHandle.getStatus());
+ LOGV2_FATAL(
+ 20185,
+ "Can't continue scan for replica set {set_name} due to {swHandle_getStatus}",
+ "set_name"_attr = _set->name,
+ "swHandle_getStatus"_attr = redact(swHandle.getStatus()));
fassertFailed(31176);
}
@@ -649,7 +665,8 @@ Refresher::NextStep Refresher::getNextStep() {
if (_scan->hostsToScan.empty()) {
// We've tried all hosts we can, so nothing more to do in this round.
if (!_scan->foundUpMaster) {
- warning() << "Unable to reach primary for set " << _set->name;
+ LOGV2_WARNING(
+ 20181, "Unable to reach primary for set {set_name}", "set_name"_attr = _set->name);
// Since we've talked to everyone we could but still didn't find a primary, we
// do the best we can, and assume all unconfirmedReplies are actually from nodes
@@ -682,10 +699,12 @@ Refresher::NextStep Refresher::getNextStep() {
} else {
auto nScans = _set->consecutiveFailedScans++;
if (nScans <= 10 || nScans % 10 == 0) {
- log() << "Cannot reach any nodes for set " << _set->name
- << ". Please check network connectivity and the status of the set. "
- << "This has happened for " << _set->consecutiveFailedScans
- << " checks in a row.";
+ LOGV2(20165,
+ "Cannot reach any nodes for set {set_name}. Please check network "
+ "connectivity and the status of the set. This has happened for "
+ "{set_consecutiveFailedScans} checks in a row.",
+ "set_name"_attr = _set->name,
+ "set_consecutiveFailedScans"_attr = _set->consecutiveFailedScans);
}
}
@@ -693,8 +712,11 @@ Refresher::NextStep Refresher::getNextStep() {
_set->currentScan.reset();
_set->notify();
- LOG(1) << "Refreshing replica set " << _set->name << " took " << _scan->timer.millis()
- << "ms";
+ LOGV2_DEBUG(20166,
+ 1,
+ "Refreshing replica set {set_name} took {scan_timer_millis}ms",
+ "set_name"_attr = _set->name,
+ "scan_timer_millis"_attr = _scan->timer.millis());
return NextStep(NextStep::DONE);
}
@@ -732,9 +754,13 @@ void Refresher::receivedIsMaster(const HostAndPort& from,
_scan->possibleNodes.insert(reply.members.begin(), reply.members.end());
}
} else {
- error() << "replset name mismatch: expected \"" << _set->name << "\", "
- << "but remote node " << from << " has replset name \"" << reply.setName << "\""
- << ", ismaster: " << replyObj;
+ LOGV2_ERROR(20183,
+ "replset name mismatch: expected \"{set_name}\", but remote node {from} "
+ "has replset name \"{reply_setName}\", ismaster: {replyObj}",
+ "set_name"_attr = _set->name,
+ "from"_attr = from,
+ "reply_setName"_attr = reply.setName,
+ "replyObj"_attr = replyObj);
}
failedHost(from,
@@ -861,8 +887,12 @@ Status Refresher::receivedIsMasterFromMaster(const HostAndPort& from, const IsMa
// REMINDER: both _set->nodes and reply.members are sorted.
if (_set->nodes.size() != reply.members.size() ||
!std::equal(_set->nodes.begin(), _set->nodes.end(), reply.members.begin(), hostsEqual)) {
- LOG(2) << "Adjusting nodes in our view of replica set " << _set->name
- << " based on master reply: " << redact(reply.raw);
+ LOGV2_DEBUG(20167,
+ 2,
+ "Adjusting nodes in our view of replica set {set_name} based on master reply: "
+ "{reply_raw}",
+ "set_name"_attr = _set->name,
+ "reply_raw"_attr = redact(reply.raw));
// remove non-members from _set->nodes
_set->nodes.erase(
@@ -900,7 +930,10 @@ Status Refresher::receivedIsMasterFromMaster(const HostAndPort& from, const IsMa
// LogLevel can be pretty low, since replica set reconfiguration should be pretty rare
// and we want to record our changes
- log() << "Confirmed replica set for " << _set->name << " is " << _set->seedConnStr;
+ LOGV2(20168,
+ "Confirmed replica set for {set_name} is {set_seedConnStr}",
+ "set_name"_attr = _set->name,
+ "set_seedConnStr"_attr = _set->seedConnStr);
_set->notifier->onConfirmedSet(_set->seedConnStr, reply.host, reply.passives);
}
@@ -971,7 +1004,10 @@ void IsMasterReply::parse(const BSONObj& obj) {
}
} catch (const std::exception& e) {
ok = false;
- log() << "exception while parsing isMaster reply: " << e.what() << " " << obj;
+ LOGV2(20169,
+ "exception while parsing isMaster reply: {e_what} {obj}",
+ "e_what"_attr = e.what(),
+ "obj"_attr = obj);
}
}
@@ -979,7 +1015,10 @@ Node::Node(const HostAndPort& host) : host(host), latencyMicros(unknownLatency)
void Node::markFailed(const Status& status) {
if (isUp) {
- log() << "Marking host " << host << " as failed" << causedBy(redact(status));
+ LOGV2(20170,
+ "Marking host {host} as failed{causedBy_status}",
+ "host"_attr = host,
+ "causedBy_status"_attr = causedBy(redact(status)));
isUp = false;
}
@@ -989,11 +1028,15 @@ void Node::markFailed(const Status& status) {
bool Node::matches(const ReadPreference pref) const {
if (!isUp) {
- LOG(3) << "Host " << host << " is not up";
+ LOGV2_DEBUG(20171, 3, "Host {host} is not up", "host"_attr = host);
return false;
}
- LOG(3) << "Host " << host << " is " << (isMaster ? "primary" : "not primary");
+ LOGV2_DEBUG(20172,
+ 3,
+ "Host {host} is {isMaster_primary_not_primary}",
+ "host"_attr = host,
+ "isMaster_primary_not_primary"_attr = (isMaster ? "primary" : "not primary"));
if (pref == ReadPreference::PrimaryOnly) {
return isMaster;
}
@@ -1020,7 +1063,11 @@ void Node::update(const IsMasterReply& reply) {
invariant(host == reply.host);
invariant(reply.ok);
- LOG(3) << "Updating host " << host << " based on ismaster reply: " << reply.raw;
+ LOGV2_DEBUG(20173,
+ 3,
+ "Updating host {host} based on ismaster reply: {reply_raw}",
+ "host"_attr = host,
+ "reply_raw"_attr = reply.raw);
// Nodes that are hidden or neither master or secondary are considered down since we can't
// send any operations to them.
@@ -1043,10 +1090,18 @@ void Node::update(const IsMasterReply& reply) {
}
}
- LOG(3) << "Updating " << host << " lastWriteDate to " << reply.lastWriteDate;
+ LOGV2_DEBUG(20174,
+ 3,
+ "Updating {host} lastWriteDate to {reply_lastWriteDate}",
+ "host"_attr = host,
+ "reply_lastWriteDate"_attr = reply.lastWriteDate);
lastWriteDate = reply.lastWriteDate;
- LOG(3) << "Updating " << host << " opTime to " << reply.opTime;
+ LOGV2_DEBUG(20175,
+ 3,
+ "Updating {host} opTime to {reply_opTime}",
+ "host"_attr = host,
+ "reply_opTime"_attr = reply.opTime);
opTime = reply.opTime;
lastWriteDateUpdateTime = Date_t::now();
}
@@ -1065,7 +1120,9 @@ SetState::SetState(const MongoURI& uri,
uassert(13642, "Replica set seed list can't be empty", !seedNodes.empty());
if (name.empty())
- warning() << "Replica set name empty, first node: " << *(seedNodes.begin());
+ LOGV2_WARNING(20182,
+ "Replica set name empty, first node: {seedNodes_begin}",
+ "seedNodes_begin"_attr = *(seedNodes.begin()));
// This adds the seed hosts to nodes, but they aren't usable for anything except seeding a
// scan until we start a scan and either find a master or contact all hosts without finding
@@ -1265,7 +1322,11 @@ Node* SetState::findOrCreateNode(const HostAndPort& host) {
// to consider alternate algorithms.
Nodes::iterator it = std::lower_bound(nodes.begin(), nodes.end(), host, compareHosts);
if (it == nodes.end() || it->host != host) {
- LOG(2) << "Adding node " << host << " to our view of replica set " << name;
+ LOGV2_DEBUG(20176,
+ 2,
+ "Adding node {host} to our view of replica set {name}",
+ "host"_attr = host,
+ "name"_attr = name);
it = nodes.insert(it, Node(host));
}
return &(*it);
@@ -1274,8 +1335,12 @@ Node* SetState::findOrCreateNode(const HostAndPort& host) {
void SetState::updateNodeIfInNodes(const IsMasterReply& reply) {
Node* node = findNode(reply.host);
if (!node) {
- LOG(2) << "Skipping application of ismaster reply from " << reply.host
- << " since it isn't a confirmed member of set " << name;
+ LOGV2_DEBUG(20177,
+ 2,
+ "Skipping application of ismaster reply from {reply_host} since it isn't a "
+ "confirmed member of set {name}",
+ "reply_host"_attr = reply.host,
+ "name"_attr = name);
return;
}
@@ -1321,12 +1386,16 @@ void SetState::notify() {
it->promise.emplaceValue(std::move(match));
waiters.erase(it++);
} else if (it->deadline <= cachedNow) {
- LOG(1) << "Unable to statisfy read preference " << it->criteria << " by deadline "
- << it->deadline;
+ LOGV2_DEBUG(
+ 20178,
+ 1,
+ "Unable to statisfy read preference {it_criteria} by deadline {it_deadline}",
+ "it_criteria"_attr = it->criteria,
+ "it_deadline"_attr = it->deadline);
it->promise.setError(makeUnsatisfedReadPrefError(it->criteria));
waiters.erase(it++);
} else if (shouldQuickFail) {
- LOG(1) << "Unable to statisfy read preference because tests fail quickly";
+ LOGV2_DEBUG(20179, 1, "Unable to statisfy read preference because tests fail quickly");
it->promise.setError(makeUnsatisfedReadPrefError(it->criteria));
waiters.erase(it++);
} else {
diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp
index 96d270a5e4e..8e27ca8e284 100644
--- a/src/mongo/client/replica_set_monitor_manager.cpp
+++ b/src/mongo/client/replica_set_monitor_manager.cpp
@@ -45,6 +45,7 @@
#include "mongo/executor/task_executor.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
#include "mongo/util/log.h"
@@ -121,7 +122,7 @@ shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorManager::getOrCreateMonitor(const
return monitor;
}
- log() << "Starting new replica set monitor for " << uri.toString();
+ LOGV2(20186, "Starting new replica set monitor for {uri}", "uri"_attr = uri.toString());
auto newMonitor = std::make_shared<ReplicaSetMonitor>(uri);
_monitors[setName] = newMonitor;
@@ -149,7 +150,8 @@ void ReplicaSetMonitorManager::removeMonitor(StringData setName) {
monitor->drop();
}
_monitors.erase(it);
- log() << "Removed ReplicaSetMonitor for replica set " << setName;
+ LOGV2(
+ 20187, "Removed ReplicaSetMonitor for replica set {setName}", "setName"_attr = setName);
}
}
@@ -172,12 +174,12 @@ void ReplicaSetMonitorManager::shutdown() {
}
if (taskExecutor) {
- LOG(1) << "Shutting down task executor used for monitoring replica sets";
+ LOGV2_DEBUG(20188, 1, "Shutting down task executor used for monitoring replica sets");
taskExecutor->shutdown();
}
if (monitors.size()) {
- log() << "Dropping all ongoing scans against replica sets";
+ LOGV2(20189, "Dropping all ongoing scans against replica sets");
}
for (auto& [name, monitor] : monitors) {
auto anchor = monitor.lock();
diff --git a/src/mongo/client/replica_set_monitor_scan_test.cpp b/src/mongo/client/replica_set_monitor_scan_test.cpp
index fdba042c86c..dfac48e56f8 100644
--- a/src/mongo/client/replica_set_monitor_scan_test.cpp
+++ b/src/mongo/client/replica_set_monitor_scan_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/client/replica_set_monitor_test_fixture.h"
#include "mongo/client/mongo_uri.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -1416,11 +1417,15 @@ TEST_F(MinOpTimeTest, MinOpTimeIgnored) {
class Listener : public ReplicaSetChangeNotifier::Listener {
public:
void logEvent(StringData name, const Key& key) {
- log() << name << ": " << key;
+ LOGV2(20190, "{name}: {key}", "name"_attr = name, "key"_attr = key);
}
void logEvent(StringData name, const State& state) {
- log() << name << ": "
- << "(" << state.generation << ") " << state.connStr << " | " << state.primary;
+ LOGV2(20191,
+ "{name}: ({state_generation}) {state_connStr} | {state_primary}",
+ "name"_attr = name,
+ "state_generation"_attr = state.generation,
+ "state_connStr"_attr = state.connStr,
+ "state_primary"_attr = state.primary);
}
void onFoundSet(const Key& key) noexcept override {
diff --git a/src/mongo/client/replica_set_monitor_test_concurrent.cpp b/src/mongo/client/replica_set_monitor_test_concurrent.cpp
index 55ac5e4716c..f5720053f4f 100644
--- a/src/mongo/client/replica_set_monitor_test_concurrent.cpp
+++ b/src/mongo/client/replica_set_monitor_test_concurrent.cpp
@@ -38,6 +38,7 @@
#include "mongo/executor/thread_pool_mock.h"
#include "mongo/executor/thread_pool_task_executor.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/duration.h"
#include "mongo/util/log.h"
@@ -102,15 +103,19 @@ protected:
const auto net = getNet();
const auto request = noi->getRequest();
_numChecks[request.target]++;
- LOG(2) << "at " << elapsed() << " got mock net operation " << request.toString();
+ LOGV2_DEBUG(20192,
+ 2,
+ "at {elapsed} got mock net operation {request}",
+ "elapsed"_attr = elapsed(),
+ "request"_attr = request.toString());
const auto node = replSet.getNode(request.target.toString());
if (node->isRunning()) {
const auto opmsg = OpMsgRequest::fromDBAndBody(request.dbname, request.cmdObj);
const auto reply = node->runCommand(request.id, opmsg)->getCommandReply();
- LOG(2) << "replying " << reply;
+ LOGV2_DEBUG(20193, 2, "replying {reply}", "reply"_attr = reply);
net->scheduleSuccessfulResponse(noi, RemoteCommandResponse(reply, Milliseconds(0)));
} else {
- LOG(2) << "black hole";
+ LOGV2_DEBUG(20194, 2, "black hole");
net->blackHole(noi);
}
net->runReadyNetworkOperations();
@@ -122,9 +127,13 @@ protected:
InNetworkGuard guard(net);
// Operations can happen inline with advanceTime(), so log before and after the call.
- LOG(3) << "Advancing time from " << elapsed() << " to " << (elapsed() + d);
+ LOGV2_DEBUG(20195,
+ 3,
+ "Advancing time from {elapsed} to {elapsed_d}",
+ "elapsed"_attr = elapsed(),
+ "elapsed_d"_attr = (elapsed() + d));
net->advanceTime(net->now() + d);
- LOG(3) << "Advanced to " << elapsed();
+ LOGV2_DEBUG(20196, 3, "Advanced to {elapsed}", "elapsed"_attr = elapsed());
}
int getNumChecks(HostAndPort host) {
diff --git a/src/mongo/client/sasl_client_authenticate_impl.cpp b/src/mongo/client/sasl_client_authenticate_impl.cpp
index 860f913971b..f95ed39811d 100644
--- a/src/mongo/client/sasl_client_authenticate_impl.cpp
+++ b/src/mongo/client/sasl_client_authenticate_impl.cpp
@@ -48,6 +48,7 @@
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/client/sasl_client_session.h"
#include "mongo/db/auth/sasl_command_constants.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/base64.h"
#include "mongo/util/log.h"
@@ -181,7 +182,10 @@ Future<void> asyncSaslConversation(auth::RunCommandHook runCommand,
if (!status.isOK())
return status;
- LOG(saslLogLevel) << "sasl client input: " << base64::encode(payload) << endl;
+ LOGV2_DEBUG(20197,
+ logSeverityV1toV2(saslLogLevel).toInt(),
+ "sasl client input: {base64_encode_payload}",
+ "base64_encode_payload"_attr = base64::encode(payload));
// Create new payload for our response
std::string responsePayload;
@@ -189,7 +193,10 @@ Future<void> asyncSaslConversation(auth::RunCommandHook runCommand,
if (!status.isOK())
return status;
- LOG(saslLogLevel) << "sasl client output: " << base64::encode(responsePayload) << endl;
+ LOGV2_DEBUG(20198,
+ logSeverityV1toV2(saslLogLevel).toInt(),
+ "sasl client output: {base64_encode_responsePayload}",
+ "base64_encode_responsePayload"_attr = base64::encode(responsePayload));
// Handle a done from the server which comes before the client is complete.
const bool serverDone = inputObj[saslCommandDoneFieldName].trueValue();
diff --git a/src/mongo/client/sdam/sdam_json_test_runner.cpp b/src/mongo/client/sdam/sdam_json_test_runner.cpp
index 10027290a17..ec4b8e453d2 100644
--- a/src/mongo/client/sdam/sdam_json_test_runner.cpp
+++ b/src/mongo/client/sdam/sdam_json_test_runner.cpp
@@ -43,6 +43,7 @@
#include "mongo/client/sdam/sdam_json_test_runner_cli_options_gen.h"
#include "mongo/client/sdam/topology_manager.h"
#include "mongo/logger/logger.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/unordered_set.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/log.h"
@@ -126,10 +127,14 @@ public:
}
void LogParams() const {
- log() << "Verbosity: " << _verbose << std::endl;
- log() << "Source Directory: " << _sourceDirectory << std::endl;
+ LOGV2(20199, "Verbosity: {verbose}", "verbose"_attr = _verbose);
+ LOGV2(20200,
+ "Source Directory: {sourceDirectory}",
+ "sourceDirectory"_attr = _sourceDirectory);
if (_testFilters.size()) {
- log() << "Filters: " << boost::join(_testFilters, ", ");
+ LOGV2(20201,
+ "Filters: {boost_join_testFilters}",
+ "boost_join_testFilters"_attr = boost::join(_testFilters, ", "));
}
}
@@ -212,13 +217,18 @@ public:
for (auto response : _isMasterResponses) {
auto descriptionStr =
(response.getResponse()) ? response.getResponse()->toString() : "[ Network Error ]";
- log() << "Sending server description: " << response.getServer() << " : "
- << descriptionStr << std::endl;
+ LOGV2(20202,
+ "Sending server description: {response_getServer} : {descriptionStr}",
+ "response_getServer"_attr = response.getServer(),
+ "descriptionStr"_attr = descriptionStr);
topology.onServerDescription(response);
}
- log() << "TopologyDescription after Phase " << _phaseNum << ": "
- << topology.getTopologyDescription()->toString() << std::endl;
+ LOGV2(20203,
+ "TopologyDescription after Phase {phaseNum}: {topology_getTopologyDescription}",
+ "phaseNum"_attr = _phaseNum,
+ "topology_getTopologyDescription"_attr =
+ topology.getTopologyDescription()->toString());
validateServers(
&testResult, topology.getTopologyDescription(), _topologyOutcome["servers"].Obj());
@@ -553,11 +563,16 @@ public:
TestCaseResult result{{}, _testFilePath, _testName};
for (const auto& testPhase : _testPhases) {
- log() << emphasize("Phase " + std::to_string(testPhase.getPhaseNum()));
+ LOGV2(20204,
+ "{emphasize_Phase_std_to_string_testPhase_getPhaseNum}",
+ "emphasize_Phase_std_to_string_testPhase_getPhaseNum"_attr =
+ emphasize("Phase " + std::to_string(testPhase.getPhaseNum())));
auto phaseResult = testPhase.execute(topology);
result.phaseResults.push_back(phaseResult);
if (!result.Success()) {
- log() << "Phase " << phaseResult.phaseNumber << " failed.";
+ LOGV2(20205,
+ "Phase {phaseResult_phaseNumber} failed.",
+ "phaseResult_phaseNumber"_attr = phaseResult.phaseNumber);
break;
}
}
@@ -572,8 +587,11 @@ public:
private:
void parseTest(fs::path testFilePath) {
_testFilePath = testFilePath.string();
- log() << "";
- log() << emphasize("Parsing " + testFilePath.string());
+ LOGV2(20206, "");
+ LOGV2(20207,
+ "{emphasize_Parsing_testFilePath_string}",
+ "emphasize_Parsing_testFilePath_string"_attr =
+ emphasize("Parsing " + testFilePath.string()));
{
std::ifstream testFile(_testFilePath);
std::ostringstream json;
@@ -636,7 +654,10 @@ public:
for (auto jsonTest : testFiles) {
auto testCase = JsonTestCase(jsonTest);
try {
- log() << emphasize("Executing " + testCase.Name());
+ LOGV2(20208,
+ "{emphasize_Executing_testCase_Name}",
+ "emphasize_Executing_testCase_Name"_attr =
+ emphasize("Executing " + testCase.Name()));
results.push_back(testCase.execute());
} catch (const DBException& ex) {
std::stringstream error;
@@ -661,7 +682,9 @@ public:
results.begin(), results.end(), [](const JsonTestCase::TestCaseResult& result) {
return !result.Success();
})) {
- log() << emphasize("Failed Test Results");
+ LOGV2(20209,
+ "{emphasize_Failed_Test_Results}",
+ "emphasize_Failed_Test_Results"_attr = emphasize("Failed Test Results"));
}
for (const auto result : results) {
@@ -671,22 +694,31 @@ public:
if (result.Success()) {
++numSuccess;
} else {
- log() << emphasize(testName);
- log() << "error in file: " << file;
+ LOGV2(
+ 20210, "{emphasize_testName}", "emphasize_testName"_attr = emphasize(testName));
+ LOGV2(20211, "error in file: {file}", "file"_attr = file);
++numFailed;
for (auto phaseResult : phaseResults) {
- log() << "Phase " << phaseResult.phaseNumber << ": " << std::endl;
+ LOGV2(20212,
+ "Phase {phaseResult_phaseNumber}: ",
+ "phaseResult_phaseNumber"_attr = phaseResult.phaseNumber);
if (!phaseResult.Success()) {
for (auto error : phaseResult.errorDescriptions) {
- log() << "\t" << error.first << ": " << error.second << std::endl;
+ LOGV2(20213,
+ "\t{error_first}: {error_second}",
+ "error_first"_attr = error.first,
+ "error_second"_attr = error.second);
}
}
}
- log() << std::endl;
+ LOGV2(20214, "");
}
}
- log() << numTestCases << " test cases; " << numSuccess << " success; " << numFailed
- << " failed.";
+ LOGV2(20215,
+ "{numTestCases} test cases; {numSuccess} success; {numFailed} failed.",
+ "numTestCases"_attr = numTestCases,
+ "numSuccess"_attr = numSuccess,
+ "numFailed"_attr = numFailed);
return numFailed;
}
@@ -721,7 +753,10 @@ private:
if (filePath.string().find(filter) != std::string::npos) {
return true;
} else {
- LOG(2) << "'" << filePath.string() << "' skipped due to filter configuration.";
+ LOGV2_DEBUG(20216,
+ 2,
+ "'{filePath_string}' skipped due to filter configuration.",
+ "filePath_string"_attr = filePath.string());
}
}
diff --git a/src/mongo/client/sdam/topology_description_test.cpp b/src/mongo/client/sdam/topology_description_test.cpp
index 1b6181562ae..3f580a9d415 100644
--- a/src/mongo/client/sdam/topology_description_test.cpp
+++ b/src/mongo/client/sdam/topology_description_test.cpp
@@ -26,6 +26,8 @@
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/client/sdam/sdam_test_base.h"
#include "mongo/client/sdam/topology_description.h"
@@ -34,7 +36,9 @@
#include "mongo/client/sdam/server_description.h"
#include "mongo/client/sdam/server_description_builder.h"
#include "mongo/db/wire_version.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/death_test.h"
+#include "mongo/util/log.h"
namespace mongo {
template std::ostream& operator<<(std::ostream& os,
@@ -143,8 +147,9 @@ TEST_F(TopologyDescriptionTestFixture, ShouldOnlyAllowSingleAndRsNoPrimaryWithSe
topologyTypes.end());
for (const auto topologyType : topologyTypes) {
- unittest::log() << "Check TopologyType " << toString(topologyType)
- << " with setName value.";
+ LOGV2(20217,
+ "Check TopologyType {topologyType} with setName value.",
+ "topologyType"_attr = toString(topologyType));
ASSERT_THROWS_CODE(
SdamConfiguration(kOneServer, topologyType, mongo::Seconds(10), kSetName),
DBException,
diff --git a/src/mongo/client/sdam/topology_manager.cpp b/src/mongo/client/sdam/topology_manager.cpp
index c2153ae667c..9cad8440f57 100644
--- a/src/mongo/client/sdam/topology_manager.cpp
+++ b/src/mongo/client/sdam/topology_manager.cpp
@@ -31,6 +31,7 @@
#include "mongo/client/sdam/topology_manager.h"
#include "mongo/client/sdam/topology_state_machine.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo::sdam {
@@ -76,10 +77,12 @@ void TopologyManager::onServerDescription(const IsMasterOutcome& isMasterOutcome
boost::optional<int> poolResetCounter = boost::none;
if (isMasterOutcome.isSuccess()) {
if (isStaleTopologyVersion(lastTopologyVersion, newTopologyVersion)) {
- log() << "Ignoring this isMaster response because our topologyVersion: "
- << lastTopologyVersion->toBSON()
- << "is fresher than the provided topologyVersion: "
- << newTopologyVersion->toBSON();
+ LOGV2(20218,
+ "Ignoring this isMaster response because our topologyVersion: "
+ "{lastTopologyVersion}is fresher than the provided topologyVersion: "
+ "{newTopologyVersion}",
+ "lastTopologyVersion"_attr = lastTopologyVersion->toBSON(),
+ "newTopologyVersion"_attr = newTopologyVersion->toBSON());
return;
}
diff --git a/src/mongo/client/sdam/topology_state_machine.cpp b/src/mongo/client/sdam/topology_state_machine.cpp
index dc793595b5c..c54053b2260 100644
--- a/src/mongo/client/sdam/topology_state_machine.cpp
+++ b/src/mongo/client/sdam/topology_state_machine.cpp
@@ -33,6 +33,7 @@
#include <ostream>
#include "mongo/client/sdam/sdam_test_base.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo::sdam {
@@ -149,8 +150,11 @@ void mongo::sdam::TopologyStateMachine::initTransitionTable() {
void TopologyStateMachine::onServerDescription(TopologyDescription& topologyDescription,
const ServerDescriptionPtr& serverDescription) {
if (!topologyDescription.containsServerAddress(serverDescription->getAddress())) {
- LOG(0) << kLogPrefix << "ignoring ismaster reply from server that is not in the topology: "
- << serverDescription->getAddress() << std::endl;
+ LOGV2(20219,
+ "{kLogPrefix}ignoring ismaster reply from server that is not in the topology: "
+ "{serverDescription_getAddress}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "serverDescription_getAddress"_attr = serverDescription->getAddress());
return;
}
@@ -364,40 +368,59 @@ void TopologyStateMachine::setTopologyTypeAndUpdateRSWithoutPrimary(
void TopologyStateMachine::removeServerDescription(TopologyDescription& topologyDescription,
const ServerAddress serverAddress) {
topologyDescription.removeServerDescription(serverAddress);
- LOG(0) << kLogPrefix << "server '" << serverAddress << "' was removed from the topology."
- << std::endl;
+ LOGV2(20220,
+ "{kLogPrefix}server '{serverAddress}' was removed from the topology.",
+ "kLogPrefix"_attr = kLogPrefix,
+ "serverAddress"_attr = serverAddress);
}
void TopologyStateMachine::modifyTopologyType(TopologyDescription& topologyDescription,
TopologyType topologyType) {
topologyDescription._type = topologyType;
- LOG(0) << kLogPrefix << "the topology type was set to " << toString(topologyType) << std::endl;
+ LOGV2(20221,
+ "{kLogPrefix}the topology type was set to {topologyType}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "topologyType"_attr = toString(topologyType));
}
void TopologyStateMachine::modifySetName(TopologyDescription& topologyDescription,
const boost::optional<std::string>& setName) {
topologyDescription._setName = setName;
- LOG(0) << kLogPrefix << "the topology setName was set to " << ((setName) ? *setName : "[null]")
- << std::endl;
+ LOGV2(20222,
+ "{kLogPrefix}the topology setName was set to {setName_setName_null}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "setName_setName_null"_attr = ((setName) ? *setName : "[null]"));
}
void TopologyStateMachine::installServerDescription(TopologyDescription& topologyDescription,
ServerDescriptionPtr newServerDescription,
bool newServer) {
topologyDescription.installServerDescription(newServerDescription);
- LOG(1) << kLogPrefix << ((newServer) ? "installed new" : "updated existing")
- << " server description: " << newServerDescription->toString() << std::endl;
+ LOGV2_DEBUG(20223,
+ 1,
+ "{kLogPrefix}{newServer_installed_new_updated_existing} server description: "
+ "{newServerDescription}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "newServer_installed_new_updated_existing"_attr =
+ ((newServer) ? "installed new" : "updated existing"),
+ "newServerDescription"_attr = newServerDescription->toString());
}
void TopologyStateMachine::modifyMaxElectionId(TopologyDescription& topologyDescription,
const OID& newMaxElectionId) {
topologyDescription._maxElectionId = newMaxElectionId;
- LOG(0) << kLogPrefix << "topology max election id set to " << newMaxElectionId << std::endl;
+ LOGV2(20224,
+ "{kLogPrefix}topology max election id set to {newMaxElectionId}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "newMaxElectionId"_attr = newMaxElectionId);
}
void TopologyStateMachine::modifyMaxSetVersion(TopologyDescription& topologyDescription,
int& newMaxSetVersion) {
topologyDescription._maxSetVersion = newMaxSetVersion;
- LOG(0) << kLogPrefix << "topology max set version set to " << newMaxSetVersion << std::endl;
+ LOGV2(20225,
+ "{kLogPrefix}topology max set version set to {newMaxSetVersion}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "newMaxSetVersion"_attr = newMaxSetVersion);
}
} // namespace mongo::sdam
diff --git a/src/mongo/db/auth/authorization_manager_impl.cpp b/src/mongo/db/auth/authorization_manager_impl.cpp
index f996254981d..603cf4c924c 100644
--- a/src/mongo/db/auth/authorization_manager_impl.cpp
+++ b/src/mongo/db/auth/authorization_manager_impl.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/auth/user_management_commands_parser.h"
#include "mongo/db/global_settings.h"
#include "mongo/db/mongod_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -413,7 +414,7 @@ StatusWith<UserHandle> AuthorizationManagerImpl::acquireUser(OperationContext* o
auto cachedUser = _userCache.acquire(opCtx, userName);
invariant(cachedUser);
- LOG(1) << "Returning user " << userName << " from cache";
+ LOGV2_DEBUG(20226, 1, "Returning user {userName} from cache", "userName"_attr = userName);
return cachedUser;
} catch (const DBException& ex) {
return ex.toStatus();
@@ -442,7 +443,7 @@ void AuthorizationManagerImpl::updatePinnedUsersList(std::vector<UserName> names
bool noUsersToPin = _usersToPin->empty();
_pinnedUsersCond.notify_one();
if (noUsersToPin) {
- LOG(1) << "There were no users to pin, not starting tracker thread";
+ LOGV2_DEBUG(20227, 1, "There were no users to pin, not starting tracker thread");
return;
}
@@ -456,7 +457,7 @@ void AuthorizationManagerImpl::_pinnedUsersThreadRoutine() noexcept try {
Client::initThread("PinnedUsersTracker");
std::list<UserHandle> pinnedUsers;
std::vector<UserName> usersToPin;
- LOG(1) << "Starting pinned users tracking thread";
+ LOGV2_DEBUG(20228, 1, "Starting pinned users tracking thread");
while (true) {
auto opCtx = cc().makeOperationContext();
@@ -485,13 +486,22 @@ void AuthorizationManagerImpl::_pinnedUsersThreadRoutine() noexcept try {
if (!user.isValid() || !shouldPin) {
if (!shouldPin) {
- LOG(2) << "Unpinning user " << user->getName();
+ LOGV2_DEBUG(20229,
+ 2,
+ "Unpinning user {user_getName}",
+ "user_getName"_attr = user->getName());
} else {
- LOG(2) << "Pinned user no longer valid, will re-pin " << user->getName();
+ LOGV2_DEBUG(20230,
+ 2,
+ "Pinned user no longer valid, will re-pin {user_getName}",
+ "user_getName"_attr = user->getName());
}
it = pinnedUsers.erase(it);
} else {
- LOG(3) << "Pinned user is still valid and pinned " << user->getName();
+ LOGV2_DEBUG(20231,
+ 3,
+ "Pinned user is still valid and pinned {user_getName}",
+ "user_getName"_attr = user->getName());
++it;
}
}
@@ -506,42 +516,45 @@ void AuthorizationManagerImpl::_pinnedUsersThreadRoutine() noexcept try {
auto swUser = acquireUser(opCtx.get(), userName);
if (swUser.isOK()) {
- LOG(2) << "Pinned user " << userName;
+ LOGV2_DEBUG(20232, 2, "Pinned user {userName}", "userName"_attr = userName);
pinnedUsers.emplace_back(std::move(swUser.getValue()));
} else {
const auto& status = swUser.getStatus();
// If the user is not found, then it might just not exist yet. Skip this user for
// now.
if (status != ErrorCodes::UserNotFound) {
- warning() << "Unable to fetch pinned user " << userName.toString() << ": "
- << status;
+ LOGV2_WARNING(20239,
+ "Unable to fetch pinned user {userName}: {status}",
+ "userName"_attr = userName.toString(),
+ "status"_attr = status);
} else {
- LOG(2) << "Pinned user not found: " << userName;
+ LOGV2_DEBUG(
+ 20233, 2, "Pinned user not found: {userName}", "userName"_attr = userName);
}
}
}
}
} catch (const ExceptionFor<ErrorCodes::InterruptedAtShutdown>&) {
- LOG(1) << "Ending pinned users tracking thread";
+ LOGV2_DEBUG(20234, 1, "Ending pinned users tracking thread");
return;
}
void AuthorizationManagerImpl::invalidateUserByName(OperationContext* opCtx,
const UserName& userName) {
- LOG(2) << "Invalidating user " << userName;
+ LOGV2_DEBUG(20235, 2, "Invalidating user {userName}", "userName"_attr = userName);
_authSchemaVersionCache.invalidateAll();
_userCache.invalidate(userName);
}
void AuthorizationManagerImpl::invalidateUsersFromDB(OperationContext* opCtx, StringData dbname) {
- LOG(2) << "Invalidating all users from database " << dbname;
+ LOGV2_DEBUG(20236, 2, "Invalidating all users from database {dbname}", "dbname"_attr = dbname);
_authSchemaVersionCache.invalidateAll();
_userCache.invalidateIf(
[&](const UserName& user, const User*) { return user.getDB() == dbname; });
}
void AuthorizationManagerImpl::invalidateUserCache(OperationContext* opCtx) {
- LOG(2) << "Invalidating user cache";
+ LOGV2_DEBUG(20237, 2, "Invalidating user cache");
_authSchemaVersionCache.invalidateAll();
_userCache.invalidateAll();
}
@@ -603,7 +616,7 @@ AuthorizationManagerImpl::UserCacheImpl::UserCacheImpl(
boost::optional<User> AuthorizationManagerImpl::UserCacheImpl::lookup(OperationContext* opCtx,
const UserName& userName) {
- LOG(1) << "Getting user " << userName << " from disk";
+ LOGV2_DEBUG(20238, 1, "Getting user {userName} from disk", "userName"_attr = userName);
// Number of times to retry a user document that fetches due to transient AuthSchemaIncompatible
// errors. These errors should only ever occur during and shortly after schema upgrades.
diff --git a/src/mongo/db/auth/authorization_session_impl.cpp b/src/mongo/db/auth/authorization_session_impl.cpp
index 941f3b84cf8..c0beeb758aa 100644
--- a/src/mongo/db/auth/authorization_session_impl.cpp
+++ b/src/mongo/db/auth/authorization_session_impl.cpp
@@ -53,6 +53,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/pipeline/aggregation_request.h"
#include "mongo/db/pipeline/lite_parsed_pipeline.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -139,8 +140,11 @@ Status AuthorizationSessionImpl::addAndAuthorizeUser(OperationContext* opCtx,
Status restrictionStatus =
restrictionSet.validate(RestrictionEnvironment::get(*opCtx->getClient()));
if (!restrictionStatus.isOK()) {
- log() << "Failed to acquire user '" << userName
- << "' because of unmet authentication restrictions: " << restrictionStatus.reason();
+ LOGV2(20240,
+ "Failed to acquire user '{userName}' because of unmet authentication restrictions: "
+ "{restrictionStatus_reason}",
+ "userName"_attr = userName,
+ "restrictionStatus_reason"_attr = restrictionStatus.reason());
return AuthorizationManager::authenticationFailedStatus;
}
@@ -553,9 +557,11 @@ bool AuthorizationSessionImpl::isAuthorizedToCreateRole(
return true;
}
}
- log() << "Not authorized to create the first role in the system '" << args.roleName
- << "' using the localhost exception. The user needs to acquire the role through "
- "external authentication first.";
+ LOGV2(20241,
+ "Not authorized to create the first role in the system '{args_roleName}' using the "
+ "localhost exception. The user needs to acquire the role through "
+ "external authentication first.",
+ "args_roleName"_attr = args.roleName);
}
return false;
@@ -765,45 +771,56 @@ void AuthorizationSessionImpl::_refreshUserInfoAsNeeded(OperationContext* opCtx)
Status restrictionStatus = restrictionSet.validate(
RestrictionEnvironment::get(*opCtx->getClient()));
if (!restrictionStatus.isOK()) {
- log() << "Removed user " << name
- << " with unmet authentication restrictions from session cache of"
- << " user information. Restriction failed because: "
- << restrictionStatus.reason();
+ LOGV2(20242,
+ "Removed user {name} with unmet authentication restrictions from "
+ "session cache of user information. Restriction failed because: "
+ "{restrictionStatus_reason}",
+ "name"_attr = name,
+ "restrictionStatus_reason"_attr = restrictionStatus.reason());
// If we remove from the UserSet, we cannot increment the iterator.
continue;
}
} catch (...) {
- log() << "Evaluating authentication restrictions for " << name
- << " resulted in an unknown exception. Removing user from the"
- << " session cache.";
+ LOGV2(20243,
+ "Evaluating authentication restrictions for {name} resulted in an "
+ "unknown exception. Removing user from the session cache.",
+ "name"_attr = name);
continue;
}
// Success! Replace the old User object with the updated one.
removeGuard.dismiss();
_authenticatedUsers.replaceAt(it, std::move(updatedUser));
- LOG(1) << "Updated session cache of user information for " << name;
+ LOGV2_DEBUG(20244,
+ 1,
+ "Updated session cache of user information for {name}",
+ "name"_attr = name);
break;
}
case ErrorCodes::UserNotFound: {
// User does not exist anymore; remove it from _authenticatedUsers.
- log() << "Removed deleted user " << name
- << " from session cache of user information.";
+ LOGV2(20245,
+ "Removed deleted user {name} from session cache of user information.",
+ "name"_attr = name);
continue; // No need to advance "it" in this case.
}
case ErrorCodes::UnsupportedFormat: {
// An auth subsystem has explicitly indicated a failure.
- log() << "Removed user " << name
- << " from session cache of user information because of refresh failure:"
- << " '" << status << "'.";
+ LOGV2(20246,
+ "Removed user {name} from session cache of user information because of "
+ "refresh failure: '{status}'.",
+ "name"_attr = name,
+ "status"_attr = status);
continue; // No need to advance "it" in this case.
}
default:
// Unrecognized error; assume that it's transient, and continue working with the
// out-of-date privilege data.
- warning() << "Could not fetch updated user privilege information for " << name
- << "; continuing to use old information. Reason is "
- << redact(status);
+ LOGV2_WARNING(20247,
+ "Could not fetch updated user privilege information for {name}; "
+ "continuing to use old information. Reason is {status}",
+ "name"_attr = name,
+ "status"_attr = redact(status));
removeGuard.dismiss();
break;
}
diff --git a/src/mongo/db/auth/authz_session_external_state_server_common.cpp b/src/mongo/db/auth/authz_session_external_state_server_common.cpp
index b9829fde37e..9b29806013b 100644
--- a/src/mongo/db/auth/authz_session_external_state_server_common.cpp
+++ b/src/mongo/db/auth/authz_session_external_state_server_common.cpp
@@ -38,6 +38,7 @@
#include "mongo/base/status.h"
#include "mongo/db/auth/enable_localhost_auth_bypass_parameter_gen.h"
#include "mongo/db/client.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/log.h"
@@ -70,9 +71,9 @@ void AuthzSessionExternalStateServerCommon::_checkShouldAllowLocalhost(Operation
_allowLocalhost = !_authzManager->hasAnyPrivilegeDocuments(opCtx);
if (_allowLocalhost) {
std::call_once(checkShouldAllowLocalhostOnceFlag, []() {
- log() << "note: no users configured in admin.system.users, allowing localhost "
- "access"
- << std::endl;
+ LOGV2(20248,
+ "note: no users configured in admin.system.users, allowing localhost "
+ "access");
});
}
}
diff --git a/src/mongo/db/auth/sasl_commands.cpp b/src/mongo/db/auth/sasl_commands.cpp
index a6276d3fec9..22403e23303 100644
--- a/src/mongo/db/auth/sasl_commands.cpp
+++ b/src/mongo/db/auth/sasl_commands.cpp
@@ -53,6 +53,7 @@
#include "mongo/db/commands/authentication_commands.h"
#include "mongo/db/server_options.h"
#include "mongo/db/stats/counters.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/base64.h"
#include "mongo/util/log.h"
#include "mongo/util/sequence_util.h"
@@ -187,10 +188,15 @@ Status doSaslStep(OperationContext* opCtx,
StatusWith<std::string> swResponse = mechanism.step(opCtx, payload);
if (!swResponse.isOK()) {
- log() << "SASL " << mechanism.mechanismName() << " authentication failed for "
- << mechanism.getPrincipalName() << " on " << mechanism.getAuthenticationDatabase()
- << " from client " << opCtx->getClient()->getRemote().toString() << " ; "
- << redact(swResponse.getStatus());
+ LOGV2(20249,
+ "SASL {mechanism_mechanismName} authentication failed for "
+ "{mechanism_getPrincipalName} on {mechanism_getAuthenticationDatabase} from client "
+ "{opCtx_getClient_getRemote} ; {swResponse_getStatus}",
+ "mechanism_mechanismName"_attr = mechanism.mechanismName(),
+ "mechanism_getPrincipalName"_attr = mechanism.getPrincipalName(),
+ "mechanism_getAuthenticationDatabase"_attr = mechanism.getAuthenticationDatabase(),
+ "opCtx_getClient_getRemote"_attr = opCtx->getClient()->getRemote().toString(),
+ "swResponse_getStatus"_attr = redact(swResponse.getStatus()));
sleepmillis(saslGlobalParams.authFailedDelay.load());
// All the client needs to know is that authentication has failed.
@@ -211,9 +217,14 @@ Status doSaslStep(OperationContext* opCtx,
}
if (!serverGlobalParams.quiet.load()) {
- log() << "Successfully authenticated as principal " << mechanism.getPrincipalName()
- << " on " << mechanism.getAuthenticationDatabase() << " from client "
- << opCtx->getClient()->session()->remote();
+ LOGV2(20250,
+ "Successfully authenticated as principal {mechanism_getPrincipalName} on "
+ "{mechanism_getAuthenticationDatabase} from client "
+ "{opCtx_getClient_session_remote}",
+ "mechanism_getPrincipalName"_attr = mechanism.getPrincipalName(),
+ "mechanism_getAuthenticationDatabase"_attr =
+ mechanism.getAuthenticationDatabase(),
+ "opCtx_getClient_session_remote"_attr = opCtx->getClient()->session()->remote());
}
if (session->isSpeculative()) {
authCounter.incSpeculativeAuthenticateSuccessful(mechanism.mechanismName().toString());
diff --git a/src/mongo/db/auth/sasl_mechanism_registry.cpp b/src/mongo/db/auth/sasl_mechanism_registry.cpp
index 741dde39126..5c07d4e2eac 100644
--- a/src/mongo/db/auth/sasl_mechanism_registry.cpp
+++ b/src/mongo/db/auth/sasl_mechanism_registry.cpp
@@ -35,6 +35,7 @@
#include "mongo/base/init.h"
#include "mongo/db/auth/sasl_options.h"
#include "mongo/db/auth/user.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/icu.h"
#include "mongo/util/log.h"
#include "mongo/util/net/socket_utils.h"
@@ -108,8 +109,9 @@ void SASLServerMechanismRegistry::advertiseMechanismNamesForUser(OperationContex
if (!swUser.isOK()) {
auto& status = swUser.getStatus();
if (status.code() == ErrorCodes::UserNotFound) {
- log() << "Supported SASL mechanisms requested for unknown user '" << userName
- << "'";
+ LOGV2(20251,
+ "Supported SASL mechanisms requested for unknown user '{userName}'",
+ "userName"_attr = userName);
return;
}
uassertStatusOK(status);
diff --git a/src/mongo/db/auth/sasl_scram_test.cpp b/src/mongo/db/auth/sasl_scram_test.cpp
index 23c6c548f3c..4b2ec0b84d5 100644
--- a/src/mongo/db/auth/sasl_scram_test.cpp
+++ b/src/mongo/db/auth/sasl_scram_test.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/auth/sasl_mechanism_registry.h"
#include "mongo/db/auth/sasl_scram_server_conversation.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/base64.h"
#include "mongo/util/log.h"
@@ -270,12 +271,12 @@ protected:
public:
void run() {
- log() << "SCRAM-SHA-1 variant";
+ LOGV2(20252, "SCRAM-SHA-1 variant");
saslServerSession = std::make_unique<SaslSCRAMSHA1ServerMechanism>("test");
_digestPassword = true;
Test::run();
- log() << "SCRAM-SHA-256 variant";
+ LOGV2(20253, "SCRAM-SHA-256 variant");
saslServerSession = std::make_unique<SaslSCRAMSHA256ServerMechanism>("test");
_digestPassword = false;
Test::run();
diff --git a/src/mongo/db/auth/security_key.cpp b/src/mongo/db/auth/security_key.cpp
index fe310befdf2..5fb3d1badd4 100644
--- a/src/mongo/db/auth/security_key.cpp
+++ b/src/mongo/db/auth/security_key.cpp
@@ -52,6 +52,7 @@
#include "mongo/db/auth/security_file.h"
#include "mongo/db/auth/user.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/icu.h"
#include "mongo/util/log.h"
#include "mongo/util/password_digest.h"
@@ -70,15 +71,20 @@ public:
boost::optional<User::CredentialData> generate(const std::string& password) {
if (password.size() < kMinKeyLength || password.size() > kMaxKeyLength) {
- error() << " security key in " << _filename << " has length " << password.size()
- << ", must be between 6 and 1024 chars";
+ LOGV2_ERROR(20255,
+ " security key in {filename} has length {password_size}, must be between 6 "
+ "and 1024 chars",
+ "filename"_attr = _filename,
+ "password_size"_attr = password.size());
return boost::none;
}
auto swSaslPassword = icuSaslPrep(password);
if (!swSaslPassword.isOK()) {
- error() << "Could not prep security key file for SCRAM-SHA-256: "
- << swSaslPassword.getStatus();
+ LOGV2_ERROR(
+ 20256,
+ "Could not prep security key file for SCRAM-SHA-256: {swSaslPassword_getStatus}",
+ "swSaslPassword_getStatus"_attr = swSaslPassword.getStatus());
return boost::none;
}
const auto passwordDigest = mongo::createPasswordDigest(
@@ -109,7 +115,9 @@ private:
target.storedKey = source[scram::kStoredKeyFieldName].String();
target.serverKey = source[scram::kServerKeyFieldName].String();
if (!target.isValid()) {
- error() << "Could not generate valid credentials from key in " << _filename;
+ LOGV2_ERROR(20257,
+ "Could not generate valid credentials from key in {filename}",
+ "filename"_attr = _filename);
return false;
}
@@ -128,15 +136,20 @@ using std::string;
bool setUpSecurityKey(const string& filename) {
auto swKeyStrings = mongo::readSecurityFile(filename);
if (!swKeyStrings.isOK()) {
- log() << swKeyStrings.getStatus().reason();
+ LOGV2(20254,
+ "{swKeyStrings_getStatus_reason}",
+ "swKeyStrings_getStatus_reason"_attr = swKeyStrings.getStatus().reason());
return false;
}
auto keyStrings = std::move(swKeyStrings.getValue());
if (keyStrings.size() > 2) {
- error() << "Only two keys are supported in the security key file, " << keyStrings.size()
- << " are specified in " << filename;
+ LOGV2_ERROR(20258,
+ "Only two keys are supported in the security key file, {keyStrings_size} are "
+ "specified in {filename}",
+ "keyStrings_size"_attr = keyStrings.size(),
+ "filename"_attr = filename);
return false;
}
diff --git a/src/mongo/db/auth/user_cache_invalidator_job.cpp b/src/mongo/db/auth/user_cache_invalidator_job.cpp
index 771194c14c6..d301173441e 100644
--- a/src/mongo/db/auth/user_cache_invalidator_job.cpp
+++ b/src/mongo/db/auth/user_cache_invalidator_job.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/auth/user_cache_invalidator_job_parameters_gen.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/compiler.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/get_status_from_command_result.h"
@@ -63,7 +64,11 @@ public:
void setInterval(Seconds interval) {
{
stdx::lock_guard<Latch> twiddle(_mutex);
- LOG(5) << "setInterval: old=" << _interval << ", new=" << interval;
+ LOGV2_DEBUG(20259,
+ 5,
+ "setInterval: old={interval}, new={interval2}",
+ "interval"_attr = _interval,
+ "interval2"_attr = interval);
_interval = interval;
}
_condition.notify_all();
@@ -94,15 +99,19 @@ public:
Date_t now = Date_t::now();
Date_t expiry = _last + _interval;
- LOG(5) << "wait: now=" << now << ", expiry=" << expiry;
+ LOGV2_DEBUG(20260,
+ 5,
+ "wait: now={now}, expiry={expiry}",
+ "now"_attr = now,
+ "expiry"_attr = expiry);
if (now >= expiry) {
_last = now;
- LOG(5) << "wait: done";
+ LOGV2_DEBUG(20261, 5, "wait: done");
return true;
}
- LOG(5) << "wait: blocking";
+ LOGV2_DEBUG(20262, 5, "wait: blocking");
MONGO_IDLE_THREAD_BLOCK;
_condition.wait_until(lock, expiry.toSystemTimePoint());
}
@@ -165,13 +174,15 @@ void UserCacheInvalidator::initialize(OperationContext* opCtx) {
}
if (currentGeneration.getStatus().code() == ErrorCodes::CommandNotFound) {
- warning() << "_getUserCacheGeneration command not found while fetching initial user "
- "cache generation from the config server(s). This most likely means you are "
- "running an outdated version of mongod on the config servers";
+ LOGV2_WARNING(20264,
+ "_getUserCacheGeneration command not found while fetching initial user "
+ "cache generation from the config server(s). This most likely means you are "
+ "running an outdated version of mongod on the config servers");
} else {
- warning() << "An error occurred while fetching initial user cache generation from "
- "config servers: "
- << currentGeneration.getStatus();
+ LOGV2_WARNING(20265,
+ "An error occurred while fetching initial user cache generation from "
+ "config servers: {currentGeneration_getStatus}",
+ "currentGeneration_getStatus"_attr = currentGeneration.getStatus());
}
_previousCacheGeneration = OID();
}
@@ -184,26 +195,35 @@ void UserCacheInvalidator::run() {
auto opCtx = cc().makeOperationContext();
StatusWith<OID> currentGeneration = getCurrentCacheGeneration(opCtx.get());
if (!currentGeneration.isOK()) {
- warning() << "An error occurred while fetching current user cache generation "
- "to check if user cache needs invalidation: "
- << currentGeneration.getStatus();
+ LOGV2_WARNING(
+ 20266,
+ "An error occurred while fetching current user cache generation "
+ "to check if user cache needs invalidation: {currentGeneration_getStatus}",
+ "currentGeneration_getStatus"_attr = currentGeneration.getStatus());
// When in doubt, invalidate the cache
try {
_authzManager->invalidateUserCache(opCtx.get());
} catch (const DBException& e) {
- warning() << "Error invalidating user cache: " << e.toStatus();
+ LOGV2_WARNING(20267,
+ "Error invalidating user cache: {e_toStatus}",
+ "e_toStatus"_attr = e.toStatus());
}
continue;
}
if (currentGeneration.getValue() != _previousCacheGeneration) {
- log() << "User cache generation changed from " << _previousCacheGeneration << " to "
- << currentGeneration.getValue() << "; invalidating user cache";
+ LOGV2(20263,
+ "User cache generation changed from {previousCacheGeneration} to "
+ "{currentGeneration_getValue}; invalidating user cache",
+ "previousCacheGeneration"_attr = _previousCacheGeneration,
+ "currentGeneration_getValue"_attr = currentGeneration.getValue());
try {
_authzManager->invalidateUserCache(opCtx.get());
} catch (const DBException& e) {
- warning() << "Error invalidating user cache: " << e.toStatus();
+ LOGV2_WARNING(20268,
+ "Error invalidating user cache: {e_toStatus}",
+ "e_toStatus"_attr = e.toStatus());
}
_previousCacheGeneration = currentGeneration.getValue();
diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp
index 3df128c471f..97010dc6ac3 100644
--- a/src/mongo/db/catalog/catalog_control.cpp
+++ b/src/mongo/db/catalog/catalog_control.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/index_builds_coordinator.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/rebuild_indexes.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -72,8 +73,13 @@ MinVisibleTimestampMap closeCatalog(OperationContext* opCtx) {
// If there's a minimum visible, invariant there's also a UUID.
invariant(!minVisible || uuid);
if (uuid && minVisible) {
- LOG(1) << "closeCatalog: preserving min visible timestamp. Collection: "
- << coll->ns() << " UUID: " << uuid << " TS: " << minVisible;
+ LOGV2_DEBUG(20269,
+ 1,
+ "closeCatalog: preserving min visible timestamp. Collection: {coll_ns} "
+ "UUID: {uuid} TS: {minVisible}",
+ "coll_ns"_attr = coll->ns(),
+ "uuid"_attr = uuid,
+ "minVisible"_attr = minVisible);
minVisibleTimestampMap[*uuid] = *minVisible;
}
}
@@ -87,14 +93,14 @@ MinVisibleTimestampMap closeCatalog(OperationContext* opCtx) {
// to work before acquiring locks, and might otherwise spuriously regard a UUID as unknown
// while reloading the catalog.
CollectionCatalog::get(opCtx).onCloseCatalog(opCtx);
- LOG(1) << "closeCatalog: closing collection catalog";
+ LOGV2_DEBUG(20270, 1, "closeCatalog: closing collection catalog");
// Close all databases.
- log() << "closeCatalog: closing all databases";
+ LOGV2(20271, "closeCatalog: closing all databases");
databaseHolder->closeAll(opCtx);
// Close the storage engine's catalog.
- log() << "closeCatalog: closing storage engine catalog";
+ LOGV2(20272, "closeCatalog: closing storage engine catalog");
opCtx->getServiceContext()->getStorageEngine()->closeCatalog(opCtx);
reopenOnFailure.dismiss();
@@ -105,11 +111,11 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib
invariant(opCtx->lockState()->isW());
// Load the catalog in the storage engine.
- log() << "openCatalog: loading storage engine catalog";
+ LOGV2(20273, "openCatalog: loading storage engine catalog");
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
storageEngine->loadCatalog(opCtx);
- log() << "openCatalog: reconciling catalog and idents";
+ LOGV2(20274, "openCatalog: reconciling catalog and idents");
auto reconcileResult = fassert(40688, storageEngine->reconcileCatalogAndIdents(opCtx));
// Determine which indexes need to be rebuilt. rebuildIndexesOnCollection() requires that all
@@ -149,8 +155,10 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib
invariant(collection, str::stream() << "couldn't get collection " << collNss.toString());
for (const auto& indexName : entry.second.first) {
- log() << "openCatalog: rebuilding index: collection: " << collNss.toString()
- << ", index: " << indexName;
+ LOGV2(20275,
+ "openCatalog: rebuilding index: collection: {collNss}, index: {indexName}",
+ "collNss"_attr = collNss.toString(),
+ "indexName"_attr = indexName);
}
std::vector<BSONObj> indexSpecs = entry.second.second;
@@ -165,7 +173,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib
opCtx, reconcileResult.indexBuildsToRestart);
// Open all databases and repopulate the CollectionCatalog.
- log() << "openCatalog: reopening all databases";
+ LOGV2(20276, "openCatalog: reopening all databases");
auto databaseHolder = DatabaseHolder::get(opCtx);
std::vector<std::string> databasesToOpen = storageEngine->listDatabases();
for (auto&& dbName : databasesToOpen) {
@@ -189,7 +197,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib
// If this is the oplog collection, re-establish the replication system's cached pointer
// to the oplog.
if (collNss.isOplog()) {
- log() << "openCatalog: updating cached oplog pointer";
+ LOGV2(20277, "openCatalog: updating cached oplog pointer");
collection->establishOplogCollectionForLogging(opCtx);
}
}
@@ -199,7 +207,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib
// catalog. Clear the pre-closing state.
CollectionCatalog::get(opCtx).onOpenCatalog(opCtx);
opCtx->getServiceContext()->incrementCatalogGeneration();
- log() << "openCatalog: finished reloading collection catalog";
+ LOGV2(20278, "openCatalog: finished reloading collection catalog");
}
} // namespace catalog
} // namespace mongo
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index 5ad39981d44..f73b63b3da5 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -56,6 +56,7 @@
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/recovery_unit.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -384,7 +385,7 @@ Status _collModInternal(OperationContext* opCtx,
std::make_unique<CollModResultChange>(oldExpireSecs, newExpireSecs, result));
if (MONGO_unlikely(assertAfterIndexUpdate.shouldFail())) {
- log() << "collMod - assertAfterIndexUpdate fail point enabled.";
+ LOGV2(20307, "collMod - assertAfterIndexUpdate fail point enabled.");
uasserted(50970, "trigger rollback after the index update");
}
}
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp
index 2907e940f3c..47dea8b1ad5 100644
--- a/src/mongo/db/catalog/collection_catalog.cpp
+++ b/src/mongo/db/catalog/collection_catalog.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/concurrency/lock_manager_defs.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/storage/recovery_unit.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/uuid.h"
@@ -384,12 +385,18 @@ void CollectionCatalog::registerCollection(CollectionUUID uuid, std::unique_ptr<
auto ns = (*coll)->ns();
stdx::lock_guard<Latch> lock(_catalogLock);
if (_collections.find(ns) != _collections.end()) {
- log() << "Conflicted creating a collection. ns: " << (*coll)->ns() << " ("
- << (*coll)->uuid() << ").";
+ LOGV2(20279,
+ "Conflicted creating a collection. ns: {coll_ns} ({coll_uuid}).",
+ "coll_ns"_attr = (*coll)->ns(),
+ "coll_uuid"_attr = (*coll)->uuid());
throw WriteConflictException();
}
- LOG(1) << "Registering collection " << ns << " with UUID " << uuid;
+ LOGV2_DEBUG(20280,
+ 1,
+ "Registering collection {ns} with UUID {uuid}",
+ "ns"_attr = ns,
+ "uuid"_attr = uuid);
auto dbName = ns.db().toString();
auto dbIdPair = std::make_pair(dbName, uuid);
@@ -419,7 +426,11 @@ std::unique_ptr<Collection> CollectionCatalog::deregisterCollection(CollectionUU
auto dbName = ns.db().toString();
auto dbIdPair = std::make_pair(dbName, uuid);
- LOG(1) << "Deregistering collection " << ns << " with UUID " << uuid;
+ LOGV2_DEBUG(20281,
+ 1,
+ "Deregistering collection {ns} with UUID {uuid}",
+ "ns"_attr = ns,
+ "uuid"_attr = uuid);
// Make sure collection object exists.
invariant(_collections.find(ns) != _collections.end());
@@ -447,14 +458,18 @@ std::unique_ptr<RecoveryUnit::Change> CollectionCatalog::makeFinishDropCollectio
void CollectionCatalog::deregisterAllCollections() {
stdx::lock_guard<Latch> lock(_catalogLock);
- LOG(0) << "Deregistering all the collections";
+ LOGV2(20282, "Deregistering all the collections");
for (auto& entry : _catalog) {
auto uuid = entry.first;
auto ns = entry.second->ns();
auto dbName = ns.db().toString();
auto dbIdPair = std::make_pair(dbName, uuid);
- LOG(1) << "Deregistering collection " << ns << " with UUID " << uuid;
+ LOGV2_DEBUG(20283,
+ 1,
+ "Deregistering collection {ns} with UUID {uuid}",
+ "ns"_attr = ns,
+ "uuid"_attr = uuid);
entry.second.reset();
}
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp
index 13d91880c82..803c11cdd79 100644
--- a/src/mongo/db/catalog/collection_compact.cpp
+++ b/src/mongo/db/catalog/collection_compact.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/index_builds_coordinator.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -103,7 +104,10 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx,
recordStore = collection->getRecordStore();
}
- log(LogComponent::kCommand) << "compact " << collectionNss << " begin";
+ LOGV2_OPTIONS(20284,
+ {logComponentV1toV2(LogComponent::kCommand)},
+ "compact {collectionNss} begin",
+ "collectionNss"_attr = collectionNss);
auto oldTotalSize = recordStore->storageSize(opCtx) + collection->getIndexSize(opCtx);
auto indexCatalog = collection->getIndexCatalog();
@@ -119,8 +123,11 @@ StatusWith<int64_t> compactCollection(OperationContext* opCtx,
auto totalSizeDiff =
oldTotalSize - recordStore->storageSize(opCtx) - collection->getIndexSize(opCtx);
- log() << "compact " << collectionNss << " bytes freed: " << totalSizeDiff;
- log() << "compact " << collectionNss << " end";
+ LOGV2(20285,
+ "compact {collectionNss} bytes freed: {totalSizeDiff}",
+ "collectionNss"_attr = collectionNss,
+ "totalSizeDiff"_attr = totalSizeDiff);
+ LOGV2(20286, "compact {collectionNss} end", "collectionNss"_attr = collectionNss);
return totalSizeDiff;
}
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index ff5a81d6f48..cf1864f7f22 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -71,6 +71,7 @@
#include "mongo/db/update/update_driver.h"
#include "mongo/db/auth/user_document_parser.h" // XXX-ANDY
+#include "mongo/logv2/log.h"
#include "mongo/rpc/object_check.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -114,7 +115,7 @@ Status checkFailCollectionInsertsFailPoint(const NamespaceString& ns, const BSON
const std::string msg = str::stream()
<< "Failpoint (failCollectionInserts) has been enabled (" << data
<< "), so rejecting insert (first doc): " << firstDoc;
- log() << msg;
+ LOGV2(20287, "{msg}", "msg"_attr = msg);
s = {ErrorCodes::FailPointEnabled, msg};
},
[&](const BSONObj& data) {
@@ -142,9 +143,11 @@ std::unique_ptr<CollatorInterface> parseCollation(OperationContext* opCtx,
// integration, shut down the server. Errors other than IncompatibleCollationVersion should not
// be possible, so these are an invariant rather than fassert.
if (collator == ErrorCodes::IncompatibleCollationVersion) {
- log() << "Collection " << nss
- << " has a default collation which is incompatible with this version: "
- << collationSpec;
+ LOGV2(20288,
+ "Collection {nss} has a default collation which is incompatible with this version: "
+ "{collationSpec}",
+ "nss"_attr = nss,
+ "collationSpec"_attr = collationSpec);
fassertFailedNoTrace(40144);
}
invariant(collator.getStatus());
@@ -297,8 +300,11 @@ void CollectionImpl::init(OperationContext* opCtx) {
parseValidator(opCtx, _validatorDoc, MatchExpressionParser::kAllowAllSpecialFeatures);
if (!_swValidator.isOK()) {
// Log an error and startup warning if the collection validator is malformed.
- warning() << "Collection " << _ns
- << " has malformed validator: " << _swValidator.getStatus() << startupWarningsLog;
+ LOGV2_WARNING_OPTIONS(20293,
+ {logv2::LogTag::kStartupWarnings},
+ "Collection {ns} has malformed validator: {swValidator_getStatus}",
+ "ns"_attr = _ns,
+ "swValidator_getStatus"_attr = _swValidator.getStatus());
}
_validationAction = uassertStatusOK(_parseValidationAction(collectionOptions.validationAction));
_validationLevel = uassertStatusOK(_parseValidationLevel(collectionOptions.validationLevel));
@@ -370,8 +376,10 @@ Status CollectionImpl::checkValidation(OperationContext* opCtx, const BSONObj& d
return Status::OK();
if (_validationAction == ValidationAction::WARN) {
- warning() << "Document would fail validation"
- << " collection: " << ns() << " doc: " << redact(document);
+ LOGV2_WARNING(20294,
+ "Document would fail validation collection: {ns} doc: {document}",
+ "ns"_attr = ns(),
+ "document"_attr = redact(document));
return Status::OK();
}
@@ -491,8 +499,11 @@ Status CollectionImpl::insertDocuments(OperationContext* opCtx,
whenFirst += " when first _id is ";
whenFirst += firstIdElem.str();
}
- log() << "hangAfterCollectionInserts fail point enabled for " << _ns << whenFirst
- << ". Blocking until fail point is disabled.";
+ LOGV2(20289,
+ "hangAfterCollectionInserts fail point enabled for {ns}{whenFirst}. Blocking "
+ "until fail point is disabled.",
+ "ns"_attr = _ns,
+ "whenFirst"_attr = whenFirst);
hangAfterCollectionInserts.pauseWhileSet(opCtx);
},
[&](const BSONObj& data) {
@@ -544,8 +555,10 @@ Status CollectionImpl::insertDocumentForBulkLoader(OperationContext* opCtx,
status = onRecordInserted(loc.getValue());
if (MONGO_unlikely(failAfterBulkLoadDocInsert.shouldFail())) {
- log() << "Failpoint failAfterBulkLoadDocInsert enabled for " << _ns.ns()
- << ". Throwing WriteConflictException.";
+ LOGV2(20290,
+ "Failpoint failAfterBulkLoadDocInsert enabled for {ns_ns}. Throwing "
+ "WriteConflictException.",
+ "ns_ns"_attr = _ns.ns());
throw WriteConflictException();
}
@@ -669,7 +682,7 @@ void CollectionImpl::deleteDocument(OperationContext* opCtx,
bool noWarn,
Collection::StoreDeletedDoc storeDeletedDoc) {
if (isCapped()) {
- log() << "failing remove on a capped ns " << _ns;
+ LOGV2(20291, "failing remove on a capped ns {ns}", "ns"_attr = _ns);
uasserted(10089, "cannot remove from a capped collection");
return;
}
@@ -870,8 +883,14 @@ bool CollectionImpl::isEmpty(OperationContext* opCtx) const {
bob.appendNumber("fastCount", static_cast<long long>(fastCount));
bob.append("cursor", str::stream() << (cursorEmptyCollRes ? "0" : ">=1"));
- LOG(2) << "Detected erroneous fast count for collection " << ns() << "(" << uuid() << ") ["
- << getRecordStore()->getIdent() << "]. Record count reported by: " << bob.obj();
+ LOGV2_DEBUG(20292,
+ 2,
+ "Detected erroneous fast count for collection {ns}({uuid}) "
+ "[{getRecordStore_getIdent}]. Record count reported by: {bob_obj}",
+ "ns"_attr = ns(),
+ "uuid"_attr = uuid(),
+ "getRecordStore_getIdent"_attr = getRecordStore()->getIdent(),
+ "bob_obj"_attr = bob.obj());
}
return cursorEmptyCollRes;
diff --git a/src/mongo/db/catalog/collection_validation.cpp b/src/mongo/db/catalog/collection_validation.cpp
index df087f66649..8cce0049db4 100644
--- a/src/mongo/db/catalog/collection_validation.cpp
+++ b/src/mongo/db/catalog/collection_validation.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -92,9 +93,12 @@ std::map<std::string, int64_t> _validateIndexesInternalStructure(
const IndexDescriptor* descriptor = entry->descriptor();
const IndexAccessMethod* iam = entry->accessMethod();
- log(LogComponent::kIndex) << "validating the internal structure of index "
- << descriptor->indexName() << " on collection "
- << descriptor->parentNS();
+ LOGV2_OPTIONS(20295,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "validating the internal structure of index {descriptor_indexName} on "
+ "collection {descriptor_parentNS}",
+ "descriptor_indexName"_attr = descriptor->indexName(),
+ "descriptor_parentNS"_attr = descriptor->parentNS());
ValidateResults& curIndexResults = (*indexNsResultsMap)[descriptor->indexName()];
@@ -129,8 +133,12 @@ void _validateIndexes(OperationContext* opCtx,
const IndexDescriptor* descriptor = index->descriptor();
- log(LogComponent::kIndex) << "validating index consistency " << descriptor->indexName()
- << " on collection " << descriptor->parentNS();
+ LOGV2_OPTIONS(20296,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "validating index consistency {descriptor_indexName} on collection "
+ "{descriptor_parentNS}",
+ "descriptor_indexName"_attr = descriptor->indexName(),
+ "descriptor_parentNS"_attr = descriptor->parentNS());
ValidateResults& curIndexResults = (*indexNsResultsMap)[descriptor->indexName()];
int64_t numTraversedKeys;
@@ -188,7 +196,9 @@ void _gatherIndexEntryErrors(OperationContext* opCtx,
ValidateResults* result) {
indexConsistency->setSecondPhase();
- log(LogComponent::kIndex) << "Starting to traverse through all the document key sets.";
+ LOGV2_OPTIONS(20297,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Starting to traverse through all the document key sets.");
// During the second phase of validation, iterate through each documents key set and only record
// the keys that were inconsistent during the first phase of validation.
@@ -198,8 +208,12 @@ void _gatherIndexEntryErrors(OperationContext* opCtx,
indexValidator->traverseRecordStore(opCtx, &tempValidateResults, &tempBuilder);
}
- log(LogComponent::kIndex) << "Finished traversing through all the document key sets.";
- log(LogComponent::kIndex) << "Starting to traverse through all the indexes.";
+ LOGV2_OPTIONS(20298,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Finished traversing through all the document key sets.");
+ LOGV2_OPTIONS(20299,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Starting to traverse through all the indexes.");
// Iterate through all the indexes in the collection and only record the index entry keys that
// had inconsistencies during the first phase.
@@ -208,8 +222,10 @@ void _gatherIndexEntryErrors(OperationContext* opCtx,
const IndexDescriptor* descriptor = index->descriptor();
- log(LogComponent::kIndex) << "Traversing through the index entries for index "
- << descriptor->indexName() << ".";
+ LOGV2_OPTIONS(20300,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Traversing through the index entries for index {descriptor_indexName}.",
+ "descriptor_indexName"_attr = descriptor->indexName());
indexValidator->traverseIndex(opCtx,
index.get(),
@@ -217,7 +233,9 @@ void _gatherIndexEntryErrors(OperationContext* opCtx,
/*ValidateResults=*/nullptr);
}
- log(LogComponent::kIndex) << "Finished traversing through all the indexes.";
+ LOGV2_OPTIONS(20301,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Finished traversing through all the indexes.");
indexConsistency->addIndexEntryErrors(indexNsResultsMap, result);
}
@@ -296,8 +314,12 @@ void _reportInvalidResults(OperationContext* opCtx,
const string uuidString) {
_reportValidationResults(
opCtx, validateState, indexNsResultsMap, keysPerIndex, results, output);
- log(LogComponent::kIndex) << "Validation complete for collection " << validateState->nss()
- << uuidString << ". Corruption found.";
+ LOGV2_OPTIONS(
+ 20302,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Validation complete for collection {validateState_nss}{uuidString}. Corruption found.",
+ "validateState_nss"_attr = validateState->nss(),
+ "uuidString"_attr = uuidString);
}
template <typename T>
@@ -469,7 +491,11 @@ Status validate(OperationContext* opCtx,
validateState.initializeCursors(opCtx);
// Validate the record store.
- log(LogComponent::kIndex) << "validating collection " << validateState.nss() << uuidString;
+ LOGV2_OPTIONS(20303,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "validating collection {validateState_nss}{uuidString}",
+ "validateState_nss"_attr = validateState.nss(),
+ "uuidString"_attr = uuidString);
IndexConsistency indexConsistency(opCtx, &validateState);
ValidateAdaptor indexValidator(&indexConsistency, &validateState, &indexNsResultsMap);
@@ -492,7 +518,7 @@ Status validate(OperationContext* opCtx,
if (MONGO_unlikely(pauseCollectionValidationWithLock.shouldFail())) {
_validationIsPausedForTest.store(true);
- log() << "Failpoint 'pauseCollectionValidationWithLock' activated.";
+ LOGV2(20304, "Failpoint 'pauseCollectionValidationWithLock' activated.");
pauseCollectionValidationWithLock.pauseWhileSet();
_validationIsPausedForTest.store(false);
}
@@ -518,9 +544,11 @@ Status validate(OperationContext* opCtx,
results);
if (indexConsistency.haveEntryMismatch()) {
- log(LogComponent::kIndex)
- << "Index inconsistencies were detected on collection " << validateState.nss()
- << ". Starting the second phase of index validation to gather concise errors.";
+ LOGV2_OPTIONS(20305,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Index inconsistencies were detected on collection {validateState_nss}. "
+ "Starting the second phase of index validation to gather concise errors.",
+ "validateState_nss"_attr = validateState.nss());
_gatherIndexEntryErrors(opCtx,
&validateState,
&indexConsistency,
@@ -559,8 +587,12 @@ Status validate(OperationContext* opCtx,
_reportValidationResults(
opCtx, &validateState, &indexNsResultsMap, &keysPerIndex, results, output);
- log(LogComponent::kIndex) << "Validation complete for collection " << validateState.nss()
- << uuidString << ". No corruption found.";
+ LOGV2_OPTIONS(20306,
+ {logComponentV1toV2(LogComponent::kIndex)},
+ "Validation complete for collection {validateState_nss}{uuidString}. No "
+ "corruption found.",
+ "validateState_nss"_attr = validateState.nss(),
+ "uuidString"_attr = uuidString);
output->append("ns", validateState.nss().ns());
} catch (ExceptionFor<ErrorCodes::CursorNotFound>&) {
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
index b70f4cd675f..d6c1c767623 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/views/view_catalog.h"
#include "mongo/logger/redaction.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -253,9 +254,12 @@ Status createCollectionForApplyOps(OperationContext* opCtx,
return Result(Status::OK());
if (currentName && currentName->isDropPendingNamespace()) {
- log() << "CMD: create " << newCollName
- << " - existing collection with conflicting UUID " << uuid
- << " is in a drop-pending state: " << *currentName;
+ LOGV2(20308,
+ "CMD: create {newCollName} - existing collection with conflicting UUID "
+ "{uuid} is in a drop-pending state: {currentName}",
+ "newCollName"_attr = newCollName,
+ "uuid"_attr = uuid,
+ "currentName"_attr = *currentName);
return Result(Status(ErrorCodes::NamespaceExists,
str::stream()
<< "existing collection " << currentName->toString()
@@ -297,9 +301,12 @@ Status createCollectionForApplyOps(OperationContext* opCtx,
}
// It is ok to log this because this doesn't happen very frequently.
- log() << "CMD: create " << newCollName
- << " - renaming existing collection with conflicting UUID " << uuid
- << " to temporary collection " << tmpName;
+ LOGV2(20309,
+ "CMD: create {newCollName} - renaming existing collection with "
+ "conflicting UUID {uuid} to temporary collection {tmpName}",
+ "newCollName"_attr = newCollName,
+ "uuid"_attr = uuid,
+ "tmpName"_attr = tmpName);
Status status = db->renameCollection(opCtx, newCollName, tmpName, stayTemp);
if (!status.isOK())
return Result(status);
diff --git a/src/mongo/db/catalog/database_holder_impl.cpp b/src/mongo/db/catalog/database_holder_impl.cpp
index 9f20c1f563a..c16c9cf0b0a 100644
--- a/src/mongo/db/catalog/database_holder_impl.cpp
+++ b/src/mongo/db/catalog/database_holder_impl.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/stats/top.h"
#include "mongo/db/storage/storage_engine.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -175,7 +176,7 @@ void DatabaseHolderImpl::dropDb(OperationContext* opCtx, Database* db) {
// Store the name so we have if for after the db object is deleted
auto name = db->name();
- LOG(1) << "dropDatabase " << name;
+ LOGV2_DEBUG(20310, 1, "dropDatabase {name}", "name"_attr = name);
invariant(opCtx->lockState()->isDbLockedForMode(name, MODE_X));
@@ -251,7 +252,7 @@ void DatabaseHolderImpl::closeAll(OperationContext* opCtx) {
}
for (const auto& name : dbs) {
- LOG(2) << "DatabaseHolder::closeAll name:" << name;
+ LOGV2_DEBUG(20311, 2, "DatabaseHolder::closeAll name:{name}", "name"_attr = name);
Database* db = _dbs[name];
CollectionCatalog::get(opCtx).onCloseDatabase(opCtx, name);
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 78ce8314d82..f9872364a89 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -73,6 +73,7 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/system_index.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/s/cannot_implicitly_create_collection_info.h"
#include "mongo/util/assert_util.h"
@@ -138,7 +139,7 @@ void DatabaseImpl::init(OperationContext* const opCtx) const {
Status status = validateDBName(_name);
if (!status.isOK()) {
- warning() << "tried to open invalid db: " << _name;
+ LOGV2_WARNING(20325, "tried to open invalid db: {name}", "name"_attr = _name);
uasserted(10028, status.toString());
}
@@ -159,9 +160,12 @@ void DatabaseImpl::init(OperationContext* const opCtx) const {
auto views = ViewCatalog::get(this);
Status reloadStatus = views->reload(opCtx, ViewCatalogLookupBehavior::kValidateDurableViews);
if (!reloadStatus.isOK()) {
- warning() << "Unable to parse views: " << redact(reloadStatus)
- << "; remove any invalid views from the " << _viewsName
- << " collection to restore server functionality." << startupWarningsLog;
+ LOGV2_WARNING_OPTIONS(20326,
+ {logv2::LogTag::kStartupWarnings},
+ "Unable to parse views: {reloadStatus}; remove any invalid views "
+ "from the {viewsName} collection to restore server functionality.",
+ "reloadStatus"_attr = redact(reloadStatus),
+ "viewsName"_attr = _viewsName);
}
}
@@ -173,13 +177,17 @@ void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const {
WriteUnitOfWork wuow(opCtx);
Status status = dropCollection(opCtx, collection->ns(), {});
if (!status.isOK()) {
- warning() << "could not drop temp collection '" << collection->ns()
- << "': " << redact(status);
+ LOGV2_WARNING(20327,
+ "could not drop temp collection '{collection_ns}': {status}",
+ "collection_ns"_attr = collection->ns(),
+ "status"_attr = redact(status));
}
wuow.commit();
} catch (const WriteConflictException&) {
- warning() << "could not drop temp collection '" << collection->ns()
- << "' due to WriteConflictException";
+ LOGV2_WARNING(
+ 20328,
+ "could not drop temp collection '{collection_ns}' due to WriteConflictException",
+ "collection_ns"_attr = collection->ns());
opCtx->recoveryUnit()->abandonSnapshot();
}
return true;
@@ -289,8 +297,10 @@ void DatabaseImpl::getStats(OperationContext* opCtx, BSONObjBuilder* output, dou
} else {
output->appendNumber("fsUsedSize", -1);
output->appendNumber("fsTotalSize", -1);
- log() << "Failed to query filesystem disk stats (code: " << ec.value()
- << "): " << ec.message();
+ LOGV2(20312,
+ "Failed to query filesystem disk stats (code: {ec_value}): {ec_message}",
+ "ec_value"_attr = ec.value(),
+ "ec_message"_attr = ec.message());
}
}
}
@@ -340,7 +350,7 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
repl::OpTime dropOpTime) const {
invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_X));
- LOG(1) << "dropCollection: " << nss;
+ LOGV2_DEBUG(20313, 1, "dropCollection: {nss}", "nss"_attr = nss);
// A valid 'dropOpTime' is not allowed when writes are replicated.
if (!dropOpTime.isNull() && opCtx->writesAreReplicated()) {
@@ -393,9 +403,13 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
_dropCollectionIndexes(opCtx, nss, collection);
auto commitTimestamp = opCtx->recoveryUnit()->getCommitTimestamp();
- log() << "dropCollection: " << nss << " (" << uuid
- << ") - storage engine will take ownership of drop-pending collection with optime "
- << dropOpTime << " and commit timestamp " << commitTimestamp;
+ LOGV2(20314,
+ "dropCollection: {nss} ({uuid}) - storage engine will take ownership of drop-pending "
+ "collection with optime {dropOpTime} and commit timestamp {commitTimestamp}",
+ "nss"_attr = nss,
+ "uuid"_attr = uuid,
+ "dropOpTime"_attr = dropOpTime,
+ "commitTimestamp"_attr = commitTimestamp);
if (dropOpTime.isNull()) {
// Log oplog entry for collection drop and remove the UUID.
dropOpTime = opObserver->onDropCollection(
@@ -434,9 +448,13 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
// Rename collection using drop-pending namespace generated from drop optime.
auto dpns = nss.makeDropPendingNamespace(dropOpTime);
const bool stayTemp = true;
- log() << "dropCollection: " << nss << " (" << uuid
- << ") - renaming to drop-pending collection: " << dpns << " with drop optime "
- << dropOpTime;
+ LOGV2(20315,
+ "dropCollection: {nss} ({uuid}) - renaming to drop-pending collection: {dpns} with drop "
+ "optime {dropOpTime}",
+ "nss"_attr = nss,
+ "uuid"_attr = uuid,
+ "dpns"_attr = dpns,
+ "dropOpTime"_attr = dropOpTime);
{
Lock::CollectionLock collLk(opCtx, dpns, MODE_X);
fassert(40464, renameCollection(opCtx, nss, dpns, stayTemp));
@@ -453,19 +471,22 @@ void DatabaseImpl::_dropCollectionIndexes(OperationContext* opCtx,
const NamespaceString& nss,
Collection* collection) const {
invariant(_name == nss.db());
- LOG(1) << "dropCollection: " << nss << " - dropAllIndexes start";
+ LOGV2_DEBUG(20316, 1, "dropCollection: {nss} - dropAllIndexes start", "nss"_attr = nss);
collection->getIndexCatalog()->dropAllIndexes(opCtx, true);
invariant(DurableCatalog::get(opCtx)->getTotalIndexCount(opCtx, collection->getCatalogId()) ==
0);
- LOG(1) << "dropCollection: " << nss << " - dropAllIndexes done";
+ LOGV2_DEBUG(20317, 1, "dropCollection: {nss} - dropAllIndexes done", "nss"_attr = nss);
}
Status DatabaseImpl::_finishDropCollection(OperationContext* opCtx,
const NamespaceString& nss,
Collection* collection) const {
UUID uuid = collection->uuid();
- log() << "Finishing collection drop for " << nss << " (" << uuid << ").";
+ LOGV2(20318,
+ "Finishing collection drop for {nss} ({uuid}).",
+ "nss"_attr = nss,
+ "uuid"_attr = uuid);
auto status = DurableCatalog::get(opCtx)->dropCollection(opCtx, collection->getCatalogId());
if (!status.isOK())
@@ -514,8 +535,11 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx,
<< toNss);
}
- log() << "renameCollection: renaming collection " << collToRename->uuid() << " from " << fromNss
- << " to " << toNss;
+ LOGV2(20319,
+ "renameCollection: renaming collection {collToRename_uuid} from {fromNss} to {toNss}",
+ "collToRename_uuid"_attr = collToRename->uuid(),
+ "fromNss"_attr = fromNss,
+ "toNss"_attr = toNss);
Top::get(opCtx->getServiceContext()).collectionDropped(fromNss);
@@ -623,7 +647,7 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx,
if (!canAcceptWrites) {
std::string msg = str::stream()
<< "Attempted to create a new collection " << nss << " without a UUID";
- severe() << msg;
+ LOGV2_FATAL(20329, "{msg}", "msg"_attr = msg);
uasserted(ErrorCodes::InvalidOptions, msg);
} else {
optionsWithUUID.uuid.emplace(CollectionUUID::gen());
@@ -658,8 +682,13 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx,
_checkCanCreateCollection(opCtx, nss, optionsWithUUID);
audit::logCreateCollection(&cc(), nss.ns());
- log() << "createCollection: " << nss << " with " << (generatedUUID ? "generated" : "provided")
- << " UUID: " << optionsWithUUID.uuid.get() << " and options: " << options.toBSON();
+ LOGV2(20320,
+ "createCollection: {nss} with {generatedUUID_generated_provided} UUID: "
+ "{optionsWithUUID_uuid_get} and options: {options}",
+ "nss"_attr = nss,
+ "generatedUUID_generated_provided"_attr = (generatedUUID ? "generated" : "provided"),
+ "optionsWithUUID_uuid_get"_attr = optionsWithUUID.uuid.get(),
+ "options"_attr = options.toBSON());
// Create Collection object
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
@@ -781,7 +810,10 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext*
CollectionCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, _name)) {
if (nss.isDropPendingNamespace()) {
auto dropOpTime = fassert(40459, nss.getDropPendingNamespaceOpTime());
- log() << "Found drop-pending namespace " << nss << " with drop optime " << dropOpTime;
+ LOGV2(20321,
+ "Found drop-pending namespace {nss} with drop optime {dropOpTime}",
+ "nss"_attr = nss,
+ "dropOpTime"_attr = dropOpTime);
repl::DropPendingCollectionReaper::get(opCtx)->addDropPendingNamespace(
opCtx, dropOpTime, nss);
}
@@ -796,11 +828,15 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext*
if (coll->getIndexCatalog()->findIdIndex(opCtx))
continue;
- log() << "WARNING: the collection '" << nss << "' lacks a unique index on _id."
- << " This index is needed for replication to function properly" << startupWarningsLog;
- log() << "\t To fix this, you need to create a unique index on _id."
- << " See http://dochub.mongodb.org/core/build-replica-set-indexes"
- << startupWarningsLog;
+ LOGV2_OPTIONS(20322,
+ {logv2::LogTag::kStartupWarnings},
+ "WARNING: the collection '{nss}' lacks a unique index on _id. This index is "
+ "needed for replication to function properly",
+ "nss"_attr = nss);
+ LOGV2_OPTIONS(20323,
+ {logv2::LogTag::kStartupWarnings},
+ "\t To fix this, you need to create a unique index on _id. See "
+ "http://dochub.mongodb.org/core/build-replica-set-indexes");
}
}
@@ -809,7 +845,11 @@ Status DatabaseImpl::userCreateNS(OperationContext* opCtx,
CollectionOptions collectionOptions,
bool createDefaultIndexes,
const BSONObj& idIndex) const {
- LOG(1) << "create collection " << nss << ' ' << collectionOptions.toBSON();
+ LOGV2_DEBUG(20324,
+ 1,
+ "create collection {nss} {collectionOptions}",
+ "nss"_attr = nss,
+ "collectionOptions"_attr = collectionOptions.toBSON());
if (!NamespaceString::validCollectionComponent(nss.ns()))
return Status(ErrorCodes::InvalidNamespace, str::stream() << "invalid ns: " << nss);
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp
index f973c1257bd..1f18d42eec0 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -74,8 +75,9 @@ Status _dropView(OperationContext* opCtx,
Lock::CollectionLock systemViewsLock(opCtx, db->getSystemViewsName(), MODE_X);
if (MONGO_unlikely(hangDuringDropCollection.shouldFail())) {
- log() << "hangDuringDropCollection fail point enabled. Blocking until fail point is "
- "disabled.";
+ LOGV2(20330,
+ "hangDuringDropCollection fail point enabled. Blocking until fail point is "
+ "disabled.");
hangDuringDropCollection.pauseWhileSet();
}
@@ -116,8 +118,9 @@ Status _dropCollection(OperationContext* opCtx,
}
if (MONGO_unlikely(hangDuringDropCollection.shouldFail())) {
- log() << "hangDuringDropCollection fail point enabled. Blocking until fail point is "
- "disabled.";
+ LOGV2(20331,
+ "hangDuringDropCollection fail point enabled. Blocking until fail point is "
+ "disabled.");
hangDuringDropCollection.pauseWhileSet();
}
@@ -160,11 +163,11 @@ Status dropCollection(OperationContext* opCtx,
const repl::OpTime& dropOpTime,
DropCollectionSystemCollectionMode systemCollectionMode) {
if (!serverGlobalParams.quiet.load()) {
- log() << "CMD: drop " << collectionName;
+ LOGV2(20332, "CMD: drop {collectionName}", "collectionName"_attr = collectionName);
}
if (MONGO_unlikely(hangDropCollectionBeforeLockAcquisition.shouldFail())) {
- log() << "Hanging drop collection before lock acquisition while fail point is set";
+ LOGV2(20333, "Hanging drop collection before lock acquisition while fail point is set");
hangDropCollectionBeforeLockAcquisition.pauseWhileSet();
}
return writeConflictRetry(opCtx, "drop", collectionName.ns(), [&] {
diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp
index f598148c68a..7276059b343 100644
--- a/src/mongo/db/catalog/drop_database.cpp
+++ b/src/mongo/db/catalog/drop_database.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/service_context.h"
#include "mongo/db/write_concern_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/duration.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -85,7 +86,7 @@ void _finishDropDatabase(OperationContext* opCtx,
});
if (MONGO_unlikely(dropDatabaseHangBeforeInMemoryDrop.shouldFail())) {
- log() << "dropDatabase - fail point dropDatabaseHangBeforeInMemoryDrop enabled.";
+ LOGV2(20334, "dropDatabase - fail point dropDatabaseHangBeforeInMemoryDrop enabled.");
dropDatabaseHangBeforeInMemoryDrop.pauseWhileSet();
}
@@ -93,8 +94,11 @@ void _finishDropDatabase(OperationContext* opCtx,
databaseHolder->dropDb(opCtx, db);
dropPendingGuard.dismiss();
- log() << "dropDatabase " << dbName << " - dropped " << numCollections << " collection(s)";
- log() << "dropDatabase " << dbName << " - finished";
+ LOGV2(20335,
+ "dropDatabase {dbName} - dropped {numCollections} collection(s)",
+ "dbName"_attr = dbName,
+ "numCollections"_attr = numCollections);
+ LOGV2(20336, "dropDatabase {dbName} - finished", "dbName"_attr = dbName);
}
} // namespace
@@ -147,7 +151,7 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) {
<< "The database is currently being dropped. Database: " << dbName);
}
- log() << "dropDatabase " << dbName << " - starting";
+ LOGV2(20337, "dropDatabase {dbName} - starting", "dbName"_attr = dbName);
db->setDropPending(opCtx, true);
// If Database::dropCollectionEventIfSystem() fails, we should reset the drop-pending state
@@ -164,11 +168,17 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) {
const auto& nss = collection->ns();
numCollections++;
- log() << "dropDatabase " << dbName << " - dropping collection: " << nss;
+ LOGV2(20338,
+ "dropDatabase {dbName} - dropping collection: {nss}",
+ "dbName"_attr = dbName,
+ "nss"_attr = nss);
if (nss.isDropPendingNamespace() && replCoord->isReplEnabled() &&
opCtx->writesAreReplicated()) {
- log() << "dropDatabase " << dbName << " - found drop-pending collection: " << nss;
+ LOGV2(20339,
+ "dropDatabase {dbName} - found drop-pending collection: {nss}",
+ "dbName"_attr = dbName,
+ "nss"_attr = nss);
latestDropPendingOpTime = std::max(
latestDropPendingOpTime, uassertStatusOK(nss.getDropPendingNamespaceOpTime()));
continue;
@@ -264,17 +274,26 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) {
const WriteConcernOptions dropDatabaseWriteConcern(
WriteConcernOptions::kMajority, WriteConcernOptions::SyncMode::UNSET, wTimeout);
- log() << "dropDatabase " << dbName << " waiting for " << awaitOpTime
- << " to be replicated at " << dropDatabaseWriteConcern.toBSON() << ". Dropping "
- << numCollectionsToDrop << " collection(s), with last collection drop at "
- << latestDropPendingOpTime;
+ LOGV2(20340,
+ "dropDatabase {dbName} waiting for {awaitOpTime} to be replicated at "
+ "{dropDatabaseWriteConcern}. Dropping {numCollectionsToDrop} collection(s), with "
+ "last collection drop at {latestDropPendingOpTime}",
+ "dbName"_attr = dbName,
+ "awaitOpTime"_attr = awaitOpTime,
+ "dropDatabaseWriteConcern"_attr = dropDatabaseWriteConcern.toBSON(),
+ "numCollectionsToDrop"_attr = numCollectionsToDrop,
+ "latestDropPendingOpTime"_attr = latestDropPendingOpTime);
auto result = replCoord->awaitReplication(opCtx, awaitOpTime, dropDatabaseWriteConcern);
// If the user-provided write concern is weaker than majority, this is effectively a no-op.
if (result.status.isOK() && !userWriteConcern.usedDefault) {
- log() << "dropDatabase " << dbName << " waiting for " << awaitOpTime
- << " to be replicated at " << userWriteConcern.toBSON();
+ LOGV2(20341,
+ "dropDatabase {dbName} waiting for {awaitOpTime} to be replicated at "
+ "{userWriteConcern}",
+ "dbName"_attr = dbName,
+ "awaitOpTime"_attr = awaitOpTime,
+ "userWriteConcern"_attr = userWriteConcern.toBSON());
result = replCoord->awaitReplication(opCtx, awaitOpTime, userWriteConcern);
}
@@ -286,14 +305,19 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) {
<< awaitOpTime.toString() << ") to replicate.");
}
- log() << "dropDatabase " << dbName << " - successfully dropped " << numCollectionsToDrop
- << " collection(s) (most recent drop optime: " << awaitOpTime << ") after "
- << result.duration << ". dropping database";
+ LOGV2(20342,
+ "dropDatabase {dbName} - successfully dropped {numCollectionsToDrop} collection(s) "
+ "(most recent drop optime: {awaitOpTime}) after {result_duration}. dropping database",
+ "dbName"_attr = dbName,
+ "numCollectionsToDrop"_attr = numCollectionsToDrop,
+ "awaitOpTime"_attr = awaitOpTime,
+ "result_duration"_attr = result.duration);
}
if (MONGO_unlikely(dropDatabaseHangAfterAllCollectionsDrop.shouldFail())) {
- log() << "dropDatabase - fail point dropDatabaseHangAfterAllCollectionsDrop enabled. "
- "Blocking until fail point is disabled. ";
+ LOGV2(20343,
+ "dropDatabase - fail point dropDatabaseHangAfterAllCollectionsDrop enabled. "
+ "Blocking until fail point is disabled. ");
dropDatabaseHangAfterAllCollectionsDrop.pauseWhileSet();
}
diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp
index 8f29522b82f..1d55cd77d59 100644
--- a/src/mongo/db/catalog/drop_indexes.cpp
+++ b/src/mongo/db/catalog/drop_indexes.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/repl_set_member_in_standalone_mode.h"
#include "mongo/db/service_context.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -222,7 +223,10 @@ Status dropIndexes(OperationContext* opCtx,
}
if (!serverGlobalParams.quiet.load()) {
- LOG(0) << "CMD: dropIndexes " << nss << ": " << cmdObj[kIndexFieldName].toString(false);
+ LOGV2(20344,
+ "CMD: dropIndexes {nss}: {cmdObj_kIndexFieldName_false}",
+ "nss"_attr = nss,
+ "cmdObj_kIndexFieldName_false"_attr = cmdObj[kIndexFieldName].toString(false));
}
// If db/collection does not exist, short circuit and return.
diff --git a/src/mongo/db/catalog/index_build_block.cpp b/src/mongo/db/catalog/index_build_block.cpp
index 64fb8c10cdd..3cc6bd8f893 100644
--- a/src/mongo/db/catalog/index_build_block.cpp
+++ b/src/mongo/db/catalog/index_build_block.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/query/collection_query_info.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/ttl_collection_cache.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -178,7 +179,10 @@ void IndexBuildBlock::success(OperationContext* opCtx, Collection* collection) {
invariant(_indexBuildInterceptor->areAllConstraintsChecked(opCtx));
}
- log() << "index build: done building index " << _indexName << " on ns " << _nss;
+ LOGV2(20345,
+ "index build: done building index {indexName} on ns {nss}",
+ "indexName"_attr = _indexName,
+ "nss"_attr = _nss);
collection->indexBuildSuccess(opCtx, _indexCatalogEntry);
auto svcCtx = opCtx->getClient()->getServiceContext();
diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp
index 1710718790e..6e88a1985c0 100644
--- a/src/mongo/db/catalog/index_builds_manager.cpp
+++ b/src/mongo/db/catalog/index_builds_manager.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/write_unit_of_work.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -109,8 +110,13 @@ Status IndexBuildsManager::setUpIndexBuild(OperationContext* opCtx,
return ex.toStatus();
}
- log() << "Index build initialized: " << buildUUID << ": " << nss << " (" << collection->uuid()
- << " ): indexes: " << indexes.size();
+ LOGV2(
+ 20346,
+ "Index build initialized: {buildUUID}: {nss} ({collection_uuid} ): indexes: {indexes_size}",
+ "buildUUID"_attr = buildUUID,
+ "nss"_attr = nss,
+ "collection_uuid"_attr = collection->uuid(),
+ "indexes_size"_attr = indexes.size());
return Status::OK();
}
@@ -155,12 +161,16 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd
auto validStatus = validateBSON(data.data(), data.size(), BSONVersion::kLatest);
if (!validStatus.isOK()) {
if (repair == RepairData::kNo) {
- severe() << "Invalid BSON detected at " << id << ": "
- << redact(validStatus);
+ LOGV2_FATAL(20349,
+ "Invalid BSON detected at {id}: {validStatus}",
+ "id"_attr = id,
+ "validStatus"_attr = redact(validStatus));
fassertFailed(31396);
}
- warning() << "Invalid BSON detected at " << id << ": " << redact(validStatus)
- << ". Deleting.";
+ LOGV2_WARNING(20348,
+ "Invalid BSON detected at {id}: {validStatus}. Deleting.",
+ "id"_attr = id,
+ "validStatus"_attr = redact(validStatus));
rs->deleteRecord(opCtx, id);
} else {
numRecords++;
@@ -277,7 +287,10 @@ bool IndexBuildsManager::abortIndexBuildWithoutCleanup(OperationContext* opCtx,
return false;
}
- log() << "Index build aborted without cleanup: " << buildUUID << ": " << reason;
+ LOGV2(20347,
+ "Index build aborted without cleanup: {buildUUID}: {reason}",
+ "buildUUID"_attr = buildUUID,
+ "reason"_attr = reason);
std::shared_ptr<MultiIndexBlock> builder = builderIt->second;
lk.unlock();
diff --git a/src/mongo/db/catalog/index_catalog_entry_impl.cpp b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
index 3c208009adc..cd2a5f18b32 100644
--- a/src/mongo/db/catalog/index_catalog_entry_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_entry_impl.cpp
@@ -52,6 +52,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -109,8 +110,12 @@ IndexCatalogEntryImpl::IndexCatalogEntryImpl(OperationContext* const opCtx,
MatchExpressionParser::kBanAllSpecialFeatures);
invariant(statusWithMatcher.getStatus());
_filterExpression = std::move(statusWithMatcher.getValue());
- LOG(2) << "have filter expression for " << ns() << " " << _descriptor->indexName() << " "
- << redact(filter);
+ LOGV2_DEBUG(20350,
+ 2,
+ "have filter expression for {ns} {descriptor_indexName} {filter}",
+ "ns"_attr = ns(),
+ "descriptor_indexName"_attr = _descriptor->indexName(),
+ "filter"_attr = redact(filter));
}
}
@@ -257,8 +262,12 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
}
if (indexMetadataHasChanged && _queryInfo) {
- LOG(1) << ns() << ": clearing plan cache - index " << _descriptor->keyPattern()
- << " set to multi key.";
+ LOGV2_DEBUG(
+ 20351,
+ 1,
+ "{ns}: clearing plan cache - index {descriptor_keyPattern} set to multi key.",
+ "ns"_attr = ns(),
+ "descriptor_keyPattern"_attr = _descriptor->keyPattern());
_queryInfo->clearQueryCache();
}
};
@@ -288,8 +297,10 @@ void IndexCatalogEntryImpl::setMultikey(OperationContext* opCtx,
auto status = opCtx->recoveryUnit()->setTimestamp(writeTs);
if (status.code() == ErrorCodes::BadValue) {
- log() << "Temporarily could not timestamp the multikey catalog write, retrying. "
- << status.reason();
+ LOGV2(20352,
+ "Temporarily could not timestamp the multikey catalog write, retrying. "
+ "{status_reason}",
+ "status_reason"_attr = status.reason());
throw WriteConflictException();
}
fassert(31164, status);
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index d1ac7fea2d0..35fc295c73e 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -73,6 +73,7 @@
#include "mongo/db/storage/kv/kv_engine.h"
#include "mongo/db/storage/storage_engine_init.h"
#include "mongo/db/ttl_collection_cache.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -229,30 +230,40 @@ void IndexCatalogImpl::_logInternalState(OperationContext* opCtx,
bool haveIdIndex) {
invariant(opCtx->lockState()->isCollectionLockedForMode(_collection->ns(), MODE_X));
- error() << "Internal Index Catalog state: "
- << " numIndexesTotal(): " << numIndexesTotal(opCtx)
- << " numSystemIndexesEntries: " << numIndexesInCollectionCatalogEntry
- << " _readyIndexes.size(): " << _readyIndexes.size()
- << " _buildingIndexes.size(): " << _buildingIndexes.size()
- << " indexNamesToDrop: " << indexNamesToDrop.size() << " haveIdIndex: " << haveIdIndex;
+ LOGV2_ERROR(
+ 20365,
+ "Internal Index Catalog state: numIndexesTotal(): {numIndexesTotal_opCtx} "
+ "numSystemIndexesEntries: {numIndexesInCollectionCatalogEntry} _readyIndexes.size(): "
+ "{readyIndexes_size} _buildingIndexes.size(): {buildingIndexes_size} indexNamesToDrop: "
+ "{indexNamesToDrop_size} haveIdIndex: {haveIdIndex}",
+ "numIndexesTotal_opCtx"_attr = numIndexesTotal(opCtx),
+ "numIndexesInCollectionCatalogEntry"_attr = numIndexesInCollectionCatalogEntry,
+ "readyIndexes_size"_attr = _readyIndexes.size(),
+ "buildingIndexes_size"_attr = _buildingIndexes.size(),
+ "indexNamesToDrop_size"_attr = indexNamesToDrop.size(),
+ "haveIdIndex"_attr = haveIdIndex);
// Report the ready indexes.
- error() << "Ready indexes:";
+ LOGV2_ERROR(20366, "Ready indexes:");
for (const auto& entry : _readyIndexes) {
const IndexDescriptor* desc = entry->descriptor();
- error() << "Index '" << desc->indexName()
- << "' with specification: " << redact(desc->infoObj());
+ LOGV2_ERROR(20367,
+ "Index '{desc_indexName}' with specification: {desc_infoObj}",
+ "desc_indexName"_attr = desc->indexName(),
+ "desc_infoObj"_attr = redact(desc->infoObj()));
}
// Report the in-progress indexes.
- error() << "In-progress indexes:";
+ LOGV2_ERROR(20368, "In-progress indexes:");
for (const auto& entry : _buildingIndexes) {
const IndexDescriptor* desc = entry->descriptor();
- error() << "Index '" << desc->indexName()
- << "' with specification: " << redact(desc->infoObj());
+ LOGV2_ERROR(20369,
+ "Index '{desc_indexName}' with specification: {desc_infoObj}",
+ "desc_indexName"_attr = desc->indexName(),
+ "desc_infoObj"_attr = redact(desc->infoObj()));
}
- error() << "Internal Collection Catalog Entry state:";
+ LOGV2_ERROR(20370, "Internal Collection Catalog Entry state:");
std::vector<std::string> allIndexes;
std::vector<std::string> readyIndexes;
@@ -260,23 +271,36 @@ void IndexCatalogImpl::_logInternalState(OperationContext* opCtx,
durableCatalog->getAllIndexes(opCtx, _collection->getCatalogId(), &allIndexes);
durableCatalog->getReadyIndexes(opCtx, _collection->getCatalogId(), &readyIndexes);
- error() << "All indexes:";
+ LOGV2_ERROR(20371, "All indexes:");
for (const auto& index : allIndexes) {
- error() << "Index '" << index << "' with specification: "
- << redact(durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index));
+ LOGV2_ERROR(20372,
+ "Index '{index}' with specification: "
+ "{durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index}",
+ "index"_attr = index,
+ "durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index"_attr = redact(
+ durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index)));
}
- error() << "Ready indexes:";
+ LOGV2_ERROR(20373, "Ready indexes:");
for (const auto& index : readyIndexes) {
- error() << "Index '" << index << "' with specification: "
- << redact(durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index));
+ LOGV2_ERROR(20374,
+ "Index '{index}' with specification: "
+ "{durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index}",
+ "index"_attr = index,
+ "durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_index"_attr = redact(
+ durableCatalog->getIndexSpec(opCtx, _collection->getCatalogId(), index)));
}
- error() << "Index names to drop:";
+ LOGV2_ERROR(20375, "Index names to drop:");
for (const auto& indexNameToDrop : indexNamesToDrop) {
- error() << "Index '" << indexNameToDrop << "' with specification: "
- << redact(durableCatalog->getIndexSpec(
- opCtx, _collection->getCatalogId(), indexNameToDrop));
+ LOGV2_ERROR(
+ 20376,
+ "Index '{indexNameToDrop}' with specification: "
+ "{durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_indexNameToDrop}",
+ "indexNameToDrop"_attr = indexNameToDrop,
+ "durableCatalog_getIndexSpec_opCtx_collection_getCatalogId_indexNameToDrop"_attr =
+ redact(durableCatalog->getIndexSpec(
+ opCtx, _collection->getCatalogId(), indexNameToDrop)));
}
}
@@ -364,8 +388,12 @@ IndexCatalogEntry* IndexCatalogImpl::createIndexEntry(OperationContext* opCtx,
CreateIndexEntryFlags flags) {
Status status = _isSpecOk(opCtx, descriptor->infoObj());
if (!status.isOK()) {
- severe() << "Found an invalid index " << descriptor->infoObj() << " on the "
- << _collection->ns() << " collection: " << redact(status);
+ LOGV2_FATAL(20378,
+ "Found an invalid index {descriptor_infoObj} on the {collection_ns} "
+ "collection: {status}",
+ "descriptor_infoObj"_attr = descriptor->infoObj(),
+ "collection_ns"_attr = _collection->ns(),
+ "status"_attr = redact(status));
fassertFailedNoTrace(28782);
}
@@ -788,8 +816,13 @@ Status IndexCatalogImpl::_doesSpecConflictWithExisting(OperationContext* opCtx,
const IndexDescriptor* desc =
findIndexByKeyPatternAndCollationSpec(opCtx, key, collation, includeUnfinishedIndexes);
if (desc) {
- LOG(2) << "Index already exists with a different name: " << name << " pattern: " << key
- << " collation: " << collation;
+ LOGV2_DEBUG(20353,
+ 2,
+ "Index already exists with a different name: {name} pattern: {key} "
+ "collation: {collation}",
+ "name"_attr = name,
+ "key"_attr = key,
+ "collation"_attr = collation);
IndexDescriptor temp(_collection, _getAccessMethodName(key), spec);
if (!desc->areIndexOptionsEquivalent(&temp))
@@ -807,7 +840,7 @@ Status IndexCatalogImpl::_doesSpecConflictWithExisting(OperationContext* opCtx,
if (numIndexesTotal(opCtx) >= kMaxNumIndexesAllowed) {
string s = str::stream() << "add index fails, too many indexes for " << _collection->ns()
<< " key:" << key;
- log() << s;
+ LOGV2(20354, "{s}", "s"_attr = s);
return Status(ErrorCodes::CannotCreateIndex, s);
}
@@ -875,7 +908,7 @@ void IndexCatalogImpl::dropAllIndexes(OperationContext* opCtx,
string indexName = indexNamesToDrop[i];
const IndexDescriptor* desc = findIndexByName(opCtx, indexName, true);
invariant(desc);
- LOG(1) << "\t dropAllIndexes dropping: " << desc->toString();
+ LOGV2_DEBUG(20355, 1, "\t dropAllIndexes dropping: {desc}", "desc"_attr = desc->toString());
IndexCatalogEntry* entry = _readyIndexes.find(desc);
invariant(entry);
@@ -1019,8 +1052,12 @@ void IndexCatalogImpl::deleteIndexFromDisk(OperationContext* opCtx, const string
* This is ok, as we may be partially through index creation.
*/
} else if (!status.isOK()) {
- warning() << "couldn't drop index " << indexName << " on collection: " << _collection->ns()
- << " because of " << redact(status);
+ LOGV2_WARNING(
+ 20364,
+ "couldn't drop index {indexName} on collection: {collection_ns} because of {status}",
+ "indexName"_attr = indexName,
+ "collection_ns"_attr = _collection->ns(),
+ "status"_attr = redact(status));
}
}
@@ -1076,7 +1113,7 @@ int IndexCatalogImpl::numIndexesTotal(OperationContext* opCtx) const {
}
// Ignore the write conflict for read transactions; we will eventually roll back this
// transaction anyway.
- log() << " Skipping dassert check due to: " << ex;
+ LOGV2(20356, " Skipping dassert check due to: {ex}", "ex"_attr = ex);
}
}
@@ -1097,17 +1134,19 @@ int IndexCatalogImpl::numIndexesReady(OperationContext* opCtx) const {
// There is a potential inconistency where the index information in the collection catalog
// entry and the index catalog differ. Log as much information as possible here.
if (itIndexes.size() != completedIndexes.size()) {
- log() << "index catalog reports: ";
+ LOGV2(20357, "index catalog reports: ");
for (const IndexDescriptor* i : itIndexes) {
- log() << " index: " << i->toString();
+ LOGV2(20358, " index: {i}", "i"_attr = i->toString());
}
- log() << "collection catalog reports: ";
+ LOGV2(20359, "collection catalog reports: ");
for (auto const& i : completedIndexes) {
- log() << " index: " << i;
+ LOGV2(20360, " index: {i}", "i"_attr = i);
}
- log() << "collection uuid: " << _collection->uuid();
+ LOGV2(20361,
+ "collection uuid: {collection_uuid}",
+ "collection_uuid"_attr = _collection->uuid());
invariant(itIndexes.size() == completedIndexes.size(),
"The number of ready indexes reported in the collection metadata catalog did "
@@ -1484,8 +1523,11 @@ void IndexCatalogImpl::_unindexKeys(OperationContext* opCtx,
Status status = index->accessMethod()->removeKeys(opCtx, keys, loc, options, &removed);
if (!status.isOK()) {
- log() << "Couldn't unindex record " << redact(obj) << " from collection "
- << _collection->ns() << ". Status: " << redact(status);
+ LOGV2(20362,
+ "Couldn't unindex record {obj} from collection {collection_ns}. Status: {status}",
+ "obj"_attr = redact(obj),
+ "collection_ns"_attr = _collection->ns(),
+ "status"_attr = redact(status));
}
if (keysDeletedOut) {
@@ -1615,10 +1657,15 @@ Status IndexCatalogImpl::compactIndexes(OperationContext* opCtx) {
++it) {
IndexCatalogEntry* entry = it->get();
- LOG(1) << "compacting index: " << entry->descriptor()->toString();
+ LOGV2_DEBUG(20363,
+ 1,
+ "compacting index: {entry_descriptor}",
+ "entry_descriptor"_attr = entry->descriptor()->toString());
Status status = entry->accessMethod()->compact(opCtx);
if (!status.isOK()) {
- error() << "failed to compact index: " << entry->descriptor()->toString();
+ LOGV2_ERROR(20377,
+ "failed to compact index: {entry_descriptor}",
+ "entry_descriptor"_attr = entry->descriptor()->toString());
return status;
}
}
diff --git a/src/mongo/db/catalog/index_timestamp_helper.cpp b/src/mongo/db/catalog/index_timestamp_helper.cpp
index 8686e7af8f8..55e8dd04d74 100644
--- a/src/mongo/db/catalog/index_timestamp_helper.cpp
+++ b/src/mongo/db/catalog/index_timestamp_helper.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/logical_clock.h"
#include "mongo/db/repl/member_state.h"
#include "mongo/db/repl/replication_coordinator.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -94,10 +95,15 @@ void IndexTimestampHelper::setGhostCommitTimestampForWrite(OperationContext* opC
auto status = opCtx->recoveryUnit()->setTimestamp(commitTimestamp);
if (status.code() == ErrorCodes::BadValue) {
- log() << "Temporarily could not apply ghost commit timestamp. " << status.reason();
+ LOGV2(20379,
+ "Temporarily could not apply ghost commit timestamp. {status_reason}",
+ "status_reason"_attr = status.reason());
throw WriteConflictException();
}
- LOG(1) << "assigning ghost commit timestamp: " << commitTimestamp.toString();
+ LOGV2_DEBUG(20380,
+ 1,
+ "assigning ghost commit timestamp: {commitTimestamp}",
+ "commitTimestamp"_attr = commitTimestamp.toString());
fassert(51053, status);
}
@@ -153,8 +159,9 @@ bool IndexTimestampHelper::setGhostCommitTimestampForCatalogWrite(OperationConte
auto status = opCtx->recoveryUnit()->setTimestamp(
LogicalClock::get(opCtx)->getClusterTime().asTimestamp());
if (status.code() == ErrorCodes::BadValue) {
- log() << "Temporarily could not timestamp the index build commit, retrying. "
- << status.reason();
+ LOGV2(20381,
+ "Temporarily could not timestamp the index build commit, retrying. {status_reason}",
+ "status_reason"_attr = status.reason());
throw WriteConflictException();
}
fassert(50701, status);
diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp
index 06cf823e09c..b3a7aaf8209 100644
--- a/src/mongo/db/catalog/multi_index_block.cpp
+++ b/src/mongo/db/catalog/multi_index_block.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/storage/write_unit_of_work.h"
#include "mongo/logger/redaction.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -141,7 +142,7 @@ void MultiIndexBlock::cleanUpAfterBuild(OperationContext* opCtx,
// Simply get a timestamp to write with here; we can't write to the oplog.
repl::UnreplicatedWritesBlock uwb(opCtx);
if (!IndexTimestampHelper::setGhostCommitTimestampForCatalogWrite(opCtx, nss)) {
- log() << "Did not timestamp index abort write.";
+ LOGV2(20382, "Did not timestamp index abort write.");
}
}
@@ -155,11 +156,16 @@ void MultiIndexBlock::cleanUpAfterBuild(OperationContext* opCtx,
} catch (const DBException& e) {
if (e.toStatus() == ErrorCodes::ExceededMemoryLimit)
continue;
- error() << "Caught exception while cleaning up partially built indexes: " << redact(e);
+ LOGV2_ERROR(20393,
+ "Caught exception while cleaning up partially built indexes: {e}",
+ "e"_attr = redact(e));
} catch (const std::exception& e) {
- error() << "Caught exception while cleaning up partially built indexes: " << e.what();
+ LOGV2_ERROR(20394,
+ "Caught exception while cleaning up partially built indexes: {e_what}",
+ "e_what"_attr = e.what());
} catch (...) {
- error() << "Caught unknown exception while cleaning up partially built indexes.";
+ LOGV2_ERROR(20395,
+ "Caught unknown exception while cleaning up partially built indexes.");
}
fassertFailed(18644);
}
@@ -238,9 +244,10 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(OperationContext* opCtx,
BSONObj info = indexSpecs[i];
if (enableHybrid) {
if (info["background"].isBoolean() && !info["background"].Bool()) {
- log()
- << "ignoring obselete { background: false } index build option because all "
- "indexes are built in the background with the hybrid method";
+ LOGV2(
+ 20383,
+ "ignoring obselete {{ background: false }} index build option because all "
+ "indexes are built in the background with the hybrid method");
}
continue;
}
@@ -321,11 +328,17 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(OperationContext* opCtx,
}
index.options.fromIndexBuilder = true;
- log() << "index build: starting on " << ns << " properties: " << descriptor->toString()
- << " using method: " << _method;
+ LOGV2(20384,
+ "index build: starting on {ns} properties: {descriptor} using method: {method}",
+ "ns"_attr = ns,
+ "descriptor"_attr = descriptor->toString(),
+ "method"_attr = _method);
if (index.bulk)
- log() << "build may temporarily use up to "
- << eachIndexBuildMaxMemoryUsageBytes / 1024 / 1024 << " megabytes of RAM";
+ LOGV2(20385,
+ "build may temporarily use up to "
+ "{eachIndexBuildMaxMemoryUsageBytes_1024_1024} megabytes of RAM",
+ "eachIndexBuildMaxMemoryUsageBytes_1024_1024"_attr =
+ eachIndexBuildMaxMemoryUsageBytes / 1024 / 1024);
index.filterExpression = index.block->getEntry()->getFilterExpression();
@@ -367,7 +380,8 @@ void failPointHangDuringBuild(FailPoint* fp, StringData where, const BSONObj& do
fp->executeIf(
[&](const BSONObj& data) {
int i = doc.getIntField("i");
- log() << "Hanging " << where << " index build of i=" << i;
+ LOGV2(
+ 20386, "Hanging {where} index build of i={i}", "where"_attr = where, "i"_attr = i);
fp->pauseWhileSet();
},
[&](const BSONObj& data) {
@@ -405,13 +419,13 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx,
if (MONGO_unlikely(hangAfterSettingUpIndexBuild.shouldFail())) {
// Hang the build after the BackgroundOperation and curOP info is set up.
- log() << "Hanging index build due to failpoint 'hangAfterSettingUpIndexBuild'";
+ LOGV2(20387, "Hanging index build due to failpoint 'hangAfterSettingUpIndexBuild'");
hangAfterSettingUpIndexBuild.pauseWhileSet();
}
if (MONGO_unlikely(hangAndThenFailIndexBuild.shouldFail())) {
// Hang the build after the BackgroundOperation and curOP info is set up.
- log() << "Hanging index build due to failpoint 'hangAndThenFailIndexBuild'";
+ LOGV2(20388, "Hanging index build due to failpoint 'hangAndThenFailIndexBuild'");
hangAndThenFailIndexBuild.pauseWhileSet();
return {ErrorCodes::InternalError,
"Failed index build because of failpoint 'hangAndThenFailIndexBuild'"};
@@ -518,8 +532,9 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx,
}
if (MONGO_unlikely(leaveIndexBuildUnfinishedForShutdown.shouldFail())) {
- log() << "Index build interrupted due to 'leaveIndexBuildUnfinishedForShutdown' failpoint. "
- "Mimicking shutdown error code.";
+ LOGV2(20389,
+ "Index build interrupted due to 'leaveIndexBuildUnfinishedForShutdown' failpoint. "
+ "Mimicking shutdown error code.");
return Status(
ErrorCodes::InterruptedAtShutdown,
"background index build interrupted due to failpoint. returning a shutdown error.");
@@ -530,8 +545,9 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx,
Locker::LockSnapshot lockInfo;
invariant(opCtx->lockState()->saveLockStateAndUnlock(&lockInfo));
- log() << "Hanging index build with no locks due to "
- "'hangAfterStartingIndexBuildUnlocked' failpoint";
+ LOGV2(20390,
+ "Hanging index build with no locks due to "
+ "'hangAfterStartingIndexBuildUnlocked' failpoint");
hangAfterStartingIndexBuildUnlocked.pauseWhileSet();
if (isBackgroundBuilding()) {
@@ -546,8 +562,10 @@ Status MultiIndexBlock::insertAllDocumentsInCollection(OperationContext* opCtx,
progress->finished();
- log() << "index build: collection scan done. scanned " << n << " total records in "
- << t.seconds() << " seconds";
+ LOGV2(20391,
+ "index build: collection scan done. scanned {n} total records in {t_seconds} seconds",
+ "n"_attr = n,
+ "t_seconds"_attr = t.seconds());
Status ret = dumpInsertsFromBulk(opCtx);
if (!ret.isOK())
@@ -614,8 +632,11 @@ Status MultiIndexBlock::dumpInsertsFromBulk(OperationContext* opCtx,
: _indexes[i].options.dupsAllowed;
IndexCatalogEntry* entry = _indexes[i].block->getEntry();
- LOG(1) << "index build: inserting from external sorter into index: "
- << entry->descriptor()->indexName();
+ LOGV2_DEBUG(
+ 20392,
+ 1,
+ "index build: inserting from external sorter into index: {entry_descriptor_indexName}",
+ "entry_descriptor_indexName"_attr = entry->descriptor()->indexName());
// SERVER-41918 This call to commitBulk() results in file I/O that may result in an
// exception.
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index a8c9cf968da..36b5e941a35 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -58,6 +58,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -172,9 +173,15 @@ Status renameTargetCollectionToTmp(OperationContext* opCtx,
wunit.commit();
- log() << "Successfully renamed the target " << targetNs << " (" << targetUUID << ") to "
- << tmpName << " so that the source " << sourceNs << " (" << sourceUUID
- << ") could be renamed to " << targetNs;
+ LOGV2(20397,
+ "Successfully renamed the target {targetNs} ({targetUUID}) to {tmpName} so that the "
+ "source {sourceNs} ({sourceUUID}) could be renamed to {targetNs2}",
+ "targetNs"_attr = targetNs,
+ "targetUUID"_attr = targetUUID,
+ "tmpName"_attr = tmpName,
+ "sourceNs"_attr = sourceNs,
+ "sourceUUID"_attr = sourceUUID,
+ "targetNs2"_attr = targetNs);
return Status::OK();
});
@@ -245,9 +252,13 @@ Status renameCollectionAndDropTarget(OperationContext* opCtx,
// 'renameOpTime' must be null because a valid 'renameOpTimeFromApplyOps' implies
// replicated writes are not enabled.
if (!renameOpTime.isNull()) {
- severe() << "renameCollection: " << source << " to " << target
- << " (with dropTarget=true) - unexpected renameCollection oplog entry"
- << " written to the oplog with optime " << renameOpTime;
+ LOGV2_FATAL(
+ 20403,
+ "renameCollection: {source} to {target} (with dropTarget=true) - unexpected "
+ "renameCollection oplog entry written to the oplog with optime {renameOpTime}",
+ "source"_attr = source,
+ "target"_attr = target,
+ "renameOpTime"_attr = renameOpTime);
fassertFailed(40616);
}
renameOpTime = renameOpTimeFromApplyOps;
@@ -547,8 +558,11 @@ Status renameBetweenDBs(OperationContext* opCtx,
}
const auto& tmpName = tmpNameResult.getValue();
- log() << "Attempting to create temporary collection: " << tmpName
- << " with the contents of collection: " << source;
+ LOGV2(20398,
+ "Attempting to create temporary collection: {tmpName} with the contents of collection: "
+ "{source}",
+ "tmpName"_attr = tmpName,
+ "source"_attr = source);
Collection* tmpColl = nullptr;
{
@@ -582,8 +596,13 @@ Status renameBetweenDBs(OperationContext* opCtx,
if (!status.isOK()) {
// Ignoring failure case when dropping the temporary collection during cleanup because
// the rename operation has already failed for another reason.
- log() << "Unable to drop temporary collection " << tmpName << " while renaming from "
- << source << " to " << target << ": " << status;
+ LOGV2(20399,
+ "Unable to drop temporary collection {tmpName} while renaming from {source} to "
+ "{target}: {status}",
+ "tmpName"_attr = tmpName,
+ "source"_attr = source,
+ "target"_attr = target,
+ "status"_attr = status);
}
});
@@ -840,7 +859,11 @@ Status renameCollection(OperationContext* opCtx,
const std::string dropTargetMsg =
options.dropTarget ? " and drop " + target.toString() + "." : ".";
- log() << "renameCollectionForCommand: rename " << source << " to " << target << dropTargetMsg;
+ LOGV2(20400,
+ "renameCollectionForCommand: rename {source} to {target}{dropTargetMsg}",
+ "source"_attr = source,
+ "target"_attr = target,
+ "dropTargetMsg"_attr = dropTargetMsg);
if (source.db() == target.db())
return renameCollectionWithinDB(opCtx, source, target, options);
@@ -936,8 +959,13 @@ Status renameCollectionForApplyOps(OperationContext* opCtx,
const std::string dropTargetMsg =
uuidToDrop ? " and drop " + uuidToDrop->toString() + "." : ".";
const std::string uuidString = uuidToRename ? uuidToRename->toString() : "UUID unknown";
- log() << "renameCollectionForApplyOps: rename " << sourceNss << " (" << uuidString << ") to "
- << targetNss << dropTargetMsg;
+ LOGV2(20401,
+ "renameCollectionForApplyOps: rename {sourceNss} ({uuidString}) to "
+ "{targetNss}{dropTargetMsg}",
+ "sourceNss"_attr = sourceNss,
+ "uuidString"_attr = uuidString,
+ "targetNss"_attr = targetNss,
+ "dropTargetMsg"_attr = dropTargetMsg);
if (sourceNss.db() == targetNss.db()) {
return renameCollectionWithinDBForApplyOps(
@@ -958,8 +986,11 @@ Status renameCollectionForRollback(OperationContext* opCtx,
"have the same database. source: "
<< *source << ". target: " << target);
- log() << "renameCollectionForRollback: rename " << *source << " (" << uuid << ") to " << target
- << ".";
+ LOGV2(20402,
+ "renameCollectionForRollback: rename {source} ({uuid}) to {target}.",
+ "source"_attr = *source,
+ "uuid"_attr = uuid,
+ "target"_attr = target);
return renameCollectionWithinDB(opCtx, *source, target, {});
}
diff --git a/src/mongo/db/catalog/validate_adaptor.cpp b/src/mongo/db/catalog/validate_adaptor.cpp
index 78c4e00239b..18c3157dabd 100644
--- a/src/mongo/db/catalog/validate_adaptor.cpp
+++ b/src/mongo/db/catalog/validate_adaptor.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/key_string.h"
#include "mongo/db/storage/record_store.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/object_check.h"
#include "mongo/util/log.h"
@@ -278,7 +279,7 @@ void ValidateAdaptor::traverseRecordStore(OperationContext* opCtx,
ss << "Reason: Validated size of " << validatedSize
<< " bytes does not equal the record size of " << dataSize << " bytes";
}
- log() << std::string(ss);
+ LOGV2(20404, "{std_string_ss}", "std_string_ss"_attr = std::string(ss));
// Only log once
if (results->valid) {
diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp
index 4abd966b19e..843d7527c9b 100644
--- a/src/mongo/db/catalog/validate_state.cpp
+++ b/src/mongo/db/catalog/validate_state.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -167,8 +168,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) {
} catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) {
invariant(_background);
// End the validation if we can't open a checkpoint cursor on the collection.
- log() << "Skipping background validation on collection '" << _nss
- << "' because the collection is not yet in a checkpoint: " << ex;
+ LOGV2(20405,
+ "Skipping background validation on collection '{nss}' because the collection is not "
+ "yet in a checkpoint: {ex}",
+ "nss"_attr = _nss,
+ "ex"_attr = ex);
throw;
}
@@ -178,8 +182,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) {
opCtx, _collection->getCatalogId(), &readyDurableIndexes);
} catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) {
invariant(_background);
- log() << "Skipping background validation on collection '" << _nss
- << "' because the data is not yet in a checkpoint: " << ex;
+ LOGV2(20406,
+ "Skipping background validation on collection '{nss}' because the data is not yet in "
+ "a checkpoint: {ex}",
+ "nss"_attr = _nss,
+ "ex"_attr = ex);
throw;
}
@@ -197,8 +204,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) {
std::find(readyDurableIndexes.begin(), readyDurableIndexes.end(), desc->indexName()) !=
readyDurableIndexes.end();
if (_background && !isIndexDurable) {
- log() << "Skipping validation on index '" << desc->indexName() << "' in collection '"
- << _nss << "' because the index is not yet in a checkpoint.";
+ LOGV2(20407,
+ "Skipping validation on index '{desc_indexName}' in collection '{nss}' because "
+ "the index is not yet in a checkpoint.",
+ "desc_indexName"_attr = desc->indexName(),
+ "nss"_attr = _nss);
continue;
}
@@ -211,8 +221,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) {
opCtx->getServiceContext()->getStorageEngine()->getCatalog()->getIndexIdent(
opCtx, _collection->getCatalogId(), desc->indexName());
if (entry->getIdent() != diskIndexIdent) {
- log() << "Skipping validation on index '" << desc->indexName() << "' in collection '"
- << _nss << "' because the index was recreated and is not yet in a checkpoint.";
+ LOGV2(20408,
+ "Skipping validation on index '{desc_indexName}' in collection '{nss}' because "
+ "the index was recreated and is not yet in a checkpoint.",
+ "desc_indexName"_attr = desc->indexName(),
+ "nss"_attr = _nss);
continue;
}
@@ -224,8 +237,12 @@ void ValidateState::initializeCursors(OperationContext* opCtx) {
invariant(_background);
// This can only happen if the checkpoint has the MDB catalog entry for the index, but
// not the corresponding index table.
- log() << "Skipping validation on index '" << desc->indexName() << "' in collection '"
- << _nss << "' because the index data is not in a checkpoint: " << ex;
+ LOGV2(20409,
+ "Skipping validation on index '{desc_indexName}' in collection '{nss}' because "
+ "the index data is not in a checkpoint: {ex}",
+ "desc_indexName"_attr = desc->indexName(),
+ "nss"_attr = _nss,
+ "ex"_attr = ex);
continue;
}
@@ -235,8 +252,11 @@ void ValidateState::initializeCursors(OperationContext* opCtx) {
opCtx->getServiceContext()->getStorageEngine()->isInIndividuallyCheckpointedIndexesList(
diskIndexIdent)) {
_indexCursors.erase(desc->indexName());
- log() << "Skipping validation on index '" << desc->indexName() << "' in collection '"
- << _nss << "' because the index data is not yet consistent in the checkpoint.";
+ LOGV2(20410,
+ "Skipping validation on index '{desc_indexName}' in collection '{nss}' because "
+ "the index data is not yet consistent in the checkpoint.",
+ "desc_indexName"_attr = desc->indexName(),
+ "nss"_attr = _nss);
continue;
}
@@ -261,7 +281,7 @@ void ValidateState::_relockDatabaseAndCollection(OperationContext* opCtx) {
_databaseLock.reset();
if (MONGO_unlikely(hangDuringYieldingLocksForValidation.shouldFail())) {
- log() << "Hanging on fail point 'hangDuringYieldingLocksForValidation'";
+ LOGV2(20411, "Hanging on fail point 'hangDuringYieldingLocksForValidation'");
hangDuringYieldingLocksForValidation.pauseWhileSet();
}
diff --git a/src/mongo/db/catalog_raii_test.cpp b/src/mongo/db/catalog_raii_test.cpp
index b717c19b2b4..5165baebc55 100644
--- a/src/mongo/db/catalog_raii_test.cpp
+++ b/src/mongo/db/catalog_raii_test.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/concurrency/lock_state.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/db/storage/recovery_unit_noop.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
@@ -79,7 +80,7 @@ void failsWithLockTimeout(std::function<void()> func, Milliseconds timeoutMillis
func();
FAIL("Should have gotten an exception due to timeout");
} catch (const ExceptionFor<ErrorCodes::LockTimeout>& ex) {
- log() << ex;
+ LOGV2(20396, "{ex}", "ex"_attr = ex);
Date_t t2 = Date_t::now();
ASSERT_GTE(t2 - t1, timeoutMillis);
}
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 3c3f97cd03a..8dd960c2a2c 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -62,6 +62,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -155,7 +156,10 @@ struct Cloner::Fun {
if (now - lastLog >= 60) {
// report progress
if (lastLog)
- log() << "clone " << to_collection << ' ' << numSeen;
+ LOGV2(20412,
+ "clone {to_collection} {numSeen}",
+ "to_collection"_attr = to_collection,
+ "numSeen"_attr = numSeen);
lastLog = now;
}
opCtx->checkForInterrupt();
@@ -216,7 +220,7 @@ struct Cloner::Fun {
ss << "Cloner: found corrupt document in " << from_collection.toString() << ": "
<< redact(status);
if (gSkipCorruptDocumentsWhenCloning.load()) {
- warning() << ss.ss.str() << "; skipping";
+ LOGV2_WARNING(20423, "{ss_ss_str}; skipping", "ss_ss_str"_attr = ss.ss.str());
continue;
}
msgasserted(28531, ss);
@@ -235,8 +239,12 @@ struct Cloner::Fun {
Status status =
collection->insertDocument(opCtx, InsertStatement(doc), nullOpDebug, true);
if (!status.isOK() && status.code() != ErrorCodes::DuplicateKey) {
- error() << "error: exception cloning object in " << from_collection << ' '
- << redact(status) << " obj:" << redact(doc);
+ LOGV2_ERROR(
+ 20424,
+ "error: exception cloning object in {from_collection} {status} obj:{doc}",
+ "from_collection"_attr = from_collection,
+ "status"_attr = redact(status),
+ "doc"_attr = redact(doc));
uassertStatusOK(status);
}
if (status.isOK()) {
@@ -246,7 +254,10 @@ struct Cloner::Fun {
static Rarely sampler;
if (sampler.tick() && (time(nullptr) - saveLast > 60)) {
- log() << numSeen << " objects cloned so far from collection " << from_collection;
+ LOGV2(20413,
+ "{numSeen} objects cloned so far from collection {from_collection}",
+ "numSeen"_attr = numSeen,
+ "from_collection"_attr = from_collection);
saveLast = time(nullptr);
}
}
@@ -275,8 +286,14 @@ void Cloner::copy(OperationContext* opCtx,
const NamespaceString& to_collection,
const CloneOptions& opts,
Query query) {
- LOG(2) << "\t\tcloning collection " << from_collection << " to " << to_collection << " on "
- << _conn->getServerAddress() << " with filter " << redact(query.toString());
+ LOGV2_DEBUG(20414,
+ 2,
+ "\t\tcloning collection {from_collection} to {to_collection} on "
+ "{conn_getServerAddress} with filter {query}",
+ "from_collection"_attr = from_collection,
+ "to_collection"_attr = to_collection,
+ "conn_getServerAddress"_attr = _conn->getServerAddress(),
+ "query"_attr = redact(query.toString()));
Fun f(opCtx, toDBName);
f.numSeen = 0;
@@ -311,8 +328,12 @@ void Cloner::copyIndexes(OperationContext* opCtx,
const BSONObj& from_opts,
const std::list<BSONObj>& from_indexes,
const NamespaceString& to_collection) {
- LOG(2) << "\t\t copyIndexes " << from_collection << " to " << to_collection << " on "
- << _conn->getServerAddress();
+ LOGV2_DEBUG(20415,
+ 2,
+ "\t\t copyIndexes {from_collection} to {to_collection} on {conn_getServerAddress}",
+ "from_collection"_attr = from_collection,
+ "to_collection"_attr = to_collection,
+ "conn_getServerAddress"_attr = _conn->getServerAddress());
uassert(ErrorCodes::PrimarySteppedDown,
str::stream() << "Not primary while copying indexes from " << from_collection.ns()
@@ -506,8 +527,11 @@ bool Cloner::copyCollection(OperationContext* opCtx,
return result;
}
} else {
- LOG(1) << "No collection info found for ns:" << nss.toString()
- << ", host:" << _conn->getServerAddress();
+ LOGV2_DEBUG(20416,
+ 1,
+ "No collection info found for ns:{nss}, host:{conn_getServerAddress}",
+ "nss"_attr = nss.toString(),
+ "conn_getServerAddress"_attr = _conn->getServerAddress());
}
// main data
@@ -517,7 +541,8 @@ bool Cloner::copyCollection(OperationContext* opCtx,
/* TODO : copyIndexes bool does not seem to be implemented! */
if (!shouldCopyIndexes) {
- log() << "ERROR copy collection shouldCopyIndexes not implemented? " << ns;
+ LOGV2(
+ 20417, "ERROR copy collection shouldCopyIndexes not implemented? {ns}", "ns"_attr = ns);
}
// indexes
@@ -530,7 +555,7 @@ StatusWith<std::vector<BSONObj>> Cloner::filterCollectionsForClone(
const CloneOptions& opts, const std::list<BSONObj>& initialCollections) {
std::vector<BSONObj> finalCollections;
for (auto&& collection : initialCollections) {
- LOG(2) << "\t cloner got " << collection;
+ LOGV2_DEBUG(20418, 2, "\t cloner got {collection}", "collection"_attr = collection);
BSONElement collectionOptions = collection["options"];
if (collectionOptions.isABSONObj()) {
@@ -551,7 +576,7 @@ StatusWith<std::vector<BSONObj>> Cloner::filterCollectionsForClone(
if (ns.isSystem()) {
if (!ns.isLegalClientSystemNS()) {
- LOG(2) << "\t\t not cloning because system collection";
+ LOGV2_DEBUG(20419, 2, "\t\t not cloning because system collection");
continue;
}
}
@@ -785,7 +810,10 @@ Status Cloner::copyDb(OperationContext* opCtx,
continue;
}
- LOG(2) << " really will clone: " << params.collectionInfo;
+ LOGV2_DEBUG(20420,
+ 2,
+ " really will clone: {params_collectionInfo}",
+ "params_collectionInfo"_attr = params.collectionInfo);
const NamespaceString from_name(opts.fromDB, params.collectionName);
const NamespaceString to_name(toDBName, params.collectionName);
@@ -794,7 +822,11 @@ Status Cloner::copyDb(OperationContext* opCtx,
clonedColls->insert(from_name.ns());
}
- LOG(1) << "\t\t cloning " << from_name << " -> " << to_name;
+ LOGV2_DEBUG(20421,
+ 1,
+ "\t\t cloning {from_name} -> {to_name}",
+ "from_name"_attr = from_name,
+ "to_name"_attr = to_name);
copy(opCtx,
toDBName,
@@ -810,7 +842,9 @@ Status Cloner::copyDb(OperationContext* opCtx,
// now build the secondary indexes
if (opts.syncIndexes) {
for (auto&& params : createCollectionParams) {
- log() << "copying indexes for: " << params.collectionInfo;
+ LOGV2(20422,
+ "copying indexes for: {params_collectionInfo}",
+ "params_collectionInfo"_attr = params.collectionInfo);
const NamespaceString from_name(opts.fromDB, params.collectionName);
const NamespaceString to_name(toDBName, params.collectionName);
diff --git a/src/mongo/db/collection_index_builds_tracker.cpp b/src/mongo/db/collection_index_builds_tracker.cpp
index 40b4f292c27..677aa17fa3a 100644
--- a/src/mongo/db/collection_index_builds_tracker.cpp
+++ b/src/mongo/db/collection_index_builds_tracker.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/collection_index_builds_tracker.h"
#include "mongo/db/catalog/index_builds_manager.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -110,9 +111,11 @@ void CollectionIndexBuildsTracker::waitUntilNoIndexBuildsRemain(stdx::unique_loc
return true;
}
- log() << "Waiting until the following index builds are finished:";
+ LOGV2(20425, "Waiting until the following index builds are finished:");
for (const auto& indexBuild : _buildStateByBuildUUID) {
- log() << " Index build with UUID: " << indexBuild.first;
+ LOGV2(20426,
+ " Index build with UUID: {indexBuild_first}",
+ "indexBuild_first"_attr = indexBuild.first);
}
return false;
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index fbcf69dc8c2..6a94edbf374 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/read_write_concern_defaults.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/factory.h"
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
#include "mongo/rpc/op_msg_rpc_impls.h"
@@ -572,8 +573,10 @@ void CommandHelpers::evaluateFailCommandFailPoint(OperationContext* opCtx,
if (closeConnection) {
opCtx->getClient()->session()->end();
- log() << "Failing command '" << cmd->getName()
- << "' via 'failCommand' failpoint. Action: closing connection.";
+ LOGV2(20431,
+ "Failing command '{cmd_getName}' via 'failCommand' failpoint. Action: "
+ "closing connection.",
+ "cmd_getName"_attr = cmd->getName());
uasserted(50985, "Failing command due to 'failCommand' failpoint");
}
@@ -587,24 +590,33 @@ void CommandHelpers::evaluateFailCommandFailPoint(OperationContext* opCtx,
"'blockTimeMS' must be non-negative",
blockTimeMS >= 0);
- log() << "Blocking command '" << cmd->getName()
- << "' via 'failCommand' failpoint for " << blockTimeMS << " milliseconds";
+ LOGV2(20432,
+ "Blocking command '{cmd_getName}' via 'failCommand' failpoint for "
+ "{blockTimeMS} milliseconds",
+ "cmd_getName"_attr = cmd->getName(),
+ "blockTimeMS"_attr = blockTimeMS);
opCtx->sleepFor(Milliseconds{blockTimeMS});
- log() << "Unblocking command '" << cmd->getName()
- << "' via 'failCommand' failpoint";
+ LOGV2(20433,
+ "Unblocking command '{cmd_getName}' via 'failCommand' failpoint",
+ "cmd_getName"_attr = cmd->getName());
}
if (hasExtraInfo) {
- log() << "Failing command '" << cmd->getName()
- << "' via 'failCommand' failpoint. Action: returning error code " << errorCode
- << " and " << errorExtraInfo << ".";
+ LOGV2(20434,
+ "Failing command '{cmd_getName}' via 'failCommand' failpoint. Action: "
+ "returning error code {errorCode} and {errorExtraInfo}.",
+ "cmd_getName"_attr = cmd->getName(),
+ "errorCode"_attr = errorCode,
+ "errorExtraInfo"_attr = errorExtraInfo);
uassertStatusOK(Status(ErrorCodes::Error(errorCode),
"Failing command due to 'failCommand' failpoint",
errorExtraInfo.Obj()));
} else if (hasErrorCode) {
- log() << "Failing command '" << cmd->getName()
- << "' via 'failCommand' failpoint. Action: returning error code " << errorCode
- << ".";
+ LOGV2(20435,
+ "Failing command '{cmd_getName}' via 'failCommand' failpoint. Action: "
+ "returning error code {errorCode}.",
+ "cmd_getName"_attr = cmd->getName(),
+ "errorCode"_attr = errorCode);
uasserted(ErrorCodes::Error(errorCode),
"Failing command due to 'failCommand' failpoint");
}
@@ -672,7 +684,10 @@ void CommandInvocation::checkAuthorization(OperationContext* opCtx,
}
}
} catch (const DBException& e) {
- log(LogComponent::kAccessControl) << e.toStatus();
+ LOGV2_OPTIONS(20436,
+ {logComponentV1toV2(LogComponent::kAccessControl)},
+ "{e_toStatus}",
+ "e_toStatus"_attr = e.toStatus());
CommandHelpers::auditLogAuthEvent(opCtx, this, request, e.code());
throw;
}
diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp
index d51d9815d08..9ce82d61531 100644
--- a/src/mongo/db/commands/authentication_commands.cpp
+++ b/src/mongo/db/commands/authentication_commands.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/stats/counters.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
@@ -116,8 +117,9 @@ Status _authenticateX509(OperationContext* opCtx, const UserName& user, const BS
if (!clientMetadata->getApplicationName().empty() ||
(driverName != "MongoDB Internal Client" &&
driverName != "NetworkInterfaceTL")) {
- warning() << "Client isn't a mongod or mongos, but is connecting with a "
- "certificate with cluster membership";
+ LOGV2_WARNING(20430,
+ "Client isn't a mongod or mongos, but is connecting with a "
+ "certificate with cluster membership");
}
}
@@ -256,7 +258,10 @@ bool CmdAuthenticate::run(OperationContext* opCtx,
CommandHelpers::handleMarkKillOnClientDisconnect(opCtx);
if (!serverGlobalParams.quiet.load()) {
mutablebson::Document cmdToLog(cmdObj, mutablebson::Document::kInPlaceDisabled);
- log() << " authenticate db: " << dbname << " " << cmdToLog;
+ LOGV2(20427,
+ " authenticate db: {dbname} {cmdToLog}",
+ "dbname"_attr = dbname,
+ "cmdToLog"_attr = cmdToLog);
}
std::string mechanism = cmdObj.getStringField("mechanism");
if (mechanism.empty()) {
@@ -285,8 +290,13 @@ bool CmdAuthenticate::run(OperationContext* opCtx,
if (!status.isOK()) {
if (!serverGlobalParams.quiet.load()) {
auto const client = opCtx->getClient();
- log() << "Failed to authenticate " << user << " from client " << client->getRemote()
- << " with mechanism " << mechanism << ": " << status;
+ LOGV2(20428,
+ "Failed to authenticate {user} from client {client_getRemote} with mechanism "
+ "{mechanism}: {status}",
+ "user"_attr = user,
+ "client_getRemote"_attr = client->getRemote(),
+ "mechanism"_attr = mechanism,
+ "status"_attr = status);
}
sleepmillis(saslGlobalParams.authFailedDelay.load());
if (status.code() == ErrorCodes::AuthenticationFailed) {
@@ -300,8 +310,12 @@ bool CmdAuthenticate::run(OperationContext* opCtx,
}
if (!serverGlobalParams.quiet.load()) {
- log() << "Successfully authenticated as principal " << user.getUser() << " on "
- << user.getDB() << " from client " << opCtx->getClient()->session()->remote();
+ LOGV2(20429,
+ "Successfully authenticated as principal {user_getUser} on {user_getDB} from client "
+ "{opCtx_getClient_session_remote}",
+ "user_getUser"_attr = user.getUser(),
+ "user_getDB"_attr = user.getDB(),
+ "opCtx_getClient_session_remote"_attr = opCtx->getClient()->session()->remote());
}
result.append("dbname", user.getDB());
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index ba8eb767daa..3ea9f94aea4 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -61,6 +61,7 @@
#include "mongo/db/s/database_sharding_state.h"
#include "mongo/db/server_options.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/compiler.h"
#include "mongo/s/shard_key_pattern.h"
#include "mongo/util/log.h"
@@ -413,8 +414,9 @@ BSONObj runCreateIndexesOnNewCollection(OperationContext* opCtx,
if (MONGO_unlikely(hangBeforeCreateIndexesCollectionCreate.shouldFail())) {
// Simulate a scenario where a conflicting collection creation occurs
// mid-index build.
- log() << "Hanging create collection due to failpoint "
- "'hangBeforeCreateIndexesCollectionCreate'";
+ LOGV2(20437,
+ "Hanging create collection due to failpoint "
+ "'hangBeforeCreateIndexesCollectionCreate'");
hangBeforeCreateIndexesCollectionCreate.pauseWhileSet();
}
@@ -557,7 +559,7 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx,
auto protocol = IndexBuildsCoordinator::supportsTwoPhaseIndexBuild()
? IndexBuildProtocol::kTwoPhase
: IndexBuildProtocol::kSinglePhase;
- log() << "Registering index build: " << buildUUID;
+ LOGV2(20438, "Registering index build: {buildUUID}", "buildUUID"_attr = buildUUID);
ReplIndexBuildState::IndexCatalogStats stats;
IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions = {commitQuorum};
@@ -568,17 +570,24 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx,
auto deadline = opCtx->getDeadline();
// Date_t::max() means no deadline.
if (deadline == Date_t::max()) {
- log() << "Waiting for index build to complete: " << buildUUID;
+ LOGV2(20439,
+ "Waiting for index build to complete: {buildUUID}",
+ "buildUUID"_attr = buildUUID);
} else {
- log() << "Waiting for index build to complete: " << buildUUID
- << " (deadline: " << deadline << ")";
+ LOGV2(20440,
+ "Waiting for index build to complete: {buildUUID} (deadline: {deadline})",
+ "buildUUID"_attr = buildUUID,
+ "deadline"_attr = deadline);
}
// Throws on error.
try {
stats = buildIndexFuture.get(opCtx);
} catch (const ExceptionForCat<ErrorCategory::Interruption>& interruptionEx) {
- log() << "Index build interrupted: " << buildUUID << ": " << interruptionEx;
+ LOGV2(20441,
+ "Index build interrupted: {buildUUID}: {interruptionEx}",
+ "buildUUID"_attr = buildUUID,
+ "interruptionEx"_attr = interruptionEx);
hangBeforeIndexBuildAbortOnInterrupt.pauseWhileSet();
@@ -588,7 +597,9 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx,
// background and will complete when this node receives a commitIndexBuild oplog
// entry from the new primary.
if (ErrorCodes::InterruptedDueToReplStateChange == interruptionEx.code()) {
- log() << "Index build continuing in background: " << buildUUID;
+ LOGV2(20442,
+ "Index build continuing in background: {buildUUID}",
+ "buildUUID"_attr = buildUUID);
throw;
}
@@ -621,18 +632,22 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx,
Timestamp(),
str::stream() << "Index build interrupted: " << buildUUID << ": "
<< interruptionEx.toString());
- log() << "Index build aborted: " << buildUUID;
+ LOGV2(20443, "Index build aborted: {buildUUID}", "buildUUID"_attr = buildUUID);
throw;
} catch (const ExceptionForCat<ErrorCategory::NotMasterError>& ex) {
- log() << "Index build interrupted due to change in replication state: " << buildUUID
- << ": " << ex;
+ LOGV2(20444,
+ "Index build interrupted due to change in replication state: {buildUUID}: {ex}",
+ "buildUUID"_attr = buildUUID,
+ "ex"_attr = ex);
// The index build will continue to run in the background and will complete when this
// node receives a commitIndexBuild oplog entry from the new primary.
if (IndexBuildProtocol::kTwoPhase == protocol) {
- log() << "Index build continuing in background: " << buildUUID;
+ LOGV2(20445,
+ "Index build continuing in background: {buildUUID}",
+ "buildUUID"_attr = buildUUID);
throw;
}
@@ -644,24 +659,32 @@ bool runCreateIndexesWithCoordinator(OperationContext* opCtx,
Timestamp(),
str::stream() << "Index build interrupted due to change in replication state: "
<< buildUUID << ": " << ex.toString());
- log() << "Index build aborted due to NotMaster error: " << buildUUID;
+ LOGV2(20446,
+ "Index build aborted due to NotMaster error: {buildUUID}",
+ "buildUUID"_attr = buildUUID);
throw;
}
- log() << "Index build completed: " << buildUUID;
+ LOGV2(20447, "Index build completed: {buildUUID}", "buildUUID"_attr = buildUUID);
} catch (DBException& ex) {
// If the collection is dropped after the initial checks in this function (before the
// AutoStatsTracker is created), the IndexBuildsCoordinator (either startIndexBuild() or
// the the task running the index build) may return NamespaceNotFound. This is not
// considered an error and the command should return success.
if (ErrorCodes::NamespaceNotFound == ex.code()) {
- log() << "Index build failed: " << buildUUID << ": collection dropped: " << ns;
+ LOGV2(20448,
+ "Index build failed: {buildUUID}: collection dropped: {ns}",
+ "buildUUID"_attr = buildUUID,
+ "ns"_attr = ns);
return true;
}
// All other errors should be forwarded to the caller with index build information included.
- log() << "Index build failed: " << buildUUID << ": " << ex.toStatus();
+ LOGV2(20449,
+ "Index build failed: {buildUUID}: {ex_toStatus}",
+ "buildUUID"_attr = buildUUID,
+ "ex_toStatus"_attr = ex.toStatus());
ex.addContext(str::stream() << "Index build failed: " << buildUUID << ": Collection " << ns
<< " ( " << *collectionUUID << " )");
@@ -734,12 +757,13 @@ public:
}
if (shouldLogMessageOnAlreadyBuildingError) {
auto bsonElem = cmdObj.getField(kIndexesFieldName);
- log()
- << "Received a request to create indexes: '" << bsonElem
- << "', but found that at least one of the indexes is already being built, '"
- << ex.toStatus()
- << "'. This request will wait for the pre-existing index build to finish "
- "before proceeding.";
+ LOGV2(20450,
+ "Received a request to create indexes: '{bsonElem}', but found that at "
+ "least one of the indexes is already being built, '{ex_toStatus}'. This "
+ "request will wait for the pre-existing index build to finish "
+ "before proceeding.",
+ "bsonElem"_attr = bsonElem,
+ "ex_toStatus"_attr = ex.toStatus());
shouldLogMessageOnAlreadyBuildingError = false;
}
// Unset the response fields so we do not write duplicate fields.
diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp
index c933dd6ad34..42cfdf10cd6 100644
--- a/src/mongo/db/commands/dbcheck.cpp
+++ b/src/mongo/db/commands/dbcheck.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/repl/optime.h"
#include "mongo/util/background.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -210,7 +211,7 @@ protected:
}
if (_done) {
- log() << "dbCheck terminated due to stepdown";
+ LOGV2(20451, "dbCheck terminated due to stepdown");
return;
}
}
diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp
index aa82cdef7d3..8044d6abaef 100644
--- a/src/mongo/db/commands/dbcommands_d.cpp
+++ b/src/mongo/db/commands/dbcommands_d.cpp
@@ -86,6 +86,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/stats/storage_stats.h"
#include "mongo/db/write_concern.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/stale_exception.h"
#include "mongo/scripting/engine.h"
#include "mongo/util/fail_point.h"
@@ -280,7 +281,8 @@ public:
if (partialOk) {
break; // skipped chunk is probably on another shard
}
- log() << "should have chunk: " << n << " have:" << myn;
+ LOGV2(
+ 20452, "should have chunk: {n} have:{myn}", "n"_attr = n, "myn"_attr = myn);
dumpChunks(opCtx, nss.ns(), query, sort);
uassert(10040, "chunks out of order", n == myn);
}
@@ -315,7 +317,10 @@ public:
// RELOCKED
ctx.reset(new AutoGetCollectionForReadCommand(opCtx, nss));
} catch (const StaleConfigException&) {
- LOG(1) << "chunk metadata changed during filemd5, will retarget and continue";
+ LOGV2_DEBUG(
+ 20453,
+ 1,
+ "chunk metadata changed during filemd5, will retarget and continue");
break;
}
@@ -350,7 +355,7 @@ public:
q.sort(sort);
unique_ptr<DBClientCursor> c = client.query(NamespaceString(ns), q);
while (c->more()) {
- log() << c->nextSafe();
+ LOGV2(20454, "{c_nextSafe}", "c_nextSafe"_attr = c->nextSafe());
}
}
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index da181689560..7da824f9a10 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/storage/storage_engine.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/log.h"
#include "mongo/util/md5.hpp"
@@ -370,7 +371,7 @@ private:
exec = InternalPlanner::collectionScan(
opCtx, nss.ns(), collection, PlanExecutor::NO_YIELD);
} else {
- log() << "can't find _id index for: " << nss;
+ LOGV2(20455, "can't find _id index for: {nss}", "nss"_attr = nss);
return "no _id _index";
}
@@ -386,7 +387,7 @@ private:
n++;
}
if (PlanExecutor::IS_EOF != state) {
- warning() << "error while hashing, db dropped? ns=" << nss;
+ LOGV2_WARNING(20456, "error while hashing, db dropped? ns={nss}", "nss"_attr = nss);
uasserted(34371,
"Plan executor error while running dbHash command: " +
WorkingSetCommon::toStatusString(c));
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 033023ec710..58fee79a890 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -53,6 +53,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/quick_exit.h"
@@ -126,7 +127,7 @@ public:
const NamespaceString toReIndexNss =
CommandHelpers::parseNsCollectionRequired(dbname, jsobj);
- LOG(0) << "CMD: reIndex " << toReIndexNss;
+ LOGV2(20457, "CMD: reIndex {toReIndexNss}", "toReIndexNss"_attr = toReIndexNss);
AutoGetCollection autoColl(opCtx, toReIndexNss, MODE_X);
Collection* collection = autoColl.getCollection();
@@ -219,7 +220,7 @@ public:
}
if (MONGO_unlikely(reIndexCrashAfterDrop.shouldFail())) {
- log() << "exiting because 'reIndexCrashAfterDrop' fail point was set";
+ LOGV2(20458, "exiting because 'reIndexCrashAfterDrop' fail point was set");
quickExit(EXIT_ABRUPT);
}
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index c98457c1f86..0e9509623b6 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -52,6 +52,7 @@
#include "mongo/db/wire_version.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/executor/egress_tag_closer_manager.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/grid.h"
@@ -158,8 +159,11 @@ void FeatureCompatibilityVersion::onInsertOrUpdate(OperationContext* opCtx, cons
? serverGlobalParams.featureCompatibility.getVersion() != newVersion
: true;
if (isDifferent) {
- log() << "setting featureCompatibilityVersion to "
- << FeatureCompatibilityVersionParser::toString(newVersion);
+ LOGV2(
+ 20459,
+ "setting featureCompatibilityVersion to {FeatureCompatibilityVersionParser_newVersion}",
+ "FeatureCompatibilityVersionParser_newVersion"_attr =
+ FeatureCompatibilityVersionParser::toString(newVersion));
}
// Remove term field of config document on downgrade.
@@ -190,9 +194,10 @@ void FeatureCompatibilityVersion::onInsertOrUpdate(OperationContext* opCtx, cons
if (newVersion != ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44) {
if (MONGO_unlikely(hangBeforeAbortingRunningTransactionsOnFCVDowngrade.shouldFail())) {
- log() << "featureCompatibilityVersion - "
- "hangBeforeAbortingRunningTransactionsOnFCVDowngrade fail point enabled. "
- "Blocking until fail point is disabled.";
+ LOGV2(20460,
+ "featureCompatibilityVersion - "
+ "hangBeforeAbortingRunningTransactionsOnFCVDowngrade fail point enabled. "
+ "Blocking until fail point is disabled.");
hangBeforeAbortingRunningTransactionsOnFCVDowngrade.pauseWhileSet();
}
// Abort all open transactions when downgrading the featureCompatibilityVersion.
diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp
index 45ade956647..becd1c00ba6 100644
--- a/src/mongo/db/commands/fsync.cpp
+++ b/src/mongo/db/commands/fsync.cpp
@@ -49,6 +49,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/backup_cursor_hooks.h"
#include "mongo/db/storage/storage_engine.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/background.h"
@@ -134,7 +135,7 @@ public:
}
const bool lock = cmdObj["lock"].trueValue();
- log() << "CMD fsync: lock:" << lock;
+ LOGV2(20461, "CMD fsync: lock:{lock}", "lock"_attr = lock);
// fsync + lock is sometimes used to block writes out of the system and does not care if
// the `BackupCursorService::fsyncLock` call succeeds.
@@ -180,14 +181,18 @@ public:
if (!status.isOK()) {
releaseLock();
- warning() << "fsyncLock failed. Lock count reset to 0. Status: " << status;
+ LOGV2_WARNING(20468,
+ "fsyncLock failed. Lock count reset to 0. Status: {status}",
+ "status"_attr = status);
uassertStatusOK(status);
}
}
- log() << "mongod is locked and no writes are allowed. db.fsyncUnlock() to unlock";
- log() << "Lock count is " << getLockCount();
- log() << " For more info see " << FSyncCommand::url();
+ LOGV2(20462, "mongod is locked and no writes are allowed. db.fsyncUnlock() to unlock");
+ LOGV2(20463, "Lock count is {getLockCount}", "getLockCount"_attr = getLockCount());
+ LOGV2(20464,
+ " For more info see {FSyncCommand_url}",
+ "FSyncCommand_url"_attr = FSyncCommand::url());
result.append("info", "now locked against writes, use db.fsyncUnlock() to unlock");
result.append("lockCount", getLockCount());
result.append("seeAlso", FSyncCommand::url());
@@ -296,7 +301,7 @@ public:
const BSONObj& cmdObj,
std::string& errmsg,
BSONObjBuilder& result) override {
- log() << "command: unlock requested";
+ LOGV2(20465, "command: unlock requested");
Lock::ExclusiveLock lk(opCtx->lockState(), commandMutex);
@@ -316,11 +321,13 @@ public:
// If we're still locked then lock count is not zero.
invariant(lockCount > 0);
lockCount = fsyncCmd.getLockCount_inLock();
- log() << "fsyncUnlock completed. Lock count is now " << lockCount;
+ LOGV2(20466,
+ "fsyncUnlock completed. Lock count is now {lockCount}",
+ "lockCount"_attr = lockCount);
} else {
invariant(fsyncCmd.getLockCount() == 0);
lockCount = 0;
- log() << "fsyncUnlock completed. mongod is now unlocked and free to accept writes";
+ LOGV2(20467, "fsyncUnlock completed. mongod is now unlocked and free to accept writes");
}
result.append("info", str::stream() << "fsyncUnlock completed");
@@ -357,7 +364,7 @@ void FSyncLockThread::run() {
registerShutdownTask([&] {
stdx::unique_lock<Latch> stateLock(fsyncCmd.lockStateMutex);
if (fsyncCmd.getLockCount_inLock() > 0) {
- warning() << "Interrupting fsync because the server is shutting down.";
+ LOGV2_WARNING(20469, "Interrupting fsync because the server is shutting down.");
while (fsyncCmd.getLockCount_inLock()) {
// Relies on the lock to be released in 'releaseLock_inLock()' when the
// release brings the lock count to 0.
@@ -371,7 +378,7 @@ void FSyncLockThread::run() {
try {
storageEngine->flushAllFiles(&opCtx, /*callerHoldsReadLock*/ true);
} catch (const std::exception& e) {
- error() << "error doing flushAll: " << e.what();
+ LOGV2_ERROR(20472, "error doing flushAll: {e_what}", "e_what"_attr = e.what());
fsyncCmd.threadStatus = Status(ErrorCodes::CommandFailed, e.what());
fsyncCmd.acquireFsyncLockSyncCV.notify_one();
return;
@@ -397,10 +404,12 @@ void FSyncLockThread::run() {
});
} catch (const DBException& e) {
if (_allowFsyncFailure) {
- warning() << "Locking despite storage engine being unable to begin backup : "
- << e.toString();
+ LOGV2_WARNING(20470,
+ "Locking despite storage engine being unable to begin backup : {e}",
+ "e"_attr = e.toString());
} else {
- error() << "storage engine unable to begin backup : " << e.toString();
+ LOGV2_ERROR(
+ 20473, "storage engine unable to begin backup : {e}", "e"_attr = e.toString());
fsyncCmd.threadStatus = e.toStatus();
fsyncCmd.acquireFsyncLockSyncCV.notify_one();
return;
@@ -411,8 +420,10 @@ void FSyncLockThread::run() {
fsyncCmd.acquireFsyncLockSyncCV.notify_one();
while (fsyncCmd.getLockCount_inLock() > 0) {
- warning() << "WARNING: instance is locked, blocking all writes. The fsync command has "
- "finished execution, remember to unlock the instance using fsyncUnlock().";
+ LOGV2_WARNING(
+ 20471,
+ "WARNING: instance is locked, blocking all writes. The fsync command has "
+ "finished execution, remember to unlock the instance using fsyncUnlock().");
fsyncCmd.releaseFsyncLockSyncCV.wait_for(lk, Seconds(60).toSystemDuration());
}
@@ -425,7 +436,7 @@ void FSyncLockThread::run() {
}
} catch (const std::exception& e) {
- severe() << "FSyncLockThread exception: " << e.what();
+ LOGV2_FATAL(20474, "FSyncLockThread exception: {e_what}", "e_what"_attr = e.what());
fassertFailed(40350);
}
}
diff --git a/src/mongo/db/commands/generic_servers.cpp b/src/mongo/db/commands/generic_servers.cpp
index b398e6d59f2..51bfd5ab8b4 100644
--- a/src/mongo/db/commands/generic_servers.cpp
+++ b/src/mongo/db/commands/generic_servers.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/commands/shutdown.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/log_process_details.h"
+#include "mongo/logv2/log.h"
#include "mongo/logv2/ramlog.h"
#include "mongo/scripting/engine.h"
#include "mongo/util/exit.h"
@@ -354,7 +355,7 @@ void CmdShutdown::shutdownHelper(const BSONObj& cmdObj) {
::abort();
});
- log() << "terminating, shutdown command received " << cmdObj;
+ LOGV2(20475, "terminating, shutdown command received {cmdObj}", "cmdObj"_attr = cmdObj);
#if defined(_WIN32)
// Signal the ServiceMain thread to shutdown.
diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp
index 1b674dd6ef7..531952af58e 100644
--- a/src/mongo/db/commands/get_last_error.cpp
+++ b/src/mongo/db/commands/get_last_error.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/write_concern.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -263,8 +264,13 @@ public:
}
} else {
if (electionId != repl::ReplicationCoordinator::get(opCtx)->getElectionId()) {
- LOG(3) << "oid passed in is " << electionId << ", but our id is "
- << repl::ReplicationCoordinator::get(opCtx)->getElectionId();
+ LOGV2_DEBUG(20476,
+ 3,
+ "oid passed in is {electionId}, but our id is "
+ "{repl_ReplicationCoordinator_get_opCtx_getElectionId}",
+ "electionId"_attr = electionId,
+ "repl_ReplicationCoordinator_get_opCtx_getElectionId"_attr =
+ repl::ReplicationCoordinator::get(opCtx)->getElectionId());
errmsg = "election occurred after write";
result.append("code", ErrorCodes::WriteConcernFailed);
result.append("codeName",
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index 1795337753d..91b6804f691 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -57,6 +57,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/stats/top.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/chunk_version.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -328,9 +329,14 @@ public:
auto status = WorkingSetCommon::getMemberObjectStatus(doc);
invariant(!status.isOK());
// Log an error message and then perform the cleanup.
- warning() << "GetMore command executor error: "
- << PlanExecutor::statestr(*state) << ", status: " << status
- << ", stats: " << redact(Explain::getWinningPlanStats(exec));
+ LOGV2_WARNING(20478,
+ "GetMore command executor error: {PlanExecutor_statestr_state}, "
+ "status: {status}, stats: {Explain_getWinningPlanStats_exec}",
+ "PlanExecutor_statestr_state"_attr =
+ PlanExecutor::statestr(*state),
+ "status"_attr = status,
+ "Explain_getWinningPlanStats_exec"_attr =
+ redact(Explain::getWinningPlanStats(exec)));
nextBatch->abandon();
return status;
@@ -413,8 +419,9 @@ public:
ClientCursorParams::LockPolicy::kLockExternally);
if (MONGO_unlikely(GetMoreHangBeforeReadLock.shouldFail())) {
- log() << "GetMoreHangBeforeReadLock fail point enabled. Blocking until fail "
- "point is disabled.";
+ LOGV2(20477,
+ "GetMoreHangBeforeReadLock fail point enabled. Blocking until fail "
+ "point is disabled.");
GetMoreHangBeforeReadLock.pauseWhileSet(opCtx);
}
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index 59dd614002a..e1348bb8eda 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/matcher/extensions_callback_real.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/query/collection_query_info.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/unordered_set.h"
#include "mongo/util/log.h"
@@ -264,7 +265,9 @@ Status ClearFilters::clear(OperationContext* opCtx,
// Remove entry from plan cache
planCache->remove(*cq).transitional_ignore();
- LOG(0) << "Removed index filter on " << redact(cq->toStringShort());
+ LOGV2(20479,
+ "Removed index filter on {cq_Short}",
+ "cq_Short"_attr = redact(cq->toStringShort()));
return Status::OK();
}
@@ -320,7 +323,7 @@ Status ClearFilters::clear(OperationContext* opCtx,
planCache->remove(*cq).transitional_ignore();
}
- LOG(0) << "Removed all index filters for collection: " << ns;
+ LOGV2(20480, "Removed all index filters for collection: {ns}", "ns"_attr = ns);
return Status::OK();
}
@@ -397,7 +400,10 @@ Status SetFilter::set(OperationContext* opCtx,
// Remove entry from plan cache.
planCache->remove(*cq).transitional_ignore();
- LOG(0) << "Index filter set on " << redact(cq->toStringShort()) << " " << indexesElt;
+ LOGV2(20481,
+ "Index filter set on {cq_Short} {indexesElt}",
+ "cq_Short"_attr = redact(cq->toStringShort()),
+ "indexesElt"_attr = indexesElt);
return Status::OK();
}
diff --git a/src/mongo/db/commands/kill_op.cpp b/src/mongo/db/commands/kill_op.cpp
index 5a9b639427e..fa088731393 100644
--- a/src/mongo/db/commands/kill_op.cpp
+++ b/src/mongo/db/commands/kill_op.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/commands/kill_op_cmd_base.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -58,7 +59,7 @@ public:
// Used by tests to check if auth checks passed.
result.append("info", "attempting to kill op");
- log() << "going to kill op: " << opId;
+ LOGV2(20482, "going to kill op: {opId}", "opId"_attr = opId);
KillOpCmdBase::killLocalOperation(opCtx, opId);
// killOp always reports success once past the auth check.
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index a9a8582f136..05f3d15e2ea 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -65,6 +65,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/storage/durable_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/parallel.h"
@@ -467,7 +468,7 @@ Config::Config(const string& _dbname, const BSONObj& cmdObj) {
// DEPRECATED
if (auto mapParamsElem = cmdObj["mapparams"]) {
if (mapParamsDeprecationSampler.tick()) {
- warning() << "The mapparams option to MapReduce is deprecated.";
+ LOGV2_WARNING(20493, "The mapparams option to MapReduce is deprecated.");
}
if (mapParamsElem.type() == Array) {
mapParams = mapParamsElem.embeddedObjectUserCheck().getOwned();
@@ -929,11 +930,12 @@ State::~State() {
_config.tempNamespace,
_useIncremental ? _config.incLong : NamespaceString());
} catch (...) {
- error() << "Unable to drop temporary collection created by mapReduce: "
- << _config.tempNamespace
- << ". This collection will be removed automatically "
- "the next time the server starts up. "
- << exceptionToStatus();
+ LOGV2_ERROR(20494,
+ "Unable to drop temporary collection created by mapReduce: "
+ "{config_tempNamespace}. This collection will be removed automatically "
+ "the next time the server starts up. {exceptionToStatus}",
+ "config_tempNamespace"_attr = _config.tempNamespace,
+ "exceptionToStatus"_attr = exceptionToStatus());
}
}
if (_scope && !_scope->isKillPending() && _scope->getError().empty()) {
@@ -944,7 +946,7 @@ State::~State() {
_scope->invoke(cleanup, nullptr, nullptr, 0, true);
} catch (const DBException&) {
// not important because properties will be reset if scope is reused
- LOG(1) << "MapReduce terminated during state destruction";
+ LOGV2_DEBUG(20483, 1, "MapReduce terminated during state destruction");
}
}
}
@@ -1086,7 +1088,7 @@ void State::switchMode(bool jsMode) {
}
void State::bailFromJS() {
- LOG(1) << "M/R: Switching from JS mode to mixed mode";
+ LOGV2_DEBUG(20484, 1, "M/R: Switching from JS mode to mixed mode");
// reduce and reemit into c++
switchMode(false);
@@ -1363,9 +1365,14 @@ void State::reduceAndSpillInMemoryStateIfNeeded() {
// reduce now to lower mem usage
Timer t;
_scope->invoke(_reduceAll, nullptr, nullptr, 0, true);
- LOG(3) << " MR - did reduceAll: keys=" << keyCt << " dups=" << dupCt
- << " newKeys=" << _scope->getNumberInt("_keyCt") << " time=" << t.millis()
- << "ms";
+ LOGV2_DEBUG(20485,
+ 3,
+ " MR - did reduceAll: keys={keyCt} dups={dupCt} "
+ "newKeys={scope_getNumberInt_keyCt} time={t_millis}ms",
+ "keyCt"_attr = keyCt,
+ "dupCt"_attr = dupCt,
+ "scope_getNumberInt_keyCt"_attr = _scope->getNumberInt("_keyCt"),
+ "t_millis"_attr = t.millis());
return;
}
}
@@ -1378,13 +1385,19 @@ void State::reduceAndSpillInMemoryStateIfNeeded() {
long oldSize = _size;
Timer t;
reduceInMemory();
- LOG(3) << " MR - did reduceInMemory: size=" << oldSize << " dups=" << _dupCount
- << " newSize=" << _size << " time=" << t.millis() << "ms";
+ LOGV2_DEBUG(20486,
+ 3,
+ " MR - did reduceInMemory: size={oldSize} dups={dupCount} newSize={size} "
+ "time={t_millis}ms",
+ "oldSize"_attr = oldSize,
+ "dupCount"_attr = _dupCount,
+ "size"_attr = _size,
+ "t_millis"_attr = t.millis());
// if size is still high, or values are not reducing well, dump
if (_onDisk && (_size > _config.maxInMemSize || _size > oldSize / 2)) {
dumpToInc();
- LOG(3) << " MR - dumping to db";
+ LOGV2_DEBUG(20487, 3, " MR - dumping to db");
}
}
}
@@ -1411,7 +1424,7 @@ bool runMapReduce(OperationContext* opCtx,
const Config config(dbname, cmd);
- LOG(1) << "mr ns: " << config.nss;
+ LOGV2_DEBUG(20488, 1, "mr ns: {config_nss}", "config_nss"_attr = config.nss);
uassert(16149, "cannot run map reduce without the js engine", getGlobalScriptEngine());
@@ -1638,19 +1651,19 @@ bool runMapReduce(OperationContext* opCtx,
invariant(e.extraInfo<StaleConfigInfo>()->getShardId());
}
- log() << "mr detected stale config, should retry" << redact(e);
+ LOGV2(20489, "mr detected stale config, should retry{e}", "e"_attr = redact(e));
throw;
}
// TODO: The error handling code for queries is v. fragile,
// *requires* rethrow AssertionExceptions - should probably fix.
catch (AssertionException& e) {
- log() << "mr failed, removing collection" << redact(e);
+ LOGV2(20490, "mr failed, removing collection{e}", "e"_attr = redact(e));
throw;
} catch (std::exception& e) {
- log() << "mr failed, removing collection" << causedBy(e);
+ LOGV2(20491, "mr failed, removing collection{causedBy_e}", "causedBy_e"_attr = causedBy(e));
throw;
} catch (...) {
- log() << "mr failed for unknown reason, removing collection";
+ LOGV2(20492, "mr failed for unknown reason, removing collection");
throw;
}
diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp
index 2899d5b602f..b25debc548b 100644
--- a/src/mongo/db/commands/oplog_note.cpp
+++ b/src/mongo/db/commands/oplog_note.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -60,7 +61,7 @@ Status _performNoopWrite(OperationContext* opCtx, BSONObj msgObj, StringData not
opCtx, MODE_IX, Date_t::now() + Milliseconds(1), Lock::InterruptBehavior::kLeaveUnlocked);
if (!lock.isLocked()) {
- LOG(1) << "Global lock is not available skipping noopWrite";
+ LOGV2_DEBUG(20495, 1, "Global lock is not available skipping noopWrite");
return {ErrorCodes::LockFailed, "Global lock is not available"};
}
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index a189e6f3426..e474b7f6353 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/logger/logger.h"
#include "mongo/logger/parse_log_component_settings.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -358,8 +359,11 @@ public:
try {
uassertStatusOK(foundParameter->second->set(parameter));
} catch (const DBException& ex) {
- log() << "error setting parameter " << parameterName << " to "
- << redact(parameter.toString(false)) << " errMsg: " << redact(ex);
+ LOGV2(20496,
+ "error setting parameter {parameterName} to {parameter_false} errMsg: {ex}",
+ "parameterName"_attr = parameterName,
+ "parameter_false"_attr = redact(parameter.toString(false)),
+ "ex"_attr = redact(ex));
throw;
}
diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp
index 31c2153a8da..f5c124d2451 100644
--- a/src/mongo/db/commands/resize_oplog.cpp
+++ b/src/mongo/db/commands/resize_oplog.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/durable_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -107,7 +108,7 @@ public:
uassertStatusOK(status);
DurableCatalog::get(opCtx)->updateCappedSize(opCtx, coll->getCatalogId(), size);
wunit.commit();
- LOG(0) << "replSetResizeOplog success, currentSize:" << size;
+ LOGV2(20497, "replSetResizeOplog success, currentSize:{size}", "size"_attr = size);
return true;
});
}
diff --git a/src/mongo/db/commands/rwc_defaults_commands.cpp b/src/mongo/db/commands/rwc_defaults_commands.cpp
index b4ada0db3ec..2352c1650d7 100644
--- a/src/mongo/db/commands/rwc_defaults_commands.cpp
+++ b/src/mongo/db/commands/rwc_defaults_commands.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/rw_concern_default_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/log.h"
@@ -114,7 +115,9 @@ public:
opCtx, request().getDefaultReadConcern(), request().getDefaultWriteConcern());
updatePersistedDefaultRWConcernDocument(opCtx, newDefaults);
- log() << "successfully set RWC defaults to " << newDefaults.toBSON();
+ LOGV2(20498,
+ "successfully set RWC defaults to {newDefaults}",
+ "newDefaults"_attr = newDefaults.toBSON());
// Refresh to populate the cache with the latest defaults.
rwcDefaults.refreshIfNecessary(opCtx);
diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp
index 685332111b3..b7469ceb8fd 100644
--- a/src/mongo/db/commands/server_status.cpp
+++ b/src/mongo/db/commands/server_status.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/commands/server_status_internal.h"
#include "mongo/db/service_context.h"
#include "mongo/db/stats/counters.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/net/http_client.h"
#include "mongo/util/net/socket_utils.h"
@@ -145,7 +146,7 @@ public:
timeBuilder.appendNumber("at end", durationCount<Milliseconds>(runElapsed));
if (runElapsed > Milliseconds(1000)) {
BSONObj t = timeBuilder.obj();
- log() << "serverStatus was very slow: " << t;
+ LOGV2(20499, "serverStatus was very slow: {t}", "t"_attr = t);
bool include_timing = true;
const auto& elem = cmdObj[kTimingSection];
diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
index 9ca817e1d66..6dc12d4af3f 100644
--- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
+++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/s/migration_util.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/database_version_helpers.h"
@@ -213,7 +214,7 @@ public:
if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
const auto shardingState = ShardingState::get(opCtx);
if (shardingState->enabled()) {
- LOG(0) << "Upgrade: submitting orphaned ranges for cleanup";
+ LOGV2(20500, "Upgrade: submitting orphaned ranges for cleanup");
migrationutil::submitOrphanRangesForCleanup(opCtx);
}
@@ -236,7 +237,7 @@ public:
<< requestedVersion)))));
if (MONGO_unlikely(pauseBeforeUpgradingConfigMetadata.shouldFail())) {
- log() << "Hit pauseBeforeUpgradingConfigMetadata";
+ LOGV2(20501, "Hit pauseBeforeUpgradingConfigMetadata");
pauseBeforeUpgradingConfigMetadata.pauseWhileSet(opCtx);
}
ShardingCatalogManager::get(opCtx)->upgradeOrDowngradeChunksAndTags(
@@ -308,7 +309,7 @@ public:
repl::ReplicationCoordinator::modeReplSet;
if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
- LOG(0) << "Downgrade: dropping config.rangeDeletions collection";
+ LOGV2(20502, "Downgrade: dropping config.rangeDeletions collection");
migrationutil::dropRangeDeletionsCollection(opCtx);
// The primary shard sharding a collection will write the initial chunks for a
@@ -334,7 +335,7 @@ public:
<< requestedVersion)))));
if (MONGO_unlikely(pauseBeforeDowngradingConfigMetadata.shouldFail())) {
- log() << "Hit pauseBeforeDowngradingConfigMetadata";
+ LOGV2(20503, "Hit pauseBeforeDowngradingConfigMetadata");
pauseBeforeDowngradingConfigMetadata.pauseWhileSet(opCtx);
}
ShardingCatalogManager::get(opCtx)->upgradeOrDowngradeChunksAndTags(
diff --git a/src/mongo/db/commands/sleep_command.cpp b/src/mongo/db/commands/sleep_command.cpp
index 21407950cd8..c7c74a1c01f 100644
--- a/src/mongo/db/commands/sleep_command.cpp
+++ b/src/mongo/db/commands/sleep_command.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/concurrency/lock_manager_defs.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -118,7 +119,7 @@ public:
const std::string& ns,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
- log() << "test only command sleep invoked";
+ LOGV2(20504, "test only command sleep invoked");
long long msToSleep = 0;
if (cmdObj["secs"] || cmdObj["seconds"] || cmdObj["millis"]) {
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index 81b7332b31a..bf5f1101fcc 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/op_observer.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -80,7 +81,9 @@ public:
string& errmsg,
BSONObjBuilder& result) {
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj));
- log() << "test only command godinsert invoked coll:" << nss.coll();
+ LOGV2(20505,
+ "test only command godinsert invoked coll:{nss_coll}",
+ "nss_coll"_attr = nss.coll());
BSONObj obj = cmdObj["obj"].embeddedObjectUserCheck();
Lock::DBLock lk(opCtx, dbname, MODE_X);
diff --git a/src/mongo/db/commands/traffic_recording_cmds.cpp b/src/mongo/db/commands/traffic_recording_cmds.cpp
index 7fd2894c9f6..9cb02bcf45a 100644
--- a/src/mongo/db/commands/traffic_recording_cmds.cpp
+++ b/src/mongo/db/commands/traffic_recording_cmds.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/commands.h"
#include "mongo/db/traffic_recorder.h"
#include "mongo/db/traffic_recorder_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -53,9 +54,10 @@ public:
void typedRun(OperationContext* opCtx) {
TrafficRecorder::get(opCtx->getServiceContext()).start(request());
- log() << "** Warning: The recording file contains unencrypted user traffic."
- << " We recommend that you limit retention of this file and "
- << "store it on an encrypted filesystem volume.";
+ LOGV2(20506,
+ "** Warning: The recording file contains unencrypted user traffic. We recommend "
+ "that you limit retention of this file and store it on an encrypted filesystem "
+ "volume.");
}
private:
diff --git a/src/mongo/db/commands/txn_cmds.cpp b/src/mongo/db/commands/txn_cmds.cpp
index 9f9e7afa02e..91dfc7fa8dd 100644
--- a/src/mongo/db/commands/txn_cmds.cpp
+++ b/src/mongo/db/commands/txn_cmds.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/db/transaction_validation.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -95,8 +96,12 @@ public:
"commitTransaction must be run within a transaction",
txnParticipant);
- LOG(3) << "Received commitTransaction for transaction with txnNumber "
- << opCtx->getTxnNumber() << " on session " << opCtx->getLogicalSessionId()->toBSON();
+ LOGV2_DEBUG(20507,
+ 3,
+ "Received commitTransaction for transaction with txnNumber "
+ "{opCtx_getTxnNumber} on session {opCtx_getLogicalSessionId}",
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(),
+ "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON());
// commitTransaction is retryable.
if (txnParticipant.transactionIsCommitted()) {
@@ -199,8 +204,12 @@ public:
"abortTransaction must be run within a transaction",
txnParticipant);
- LOG(3) << "Received abortTransaction for transaction with txnNumber "
- << opCtx->getTxnNumber() << " on session " << opCtx->getLogicalSessionId()->toBSON();
+ LOGV2_DEBUG(20508,
+ 3,
+ "Received abortTransaction for transaction with txnNumber {opCtx_getTxnNumber} "
+ "on session {opCtx_getLogicalSessionId}",
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(),
+ "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON());
uassert(ErrorCodes::NoSuchTransaction,
"Transaction isn't in progress",
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp
index 90bec146f42..2ccf5d6d97f 100644
--- a/src/mongo/db/commands/user_management_commands.cpp
+++ b/src/mongo/db/commands/user_management_commands.cpp
@@ -67,6 +67,7 @@
#include "mongo/db/ops/write_ops.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/write_ops/batched_command_response.h"
@@ -579,7 +580,7 @@ public:
}
if (_authzManager->getCacheGeneration() == _cacheGeneration) {
- LOG(1) << "User management command did not invalidate the user cache.";
+ LOGV2_DEBUG(20509, 1, "User management command did not invalidate the user cache.");
_authzManager->invalidateUserCache(_opCtx);
}
}
@@ -2494,16 +2495,22 @@ public:
Status status = updatePrivilegeDocument(opCtx, userName, userObj);
if (!status.isOK()) {
// Match the behavior of mongorestore to continue on failure
- warning() << "Could not update user " << userName
- << " in _mergeAuthzCollections command: " << redact(status);
+ LOGV2_WARNING(
+ 20510,
+ "Could not update user {userName} in _mergeAuthzCollections command: {status}",
+ "userName"_attr = userName,
+ "status"_attr = redact(status));
}
} else {
auditCreateOrUpdateUser(userObj, true);
Status status = insertPrivilegeDocument(opCtx, userObj);
if (!status.isOK()) {
// Match the behavior of mongorestore to continue on failure
- warning() << "Could not insert user " << userName
- << " in _mergeAuthzCollections command: " << redact(status);
+ LOGV2_WARNING(
+ 20511,
+ "Could not insert user {userName} in _mergeAuthzCollections command: {status}",
+ "userName"_attr = userName,
+ "status"_attr = redact(status));
}
}
usersToDrop->erase(userName);
@@ -2532,16 +2539,22 @@ public:
Status status = updateRoleDocument(opCtx, roleName, roleObj);
if (!status.isOK()) {
// Match the behavior of mongorestore to continue on failure
- warning() << "Could not update role " << roleName
- << " in _mergeAuthzCollections command: " << redact(status);
+ LOGV2_WARNING(
+ 20512,
+ "Could not update role {roleName} in _mergeAuthzCollections command: {status}",
+ "roleName"_attr = roleName,
+ "status"_attr = redact(status));
}
} else {
auditCreateOrUpdateRole(roleObj, true);
Status status = insertRoleDocument(opCtx, roleObj);
if (!status.isOK()) {
// Match the behavior of mongorestore to continue on failure
- warning() << "Could not insert role " << roleName
- << " in _mergeAuthzCollections command: " << redact(status);
+ LOGV2_WARNING(
+ 20513,
+ "Could not insert role {roleName} in _mergeAuthzCollections command: {status}",
+ "roleName"_attr = roleName,
+ "status"_attr = redact(status));
}
}
rolesToDrop->erase(roleName);
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index 3cdf9353749..f6b32d28eab 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/record_store.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -142,8 +143,11 @@ public:
}
if (!serverGlobalParams.quiet.load()) {
- LOG(0) << "CMD: validate " << nss.ns() << (background ? ", background:true" : "")
- << (fullValidate ? ", full:true" : "");
+ LOGV2(20514,
+ "CMD: validate {nss_ns}{background_background_true}{fullValidate_full_true}",
+ "nss_ns"_attr = nss.ns(),
+ "background_background_true"_attr = (background ? ", background:true" : ""),
+ "fullValidate_full_true"_attr = (fullValidate ? ", full:true" : ""));
}
// Only one validation per collection can be in progress, the rest wait.
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index bf2b8bd62ff..8d00a0f1f44 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/storage/recovery_unit_noop.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/future.h"
#include "mongo/stdx/thread.h"
#include "mongo/unittest/unittest.h"
@@ -2074,9 +2075,13 @@ TEST_F(DConcurrencyTestFixture, CompatibleFirstStress) {
for (auto& thread : threads)
thread.join();
for (int threadId = 0; threadId < numThreads; threadId++) {
- log() << "thread " << threadId << " stats: " << acquisitionCount[threadId]
- << " acquisitions, " << timeoutCount[threadId] << " timeouts, "
- << busyWaitCount[threadId] / 1'000'000 << "M busy waits";
+ LOGV2(20515,
+ "thread {threadId} stats: {acquisitionCount_threadId} acquisitions, "
+ "{timeoutCount_threadId} timeouts, {busyWaitCount_threadId_1_000_000}M busy waits",
+ "threadId"_attr = threadId,
+ "acquisitionCount_threadId"_attr = acquisitionCount[threadId],
+ "timeoutCount_threadId"_attr = timeoutCount[threadId],
+ "busyWaitCount_threadId_1_000_000"_attr = busyWaitCount[threadId] / 1'000'000);
}
}
diff --git a/src/mongo/db/concurrency/deferred_writer.cpp b/src/mongo/db/concurrency/deferred_writer.cpp
index 4bedbe1995c..b06d4faa127 100644
--- a/src/mongo/db/concurrency/deferred_writer.cpp
+++ b/src/mongo/db/concurrency/deferred_writer.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/operation_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/concurrency/thread_pool.h"
#include "mongo/util/log.h"
@@ -47,7 +48,10 @@ auto kLogInterval = stdx::chrono::minutes(1);
void DeferredWriter::_logFailure(const Status& status) {
if (TimePoint::clock::now() - _lastLogged > kLogInterval) {
- log() << "Unable to write to collection " << _nss.toString() << ": " << status.toString();
+ LOGV2(20516,
+ "Unable to write to collection {nss}: {status}",
+ "nss"_attr = _nss.toString(),
+ "status"_attr = status.toString());
_lastLogged = stdx::chrono::system_clock::now();
}
}
@@ -55,8 +59,11 @@ void DeferredWriter::_logFailure(const Status& status) {
void DeferredWriter::_logDroppedEntry() {
_droppedEntries += 1;
if (TimePoint::clock::now() - _lastLoggedDrop > kLogInterval) {
- log() << "Deferred write buffer for " << _nss.toString() << " is full. " << _droppedEntries
- << " entries have been dropped.";
+ LOGV2(
+ 20517,
+ "Deferred write buffer for {nss} is full. {droppedEntries} entries have been dropped.",
+ "nss"_attr = _nss.toString(),
+ "droppedEntries"_attr = _droppedEntries);
_lastLoggedDrop = stdx::chrono::system_clock::now();
_droppedEntries = 0;
}
diff --git a/src/mongo/db/concurrency/flow_control_ticketholder.cpp b/src/mongo/db/concurrency/flow_control_ticketholder.cpp
index 4a8057159e1..a11c4b399c4 100644
--- a/src/mongo/db/concurrency/flow_control_ticketholder.cpp
+++ b/src/mongo/db/concurrency/flow_control_ticketholder.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/concurrency/flow_control_ticketholder.h"
#include "mongo/db/operation_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
@@ -81,7 +82,11 @@ void FlowControlTicketholder::set(ServiceContext* service,
void FlowControlTicketholder::refreshTo(int numTickets) {
invariant(numTickets >= 0);
stdx::lock_guard<Latch> lk(_mutex);
- LOG(4) << "Refreshing tickets. Before: " << _tickets << " Now: " << numTickets;
+ LOGV2_DEBUG(20518,
+ 4,
+ "Refreshing tickets. Before: {tickets} Now: {numTickets}",
+ "tickets"_attr = _tickets,
+ "numTickets"_attr = numTickets);
_tickets = numTickets;
_cv.notify_all();
}
@@ -93,7 +98,7 @@ void FlowControlTicketholder::getTicket(OperationContext* opCtx,
return;
}
- LOG(4) << "Taking ticket. Available: " << _tickets;
+ LOGV2_DEBUG(20519, 4, "Taking ticket. Available: {tickets}", "tickets"_attr = _tickets);
if (_tickets == 0) {
++stats->acquireWaitCount;
}
@@ -130,7 +135,7 @@ void FlowControlTicketholder::getTicket(OperationContext* opCtx,
// Should only be called once, during shutdown.
void FlowControlTicketholder::setInShutdown() {
- LOG(0) << "Stopping further Flow Control ticket acquisitions.";
+ LOGV2(20520, "Stopping further Flow Control ticket acquisitions.");
stdx::lock_guard<Latch> lk(_mutex);
_inShutdown = true;
_cv.notify_all();
diff --git a/src/mongo/db/concurrency/lock_manager.cpp b/src/mongo/db/concurrency/lock_manager.cpp
index 0ab21e4c425..b27c632c7ee 100644
--- a/src/mongo/db/concurrency/lock_manager.cpp
+++ b/src/mongo/db/concurrency/lock_manager.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/concurrency/locker.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -826,7 +827,9 @@ LockManager::Partition* LockManager::_getPartition(LockRequest* request) const {
}
void LockManager::dump() const {
- log() << "Dumping LockManager @ " << reinterpret_cast<uint64_t>(this) << '\n';
+ LOGV2(20521,
+ "Dumping LockManager @ {reinterpret_cast_uint64_t_this}",
+ "reinterpret_cast_uint64_t_this"_attr = reinterpret_cast<uint64_t>(this));
auto lockToClientMap = getLockToClientMap(getGlobalServiceContext());
for (unsigned i = 0; i < _numLockBuckets; i++) {
@@ -963,7 +966,7 @@ void LockManager::_dumpBucket(const std::map<LockerId, BSONObj>& lockToClientMap
}
sb << "-----------------------------------------------------------\n";
- log() << sb.str();
+ LOGV2(20522, "{sb_str}", "sb_str"_attr = sb.str());
}
}
diff --git a/src/mongo/db/concurrency/lock_state.cpp b/src/mongo/db/concurrency/lock_state.cpp
index 3f98a7322b3..2b2f104dacc 100644
--- a/src/mongo/db/concurrency/lock_state.cpp
+++ b/src/mongo/db/concurrency/lock_state.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/db/service_context.h"
#include "mongo/db/storage/flow_control.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/compiler.h"
#include "mongo/stdx/new.h"
#include "mongo/util/background.h"
@@ -203,7 +204,7 @@ void LockerImpl::dump() const {
}
_lock.unlock();
- log() << ss.str();
+ LOGV2(20523, "{ss_str}", "ss_str"_attr = ss.str());
}
@@ -1062,7 +1063,7 @@ public:
}
void taskDoWork() {
- LOG(2) << "cleaning up unused lock buckets of the global lock manager";
+ LOGV2_DEBUG(20524, 2, "cleaning up unused lock buckets of the global lock manager");
getGlobalLockManager()->cleanupUnusedLocks();
}
} unusedLockCleaner;
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index 76e64830695..96ded269c07 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/prepare_conflict_tracker.h"
#include "mongo/db/query/getmore_request.h"
#include "mongo/db/query/plan_summary_stats.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
#include "mongo/rpc/metadata/impersonated_user_metadata.h"
@@ -380,7 +381,10 @@ void CurOp::setGenericOpRequestDetails(OperationContext* opCtx,
void CurOp::setMessage_inlock(StringData message) {
if (_progressMeter.isActive()) {
- error() << "old _message: " << redact(_message) << " new message:" << redact(message);
+ LOGV2_ERROR(20527,
+ "old _message: {message} new message:{message2}",
+ "message"_attr = redact(_message),
+ "message2"_attr = redact(message));
verify(!_progressMeter.isActive());
}
_message = message.toString(); // copy
@@ -467,12 +471,16 @@ bool CurOp::completeAndLogOperation(OperationContext* opCtx,
if (lk.isLocked()) {
_debug.storageStats = opCtx->recoveryUnit()->getOperationStatistics();
} else {
- warning(component) << "Unable to gather storage statistics for a slow "
- "operation due to lock aquire timeout";
+ LOGV2_WARNING_OPTIONS(20525,
+ {logComponentV1toV2(component)},
+ "Unable to gather storage statistics for a slow "
+ "operation due to lock aquire timeout");
}
} catch (const ExceptionForCat<ErrorCategory::Interruption>&) {
- warning(component) << "Unable to gather storage statistics for a slow "
- "operation due to interrupt";
+ LOGV2_WARNING_OPTIONS(20526,
+ {logComponentV1toV2(component)},
+ "Unable to gather storage statistics for a slow "
+ "operation due to interrupt");
}
}
diff --git a/src/mongo/db/cursor_manager.cpp b/src/mongo/db/cursor_manager.cpp
index 93dd9cad7f7..6092fcbffbc 100644
--- a/src/mongo/db/cursor_manager.cpp
+++ b/src/mongo/db/cursor_manager.cpp
@@ -52,6 +52,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -90,7 +91,7 @@ std::pair<Status, int> CursorManager::killCursorsWithMatchingSessions(
OperationContext* opCtx, const SessionKiller::Matcher& matcher) {
auto eraser = [&](CursorManager& mgr, CursorId id) {
uassertStatusOK(mgr.killCursor(opCtx, id, true));
- log() << "killing cursor: " << id << " as part of killing session(s)";
+ LOGV2(20528, "killing cursor: {id} as part of killing session(s)", "id"_attr = id);
};
auto bySessionCursorKiller = makeKillCursorsBySessionAdaptor(opCtx, matcher, std::move(eraser));
@@ -141,8 +142,10 @@ std::size_t CursorManager::timeoutCursors(OperationContext* opCtx, Date_t now) {
// Be careful not to dispose of cursors while holding the partition lock.
for (auto&& cursor : toDisposeWithoutMutex) {
- log() << "Cursor id " << cursor->cursorid() << " timed out, idle since "
- << cursor->getLastUseDate();
+ LOGV2(20529,
+ "Cursor id {cursor_cursorid} timed out, idle since {cursor_getLastUseDate}",
+ "cursor_cursorid"_attr = cursor->cursorid(),
+ "cursor_getLastUseDate"_attr = cursor->getLastUseDate());
cursor->dispose(opCtx);
}
return toDisposeWithoutMutex.size();
@@ -212,8 +215,10 @@ void CursorManager::unpin(OperationContext* opCtx,
// proactively delete the cursor. In other cases we preserve the error code so that the client
// will see the reason the cursor was killed when asking for the next batch.
if (interruptStatus == ErrorCodes::Interrupted || interruptStatus == ErrorCodes::CursorKilled) {
- LOG(0) << "removing cursor " << cursor->cursorid()
- << " after completing batch: " << interruptStatus;
+ LOGV2(20530,
+ "removing cursor {cursor_cursorid} after completing batch: {interruptStatus}",
+ "cursor_cursorid"_attr = cursor->cursorid(),
+ "interruptStatus"_attr = interruptStatus);
return deregisterAndDestroyCursor(std::move(partition), opCtx, std::move(cursor));
} else if (!interruptStatus.isOK()) {
cursor->markAsKilled(interruptStatus);
diff --git a/src/mongo/db/database_index_builds_tracker.cpp b/src/mongo/db/database_index_builds_tracker.cpp
index 4f7bb13a472..c8d21639050 100644
--- a/src/mongo/db/database_index_builds_tracker.cpp
+++ b/src/mongo/db/database_index_builds_tracker.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/database_index_builds_tracker.h"
#include "mongo/db/catalog/index_builds_manager.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -80,9 +81,11 @@ void DatabaseIndexBuildsTracker::waitUntilNoIndexBuildsRemain(stdx::unique_lock<
return true;
}
- log() << "Waiting until the following index builds are finished:";
+ LOGV2(20531, "Waiting until the following index builds are finished:");
for (const auto& indexBuild : _allIndexBuilds) {
- log() << " Index build with UUID: " << indexBuild.first;
+ LOGV2(20532,
+ " Index build with UUID: {indexBuild_first}",
+ "indexBuild_first"_attr = indexBuild.first);
}
return false;
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index b5a2fd26c42..59da6fe85a1 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -152,6 +152,7 @@
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/network_interface_thread_pool.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/process_id.h"
#include "mongo/platform/random.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
@@ -300,7 +301,8 @@ ExitCode _initAndListen(int listenPort) {
}
if (kDebugBuild)
- log(LogComponent::kControl) << "DEBUG build (which is slower)" << endl;
+ LOGV2_OPTIONS(
+ 20533, {logComponentV1toV2(LogComponent::kControl)}, "DEBUG build (which is slower)");
#if defined(_WIN32)
VersionInfoInterface::instance().logTargetMinOS();
@@ -317,7 +319,7 @@ ExitCode _initAndListen(int listenPort) {
transport::TransportLayerManager::createWithConfig(&serverGlobalParams, serviceContext);
auto res = tl->setup();
if (!res.isOK()) {
- error() << "Failed to set up listener: " << res;
+ LOGV2_ERROR(20568, "Failed to set up listener: {res}", "res"_attr = res);
return EXIT_NET_ERROR;
}
serviceContext->setTransportLayer(std::move(tl));
@@ -352,9 +354,11 @@ ExitCode _initAndListen(int listenPort) {
// Warn if field name matches non-active registered storage engine.
if (isRegisteredStorageEngine(serviceContext, e.fieldName())) {
- warning() << "Detected configuration for non-active storage engine "
- << e.fieldName() << " when current storage engine is "
- << storageGlobalParams.engine;
+ LOGV2_WARNING(20566,
+ "Detected configuration for non-active storage engine {e_fieldName} "
+ "when current storage engine is {storageGlobalParams_engine}",
+ "e_fieldName"_attr = e.fieldName(),
+ "storageGlobalParams_engine"_attr = storageGlobalParams.engine);
}
}
}
@@ -362,17 +366,20 @@ ExitCode _initAndListen(int listenPort) {
// Disallow running a storage engine that doesn't support capped collections with --profile
if (!serviceContext->getStorageEngine()->supportsCappedCollections() &&
serverGlobalParams.defaultProfile != 0) {
- log() << "Running " << storageGlobalParams.engine << " with profiling is not supported. "
- << "Make sure you are not using --profile.";
+ LOGV2(20534,
+ "Running {storageGlobalParams_engine} with profiling is not supported. Make sure you "
+ "are not using --profile.",
+ "storageGlobalParams_engine"_attr = storageGlobalParams.engine);
exitCleanly(EXIT_BADOPTIONS);
}
// Disallow running WiredTiger with --nojournal in a replica set
if (storageGlobalParams.engine == "wiredTiger" && !storageGlobalParams.dur &&
replSettings.usingReplSets()) {
- log() << "Running wiredTiger without journaling in a replica set is not "
- << "supported. Make sure you are not using --nojournal and that "
- << "storage.journal.enabled is not set to 'false'.";
+ LOGV2(20535,
+ "Running wiredTiger without journaling in a replica set is not supported. Make sure "
+ "you are not using --nojournal and that storage.journal.enabled is not set to "
+ "'false'.");
exitCleanly(EXIT_BADOPTIONS);
}
@@ -415,7 +422,10 @@ ExitCode _initAndListen(int listenPort) {
try {
nonLocalDatabases = repairDatabasesAndCheckVersion(startupOpCtx.get());
} catch (const ExceptionFor<ErrorCodes::MustDowngrade>& error) {
- severe(LogComponent::kControl) << "** IMPORTANT: " << error.toStatus().reason();
+ LOGV2_FATAL_OPTIONS(20573,
+ {logComponentV1toV2(LogComponent::kControl)},
+ "** IMPORTANT: {error_toStatus_reason}",
+ "error_toStatus_reason"_attr = error.toStatus().reason());
exitCleanly(EXIT_NEED_DOWNGRADE);
}
@@ -437,11 +447,11 @@ ExitCode _initAndListen(int listenPort) {
}
if (gFlowControlEnabled.load()) {
- log() << "Flow Control is enabled on this deployment.";
+ LOGV2(20536, "Flow Control is enabled on this deployment.");
}
if (storageGlobalParams.upgrade) {
- log() << "finished checking dbs";
+ LOGV2(20537, "finished checking dbs");
exitCleanly(EXIT_CLEAN);
}
@@ -457,7 +467,7 @@ ExitCode _initAndListen(int listenPort) {
if (globalAuthzManager->shouldValidateAuthSchemaOnStartup()) {
Status status = verifySystemIndexes(startupOpCtx.get());
if (!status.isOK()) {
- log() << redact(status);
+ LOGV2(20538, "{status}", "status"_attr = redact(status));
if (status == ErrorCodes::AuthSchemaIncompatible) {
exitCleanly(EXIT_NEED_UPGRADE);
} else if (status == ErrorCodes::NotMaster) {
@@ -473,37 +483,44 @@ ExitCode _initAndListen(int listenPort) {
status =
globalAuthzManager->getAuthorizationVersion(startupOpCtx.get(), &foundSchemaVersion);
if (!status.isOK()) {
- log() << "Auth schema version is incompatible: "
- << "User and role management commands require auth data to have "
- << "at least schema version " << AuthorizationManager::schemaVersion26Final
- << " but startup could not verify schema version: " << status;
- log() << "To manually repair the 'authSchema' document in the admin.system.version "
- "collection, start up with --setParameter "
- "startupAuthSchemaValidation=false to disable validation.";
+ LOGV2(20539,
+ "Auth schema version is incompatible: User and role management commands require "
+ "auth data to have at least schema version "
+ "{AuthorizationManager_schemaVersion26Final} but startup could not verify schema "
+ "version: {status}",
+ "AuthorizationManager_schemaVersion26Final"_attr =
+ AuthorizationManager::schemaVersion26Final,
+ "status"_attr = status);
+ LOGV2(20540,
+ "To manually repair the 'authSchema' document in the admin.system.version "
+ "collection, start up with --setParameter "
+ "startupAuthSchemaValidation=false to disable validation.");
exitCleanly(EXIT_NEED_UPGRADE);
}
if (foundSchemaVersion <= AuthorizationManager::schemaVersion26Final) {
- log() << "This server is using MONGODB-CR, an authentication mechanism which "
- << "has been removed from MongoDB 4.0. In order to upgrade the auth schema, "
- << "first downgrade MongoDB binaries to version 3.6 and then run the "
- << "authSchemaUpgrade command. "
- << "See http://dochub.mongodb.org/core/3.0-upgrade-to-scram-sha-1";
+ LOGV2(20541,
+ "This server is using MONGODB-CR, an authentication mechanism which has been "
+ "removed from MongoDB 4.0. In order to upgrade the auth schema, first downgrade "
+ "MongoDB binaries to version 3.6 and then run the authSchemaUpgrade command. See "
+ "http://dochub.mongodb.org/core/3.0-upgrade-to-scram-sha-1");
exitCleanly(EXIT_NEED_UPGRADE);
}
} else if (globalAuthzManager->isAuthEnabled()) {
- error() << "Auth must be disabled when starting without auth schema validation";
+ LOGV2_ERROR(20569, "Auth must be disabled when starting without auth schema validation");
exitCleanly(EXIT_BADOPTIONS);
} else {
// If authSchemaValidation is disabled and server is running without auth,
// warn the user and continue startup without authSchema metadata checks.
- log() << startupWarningsLog;
- log() << "** WARNING: Startup auth schema validation checks are disabled for the "
- "database."
- << startupWarningsLog;
- log() << "** This mode should only be used to manually repair corrupted auth "
- "data."
- << startupWarningsLog;
+ LOGV2_OPTIONS(20542, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(20543,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: Startup auth schema validation checks are disabled for the "
+ "database.");
+ LOGV2_OPTIONS(20544,
+ {logv2::LogTag::kStartupWarnings},
+ "** This mode should only be used to manually repair corrupted auth "
+ "data.");
}
WaitForMajorityService::get(serviceContext).setUp(serviceContext);
@@ -514,8 +531,9 @@ ExitCode _initAndListen(int listenPort) {
if (shardingInitialized) {
auto status = waitForShardRegistryReload(startupOpCtx.get());
if (!status.isOK()) {
- LOG(0) << "Failed to load the shard registry as part of startup"
- << causedBy(redact(status));
+ LOGV2(20545,
+ "Failed to load the shard registry as part of startup{causedBy_status}",
+ "causedBy_status"_attr = causedBy(redact(status)));
}
}
@@ -526,8 +544,10 @@ ExitCode _initAndListen(int listenPort) {
.refreshIfNecessary(startupOpCtx.get());
}
} catch (const DBException& ex) {
- warning() << "Failed to load read and write concern defaults at startup"
- << causedBy(redact(ex.toStatus()));
+ LOGV2_WARNING(
+ 20567,
+ "Failed to load read and write concern defaults at startup{causedBy_ex_toStatus}",
+ "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus())));
}
auto storageEngine = serviceContext->getStorageEngine();
@@ -604,23 +624,34 @@ ExitCode _initAndListen(int listenPort) {
replCoord->startup(startupOpCtx.get());
if (getReplSetMemberInStandaloneMode(serviceContext)) {
- log() << startupWarningsLog;
- log() << "** WARNING: mongod started without --replSet yet document(s) are present in "
- << NamespaceString::kSystemReplSetNamespace << "." << startupWarningsLog;
- log() << "** Database contents may appear inconsistent with the oplog and may "
- "appear to not contain"
- << startupWarningsLog;
- log() << "** writes that were visible when this node was running as part of a "
- "replica set."
- << startupWarningsLog;
- log() << "** Restart with --replSet unless you are doing maintenance and no "
- "other clients are connected."
- << startupWarningsLog;
- log() << "** The TTL collection monitor will not start because of this."
- << startupWarningsLog;
- log() << "** ";
- log() << " For more info see http://dochub.mongodb.org/core/ttlcollections";
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(20546, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(20547,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: mongod started without --replSet yet document(s) are "
+ "present in {NamespaceString_kSystemReplSetNamespace}.",
+ "NamespaceString_kSystemReplSetNamespace"_attr =
+ NamespaceString::kSystemReplSetNamespace);
+ LOGV2_OPTIONS(
+ 20548,
+ {logv2::LogTag::kStartupWarnings},
+ "** Database contents may appear inconsistent with the oplog and may "
+ "appear to not contain");
+ LOGV2_OPTIONS(
+ 20549,
+ {logv2::LogTag::kStartupWarnings},
+ "** writes that were visible when this node was running as part of a "
+ "replica set.");
+ LOGV2_OPTIONS(
+ 20550,
+ {logv2::LogTag::kStartupWarnings},
+ "** Restart with --replSet unless you are doing maintenance and no "
+ "other clients are connected.");
+ LOGV2_OPTIONS(20551,
+ {logv2::LogTag::kStartupWarnings},
+ "** The TTL collection monitor will not start because of this.");
+ LOGV2(20552, "** ");
+ LOGV2(20553, " For more info see http://dochub.mongodb.org/core/ttlcollections");
+ LOGV2_OPTIONS(20554, {logv2::LogTag::kStartupWarnings}, "");
} else {
startTTLBackgroundJob(serviceContext);
}
@@ -670,20 +701,22 @@ ExitCode _initAndListen(int listenPort) {
auto start = serviceContext->getServiceExecutor()->start();
if (!start.isOK()) {
- error() << "Failed to start the service executor: " << start;
+ LOGV2_ERROR(20570, "Failed to start the service executor: {start}", "start"_attr = start);
return EXIT_NET_ERROR;
}
start = serviceContext->getServiceEntryPoint()->start();
if (!start.isOK()) {
- error() << "Failed to start the service entry point: " << start;
+ LOGV2_ERROR(
+ 20571, "Failed to start the service entry point: {start}", "start"_attr = start);
return EXIT_NET_ERROR;
}
if (!storageGlobalParams.repair) {
start = serviceContext->getTransportLayer()->start();
if (!start.isOK()) {
- error() << "Failed to start the listener: " << start.toString();
+ LOGV2_ERROR(
+ 20572, "Failed to start the listener: {start}", "start"_attr = start.toString());
return EXIT_NET_ERROR;
}
}
@@ -695,12 +728,12 @@ ExitCode _initAndListen(int listenPort) {
#else
if (ntservice::shouldStartService()) {
ntservice::reportStatus(SERVICE_RUNNING);
- log() << "Service running";
+ LOGV2(20555, "Service running");
}
#endif
if (MONGO_unlikely(shutdownAtStartup.shouldFail())) {
- log() << "starting clean exit via failpoint";
+ LOGV2(20556, "starting clean exit via failpoint");
exitCleanly(EXIT_CLEAN);
}
@@ -712,16 +745,18 @@ ExitCode initAndListen(int listenPort) {
try {
return _initAndListen(listenPort);
} catch (DBException& e) {
- log() << "exception in initAndListen: " << e.toString() << ", terminating";
+ LOGV2(20557, "exception in initAndListen: {e}, terminating", "e"_attr = e.toString());
return EXIT_UNCAUGHT;
} catch (std::exception& e) {
- log() << "exception in initAndListen std::exception: " << e.what() << ", terminating";
+ LOGV2(20558,
+ "exception in initAndListen std::exception: {e_what}, terminating",
+ "e_what"_attr = e.what());
return EXIT_UNCAUGHT;
} catch (int& n) {
- log() << "exception in initAndListen int: " << n << ", terminating";
+ LOGV2(20559, "exception in initAndListen int: {n}, terminating", "n"_attr = n);
return EXIT_UNCAUGHT;
} catch (...) {
- log() << "exception in initAndListen, terminating";
+ LOGV2(20560, "exception in initAndListen, terminating");
return EXIT_UNCAUGHT;
}
}
@@ -966,8 +1001,9 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
} catch (const ExceptionFor<ErrorCodes::NotMaster>&) {
// ignore not master errors
} catch (const DBException& e) {
- log() << "Failed to stepDown in non-command initiated shutdown path "
- << e.toString();
+ LOGV2(20561,
+ "Failed to stepDown in non-command initiated shutdown path {e}",
+ "e"_attr = e.toString());
}
}
}
@@ -992,7 +1028,9 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
// Shutdown the TransportLayer so that new connections aren't accepted
if (auto tl = serviceContext->getTransportLayer()) {
- log(LogComponent::kNetwork) << "shutdown: going to close listening sockets...";
+ LOGV2_OPTIONS(20562,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "shutdown: going to close listening sockets...");
tl->shutdown();
}
@@ -1087,8 +1125,9 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
// Shutdown the Service Entry Point and its sessions and give it a grace period to complete.
if (auto sep = serviceContext->getServiceEntryPoint()) {
if (!sep->shutdown(Seconds(10))) {
- log(LogComponent::kNetwork)
- << "Service entry point failed to shutdown within timelimit.";
+ LOGV2_OPTIONS(20563,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "Service entry point failed to shutdown within timelimit.");
}
}
@@ -1096,8 +1135,10 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
if (auto svcExec = serviceContext->getServiceExecutor()) {
Status status = svcExec->shutdown(Seconds(10));
if (!status.isOK()) {
- log(LogComponent::kNetwork)
- << "Service executor failed to shutdown within timelimit: " << status.reason();
+ LOGV2_OPTIONS(20564,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "Service executor failed to shutdown within timelimit: {status_reason}",
+ "status_reason"_attr = status.reason());
}
}
#endif
@@ -1126,7 +1167,7 @@ void shutdownTask(const ShutdownTaskArgs& shutdownArgs) {
// the memory and makes leak sanitizer happy.
ScriptEngine::dropScopeCache();
- log(LogComponent::kControl) << "now exiting";
+ LOGV2_OPTIONS(20565, {logComponentV1toV2(LogComponent::kControl)}, "now exiting");
audit::logShutdown(client);
@@ -1142,7 +1183,10 @@ int mongoDbMain(int argc, char* argv[], char** envp) {
Status status = mongo::runGlobalInitializers(argc, argv, envp);
if (!status.isOK()) {
- severe(LogComponent::kControl) << "Failed global initialization: " << status;
+ LOGV2_FATAL_OPTIONS(20574,
+ {logComponentV1toV2(LogComponent::kControl)},
+ "Failed global initialization: {status}",
+ "status"_attr = status);
quickExit(EXIT_FAILURE);
}
@@ -1150,7 +1194,10 @@ int mongoDbMain(int argc, char* argv[], char** envp) {
setGlobalServiceContext(ServiceContext::make());
} catch (...) {
auto cause = exceptionToStatus();
- severe(LogComponent::kControl) << "Failed to create service context: " << redact(cause);
+ LOGV2_FATAL_OPTIONS(20575,
+ {logComponentV1toV2(LogComponent::kControl)},
+ "Failed to create service context: {cause}",
+ "cause"_attr = redact(cause));
quickExit(EXIT_FAILURE);
}
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index 02df85a977b..07b4c52c2bf 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/db_raii_gen.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/collection_sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -191,9 +192,13 @@ AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx,
// waiting for the lastAppliedTimestamp to move forward. Instead we force the reader take
// the PBWM lock and retry.
if (lastAppliedTimestamp) {
- LOG(0) << "tried reading at last-applied time: " << *lastAppliedTimestamp
- << " on ns: " << nss.ns() << ", but future catalog changes are pending at time "
- << *minSnapshot << ". Trying again without reading at last-applied time.";
+ LOGV2(20576,
+ "tried reading at last-applied time: {lastAppliedTimestamp} on ns: {nss_ns}, but "
+ "future catalog changes are pending at time {minSnapshot}. Trying again without "
+ "reading at last-applied time.",
+ "lastAppliedTimestamp"_attr = *lastAppliedTimestamp,
+ "nss_ns"_attr = nss.ns(),
+ "minSnapshot"_attr = *minSnapshot);
// Destructing the block sets _shouldConflictWithSecondaryBatchApplication back to the
// previous value. If the previous value is false (because there is another
// shouldNotConflictWithSecondaryBatchApplicationBlock outside of this function), this
@@ -265,7 +270,7 @@ bool AutoGetCollectionForRead::_shouldReadAtLastAppliedTimestamp(
// This may occur when multiple collection locks are held concurrently, which is often the case
// when DBDirectClient is used.
if (opCtx->lockState()->isLockHeldForMode(resourceIdParallelBatchWriterMode, MODE_IS)) {
- LOG(1) << "not reading at last-applied because the PBWM lock is held";
+ LOGV2_DEBUG(20577, 1, "not reading at last-applied because the PBWM lock is held");
return false;
}
diff --git a/src/mongo/db/db_raii_test.cpp b/src/mongo/db/db_raii_test.cpp
index 73a072aa86a..9df8b19356f 100644
--- a/src/mongo/db/db_raii_test.cpp
+++ b/src/mongo/db/db_raii_test.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/client.h"
#include "mongo/db/concurrency/lock_state.h"
#include "mongo/db/db_raii.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
@@ -69,7 +70,7 @@ void failsWithLockTimeout(std::function<void()> func, Milliseconds timeoutMillis
func();
FAIL("Should have gotten an exception due to timeout");
} catch (const ExceptionFor<ErrorCodes::LockTimeout>& ex) {
- log() << ex;
+ LOGV2(20578, "{ex}", "ex"_attr = ex);
Date_t t2 = Date_t::now();
ASSERT_GTE(t2 - t1, timeoutMillis);
}
diff --git a/src/mongo/db/exec/cached_plan.cpp b/src/mongo/db/exec/cached_plan.cpp
index 7f35e28a63d..1467eed69a6 100644
--- a/src/mongo/db/exec/cached_plan.cpp
+++ b/src/mongo/db/exec/cached_plan.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/query/query_knobs_gen.h"
#include "mongo/db/query/query_planner.h"
#include "mongo/db/query/stage_builder.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
#include "mongo/util/transitional_tools_do_not_use/vector_spooling.h"
@@ -141,10 +142,15 @@ Status CachedPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
// existing cache entry nor cache the result of replanning.
BSONObj statusObj = WorkingSetCommon::getStatusMemberDocument(*_ws, id)->toBson();
- LOG(1) << "Execution of cached plan failed, falling back to replan."
- << " query: " << redact(_canonicalQuery->toStringShort())
- << " planSummary: " << Explain::getPlanSummary(child().get())
- << " status: " << redact(statusObj);
+ LOGV2_DEBUG(20579,
+ 1,
+ "Execution of cached plan failed, falling back to replan. query: "
+ "{canonicalQuery_Short} planSummary: {Explain_getPlanSummary_child_get} "
+ "status: {statusObj}",
+ "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()),
+ "Explain_getPlanSummary_child_get"_attr =
+ Explain::getPlanSummary(child().get()),
+ "statusObj"_attr = redact(statusObj));
const bool shouldCache = false;
return replan(yieldPolicy,
@@ -158,11 +164,16 @@ Status CachedPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
// If we're here, the trial period took more than 'maxWorksBeforeReplan' work cycles. This
// plan is taking too long, so we replan from scratch.
- LOG(1) << "Execution of cached plan required " << maxWorksBeforeReplan
- << " works, but was originally cached with only " << _decisionWorks
- << " works. Evicting cache entry and replanning query: "
- << redact(_canonicalQuery->toStringShort())
- << " plan summary before replan: " << Explain::getPlanSummary(child().get());
+ LOGV2_DEBUG(
+ 20580,
+ 1,
+ "Execution of cached plan required {maxWorksBeforeReplan} works, but was originally cached "
+ "with only {decisionWorks} works. Evicting cache entry and replanning query: "
+ "{canonicalQuery_Short} plan summary before replan: {Explain_getPlanSummary_child_get}",
+ "maxWorksBeforeReplan"_attr = maxWorksBeforeReplan,
+ "decisionWorks"_attr = _decisionWorks,
+ "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()),
+ "Explain_getPlanSummary_child_get"_attr = Explain::getPlanSummary(child().get()));
const bool shouldCache = true;
return replan(
@@ -222,11 +233,15 @@ Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache, s
_replannedQs = std::move(solutions.back());
solutions.pop_back();
- LOG(1)
- << "Replanning of query resulted in single query solution, which will not be cached. "
- << redact(_canonicalQuery->toStringShort())
- << " plan summary after replan: " << Explain::getPlanSummary(child().get())
- << " previous cache entry evicted: " << (shouldCache ? "yes" : "no");
+ LOGV2_DEBUG(
+ 20581,
+ 1,
+ "Replanning of query resulted in single query solution, which will not be cached. "
+ "{canonicalQuery_Short} plan summary after replan: {Explain_getPlanSummary_child_get} "
+ "previous cache entry evicted: {shouldCache_yes_no}",
+ "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()),
+ "Explain_getPlanSummary_child_get"_attr = Explain::getPlanSummary(child().get()),
+ "shouldCache_yes_no"_attr = (shouldCache ? "yes" : "no"));
return Status::OK();
}
@@ -255,9 +270,14 @@ Status CachedPlanStage::replan(PlanYieldPolicy* yieldPolicy, bool shouldCache, s
return pickBestPlanStatus;
}
- LOG(1) << "Replanning " << redact(_canonicalQuery->toStringShort())
- << " resulted in plan with summary: " << Explain::getPlanSummary(child().get())
- << ", which " << (shouldCache ? "has" : "has not") << " been written to the cache";
+ LOGV2_DEBUG(20582,
+ 1,
+ "Replanning {canonicalQuery_Short} resulted in plan with summary: "
+ "{Explain_getPlanSummary_child_get}, which {shouldCache_has_has_not} been written "
+ "to the cache",
+ "canonicalQuery_Short"_attr = redact(_canonicalQuery->toStringShort()),
+ "Explain_getPlanSummary_child_get"_attr = Explain::getPlanSummary(child().get()),
+ "shouldCache_has_has_not"_attr = (shouldCache ? "has" : "has not"));
return Status::OK();
}
@@ -302,12 +322,19 @@ void CachedPlanStage::updatePlanCache() {
PlanCache* cache = CollectionQueryInfo::get(collection()).getPlanCache();
Status fbs = cache->feedback(*_canonicalQuery, score);
if (!fbs.isOK()) {
- LOG(5) << _canonicalQuery->ns() << ": Failed to update cache with feedback: " << redact(fbs)
- << " - "
- << "(query: " << redact(_canonicalQuery->getQueryObj())
- << "; sort: " << _canonicalQuery->getQueryRequest().getSort()
- << "; projection: " << _canonicalQuery->getQueryRequest().getProj()
- << ") is no longer in plan cache.";
+ LOGV2_DEBUG(
+ 20583,
+ 5,
+ "{canonicalQuery_ns}: Failed to update cache with feedback: {fbs} - (query: "
+ "{canonicalQuery_getQueryObj}; sort: {canonicalQuery_getQueryRequest_getSort}; "
+ "projection: {canonicalQuery_getQueryRequest_getProj}) is no longer in plan cache.",
+ "canonicalQuery_ns"_attr = _canonicalQuery->ns(),
+ "fbs"_attr = redact(fbs),
+ "canonicalQuery_getQueryObj"_attr = redact(_canonicalQuery->getQueryObj()),
+ "canonicalQuery_getQueryRequest_getSort"_attr =
+ _canonicalQuery->getQueryRequest().getSort(),
+ "canonicalQuery_getQueryRequest_getProj"_attr =
+ _canonicalQuery->getQueryRequest().getProj());
}
}
diff --git a/src/mongo/db/exec/collection_scan.cpp b/src/mongo/db/exec/collection_scan.cpp
index 66711faadf6..987d3ea69f3 100644
--- a/src/mongo/db/exec/collection_scan.cpp
+++ b/src/mongo/db/exec/collection_scan.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/exec/working_set_common.h"
#include "mongo/db/repl/optime.h"
#include "mongo/db/storage/oplog_hack.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -173,7 +174,7 @@ PlanStage::StageState CollectionScan::doWork(WorkingSetID* out) {
boost::optional<RecordId> startLoc =
collection()->getRecordStore()->oplogStartHack(getOpCtx(), goal.getValue());
if (startLoc && !startLoc->isNull()) {
- LOG(3) << "Using direct oplog seek";
+ LOGV2_DEBUG(20584, 3, "Using direct oplog seek");
record = _cursor->seekExact(*startLoc);
}
}
diff --git a/src/mongo/db/exec/document_value/document_value_test.cpp b/src/mongo/db/exec/document_value/document_value_test.cpp
index d641b699ae5..2b7797affe6 100644
--- a/src/mongo/db/exec/document_value/document_value_test.cpp
+++ b/src/mongo/db/exec/document_value/document_value_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include <math.h>
#include "mongo/platform/basic.h"
@@ -41,6 +43,8 @@
#include "mongo/db/json.h"
#include "mongo/db/pipeline/field_path.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/logv2/log.h"
+#include "mongo/util/log.h"
namespace DocumentTests {
@@ -236,7 +240,7 @@ public:
// Remove the second field.
md.setField("b", Value());
- log() << md.peek().toString();
+ LOGV2(20585, "{md_peek}", "md_peek"_attr = md.peek().toString());
ASSERT_EQUALS(2U, md.peek().size());
ASSERT(md.peek()["b"].missing());
ASSERT_EQUALS("a", getNthField(md.peek(), 0).first.toString());
@@ -1915,7 +1919,7 @@ private:
assertComparison(expectedResult, fromBson(a), fromBson(b));
}
void assertComparison(int expectedResult, const Value& a, const Value& b) {
- mongo::unittest::log() << "testing " << a.toString() << " and " << b.toString();
+ LOGV2(20586, "testing {a} and {b}", "a"_attr = a.toString(), "b"_attr = b.toString());
// reflexivity
ASSERT_EQUALS(0, cmp(a, a));
diff --git a/src/mongo/db/exec/inclusion_projection_executor_test.cpp b/src/mongo/db/exec/inclusion_projection_executor_test.cpp
index e31e5867522..862675bc657 100644
--- a/src/mongo/db/exec/inclusion_projection_executor_test.cpp
+++ b/src/mongo/db/exec/inclusion_projection_executor_test.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/pipeline/dependencies.h"
#include "mongo/db/pipeline/expression_context_for_test.h"
#include "mongo/db/query/projection_parser.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -82,8 +83,11 @@ public:
base->run();
}
} catch (...) {
- log() << "exception while testing with allowFastPath=" << _allowFastPath
- << " and allowFallBackToDefault=" << AllowFallBackToDefault;
+ LOGV2(20587,
+ "exception while testing with allowFastPath={allowFastPath} and "
+ "allowFallBackToDefault={AllowFallBackToDefault}",
+ "allowFastPath"_attr = _allowFastPath,
+ "AllowFallBackToDefault"_attr = AllowFallBackToDefault);
throw;
}
}
diff --git a/src/mongo/db/exec/multi_plan.cpp b/src/mongo/db/exec/multi_plan.cpp
index 38805b4e31d..be859d79e1c 100644
--- a/src/mongo/db/exec/multi_plan.cpp
+++ b/src/mongo/db/exec/multi_plan.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/query/explain.h"
#include "mongo/db/query/plan_cache.h"
#include "mongo/db/query/plan_ranker.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -117,7 +118,7 @@ PlanStage::StageState MultiPlanStage::doWork(WorkingSetID* out) {
StageState state = bestPlan.root->work(out);
if (PlanStage::FAILURE == state && hasBackupPlan()) {
- LOG(5) << "Best plan errored out switching to backup";
+ LOGV2_DEBUG(20588, 5, "Best plan errored out switching to backup");
// Uncache the bad solution if we fall back
// on the backup solution.
//
@@ -138,7 +139,7 @@ PlanStage::StageState MultiPlanStage::doWork(WorkingSetID* out) {
}
if (hasBackupPlan() && PlanStage::ADVANCED == state) {
- LOG(5) << "Best plan had a blocking stage, became unblocked";
+ LOGV2_DEBUG(20589, 5, "Best plan had a blocking stage, became unblocked");
_backupPlanIdx = kNoSuchPlan;
}
@@ -250,15 +251,22 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
const auto& alreadyProduced = bestCandidate.results;
const auto& bestSolution = bestCandidate.solution;
- LOG(5) << "Winning solution:\n" << redact(bestSolution->toString());
- LOG(2) << "Winning plan: " << Explain::getPlanSummary(bestCandidate.root);
+ LOGV2_DEBUG(20590,
+ 5,
+ "Winning solution:\n{bestSolution}",
+ "bestSolution"_attr = redact(bestSolution->toString()));
+ LOGV2_DEBUG(20591,
+ 2,
+ "Winning plan: {Explain_getPlanSummary_bestCandidate_root}",
+ "Explain_getPlanSummary_bestCandidate_root"_attr =
+ Explain::getPlanSummary(bestCandidate.root));
_backupPlanIdx = kNoSuchPlan;
if (bestSolution->hasBlockingStage && (0 == alreadyProduced.size())) {
- LOG(5) << "Winner has blocking stage, looking for backup plan...";
+ LOGV2_DEBUG(20592, 5, "Winner has blocking stage, looking for backup plan...");
for (auto&& ix : candidateOrder) {
if (!_candidates[ix].solution->hasBlockingStage) {
- LOG(5) << "Candidate " << ix << " is backup child";
+ LOGV2_DEBUG(20593, 5, "Candidate {ix} is backup child", "ix"_attr = ix);
_backupPlanIdx = ix;
break;
}
@@ -286,12 +294,20 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
size_t winnerIdx = ranking->candidateOrder[0];
size_t runnerUpIdx = ranking->candidateOrder[1];
- LOG(1) << "Winning plan tied with runner-up. Not caching."
- << " query: " << redact(_query->toStringShort())
- << " winner score: " << ranking->scores[0]
- << " winner summary: " << Explain::getPlanSummary(_candidates[winnerIdx].root)
- << " runner-up score: " << ranking->scores[1] << " runner-up summary: "
- << Explain::getPlanSummary(_candidates[runnerUpIdx].root);
+ LOGV2_DEBUG(20594,
+ 1,
+ "Winning plan tied with runner-up. Not caching. query: {query_Short} "
+ "winner score: {ranking_scores_0} winner summary: "
+ "{Explain_getPlanSummary_candidates_winnerIdx_root} runner-up score: "
+ "{ranking_scores_1} runner-up summary: "
+ "{Explain_getPlanSummary_candidates_runnerUpIdx_root}",
+ "query_Short"_attr = redact(_query->toStringShort()),
+ "ranking_scores_0"_attr = ranking->scores[0],
+ "Explain_getPlanSummary_candidates_winnerIdx_root"_attr =
+ Explain::getPlanSummary(_candidates[winnerIdx].root),
+ "ranking_scores_1"_attr = ranking->scores[1],
+ "Explain_getPlanSummary_candidates_runnerUpIdx_root"_attr =
+ Explain::getPlanSummary(_candidates[runnerUpIdx].root));
}
if (alreadyProduced.empty()) {
@@ -300,10 +316,15 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
canCache = false;
size_t winnerIdx = ranking->candidateOrder[0];
- LOG(1) << "Winning plan had zero results. Not caching."
- << " query: " << redact(_query->toStringShort())
- << " winner score: " << ranking->scores[0]
- << " winner summary: " << Explain::getPlanSummary(_candidates[winnerIdx].root);
+ LOGV2_DEBUG(20595,
+ 1,
+ "Winning plan had zero results. Not caching. query: {query_Short} winner "
+ "score: {ranking_scores_0} winner summary: "
+ "{Explain_getPlanSummary_candidates_winnerIdx_root}",
+ "query_Short"_attr = redact(_query->toStringShort()),
+ "ranking_scores_0"_attr = ranking->scores[0],
+ "Explain_getPlanSummary_candidates_winnerIdx_root"_attr =
+ Explain::getPlanSummary(_candidates[winnerIdx].root));
}
}
@@ -329,8 +350,11 @@ Status MultiPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
bool validSolutions = true;
for (size_t ix = 0; ix < solutions.size(); ++ix) {
if (nullptr == solutions[ix]->cacheData.get()) {
- LOG(5) << "Not caching query because this solution has no cache data: "
- << redact(solutions[ix]->toString());
+ LOGV2_DEBUG(
+ 20596,
+ 5,
+ "Not caching query because this solution has no cache data: {solutions_ix}",
+ "solutions_ix"_attr = redact(solutions[ix]->toString()));
validSolutions = false;
break;
}
diff --git a/src/mongo/db/exec/projection_executor_builder_test.cpp b/src/mongo/db/exec/projection_executor_builder_test.cpp
index c89235aeb6b..ecdd29d44fc 100644
--- a/src/mongo/db/exec/projection_executor_builder_test.cpp
+++ b/src/mongo/db/exec/projection_executor_builder_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/query/collation/collator_interface_mock.h"
#include "mongo/db/query/projection_ast_util.h"
#include "mongo/db/query/projection_parser.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -64,8 +65,11 @@ public:
_allowFastPath = false;
base->run();
} catch (...) {
- log() << "exception while testing with allowFastPath=" << _allowFastPath
- << " and allowFallBackToDefault=" << AllowFallBackToDefault;
+ LOGV2(20597,
+ "exception while testing with allowFastPath={allowFastPath} and "
+ "allowFallBackToDefault={AllowFallBackToDefault}",
+ "allowFastPath"_attr = _allowFastPath,
+ "AllowFallBackToDefault"_attr = AllowFallBackToDefault);
throw;
}
}
diff --git a/src/mongo/db/exec/subplan.cpp b/src/mongo/db/exec/subplan.cpp
index c6fc9991185..dc9b66466b8 100644
--- a/src/mongo/db/exec/subplan.cpp
+++ b/src/mongo/db/exec/subplan.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/query/query_planner.h"
#include "mongo/db/query/query_planner_common.h"
#include "mongo/db/query/stage_builder.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
#include "mongo/util/transitional_tools_do_not_use/vector_spooling.h"
@@ -111,7 +112,7 @@ Status SubplanStage::planSubqueries() {
const auto insertionRes = _indexMap.insert(std::make_pair(ie.identifier, i));
// Be sure the key was not already in the map.
invariant(insertionRes.second);
- LOG(5) << "Subplanner: index " << i << " is " << ie;
+ LOGV2_DEBUG(20598, 5, "Subplanner: index {i} is {ie}", "i"_attr = i, "ie"_attr = ie);
}
for (size_t i = 0; i < _orExpression->numChildren(); ++i) {
@@ -141,8 +142,12 @@ Status SubplanStage::planSubqueries() {
auto planCacheKey = planCache->computeKey(*branchResult->canonicalQuery);
if (auto cachedSol = planCache->getCacheEntryIfActive(planCacheKey)) {
// We have a CachedSolution. Store it for later.
- LOG(5) << "Subplanner: cached plan found for child " << i << " of "
- << _orExpression->numChildren();
+ LOGV2_DEBUG(
+ 20599,
+ 5,
+ "Subplanner: cached plan found for child {i} of {orExpression_numChildren}",
+ "i"_attr = i,
+ "orExpression_numChildren"_attr = _orExpression->numChildren());
branchResult->cachedSolution = std::move(cachedSol);
}
@@ -150,7 +155,11 @@ Status SubplanStage::planSubqueries() {
if (!branchResult->cachedSolution) {
// No CachedSolution found. We'll have to plan from scratch.
- LOG(5) << "Subplanner: planning child " << i << " of " << _orExpression->numChildren();
+ LOGV2_DEBUG(20600,
+ 5,
+ "Subplanner: planning child {i} of {orExpression_numChildren}",
+ "i"_attr = i,
+ "orExpression_numChildren"_attr = _orExpression->numChildren());
// We don't set NO_TABLE_SCAN because peeking at the cache data will keep us from
// considering any plan that's a collscan.
@@ -164,7 +173,10 @@ Status SubplanStage::planSubqueries() {
}
branchResult->solutions = std::move(solutions.getValue());
- LOG(5) << "Subplanner: got " << branchResult->solutions.size() << " solutions";
+ LOGV2_DEBUG(20601,
+ 5,
+ "Subplanner: got {branchResult_solutions_size} solutions",
+ "branchResult_solutions_size"_attr = branchResult->solutions.size());
}
}
@@ -329,7 +341,10 @@ Status SubplanStage::choosePlanForSubqueries(PlanYieldPolicy* yieldPolicy) {
return Status(ErrorCodes::NoQueryExecutionPlans, ss);
}
- LOG(5) << "Subplanner: fully tagged tree is " << redact(solnRoot->toString());
+ LOGV2_DEBUG(20602,
+ 5,
+ "Subplanner: fully tagged tree is {solnRoot}",
+ "solnRoot"_attr = redact(solnRoot->toString()));
_compositeSolution =
QueryPlannerAnalysis::analyzeDataAccess(*_query, _plannerParams, std::move(solnRoot));
@@ -340,7 +355,10 @@ Status SubplanStage::choosePlanForSubqueries(PlanYieldPolicy* yieldPolicy) {
return Status(ErrorCodes::NoQueryExecutionPlans, ss);
}
- LOG(5) << "Subplanner: Composite solution is " << redact(_compositeSolution->toString());
+ LOGV2_DEBUG(20603,
+ 5,
+ "Subplanner: Composite solution is {compositeSolution}",
+ "compositeSolution"_attr = redact(_compositeSolution->toString()));
// Use the index tags from planning each branch to construct the composite solution,
// and set that solution as our child stage.
diff --git a/src/mongo/db/exec/trial_stage.cpp b/src/mongo/db/exec/trial_stage.cpp
index 1e5b36fb7c4..4220631d974 100644
--- a/src/mongo/db/exec/trial_stage.cpp
+++ b/src/mongo/db/exec/trial_stage.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/exec/or.h"
#include "mongo/db/exec/queued_data_stage.h"
#include "mongo/db/exec/working_set_common.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -145,7 +146,10 @@ PlanStage::StageState TrialStage::_workTrialPlan(WorkingSetID* out) {
// Either of these cause us to immediately end the trial phase and switch to the backup.
auto statusDoc = WorkingSetCommon::getStatusMemberDocument(*_ws, *out);
BSONObj statusObj = statusDoc ? statusDoc->toBson() : BSONObj();
- LOG(1) << "Trial plan failed; switching to backup plan. Status: " << redact(statusObj);
+ LOGV2_DEBUG(20604,
+ 1,
+ "Trial plan failed; switching to backup plan. Status: {statusObj}",
+ "statusObj"_attr = redact(statusObj));
_specificStats.trialCompleted = true;
_replaceCurrentPlan(_backupPlan);
*out = WorkingSet::INVALID_ID;
diff --git a/src/mongo/db/exec/update_stage.cpp b/src/mongo/db/exec/update_stage.cpp
index 2ded1a54e58..6ff31d7bf77 100644
--- a/src/mongo/db/exec/update_stage.cpp
+++ b/src/mongo/db/exec/update_stage.cpp
@@ -52,6 +52,7 @@
#include "mongo/db/storage/duplicate_key_error_info.h"
#include "mongo/db/update/path_support.h"
#include "mongo/db/update/storage_validation.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/shard_key_pattern.h"
#include "mongo/s/would_change_owning_shard_exception.h"
#include "mongo/util/assert_util.h"
@@ -735,7 +736,7 @@ bool UpdateStage::checkUpdateChangesShardKeyFields(ScopedCollectionMetadata meta
if (!metadata->keyBelongsToMe(newShardKey)) {
if (MONGO_unlikely(hangBeforeThrowWouldChangeOwningShard.shouldFail())) {
- log() << "Hit hangBeforeThrowWouldChangeOwningShard failpoint";
+ LOGV2(20605, "Hit hangBeforeThrowWouldChangeOwningShard failpoint");
hangBeforeThrowWouldChangeOwningShard.pauseWhileSet(getOpCtx());
}
diff --git a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp
index 6b33f660d87..677f5ec18b3 100644
--- a/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp
+++ b/src/mongo/db/exhaust_cursor_currentop_integration_test.cpp
@@ -27,15 +27,19 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/client/dbclient_connection.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/db/query/cursor_response.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/stdx/future.h"
#include "mongo/unittest/integration_test.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
#include "mongo/util/system_clock_source.h"
namespace mongo {
@@ -114,9 +118,12 @@ bool confirmCurrentOpContents(DBClientBase* conn,
sleepFor(intervalMS);
}
auto currentOp = BSON("currentOp" << BSON("idleCursors" << true));
- unittest::log()
- << "confirmCurrentOpContents fails with curOpMatch: " << curOpMatch << " currentOp: "
- << conn->runCommand(OpMsgRequest::fromDBAndBody("admin", currentOp))->getCommandReply();
+ LOGV2(20606,
+ "confirmCurrentOpContents fails with curOpMatch: {curOpMatch} currentOp: "
+ "{conn_runCommand_OpMsgRequest_fromDBAndBody_admin_currentOp_getCommandReply}",
+ "curOpMatch"_attr = curOpMatch,
+ "conn_runCommand_OpMsgRequest_fromDBAndBody_admin_currentOp_getCommandReply"_attr =
+ conn->runCommand(OpMsgRequest::fromDBAndBody("admin", currentOp))->getCommandReply());
return false;
}
@@ -167,7 +174,9 @@ auto startExhaustQuery(
sleepFor(Milliseconds(10));
}
ASSERT(queryCursor);
- unittest::log() << "Started exhaust query with cursorId: " << queryCursor->getCursorId();
+ LOGV2(20607,
+ "Started exhaust query with cursorId: {queryCursor_getCursorId}",
+ "queryCursor_getCursorId"_attr = queryCursor->getCursorId());
return queryThread;
}
@@ -286,7 +295,7 @@ void testClientDisconnect(bool disconnectAfterGetMoreBatch) {
// Kill the client connection while the exhaust getMore is blocked on the failpoint.
queryConnection->shutdownAndDisallowReconnect();
- unittest::log() << "Killed exhaust connection.";
+ LOGV2(20608, "Killed exhaust connection.");
if (disconnectAfterGetMoreBatch) {
// Disable the failpoint to allow the exhaust getMore to continue sending out the response
diff --git a/src/mongo/db/free_mon/free_mon_controller.cpp b/src/mongo/db/free_mon/free_mon_controller.cpp
index a9de7ca4c49..895a278a57b 100644
--- a/src/mongo/db/free_mon/free_mon_controller.cpp
+++ b/src/mongo/db/free_mon/free_mon_controller.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/ftdc/collector.h"
#include "mongo/logger/logstream_builder.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -167,7 +168,7 @@ void FreeMonController::start(RegistrationType registrationType,
void FreeMonController::stop() {
// Stop the agent
- log() << "Shutting down free monitoring";
+ LOGV2(20609, "Shutting down free monitoring");
{
stdx::lock_guard<Latch> lock(_mutex);
@@ -198,7 +199,9 @@ void FreeMonController::turnCrankForTest(size_t countMessagesToIgnore) {
invariant(_state == State::kStarted);
}
- log() << "Turning Crank: " << countMessagesToIgnore;
+ LOGV2(20610,
+ "Turning Crank: {countMessagesToIgnore}",
+ "countMessagesToIgnore"_attr = countMessagesToIgnore);
_processor->turnCrankForTest(countMessagesToIgnore);
}
diff --git a/src/mongo/db/free_mon/free_mon_controller_test.cpp b/src/mongo/db/free_mon/free_mon_controller_test.cpp
index 296b3700b93..afb05e22f9f 100644
--- a/src/mongo/db/free_mon/free_mon_controller_test.cpp
+++ b/src/mongo/db/free_mon/free_mon_controller_test.cpp
@@ -62,6 +62,7 @@
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/executor/network_interface_mock.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/object_check.h"
#include "mongo/unittest/barrier.h"
#include "mongo/unittest/temp_dir.h"
@@ -245,7 +246,7 @@ public:
Future<FreeMonRegistrationResponse> sendRegistrationAsync(
const FreeMonRegistrationRequest& req) final {
- log() << "Sending Registration ...";
+ LOGV2(20611, "Sending Registration ...");
_registers.addAndFetch(1);
@@ -291,7 +292,7 @@ public:
Future<FreeMonMetricsResponse> sendMetricsAsync(const FreeMonMetricsRequest& req) final {
- log() << "Sending Metrics ...";
+ LOGV2(20612, "Sending Metrics ...");
_metrics.addAndFetch(1);
@@ -508,8 +509,8 @@ TEST(FreeMonRetryTest, TestRegistration) {
// If jitter is large as possible, we'd expect trueMin increments before false.
const auto trueMin = characterizeJitter(Seconds{9}, Seconds{119});
- // unittest::log() << "trueMin:" << trueMin;
- // unittest::log() << "trueMax:" << trueMax;
+ // LOGV2(20613, "trueMin:{trueMin}", "trueMin"_attr = trueMin);
+ // LOGV2(20614, "trueMax:{trueMax}", "trueMax"_attr = trueMax);
for (int j = 0; j < 30; j++) {
// std::cout << "j: " << j << "\n";
diff --git a/src/mongo/db/free_mon/free_mon_processor.cpp b/src/mongo/db/free_mon/free_mon_processor.cpp
index 8cb57bda42f..469488ba029 100644
--- a/src/mongo/db/free_mon/free_mon_processor.cpp
+++ b/src/mongo/db/free_mon/free_mon_processor.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/free_mon/free_mon_storage.h"
#include "mongo/db/service_context.h"
#include "mongo/idl/idl_parser.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -259,9 +260,11 @@ void FreeMonProcessor::run() {
// Stop the queue
_queue.stop();
- warning() << "Uncaught exception in '" << exceptionToStatus()
- << "' in free monitoring subsystem. Shutting down the "
- "free monitoring subsystem.";
+ LOGV2_WARNING(20619,
+ "Uncaught exception in '{exceptionToStatus}' in free monitoring subsystem. "
+ "Shutting down the "
+ "free monitoring subsystem.",
+ "exceptionToStatus"_attr = exceptionToStatus());
}
}
@@ -600,7 +603,7 @@ void FreeMonProcessor::doAsyncRegisterComplete(
Status s = validateRegistrationResponse(resp);
if (!s.isOK()) {
- warning() << "Free Monitoring registration halted due to " << s;
+ LOGV2_WARNING(20620, "Free Monitoring registration halted due to {s}", "s"_attr = s);
// Disable on any error
_state->setState(StorageStateEnum::disabled);
@@ -646,7 +649,9 @@ void FreeMonProcessor::doAsyncRegisterComplete(
// Notify waiters
notifyPendingRegisters(Status::OK());
- log() << "Free Monitoring is Enabled. Frequency: " << resp.getReportingInterval() << " seconds";
+ LOGV2(20615,
+ "Free Monitoring is Enabled. Frequency: {resp_getReportingInterval} seconds",
+ "resp_getReportingInterval"_attr = resp.getReportingInterval());
// Enqueue next metrics upload immediately to deliver a good experience
enqueue(FreeMonMessage::createNow(FreeMonMessageType::MetricsSend));
@@ -666,12 +671,16 @@ void FreeMonProcessor::doAsyncRegisterFail(
if (!_registrationRetry->incrementError()) {
// We have exceeded our retry
- warning() << "Free Monitoring is abandoning registration after excess retries";
+ LOGV2_WARNING(20621, "Free Monitoring is abandoning registration after excess retries");
return;
}
- LOG(1) << "Free Monitoring Registration Failed with status '" << msg->getPayload()
- << "', retrying in " << _registrationRetry->getNextDuration();
+ LOGV2_DEBUG(20616,
+ 1,
+ "Free Monitoring Registration Failed with status '{msg_getPayload}', retrying in "
+ "{registrationRetry_getNextDuration}",
+ "msg_getPayload"_attr = msg->getPayload(),
+ "registrationRetry_getNextDuration"_attr = _registrationRetry->getNextDuration());
// Enqueue a register retry
enqueue(FreeMonRegisterCommandMessage::createWithDeadline(
@@ -688,7 +697,7 @@ void FreeMonProcessor::doCommandUnregister(
writeState(client);
- log() << "Free Monitoring is Disabled";
+ LOGV2(20617, "Free Monitoring is Disabled");
msg->setStatus(Status::OK());
}
@@ -778,7 +787,7 @@ void FreeMonProcessor::doAsyncMetricsComplete(
Status s = validateMetricsResponse(resp);
if (!s.isOK()) {
- warning() << "Free Monitoring metrics uploading halted due to " << s;
+ LOGV2_WARNING(20622, "Free Monitoring metrics uploading halted due to {s}", "s"_attr = s);
// Disable free monitoring on validation errors
_state->setState(StorageStateEnum::disabled);
@@ -851,12 +860,16 @@ void FreeMonProcessor::doAsyncMetricsFail(
if (!_metricsRetry->incrementError()) {
// We have exceeded our retry
- warning() << "Free Monitoring is abandoning metrics upload after excess retries";
+ LOGV2_WARNING(20623, "Free Monitoring is abandoning metrics upload after excess retries");
return;
}
- LOG(1) << "Free Monitoring Metrics upload failed with status " << msg->getPayload()
- << ", retrying in " << _metricsRetry->getNextDuration();
+ LOGV2_DEBUG(20618,
+ 1,
+ "Free Monitoring Metrics upload failed with status {msg_getPayload}, retrying in "
+ "{metricsRetry_getNextDuration}",
+ "msg_getPayload"_attr = msg->getPayload(),
+ "metricsRetry_getNextDuration"_attr = _metricsRetry->getNextDuration());
// Enqueue next metrics upload
enqueue(FreeMonMessage::createWithDeadline(FreeMonMessageType::MetricsSend,
@@ -948,9 +961,11 @@ void FreeMonProcessor::doNotifyOnUpsert(
// Stop the queue
_queue.stop();
- warning() << "Uncaught exception in '" << exceptionToStatus()
- << "' in free monitoring op observer. Shutting down the "
- "free monitoring subsystem.";
+ LOGV2_WARNING(20624,
+ "Uncaught exception in '{exceptionToStatus}' in free monitoring op observer. "
+ "Shutting down the "
+ "free monitoring subsystem.",
+ "exceptionToStatus"_attr = exceptionToStatus());
}
}
diff --git a/src/mongo/db/ftdc/controller.cpp b/src/mongo/db/ftdc/controller.cpp
index 937fe0dbc7d..47acae27edf 100644
--- a/src/mongo/db/ftdc/controller.cpp
+++ b/src/mongo/db/ftdc/controller.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/ftdc/collector.h"
#include "mongo/db/ftdc/util.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/stdx/thread.h"
@@ -137,8 +138,9 @@ BSONObj FTDCController::getMostRecentPeriodicDocument() {
}
void FTDCController::start() {
- log() << "Initializing full-time diagnostic data capture with directory '"
- << _path.generic_string() << "'";
+ LOGV2(20625,
+ "Initializing full-time diagnostic data capture with directory '{path_generic_string}'",
+ "path_generic_string"_attr = _path.generic_string());
// Start the thread
_thread = stdx::thread([this] { doLoop(); });
@@ -152,7 +154,7 @@ void FTDCController::start() {
}
void FTDCController::stop() {
- log() << "Shutting down full-time diagnostic data capture";
+ LOGV2(20626, "Shutting down full-time diagnostic data capture");
{
stdx::lock_guard<Latch> lock(_mutex);
@@ -180,7 +182,9 @@ void FTDCController::stop() {
if (_mgr) {
auto s = _mgr->close();
if (!s.isOK()) {
- log() << "Failed to close full-time diagnostic data capture file manager: " << s;
+ LOGV2(20627,
+ "Failed to close full-time diagnostic data capture file manager: {s}",
+ "s"_attr = s);
}
}
}
diff --git a/src/mongo/db/ftdc/file_manager.cpp b/src/mongo/db/ftdc/file_manager.cpp
index 61ac60fcc48..783e9793c55 100644
--- a/src/mongo/db/ftdc/file_manager.cpp
+++ b/src/mongo/db/ftdc/file_manager.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/ftdc/constants.h"
#include "mongo/db/ftdc/file_reader.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -227,8 +228,12 @@ Status FTDCFileManager::trimDirectory(std::vector<boost::filesystem::path>& file
size += fileSize;
if (size >= maxSize) {
- LOG(1) << "Cleaning file over full-time diagnostic data capture quota, file: "
- << (*it).generic_string() << " with size " << fileSize;
+ LOGV2_DEBUG(20628,
+ 1,
+ "Cleaning file over full-time diagnostic data capture quota, file: "
+ "{it_generic_string} with size {fileSize}",
+ "it_generic_string"_attr = (*it).generic_string(),
+ "fileSize"_attr = fileSize);
boost::filesystem::remove(*it, ec);
if (ec) {
@@ -257,8 +262,9 @@ FTDCFileManager::recoverInterimFile() {
boost::system::error_code ec;
size_t size = boost::filesystem::file_size(interimFile, ec);
if (ec) {
- log() << "Recover interim file failed as the file size could not be checked: "
- << ec.message();
+ LOGV2(20629,
+ "Recover interim file failed as the file size could not be checked: {ec_message}",
+ "ec_message"_attr = ec.message());
return docs;
}
@@ -269,11 +275,12 @@ FTDCFileManager::recoverInterimFile() {
FTDCFileReader read;
auto s = read.open(interimFile);
if (!s.isOK()) {
- log() << "Unclean full-time diagnostic data capture shutdown detected, found interim file, "
- "but failed "
- "to open it, some "
- "metrics may have been lost. "
- << s;
+ LOGV2(20630,
+ "Unclean full-time diagnostic data capture shutdown detected, found interim file, "
+ "but failed "
+ "to open it, some "
+ "metrics may have been lost. {s}",
+ "s"_attr = s);
// Note: We ignore any actual errors as reading from the interim files is a best-effort
return docs;
@@ -288,10 +295,11 @@ FTDCFileManager::recoverInterimFile() {
// Warn if the interim file was corrupt or we had an unclean shutdown
if (!m.isOK() || !docs.empty()) {
- log() << "Unclean full-time diagnostic data capture shutdown detected, found interim file, "
- "some "
- "metrics may have been lost. "
- << m.getStatus();
+ LOGV2(20631,
+ "Unclean full-time diagnostic data capture shutdown detected, found interim file, "
+ "some "
+ "metrics may have been lost. {m_getStatus}",
+ "m_getStatus"_attr = m.getStatus());
}
// Note: We ignore any actual errors as reading from the interim files is a best-effort
diff --git a/src/mongo/db/ftdc/file_manager_test.cpp b/src/mongo/db/ftdc/file_manager_test.cpp
index a6cf6c6b38c..c8fba1ddd2c 100644
--- a/src/mongo/db/ftdc/file_manager_test.cpp
+++ b/src/mongo/db/ftdc/file_manager_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <algorithm>
@@ -46,8 +48,10 @@
#include "mongo/db/ftdc/file_writer.h"
#include "mongo/db/ftdc/ftdc_test.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace mongo {
@@ -111,7 +115,10 @@ TEST_F(FTDCFileManagerTest, TestFull) {
for (auto& file : files) {
int fs = boost::filesystem::file_size(file);
ASSERT_TRUE(fs < c.maxFileSizeBytes * 1.10);
- unittest::log() << "File " << file.generic_string() << " has size " << fs;
+ LOGV2(20632,
+ "File {file_generic_string} has size {fs}",
+ "file_generic_string"_attr = file.generic_string(),
+ "fs"_attr = fs);
if (file.generic_string().find("interim") == std::string::npos) {
sum += fs;
}
diff --git a/src/mongo/db/ftdc/util.cpp b/src/mongo/db/ftdc/util.cpp
index 9500bf62ecb..a1442ec8b6f 100644
--- a/src/mongo/db/ftdc/util.cpp
+++ b/src/mongo/db/ftdc/util.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/ftdc/constants.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -180,8 +181,10 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc,
while (itCurrent.more()) {
// Schema mismatch if current document is longer than reference document
if (matches && !itReference.more()) {
- LOG(4) << "full-time diagnostic data capture schema change: currrent document is "
- "longer than reference document";
+ LOGV2_DEBUG(20633,
+ 4,
+ "full-time diagnostic data capture schema change: currrent document is "
+ "longer than reference document");
matches = false;
}
@@ -191,10 +194,15 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc,
if (matches) {
// Check for matching field names
if (referenceElement.fieldNameStringData() != currentElement.fieldNameStringData()) {
- LOG(4)
- << "full-time diagnostic data capture schema change: field name change - from '"
- << referenceElement.fieldNameStringData() << "' to '"
- << currentElement.fieldNameStringData() << "'";
+ LOGV2_DEBUG(20634,
+ 4,
+ "full-time diagnostic data capture schema change: field name change - "
+ "from '{referenceElement_fieldNameStringData}' to "
+ "'{currentElement_fieldNameStringData}'",
+ "referenceElement_fieldNameStringData"_attr =
+ referenceElement.fieldNameStringData(),
+ "currentElement_fieldNameStringData"_attr =
+ currentElement.fieldNameStringData());
matches = false;
}
@@ -205,11 +213,19 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc,
if ((currentElement.type() != referenceElement.type()) &&
!(referenceElement.isNumber() == true &&
currentElement.isNumber() == referenceElement.isNumber())) {
- LOG(4) << "full-time diagnostic data capture schema change: field type change for "
- "field '"
- << referenceElement.fieldNameStringData() << "' from '"
- << static_cast<int>(referenceElement.type()) << "' to '"
- << static_cast<int>(currentElement.type()) << "'";
+ LOGV2_DEBUG(
+ 20635,
+ 4,
+ "full-time diagnostic data capture schema change: field type change for "
+ "field '{referenceElement_fieldNameStringData}' from "
+ "'{static_cast_int_referenceElement_type}' to "
+ "'{static_cast_int_currentElement_type}'",
+ "referenceElement_fieldNameStringData"_attr =
+ referenceElement.fieldNameStringData(),
+ "static_cast_int_referenceElement_type"_attr =
+ static_cast<int>(referenceElement.type()),
+ "static_cast_int_currentElement_type"_attr =
+ static_cast<int>(currentElement.type()));
matches = false;
}
}
@@ -261,8 +277,10 @@ StatusWith<bool> extractMetricsFromDocument(const BSONObj& referenceDoc,
// schema mismatch if ref is longer than curr
if (matches && itReference.more()) {
- LOG(4) << "full-time diagnostic data capture schema change: reference document is longer "
- "then current";
+ LOGV2_DEBUG(20636,
+ 4,
+ "full-time diagnostic data capture schema change: reference document is longer "
+ "then current");
matches = false;
}
diff --git a/src/mongo/db/geo/r2_region_coverer.cpp b/src/mongo/db/geo/r2_region_coverer.cpp
index 284350f62ab..c1c6b06c28d 100644
--- a/src/mongo/db/geo/r2_region_coverer.cpp
+++ b/src/mongo/db/geo/r2_region_coverer.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/geo/r2_region_coverer.h"
#include "mongo/db/geo/shapes.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -108,7 +109,10 @@ void R2RegionCoverer::getCovering(const R2Region& region, vector<GeoHash>* cover
Candidate* candidate = _candidateQueue->top().second; // Owned
_candidateQueue->pop();
// REDACT?? I think this may have User info, but I'm not sure how to redact
- LOG(3) << "Pop: " << redact(candidate->cell.toString());
+ LOGV2_DEBUG(20637,
+ 3,
+ "Pop: {candidate_cell}",
+ "candidate_cell"_attr = redact(candidate->cell.toString()));
// Try to expand this cell into its children
if (candidate->cell.getBits() < _minLevel || candidate->numChildren == 1 ||
@@ -123,7 +127,10 @@ void R2RegionCoverer::getCovering(const R2Region& region, vector<GeoHash>* cover
candidate->isTerminal = true;
addCandidate(candidate);
}
- LOG(3) << "Queue: " << _candidateQueue->size();
+ LOGV2_DEBUG(20638,
+ 3,
+ "Queue: {candidateQueue_size}",
+ "candidateQueue_size"_attr = _candidateQueue->size());
}
_region = nullptr;
@@ -185,7 +192,11 @@ void R2RegionCoverer::addCandidate(Candidate* candidate) {
numTerminals);
_candidateQueue->push(make_pair(priority, candidate)); // queue owns candidate
// REDACT??
- LOG(3) << "Push: " << redact(candidate->cell.toString()) << " (" << priority << ") ";
+ LOGV2_DEBUG(20639,
+ 3,
+ "Push: {candidate_cell} ({priority}) ",
+ "candidate_cell"_attr = redact(candidate->cell.toString()),
+ "priority"_attr = priority);
}
}
diff --git a/src/mongo/db/geo/r2_region_coverer_test.cpp b/src/mongo/db/geo/r2_region_coverer_test.cpp
index d569cb78ce1..394698b1d47 100644
--- a/src/mongo/db/geo/r2_region_coverer_test.cpp
+++ b/src/mongo/db/geo/r2_region_coverer_test.cpp
@@ -38,6 +38,7 @@
#include "mongo/base/init.h"
#include "mongo/bson/bsonmisc.h"
#include "mongo/db/geo/geometry_container.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -58,7 +59,7 @@ MONGO_INITIALIZER(R2CellUnion_Test)(InitializerContext* context) {
}
}
generator.seed(seed);
- log() << "R2CellUnion Test - Random Number Generator Seed: " << seed;
+ LOGV2(20640, "R2CellUnion Test - Random Number Generator Seed: {seed}", "seed"_attr = seed);
return Status::OK();
}
@@ -226,8 +227,8 @@ void checkCellIdCovering(const GeoHashConverter& converter,
// The covering doesn't contain this cell, so the region shouldn't contain this cell.
if (region.fastContains(cell)) {
- log() << "covering " << covering.toString();
- log() << "cellId " << cellId;
+ LOGV2(20641, "covering {covering}", "covering"_attr = covering.toString());
+ LOGV2(20642, "cellId {cellId}", "cellId"_attr = cellId);
}
ASSERT_FALSE(region.fastContains(cell));
@@ -726,8 +727,12 @@ TEST(R2CellUnion, Normalize) {
ASSERT_EQUALS(expected[i], cellUnion.cellIds()[i]);
}
}
- log() << "Average Unnormalized Size: " << unnormalizedSum * 1.0 / kIters;
- log() << "Average Normalized Size: " << normalizedSum * 1.0 / kIters;
+ LOGV2(20643,
+ "Average Unnormalized Size: {unnormalizedSum_1_0_kIters}",
+ "unnormalizedSum_1_0_kIters"_attr = unnormalizedSum * 1.0 / kIters);
+ LOGV2(20644,
+ "Average Normalized Size: {normalizedSum_1_0_kIters}",
+ "normalizedSum_1_0_kIters"_attr = normalizedSum * 1.0 / kIters);
}
void testContains(const R2CellUnion& cellUnion, GeoHash id, int num) {
diff --git a/src/mongo/db/index/2d_key_generator_test.cpp b/src/mongo/db/index/2d_key_generator_test.cpp
index 2745eb06b8a..88556e0b58e 100644
--- a/src/mongo/db/index/2d_key_generator_test.cpp
+++ b/src/mongo/db/index/2d_key_generator_test.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/index/2d_common.h"
#include "mongo/db/index/expression_params.h"
#include "mongo/db/json.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -61,14 +62,18 @@ std::string dumpKeyset(const KeyStringSet& keyStrings) {
bool assertKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) {
if (expectedKeys.size() != actualKeys.size()) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20645,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20646,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
diff --git a/src/mongo/db/index/btree_key_generator_test.cpp b/src/mongo/db/index/btree_key_generator_test.cpp
index 811c5d41bab..4607d217de4 100644
--- a/src/mongo/db/index/btree_key_generator_test.cpp
+++ b/src/mongo/db/index/btree_key_generator_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/db/json.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -137,15 +138,22 @@ bool testKeygen(const BSONObj& kp,
//
bool match = keysetsEqual(expectedKeys, actualKeys);
if (!match) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20647,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
match = (expectedMultikeyPaths == actualMultikeyPaths);
if (!match) {
- log() << "Expected: " << dumpMultikeyPaths(expectedMultikeyPaths) << ", "
- << "Actual: " << dumpMultikeyPaths(actualMultikeyPaths);
+ LOGV2(20648,
+ "Expected: {dumpMultikeyPaths_expectedMultikeyPaths}, Actual: "
+ "{dumpMultikeyPaths_actualMultikeyPaths}",
+ "dumpMultikeyPaths_expectedMultikeyPaths"_attr =
+ dumpMultikeyPaths(expectedMultikeyPaths),
+ "dumpMultikeyPaths_actualMultikeyPaths"_attr =
+ dumpMultikeyPaths(actualMultikeyPaths));
}
return match;
diff --git a/src/mongo/db/index/duplicate_key_tracker.cpp b/src/mongo/db/index/duplicate_key_tracker.cpp
index 9898415dfe4..fc1d3604f90 100644
--- a/src/mongo/db/index/duplicate_key_tracker.cpp
+++ b/src/mongo/db/index/duplicate_key_tracker.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/curop.h"
#include "mongo/db/index/index_access_method.h"
#include "mongo/db/keypattern.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -79,8 +80,13 @@ Status DuplicateKeyTracker::recordKeys(OperationContext* opCtx, const std::vecto
records.emplace_back(Record{RecordId(), RecordData(obj.objdata(), obj.objsize())});
}
- LOG(1) << "recording " << records.size() << " duplicate key conflicts on unique index: "
- << _indexCatalogEntry->descriptor()->indexName();
+ LOGV2_DEBUG(20676,
+ 1,
+ "recording {records_size} duplicate key conflicts on unique index: "
+ "{indexCatalogEntry_descriptor_indexName}",
+ "records_size"_attr = records.size(),
+ "indexCatalogEntry_descriptor_indexName"_attr =
+ _indexCatalogEntry->descriptor()->indexName());
WriteUnitOfWork wuow(opCtx);
std::vector<Timestamp> timestamps(records.size());
@@ -138,9 +144,13 @@ Status DuplicateKeyTracker::checkConstraints(OperationContext* opCtx) const {
invariant(resolved == _duplicateCounter.load());
int logLevel = (resolved > 0) ? 0 : 1;
- LOG(logLevel) << "index build: resolved " << resolved
- << " duplicate key conflicts for unique index: "
- << _indexCatalogEntry->descriptor()->indexName();
+ LOGV2_DEBUG(20677,
+ logSeverityV1toV2(logLevel).toInt(),
+ "index build: resolved {resolved} duplicate key conflicts for unique index: "
+ "{indexCatalogEntry_descriptor_indexName}",
+ "resolved"_attr = resolved,
+ "indexCatalogEntry_descriptor_indexName"_attr =
+ _indexCatalogEntry->descriptor()->indexName());
return Status::OK();
}
diff --git a/src/mongo/db/index/hash_key_generator_test.cpp b/src/mongo/db/index/hash_key_generator_test.cpp
index f2babba8cb4..c75e526ae47 100644
--- a/src/mongo/db/index/hash_key_generator_test.cpp
+++ b/src/mongo/db/index/hash_key_generator_test.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/hasher.h"
#include "mongo/db/json.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -64,14 +65,18 @@ std::string dumpKeyset(const KeyStringSet& keyStrings) {
bool assertKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) {
if (expectedKeys.size() != actualKeys.size()) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20678,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20679,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
diff --git a/src/mongo/db/index/haystack_access_method.cpp b/src/mongo/db/index/haystack_access_method.cpp
index e309dcaebed..98a04d22d89 100644
--- a/src/mongo/db/index/haystack_access_method.cpp
+++ b/src/mongo/db/index/haystack_access_method.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/index/haystack_access_method_internal.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/query/internal_plans.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -89,8 +90,12 @@ void HaystackAccessMethod::searchCommand(OperationContext* opCtx,
unsigned limit) const {
Timer t;
- LOG(1) << "SEARCH near:" << redact(nearObj) << " maxDistance:" << maxDistance
- << " search: " << redact(search);
+ LOGV2_DEBUG(20680,
+ 1,
+ "SEARCH near:{nearObj} maxDistance:{maxDistance} search: {search}",
+ "nearObj"_attr = redact(nearObj),
+ "maxDistance"_attr = maxDistance,
+ "search"_attr = redact(search));
int x, y;
{
BSONObjIterator i(nearObj);
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index cb325e1e6ab..f929b0f3ffa 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -52,6 +52,7 @@
#include "mongo/db/repl/timestamp_block.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/progress_meter.h"
#include "mongo/util/scopeguard.h"
@@ -113,7 +114,10 @@ bool AbstractIndexAccessMethod::isFatalError(OperationContext* opCtx,
// A document might be indexed multiple times during a background index build if it moves ahead
// of the cursor (e.g. via an update). We test this scenario and swallow the error accordingly.
if (status == ErrorCodes::DuplicateKeyValue && !_indexCatalogEntry->isReady(opCtx)) {
- LOG(3) << "KeyString " << key << " already in index during background indexing (ok)";
+ LOGV2_DEBUG(20681,
+ 3,
+ "KeyString {key} already in index during background indexing (ok)",
+ "key"_attr = key);
return false;
}
return true;
@@ -200,10 +204,16 @@ void AbstractIndexAccessMethod::removeOneKey(OperationContext* opCtx,
try {
_newInterface->unindex(opCtx, keyString, dupsAllowed);
} catch (AssertionException& e) {
- log() << "Assertion failure: _unindex failed on: " << _descriptor->parentNS()
- << " for index: " << _descriptor->indexName();
- log() << "Assertion failure: _unindex failed: " << redact(e) << " KeyString:" << keyString
- << " dl:" << loc;
+ LOGV2(20682,
+ "Assertion failure: _unindex failed on: {descriptor_parentNS} for index: "
+ "{descriptor_indexName}",
+ "descriptor_parentNS"_attr = _descriptor->parentNS(),
+ "descriptor_indexName"_attr = _descriptor->indexName());
+ LOGV2(20683,
+ "Assertion failure: _unindex failed: {e} KeyString:{keyString} dl:{loc}",
+ "e"_attr = redact(e),
+ "keyString"_attr = keyString,
+ "loc"_attr = loc);
logContext();
}
}
@@ -523,8 +533,13 @@ Status AbstractIndexAccessMethod::BulkBuilderImpl::insert(OperationContext* opCt
// index builder can retry at a point when data is consistent.
auto interceptor = _indexCatalogEntry->indexBuildInterceptor();
if (interceptor && interceptor->getSkippedRecordTracker()) {
- LOG(1) << "Recording suppressed key generation error to retry later: " << status
- << " on " << loc << ": " << redact(obj);
+ LOGV2_DEBUG(20684,
+ 1,
+ "Recording suppressed key generation error to retry later: "
+ "{status} on {loc}: {obj}",
+ "status"_attr = status,
+ "loc"_attr = loc,
+ "obj"_attr = redact(obj));
interceptor->getSkippedRecordTracker()->record(opCtx, loc);
}
});
@@ -618,9 +633,11 @@ Status AbstractIndexAccessMethod::commitBulk(OperationContext* opCtx,
if (kDebugBuild || _descriptor->unique()) {
cmpData = data.first.compareWithoutRecordId(previousKey);
if (cmpData < 0) {
- severe() << "expected the next key" << data.first.toString()
- << " to be greater than or equal to the previous key"
- << previousKey.toString();
+ LOGV2_FATAL(20687,
+ "expected the next key{data_first} to be greater than or equal to the "
+ "previous key{previousKey}",
+ "data_first"_attr = data.first.toString(),
+ "previousKey"_attr = previousKey.toString());
fassertFailedNoTrace(31171);
}
}
@@ -667,8 +684,11 @@ Status AbstractIndexAccessMethod::commitBulk(OperationContext* opCtx,
pm.finished();
- log() << "index build: inserted " << bulk->getKeysInserted()
- << " keys from external sorter into index in " << timer.seconds() << " seconds";
+ LOGV2(20685,
+ "index build: inserted {bulk_getKeysInserted} keys from external sorter into index in "
+ "{timer_seconds} seconds",
+ "bulk_getKeysInserted"_attr = bulk->getKeysInserted(),
+ "timer_seconds"_attr = timer.seconds());
WriteUnitOfWork wunit(opCtx);
builder->commit(true);
@@ -682,8 +702,13 @@ void AbstractIndexAccessMethod::setIndexIsMultikey(OperationContext* opCtx, Mult
IndexAccessMethod::OnSuppressedErrorFn IndexAccessMethod::kNoopOnSuppressedErrorFn =
[](Status status, const BSONObj& obj, boost::optional<RecordId> loc) {
- LOG(1) << "Suppressed key generation error: " << redact(status)
- << " when getting index keys for " << loc << ": " << redact(obj);
+ LOGV2_DEBUG(
+ 20686,
+ 1,
+ "Suppressed key generation error: {status} when getting index keys for {loc}: {obj}",
+ "status"_attr = redact(status),
+ "loc"_attr = loc,
+ "obj"_attr = redact(obj));
};
void AbstractIndexAccessMethod::getKeys(const BSONObj& obj,
diff --git a/src/mongo/db/index/index_access_method_factory_impl.cpp b/src/mongo/db/index/index_access_method_factory_impl.cpp
index 2eb06511d1b..bff506b0023 100644
--- a/src/mongo/db/index/index_access_method_factory_impl.cpp
+++ b/src/mongo/db/index/index_access_method_factory_impl.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/index/haystack_access_method.h"
#include "mongo/db/index/s2_access_method.h"
#include "mongo/db/index/wildcard_access_method.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -62,7 +63,9 @@ std::unique_ptr<IndexAccessMethod> IndexAccessMethodFactoryImpl::make(
return std::make_unique<TwoDAccessMethod>(entry, std::move(sortedDataInterface));
else if (IndexNames::WILDCARD == type)
return std::make_unique<WildcardAccessMethod>(entry, std::move(sortedDataInterface));
- log() << "Can't find index for keyPattern " << desc->keyPattern();
+ LOGV2(20688,
+ "Can't find index for keyPattern {desc_keyPattern}",
+ "desc_keyPattern"_attr = desc->keyPattern());
fassertFailed(31021);
}
diff --git a/src/mongo/db/index/index_build_interceptor.cpp b/src/mongo/db/index/index_build_interceptor.cpp
index 90de76f1be5..8ca9bf0fd20 100644
--- a/src/mongo/db/index/index_build_interceptor.cpp
+++ b/src/mongo/db/index/index_build_interceptor.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/multi_key_path_tracker.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/progress_meter.h"
@@ -268,10 +269,17 @@ Status IndexBuildInterceptor::drainWritesIntoIndex(OperationContext* opCtx,
progress->finished();
int logLevel = (_numApplied - appliedAtStart > 0) ? 0 : 1;
- LOG(logLevel) << "index build: drain applied " << (_numApplied - appliedAtStart)
- << " side writes (inserted: " << totalInserted << ", deleted: " << totalDeleted
- << ") for '" << _indexCatalogEntry->descriptor()->indexName() << "' in "
- << timer.millis() << " ms";
+ LOGV2_DEBUG(20689,
+ logSeverityV1toV2(logLevel).toInt(),
+ "index build: drain applied {numApplied_appliedAtStart} side writes (inserted: "
+ "{totalInserted}, deleted: {totalDeleted}) for "
+ "'{indexCatalogEntry_descriptor_indexName}' in {timer_millis} ms",
+ "numApplied_appliedAtStart"_attr = (_numApplied - appliedAtStart),
+ "totalInserted"_attr = totalInserted,
+ "totalDeleted"_attr = totalDeleted,
+ "indexCatalogEntry_descriptor_indexName"_attr =
+ _indexCatalogEntry->descriptor()->indexName(),
+ "timer_millis"_attr = timer.millis());
return Status::OK();
}
@@ -355,7 +363,7 @@ void IndexBuildInterceptor::_yield(OperationContext* opCtx) {
hangDuringIndexBuildDrainYield.executeIf(
[&](auto&&) {
- log() << "Hanging index build during drain yield";
+ LOGV2(20690, "Hanging index build during drain yield");
hangDuringIndexBuildDrainYield.pauseWhileSet();
},
[&](auto&& config) {
@@ -380,7 +388,7 @@ bool IndexBuildInterceptor::areAllWritesApplied(OperationContext* opCtx) const {
<< writesRecorded << ", applied: " << _numApplied;
dassert(writesRecorded == _numApplied, message);
- warning() << message;
+ LOGV2_WARNING(20692, "{message}", "message"_attr = message);
}
return true;
}
@@ -482,8 +490,13 @@ Status IndexBuildInterceptor::sideWrite(OperationContext* opCtx,
RecordData(doc.objdata(), doc.objsize())});
}
- LOG(2) << "recording " << records.size() << " side write keys on index '"
- << _indexCatalogEntry->descriptor()->indexName() << "'";
+ LOGV2_DEBUG(20691,
+ 2,
+ "recording {records_size} side write keys on index "
+ "'{indexCatalogEntry_descriptor_indexName}'",
+ "records_size"_attr = records.size(),
+ "indexCatalogEntry_descriptor_indexName"_attr =
+ _indexCatalogEntry->descriptor()->indexName());
// By passing a vector of null timestamps, these inserts are not timestamped individually, but
// rather with the timestamp of the owning operation.
diff --git a/src/mongo/db/index/s2_key_generator_test.cpp b/src/mongo/db/index/s2_key_generator_test.cpp
index 1a8432d0ff6..40ec009fcc3 100644
--- a/src/mongo/db/index/s2_key_generator_test.cpp
+++ b/src/mongo/db/index/s2_key_generator_test.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/index/s2_common.h"
#include "mongo/db/json.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -79,14 +80,18 @@ std::string dumpMultikeyPaths(const MultikeyPaths& multikeyPaths) {
bool areKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) {
if (expectedKeys.size() != actualKeys.size()) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20693,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20694,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
diff --git a/src/mongo/db/index/wildcard_key_generator_test.cpp b/src/mongo/db/index/wildcard_key_generator_test.cpp
index 4d5d7f9f3c1..4a3233caa04 100644
--- a/src/mongo/db/index/wildcard_key_generator_test.cpp
+++ b/src/mongo/db/index/wildcard_key_generator_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/bson/json.h"
#include "mongo/db/index/wildcard_key_generator.h"
#include "mongo/db/query/collation/collator_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -67,14 +68,18 @@ std::string dumpKeyset(const KeyStringSet& keyStrings) {
bool assertKeysetsEqual(const KeyStringSet& expectedKeys, const KeyStringSet& actualKeys) {
if (expectedKeys.size() != actualKeys.size()) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20695,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
if (!std::equal(expectedKeys.begin(), expectedKeys.end(), actualKeys.begin())) {
- log() << "Expected: " << dumpKeyset(expectedKeys) << ", "
- << "Actual: " << dumpKeyset(actualKeys);
+ LOGV2(20696,
+ "Expected: {dumpKeyset_expectedKeys}, Actual: {dumpKeyset_actualKeys}",
+ "dumpKeyset_expectedKeys"_attr = dumpKeyset(expectedKeys),
+ "dumpKeyset_actualKeys"_attr = dumpKeyset(actualKeys));
return false;
}
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index b18f136597a..629ccf6b2d3 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -56,6 +56,7 @@
#include "mongo/db/server_recovery.h"
#include "mongo/db/service_context.h"
#include "mongo/db/storage/durable_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/shard_key_pattern.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -255,8 +256,13 @@ void unlockRSTLForIndexCleanup(OperationContext* opCtx) {
void logFailure(Status status,
const NamespaceString& nss,
std::shared_ptr<ReplIndexBuildState> replState) {
- log() << "Index build failed: " << replState->buildUUID << ": " << nss << " ( "
- << replState->collectionUUID << " ): " << status;
+ LOGV2(
+ 20649,
+ "Index build failed: {replState_buildUUID}: {nss} ( {replState_collectionUUID} ): {status}",
+ "replState_buildUUID"_attr = replState->buildUUID,
+ "nss"_attr = nss,
+ "replState_collectionUUID"_attr = replState->collectionUUID,
+ "status"_attr = status);
}
/**
@@ -270,16 +276,26 @@ void forEachIndexBuild(
return;
}
- log() << logPrefix << "active index builds: " << indexBuilds.size();
+ LOGV2(20650,
+ "{logPrefix}active index builds: {indexBuilds_size}",
+ "logPrefix"_attr = logPrefix,
+ "indexBuilds_size"_attr = indexBuilds.size());
for (auto replState : indexBuilds) {
std::string indexNamesStr;
str::joinStringDelim(replState->indexNames, &indexNamesStr, ',');
- log() << logPrefix << replState->buildUUID << ": collection: " << replState->collectionUUID
- << "; indexes: " << replState->indexNames.size() << " [" << indexNamesStr
- << "]; method: "
- << (IndexBuildProtocol::kTwoPhase == replState->protocol ? "two phase"
- : "single phase");
+ LOGV2(20651,
+ "{logPrefix}{replState_buildUUID}: collection: {replState_collectionUUID}; indexes: "
+ "{replState_indexNames_size} [{indexNamesStr}]; method: "
+ "{IndexBuildProtocol_kTwoPhase_replState_protocol_two_phase_single_phase}",
+ "logPrefix"_attr = logPrefix,
+ "replState_buildUUID"_attr = replState->buildUUID,
+ "replState_collectionUUID"_attr = replState->collectionUUID,
+ "replState_indexNames_size"_attr = replState->indexNames.size(),
+ "indexNamesStr"_attr = indexNamesStr,
+ "IndexBuildProtocol_kTwoPhase_replState_protocol_two_phase_single_phase"_attr =
+ (IndexBuildProtocol::kTwoPhase == replState->protocol ? "two phase"
+ : "single phase"));
onIndexBuild(replState);
}
@@ -402,9 +418,11 @@ Status IndexBuildsCoordinator::_startIndexBuildForRecovery(OperationContext* opC
// after an abort has been rolled back.
if (!DurableCatalog::get(opCtx)->isIndexPresent(
opCtx, collection->getCatalogId(), indexNames[i])) {
- log() << "The index for build " << buildUUID
- << " was not found while trying to drop the index during recovery: "
- << indexNames[i];
+ LOGV2(20652,
+ "The index for build {buildUUID} was not found while trying to drop the "
+ "index during recovery: {indexNames_i}",
+ "buildUUID"_attr = buildUUID,
+ "indexNames_i"_attr = indexNames[i]);
continue;
}
@@ -583,11 +601,15 @@ void IndexBuildsCoordinator::applyCommitIndexBuild(OperationContext* opCtx,
// If the index build was not found, we must restart the build. For some reason the index
// build has already been aborted on this node. This is possible in certain infrequent race
// conditions with stepdown, shutdown, and user interruption.
- log() << "Could not find an active index build with UUID " << buildUUID
- << " while processing a commitIndexBuild oplog entry. Restarting the index build on "
- "collection "
- << nss << " (" << collUUID << ") at optime "
- << opCtx->recoveryUnit()->getCommitTimestamp();
+ LOGV2(20653,
+ "Could not find an active index build with UUID {buildUUID} while processing a "
+ "commitIndexBuild oplog entry. Restarting the index build on "
+ "collection {nss} ({collUUID}) at optime {opCtx_recoveryUnit_getCommitTimestamp}",
+ "buildUUID"_attr = buildUUID,
+ "nss"_attr = nss,
+ "collUUID"_attr = collUUID,
+ "opCtx_recoveryUnit_getCommitTimestamp"_attr =
+ opCtx->recoveryUnit()->getCommitTimestamp());
IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions;
indexBuildOptions.replSetAndNotPrimaryAtStart = true;
@@ -621,7 +643,10 @@ void IndexBuildsCoordinator::applyCommitIndexBuild(OperationContext* opCtx,
replState->condVar.notify_all();
}
auto fut = replState->sharedPromise.getFuture();
- log() << "Index build joined after commit: " << buildUUID << ": " << fut.waitNoThrow(opCtx);
+ LOGV2(20654,
+ "Index build joined after commit: {buildUUID}: {fut_waitNoThrow_opCtx}",
+ "buildUUID"_attr = buildUUID,
+ "fut_waitNoThrow_opCtx"_attr = fut.waitNoThrow(opCtx));
// Throws if there was an error building the index.
fut.get();
@@ -661,7 +686,10 @@ void IndexBuildsCoordinator::abortIndexBuildByBuildUUID(OperationContext* opCtx,
auto replState = invariant(_getIndexBuild(buildUUID));
auto fut = replState->sharedPromise.getFuture();
- log() << "Index build joined after abort: " << buildUUID << ": " << fut.waitNoThrow();
+ LOGV2(20655,
+ "Index build joined after abort: {buildUUID}: {fut_waitNoThrow}",
+ "buildUUID"_attr = buildUUID,
+ "fut_waitNoThrow"_attr = fut.waitNoThrow());
}
bool IndexBuildsCoordinator::abortIndexBuildByBuildUUIDNoWait(OperationContext* opCtx,
@@ -674,8 +702,10 @@ bool IndexBuildsCoordinator::abortIndexBuildByBuildUUIDNoWait(OperationContext*
// succeed, so suppress the error.
auto replStateResult = _getIndexBuild(buildUUID);
if (!replStateResult.isOK()) {
- log() << "ignoring error while aborting index build " << buildUUID << ": "
- << replStateResult.getStatus();
+ LOGV2(20656,
+ "ignoring error while aborting index build {buildUUID}: {replStateResult_getStatus}",
+ "buildUUID"_attr = buildUUID,
+ "replStateResult_getStatus"_attr = replStateResult.getStatus());
return false;
}
@@ -718,7 +748,7 @@ std::size_t IndexBuildsCoordinator::getActiveIndexBuildCount(OperationContext* o
}
void IndexBuildsCoordinator::onStepUp(OperationContext* opCtx) {
- log() << "IndexBuildsCoordinator::onStepUp - this node is stepping up to primary";
+ LOGV2(20657, "IndexBuildsCoordinator::onStepUp - this node is stepping up to primary");
auto indexBuilds = _getIndexBuilds();
auto onIndexBuild = [this, opCtx](std::shared_ptr<ReplIndexBuildState> replState) {
@@ -753,35 +783,37 @@ void IndexBuildsCoordinator::onStepUp(OperationContext* opCtx) {
}
IndexBuilds IndexBuildsCoordinator::onRollback(OperationContext* opCtx) {
- log() << "IndexBuildsCoordinator::onRollback - this node is entering the rollback state";
+ LOGV2(20658, "IndexBuildsCoordinator::onRollback - this node is entering the rollback state");
IndexBuilds buildsAborted;
auto indexBuilds = _getIndexBuilds();
- auto onIndexBuild = [this, opCtx, &buildsAborted](
- std::shared_ptr<ReplIndexBuildState> replState) {
- if (IndexBuildProtocol::kSinglePhase == replState->protocol) {
- log() << "IndexBuildsCoordinator::onRollback - not aborting single phase index build: "
- << replState->buildUUID;
- return;
- }
- const std::string reason = "rollback";
-
- IndexBuildDetails aborted{replState->collectionUUID};
- // Record the index builds aborted due to rollback. This allows any rollback algorithm
- // to efficiently restart all unfinished index builds without having to scan all indexes
- // in all collections.
- for (auto spec : replState->indexSpecs) {
- aborted.indexSpecs.emplace_back(spec.getOwned());
- }
- buildsAborted.insert({replState->buildUUID, aborted});
+ auto onIndexBuild =
+ [this, opCtx, &buildsAborted](std::shared_ptr<ReplIndexBuildState> replState) {
+ if (IndexBuildProtocol::kSinglePhase == replState->protocol) {
+ LOGV2(20659,
+ "IndexBuildsCoordinator::onRollback - not aborting single phase index build: "
+ "{replState_buildUUID}",
+ "replState_buildUUID"_attr = replState->buildUUID);
+ return;
+ }
+ const std::string reason = "rollback";
+
+ IndexBuildDetails aborted{replState->collectionUUID};
+ // Record the index builds aborted due to rollback. This allows any rollback algorithm
+ // to efficiently restart all unfinished index builds without having to scan all indexes
+ // in all collections.
+ for (auto spec : replState->indexSpecs) {
+ aborted.indexSpecs.emplace_back(spec.getOwned());
+ }
+ buildsAborted.insert({replState->buildUUID, aborted});
- // Leave abort timestamp as null. This will unblock the index build and allow it to
- // complete without cleaning up. Subsequently, the rollback algorithm can decide how to
- // undo the index build depending on the state of the oplog. Waits for index build
- // thread to exit.
- abortIndexBuildByBuildUUID(opCtx, replState->buildUUID, Timestamp(), reason);
- };
+ // Leave abort timestamp as null. This will unblock the index build and allow it to
+ // complete without cleaning up. Subsequently, the rollback algorithm can decide how to
+ // undo the index build depending on the state of the oplog. Waits for index build
+ // thread to exit.
+ abortIndexBuildByBuildUUID(opCtx, replState->buildUUID, Timestamp(), reason);
+ };
forEachIndexBuild(indexBuilds, "IndexBuildsCoordinator::onRollback - "_sd, onIndexBuild);
return buildsAborted;
}
@@ -793,8 +825,12 @@ void IndexBuildsCoordinator::restartIndexBuildsForRecovery(OperationContext* opC
CollectionCatalog::get(opCtx).lookupNSSByUUID(opCtx, build.collUUID);
invariant(nss);
- log() << "Restarting index build for collection: " << *nss
- << ", collection UUID: " << build.collUUID << ", index build UUID: " << buildUUID;
+ LOGV2(20660,
+ "Restarting index build for collection: {nss}, collection UUID: {build_collUUID}, "
+ "index build UUID: {buildUUID}",
+ "nss"_attr = *nss,
+ "build_collUUID"_attr = build.collUUID,
+ "buildUUID"_attr = buildUUID);
IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions;
// Start the index build as if in secondary oplog application.
@@ -1074,7 +1110,7 @@ Status IndexBuildsCoordinator::_registerIndexBuild(
}
}
std::string msg = ss;
- log() << msg;
+ LOGV2(20661, "{msg}", "msg"_attr = msg);
if (aborted) {
return {ErrorCodes::IndexBuildAborted, msg};
}
@@ -1304,7 +1340,8 @@ IndexBuildsCoordinator::PostSetupAction IndexBuildsCoordinator::_setUpIndexBuild
((status == ErrorCodes::IndexOptionsConflict ||
status == ErrorCodes::IndexKeySpecsConflict) &&
options.indexConstraints == IndexBuildsManager::IndexConstraints::kRelax)) {
- LOG(1) << "Ignoring indexing error: " << redact(status);
+ LOGV2_DEBUG(
+ 20662, 1, "Ignoring indexing error: {status}", "status"_attr = redact(status));
return PostSetupAction::kCompleteIndexBuildEarly;
}
@@ -1599,11 +1636,17 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
_indexBuildsManager.tearDownIndexBuild(
opCtx, collection, replState->buildUUID, MultiIndexBlock::kNoopOnCleanUpFn);
- log() << "Index build completed successfully: " << replState->buildUUID << ": " << nss
- << " ( " << replState->collectionUUID
- << " ). Index specs built: " << replState->indexSpecs.size()
- << ". Indexes in catalog before build: " << replState->stats.numIndexesBefore
- << ". Indexes in catalog after build: " << replState->stats.numIndexesAfter;
+ LOGV2(20663,
+ "Index build completed successfully: {replState_buildUUID}: {nss} ( "
+ "{replState_collectionUUID} ). Index specs built: {replState_indexSpecs_size}. "
+ "Indexes in catalog before build: {replState_stats_numIndexesBefore}. Indexes in "
+ "catalog after build: {replState_stats_numIndexesAfter}",
+ "replState_buildUUID"_attr = replState->buildUUID,
+ "nss"_attr = nss,
+ "replState_collectionUUID"_attr = replState->collectionUUID,
+ "replState_indexSpecs_size"_attr = replState->indexSpecs.size(),
+ "replState_stats_numIndexesBefore"_attr = replState->stats.numIndexesBefore,
+ "replState_stats_numIndexesAfter"_attr = replState->stats.numIndexesAfter);
return;
}
@@ -1678,9 +1721,11 @@ void IndexBuildsCoordinator::_buildIndexTwoPhase(
if (!replSetAndNotPrimary) {
throw;
}
- log() << "Index build failed before final phase during oplog application. "
- "Waiting for abort: "
- << replState->buildUUID << ": " << ex;
+ LOGV2(20664,
+ "Index build failed before final phase during oplog application. "
+ "Waiting for abort: {replState_buildUUID}: {ex}",
+ "replState_buildUUID"_attr = replState->buildUUID,
+ "ex"_attr = ex);
preAbortStatus = ex.toStatus();
}
@@ -1735,7 +1780,7 @@ void IndexBuildsCoordinator::_scanCollectionAndInsertKeysIntoSorter(
}
if (MONGO_unlikely(hangAfterIndexBuildDumpsInsertsFromBulk.shouldFail())) {
- log() << "Hanging after dumping inserts from bulk builder";
+ LOGV2(20665, "Hanging after dumping inserts from bulk builder");
hangAfterIndexBuildDumpsInsertsFromBulk.pauseWhileSet();
}
}
@@ -1761,7 +1806,7 @@ NamespaceString IndexBuildsCoordinator::_insertKeysFromSideTablesWithoutBlocking
}
if (MONGO_unlikely(hangAfterIndexBuildFirstDrain.shouldFail())) {
- log() << "Hanging after index build first drain";
+ LOGV2(20666, "Hanging after index build first drain");
hangAfterIndexBuildFirstDrain.pauseWhileSet();
}
@@ -1783,7 +1828,7 @@ NamespaceString IndexBuildsCoordinator::_insertKeysFromSideTablesWithoutBlocking
}
if (MONGO_unlikely(hangAfterIndexBuildSecondDrain.shouldFail())) {
- log() << "Hanging after index build second drain";
+ LOGV2(20667, "Hanging after index build second drain");
hangAfterIndexBuildSecondDrain.pauseWhileSet();
}
@@ -1800,8 +1845,10 @@ Timestamp IndexBuildsCoordinator::_waitForCommitOrAbort(
const Status& preAbortStatus) {
Timestamp commitIndexBuildTimestamp;
if (shouldWaitForCommitOrAbort(opCtx, nss, *replState)) {
- log() << "Index build waiting for commit or abort before completing final phase: "
- << replState->buildUUID;
+ LOGV2(20668,
+ "Index build waiting for commit or abort before completing final phase: "
+ "{replState_buildUUID}",
+ "replState_buildUUID"_attr = replState->buildUUID);
// Yield locks and storage engine resources before blocking.
opCtx->recoveryUnit()->abandonSnapshot();
@@ -1816,9 +1863,12 @@ Timestamp IndexBuildsCoordinator::_waitForCommitOrAbort(
opCtx->waitForConditionOrInterrupt(replState->condVar, lk, isReadyToCommitOrAbort);
if (replState->isCommitReady) {
- log() << "Committing index build: " << replState->buildUUID
- << ", timestamp: " << replState->commitTimestamp
- << ", collection UUID: " << replState->collectionUUID;
+ LOGV2(20669,
+ "Committing index build: {replState_buildUUID}, timestamp: "
+ "{replState_commitTimestamp}, collection UUID: {replState_collectionUUID}",
+ "replState_buildUUID"_attr = replState->buildUUID,
+ "replState_commitTimestamp"_attr = replState->commitTimestamp,
+ "replState_collectionUUID"_attr = replState->collectionUUID);
commitIndexBuildTimestamp = replState->commitTimestamp;
invariant(!replState->aborted, replState->buildUUID.toString());
uassertStatusOK(preAbortStatus.withContext(
@@ -1826,11 +1876,15 @@ Timestamp IndexBuildsCoordinator::_waitForCommitOrAbort(
"commitIndexBuild oplog entry from the primary with timestamp: "
<< replState->commitTimestamp.toString()));
} else if (replState->aborted) {
- log() << "Aborting index build: " << replState->buildUUID
- << ", timestamp: " << replState->abortTimestamp
- << ", reason: " << replState->abortReason
- << ", collection UUID: " << replState->collectionUUID
- << ", local index error (if any): " << preAbortStatus;
+ LOGV2(20670,
+ "Aborting index build: {replState_buildUUID}, timestamp: "
+ "{replState_abortTimestamp}, reason: {replState_abortReason}, collection UUID: "
+ "{replState_collectionUUID}, local index error (if any): {preAbortStatus}",
+ "replState_buildUUID"_attr = replState->buildUUID,
+ "replState_abortTimestamp"_attr = replState->abortTimestamp,
+ "replState_abortReason"_attr = replState->abortReason,
+ "replState_collectionUUID"_attr = replState->collectionUUID,
+ "preAbortStatus"_attr = preAbortStatus);
invariant(!replState->isCommitReady, replState->buildUUID.toString());
}
}
@@ -1905,14 +1959,16 @@ void IndexBuildsCoordinator::_insertKeysFromSideTablesAndCommit(
}
if (indexBuildOptions.replSetAndNotPrimaryAtStart) {
- LOG(1) << "Skipping createIndexes oplog entry for index build: "
- << replState->buildUUID;
+ LOGV2_DEBUG(20671,
+ 1,
+ "Skipping createIndexes oplog entry for index build: {replState_buildUUID}",
+ "replState_buildUUID"_attr = replState->buildUUID);
// Get a timestamp to complete the index build in the absence of a createIndexBuild
// oplog entry.
repl::UnreplicatedWritesBlock uwb(opCtx);
if (!IndexTimestampHelper::setGhostCommitTimestampForCatalogWrite(opCtx,
collection->ns())) {
- log() << "Did not timestamp index commit write.";
+ LOGV2(20672, "Did not timestamp index commit write.");
}
return;
}
@@ -1954,7 +2010,10 @@ StatusWith<std::pair<long long, long long>> IndexBuildsCoordinator::_runIndexReb
indexCatalogStats.numIndexesBefore = getNumIndexesTotal(opCtx, collection);
try {
- log() << "Index builds manager starting: " << buildUUID << ": " << nss;
+ LOGV2(20673,
+ "Index builds manager starting: {buildUUID}: {nss}",
+ "buildUUID"_attr = buildUUID,
+ "nss"_attr = nss);
std::tie(numRecords, dataSize) =
uassertStatusOK(_indexBuildsManager.startBuildingIndexForRecovery(
@@ -1973,14 +2032,24 @@ StatusWith<std::pair<long long, long long>> IndexBuildsCoordinator::_runIndexReb
indexCatalogStats.numIndexesAfter = getNumIndexesTotal(opCtx, collection);
- log() << "Index builds manager completed successfully: " << buildUUID << ": " << nss
- << ". Index specs requested: " << replState->indexSpecs.size()
- << ". Indexes in catalog before build: " << indexCatalogStats.numIndexesBefore
- << ". Indexes in catalog after build: " << indexCatalogStats.numIndexesAfter;
+ LOGV2(20674,
+ "Index builds manager completed successfully: {buildUUID}: {nss}. Index specs "
+ "requested: {replState_indexSpecs_size}. Indexes in catalog before build: "
+ "{indexCatalogStats_numIndexesBefore}. Indexes in catalog after build: "
+ "{indexCatalogStats_numIndexesAfter}",
+ "buildUUID"_attr = buildUUID,
+ "nss"_attr = nss,
+ "replState_indexSpecs_size"_attr = replState->indexSpecs.size(),
+ "indexCatalogStats_numIndexesBefore"_attr = indexCatalogStats.numIndexesBefore,
+ "indexCatalogStats_numIndexesAfter"_attr = indexCatalogStats.numIndexesAfter);
} catch (const DBException& ex) {
status = ex.toStatus();
invariant(status != ErrorCodes::IndexAlreadyExists);
- log() << "Index builds manager failed: " << buildUUID << ": " << nss << ": " << status;
+ LOGV2(20675,
+ "Index builds manager failed: {buildUUID}: {nss}: {status}",
+ "buildUUID"_attr = buildUUID,
+ "nss"_attr = nss,
+ "status"_attr = status);
}
// Index build is registered in manager regardless of IndexBuildsManager::setUpIndexBuild()
diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp
index 2d262167793..db4f894e815 100644
--- a/src/mongo/db/initialize_server_global_state.cpp
+++ b/src/mongo/db/initialize_server_global_state.cpp
@@ -58,6 +58,7 @@
#include "mongo/logger/rotatable_file_manager.h"
#include "mongo/logger/rotatable_file_writer.h"
#include "mongo/logger/syslog_appender.h"
+#include "mongo/logv2/log.h"
#include "mongo/logv2/log_domain_global.h"
#include "mongo/platform/process_id.h"
#include "mongo/util/log.h"
@@ -287,8 +288,10 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
boost::system::error_code ec;
boost::filesystem::rename(absoluteLogpath, renameTarget, ec);
if (!ec) {
- log() << "log file \"" << absoluteLogpath << "\" exists; moved to \""
- << renameTarget << "\".";
+ LOGV2(20697,
+ "log file \"{absoluteLogpath}\" exists; moved to \"{renameTarget}\".",
+ "absoluteLogpath"_attr = absoluteLogpath,
+ "renameTarget"_attr = renameTarget);
} else {
return Status(ErrorCodes::FileRenameFailed,
str::stream()
@@ -321,7 +324,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
: logv2::LogDomainGlobal::ConfigurationOptions::OpenMode::kTruncate;
if (serverGlobalParams.logAppend && exists) {
- log() << "***** SERVER RESTARTED *****";
+ LOGV2(20698, "***** SERVER RESTARTED *****");
// FIXME rewrite for logv2
// Status status = logger::RotatableFileWriter::Use(writer.getValue()).status();
// if (!status.isOK())
@@ -339,7 +342,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection,
javascriptAppender = std::make_unique<RotatableFileAppender<MessageEventEphemeral>>(
std::make_unique<MessageEventDetailsEncoder>(), writer.getValue());
if (serverGlobalParams.logAppend && exists) {
- log() << "***** SERVER RESTARTED *****";
+ LOGV2(20699, "***** SERVER RESTARTED *****");
Status status = logger::RotatableFileWriter::Use(writer.getValue()).status();
if (!status.isOK())
return status;
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index 82993e676c9..87819671ad4 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/curop.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
#include "mongo/util/log.h"
@@ -159,8 +160,9 @@ void profile(OperationContext* opCtx, NetworkOp op) {
Database* const db = autoGetDb->getDb();
if (!db) {
// Database disappeared
- log() << "note: not profiling because db went away for "
- << CurOp::get(opCtx)->getNS();
+ LOGV2(20700,
+ "note: not profiling because db went away for {CurOp_get_opCtx_getNS}",
+ "CurOp_get_opCtx_getNS"_attr = CurOp::get(opCtx)->getNS());
break;
}
@@ -201,14 +203,21 @@ void profile(OperationContext* opCtx, NetworkOp op) {
}
} catch (const AssertionException& assertionEx) {
if (acquireDbXLock && ErrorCodes::isInterruption(assertionEx)) {
- warning()
- << "Interrupted while attempting to create profile collection in database "
- << dbName << " to profile operation " << networkOpToString(op) << " against "
- << CurOp::get(opCtx)->getNS()
- << ". Manually create profile collection to ensure future operations are logged.";
+ LOGV2_WARNING(
+ 20702,
+ "Interrupted while attempting to create profile collection in database {dbName} to "
+ "profile operation {networkOpToString_op} against {CurOp_get_opCtx_getNS}. "
+ "Manually create profile collection to ensure future operations are logged.",
+ "dbName"_attr = dbName,
+ "networkOpToString_op"_attr = networkOpToString(op),
+ "CurOp_get_opCtx_getNS"_attr = CurOp::get(opCtx)->getNS());
} else {
- warning() << "Caught Assertion while trying to profile " << networkOpToString(op)
- << " against " << CurOp::get(opCtx)->getNS() << ": " << redact(assertionEx);
+ LOGV2_WARNING(20703,
+ "Caught Assertion while trying to profile {networkOpToString_op} against "
+ "{CurOp_get_opCtx_getNS}: {assertionEx}",
+ "networkOpToString_op"_attr = networkOpToString(op),
+ "CurOp_get_opCtx_getNS"_attr = CurOp::get(opCtx)->getNS(),
+ "assertionEx"_attr = redact(assertionEx));
}
}
}
@@ -231,7 +240,9 @@ Status createProfileCollection(OperationContext* opCtx, Database* db) {
}
// system.profile namespace doesn't exist; create it
- log() << "Creating profile collection: " << dbProfilingNS;
+ LOGV2(20701,
+ "Creating profile collection: {dbProfilingNS}",
+ "dbProfilingNS"_attr = dbProfilingNS);
CollectionOptions collectionOptions;
collectionOptions.capped = true;
diff --git a/src/mongo/db/keys_collection_client_direct.cpp b/src/mongo/db/keys_collection_client_direct.cpp
index 861440f7707..817b380ec41 100644
--- a/src/mongo/db/keys_collection_client_direct.cpp
+++ b/src/mongo/db/keys_collection_client_direct.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/logical_time.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/write_ops/batched_command_request.h"
@@ -158,9 +159,12 @@ Status KeysCollectionClientDirect::_insert(OperationContext* opCtx,
Shard::CommandResponse::processBatchWriteResponse(swResponse, &batchResponse);
if (retry < kOnErrorNumRetries &&
isRetriableError(writeStatus.code(), Shard::RetryPolicy::kIdempotent)) {
- LOG(2) << "Batch write command to " << nss.db()
- << "failed with retriable error and will be retried"
- << causedBy(redact(writeStatus));
+ LOGV2_DEBUG(20704,
+ 2,
+ "Batch write command to {nss_db}failed with retriable error and will be "
+ "retried{causedBy_writeStatus}",
+ "nss_db"_attr = nss.db(),
+ "causedBy_writeStatus"_attr = causedBy(redact(writeStatus)));
continue;
}
diff --git a/src/mongo/db/keys_collection_manager.cpp b/src/mongo/db/keys_collection_manager.cpp
index 91e8bd8f4a4..a921df95c59 100644
--- a/src/mongo/db/keys_collection_manager.cpp
+++ b/src/mongo/db/keys_collection_manager.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/logical_time.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -293,7 +294,7 @@ void KeysCollectionManager::PeriodicRunner::_doPeriodicRefresh(ServiceContext* s
return _inShutdown || _refreshRequest;
});
} catch (const DBException& e) {
- LOG(1) << "Unable to wait for refresh request due to: " << e;
+ LOGV2_DEBUG(20705, 1, "Unable to wait for refresh request due to: {e}", "e"_attr = e);
if (ErrorCodes::isShutdownError(e)) {
return;
diff --git a/src/mongo/db/kill_sessions_common.cpp b/src/mongo/db/kill_sessions_common.cpp
index 7a3f93e9d3c..fd31d2f1438 100644
--- a/src/mongo/db/kill_sessions_common.cpp
+++ b/src/mongo/db/kill_sessions_common.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
#include "mongo/db/session_killer.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -56,8 +57,10 @@ SessionKiller::Result killSessionsLocalKillOps(OperationContext* opCtx,
if (const KillAllSessionsByPattern* pattern = matcher.match(*lsid)) {
ScopedKillAllSessionsByPatternImpersonator impersonator(opCtx, *pattern);
- log() << "killing op: " << opCtxToKill->getOpID()
- << " as part of killing session: " << lsid->toBSON();
+ LOGV2(20706,
+ "killing op: {opCtxToKill_getOpID} as part of killing session: {lsid}",
+ "opCtxToKill_getOpID"_attr = opCtxToKill->getOpID(),
+ "lsid"_attr = lsid->toBSON());
opCtx->getServiceContext()->killOperation(lk, opCtxToKill);
}
diff --git a/src/mongo/db/kill_sessions_local.cpp b/src/mongo/db/kill_sessions_local.cpp
index eb708bb97f8..91da0862ab0 100644
--- a/src/mongo/db/kill_sessions_local.cpp
+++ b/src/mongo/db/kill_sessions_local.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/session_catalog.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -118,31 +119,34 @@ SessionKiller::Result killSessionsLocal(OperationContext* opCtx,
void killAllExpiredTransactions(OperationContext* opCtx) {
SessionKiller::Matcher matcherAllSessions(
KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)});
- killSessionsAction(opCtx,
- matcherAllSessions,
- [when = opCtx->getServiceContext()->getPreciseClockSource()->now()](
- const ObservableSession& session) {
- return TransactionParticipant::get(session).expiredAsOf(when);
- },
- [](OperationContext* opCtx, const SessionToKill& session) {
- auto txnParticipant = TransactionParticipant::get(session);
- // If the transaction is aborted here, it means it was aborted after
- // the filter. The most likely reason for this is that the transaction
- // was active and the session kill aborted it. We still want to log
- // that as aborted due to transactionLifetimeLimitSessions.
- if (txnParticipant.transactionIsInProgress() ||
- txnParticipant.transactionIsAborted()) {
- log() << "Aborting transaction with txnNumber "
- << txnParticipant.getActiveTxnNumber() << " on session "
- << session.getSessionId().getId()
- << " because it has been running for longer than "
- "'transactionLifetimeLimitSeconds'";
- if (txnParticipant.transactionIsInProgress()) {
- txnParticipant.abortTransaction(opCtx);
- }
- }
- },
- ErrorCodes::TransactionExceededLifetimeLimitSeconds);
+ killSessionsAction(
+ opCtx,
+ matcherAllSessions,
+ [when = opCtx->getServiceContext()->getPreciseClockSource()->now()](
+ const ObservableSession& session) {
+ return TransactionParticipant::get(session).expiredAsOf(when);
+ },
+ [](OperationContext* opCtx, const SessionToKill& session) {
+ auto txnParticipant = TransactionParticipant::get(session);
+ // If the transaction is aborted here, it means it was aborted after
+ // the filter. The most likely reason for this is that the transaction
+ // was active and the session kill aborted it. We still want to log
+ // that as aborted due to transactionLifetimeLimitSessions.
+ if (txnParticipant.transactionIsInProgress() || txnParticipant.transactionIsAborted()) {
+ LOGV2(20707,
+ "Aborting transaction with txnNumber {txnParticipant_getActiveTxnNumber} on "
+ "session {session_getSessionId_getId} because it has been running for longer "
+ "than "
+ "'transactionLifetimeLimitSeconds'",
+ "txnParticipant_getActiveTxnNumber"_attr =
+ txnParticipant.getActiveTxnNumber(),
+ "session_getSessionId_getId"_attr = session.getSessionId().getId());
+ if (txnParticipant.transactionIsInProgress()) {
+ txnParticipant.abortTransaction(opCtx);
+ }
+ }
+ },
+ ErrorCodes::TransactionExceededLifetimeLimitSeconds);
}
void killSessionsLocalShutdownAllTransactions(OperationContext* opCtx) {
@@ -189,29 +193,34 @@ void yieldLocksForPreparedTransactions(OperationContext* opCtx) {
// to yield their locks.
SessionKiller::Matcher matcherAllSessions(
KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(newOpCtx.get())});
- killSessionsAction(newOpCtx.get(),
- matcherAllSessions,
- [](const ObservableSession& session) {
- return TransactionParticipant::get(session).transactionIsPrepared();
- },
- [](OperationContext* killerOpCtx, const SessionToKill& session) {
- auto txnParticipant = TransactionParticipant::get(session);
- // Yield locks for prepared transactions.
- // When scanning and killing operations, all prepared transactions are
- // included in the
- // list. Even though new sessions may be created after the scan, none of
- // them can become
- // prepared during stepdown, since the RSTL has been enqueued, preventing
- // any new
- // writes.
- if (txnParticipant.transactionIsPrepared()) {
- LOG(3) << "Yielding locks of prepared transaction. SessionId: "
- << session.getSessionId().getId()
- << " TxnNumber: " << txnParticipant.getActiveTxnNumber();
- txnParticipant.refreshLocksForPreparedTransaction(killerOpCtx, true);
- }
- },
- ErrorCodes::InterruptedDueToReplStateChange);
+ killSessionsAction(
+ newOpCtx.get(),
+ matcherAllSessions,
+ [](const ObservableSession& session) {
+ return TransactionParticipant::get(session).transactionIsPrepared();
+ },
+ [](OperationContext* killerOpCtx, const SessionToKill& session) {
+ auto txnParticipant = TransactionParticipant::get(session);
+ // Yield locks for prepared transactions.
+ // When scanning and killing operations, all prepared transactions are
+ // included in the
+ // list. Even though new sessions may be created after the scan, none of
+ // them can become
+ // prepared during stepdown, since the RSTL has been enqueued, preventing
+ // any new
+ // writes.
+ if (txnParticipant.transactionIsPrepared()) {
+ LOGV2_DEBUG(
+ 20708,
+ 3,
+ "Yielding locks of prepared transaction. SessionId: "
+ "{session_getSessionId_getId} TxnNumber: {txnParticipant_getActiveTxnNumber}",
+ "session_getSessionId_getId"_attr = session.getSessionId().getId(),
+ "txnParticipant_getActiveTxnNumber"_attr = txnParticipant.getActiveTxnNumber());
+ txnParticipant.refreshLocksForPreparedTransaction(killerOpCtx, true);
+ }
+ },
+ ErrorCodes::InterruptedDueToReplStateChange);
}
} // namespace mongo
diff --git a/src/mongo/db/log_process_details.cpp b/src/mongo/db/log_process_details.cpp
index 9e30fc04822..140f0f51495 100644
--- a/src/mongo/db/log_process_details.cpp
+++ b/src/mongo/db/log_process_details.cpp
@@ -51,7 +51,7 @@ bool is32bit() {
void logProcessDetails() {
auto&& vii = VersionInfoInterface::instance();
- log() << mongodVersion(vii);
+ LOGV2(20719, "{mongodVersion_vii}", "mongodVersion_vii"_attr = mongodVersion(vii));
vii.logBuildInfo();
ProcessInfo p;
@@ -61,17 +61,24 @@ void logProcessDetails() {
"version"_attr = p.getOsVersion());
if (ProcessInfo::getMemSizeMB() < ProcessInfo::getSystemMemSizeMB()) {
- log() << ProcessInfo::getMemSizeMB() << " MB of memory available to the process out of "
- << ProcessInfo::getSystemMemSizeMB() << " MB total system memory";
+ LOGV2(20720,
+ "{ProcessInfo_getMemSizeMB} MB of memory available to the process out of "
+ "{ProcessInfo_getSystemMemSizeMB} MB total system memory",
+ "ProcessInfo_getMemSizeMB"_attr = ProcessInfo::getMemSizeMB(),
+ "ProcessInfo_getSystemMemSizeMB"_attr = ProcessInfo::getSystemMemSizeMB());
}
printCommandLineOpts();
}
void logProcessDetailsForLogRotate(ServiceContext* serviceContext) {
- log() << "pid=" << ProcessId::getCurrent() << " port=" << serverGlobalParams.port
- << (is32bit() ? " 32" : " 64") << "-bit "
- << "host=" << getHostNameCached();
+ LOGV2(20721,
+ "pid={ProcessId_getCurrent} port={serverGlobalParams_port}{is32bit_32_64}-bit "
+ "host={getHostNameCached}",
+ "ProcessId_getCurrent"_attr = ProcessId::getCurrent(),
+ "serverGlobalParams_port"_attr = serverGlobalParams.port,
+ "is32bit_32_64"_attr = (is32bit() ? " 32" : " 64"),
+ "getHostNameCached"_attr = getHostNameCached());
auto replCoord = repl::ReplicationCoordinator::get(serviceContext);
if (replCoord != nullptr &&
@@ -79,10 +86,12 @@ void logProcessDetailsForLogRotate(ServiceContext* serviceContext) {
auto rsConfig = replCoord->getConfig();
if (rsConfig.isInitialized()) {
- log() << "Replica Set Config: " << rsConfig.toBSON();
- log() << "Replica Set Member State: " << (replCoord->getMemberState()).toString();
+ LOGV2(20722, "Replica Set Config: {rsConfig}", "rsConfig"_attr = rsConfig.toBSON());
+ LOGV2(20723,
+ "Replica Set Member State: {replCoord_getMemberState}",
+ "replCoord_getMemberState"_attr = (replCoord->getMemberState()).toString());
} else {
- log() << "Node currently has no Replica Set Config.";
+ LOGV2(20724, "Node currently has no Replica Set Config.");
}
}
diff --git a/src/mongo/db/logical_clock.cpp b/src/mongo/db/logical_clock.cpp
index 6dea3e7acdc..cb785c29ec5 100644
--- a/src/mongo/db/logical_clock.cpp
+++ b/src/mongo/db/logical_clock.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
#include "mongo/db/time_proof_service.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -122,8 +123,9 @@ LogicalTime LogicalClock::reserveTicks(uint64_t nTicks) {
// second.
else if (clusterTime.asTimestamp().getInc() > (kMaxSignedInt - nTicks)) {
- log() << "Exceeded maximum allowable increment value within one second. Moving clusterTime "
- "forward to the next second.";
+ LOGV2(20709,
+ "Exceeded maximum allowable increment value within one second. Moving clusterTime "
+ "forward to the next second.");
// Move time forward to the next second
clusterTime = LogicalTime(Timestamp(clusterTime.asTimestamp().getSecs() + 1, 0));
diff --git a/src/mongo/db/logical_session_cache_impl.cpp b/src/mongo/db/logical_session_cache_impl.cpp
index eae770cfecc..f3c162006b2 100644
--- a/src/mongo/db/logical_session_cache_impl.cpp
+++ b/src/mongo/db/logical_session_cache_impl.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/util/duration.h"
#include "mongo/util/log.h"
@@ -124,15 +125,17 @@ void LogicalSessionCacheImpl::_periodicRefresh(Client* client) {
try {
_refresh(client);
} catch (...) {
- log() << "Failed to refresh session cache: " << exceptionToStatus()
- << ", will try again at the next refresh interval";
+ LOGV2(20710,
+ "Failed to refresh session cache: {exceptionToStatus}, will try again at the next "
+ "refresh interval",
+ "exceptionToStatus"_attr = exceptionToStatus());
}
}
void LogicalSessionCacheImpl::_periodicReap(Client* client) {
auto res = _reap(client);
if (!res.isOK()) {
- log() << "Failed to reap transaction table: " << res;
+ LOGV2(20711, "Failed to reap transaction table: {res}", "res"_attr = res);
}
return;
@@ -174,9 +177,12 @@ Status LogicalSessionCacheImpl::_reap(Client* client) {
"waiting until next sessions reap interval";
if (ex.code() != ErrorCodes::NamespaceNotFound ||
ex.code() != ErrorCodes::NamespaceNotSharded) {
- log() << notSetUpWarning << ": " << ex.reason();
+ LOGV2(20712,
+ "{notSetUpWarning}: {ex_reason}",
+ "notSetUpWarning"_attr = notSetUpWarning,
+ "ex_reason"_attr = ex.reason());
} else {
- log() << notSetUpWarning;
+ LOGV2(20713, "{notSetUpWarning}", "notSetUpWarning"_attr = notSetUpWarning);
}
return Status::OK();
}
@@ -243,8 +249,10 @@ void LogicalSessionCacheImpl::_refresh(Client* client) {
try {
_sessionsColl->setupSessionsCollection(opCtx);
} catch (const DBException& ex) {
- log() << "Failed to refresh session cache, will try again at the next refresh interval"
- << causedBy(redact(ex));
+ LOGV2(20714,
+ "Failed to refresh session cache, will try again at the next refresh "
+ "interval{causedBy_ex}",
+ "causedBy_ex"_attr = causedBy(redact(ex)));
return;
}
@@ -374,7 +382,10 @@ Status LogicalSessionCacheImpl::_addToCacheIfNotFull(WithLock, LogicalSessionRec
"high"};
auto severity =
MONGO_GET_LIMITED_SEVERITY(ErrorCodes::TooManyLogicalSessions, Seconds{1}, 0, 2);
- LOG(severity) << status.toString();
+ LOGV2_DEBUG(20715,
+ logSeverityV1toV2(severity).toInt(),
+ "{status}",
+ "status"_attr = status.toString());
return status;
}
diff --git a/src/mongo/db/logical_time_validator.cpp b/src/mongo/db/logical_time_validator.cpp
index 6d448f78a5f..0fa0b55cfc5 100644
--- a/src/mongo/db/logical_time_validator.cpp
+++ b/src/mongo/db/logical_time_validator.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/logical_clock.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -195,7 +196,7 @@ bool LogicalTimeValidator::shouldGossipLogicalTime() {
}
void LogicalTimeValidator::resetKeyManagerCache() {
- log() << "Resetting key manager cache";
+ LOGV2(20716, "Resetting key manager cache");
invariant(_keyManager);
_keyManager->clearCache();
stdx::lock_guard<Latch> lk(_mutex);
@@ -205,7 +206,7 @@ void LogicalTimeValidator::resetKeyManagerCache() {
void LogicalTimeValidator::stopKeyManager() {
if (_keyManager) {
- log() << "Stopping key manager";
+ LOGV2(20717, "Stopping key manager");
_keyManager->stopMonitoring();
_keyManager->clearCache();
@@ -213,7 +214,7 @@ void LogicalTimeValidator::stopKeyManager() {
_lastSeenValidTime = SignedLogicalTime();
_timeProofService.resetCache();
} else {
- log() << "Stopping key manager: no key manager exists.";
+ LOGV2(20718, "Stopping key manager: no key manager exists.");
}
}
diff --git a/src/mongo/db/matcher/rewrite_expr.cpp b/src/mongo/db/matcher/rewrite_expr.cpp
index 01e5a6e51c5..31dfcfd51ee 100644
--- a/src/mongo/db/matcher/rewrite_expr.cpp
+++ b/src/mongo/db/matcher/rewrite_expr.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/matcher/expression_internal_expr_eq.h"
#include "mongo/db/matcher/expression_leaf.h"
#include "mongo/db/matcher/expression_tree.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -44,16 +45,25 @@ using CmpOp = ExpressionCompare::CmpOp;
RewriteExpr::RewriteResult RewriteExpr::rewrite(const boost::intrusive_ptr<Expression>& expression,
const CollatorInterface* collator) {
- LOG(5) << "Expression prior to rewrite: " << expression->serialize(false);
+ LOGV2_DEBUG(20725,
+ 5,
+ "Expression prior to rewrite: {expression_serialize_false}",
+ "expression_serialize_false"_attr = expression->serialize(false));
RewriteExpr rewriteExpr(collator);
std::unique_ptr<MatchExpression> matchExpression;
if (auto matchTree = rewriteExpr._rewriteExpression(expression)) {
matchExpression = std::move(matchTree);
- LOG(5) << "Post-rewrite MatchExpression: " << matchExpression->debugString();
+ LOGV2_DEBUG(20726,
+ 5,
+ "Post-rewrite MatchExpression: {matchExpression_debugString}",
+ "matchExpression_debugString"_attr = matchExpression->debugString());
matchExpression = MatchExpression::optimize(std::move(matchExpression));
- LOG(5) << "Post-rewrite/post-optimized MatchExpression: " << matchExpression->debugString();
+ LOGV2_DEBUG(20727,
+ 5,
+ "Post-rewrite/post-optimized MatchExpression: {matchExpression_debugString}",
+ "matchExpression_debugString"_attr = matchExpression->debugString());
}
return {std::move(matchExpression), std::move(rewriteExpr._matchExprElemStorage)};
diff --git a/src/mongo/db/matcher/schema/json_schema_parser.cpp b/src/mongo/db/matcher/schema/json_schema_parser.cpp
index a8ad976b5da..005ddeab349 100644
--- a/src/mongo/db/matcher/schema/json_schema_parser.cpp
+++ b/src/mongo/db/matcher/schema/json_schema_parser.cpp
@@ -60,6 +60,7 @@
#include "mongo/db/matcher/schema/expression_internal_schema_xor.h"
#include "mongo/db/matcher/schema/json_pointer.h"
#include "mongo/logger/log_component_settings.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/string_map.h"
@@ -1610,12 +1611,19 @@ StatusWithMatchExpression JSONSchemaParser::parse(
const boost::intrusive_ptr<ExpressionContext>& expCtx,
BSONObj schema,
bool ignoreUnknownKeywords) {
- LOG(5) << "Parsing JSON Schema: " << schema.jsonString(JsonStringFormat::LegacyStrict);
+ LOGV2_DEBUG(20728,
+ 5,
+ "Parsing JSON Schema: {schema_jsonString_JsonStringFormat_LegacyStrict}",
+ "schema_jsonString_JsonStringFormat_LegacyStrict"_attr =
+ schema.jsonString(JsonStringFormat::LegacyStrict));
try {
auto translation = _parse(expCtx, ""_sd, schema, ignoreUnknownKeywords);
if (shouldLog(logger::LogSeverity::Debug(5)) && translation.isOK()) {
- LOG(5) << "Translated schema match expression: "
- << translation.getValue()->debugString();
+ LOGV2_DEBUG(20729,
+ 5,
+ "Translated schema match expression: {translation_getValue_debugString}",
+ "translation_getValue_debugString"_attr =
+ translation.getValue()->debugString());
}
return translation;
} catch (const DBException& ex) {
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index 11a75108e9c..c841a794121 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -53,6 +53,7 @@
#include "mongo/db/server_options_base.h"
#include "mongo/db/server_options_nongeneral_gen.h"
#include "mongo/db/server_options_server_helpers.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/util/options_parser/startup_options.h"
@@ -101,13 +102,19 @@ void printMongodHelp(const moe::OptionSection& options) {
namespace {
void sysRuntimeInfo() {
#if defined(_SC_PAGE_SIZE)
- log() << " page size: " << (int)sysconf(_SC_PAGE_SIZE);
+ LOGV2(20873,
+ " page size: {int_sysconf_SC_PAGE_SIZE}",
+ "int_sysconf_SC_PAGE_SIZE"_attr = (int)sysconf(_SC_PAGE_SIZE));
#endif
#if defined(_SC_PHYS_PAGES)
- log() << " _SC_PHYS_PAGES: " << sysconf(_SC_PHYS_PAGES);
+ LOGV2(20874,
+ " _SC_PHYS_PAGES: {sysconf_SC_PHYS_PAGES}",
+ "sysconf_SC_PHYS_PAGES"_attr = sysconf(_SC_PHYS_PAGES));
#endif
#if defined(_SC_AVPHYS_PAGES)
- log() << " _SC_AVPHYS_PAGES: " << sysconf(_SC_AVPHYS_PAGES);
+ LOGV2(20875,
+ " _SC_AVPHYS_PAGES: {sysconf_SC_AVPHYS_PAGES}",
+ "sysconf_SC_AVPHYS_PAGES"_attr = sysconf(_SC_AVPHYS_PAGES));
#endif
}
} // namespace
@@ -121,7 +128,7 @@ bool handlePreValidationMongodOptions(const moe::Environment& params,
if (params.count("version") && params["version"].as<bool>() == true) {
setPlainConsoleLogger();
auto&& vii = VersionInfoInterface::instance();
- log() << mongodVersion(vii);
+ LOGV2(20876, "{mongodVersion_vii}", "mongodVersion_vii"_attr = mongodVersion(vii));
vii.logBuildInfo();
return false;
}
@@ -132,7 +139,7 @@ bool handlePreValidationMongodOptions(const moe::Environment& params,
}
if (params.count("master") || params.count("slave")) {
- severe() << "Master/slave replication is no longer supported";
+ LOGV2_FATAL(20881, "Master/slave replication is no longer supported");
return false;
}
@@ -572,10 +579,11 @@ Status storeMongodOptions(const moe::Environment& params) {
if (params.count("replication.enableMajorityReadConcern") &&
!params["replication.enableMajorityReadConcern"].as<bool>()) {
- warning()
- << "Config servers require majority read concern, but it was explicitly "
- "disabled. The override is being ignored and the process is continuing "
- "with majority read concern enabled.";
+ LOGV2_WARNING(
+ 20879,
+ "Config servers require majority read concern, but it was explicitly "
+ "disabled. The override is being ignored and the process is continuing "
+ "with majority read concern enabled.");
}
serverGlobalParams.enableMajorityReadConcern = true;
@@ -630,10 +638,11 @@ Status storeMongodOptions(const moe::Environment& params) {
// Check if we are 32 bit and have not explicitly specified any journaling options
if (sizeof(void*) == 4 && !params.count("storage.journal.enabled")) {
// trying to make this stand out more like startup warnings
- log() << endl;
- warning() << "32-bit servers don't have journaling enabled by default. "
- << "Please use --journal if you want durability.";
- log() << endl;
+ LOGV2(20877, "");
+ LOGV2_WARNING(20880,
+ "32-bit servers don't have journaling enabled by default. Please use "
+ "--journal if you want durability.");
+ LOGV2(20878, "");
}
bool isClusterRoleShard = params.count("shardsvr");
diff --git a/src/mongo/db/operation_context.cpp b/src/mongo/db/operation_context.cpp
index 282612c54c8..1e1858d812b 100644
--- a/src/mongo/db/operation_context.cpp
+++ b/src/mongo/db/operation_context.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/client.h"
#include "mongo/db/operation_key_manager.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/platform/random.h"
#include "mongo/transport/baton.h"
@@ -223,7 +224,9 @@ Status OperationContext::checkForInterruptNoAssert() noexcept {
checkForInterruptFail.executeIf(
[&](auto&&) {
- log() << "set pending kill on op " << getOpID() << ", for checkForInterruptFail";
+ LOGV2(20882,
+ "set pending kill on op {getOpID}, for checkForInterruptFail",
+ "getOpID"_attr = getOpID());
markKilled();
},
[&](auto&& data) { return opShouldFail(getClient(), data); });
@@ -324,7 +327,7 @@ void OperationContext::markKilled(ErrorCodes::Error killCode) {
invariant(!ErrorExtraInfo::parserFor(killCode));
if (killCode == ErrorCodes::ClientDisconnect) {
- log() << "operation was interrupted because a client disconnected";
+ LOGV2(20883, "operation was interrupted because a client disconnected");
}
if (auto status = ErrorCodes::OK; _killCode.compareAndSwap(&status, killCode)) {
diff --git a/src/mongo/db/operation_killer.cpp b/src/mongo/db/operation_killer.cpp
index 742a9d142e3..e6546e6c246 100644
--- a/src/mongo/db/operation_killer.cpp
+++ b/src/mongo/db/operation_killer.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/client.h"
#include "mongo/db/operation_key_manager.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -82,7 +83,7 @@ void OperationKiller::killOperation(OperationId opId) {
serviceContext->killOperation(target, target->getOperationContext());
- log() << "Killed operation: " << opId;
+ LOGV2(20884, "Killed operation: {opId}", "opId"_attr = opId);
}
void OperationKiller::killOperation(const OperationKey& opKey) {
diff --git a/src/mongo/db/ops/update_result.cpp b/src/mongo/db/ops/update_result.cpp
index 8765dd1dde1..e5276be908a 100644
--- a/src/mongo/db/ops/update_result.cpp
+++ b/src/mongo/db/ops/update_result.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/ops/update_result.h"
#include "mongo/db/lasterror.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -53,7 +54,7 @@ UpdateResult::UpdateResult(bool existing_,
if (!existing && numMatched == 0 && !id.eoo()) {
upserted = id.wrap(kUpsertedFieldName);
}
- LOG(4) << "UpdateResult -- " << redact(toString());
+ LOGV2_DEBUG(20885, 4, "UpdateResult -- {}", ""_attr = redact(toString()));
}
std::string UpdateResult::toString() const {
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp
index 196fb827e86..0518b6dd75e 100644
--- a/src/mongo/db/ops/write_ops_exec.cpp
+++ b/src/mongo/db/ops/write_ops_exec.cpp
@@ -74,6 +74,7 @@
#include "mongo/db/storage/duplicate_key_error_info.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/db/write_concern.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/cannot_implicitly_create_collection_info.h"
#include "mongo/s/would_change_owning_shard_exception.h"
@@ -128,8 +129,13 @@ void finishCurOp(OperationContext* opCtx, CurOp* curOp) {
curOp->getReadWriteType());
if (!curOp->debug().errInfo.isOK()) {
- LOG(3) << "Caught Assertion in " << redact(logicalOpToString(curOp->getLogicalOp()))
- << ": " << curOp->debug().errInfo.toString();
+ LOGV2_DEBUG(
+ 20886,
+ 3,
+ "Caught Assertion in {logicalOpToString_curOp_getLogicalOp}: {curOp_debug_errInfo}",
+ "logicalOpToString_curOp_getLogicalOp"_attr =
+ redact(logicalOpToString(curOp->getLogicalOp())),
+ "curOp_debug_errInfo"_attr = curOp->debug().errInfo.toString());
}
// Mark the op as complete, and log it if appropriate. Returns a boolean indicating whether
@@ -147,7 +153,7 @@ void finishCurOp(OperationContext* opCtx, CurOp* curOp) {
// We need to ignore all errors here. We don't want a successful op to fail because of a
// failure to record stats. We also don't want to replace the error reported for an op that
// is failing.
- log() << "Ignoring error from finishCurOp: " << redact(ex);
+ LOGV2(20887, "Ignoring error from finishCurOp: {ex}", "ex"_attr = redact(ex));
}
}
@@ -168,7 +174,11 @@ public:
// guard to fire in that case. Operations on the local DB aren't replicated, so they
// don't need to bump the lastOp.
replClientInfo().setLastOpToSystemLastOpTimeIgnoringInterrupt(_opCtx);
- LOG(5) << "Set last op to system time: " << replClientInfo().getLastOp().getTimestamp();
+ LOGV2_DEBUG(20888,
+ 5,
+ "Set last op to system time: {replClientInfo_getLastOp_getTimestamp}",
+ "replClientInfo_getLastOp_getTimestamp"_attr =
+ replClientInfo().getLastOp().getTimestamp());
}
}
@@ -375,10 +385,11 @@ bool insertBatchAndHandleErrors(OperationContext* opCtx,
opCtx,
"hangDuringBatchInsert",
[&wholeOp]() {
- log() << "batch insert - hangDuringBatchInsert fail point enabled for namespace "
- << wholeOp.getNamespace()
- << ". Blocking "
- "until fail point is disabled.";
+ LOGV2(20889,
+ "batch insert - hangDuringBatchInsert fail point enabled for namespace "
+ "{wholeOp_getNamespace}. Blocking "
+ "until fail point is disabled.",
+ "wholeOp_getNamespace"_attr = wholeOp.getNamespace());
},
true, // Check for interrupt periodically.
wholeOp.getNamespace());
@@ -609,9 +620,11 @@ static SingleWriteResult performSingleUpdateOp(OperationContext* opCtx,
opCtx,
"hangDuringBatchUpdate",
[&ns]() {
- log() << "batch update - hangDuringBatchUpdate fail point enabled for nss " << ns
- << ". Blocking until "
- "fail point is disabled.";
+ LOGV2(20890,
+ "batch update - hangDuringBatchUpdate fail point enabled for nss {ns}. Blocking "
+ "until "
+ "fail point is disabled.",
+ "ns"_attr = ns);
},
false /*checkForInterrupt*/,
ns);
@@ -862,8 +875,9 @@ static SingleWriteResult performSingleDeleteOp(OperationContext* opCtx,
opCtx,
"hangDuringBatchRemove",
[]() {
- log() << "batch remove - hangDuringBatchRemove fail point enabled. Blocking "
- "until fail point is disabled.";
+ LOGV2(20891,
+ "batch remove - hangDuringBatchRemove fail point enabled. Blocking "
+ "until fail point is disabled.");
},
true // Check for interrupt periodically.
);
diff --git a/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp b/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp
index 12d931edc4c..975a225a7fd 100644
--- a/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp
+++ b/src/mongo/db/periodic_runner_job_abort_expired_transactions.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/db/transaction_participant_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/periodic_runner.h"
@@ -108,15 +109,18 @@ void PeriodicThreadToAbortExpiredTransactions::_init(ServiceContext* serviceCont
_anchor = std::make_shared<PeriodicJobAnchor>(periodicRunner->makeJob(std::move(job)));
- TransactionParticipant::observeTransactionLifetimeLimitSeconds.addObserver(
- [anchor = _anchor](const Argument& secs) {
- try {
- anchor->setPeriod(getPeriod(secs));
- } catch (const DBException& ex) {
- log() << "Failed to update period of thread which aborts expired transactions "
- << ex.toStatus();
- }
- });
+ TransactionParticipant::observeTransactionLifetimeLimitSeconds.addObserver([anchor = _anchor](
+ const Argument&
+ secs) {
+ try {
+ anchor->setPeriod(getPeriod(secs));
+ } catch (const DBException& ex) {
+ LOGV2(
+ 20892,
+ "Failed to update period of thread which aborts expired transactions {ex_toStatus}",
+ "ex_toStatus"_attr = ex.toStatus());
+ }
+ });
}
} // namespace mongo
diff --git a/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp b/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
index 3f9010eb08d..5d99a62f91b 100644
--- a/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
+++ b/src/mongo/db/periodic_runner_job_decrease_snapshot_cache_pressure.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/snapshot_window_options.h"
#include "mongo/db/snapshot_window_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/periodic_runner.h"
@@ -82,9 +83,11 @@ void PeriodicThreadToDecreaseSnapshotHistoryCachePressure::_init(ServiceContext*
SnapshotWindowUtil::decreaseTargetSnapshotWindowSize(opCtx.get());
} catch (const DBException& ex) {
if (!ErrorCodes::isShutdownError(ex.toStatus().code())) {
- warning() << "Periodic task to check for and decrease cache pressure caused by "
- "maintaining too much snapshot history failed! Caused by: "
- << ex.toStatus();
+ LOGV2_WARNING(
+ 20894,
+ "Periodic task to check for and decrease cache pressure caused by "
+ "maintaining too much snapshot history failed! Caused by: {ex_toStatus}",
+ "ex_toStatus"_attr = ex.toStatus());
}
}
},
@@ -97,9 +100,10 @@ void PeriodicThreadToDecreaseSnapshotHistoryCachePressure::_init(ServiceContext*
try {
anchor->setPeriod(Seconds(secs));
} catch (const DBException& ex) {
- log() << "Failed to update the period of the thread which decreases data history cache "
- "target size if there is cache pressure."
- << ex.toStatus();
+ LOGV2(20893,
+ "Failed to update the period of the thread which decreases data history cache "
+ "target size if there is cache pressure.{ex_toStatus}",
+ "ex_toStatus"_attr = ex.toStatus());
}
});
}
diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp
index bf576960b20..ef90138a584 100644
--- a/src/mongo/db/pipeline/document_source_cursor.cpp
+++ b/src/mongo/db/pipeline/document_source_cursor.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/query/explain.h"
#include "mongo/db/query/find_common.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -80,7 +81,8 @@ void DocumentSourceCursor::loadBatch() {
}
while (MONGO_unlikely(hangBeforeDocumentSourceCursorLoadBatch.shouldFail())) {
- log() << "Hanging aggregation due to 'hangBeforeDocumentSourceCursorLoadBatch' failpoint";
+ LOGV2(20895,
+ "Hanging aggregation due to 'hangBeforeDocumentSourceCursorLoadBatch' failpoint");
sleepmillis(10);
}
diff --git a/src/mongo/db/pipeline/document_source_exchange.cpp b/src/mongo/db/pipeline/document_source_exchange.cpp
index 9e8e37e97cd..8c7b990ba78 100644
--- a/src/mongo/db/pipeline/document_source_exchange.cpp
+++ b/src/mongo/db/pipeline/document_source_exchange.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/hasher.h"
#include "mongo/db/pipeline/document_source_exchange.h"
#include "mongo/db/storage/key_string.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -302,7 +303,8 @@ DocumentSource::GetNextResult Exchange::getNext(OperationContext* opCtx,
// There is not any document so try to load more from the source.
if (_loadingThreadId == kInvalidThreadId) {
- LOG(3) << "A consumer " << consumerId << " begins loading";
+ LOGV2_DEBUG(
+ 20896, 3, "A consumer {consumerId} begins loading", "consumerId"_attr = consumerId);
try {
// This consumer won the race and will fill the buffers.
@@ -316,7 +318,7 @@ DocumentSource::GetNextResult Exchange::getNext(OperationContext* opCtx,
size_t fullConsumerId = loadNextBatch();
if (MONGO_unlikely(exchangeFailLoadNextBatch.shouldFail())) {
- log() << "exchangeFailLoadNextBatch fail point enabled.";
+ LOGV2(20897, "exchangeFailLoadNextBatch fail point enabled.");
uasserted(ErrorCodes::FailPointEnabled,
"Asserting on loading the next batch due to failpoint.");
}
diff --git a/src/mongo/db/pipeline/document_source_exchange_test.cpp b/src/mongo/db/pipeline/document_source_exchange_test.cpp
index 65ab3f8b4a4..539cbc5cef9 100644
--- a/src/mongo/db/pipeline/document_source_exchange_test.cpp
+++ b/src/mongo/db/pipeline/document_source_exchange_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/db/hasher.h"
@@ -36,11 +38,13 @@
#include "mongo/db/storage/key_string.h"
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/concurrency/thread_pool.h"
+#include "mongo/util/log.h"
#include "mongo/util/system_clock_source.h"
#include "mongo/util/time_support.h"
@@ -117,7 +121,7 @@ protected:
static auto getNewSeed() {
auto seed = Date_t::now().asInt64();
- unittest::log() << "Generated new seed is " << seed;
+ LOGV2(20898, "Generated new seed is {seed}", "seed"_attr = seed);
return seed;
}
diff --git a/src/mongo/db/pipeline/document_source_match_test.cpp b/src/mongo/db/pipeline/document_source_match_test.cpp
index cb4821161fd..9873ba1c55b 100644
--- a/src/mongo/db/pipeline/document_source_match_test.cpp
+++ b/src/mongo/db/pipeline/document_source_match_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <string>
@@ -40,8 +42,10 @@
#include "mongo/db/pipeline/document_source_match.h"
#include "mongo/db/pipeline/document_source_mock.h"
#include "mongo/db/pipeline/pipeline.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace {
@@ -59,7 +63,7 @@ TEST_F(DocumentSourceMatchTest, RedactSafePortion) {
auto match = DocumentSourceMatch::create(fromjson(input), expCtx);
ASSERT_BSONOBJ_EQ(match->redactSafePortion(), fromjson(safePortion));
} catch (...) {
- unittest::log() << "Problem with redactSafePortion() of: " << input;
+ LOGV2(20899, "Problem with redactSafePortion() of: {input}", "input"_attr = input);
throw;
}
};
diff --git a/src/mongo/db/pipeline/document_source_merge.cpp b/src/mongo/db/pipeline/document_source_merge.cpp
index bc3239eb726..ad68c53598c 100644
--- a/src/mongo/db/pipeline/document_source_merge.cpp
+++ b/src/mongo/db/pipeline/document_source_merge.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/curop_failpoint_helpers.h"
#include "mongo/db/ops/write_ops.h"
#include "mongo/db/pipeline/document_path_support.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -487,8 +488,9 @@ void DocumentSourceMerge::waitWhileFailPointEnabled() {
pExpCtx->opCtx,
"hangWhileBuildingDocumentSourceMergeBatch",
[]() {
- log() << "Hanging aggregation due to 'hangWhileBuildingDocumentSourceMergeBatch' "
- << "failpoint";
+ LOGV2(
+ 20900,
+ "Hanging aggregation due to 'hangWhileBuildingDocumentSourceMergeBatch' failpoint");
});
}
diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp
index 67df77f760c..93122dac504 100644
--- a/src/mongo/db/pipeline/document_source_out.cpp
+++ b/src/mongo/db/pipeline/document_source_out.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/curop_failpoint_helpers.h"
#include "mongo/db/ops/write_ops.h"
#include "mongo/db/pipeline/document_path_support.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/destructor_guard.h"
#include "mongo/util/fail_point.h"
@@ -152,8 +153,8 @@ void DocumentSourceOut::initialize() {
pExpCtx->opCtx,
"outWaitAfterTempCollectionCreation",
[]() {
- log() << "Hanging aggregation due to 'outWaitAfterTempCollectionCreation' "
- << "failpoint";
+ LOGV2(20901,
+ "Hanging aggregation due to 'outWaitAfterTempCollectionCreation' failpoint");
});
if (_originalIndexes.empty()) {
return;
@@ -245,8 +246,8 @@ void DocumentSourceOut::waitWhileFailPointEnabled() {
pExpCtx->opCtx,
"hangWhileBuildingDocumentSourceOutBatch",
[]() {
- log() << "Hanging aggregation due to 'hangWhileBuildingDocumentSourceOutBatch' "
- << "failpoint";
+ LOGV2(20902,
+ "Hanging aggregation due to 'hangWhileBuildingDocumentSourceOutBatch' failpoint");
});
}
diff --git a/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp b/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp
index 09e4b1fc148..64ca6cdf86b 100644
--- a/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp
+++ b/src/mongo/db/pipeline/document_source_sample_from_random_cursor.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/exec/document_value/value.h"
#include "mongo/db/pipeline/expression.h"
#include "mongo/db/pipeline/expression_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -121,8 +122,10 @@ DocumentSource::GetNextResult DocumentSourceSampleFromRandomCursor::getNextNonDu
if (_seenDocs.insert(std::move(idField)).second) {
return nextInput;
}
- LOG(1) << "$sample encountered duplicate document: "
- << nextInput.getDocument().toString();
+ LOGV2_DEBUG(20903,
+ 1,
+ "$sample encountered duplicate document: {nextInput_getDocument}",
+ "nextInput_getDocument"_attr = nextInput.getDocument().toString());
break; // Try again with the next document.
}
case GetNextResult::ReturnStatus::kPauseExecution: {
diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
index d6d3569e5a8..e288214f60d 100644
--- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp
+++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp
@@ -49,6 +49,7 @@
#include "mongo/db/pipeline/lite_parsed_pipeline.h"
#include "mongo/db/pipeline/semantic_analysis.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/query/cluster_query_knobs_gen.h"
@@ -171,7 +172,10 @@ std::vector<RemoteCursor> establishShardCursors(
const std::set<ShardId>& shardIds,
const BSONObj& cmdObj,
const ReadPreferenceSetting& readPref) {
- LOG(1) << "Dispatching command " << redact(cmdObj) << " to establish cursors on shards";
+ LOGV2_DEBUG(20904,
+ 1,
+ "Dispatching command {cmdObj} to establish cursors on shards",
+ "cmdObj"_attr = redact(cmdObj));
const bool mustRunOnAll = mustRunOnAllShards(nss, hasChangeStream);
std::vector<std::pair<ShardId, BSONObj>> requests;
@@ -204,8 +208,9 @@ std::vector<RemoteCursor> establishShardCursors(
}
if (MONGO_unlikely(shardedAggregateHangBeforeEstablishingShardCursors.shouldFail())) {
- log() << "shardedAggregateHangBeforeEstablishingShardCursors fail point enabled. Blocking "
- "until fail point is disabled.";
+ LOGV2(20905,
+ "shardedAggregateHangBeforeEstablishingShardCursors fail point enabled. Blocking "
+ "until fail point is disabled.");
while (MONGO_unlikely(shardedAggregateHangBeforeEstablishingShardCursors.shouldFail())) {
sleepsecs(1);
}
@@ -754,10 +759,13 @@ DispatchShardPipelineResults dispatchShardPipeline(
boost::optional<SplitPipeline> splitPipelines;
if (needsSplit) {
- LOG(5) << "Splitting pipeline: "
- << "targeting = " << shardIds.size()
- << " shards, needsMongosMerge = " << needsMongosMerge
- << ", needsPrimaryShardMerge = " << needsPrimaryShardMerge;
+ LOGV2_DEBUG(20906,
+ 5,
+ "Splitting pipeline: targeting = {shardIds_size} shards, needsMongosMerge = "
+ "{needsMongosMerge}, needsPrimaryShardMerge = {needsPrimaryShardMerge}",
+ "shardIds_size"_attr = shardIds.size(),
+ "needsMongosMerge"_attr = needsMongosMerge,
+ "needsPrimaryShardMerge"_attr = needsPrimaryShardMerge);
splitPipelines = splitPipeline(std::move(pipeline));
exchangeSpec = checkIfEligibleForExchange(opCtx, splitPipelines->mergePipeline.get());
diff --git a/src/mongo/db/query/collection_query_info.cpp b/src/mongo/db/query/collection_query_info.cpp
index 9d18d8175d9..2ff45ae8fe5 100644
--- a/src/mongo/db/query/collection_query_info.cpp
+++ b/src/mongo/db/query/collection_query_info.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/query/plan_cache.h"
#include "mongo/db/query/planner_ixselect.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/clock_source.h"
#include "mongo/util/log.h"
@@ -178,7 +179,10 @@ void CollectionQueryInfo::notifyOfQuery(OperationContext* opCtx,
void CollectionQueryInfo::clearQueryCache() {
const Collection* coll = get.owner(this);
- LOG(1) << coll->ns() << ": clearing plan cache - collection info cache reset";
+ LOGV2_DEBUG(20907,
+ 1,
+ "{coll_ns}: clearing plan cache - collection info cache reset",
+ "coll_ns"_attr = coll->ns());
if (nullptr != _planCache.get()) {
_planCache->clear();
}
diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp
index a87df84a6df..197475a9173 100644
--- a/src/mongo/db/query/find.cpp
+++ b/src/mongo/db/query/find.cpp
@@ -63,6 +63,7 @@
#include "mongo/db/stats/top.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/stale_exception.h"
#include "mongo/util/fail_point.h"
@@ -203,8 +204,10 @@ void generateBatch(int ntoreturn,
switch (*state) {
// Log an error message and then perform the cleanup.
case PlanExecutor::FAILURE: {
- error() << "getMore executor error, stats: "
- << redact(Explain::getWinningPlanStats(exec));
+ LOGV2_ERROR(20918,
+ "getMore executor error, stats: {Explain_getWinningPlanStats_exec}",
+ "Explain_getWinningPlanStats_exec"_attr =
+ redact(Explain::getWinningPlanStats(exec)));
// We should always have a valid status object by this point.
auto status = WorkingSetCommon::getMemberObjectStatus(doc);
invariant(!status.isOK());
@@ -244,7 +247,7 @@ Message getMore(OperationContext* opCtx,
bool* isCursorAuthorized) {
invariant(ntoreturn >= 0);
- LOG(5) << "Running getMore, cursorid: " << cursorid;
+ LOGV2_DEBUG(20909, 5, "Running getMore, cursorid: {cursorid}", "cursorid"_attr = cursorid);
CurOp& curOp = *CurOp::get(opCtx);
curOp.ensureStarted();
@@ -525,8 +528,11 @@ Message getMore(OperationContext* opCtx,
cursorid = 0;
curOp.debug().cursorExhausted = true;
- LOG(5) << "getMore NOT saving client cursor, ended with state "
- << PlanExecutor::statestr(state);
+ LOGV2_DEBUG(
+ 20910,
+ 5,
+ "getMore NOT saving client cursor, ended with state {PlanExecutor_statestr_state}",
+ "PlanExecutor_statestr_state"_attr = PlanExecutor::statestr(state));
} else {
cursorFreer.dismiss();
// Continue caching the ClientCursor.
@@ -534,7 +540,10 @@ Message getMore(OperationContext* opCtx,
cursorPin->incNBatches();
exec->saveState();
exec->detachFromOperationContext();
- LOG(5) << "getMore saving client cursor ended with state " << PlanExecutor::statestr(state);
+ LOGV2_DEBUG(20911,
+ 5,
+ "getMore saving client cursor ended with state {PlanExecutor_statestr_state}",
+ "PlanExecutor_statestr_state"_attr = PlanExecutor::statestr(state));
// Set 'exhaust' if the client requested exhaust and the cursor is not exhausted.
*exhaust = opCtx->isExhaust();
@@ -567,7 +576,8 @@ Message getMore(OperationContext* opCtx,
qr.setCursorId(cursorid);
qr.setStartingFrom(startingResult);
qr.setNReturned(numResults);
- LOG(5) << "getMore returned " << numResults << " results\n";
+ LOGV2_DEBUG(
+ 20912, 5, "getMore returned {numResults} results\n", "numResults"_attr = numResults);
return Message(bb.release());
}
@@ -605,8 +615,9 @@ bool runQuery(OperationContext* opCtx,
"Can't canonicalize query");
invariant(cq.get());
- LOG(5) << "Running query:\n" << redact(cq->toString());
- LOG(2) << "Running query: " << redact(cq->toStringShort());
+ LOGV2_DEBUG(20913, 5, "Running query:\n{cq}", "cq"_attr = redact(cq->toString()));
+ LOGV2_DEBUG(
+ 20914, 2, "Running query: {cq_Short}", "cq_Short"_attr = redact(cq->toStringShort()));
// Parse, canonicalize, plan, transcribe, and get a plan executor.
AutoGetCollectionForReadCommand ctx(opCtx, nss, AutoGetCollection::ViewMode::kViewsForbidden);
@@ -704,17 +715,25 @@ bool runQuery(OperationContext* opCtx,
++numResults;
if (FindCommon::enoughForFirstBatch(qr, numResults)) {
- LOG(5) << "Enough for first batch, wantMore=" << qr.wantMore()
- << " ntoreturn=" << qr.getNToReturn().value_or(0)
- << " numResults=" << numResults;
+ LOGV2_DEBUG(20915,
+ 5,
+ "Enough for first batch, wantMore={qr_wantMore} "
+ "ntoreturn={qr_getNToReturn_value_or_0} numResults={numResults}",
+ "qr_wantMore"_attr = qr.wantMore(),
+ "qr_getNToReturn_value_or_0"_attr = qr.getNToReturn().value_or(0),
+ "numResults"_attr = numResults);
break;
}
}
// Caller expects exceptions thrown in certain cases.
if (PlanExecutor::FAILURE == state) {
- error() << "Plan executor error during find: " << PlanExecutor::statestr(state)
- << ", stats: " << redact(Explain::getWinningPlanStats(exec.get()));
+ LOGV2_ERROR(20919,
+ "Plan executor error during find: {PlanExecutor_statestr_state}, stats: "
+ "{Explain_getWinningPlanStats_exec_get}",
+ "PlanExecutor_statestr_state"_attr = PlanExecutor::statestr(state),
+ "Explain_getWinningPlanStats_exec_get"_attr =
+ redact(Explain::getWinningPlanStats(exec.get())));
uassertStatusOKWithContext(WorkingSetCommon::getMemberObjectStatus(doc),
"Executor error during OP_QUERY find");
MONGO_UNREACHABLE;
@@ -746,8 +765,11 @@ bool runQuery(OperationContext* opCtx,
});
ccId = pinnedCursor.getCursor()->cursorid();
- LOG(5) << "caching executor with cursorid " << ccId << " after returning " << numResults
- << " results";
+ LOGV2_DEBUG(20916,
+ 5,
+ "caching executor with cursorid {ccId} after returning {numResults} results",
+ "ccId"_attr = ccId,
+ "numResults"_attr = numResults);
// Set curOp.debug().exhaust if the client requested exhaust and the cursor is not
// exhausted.
@@ -768,7 +790,10 @@ bool runQuery(OperationContext* opCtx,
endQueryOp(opCtx, collection, *pinnedCursor.getCursor()->getExecutor(), numResults, ccId);
} else {
- LOG(5) << "Not caching executor but returning " << numResults << " results.";
+ LOGV2_DEBUG(20917,
+ 5,
+ "Not caching executor but returning {numResults} results.",
+ "numResults"_attr = numResults);
endQueryOp(opCtx, collection, *exec, numResults, ccId);
}
diff --git a/src/mongo/db/query/find_common.cpp b/src/mongo/db/query/find_common.cpp
index e236faccfb7..6b8a3a97b30 100644
--- a/src/mongo/db/query/find_common.cpp
+++ b/src/mongo/db/query/find_common.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/curop_failpoint_helpers.h"
#include "mongo/db/query/canonical_query.h"
#include "mongo/db/query/query_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -79,8 +80,9 @@ bool FindCommon::haveSpaceForNext(const BSONObj& nextDoc, long long numDocs, int
void FindCommon::waitInFindBeforeMakingBatch(OperationContext* opCtx, const CanonicalQuery& cq) {
auto whileWaitingFunc = [&, hasLogged = false]() mutable {
if (!std::exchange(hasLogged, true)) {
- log() << "Waiting in find before making batch for query - "
- << redact(cq.toStringShort());
+ LOGV2(20908,
+ "Waiting in find before making batch for query - {cq_Short}",
+ "cq_Short"_attr = redact(cq.toStringShort()));
}
};
diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp
index 255b814f97b..4738f0fa6be 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -87,6 +87,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/engine.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -186,9 +187,14 @@ IndexEntry indexEntryFromIndexCatalogEntry(OperationContext* opCtx,
multikeyPathSet = accessMethod->getMultikeyPathSet(opCtx, &mkAccessStats);
}
- LOG(2) << "Multikey path metadata range index scan stats: { index: "
- << desc->indexName() << ", numSeeks: " << mkAccessStats.keysExamined
- << ", keysExamined: " << mkAccessStats.keysExamined << "}";
+ LOGV2_DEBUG(20920,
+ 2,
+ "Multikey path metadata range index scan stats: {{ index: "
+ "{desc_indexName}, numSeeks: {mkAccessStats_keysExamined}, keysExamined: "
+ "{mkAccessStats_keysExamined2}}}",
+ "desc_indexName"_attr = desc->indexName(),
+ "mkAccessStats_keysExamined"_attr = mkAccessStats.keysExamined,
+ "mkAccessStats_keysExamined2"_attr = mkAccessStats.keysExamined);
}
}
@@ -358,8 +364,11 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
// This can happen as we're called by internal clients as well.
if (nullptr == collection) {
const string& ns = canonicalQuery->ns();
- LOG(2) << "Collection " << ns << " does not exist."
- << " Using EOF plan: " << redact(canonicalQuery->toStringShort());
+ LOGV2_DEBUG(20921,
+ 2,
+ "Collection {ns} does not exist. Using EOF plan: {canonicalQuery_Short}",
+ "ns"_attr = ns,
+ "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()));
root = std::make_unique<EOFStage>(opCtx);
return PrepareExecutionResult(std::move(canonicalQuery), nullptr, std::move(root));
}
@@ -380,7 +389,10 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
// If we have an _id index we can use an idhack plan.
if (descriptor && IDHackStage::supportsQuery(collection, *canonicalQuery)) {
- LOG(2) << "Using idhack: " << redact(canonicalQuery->toStringShort());
+ LOGV2_DEBUG(20922,
+ 2,
+ "Using idhack: {canonicalQuery_Short}",
+ "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()));
root = std::make_unique<IDHackStage>(opCtx, canonicalQuery.get(), ws, descriptor);
@@ -473,7 +485,11 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
auto querySolution = std::move(statusWithQs.getValue());
if ((plannerParams.options & QueryPlannerParams::IS_COUNT) &&
turnIxscanIntoCount(querySolution.get())) {
- LOG(2) << "Using fast count: " << redact(canonicalQuery->toStringShort());
+ LOGV2_DEBUG(20923,
+ 2,
+ "Using fast count: {canonicalQuery_Short}",
+ "canonicalQuery_Short"_attr =
+ redact(canonicalQuery->toStringShort()));
}
auto root =
@@ -499,7 +515,10 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
if (internalQueryPlanOrChildrenIndependently.load() &&
SubplanStage::canUseSubplanning(*canonicalQuery)) {
- LOG(2) << "Running query as sub-queries: " << redact(canonicalQuery->toStringShort());
+ LOGV2_DEBUG(20924,
+ 2,
+ "Running query as sub-queries: {canonicalQuery_Short}",
+ "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()));
root = std::make_unique<SubplanStage>(
opCtx, collection, ws, plannerParams, canonicalQuery.get());
@@ -524,8 +543,13 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
auto root =
StageBuilder::build(opCtx, collection, *canonicalQuery, *solutions[i], ws);
- LOG(2) << "Using fast count: " << redact(canonicalQuery->toStringShort())
- << ", planSummary: " << Explain::getPlanSummary(root.get());
+ LOGV2_DEBUG(20925,
+ 2,
+ "Using fast count: {canonicalQuery_Short}, planSummary: "
+ "{Explain_getPlanSummary_root_get}",
+ "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()),
+ "Explain_getPlanSummary_root_get"_attr =
+ Explain::getPlanSummary(root.get()));
return PrepareExecutionResult(
std::move(canonicalQuery), std::move(solutions[i]), std::move(root));
@@ -537,9 +561,12 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx,
// Only one possible plan. Run it. Build the stages from the solution.
auto root = StageBuilder::build(opCtx, collection, *canonicalQuery, *solutions[0], ws);
- LOG(2) << "Only one plan is available; it will be run but will not be cached. "
- << redact(canonicalQuery->toStringShort())
- << ", planSummary: " << Explain::getPlanSummary(root.get());
+ LOGV2_DEBUG(20926,
+ 2,
+ "Only one plan is available; it will be run but will not be cached. "
+ "{canonicalQuery_Short}, planSummary: {Explain_getPlanSummary_root_get}",
+ "canonicalQuery_Short"_attr = redact(canonicalQuery->toStringShort()),
+ "Explain_getPlanSummary_root_get"_attr = Explain::getPlanSummary(root.get()));
return PrepareExecutionResult(
std::move(canonicalQuery), std::move(solutions[0]), std::move(root));
@@ -731,8 +758,11 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorDelete(
if (!collection) {
// Treat collections that do not exist as empty collections. Return a PlanExecutor which
// contains an EOF stage.
- LOG(2) << "Collection " << nss.ns() << " does not exist."
- << " Using EOF stage: " << redact(request->getQuery());
+ LOGV2_DEBUG(20927,
+ 2,
+ "Collection {nss_ns} does not exist. Using EOF stage: {request_getQuery}",
+ "nss_ns"_attr = nss.ns(),
+ "request_getQuery"_attr = redact(request->getQuery()));
return PlanExecutor::make(
opCtx, std::move(ws), std::make_unique<EOFStage>(opCtx), nullptr, policy, nss);
}
@@ -759,7 +789,10 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorDelete(
if (descriptor && CanonicalQuery::isSimpleIdQuery(unparsedQuery) &&
request->getProj().isEmpty() && hasCollectionDefaultCollation) {
- LOG(2) << "Using idhack: " << redact(unparsedQuery);
+ LOGV2_DEBUG(20928,
+ 2,
+ "Using idhack: {unparsedQuery}",
+ "unparsedQuery"_attr = redact(unparsedQuery));
auto idHackStage = std::make_unique<IDHackStage>(
opCtx, unparsedQuery["_id"].wrap(), ws.get(), descriptor);
@@ -880,8 +913,11 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorUpdate(
// we are an explain. If the collection doesn't exist, we're not an explain, and the upsert flag
// is true, we expect the caller to have created the collection already.
if (!collection) {
- LOG(2) << "Collection " << nss.ns() << " does not exist."
- << " Using EOF stage: " << redact(request->getQuery());
+ LOGV2_DEBUG(20929,
+ 2,
+ "Collection {nss_ns} does not exist. Using EOF stage: {request_getQuery}",
+ "nss_ns"_attr = nss.ns(),
+ "request_getQuery"_attr = redact(request->getQuery()));
return PlanExecutor::make(
opCtx, std::move(ws), std::make_unique<EOFStage>(opCtx), nullptr, policy, nss);
}
@@ -906,7 +942,10 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorUpdate(
if (descriptor && CanonicalQuery::isSimpleIdQuery(unparsedQuery) &&
request->getProj().isEmpty() && hasCollectionDefaultCollation) {
- LOG(2) << "Using idhack: " << redact(unparsedQuery);
+ LOGV2_DEBUG(20930,
+ 2,
+ "Using idhack: {unparsedQuery}",
+ "unparsedQuery"_attr = redact(unparsedQuery));
// Working set 'ws' is discarded. InternalPlanner::updateWithIdHack() makes its own
// WorkingSet.
@@ -1507,8 +1546,13 @@ StatusWith<std::unique_ptr<PlanExecutor, PlanExecutor::Deleter>> getExecutorForS
auto root =
StageBuilder::build(opCtx, collection, *parsedDistinct->getQuery(), *soln, ws.get());
- LOG(2) << "Using fast distinct: " << redact(parsedDistinct->getQuery()->toStringShort())
- << ", planSummary: " << Explain::getPlanSummary(root.get());
+ LOGV2_DEBUG(20931,
+ 2,
+ "Using fast distinct: {parsedDistinct_getQuery_Short}, planSummary: "
+ "{Explain_getPlanSummary_root_get}",
+ "parsedDistinct_getQuery_Short"_attr =
+ redact(parsedDistinct->getQuery()->toStringShort()),
+ "Explain_getPlanSummary_root_get"_attr = Explain::getPlanSummary(root.get()));
return PlanExecutor::make(parsedDistinct->releaseQuery(),
std::move(ws),
@@ -1548,8 +1592,14 @@ getExecutorDistinctFromIndexSolutions(OperationContext* opCtx,
auto root = StageBuilder::build(
opCtx, collection, *parsedDistinct->getQuery(), *currentSolution, ws.get());
- LOG(2) << "Using fast distinct: " << redact(parsedDistinct->getQuery()->toStringShort())
- << ", planSummary: " << Explain::getPlanSummary(root.get());
+ LOGV2_DEBUG(20932,
+ 2,
+ "Using fast distinct: {parsedDistinct_getQuery_Short}, planSummary: "
+ "{Explain_getPlanSummary_root_get}",
+ "parsedDistinct_getQuery_Short"_attr =
+ redact(parsedDistinct->getQuery()->toStringShort()),
+ "Explain_getPlanSummary_root_get"_attr =
+ Explain::getPlanSummary(root.get()));
return PlanExecutor::make(parsedDistinct->releaseQuery(),
std::move(ws),
diff --git a/src/mongo/db/query/index_bounds_builder.cpp b/src/mongo/db/query/index_bounds_builder.cpp
index 1e3a5bf9d47..9bb746228e1 100644
--- a/src/mongo/db/query/index_bounds_builder.cpp
+++ b/src/mongo/db/query/index_bounds_builder.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/query/planner_ixselect.h"
#include "mongo/db/query/planner_wildcard_helpers.h"
#include "mongo/db/query/query_knobs_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
#include "third_party/s2/s2cell.h"
@@ -887,13 +888,15 @@ void IndexBoundsBuilder::_translatePredicate(const MatchExpression* expr,
*tightnessOut = IndexBoundsBuilder::INEXACT_FETCH;
} else {
- warning() << "Planner error trying to build geo bounds for " << elt.toString()
- << " index element.";
+ LOGV2_WARNING(20934,
+ "Planner error trying to build geo bounds for {elt} index element.",
+ "elt"_attr = elt.toString());
verify(0);
}
} else {
- warning() << "Planner error, trying to build bounds for expression: "
- << redact(expr->debugString());
+ LOGV2_WARNING(20935,
+ "Planner error, trying to build bounds for expression: {expr_debugString}",
+ "expr_debugString"_attr = redact(expr->debugString()));
verify(0);
}
}
@@ -1198,9 +1201,11 @@ void IndexBoundsBuilder::alignBounds(IndexBounds* bounds, const BSONObj& kp, int
}
if (!bounds->isValidFor(kp, scanDir)) {
- log() << "INVALID BOUNDS: " << redact(bounds->toString()) << endl
- << "kp = " << redact(kp) << endl
- << "scanDir = " << scanDir;
+ LOGV2(20933,
+ "INVALID BOUNDS: {bounds}\nkp = {kp}\nscanDir = {scanDir}",
+ "bounds"_attr = redact(bounds->toString()),
+ "kp"_attr = redact(kp),
+ "scanDir"_attr = scanDir);
MONGO_UNREACHABLE;
}
}
diff --git a/src/mongo/db/query/plan_cache.cpp b/src/mongo/db/query/plan_cache.cpp
index 9d03e0b1012..5e25131d41f 100644
--- a/src/mongo/db/query/plan_cache.cpp
+++ b/src/mongo/db/query/plan_cache.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/query/planner_ixselect.h"
#include "mongo/db/query/query_knobs_gen.h"
#include "mongo/db/query/query_solution.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
@@ -438,8 +439,10 @@ std::unique_ptr<CachedSolution> PlanCache::getCacheEntryIfActive(const PlanCache
PlanCache::GetResult res = get(key);
if (res.state == PlanCache::CacheEntryState::kPresentInactive) {
- LOG(2) << "Not using cached entry for " << redact(res.cachedSolution->toString())
- << " since it is inactive";
+ LOGV2_DEBUG(20936,
+ 2,
+ "Not using cached entry for {res_cachedSolution} since it is inactive",
+ "res_cachedSolution"_attr = redact(res.cachedSolution->toString()));
return nullptr;
}
@@ -460,9 +463,17 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query
double growthCoefficient) {
NewEntryState res;
if (!oldEntry) {
- LOG(1) << "Creating inactive cache entry for query shape " << redact(query.toStringShort())
- << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey "
- << unsignedIntToFixedLengthHex(planCacheKey) << " with works value " << newWorks;
+ LOGV2_DEBUG(20937,
+ 1,
+ "Creating inactive cache entry for query shape {query_Short} queryHash "
+ "{unsignedIntToFixedLengthHex_queryHash} planCacheKey "
+ "{unsignedIntToFixedLengthHex_planCacheKey} with works value {newWorks}",
+ "query_Short"_attr = redact(query.toStringShort()),
+ "unsignedIntToFixedLengthHex_queryHash"_attr =
+ unsignedIntToFixedLengthHex(queryHash),
+ "unsignedIntToFixedLengthHex_planCacheKey"_attr =
+ unsignedIntToFixedLengthHex(planCacheKey),
+ "newWorks"_attr = newWorks);
res.shouldBeCreated = true;
res.shouldBeActive = false;
return res;
@@ -472,18 +483,35 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query
// The new plan did better than the currently stored active plan. This case may
// occur if many MultiPlanners are run simultaneously.
- LOG(1) << "Replacing active cache entry for query " << redact(query.toStringShort())
- << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey "
- << unsignedIntToFixedLengthHex(planCacheKey) << " with works " << oldEntry->works
- << " with a plan with works " << newWorks;
+ LOGV2_DEBUG(20938,
+ 1,
+ "Replacing active cache entry for query {query_Short} queryHash "
+ "{unsignedIntToFixedLengthHex_queryHash} planCacheKey "
+ "{unsignedIntToFixedLengthHex_planCacheKey} with works {oldEntry_works} with a "
+ "plan with works {newWorks}",
+ "query_Short"_attr = redact(query.toStringShort()),
+ "unsignedIntToFixedLengthHex_queryHash"_attr =
+ unsignedIntToFixedLengthHex(queryHash),
+ "unsignedIntToFixedLengthHex_planCacheKey"_attr =
+ unsignedIntToFixedLengthHex(planCacheKey),
+ "oldEntry_works"_attr = oldEntry->works,
+ "newWorks"_attr = newWorks);
res.shouldBeCreated = true;
res.shouldBeActive = true;
} else if (oldEntry->isActive) {
- LOG(1) << "Attempt to write to the planCache for query " << redact(query.toStringShort())
- << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey "
- << unsignedIntToFixedLengthHex(planCacheKey) << " with a plan with works "
- << newWorks << " is a noop, since there's already a plan with works value "
- << oldEntry->works;
+ LOGV2_DEBUG(20939,
+ 1,
+ "Attempt to write to the planCache for query {query_Short} queryHash "
+ "{unsignedIntToFixedLengthHex_queryHash} planCacheKey "
+ "{unsignedIntToFixedLengthHex_planCacheKey} with a plan with works {newWorks} "
+ "is a noop, since there's already a plan with works value {oldEntry_works}",
+ "query_Short"_attr = redact(query.toStringShort()),
+ "unsignedIntToFixedLengthHex_queryHash"_attr =
+ unsignedIntToFixedLengthHex(queryHash),
+ "unsignedIntToFixedLengthHex_planCacheKey"_attr =
+ unsignedIntToFixedLengthHex(planCacheKey),
+ "newWorks"_attr = newWorks,
+ "oldEntry_works"_attr = oldEntry->works);
// There is already an active cache entry with a higher works value.
// We do nothing.
res.shouldBeCreated = false;
@@ -499,11 +527,18 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query
const double increasedWorks = std::max(
oldEntry->works + 1u, static_cast<size_t>(oldEntry->works * growthCoefficient));
- LOG(1) << "Increasing work value associated with cache entry for query "
- << redact(query.toStringShort()) << " queryHash "
- << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey "
- << unsignedIntToFixedLengthHex(planCacheKey) << " from " << oldEntry->works << " to "
- << increasedWorks;
+ LOGV2_DEBUG(
+ 20940,
+ 1,
+ "Increasing work value associated with cache entry for query {query_Short} queryHash "
+ "{unsignedIntToFixedLengthHex_queryHash} planCacheKey "
+ "{unsignedIntToFixedLengthHex_planCacheKey} from {oldEntry_works} to {increasedWorks}",
+ "query_Short"_attr = redact(query.toStringShort()),
+ "unsignedIntToFixedLengthHex_queryHash"_attr = unsignedIntToFixedLengthHex(queryHash),
+ "unsignedIntToFixedLengthHex_planCacheKey"_attr =
+ unsignedIntToFixedLengthHex(planCacheKey),
+ "oldEntry_works"_attr = oldEntry->works,
+ "increasedWorks"_attr = increasedWorks);
oldEntry->works = increasedWorks;
// Don't create a new entry.
@@ -512,10 +547,19 @@ PlanCache::NewEntryState PlanCache::getNewEntryState(const CanonicalQuery& query
// This plan performed just as well or better than we expected, based on the
// inactive entry's works. We use this as an indicator that it's safe to
// cache (as an active entry) the plan this query used for the future.
- LOG(1) << "Inactive cache entry for query " << redact(query.toStringShort())
- << " queryHash " << unsignedIntToFixedLengthHex(queryHash) << " planCacheKey "
- << unsignedIntToFixedLengthHex(planCacheKey) << " with works " << oldEntry->works
- << " is being promoted to active entry with works value " << newWorks;
+ LOGV2_DEBUG(20941,
+ 1,
+ "Inactive cache entry for query {query_Short} queryHash "
+ "{unsignedIntToFixedLengthHex_queryHash} planCacheKey "
+ "{unsignedIntToFixedLengthHex_planCacheKey} with works {oldEntry_works} is "
+ "being promoted to active entry with works value {newWorks}",
+ "query_Short"_attr = redact(query.toStringShort()),
+ "unsignedIntToFixedLengthHex_queryHash"_attr =
+ unsignedIntToFixedLengthHex(queryHash),
+ "unsignedIntToFixedLengthHex_planCacheKey"_attr =
+ unsignedIntToFixedLengthHex(planCacheKey),
+ "oldEntry_works"_attr = oldEntry->works,
+ "newWorks"_attr = newWorks);
// We'll replace the old inactive entry with an active entry.
res.shouldBeCreated = true;
res.shouldBeActive = true;
@@ -594,8 +638,12 @@ Status PlanCache::set(const CanonicalQuery& query,
std::unique_ptr<PlanCacheEntry> evictedEntry = _cache.add(key, newEntry.release());
if (nullptr != evictedEntry.get()) {
- LOG(1) << query.nss() << ": plan cache maximum size exceeded - "
- << "removed least recently used entry " << redact(evictedEntry->toString());
+ LOGV2_DEBUG(20942,
+ 1,
+ "{query_nss}: plan cache maximum size exceeded - removed least recently used "
+ "entry {evictedEntry}",
+ "query_nss"_attr = query.nss(),
+ "evictedEntry"_attr = redact(evictedEntry->toString()));
}
return Status::OK();
diff --git a/src/mongo/db/query/plan_enumerator.cpp b/src/mongo/db/query/plan_enumerator.cpp
index f213e98c6c9..733b17056eb 100644
--- a/src/mongo/db/query/plan_enumerator.cpp
+++ b/src/mongo/db/query/plan_enumerator.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/query/index_tag.h"
#include "mongo/db/query/indexability.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/string_map.h"
@@ -340,7 +341,7 @@ PlanEnumerator::MemoID PlanEnumerator::memoIDForNode(MatchExpression* node) {
stdx::unordered_map<MatchExpression*, MemoID>::iterator it = _nodeToId.find(node);
if (_nodeToId.end() == it) {
- error() << "Trying to look up memo entry for node, none found.";
+ LOGV2_ERROR(20945, "Trying to look up memo entry for node, none found.");
MONGO_UNREACHABLE;
}
@@ -359,7 +360,8 @@ unique_ptr<MatchExpression> PlanEnumerator::getNext() {
tagForSort(tree.get());
_root->resetTag();
- LOG(5) << "Enumerator: memo just before moving:" << endl << dumpMemo();
+ LOGV2_DEBUG(
+ 20943, 5, "Enumerator: memo just before moving:\n{dumpMemo}", "dumpMemo"_attr = dumpMemo());
_done = nextMemo(memoIDForNode(_root));
return tree;
}
@@ -1568,7 +1570,7 @@ void PlanEnumerator::compound(const vector<MatchExpression*>& tryCompound,
//
void PlanEnumerator::tagMemo(size_t id) {
- LOG(5) << "Tagging memoID " << id;
+ LOGV2_DEBUG(20944, 5, "Tagging memoID {id}", "id"_attr = id);
NodeAssignment* assign = _memo[id];
verify(nullptr != assign);
diff --git a/src/mongo/db/query/plan_executor_impl.cpp b/src/mongo/db/query/plan_executor_impl.cpp
index c4e1bb83c7d..fae86c1e8ce 100644
--- a/src/mongo/db/query/plan_executor_impl.cpp
+++ b/src/mongo/db/query/plan_executor_impl.cpp
@@ -56,6 +56,7 @@
#include "mongo/db/query/plan_yield_policy.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -635,8 +636,9 @@ PlanExecutor::ExecState PlanExecutorImpl::_getNextImpl(Snapshotted<Document>* ob
}
return true;
}))) {
- log() << "PlanExecutor - planExecutorHangBeforeShouldWaitForInserts fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(20946,
+ "PlanExecutor - planExecutorHangBeforeShouldWaitForInserts fail point "
+ "enabled. Blocking until fail point is disabled.");
planExecutorHangBeforeShouldWaitForInserts.pauseWhileSet();
}
if (!_shouldWaitForInserts()) {
diff --git a/src/mongo/db/query/plan_ranker.cpp b/src/mongo/db/query/plan_ranker.cpp
index 7b998c6d583..2c5abd7cad6 100644
--- a/src/mongo/db/query/plan_ranker.cpp
+++ b/src/mongo/db/query/plan_ranker.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/query/query_knobs_gen.h"
#include "mongo/db/query/query_solution.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace {
@@ -93,25 +94,42 @@ StatusWith<std::unique_ptr<PlanRankingDecision>> PlanRanker::pickBestPlan(
// Compute score for each tree. Record the best.
for (size_t i = 0; i < statTrees.size(); ++i) {
if (!candidates[i].failed) {
- LOG(5) << "Scoring plan " << i << ":" << endl
- << redact(candidates[i].solution->toString()) << "Stats:\n"
- << redact(Explain::statsToBSON(*statTrees[i])
- .jsonString(ExtendedRelaxedV2_0_0, true));
- LOG(2) << "Scoring query plan: " << Explain::getPlanSummary(candidates[i].root)
- << " planHitEOF=" << statTrees[i]->common.isEOF;
+ LOGV2_DEBUG(
+ 20956,
+ 5,
+ "Scoring plan "
+ "{i}:\n{candidates_i_solution}Stats:\n{Explain_statsToBSON_statTrees_i_jsonString_"
+ "ExtendedRelaxedV2_0_0_true}",
+ "i"_attr = i,
+ "candidates_i_solution"_attr = redact(candidates[i].solution->toString()),
+ "Explain_statsToBSON_statTrees_i_jsonString_ExtendedRelaxedV2_0_0_true"_attr =
+ redact(Explain::statsToBSON(*statTrees[i])
+ .jsonString(ExtendedRelaxedV2_0_0, true)));
+ LOGV2_DEBUG(20957,
+ 2,
+ "Scoring query plan: {Explain_getPlanSummary_candidates_i_root} "
+ "planHitEOF={statTrees_i_common_isEOF}",
+ "Explain_getPlanSummary_candidates_i_root"_attr =
+ Explain::getPlanSummary(candidates[i].root),
+ "statTrees_i_common_isEOF"_attr = statTrees[i]->common.isEOF);
double score = scoreTree(statTrees[i].get());
- LOG(5) << "score = " << score;
+ LOGV2_DEBUG(20958, 5, "score = {score}", "score"_attr = score);
if (statTrees[i]->common.isEOF) {
- LOG(5) << "Adding +" << eofBonus << " EOF bonus to score.";
+ LOGV2_DEBUG(
+ 20959, 5, "Adding +{eofBonus} EOF bonus to score.", "eofBonus"_attr = eofBonus);
score += 1;
}
scoresAndCandidateindices.push_back(std::make_pair(score, i));
} else {
failed.push_back(i);
- LOG(2) << "Not scording plan: " << Explain::getPlanSummary(candidates[i].root)
- << " because the plan failed.";
+ LOGV2_DEBUG(20960,
+ 2,
+ "Not scording plan: {Explain_getPlanSummary_candidates_i_root} because the "
+ "plan failed.",
+ "Explain_getPlanSummary_candidates_i_root"_attr =
+ Explain::getPlanSummary(candidates[i].root));
}
}
@@ -265,14 +283,17 @@ double PlanRanker::scoreTree(const PlanStageStats* stats) {
<< str::convertDoubleToString(noSortBonus) << " noSortBonus + "
<< str::convertDoubleToString(noIxisectBonus)
<< " noIxisectBonus = " << str::convertDoubleToString(tieBreakers) << ")";
- LOG(2) << sb.str();
+ LOGV2_DEBUG(20961, 2, "{sb_str}", "sb_str"_attr = sb.str());
if (internalQueryForceIntersectionPlans.load()) {
if (hasStage(STAGE_AND_HASH, stats) || hasStage(STAGE_AND_SORTED, stats)) {
// The boost should be >2.001 to make absolutely sure the ixisect plan will win due
// to the combination of 1) productivity, 2) eof bonus, and 3) no ixisect bonus.
score += 3;
- LOG(5) << "Score boosted to " << score << " due to intersection forcing.";
+ LOGV2_DEBUG(20962,
+ 5,
+ "Score boosted to {score} due to intersection forcing.",
+ "score"_attr = score);
}
}
diff --git a/src/mongo/db/query/planner_access.cpp b/src/mongo/db/query/planner_access.cpp
index 7a09019424c..9510cc85481 100644
--- a/src/mongo/db/query/planner_access.cpp
+++ b/src/mongo/db/query/planner_access.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/query/query_knobs_gen.h"
#include "mongo/db/query/query_planner.h"
#include "mongo/db/query/query_planner_common.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/transitional_tools_do_not_use/vector_spooling.h"
@@ -1112,8 +1113,10 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::buildIndexedAnd(
} else {
// We can't use sort-based intersection, and hash-based intersection is disabled.
// Clean up the index scans and bail out by returning NULL.
- LOG(5) << "Can't build index intersection solution: "
- << "AND_SORTED is not possible and AND_HASH is disabled.";
+ LOGV2_DEBUG(20947,
+ 5,
+ "Can't build index intersection solution: AND_SORTED is not possible and "
+ "AND_HASH is disabled.");
return nullptr;
}
}
@@ -1180,7 +1183,7 @@ std::unique_ptr<QuerySolutionNode> QueryPlannerAccess::buildIndexedOr(
// when any of our children lack index tags. If a node lacks an index tag it cannot
// be answered via an index.
if (!inArrayOperator && 0 != root->numChildren()) {
- warning() << "planner OR error, non-indexed child of OR.";
+ LOGV2_WARNING(20948, "planner OR error, non-indexed child of OR.");
// We won't enumerate an OR without indices for each child, so this isn't an issue, even
// if we have an AND with an OR child -- we won't get here unless the OR is fully
// indexed.
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp
index 0dcde5c00d7..942d27d7512 100644
--- a/src/mongo/db/query/planner_analysis.cpp
+++ b/src/mongo/db/query/planner_analysis.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/matcher/expression_geo.h"
#include "mongo/db/query/query_planner.h"
#include "mongo/db/query/query_planner_common.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -344,7 +345,10 @@ std::unique_ptr<QuerySolutionNode> addSortKeyGeneratorStageIfNeeded(
std::unique_ptr<ProjectionNode> analyzeProjection(const CanonicalQuery& query,
std::unique_ptr<QuerySolutionNode> solnRoot,
const bool hasSortStage) {
- LOG(5) << "PROJECTION: Current plan is:\n" << redact(solnRoot->toString());
+ LOGV2_DEBUG(20949,
+ 5,
+ "PROJECTION: Current plan is:\n{solnRoot}",
+ "solnRoot"_attr = redact(solnRoot->toString()));
// If the projection requires the entire document we add a fetch stage if not present. Otherwise
// we add a fetch stage if we are not covered.
@@ -644,8 +648,11 @@ bool QueryPlannerAnalysis::explodeForSort(const CanonicalQuery& query,
// Too many ixscans spoil the performance.
if (totalNumScans > (size_t)internalQueryMaxScansToExplode.load()) {
- LOG(5) << "Could expand ixscans to pull out sort order but resulting scan count"
- << "(" << totalNumScans << ") is too high.";
+ LOGV2_DEBUG(20950,
+ 5,
+ "Could expand ixscans to pull out sort order but resulting scan "
+ "count({totalNumScans}) is too high.",
+ "totalNumScans"_attr = totalNumScans);
return false;
}
@@ -705,7 +712,10 @@ QuerySolutionNode* QueryPlannerAnalysis::analyzeSort(const CanonicalQuery& query
BSONObj reverseSort = QueryPlannerCommon::reverseSortObj(sortObj);
if (sorts.end() != sorts.find(reverseSort)) {
QueryPlannerCommon::reverseScans(solnRoot);
- LOG(5) << "Reversing ixscan to provide sort. Result: " << redact(solnRoot->toString());
+ LOGV2_DEBUG(20951,
+ 5,
+ "Reversing ixscan to provide sort. Result: {solnRoot}",
+ "solnRoot"_attr = redact(solnRoot->toString()));
return solnRoot;
}
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp
index b97433015f5..27ad04ac703 100644
--- a/src/mongo/db/query/planner_ixselect.cpp
+++ b/src/mongo/db/query/planner_ixselect.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/query/indexability.h"
#include "mongo/db/query/planner_wildcard_helpers.h"
#include "mongo/db/query/query_planner_common.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -287,15 +288,20 @@ std::vector<IndexEntry> QueryPlannerIXSelect::findIndexesByHint(
auto hintName = firstHintElt.valueStringData();
for (auto&& entry : allIndices) {
if (entry.identifier.catalogName == hintName) {
- LOG(5) << "Hint by name specified, restricting indices to "
- << entry.keyPattern.toString();
+ LOGV2_DEBUG(20952,
+ 5,
+ "Hint by name specified, restricting indices to {entry_keyPattern}",
+ "entry_keyPattern"_attr = entry.keyPattern.toString());
out.push_back(entry);
}
}
} else {
for (auto&& entry : allIndices) {
if (SimpleBSONObjComparator::kInstance.evaluate(entry.keyPattern == hintedIndex)) {
- LOG(5) << "Hint specified, restricting indices to " << hintedIndex.toString();
+ LOGV2_DEBUG(20953,
+ 5,
+ "Hint specified, restricting indices to {hintedIndex}",
+ "hintedIndex"_attr = hintedIndex.toString());
out.push_back(entry);
}
}
@@ -579,8 +585,10 @@ bool QueryPlannerIXSelect::_compatible(const BSONElement& keyPatternElt,
} else if (IndexNames::GEO_HAYSTACK == indexedFieldType) {
return false;
} else {
- warning() << "Unknown indexing for node " << node->debugString() << " and field "
- << keyPatternElt.toString();
+ LOGV2_WARNING(20954,
+ "Unknown indexing for node {node_debugString} and field {keyPatternElt}",
+ "node_debugString"_attr = node->debugString(),
+ "keyPatternElt"_attr = keyPatternElt.toString());
verify(0);
}
}
diff --git a/src/mongo/db/query/planner_wildcard_helpers.cpp b/src/mongo/db/query/planner_wildcard_helpers.cpp
index 4f1743d7316..c04c33e02d0 100644
--- a/src/mongo/db/query/planner_wildcard_helpers.cpp
+++ b/src/mongo/db/query/planner_wildcard_helpers.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/exec/projection_executor_utils.h"
#include "mongo/db/index/wildcard_key_generator.h"
#include "mongo/db/query/index_bounds.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -245,9 +246,14 @@ bool validateNumericPathComponents(const MultikeyPaths& multikeyPaths,
// all paths with and without array indices. Because this is O(2^n), we decline to answer
// queries that traverse more than 8 levels of array indices.
if (arrayIndices.size() > kWildcardMaxArrayIndexTraversalDepth) {
- LOG(2) << "Declining to answer query on field '" << queryPath.dottedField()
- << "' with $** index, as it traverses through more than "
- << kWildcardMaxArrayIndexTraversalDepth << " nested array indices.";
+ LOGV2_DEBUG(20955,
+ 2,
+ "Declining to answer query on field '{queryPath_dottedField}' with $** index, "
+ "as it traverses through more than {kWildcardMaxArrayIndexTraversalDepth} "
+ "nested array indices.",
+ "queryPath_dottedField"_attr = queryPath.dottedField(),
+ "kWildcardMaxArrayIndexTraversalDepth"_attr =
+ kWildcardMaxArrayIndexTraversalDepth);
return false;
}
diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
index d95ff7dd03f..966fb61275e 100644
--- a/src/mongo/db/query/query_planner.cpp
+++ b/src/mongo/db/query/query_planner.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/query/planner_ixselect.h"
#include "mongo/db/query/query_planner_common.h"
#include "mongo/db/query/query_solution.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -475,10 +476,12 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache(
// Create a copy of the expression tree. We use cachedSoln to annotate this with indices.
unique_ptr<MatchExpression> clone = query.root()->shallowClone();
- LOG(5) << "Tagging the match expression according to cache data: " << endl
- << "Filter:" << endl
- << redact(clone->debugString()) << "Cache data:" << endl
- << redact(winnerCacheData.toString());
+ LOGV2_DEBUG(20963,
+ 5,
+ "Tagging the match expression according to cache data: "
+ "\nFilter:\n{clone_debugString}Cache data:\n{winnerCacheData}",
+ "clone_debugString"_attr = redact(clone->debugString()),
+ "winnerCacheData"_attr = redact(winnerCacheData.toString()));
stdx::unordered_set<string> fields;
QueryPlannerIXSelect::getFields(query.root(), &fields);
@@ -492,7 +495,11 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache(
const auto insertionRes = indexMap.insert(std::make_pair(ie.identifier, i));
// Be sure the key was not already in the map.
invariant(insertionRes.second);
- LOG(5) << "Index " << i << ": " << ie.identifier;
+ LOGV2_DEBUG(20964,
+ 5,
+ "Index {i}: {ie_identifier}",
+ "i"_attr = i,
+ "ie_identifier"_attr = ie.identifier);
}
Status s = tagAccordingToCache(clone.get(), winnerCacheData.tree.get(), indexMap);
@@ -503,7 +510,10 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache(
// The MatchExpression tree is in canonical order. We must order the nodes for access planning.
prepareForAccessPlanning(clone.get());
- LOG(5) << "Tagged tree:" << endl << redact(clone->debugString());
+ LOGV2_DEBUG(20965,
+ 5,
+ "Tagged tree:\n{clone_debugString}",
+ "clone_debugString"_attr = redact(clone->debugString()));
// Use the cached index assignments to build solnRoot.
std::unique_ptr<QuerySolutionNode> solnRoot(QueryPlannerAccess::buildIndexedDataAccess(
@@ -522,21 +532,30 @@ StatusWith<std::unique_ptr<QuerySolution>> QueryPlanner::planFromCache(
<< "Failed to analyze plan from cache. Query: " << query.toStringShort());
}
- LOG(5) << "Planner: solution constructed from the cache:\n" << redact(soln->toString());
+ LOGV2_DEBUG(20966,
+ 5,
+ "Planner: solution constructed from the cache:\n{soln}",
+ "soln"_attr = redact(soln->toString()));
return {std::move(soln)};
}
// static
StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
const CanonicalQuery& query, const QueryPlannerParams& params) {
- LOG(5) << "Beginning planning..." << endl
- << "=============================" << endl
- << "Options = " << optionString(params.options) << endl
- << "Canonical query:" << endl
- << redact(query.toString()) << "=============================";
+ LOGV2_DEBUG(
+ 20967,
+ 5,
+ "Beginning planning...\n=============================\nOptions = "
+ "{optionString_params_options}\nCanonical query:\n{query}=============================",
+ "optionString_params_options"_attr = optionString(params.options),
+ "query"_attr = redact(query.toString()));
for (size_t i = 0; i < params.indices.size(); ++i) {
- LOG(5) << "Index " << i << " is " << params.indices[i].toString();
+ LOGV2_DEBUG(20968,
+ 5,
+ "Index {i} is {params_indices_i}",
+ "i"_attr = i,
+ "params_indices_i"_attr = params.indices[i].toString());
}
const bool canTableScan = !(params.options & QueryPlannerParams::NO_TABLE_SCAN);
@@ -572,7 +591,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
BSONElement naturalHint = dps::extractElementAtPath(hintObj, "$natural");
if (naturalHint) {
- LOG(5) << "Forcing a table scan due to hinted $natural";
+ LOGV2_DEBUG(20969, 5, "Forcing a table scan due to hinted $natural");
if (!canTableScan) {
return Status(ErrorCodes::NoQueryExecutionPlans,
"hint $natural is not allowed, because 'notablescan' is enabled");
@@ -632,7 +651,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
stdx::unordered_set<string> fields;
QueryPlannerIXSelect::getFields(query.root(), &fields);
for (auto&& field : fields) {
- LOG(5) << "Predicate over field '" << field << "'";
+ LOGV2_DEBUG(20970, 5, "Predicate over field '{field}'", "field"_attr = field);
}
fullIndexList = QueryPlannerIXSelect::expandIndexes(fields, std::move(fullIndexList));
@@ -706,7 +725,11 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
}
for (size_t i = 0; i < relevantIndices.size(); ++i) {
- LOG(2) << "Relevant index " << i << " is " << relevantIndices[i].toString();
+ LOGV2_DEBUG(20971,
+ 2,
+ "Relevant index {i} is {relevantIndices_i}",
+ "i"_attr = i,
+ "relevantIndices_i"_attr = relevantIndices[i].toString());
}
// Figure out how useful each index is to each predicate.
@@ -728,7 +751,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
}
// query.root() is now annotated with RelevantTag(s).
- LOG(5) << "Rated tree:" << endl << redact(query.root()->debugString());
+ LOGV2_DEBUG(20972,
+ 5,
+ "Rated tree:\n{query_root_debugString}",
+ "query_root_debugString"_attr = redact(query.root()->debugString()));
// If there is a GEO_NEAR it must have an index it can use directly.
const MatchExpression* gnNode = nullptr;
@@ -736,14 +762,17 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
// No index for GEO_NEAR? No query.
RelevantTag* tag = static_cast<RelevantTag*>(gnNode->getTag());
if (!tag || (0 == tag->first.size() && 0 == tag->notFirst.size())) {
- LOG(5) << "Unable to find index for $geoNear query.";
+ LOGV2_DEBUG(20973, 5, "Unable to find index for $geoNear query.");
// Don't leave tags on query tree.
query.root()->resetTag();
return Status(ErrorCodes::NoQueryExecutionPlans,
"unable to find index for $geoNear query");
}
- LOG(5) << "Rated tree after geonear processing:" << redact(query.root()->debugString());
+ LOGV2_DEBUG(20974,
+ 5,
+ "Rated tree after geonear processing:{query_root_debugString}",
+ "query_root_debugString"_attr = redact(query.root()->debugString()));
}
// Likewise, if there is a TEXT it must have an index it can use directly.
@@ -780,7 +809,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
// assigned to it.
invariant(1 == tag->first.size() + tag->notFirst.size());
- LOG(5) << "Rated tree after text processing:" << redact(query.root()->debugString());
+ LOGV2_DEBUG(20975,
+ 5,
+ "Rated tree after text processing:{query_root_debugString}",
+ "query_root_debugString"_attr = redact(query.root()->debugString()));
}
std::vector<std::unique_ptr<QuerySolution>> out;
@@ -798,8 +830,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
unique_ptr<MatchExpression> nextTaggedTree;
while ((nextTaggedTree = isp.getNext()) && (out.size() < params.maxIndexedSolutions)) {
- LOG(5) << "About to build solntree from tagged tree:" << endl
- << redact(nextTaggedTree->debugString());
+ LOGV2_DEBUG(20976,
+ 5,
+ "About to build solntree from tagged tree:\n{nextTaggedTree_debugString}",
+ "nextTaggedTree_debugString"_attr = redact(nextTaggedTree->debugString()));
// Store the plan cache index tree before calling prepareForAccessingPlanning(), so that
// the PlanCacheIndexTree has the same sort as the MatchExpression used to generate the
@@ -808,8 +842,11 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
std::unique_ptr<PlanCacheIndexTree> cacheData;
auto statusWithCacheData = cacheDataFromTaggedTree(clone.get(), relevantIndices);
if (!statusWithCacheData.isOK()) {
- LOG(5) << "Query is not cachable: "
- << redact(statusWithCacheData.getStatus().reason());
+ LOGV2_DEBUG(20977,
+ 5,
+ "Query is not cachable: {statusWithCacheData_getStatus_reason}",
+ "statusWithCacheData_getStatus_reason"_attr =
+ redact(statusWithCacheData.getStatus().reason()));
} else {
cacheData = std::move(statusWithCacheData.getValue());
}
@@ -828,7 +865,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
auto soln = QueryPlannerAnalysis::analyzeDataAccess(query, params, std::move(solnRoot));
if (soln) {
- LOG(5) << "Planner: adding solution:" << endl << redact(soln->toString());
+ LOGV2_DEBUG(20978,
+ 5,
+ "Planner: adding solution:\n{soln}",
+ "soln"_attr = redact(soln->toString()));
if (statusWithCacheData.isOK()) {
SolutionCacheData* scd = new SolutionCacheData();
scd->tree = std::move(cacheData);
@@ -842,7 +882,8 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
// Don't leave tags on query tree.
query.root()->resetTag();
- LOG(5) << "Planner: outputted " << out.size() << " indexed solutions.";
+ LOGV2_DEBUG(
+ 20979, 5, "Planner: outputted {out_size} indexed solutions.", "out_size"_attr = out.size());
// Produce legible error message for failed OR planning with a TEXT child.
// TODO: support collection scan for non-TEXT children of OR.
@@ -877,7 +918,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
return Status(ErrorCodes::NoQueryExecutionPlans,
"Failed to build whole-index solution for $hint");
}
- LOG(5) << "Planner: outputting soln that uses hinted index as scan.";
+ LOGV2_DEBUG(20980, 5, "Planner: outputting soln that uses hinted index as scan.");
std::vector<std::unique_ptr<QuerySolution>> out;
out.push_back(std::move(soln));
return {std::move(out)};
@@ -938,7 +979,8 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
const BSONObj kp = QueryPlannerAnalysis::getSortPattern(index.keyPattern);
if (providesSort(query, kp)) {
- LOG(5) << "Planner: outputting soln that uses index to provide sort.";
+ LOGV2_DEBUG(
+ 20981, 5, "Planner: outputting soln that uses index to provide sort.");
auto soln = buildWholeIXSoln(fullIndexList[i], query, params);
if (soln) {
PlanCacheIndexTree* indexTree = new PlanCacheIndexTree();
@@ -953,8 +995,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
}
}
if (providesSort(query, QueryPlannerCommon::reverseSortObj(kp))) {
- LOG(5) << "Planner: outputting soln that uses (reverse) index "
- << "to provide sort.";
+ LOGV2_DEBUG(
+ 20982,
+ 5,
+ "Planner: outputting soln that uses (reverse) index to provide sort.");
auto soln = buildWholeIXSoln(fullIndexList[i], query, params, -1);
if (soln) {
PlanCacheIndexTree* indexTree = new PlanCacheIndexTree();
@@ -988,7 +1032,8 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
QueryPlannerParams paramsForCoveredIxScan;
auto soln = buildWholeIXSoln(index, query, paramsForCoveredIxScan);
if (soln && !soln->root->fetched()) {
- LOG(5) << "Planner: outputting soln that uses index to provide projection.";
+ LOGV2_DEBUG(
+ 20983, 5, "Planner: outputting soln that uses index to provide projection.");
PlanCacheIndexTree* indexTree = new PlanCacheIndexTree();
indexTree->setIndexEntry(index);
@@ -1030,7 +1075,10 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
"Failed to build collection scan soln");
}
if (collscan) {
- LOG(5) << "Planner: outputting a collscan:" << endl << redact(collscan->toString());
+ LOGV2_DEBUG(20984,
+ 5,
+ "Planner: outputting a collscan:\n{collscan}",
+ "collscan"_attr = redact(collscan->toString()));
SolutionCacheData* scd = new SolutionCacheData();
scd->solnType = SolutionCacheData::COLLSCAN_SOLN;
collscan->cacheData.reset(scd);
diff --git a/src/mongo/db/query/query_planner_test_fixture.cpp b/src/mongo/db/query/query_planner_test_fixture.cpp
index db4ae678f87..c7c9bd342c6 100644
--- a/src/mongo/db/query/query_planner_test_fixture.cpp
+++ b/src/mongo/db/query/query_planner_test_fixture.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/query/query_knobs_gen.h"
#include "mongo/db/query/query_planner.h"
#include "mongo/db/query/query_planner_test_lib.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/transitional_tools_do_not_use/vector_spooling.h"
@@ -478,7 +479,7 @@ size_t QueryPlannerTest::getNumSolutions() const {
void QueryPlannerTest::dumpSolutions() const {
str::stream ost;
dumpSolutions(ost);
- log() << std::string(ost);
+ LOGV2(20985, "{std_string_ost}", "std_string_ost"_attr = std::string(ost));
}
void QueryPlannerTest::dumpSolutions(str::stream& ost) const {
diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp
index 3569bc526c0..2af9934eff4 100644
--- a/src/mongo/db/read_concern_mongod.cpp
+++ b/src/mongo/db/read_concern_mongod.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/server_options.h"
#include "mongo/db/storage/recovery_unit.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/util/concurrency/notification.h"
#include "mongo/util/log.h"
@@ -121,8 +122,13 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) {
auto waitStatus = replCoord->waitUntilOpTimeForReadUntil(opCtx, readConcernArgs, deadline);
lastAppliedOpTime = LogicalTime(replCoord->getMyLastAppliedOpTime().getTimestamp());
if (!waitStatus.isOK()) {
- LOG(1) << "Wait for clusterTime: " << clusterTime.toString()
- << " until deadline: " << deadline << " failed with " << waitStatus.toString();
+ LOGV2_DEBUG(20986,
+ 1,
+ "Wait for clusterTime: {clusterTime} until deadline: {deadline} failed "
+ "with {waitStatus}",
+ "clusterTime"_attr = clusterTime.toString(),
+ "deadline"_attr = deadline,
+ "waitStatus"_attr = waitStatus.toString());
}
}
@@ -163,8 +169,12 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) {
auto myWriteRequest = writeRequests.getOrCreateWriteRequest(clusterTime);
if (std::get<0>(myWriteRequest)) { // Its a new request
try {
- LOG(2) << "New appendOplogNote request on clusterTime: " << clusterTime.toString()
- << " remaining attempts: " << remainingAttempts;
+ LOGV2_DEBUG(20987,
+ 2,
+ "New appendOplogNote request on clusterTime: {clusterTime} remaining "
+ "attempts: {remainingAttempts}",
+ "clusterTime"_attr = clusterTime.toString(),
+ "remainingAttempts"_attr = remainingAttempts);
auto swRes = myShard.getValue()->runCommand(
opCtx,
ReadPreferenceSetting(ReadPreference::PrimaryOnly),
@@ -183,8 +193,12 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) {
writeRequests.deleteWriteRequest(clusterTime);
}
} else {
- LOG(2) << "Join appendOplogNote request on clusterTime: " << clusterTime.toString()
- << " remaining attempts: " << remainingAttempts;
+ LOGV2_DEBUG(20988,
+ 2,
+ "Join appendOplogNote request on clusterTime: {clusterTime} remaining "
+ "attempts: {remainingAttempts}",
+ "clusterTime"_attr = clusterTime.toString(),
+ "remainingAttempts"_attr = remainingAttempts);
try {
status = std::get<1>(myWriteRequest)->get(opCtx);
} catch (const DBException& ex) {
@@ -199,8 +213,11 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) {
}
// This is when the noop write failed but the opLog caught up to clusterTime by replicating.
if (!status.isOK()) {
- LOG(1) << "Reached clusterTime " << lastAppliedOpTime.toString()
- << " but failed noop write due to " << status.toString();
+ LOGV2_DEBUG(20989,
+ 1,
+ "Reached clusterTime {lastAppliedOpTime} but failed noop write due to {status}",
+ "lastAppliedOpTime"_attr = lastAppliedOpTime.toString(),
+ "status"_attr = status.toString());
}
return Status::OK();
}
@@ -316,8 +333,10 @@ Status waitForReadConcernImpl(OperationContext* opCtx,
auto status = makeNoopWriteIfNeeded(opCtx, *targetClusterTime);
if (!status.isOK()) {
- LOG(0) << "Failed noop write at clusterTime: " << targetClusterTime->toString()
- << " due to " << status.toString();
+ LOGV2(20990,
+ "Failed noop write at clusterTime: {targetClusterTime} due to {status}",
+ "targetClusterTime"_attr = targetClusterTime->toString(),
+ "status"_attr = status.toString());
}
}
@@ -361,15 +380,19 @@ Status waitForReadConcernImpl(OperationContext* opCtx,
const int debugLevel = serverGlobalParams.clusterRole == ClusterRole::ConfigServer ? 1 : 2;
- LOG(debugLevel) << "Waiting for 'committed' snapshot to be available for reading: "
- << readConcernArgs;
+ LOGV2_DEBUG(
+ 20991,
+ logSeverityV1toV2(debugLevel).toInt(),
+ "Waiting for 'committed' snapshot to be available for reading: {readConcernArgs}",
+ "readConcernArgs"_attr = readConcernArgs);
opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kMajorityCommitted);
Status status = opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot();
// Wait until a snapshot is available.
while (status == ErrorCodes::ReadConcernMajorityNotAvailableYet) {
- LOG(debugLevel) << "Snapshot not available yet.";
+ LOGV2_DEBUG(
+ 20992, logSeverityV1toV2(debugLevel).toInt(), "Snapshot not available yet.");
replCoord->waitUntilSnapshotCommitted(opCtx, Timestamp());
status = opCtx->recoveryUnit()->obtainMajorityCommittedSnapshot();
}
@@ -378,8 +401,13 @@ Status waitForReadConcernImpl(OperationContext* opCtx,
return status;
}
- LOG(debugLevel) << "Using 'committed' snapshot: " << CurOp::get(opCtx)->opDescription()
- << " with readTs: " << opCtx->recoveryUnit()->getPointInTimeReadTimestamp();
+ LOGV2_DEBUG(20993,
+ logSeverityV1toV2(debugLevel).toInt(),
+ "Using 'committed' snapshot: {CurOp_get_opCtx_opDescription} with readTs: "
+ "{opCtx_recoveryUnit_getPointInTimeReadTimestamp}",
+ "CurOp_get_opCtx_opDescription"_attr = CurOp::get(opCtx)->opDescription(),
+ "opCtx_recoveryUnit_getPointInTimeReadTimestamp"_attr =
+ opCtx->recoveryUnit()->getPointInTimeReadTimestamp());
}
return Status::OK();
}
@@ -387,8 +415,9 @@ Status waitForReadConcernImpl(OperationContext* opCtx,
Status waitForLinearizableReadConcernImpl(OperationContext* opCtx, const int readConcernTimeout) {
CurOpFailpointHelpers::waitWhileFailPointEnabled(
&hangBeforeLinearizableReadConcern, opCtx, "hangBeforeLinearizableReadConcern", [opCtx]() {
- log() << "batch update - hangBeforeLinearizableReadConcern fail point enabled. "
- "Blocking until fail point is disabled.";
+ LOGV2(20994,
+ "batch update - hangBeforeLinearizableReadConcern fail point enabled. "
+ "Blocking until fail point is disabled.");
});
repl::ReplicationCoordinator* replCoord =
@@ -460,8 +489,12 @@ Status waitForSpeculativeMajorityReadConcernImpl(
}
// Block to make sure returned data is majority committed.
- LOG(1) << "Servicing speculative majority read, waiting for timestamp " << waitTs
- << " to become committed, current commit point: " << replCoord->getLastCommittedOpTime();
+ LOGV2_DEBUG(20995,
+ 1,
+ "Servicing speculative majority read, waiting for timestamp {waitTs} to become "
+ "committed, current commit point: {replCoord_getLastCommittedOpTime}",
+ "waitTs"_attr = waitTs,
+ "replCoord_getLastCommittedOpTime"_attr = replCoord->getLastCommittedOpTime());
if (!opCtx->hasDeadline()) {
// This hard-coded value represents the maximum time we are willing to wait for a timestamp
@@ -476,8 +509,12 @@ Status waitForSpeculativeMajorityReadConcernImpl(
Timer t;
auto waitStatus = replCoord->awaitTimestampCommitted(opCtx, waitTs);
if (waitStatus.isOK()) {
- LOG(1) << "Timestamp " << waitTs << " became majority committed, waited " << t.millis()
- << "ms for speculative majority read to be satisfied.";
+ LOGV2_DEBUG(20996,
+ 1,
+ "Timestamp {waitTs} became majority committed, waited {t_millis}ms for "
+ "speculative majority read to be satisfied.",
+ "waitTs"_attr = waitTs,
+ "t_millis"_attr = t.millis());
}
return waitStatus;
}
diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp
index a008c489e8b..4f4113e1db8 100644
--- a/src/mongo/db/read_write_concern_defaults.cpp
+++ b/src/mongo/db/read_write_concern_defaults.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/read_write_concern_defaults.h"
#include "mongo/db/logical_clock.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -180,7 +181,9 @@ void ReadWriteConcernDefaults::refreshIfNecessary(OperationContext* opCtx) {
(possibleNewDefaults->getEpoch() > currentDefaultsHandle->getEpoch())) {
// Use the new defaults if they have a higher epoch, if there are no defaults in the cache,
// or if the found defaults have no epoch, meaning there are no defaults in config.settings.
- log() << "refreshed RWC defaults to " << possibleNewDefaults->toBSON();
+ LOGV2(20997,
+ "refreshed RWC defaults to {possibleNewDefaults}",
+ "possibleNewDefaults"_attr = possibleNewDefaults->toBSON());
setDefault(std::move(*possibleNewDefaults));
}
}
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp
index 65e6bfd350e..07fed07a646 100644
--- a/src/mongo/db/repair_database.cpp
+++ b/src/mongo/db/repair_database.cpp
@@ -58,6 +58,7 @@
#include "mongo/db/rebuild_indexes.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/storage_engine.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -90,7 +91,7 @@ Status repairCollections(OperationContext* opCtx,
for (const auto& nss : colls) {
opCtx->checkForInterrupt();
- log() << "Repairing collection " << nss;
+ LOGV2(21027, "Repairing collection {nss}", "nss"_attr = nss);
auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, nss);
Status status = engine->repairRecordStore(opCtx, collection->getCatalogId(), nss);
@@ -128,7 +129,9 @@ Status repairCollections(OperationContext* opCtx,
return status;
}
- log() << "Collection validation results: " << output.done();
+ LOGV2(21028,
+ "Collection validation results: {output_done}",
+ "output_done"_attr = output.done());
if (!validateResults.valid) {
status = rebuildIndexesForNamespace(opCtx, nss, engine);
@@ -148,7 +151,7 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std:
invariant(opCtx->lockState()->isW());
invariant(dbName.find('.') == std::string::npos);
- log() << "repairDatabase " << dbName;
+ LOGV2(21029, "repairDatabase {dbName}", "dbName"_attr = dbName);
BackgroundOperation::assertNoBgOpInProgForDb(dbName);
@@ -163,7 +166,10 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std:
auto status = repairCollections(opCtx, engine, dbName);
if (!status.isOK()) {
- severe() << "Failed to repair database " << dbName << ": " << status.reason();
+ LOGV2_FATAL(21030,
+ "Failed to repair database {dbName}: {status_reason}",
+ "dbName"_attr = dbName,
+ "status_reason"_attr = status.reason());
}
try {
@@ -189,7 +195,8 @@ Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const std:
// have a UUID.
throw;
} catch (...) {
- severe() << "Unexpected exception encountered while reopening database after repair.";
+ LOGV2_FATAL(21031,
+ "Unexpected exception encountered while reopening database after repair.");
std::terminate(); // Logs additional info about the specific error.
}
diff --git a/src/mongo/db/repair_database_and_check_version.cpp b/src/mongo/db/repair_database_and_check_version.cpp
index f152e9c378c..2f1e1c70c75 100644
--- a/src/mongo/db/repair_database_and_check_version.cpp
+++ b/src/mongo/db/repair_database_and_check_version.cpp
@@ -57,6 +57,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/storage_repair_observer.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/exit.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -89,7 +90,7 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, fcvNss.db());
if (!db) {
- log() << "Re-creating admin database that was dropped.";
+ LOGV2(20998, "Re-creating admin database that was dropped.");
}
db = databaseHolder->openDb(opCtx, fcvNss.db());
invariant(db);
@@ -98,8 +99,9 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
// create it.
if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
opCtx, NamespaceString::kServerConfigurationNamespace)) {
- log() << "Re-creating the server configuration collection (admin.system.version) that was "
- "dropped.";
+ LOGV2(20999,
+ "Re-creating the server configuration collection (admin.system.version) that was "
+ "dropped.");
uassertStatusOK(
createCollection(opCtx, fcvNss.db().toString(), BSON("create" << fcvNss.coll())));
}
@@ -114,8 +116,11 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
fcvColl,
BSON("_id" << FeatureCompatibilityVersionParser::kParameterName),
featureCompatibilityVersion)) {
- log() << "Re-creating featureCompatibilityVersion document that was deleted with version "
- << FeatureCompatibilityVersionParser::kVersion42 << ".";
+ LOGV2(21000,
+ "Re-creating featureCompatibilityVersion document that was deleted with version "
+ "{FeatureCompatibilityVersionParser_kVersion42}.",
+ "FeatureCompatibilityVersionParser_kVersion42"_attr =
+ FeatureCompatibilityVersionParser::kVersion42);
BSONObj fcvObj = BSON("_id" << FeatureCompatibilityVersionParser::kParameterName
<< FeatureCompatibilityVersionParser::kVersionField
@@ -224,11 +229,15 @@ Status ensureCollectionProperties(OperationContext* opCtx,
// does not exist before attempting to build it or returning an error.
if (requiresIndex && !hasAutoIndexIdField &&
!checkIdIndexExists(opCtx, coll->getCatalogId())) {
- log() << "collection " << coll->ns() << " is missing an _id index; building it now";
+ LOGV2(21001,
+ "collection {coll_ns} is missing an _id index; building it now",
+ "coll_ns"_attr = coll->ns());
auto status = buildMissingIdIndex(opCtx, coll);
if (!status.isOK()) {
- error() << "could not build an _id index on collection " << coll->ns() << ": "
- << status;
+ LOGV2_ERROR(21021,
+ "could not build an _id index on collection {coll_ns}: {status}",
+ "coll_ns"_attr = coll->ns(),
+ "status"_attr = status);
return downgradeError;
}
}
@@ -259,8 +268,10 @@ void checkForCappedOplog(OperationContext* opCtx, Database* db) {
Collection* oplogCollection =
CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, oplogNss);
if (oplogCollection && !oplogCollection->isCapped()) {
- severe() << "The oplog collection " << oplogNss
- << " is not capped; a capped oplog is a requirement for replication to function.";
+ LOGV2_FATAL(21022,
+ "The oplog collection {oplogNss} is not capped; a capped oplog is a "
+ "requirement for replication to function.",
+ "oplogNss"_attr = oplogNss);
fassertFailedNoTrace(40115);
}
}
@@ -269,12 +280,11 @@ void rebuildIndexes(OperationContext* opCtx, StorageEngine* storageEngine) {
auto reconcileResult = fassert(40593, storageEngine->reconcileCatalogAndIdents(opCtx));
if (!reconcileResult.indexesToRebuild.empty() && serverGlobalParams.indexBuildRetry) {
- log() << "note: restart the server with --noIndexBuildRetry "
- << "to skip index rebuilds";
+ LOGV2(21002, "note: restart the server with --noIndexBuildRetry to skip index rebuilds");
}
if (!serverGlobalParams.indexBuildRetry) {
- log() << " not rebuilding interrupted indexes";
+ LOGV2(21003, " not rebuilding interrupted indexes");
return;
}
@@ -309,7 +319,10 @@ void rebuildIndexes(OperationContext* opCtx, StorageEngine* storageEngine) {
auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, collNss);
for (const auto& indexName : entry.second.first) {
- log() << "Rebuilding index. Collection: " << collNss << " Index: " << indexName;
+ LOGV2(21004,
+ "Rebuilding index. Collection: {collNss} Index: {indexName}",
+ "collNss"_attr = collNss,
+ "indexName"_attr = indexName);
}
std::vector<BSONObj> indexSpecs = entry.second.second;
@@ -321,7 +334,7 @@ void rebuildIndexes(OperationContext* opCtx, StorageEngine* storageEngine) {
// Therefore, when a replica set member is started in standalone mode, we cannot restart the
// index build.
if (getReplSetMemberInStandaloneMode(opCtx->getServiceContext())) {
- log() << "Not restarting unfinished index builds because we are in standalone mode";
+ LOGV2(21005, "Not restarting unfinished index builds because we are in standalone mode");
return;
}
@@ -388,7 +401,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
invariant(!storageGlobalParams.readOnly);
if (MONGO_unlikely(exitBeforeDataRepair.shouldFail())) {
- log() << "Exiting because 'exitBeforeDataRepair' fail point was set.";
+ LOGV2(21006, "Exiting because 'exitBeforeDataRepair' fail point was set.");
quickExit(EXIT_ABRUPT);
}
@@ -402,7 +415,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
}
for (const auto& dbName : dbNames) {
- LOG(1) << " Repairing database: " << dbName;
+ LOGV2_DEBUG(21007, 1, " Repairing database: {dbName}", "dbName"_attr = dbName);
fassertNoTrace(18506, repairDatabase(opCtx, storageEngine, dbName));
}
@@ -447,7 +460,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
if (storageGlobalParams.repair) {
if (MONGO_unlikely(exitBeforeRepairInvalidatesConfig.shouldFail())) {
- log() << "Exiting because 'exitBeforeRepairInvalidatesConfig' fail point was set.";
+ LOGV2(21008, "Exiting because 'exitBeforeRepairInvalidatesConfig' fail point was set.");
quickExit(EXIT_ABRUPT);
}
// This must be done after opening the "local" database as it modifies the replica set
@@ -455,23 +468,28 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
auto repairObserver = StorageRepairObserver::get(opCtx->getServiceContext());
repairObserver->onRepairDone(opCtx);
if (repairObserver->getModifications().size() > 0) {
- warning() << "Modifications made by repair:";
+ LOGV2_WARNING(21018, "Modifications made by repair:");
const auto& mods = repairObserver->getModifications();
for (const auto& mod : mods) {
- warning() << " " << mod.getDescription();
+ LOGV2_WARNING(21019,
+ " {mod_getDescription}",
+ "mod_getDescription"_attr = mod.getDescription());
}
}
if (repairObserver->isDataInvalidated()) {
if (hasReplSetConfigDoc(opCtx)) {
- warning() << "WARNING: Repair may have modified replicated data. This node will no "
- "longer be able to join a replica set without a full re-sync";
+ LOGV2_WARNING(
+ 21020,
+ "WARNING: Repair may have modified replicated data. This node will no "
+ "longer be able to join a replica set without a full re-sync");
}
}
// There were modifications, but only benign ones.
if (repairObserver->getModifications().size() > 0 && !repairObserver->isDataInvalidated()) {
- log() << "Repair has made modifications to unreplicated data. The data is healthy and "
- "the node is eligible to be returned to the replica set.";
+ LOGV2(21009,
+ "Repair has made modifications to unreplicated data. The data is healthy and "
+ "the node is eligible to be returned to the replica set.");
}
}
@@ -504,7 +522,7 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
if (dbName != "local") {
nonLocalDatabases = true;
}
- LOG(1) << " Recovering database: " << dbName;
+ LOGV2_DEBUG(21010, 1, " Recovering database: {dbName}", "dbName"_attr = dbName);
auto db = databaseHolder->openDb(opCtx, dbName);
invariant(db);
@@ -521,11 +539,13 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
// current version of mongod with --repair and then proceed with normal startup.
status = {ErrorCodes::MustUpgrade, status.reason()};
}
- severe() << "Unable to start mongod due to an incompatibility with the data files and"
- " this version of mongod: "
- << redact(status);
- severe() << "Please consult our documentation when trying to downgrade to a previous"
- " major release";
+ LOGV2_FATAL(21023,
+ "Unable to start mongod due to an incompatibility with the data files and"
+ " this version of mongod: {status}",
+ "status"_attr = redact(status));
+ LOGV2_FATAL(21024,
+ "Please consult our documentation when trying to downgrade to a previous"
+ " major release");
quickExit(EXIT_NEED_UPGRADE);
MONGO_UNREACHABLE;
}
@@ -566,23 +586,39 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
// warning.
if (version ==
ServerGlobalParams::FeatureCompatibility::Version::kUpgradingTo44) {
- log() << "** WARNING: A featureCompatibilityVersion upgrade did not "
- << "complete. " << startupWarningsLog;
- log() << "** The current featureCompatibilityVersion is "
- << FeatureCompatibilityVersionParser::toString(version) << "."
- << startupWarningsLog;
- log() << "** To fix this, use the setFeatureCompatibilityVersion "
- << "command to resume upgrade to 4.4." << startupWarningsLog;
+ LOGV2_OPTIONS(
+ 21011,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: A featureCompatibilityVersion upgrade did not complete. ");
+ LOGV2_OPTIONS(21012,
+ {logv2::LogTag::kStartupWarnings},
+ "** The current featureCompatibilityVersion is "
+ "{FeatureCompatibilityVersionParser_version}.",
+ "FeatureCompatibilityVersionParser_version"_attr =
+ FeatureCompatibilityVersionParser::toString(version));
+ LOGV2_OPTIONS(
+ 21013,
+ {logv2::LogTag::kStartupWarnings},
+ "** To fix this, use the setFeatureCompatibilityVersion "
+ "command to resume upgrade to 4.4.");
} else if (version ==
ServerGlobalParams::FeatureCompatibility::Version::
kDowngradingTo42) {
- log() << "** WARNING: A featureCompatibilityVersion downgrade did not "
- << "complete. " << startupWarningsLog;
- log() << "** The current featureCompatibilityVersion is "
- << FeatureCompatibilityVersionParser::toString(version) << "."
- << startupWarningsLog;
- log() << "** To fix this, use the setFeatureCompatibilityVersion "
- << "command to resume downgrade to 4.2." << startupWarningsLog;
+ LOGV2_OPTIONS(21014,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: A featureCompatibilityVersion downgrade did not "
+ "complete. ");
+ LOGV2_OPTIONS(21015,
+ {logv2::LogTag::kStartupWarnings},
+ "** The current featureCompatibilityVersion is "
+ "{FeatureCompatibilityVersionParser_version}.",
+ "FeatureCompatibilityVersionParser_version"_attr =
+ FeatureCompatibilityVersionParser::toString(version));
+ LOGV2_OPTIONS(
+ 21016,
+ {logv2::LogTag::kStartupWarnings},
+ "** To fix this, use the setFeatureCompatibilityVersion "
+ "command to resume downgrade to 4.2.");
}
}
}
@@ -614,13 +650,14 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
// Fail to start up if there is no featureCompatibilityVersion document and there are non-local
// databases present and we do not need to start up via initial sync.
if (!fcvDocumentExists && nonLocalDatabases && !needInitialSync) {
- severe()
- << "Unable to start up mongod due to missing featureCompatibilityVersion document.";
- severe() << "Please run with --repair to restore the document.";
+ LOGV2_FATAL(
+ 21025,
+ "Unable to start up mongod due to missing featureCompatibilityVersion document.");
+ LOGV2_FATAL(21026, "Please run with --repair to restore the document.");
fassertFailedNoTrace(40652);
}
- LOG(1) << "done repairDatabases";
+ LOGV2_DEBUG(21017, 1, "done repairDatabases");
return nonLocalDatabases;
}
diff --git a/src/mongo/db/repl/abstract_oplog_fetcher.cpp b/src/mongo/db/repl/abstract_oplog_fetcher.cpp
index 56a5fb710dd..c9bfaace0e9 100644
--- a/src/mongo/db/repl/abstract_oplog_fetcher.cpp
+++ b/src/mongo/db/repl/abstract_oplog_fetcher.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/commands/server_status_metric.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/repl/repl_server_parameters_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -211,8 +212,12 @@ void AbstractOplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
Status responseStatus =
_checkForShutdownAndConvertStatus(result.getStatus(), "error in fetcher batch callback");
if (ErrorCodes::CallbackCanceled == responseStatus) {
- LOG(1) << _getComponentName() << " oplog query cancelled to " << _getSource() << ": "
- << redact(responseStatus);
+ LOGV2_DEBUG(21032,
+ 1,
+ "{getComponentName} oplog query cancelled to {getSource}: {responseStatus}",
+ "getComponentName"_attr = _getComponentName(),
+ "getSource"_attr = _getSource(),
+ "responseStatus"_attr = redact(responseStatus));
_finishCallback(responseStatus);
return;
}
@@ -235,11 +240,16 @@ void AbstractOplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
auto scheduleStatus = _scheduleFetcher_inlock();
if (scheduleStatus.isOK()) {
- log() << "Scheduled new oplog query " << _fetcher->toString();
+ LOGV2(21033,
+ "Scheduled new oplog query {fetcher}",
+ "fetcher"_attr = _fetcher->toString());
return;
}
- error() << "Error scheduling new oplog query: " << redact(scheduleStatus)
- << ". Returning current oplog query error: " << redact(responseStatus);
+ LOGV2_ERROR(21037,
+ "Error scheduling new oplog query: {scheduleStatus}. Returning current "
+ "oplog query error: {responseStatus}",
+ "scheduleStatus"_attr = redact(scheduleStatus),
+ "responseStatus"_attr = redact(responseStatus));
}
}
_finishCallback(responseStatus);
@@ -290,8 +300,11 @@ void AbstractOplogFetcher::_callback(const Fetcher::QueryResponseStatus& result,
return;
}
auto lastDoc = lastDocRes.getValue();
- LOG(3) << _getComponentName()
- << " setting last fetched optime ahead after batch: " << lastDoc;
+ LOGV2_DEBUG(21034,
+ 3,
+ "{getComponentName} setting last fetched optime ahead after batch: {lastDoc}",
+ "getComponentName"_attr = _getComponentName(),
+ "lastDoc"_attr = lastDoc);
stdx::lock_guard<Latch> lock(_mutex);
_lastFetched = lastDoc;
@@ -348,13 +361,18 @@ std::unique_ptr<Fetcher> AbstractOplogFetcher::_makeFetcher(const BSONObj& findC
bool AbstractOplogFetcher::OplogFetcherRestartDecisionDefault::shouldContinue(
AbstractOplogFetcher* fetcher, Status status) {
if (_fetcherRestarts == _maxFetcherRestarts) {
- log() << "Error returned from oplog query (no more query restarts left): "
- << redact(status);
+ LOGV2(21035,
+ "Error returned from oplog query (no more query restarts left): {status}",
+ "status"_attr = redact(status));
return false;
}
- log() << "Restarting oplog query due to error: " << redact(status)
- << ". Last fetched optime: " << fetcher->_getLastOpTimeFetched()
- << ". Restarts remaining: " << (_maxFetcherRestarts - _fetcherRestarts);
+ LOGV2(
+ 21036,
+ "Restarting oplog query due to error: {status}. Last fetched optime: "
+ "{fetcher_getLastOpTimeFetched}. Restarts remaining: {maxFetcherRestarts_fetcherRestarts}",
+ "status"_attr = redact(status),
+ "fetcher_getLastOpTimeFetched"_attr = fetcher->_getLastOpTimeFetched(),
+ "maxFetcherRestarts_fetcherRestarts"_attr = (_maxFetcherRestarts - _fetcherRestarts));
_fetcherRestarts++;
return true;
}
diff --git a/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp b/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp
index 7c35e08ab76..5fe87c8530c 100644
--- a/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp
+++ b/src/mongo/db/repl/abstract_oplog_fetcher_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <memory>
@@ -35,8 +37,10 @@
#include "mongo/db/repl/abstract_oplog_fetcher_test_fixture.h"
#include "mongo/db/repl/oplog_entry.h"
#include "mongo/db/repl/task_executor_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/task_executor_proxy.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
namespace {
@@ -300,20 +304,20 @@ TEST_F(AbstractOplogFetcherTest, OplogFetcherStopsRestartingFetcherIfRestartLimi
ASSERT_OK(oplogFetcher.startup());
- unittest::log() << "processing find request from first fetcher";
+ LOGV2(21038, "processing find request from first fetcher");
_assertFindCommandTimestampEquals(
ops[0], processNetworkResponse({makeCursorResponse(1, {ops[0], ops[1], ops[2]})}, true));
- unittest::log() << "sending error response to getMore request from first fetcher";
+ LOGV2(21039, "sending error response to getMore request from first fetcher");
assertRemoteCommandNameEquals(
"getMore", processNetworkResponse({ErrorCodes::CappedPositionLost, "fail 1"}, true));
- unittest::log() << "sending error response to find request from second fetcher";
+ LOGV2(21040, "sending error response to find request from second fetcher");
_assertFindCommandTimestampEquals(
ops[2], processNetworkResponse({ErrorCodes::IllegalOperation, "fail 2"}, true));
- unittest::log() << "sending error response to find request from third fetcher";
+ LOGV2(21041, "sending error response to find request from third fetcher");
_assertFindCommandTimestampEquals(
ops[2], processNetworkResponse({ErrorCodes::OperationFailed, "fail 3"}, false));
@@ -335,28 +339,28 @@ TEST_F(AbstractOplogFetcherTest, OplogFetcherResetsRestartCounterOnSuccessfulFet
ASSERT_OK(oplogFetcher.startup());
- unittest::log() << "processing find request from first fetcher";
+ LOGV2(21042, "processing find request from first fetcher");
_assertFindCommandTimestampEquals(
ops[0], processNetworkResponse({makeCursorResponse(1, {ops[0], ops[1], ops[2]})}, true));
- unittest::log() << "sending error response to getMore request from first fetcher";
+ LOGV2(21043, "sending error response to getMore request from first fetcher");
assertRemoteCommandNameEquals(
"getMore", processNetworkResponse({ErrorCodes::CappedPositionLost, "fail 1"}, true));
- unittest::log() << "processing find request from second fetcher";
+ LOGV2(21044, "processing find request from second fetcher");
_assertFindCommandTimestampEquals(
ops[2], processNetworkResponse({makeCursorResponse(1, {ops[2], ops[3], ops[4]})}, true));
- unittest::log() << "sending error response to getMore request from second fetcher";
+ LOGV2(21045, "sending error response to getMore request from second fetcher");
assertRemoteCommandNameEquals(
"getMore", processNetworkResponse({ErrorCodes::IllegalOperation, "fail 2"}, true));
- unittest::log() << "sending error response to find request from third fetcher";
+ LOGV2(21046, "sending error response to find request from third fetcher");
_assertFindCommandTimestampEquals(
ops[4], processNetworkResponse({ErrorCodes::InternalError, "fail 3"}, true));
- unittest::log() << "sending error response to find request from fourth fetcher";
+ LOGV2(21047, "sending error response to find request from fourth fetcher");
_assertFindCommandTimestampEquals(
ops[4], processNetworkResponse({ErrorCodes::OperationFailed, "fail 4"}, false));
@@ -406,12 +410,12 @@ TEST_F(AbstractOplogFetcherTest,
ASSERT_OK(oplogFetcher.startup());
ASSERT_TRUE(oplogFetcher.isActive());
- unittest::log() << "processing find request from first fetcher";
+ LOGV2(21048, "processing find request from first fetcher");
_assertFindCommandTimestampEquals(
ops[0], processNetworkResponse({makeCursorResponse(1, {ops[0], ops[1], ops[2]})}, true));
- unittest::log() << "sending error response to getMore request from first fetcher";
+ LOGV2(21049, "sending error response to getMore request from first fetcher");
shouldFailSchedule = true;
assertRemoteCommandNameEquals(
"getMore", processNetworkResponse({ErrorCodes::CappedPositionLost, "dead cursor"}, false));
diff --git a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp
index 9f748b283c5..68d8e861ddd 100644
--- a/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp
+++ b/src/mongo/db/repl/abstract_oplog_fetcher_test_fixture.cpp
@@ -27,13 +27,17 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/db/repl/abstract_oplog_fetcher_test_fixture.h"
#include "mongo/db/repl/oplog_entry.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace repl {
@@ -119,13 +123,13 @@ executor::RemoteCommandRequest AbstractOplogFetcherTest::processNetworkResponse(
auto net = getNet();
executor::NetworkInterfaceMock::InNetworkGuard guard(net);
- unittest::log() << "scheduling response.";
+ LOGV2(21050, "scheduling response.");
auto request = net->scheduleSuccessfulResponse(response);
- unittest::log() << "running network ops.";
+ LOGV2(21051, "running network ops.");
net->runReadyNetworkOperations();
- unittest::log() << "checking for more requests";
+ LOGV2(21052, "checking for more requests");
ASSERT_EQUALS(expectReadyRequestsAfterProcessing, net->hasReadyRequests());
- unittest::log() << "returning consumed request";
+ LOGV2(21053, "returning consumed request");
return request;
}
diff --git a/src/mongo/db/repl/all_database_cloner.cpp b/src/mongo/db/repl/all_database_cloner.cpp
index c9c1345e982..ca47cac6aef 100644
--- a/src/mongo/db/repl/all_database_cloner.cpp
+++ b/src/mongo/db/repl/all_database_cloner.cpp
@@ -35,6 +35,7 @@
#include "mongo/base/string_data.h"
#include "mongo/db/repl/all_database_cloner.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -56,7 +57,7 @@ BaseCloner::ClonerStages AllDatabaseCloner::getStages() {
Status AllDatabaseCloner::ensurePrimaryOrSecondary(
const executor::RemoteCommandResponse& isMasterReply) {
if (!isMasterReply.isOK()) {
- log() << "Cannot reconnect because isMaster command failed.";
+ LOGV2(21054, "Cannot reconnect because isMaster command failed.");
return isMasterReply.status;
}
if (isMasterReply.data["ismaster"].trueValue() || isMasterReply.data["secondary"].trueValue())
@@ -104,14 +105,19 @@ BaseCloner::AfterStageBehavior AllDatabaseCloner::listDatabasesStage() {
auto databasesArray = getClient()->getDatabaseInfos(BSONObj(), true /* nameOnly */);
for (const auto& dbBSON : databasesArray) {
if (!dbBSON.hasField("name")) {
- LOG(1) << "Excluding database due to the 'listDatabases' response not containing a "
- "'name' field for this entry: "
- << dbBSON;
+ LOGV2_DEBUG(21055,
+ 1,
+ "Excluding database due to the 'listDatabases' response not containing a "
+ "'name' field for this entry: {dbBSON}",
+ "dbBSON"_attr = dbBSON);
continue;
}
const auto& dbName = dbBSON["name"].str();
if (dbName == "local") {
- LOG(1) << "Excluding database from the 'listDatabases' response: " << dbBSON;
+ LOGV2_DEBUG(21056,
+ 1,
+ "Excluding database from the 'listDatabases' response: {dbBSON}",
+ "dbBSON"_attr = dbBSON);
continue;
} else {
_databases.emplace_back(dbName);
@@ -146,15 +152,24 @@ void AllDatabaseCloner::postStage() {
}
auto dbStatus = _currentDatabaseCloner->run();
if (dbStatus.isOK()) {
- LOG(1) << "Database clone for '" << dbName << "' finished: " << dbStatus;
+ LOGV2_DEBUG(21057,
+ 1,
+ "Database clone for '{dbName}' finished: {dbStatus}",
+ "dbName"_attr = dbName,
+ "dbStatus"_attr = dbStatus);
} else {
- warning() << "database '" << dbName << "' (" << (_stats.databasesCloned + 1) << " of "
- << _databases.size() << ") clone failed due to " << dbStatus.toString();
+ LOGV2_WARNING(21060,
+ "database '{dbName}' ({stats_databasesCloned_1} of {databases_size}) "
+ "clone failed due to {dbStatus}",
+ "dbName"_attr = dbName,
+ "stats_databasesCloned_1"_attr = (_stats.databasesCloned + 1),
+ "databases_size"_attr = _databases.size(),
+ "dbStatus"_attr = dbStatus.toString());
setInitialSyncFailedStatus(dbStatus);
return;
}
if (StringData(dbName).equalCaseInsensitive("admin")) {
- LOG(1) << "Finished the 'admin' db, now validating it.";
+ LOGV2_DEBUG(21058, 1, "Finished the 'admin' db, now validating it.");
// Do special checks for the admin database because of auth. collections.
auto adminStatus = Status(ErrorCodes::NotYetInitialized, "");
{
@@ -167,7 +182,10 @@ void AllDatabaseCloner::postStage() {
adminStatus = getStorageInterface()->isAdminDbValid(opCtx);
}
if (!adminStatus.isOK()) {
- LOG(1) << "Validation failed on 'admin' db due to " << adminStatus;
+ LOGV2_DEBUG(21059,
+ 1,
+ "Validation failed on 'admin' db due to {adminStatus}",
+ "adminStatus"_attr = adminStatus);
setInitialSyncFailedStatus(adminStatus);
return;
}
diff --git a/src/mongo/db/repl/all_database_cloner_test.cpp b/src/mongo/db/repl/all_database_cloner_test.cpp
index ffc72c8d2fa..bbbc8a66c67 100644
--- a/src/mongo/db/repl/all_database_cloner_test.cpp
+++ b/src/mongo/db/repl/all_database_cloner_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/db/repl/all_database_cloner.h"
@@ -35,9 +37,11 @@
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/dbtests/mock/mock_dbclient_connection.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/concurrency/thread_pool.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace repl {
@@ -114,7 +118,7 @@ TEST_F(AllDatabaseClonerTest, RetriesConnect) {
ASSERT_EQ(2, _sharedData->getTotalRetries(WithLock::withoutLock()));
// Bring the server up.
- unittest::log() << "Bringing mock server back up.";
+ LOGV2(21061, "Bringing mock server back up.");
_mockServer->reboot();
// Allow the cloner to finish.
@@ -229,7 +233,7 @@ TEST_F(AllDatabaseClonerTest, RetriesListDatabases) {
ASSERT_EQ(2, _sharedData->getTotalRetries(WithLock::withoutLock()));
// Bring the server up.
- unittest::log() << "Bringing mock server back up.";
+ LOGV2(21062, "Bringing mock server back up.");
_mockServer->reboot();
// Allow the cloner to finish.
@@ -277,7 +281,7 @@ TEST_F(AllDatabaseClonerTest, RetriesListDatabasesButRollBackIdChanges) {
_mockServer->setCommandReply("replSetGetRBID", fromjson("{ok:1, rbid:2}"));
// Bring the server up.
- unittest::log() << "Bringing mock server back up.";
+ LOGV2(21063, "Bringing mock server back up.");
_mockServer->reboot();
// Allow the cloner to finish.
diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp
index 2df9c7428be..8f5be92b221 100644
--- a/src/mongo/db/repl/apply_ops.cpp
+++ b/src/mongo/db/repl/apply_ops.cpp
@@ -55,6 +55,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/session_catalog_mongod.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -266,7 +267,7 @@ Status _applyOps(OperationContext* opCtx,
ab.append(status.isOK());
if (!status.isOK()) {
- log() << "applyOps error applying: " << status;
+ LOGV2(21064, "applyOps error applying: {status}", "status"_attr = status);
errors++;
}
diff --git a/src/mongo/db/repl/base_cloner.cpp b/src/mongo/db/repl/base_cloner.cpp
index 68411039509..99b38605c4f 100644
--- a/src/mongo/db/repl/base_cloner.cpp
+++ b/src/mongo/db/repl/base_cloner.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/repl/base_cloner.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -91,8 +92,10 @@ Status BaseCloner::run() {
}
stdx::lock_guard<InitialSyncSharedData> lk(*_sharedData);
if (!_sharedData->getInitialSyncStatus(lk).isOK()) {
- log() << "Failing data clone because initial sync failed outside data clone: "
- << _sharedData->getInitialSyncStatus(lk);
+ LOGV2(21065,
+ "Failing data clone because initial sync failed outside data clone: "
+ "{sharedData_getInitialSyncStatus_lk}",
+ "sharedData_getInitialSyncStatus_lk"_attr = _sharedData->getInitialSyncStatus(lk));
}
return _sharedData->getInitialSyncStatus(lk);
}
@@ -116,13 +119,14 @@ void BaseCloner::pauseForFuzzer(BaseClonerStage* stage) {
// nb: This log message is specifically checked for in
// initial_sync_test_fixture_test.js, so if you change it here you will need to change
// it there.
- log() << "Collection Cloner scheduled a remote command on the "
- << describeForFuzzer(stage);
- log() << "initialSyncFuzzerSynchronizationPoint1 fail point enabled.";
+ LOGV2(21066,
+ "Collection Cloner scheduled a remote command on the {describeForFuzzer_stage}",
+ "describeForFuzzer_stage"_attr = describeForFuzzer(stage));
+ LOGV2(21067, "initialSyncFuzzerSynchronizationPoint1 fail point enabled.");
initialSyncFuzzerSynchronizationPoint1.pauseWhileSet();
if (MONGO_unlikely(initialSyncFuzzerSynchronizationPoint2.shouldFail())) {
- log() << "initialSyncFuzzerSynchronizationPoint2 fail point enabled.";
+ LOGV2(21068, "initialSyncFuzzerSynchronizationPoint2 fail point enabled.");
initialSyncFuzzerSynchronizationPoint2.pauseWhileSet();
}
}
@@ -130,15 +134,21 @@ void BaseCloner::pauseForFuzzer(BaseClonerStage* stage) {
}
BaseCloner::AfterStageBehavior BaseCloner::runStage(BaseClonerStage* stage) {
- LOG(1) << "Cloner " << getClonerName() << " running stage " << stage->getName();
+ LOGV2_DEBUG(21069,
+ 1,
+ "Cloner {getClonerName} running stage {stage_getName}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_getName"_attr = stage->getName());
pauseForFuzzer(stage);
auto isThisStageFailPoint = [this, stage](const BSONObj& data) {
return data["stage"].str() == stage->getName() && isMyFailPoint(data);
};
hangBeforeClonerStage.executeIf(
[&](const BSONObj& data) {
- log() << "Cloner " << getClonerName() << " hanging before running stage "
- << stage->getName();
+ LOGV2(21070,
+ "Cloner {getClonerName} hanging before running stage {stage_getName}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_getName"_attr = stage->getName());
while (!mustExit() && hangBeforeClonerStage.shouldFail(isThisStageFailPoint)) {
sleepmillis(100);
}
@@ -147,14 +157,20 @@ BaseCloner::AfterStageBehavior BaseCloner::runStage(BaseClonerStage* stage) {
auto afterStageBehavior = runStageWithRetries(stage);
hangAfterClonerStage.executeIf(
[&](const BSONObj& data) {
- log() << "Cloner " << getClonerName() << " hanging after running stage "
- << stage->getName();
+ LOGV2(21071,
+ "Cloner {getClonerName} hanging after running stage {stage_getName}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_getName"_attr = stage->getName());
while (!mustExit() && hangAfterClonerStage.shouldFail(isThisStageFailPoint)) {
sleepmillis(100);
}
},
isThisStageFailPoint);
- LOG(1) << "Cloner " << getClonerName() << " finished running stage " << stage->getName();
+ LOGV2_DEBUG(21072,
+ 1,
+ "Cloner {getClonerName} finished running stage {stage_getName}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_getName"_attr = stage->getName());
return afterStageBehavior;
}
@@ -170,7 +186,7 @@ Status BaseCloner::checkRollBackIdIsUnchanged() {
if (ErrorCodes::isRetriableError(e)) {
auto status = e.toStatus().withContext(
": failed while attempting to retrieve rollBackId after re-connect");
- LOG(1) << status;
+ LOGV2_DEBUG(21073, 1, "{status}", "status"_attr = status);
return status;
}
throw;
@@ -200,16 +216,23 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage*
// If lastError is set, this is a retry.
hangBeforeRetryingClonerStage.executeIf(
[&](const BSONObj& data) {
- log() << "Cloner " << getClonerName() << " hanging before retrying stage "
- << stage->getName();
+ LOGV2(
+ 21074,
+ "Cloner {getClonerName} hanging before retrying stage {stage_getName}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_getName"_attr = stage->getName());
while (!mustExit() &&
hangBeforeRetryingClonerStage.shouldFail(isThisStageFailPoint)) {
sleepmillis(100);
}
},
isThisStageFailPoint);
- log() << "Initial Sync retrying " << getClonerName() << " stage "
- << stage->getName() << " due to " << lastError;
+ LOGV2(21075,
+ "Initial Sync retrying {getClonerName} stage {stage_getName} due to "
+ "{lastError}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_getName"_attr = stage->getName(),
+ "lastError"_attr = lastError);
bool shouldRetry = [&] {
stdx::lock_guard<InitialSyncSharedData> lk(*_sharedData);
return _sharedData->shouldRetryOperation(lk, &_retryableOp);
@@ -225,9 +248,11 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage*
}
hangBeforeCheckingRollBackIdClonerStage.executeIf(
[&](const BSONObj& data) {
- log() << "Cloner " << getClonerName()
- << " hanging before checking rollBackId for stage "
- << stage->getName();
+ LOGV2(21076,
+ "Cloner {getClonerName} hanging before checking rollBackId for stage "
+ "{stage_getName}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_getName"_attr = stage->getName());
while (!mustExit() &&
hangBeforeCheckingRollBackIdClonerStage.shouldFail(
isThisStageFailPoint)) {
@@ -248,12 +273,21 @@ BaseCloner::AfterStageBehavior BaseCloner::runStageWithRetries(BaseClonerStage*
} catch (DBException& e) {
lastError = e.toStatus();
if (!stage->isTransientError(lastError)) {
- log() << "Non-retryable error occured during cloner " << getClonerName()
- << " stage " + stage->getName() << ": " << lastError;
+ LOGV2(21077,
+ "Non-retryable error occured during cloner "
+ "{getClonerName}{stage_stage_getName}: {lastError}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_stage_getName"_attr = " stage " + stage->getName(),
+ "lastError"_attr = lastError);
throw;
}
- LOG(1) << "Transient error occured during cloner " << getClonerName()
- << " stage " + stage->getName() << ": " << lastError;
+ LOGV2_DEBUG(21078,
+ 1,
+ "Transient error occured during cloner "
+ "{getClonerName}{stage_stage_getName}: {lastError}",
+ "getClonerName"_attr = getClonerName(),
+ "stage_stage_getName"_attr = " stage " + stage->getName(),
+ "lastError"_attr = lastError);
}
}
}
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index bbe81147ee0..270dc41626c 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -58,6 +58,7 @@
#include "mongo/db/repl/rs_rollback.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/s/shard_identity_rollback_notifier.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/util/log.h"
@@ -211,12 +212,13 @@ void BackgroundSync::_run() {
_runProducer();
} catch (const DBException& e) {
std::string msg(str::stream() << "sync producer problem: " << redact(e));
- error() << msg;
+ LOGV2_ERROR(21125, "{msg}", "msg"_attr = msg);
_replCoord->setMyHeartbeatMessage(msg);
sleepmillis(100); // sleep a bit to keep from hammering this thread with temp. errors.
} catch (const std::exception& e2) {
// redact(std::exception&) doesn't work
- severe() << "sync producer exception: " << redact(e2.what());
+ LOGV2_FATAL(
+ 21127, "sync producer exception: {e2_what}", "e2_what"_attr = redact(e2.what()));
fassertFailed(28546);
}
}
@@ -253,8 +255,9 @@ void BackgroundSync::_runProducer() {
void BackgroundSync::_produce() {
if (MONGO_unlikely(stopReplProducer.shouldFail())) {
// This log output is used in js tests so please leave it.
- log() << "bgsync - stopReplProducer fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21079,
+ "bgsync - stopReplProducer fail point "
+ "enabled. Blocking until fail point is disabled.");
mongo::sleepsecs(1);
return;
}
@@ -296,7 +299,9 @@ void BackgroundSync::_produce() {
const auto requiredOpTime = (minValidSaved > _lastOpTimeFetched) ? minValidSaved : OpTime();
lastOpTimeFetched = _lastOpTimeFetched;
if (!_syncSourceHost.empty()) {
- log() << "Clearing sync source " << _syncSourceHost << " to choose a new one.";
+ LOGV2(21080,
+ "Clearing sync source {syncSourceHost} to choose a new one.",
+ "syncSourceHost"_attr = _syncSourceHost);
}
_syncSourceHost = HostAndPort();
_syncSourceResolver = std::make_unique<SyncSourceResolver>(
@@ -328,14 +333,22 @@ void BackgroundSync::_produce() {
if (syncSourceResp.syncSourceStatus == ErrorCodes::OplogStartMissing) {
// All (accessible) sync sources are too far ahead of us.
if (_replCoord->getMemberState().primary()) {
- warning() << "Too stale to catch up.";
- log() << "Our newest OpTime : " << lastOpTimeFetched;
- log() << "Earliest OpTime available is " << syncSourceResp.earliestOpTimeSeen
- << " from " << syncSourceResp.getSyncSource();
+ LOGV2_WARNING(21115, "Too stale to catch up.");
+ LOGV2(21081,
+ "Our newest OpTime : {lastOpTimeFetched}",
+ "lastOpTimeFetched"_attr = lastOpTimeFetched);
+ LOGV2(21082,
+ "Earliest OpTime available is {syncSourceResp_earliestOpTimeSeen} from "
+ "{syncSourceResp_getSyncSource}",
+ "syncSourceResp_earliestOpTimeSeen"_attr = syncSourceResp.earliestOpTimeSeen,
+ "syncSourceResp_getSyncSource"_attr = syncSourceResp.getSyncSource());
auto status = _replCoord->abortCatchupIfNeeded(
ReplicationCoordinator::PrimaryCatchUpConclusionReason::kFailedWithError);
if (!status.isOK()) {
- LOG(1) << "Aborting catch-up failed with status: " << status;
+ LOGV2_DEBUG(21083,
+ 1,
+ "Aborting catch-up failed with status: {status}",
+ "status"_attr = status);
}
return;
}
@@ -349,22 +362,33 @@ void BackgroundSync::_produce() {
auto opCtx = cc().makeOperationContext();
ReplicationStateTransitionLockGuard transitionGuard(opCtx.get(), MODE_X);
- error() << "too stale to catch up -- entering maintenance mode";
- log() << "Our newest OpTime : " << lastOpTimeFetched;
- log() << "Earliest OpTime available is " << syncSourceResp.earliestOpTimeSeen;
- log() << "See http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember";
+ LOGV2_ERROR(21126, "too stale to catch up -- entering maintenance mode");
+ LOGV2(21084,
+ "Our newest OpTime : {lastOpTimeFetched}",
+ "lastOpTimeFetched"_attr = lastOpTimeFetched);
+ LOGV2(21085,
+ "Earliest OpTime available is {syncSourceResp_earliestOpTimeSeen}",
+ "syncSourceResp_earliestOpTimeSeen"_attr = syncSourceResp.earliestOpTimeSeen);
+ LOGV2(21086, "See http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember");
// Activate maintenance mode and transition to RECOVERING.
auto status = _replCoord->setMaintenanceMode(true);
if (!status.isOK()) {
- warning() << "Failed to transition into maintenance mode: " << status;
+ LOGV2_WARNING(21116,
+ "Failed to transition into maintenance mode: {status}",
+ "status"_attr = status);
// Do not mark ourselves too stale on errors so we can try again next time.
return;
}
status = _replCoord->setFollowerMode(MemberState::RS_RECOVERING);
if (!status.isOK()) {
- warning() << "Failed to transition into " << MemberState(MemberState::RS_RECOVERING)
- << ". Current state: " << _replCoord->getMemberState() << causedBy(status);
+ LOGV2_WARNING(21117,
+ "Failed to transition into {MemberState_MemberState_RS_RECOVERING}. "
+ "Current state: {replCoord_getMemberState}{causedBy_status}",
+ "MemberState_MemberState_RS_RECOVERING"_attr =
+ MemberState(MemberState::RS_RECOVERING),
+ "replCoord_getMemberState"_attr = _replCoord->getMemberState(),
+ "causedBy_status"_attr = causedBy(status));
// Do not mark ourselves too stale on errors so we can try again next time.
return;
}
@@ -384,22 +408,31 @@ void BackgroundSync::_produce() {
forceBgSyncSyncSourceRetryWaitMS.execute(
[&](const BSONObj& data) { sleepMS = data["sleepMS"].numberInt(); });
- log() << "Chose same sync source candidate as last time, " << source
- << ". Sleeping for " << sleepMS
- << "ms to avoid immediately choosing a new sync source for the same reason as "
- "last time.";
+ LOGV2(
+ 21087,
+ "Chose same sync source candidate as last time, {source}. Sleeping for {sleepMS}ms "
+ "to avoid immediately choosing a new sync source for the same reason as "
+ "last time.",
+ "source"_attr = source,
+ "sleepMS"_attr = sleepMS);
numTimesChoseSameSyncSource.increment(1);
mongo::sleepmillis(sleepMS);
} else {
- log() << "Changed sync source from "
- << (oldSource.empty() ? std::string("empty") : oldSource.toString()) << " to "
- << source;
+ LOGV2(
+ 21088,
+ "Changed sync source from {oldSource_empty_std_string_empty_oldSource} to {source}",
+ "oldSource_empty_std_string_empty_oldSource"_attr =
+ (oldSource.empty() ? std::string("empty") : oldSource.toString()),
+ "source"_attr = source);
numTimesChoseDifferentSyncSource.increment(1);
}
} else {
if (!syncSourceResp.isOK()) {
- log() << "failed to find sync source, received error "
- << syncSourceResp.syncSourceStatus.getStatus();
+ LOGV2(21089,
+ "failed to find sync source, received error "
+ "{syncSourceResp_syncSourceStatus_getStatus}",
+ "syncSourceResp_syncSourceStatus_getStatus"_attr =
+ syncSourceResp.syncSourceStatus.getStatus());
}
long long sleepMS = 1000;
@@ -407,8 +440,10 @@ void BackgroundSync::_produce() {
[&](const BSONObj& data) { sleepMS = data["sleepMS"].numberInt(); });
// No sync source found.
- LOG(1) << "Could not find a sync source. Sleeping for " << sleepMS
- << "ms before trying again.";
+ LOGV2_DEBUG(21090,
+ 1,
+ "Could not find a sync source. Sleeping for {sleepMS}ms before trying again.",
+ "sleepMS"_attr = sleepMS);
numTimesCouldNotFindSyncSource.increment(1);
mongo::sleepmillis(sleepMS);
return;
@@ -417,10 +452,11 @@ void BackgroundSync::_produce() {
// If we find a good sync source after having gone too stale, disable maintenance mode so we can
// transition to SECONDARY.
if (_tooStale.swap(false)) {
- log() << "No longer too stale. Able to sync from " << source;
+ LOGV2(21091, "No longer too stale. Able to sync from {source}", "source"_attr = source);
auto status = _replCoord->setMaintenanceMode(false);
if (!status.isOK()) {
- warning() << "Failed to leave maintenance mode: " << status;
+ LOGV2_WARNING(
+ 21118, "Failed to leave maintenance mode: {status}", "status"_attr = status);
}
}
@@ -484,24 +520,34 @@ void BackgroundSync::_produce() {
}
const auto logLevel = getTestCommandsEnabled() ? 0 : 1;
- LOG(logLevel) << "scheduling fetcher to read remote oplog on " << source << " starting at "
- << oplogFetcher->getFindQuery_forTest()["filter"];
+ LOGV2_DEBUG(21092,
+ logSeverityV1toV2(logLevel).toInt(),
+ "scheduling fetcher to read remote oplog on {source} starting at "
+ "{oplogFetcher_getFindQuery_forTest_filter}",
+ "source"_attr = source,
+ "oplogFetcher_getFindQuery_forTest_filter"_attr =
+ oplogFetcher->getFindQuery_forTest()["filter"]);
auto scheduleStatus = oplogFetcher->startup();
if (!scheduleStatus.isOK()) {
- warning() << "unable to schedule fetcher to read remote oplog on " << source << ": "
- << scheduleStatus;
+ LOGV2_WARNING(
+ 21119,
+ "unable to schedule fetcher to read remote oplog on {source}: {scheduleStatus}",
+ "source"_attr = source,
+ "scheduleStatus"_attr = scheduleStatus);
return;
}
oplogFetcher->join();
- LOG(1) << "fetcher stopped reading remote oplog on " << source;
+ LOGV2_DEBUG(
+ 21093, 1, "fetcher stopped reading remote oplog on {source}", "source"_attr = source);
// If the background sync is stopped after the fetcher is started, we need to
// re-evaluate our sync source and oplog common point.
if (getState() != ProducerState::Running) {
- log() << "Replication producer stopped after oplog fetcher finished returning a batch from "
- "our sync source. Abandoning this batch of oplog entries and re-evaluating our "
- "sync source.";
+ LOGV2(21094,
+ "Replication producer stopped after oplog fetcher finished returning a batch from "
+ "our sync source. Abandoning this batch of oplog entries and re-evaluating our "
+ "sync source.");
return;
}
@@ -509,7 +555,9 @@ void BackgroundSync::_produce() {
// This is bad because it means that our source
// has not returned oplog entries in ascending ts order, and they need to be.
- warning() << redact(fetcherReturnStatus);
+ LOGV2_WARNING(21120,
+ "{fetcherReturnStatus}",
+ "fetcherReturnStatus"_attr = redact(fetcherReturnStatus));
// Do not blacklist the server here, it will be blacklisted when we try to reuse it,
// if it can't return a matching oplog start from the last fetch oplog ts field.
return;
@@ -520,19 +568,23 @@ void BackgroundSync::_produce() {
opCtx.get(), fetcherReturnStatus, source, syncSourceResp.rbid, storageInterface);
if (bgSyncHangAfterRunRollback.shouldFail()) {
- log() << "bgSyncHangAfterRunRollback failpoint is set.";
+ LOGV2(21095, "bgSyncHangAfterRunRollback failpoint is set.");
while (MONGO_unlikely(bgSyncHangAfterRunRollback.shouldFail()) && !inShutdown()) {
mongo::sleepmillis(100);
}
}
} else if (fetcherReturnStatus == ErrorCodes::InvalidBSON) {
Seconds blacklistDuration(60);
- warning() << "Fetcher got invalid BSON while querying oplog. Blacklisting sync source "
- << source << " for " << blacklistDuration << ".";
+ LOGV2_WARNING(21121,
+ "Fetcher got invalid BSON while querying oplog. Blacklisting sync source "
+ "{source} for {blacklistDuration}.",
+ "source"_attr = source,
+ "blacklistDuration"_attr = blacklistDuration);
_replCoord->blacklistSyncSource(source, Date_t::now() + blacklistDuration);
} else if (!fetcherReturnStatus.isOK()) {
- warning() << "Fetcher stopped querying remote oplog with error: "
- << redact(fetcherReturnStatus);
+ LOGV2_WARNING(21122,
+ "Fetcher stopped querying remote oplog with error: {fetcherReturnStatus}",
+ "fetcherReturnStatus"_attr = redact(fetcherReturnStatus));
}
}
@@ -564,7 +616,10 @@ Status BackgroundSync::_enqueueDocuments(Fetcher::Documents::const_iterator begi
// Update last fetched info.
_lastOpTimeFetched = info.lastDocument;
- LOG(3) << "batch resetting _lastOpTimeFetched: " << _lastOpTimeFetched;
+ LOGV2_DEBUG(21096,
+ 3,
+ "batch resetting _lastOpTimeFetched: {lastOpTimeFetched}",
+ "lastOpTimeFetched"_attr = _lastOpTimeFetched);
}
// Check some things periodically (whenever we run out of items in the current cursor batch).
@@ -587,11 +642,13 @@ void BackgroundSync::_runRollback(OperationContext* opCtx,
int requiredRBID,
StorageInterface* storageInterface) {
if (_replCoord->getMemberState().primary()) {
- warning() << "Rollback situation detected in catch-up mode. Aborting catch-up mode.";
+ LOGV2_WARNING(21123,
+ "Rollback situation detected in catch-up mode. Aborting catch-up mode.");
auto status = _replCoord->abortCatchupIfNeeded(
ReplicationCoordinator::PrimaryCatchUpConclusionReason::kFailedWithError);
if (!status.isOK()) {
- LOG(1) << "Aborting catch-up failed with status: " << status;
+ LOGV2_DEBUG(
+ 21097, 1, "Aborting catch-up failed with status: {status}", "status"_attr = status);
}
return;
}
@@ -610,8 +667,12 @@ void BackgroundSync::_runRollback(OperationContext* opCtx,
lastOpTimeFetched = _lastOpTimeFetched;
}
- log() << "Starting rollback due to " << redact(fetcherReturnStatus);
- log() << "Replication commit point: " << _replCoord->getLastCommittedOpTime();
+ LOGV2(21098,
+ "Starting rollback due to {fetcherReturnStatus}",
+ "fetcherReturnStatus"_attr = redact(fetcherReturnStatus));
+ LOGV2(21099,
+ "Replication commit point: {replCoord_getLastCommittedOpTime}",
+ "replCoord_getLastCommittedOpTime"_attr = _replCoord->getLastCommittedOpTime());
// TODO: change this to call into the Applier directly to block until the applier is
// drained.
@@ -619,8 +680,11 @@ void BackgroundSync::_runRollback(OperationContext* opCtx,
// Wait till all buffered oplog entries have drained and been applied.
auto lastApplied = _replCoord->getMyLastAppliedOpTime();
if (lastApplied != lastOpTimeFetched) {
- log() << "Waiting for all operations from " << lastApplied << " until " << lastOpTimeFetched
- << " to be applied before starting rollback.";
+ LOGV2(21100,
+ "Waiting for all operations from {lastApplied} until {lastOpTimeFetched} to be "
+ "applied before starting rollback.",
+ "lastApplied"_attr = lastApplied,
+ "lastOpTimeFetched"_attr = lastOpTimeFetched);
while (lastOpTimeFetched > (lastApplied = _replCoord->getMyLastAppliedOpTime())) {
sleepmillis(10);
if (getState() != ProducerState::Running) {
@@ -631,8 +695,9 @@ void BackgroundSync::_runRollback(OperationContext* opCtx,
if (MONGO_unlikely(rollbackHangBeforeStart.shouldFail())) {
// This log output is used in js tests so please leave it.
- log() << "rollback - rollbackHangBeforeStart fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21101,
+ "rollback - rollbackHangBeforeStart fail point "
+ "enabled. Blocking until fail point is disabled.");
while (MONGO_unlikely(rollbackHangBeforeStart.shouldFail()) && !inShutdown()) {
mongo::sleepsecs(1);
}
@@ -659,11 +724,11 @@ void BackgroundSync::_runRollback(OperationContext* opCtx,
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
if (!forceRollbackViaRefetch.load() && storageEngine->supportsRecoverToStableTimestamp()) {
- log() << "Rollback using 'recoverToStableTimestamp' method.";
+ LOGV2(21102, "Rollback using 'recoverToStableTimestamp' method.");
_runRollbackViaRecoverToCheckpoint(
opCtx, source, &localOplog, storageInterface, getConnection);
} else {
- log() << "Rollback using the 'rollbackViaRefetch' method.";
+ LOGV2(21103, "Rollback using the 'rollbackViaRefetch' method.");
_fallBackOnRollbackViaRefetch(
opCtx, source, abortedIndexBuilds, requiredRBID, &localOplog, getConnection);
}
@@ -695,15 +760,17 @@ void BackgroundSync::_runRollbackViaRecoverToCheckpoint(
_rollback = std::make_unique<RollbackImpl>(
localOplog, &remoteOplog, storageInterface, _replicationProcess, _replCoord);
- log() << "Scheduling rollback (sync source: " << source << ")";
+ LOGV2(21104, "Scheduling rollback (sync source: {source})", "source"_attr = source);
auto status = _rollback->runRollback(opCtx);
if (status.isOK()) {
- log() << "Rollback successful.";
+ LOGV2(21105, "Rollback successful.");
} else if (status == ErrorCodes::UnrecoverableRollbackError) {
- severe() << "Rollback failed with unrecoverable error: " << status;
+ LOGV2_FATAL(
+ 21128, "Rollback failed with unrecoverable error: {status}", "status"_attr = status);
fassertFailedWithStatusNoTrace(50666, status);
} else {
- warning() << "Rollback failed with retryable error: " << status;
+ LOGV2_WARNING(
+ 21124, "Rollback failed with retryable error: {status}", "status"_attr = status);
}
}
@@ -736,7 +803,9 @@ HostAndPort BackgroundSync::getSyncTarget() const {
void BackgroundSync::clearSyncTarget() {
stdx::unique_lock<Latch> lock(_mutex);
- log() << "Resetting sync source to empty, which was " << _syncSourceHost;
+ LOGV2(21106,
+ "Resetting sync source to empty, which was {syncSourceHost}",
+ "syncSourceHost"_attr = _syncSourceHost);
_syncSourceHost = HostAndPort();
}
@@ -744,13 +813,13 @@ void BackgroundSync::stop(bool resetLastFetchedOptime) {
stdx::lock_guard<Latch> lock(_mutex);
_state = ProducerState::Stopped;
- log() << "Stopping replication producer";
+ LOGV2(21107, "Stopping replication producer");
_syncSourceHost = HostAndPort();
if (resetLastFetchedOptime) {
invariant(_oplogApplier->getBuffer()->isEmpty());
_lastOpTimeFetched = OpTime();
- log() << "Resetting last fetched optimes in bgsync";
+ LOGV2(21108, "Resetting last fetched optimes in bgsync");
}
if (_syncSourceResolver) {
@@ -779,21 +848,28 @@ void BackgroundSync::start(OperationContext* opCtx) {
// If a node steps down during drain mode, then the buffer may not be empty at the beginning
// of secondary state.
if (!_oplogApplier->getBuffer()->isEmpty()) {
- log() << "going to start syncing, but buffer is not empty";
+ LOGV2(21109, "going to start syncing, but buffer is not empty");
}
_state = ProducerState::Running;
// When a node steps down during drain mode, the last fetched optime would be newer than
// the last applied.
if (_lastOpTimeFetched <= lastAppliedOpTime) {
- LOG(1) << "Setting bgsync _lastOpTimeFetched=" << lastAppliedOpTime
- << ". Previous _lastOpTimeFetched: " << _lastOpTimeFetched;
+ LOGV2_DEBUG(21110,
+ 1,
+ "Setting bgsync _lastOpTimeFetched={lastAppliedOpTime}. Previous "
+ "_lastOpTimeFetched: {lastOpTimeFetched}",
+ "lastAppliedOpTime"_attr = lastAppliedOpTime,
+ "lastOpTimeFetched"_attr = _lastOpTimeFetched);
_lastOpTimeFetched = lastAppliedOpTime;
}
// Reload the last applied optime from disk if it has been changed.
} while (lastAppliedOpTime != _replCoord->getMyLastAppliedOpTime());
- LOG(1) << "bgsync fetch queue set to: " << _lastOpTimeFetched;
+ LOGV2_DEBUG(21111,
+ 1,
+ "bgsync fetch queue set to: {lastOpTimeFetched}",
+ "lastOpTimeFetched"_attr = _lastOpTimeFetched);
}
OpTime BackgroundSync::_readLastAppliedOpTime(OperationContext* opCtx) {
@@ -812,27 +888,35 @@ OpTime BackgroundSync::_readLastAppliedOpTime(OperationContext* opCtx) {
} catch (const ExceptionForCat<ErrorCategory::ShutdownError>&) {
throw;
} catch (const DBException& ex) {
- severe() << "Problem reading " << NamespaceString::kRsOplogNamespace.ns() << ": "
- << redact(ex);
+ LOGV2_FATAL(21129,
+ "Problem reading {NamespaceString_kRsOplogNamespace_ns}: {ex}",
+ "NamespaceString_kRsOplogNamespace_ns"_attr =
+ NamespaceString::kRsOplogNamespace.ns(),
+ "ex"_attr = redact(ex));
fassertFailed(18904);
}
OplogEntry parsedEntry(oplogEntry);
- LOG(1) << "Successfully read last entry of oplog while starting bgsync: " << redact(oplogEntry);
+ LOGV2_DEBUG(21112,
+ 1,
+ "Successfully read last entry of oplog while starting bgsync: {oplogEntry}",
+ "oplogEntry"_attr = redact(oplogEntry));
return parsedEntry.getOpTime();
}
bool BackgroundSync::shouldStopFetching() const {
// Check if we have been stopped.
if (getState() != ProducerState::Running) {
- LOG(2) << "Stopping oplog fetcher due to stop request.";
+ LOGV2_DEBUG(21113, 2, "Stopping oplog fetcher due to stop request.");
return true;
}
// Check current sync source.
if (getSyncTarget().empty()) {
- LOG(1) << "Stopping oplog fetcher; canceling oplog query because we have no valid sync "
- "source.";
+ LOGV2_DEBUG(21114,
+ 1,
+ "Stopping oplog fetcher; canceling oplog query because we have no valid sync "
+ "source.");
return true;
}
diff --git a/src/mongo/db/repl/collection_bulk_loader_impl.cpp b/src/mongo/db/repl/collection_bulk_loader_impl.cpp
index 944776aee8f..08393acd715 100644
--- a/src/mongo/db/repl/collection_bulk_loader_impl.cpp
+++ b/src/mongo/db/repl/collection_bulk_loader_impl.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/collection_bulk_loader_impl.h"
#include "mongo/db/repl/repl_server_parameters_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/destructor_guard.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -212,7 +213,7 @@ Status CollectionBulkLoaderImpl::insertDocuments(const std::vector<BSONObj>::con
Status CollectionBulkLoaderImpl::commit() {
return _runTaskReleaseResourcesOnFailure([&] {
_stats.startBuildingIndexes = Date_t::now();
- LOG(2) << "Creating indexes for ns: " << _nss.ns();
+ LOGV2_DEBUG(21130, 2, "Creating indexes for ns: {nss_ns}", "nss_ns"_attr = _nss.ns());
UnreplicatedWritesBlock uwb(_opCtx.get());
// Commit before deleting dups, so the dups will be removed from secondary indexes when
@@ -309,7 +310,11 @@ Status CollectionBulkLoaderImpl::commit() {
}
_stats.endBuildingIndexes = Date_t::now();
- LOG(2) << "Done creating indexes for ns: " << _nss.ns() << ", stats: " << _stats.toString();
+ LOGV2_DEBUG(21131,
+ 2,
+ "Done creating indexes for ns: {nss_ns}, stats: {stats}",
+ "nss_ns"_attr = _nss.ns(),
+ "stats"_attr = _stats.toString());
_releaseResources();
return Status::OK();
diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp
index 119239e1acf..8ad5135f5eb 100644
--- a/src/mongo/db/repl/collection_cloner.cpp
+++ b/src/mongo/db/repl/collection_cloner.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/repl/database_cloner_gen.h"
#include "mongo/db/repl/repl_server_parameters_gen.h"
#include "mongo/db/wire_version.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -117,9 +118,12 @@ BaseCloner::AfterStageBehavior CollectionCloner::CollectionClonerStage::run() {
try {
return ClonerStage<CollectionCloner>::run();
} catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
- log() << "CollectionCloner ns: '" << getCloner()->getSourceNss() << "' uuid: UUID(\""
- << getCloner()->getSourceUuid()
- << "\") stopped because collection was dropped on source.";
+ LOGV2(
+ 21132,
+ "CollectionCloner ns: '{getCloner_getSourceNss}' uuid: "
+ "UUID(\"{getCloner_getSourceUuid}\") stopped because collection was dropped on source.",
+ "getCloner_getSourceNss"_attr = getCloner()->getSourceNss(),
+ "getCloner_getSourceUuid"_attr = getCloner()->getSourceUuid());
getCloner()->waitForDatabaseWorkToComplete();
return kSkipRemainingStages;
} catch (const DBException&) {
@@ -135,8 +139,9 @@ BaseCloner::AfterStageBehavior CollectionCloner::countStage() {
// so we set it to zero here to avoid aborting the collection clone.
// Note that this count value is only used for reporting purposes.
if (count < 0) {
- warning() << "Count command returned negative value. Updating to 0 to allow progress "
- "meter to function properly. ";
+ LOGV2_WARNING(21142,
+ "Count command returned negative value. Updating to 0 to allow progress "
+ "meter to function properly. ");
count = 0;
}
@@ -151,8 +156,11 @@ BaseCloner::AfterStageBehavior CollectionCloner::countStage() {
BaseCloner::AfterStageBehavior CollectionCloner::listIndexesStage() {
auto indexSpecs = getClient()->getIndexSpecs(_sourceDbAndUuid, QueryOption_SlaveOk);
if (indexSpecs.empty()) {
- warning() << "No indexes found for collection " << _sourceNss.ns() << " while cloning from "
- << getSource();
+ LOGV2_WARNING(
+ 21143,
+ "No indexes found for collection {sourceNss_ns} while cloning from {getSource}",
+ "sourceNss_ns"_attr = _sourceNss.ns(),
+ "getSource"_attr = getSource());
}
for (auto&& spec : indexSpecs) {
if (spec["name"].str() == "_id_"_sd) {
@@ -167,9 +175,10 @@ BaseCloner::AfterStageBehavior CollectionCloner::listIndexesStage() {
};
if (!_idIndexSpec.isEmpty() && _collectionOptions.autoIndexId == CollectionOptions::NO) {
- warning()
- << "Found the _id_ index spec but the collection specified autoIndexId of false on ns:"
- << this->_sourceNss;
+ LOGV2_WARNING(21144,
+ "Found the _id_ index spec but the collection specified autoIndexId of false "
+ "on ns:{this_sourceNss}",
+ "this_sourceNss"_attr = this->_sourceNss);
}
return kContinueNormally;
}
@@ -200,12 +209,12 @@ void CollectionCloner::runQuery() {
if (_resumeSupported) {
if (_resumeToken) {
// Resume the query from where we left off.
- LOG(1) << "Collection cloner will resume the last successful query";
+ LOGV2_DEBUG(21133, 1, "Collection cloner will resume the last successful query");
query = QUERY("query" << BSONObj() << "$readOnce" << true << "$_requestResumeToken"
<< true << "$_resumeAfter" << _resumeToken.get());
} else {
// New attempt at a resumable query.
- LOG(1) << "Collection cloner will run a new query";
+ LOGV2_DEBUG(21134, 1, "Collection cloner will run a new query");
query = QUERY("query" << BSONObj() << "$readOnce" << true << "$_requestResumeToken"
<< true);
}
@@ -247,7 +256,9 @@ void CollectionCloner::runQuery() {
// Collection has changed upstream. This will trigger the code block above next round,
// (unless we find out the collection was dropped via getting a NamespaceNotFound).
if (_queryStage.isCursorError(status)) {
- log() << "Lost cursor during non-resumable query: " << status;
+ LOGV2(21135,
+ "Lost cursor during non-resumable query: {status}",
+ "status"_attr = status);
_lostNonResumableCursor = true;
throw;
}
@@ -268,7 +279,7 @@ void CollectionCloner::handleNextBatch(DBClientCursorBatchIterator& iter) {
std::string message = str::stream()
<< "Collection cloning cancelled due to initial sync failure: "
<< getSharedData()->getInitialSyncStatus(lk).toString();
- log() << message;
+ LOGV2(21136, "{message}", "message"_attr = message);
uasserted(ErrorCodes::CallbackCanceled, message);
}
}
@@ -316,9 +327,10 @@ void CollectionCloner::handleNextBatch(DBClientCursorBatchIterator& iter) {
while (MONGO_unlikely(
initialSyncHangCollectionClonerAfterHandlingBatchResponse.shouldFail()) &&
!mustExit()) {
- log() << "initialSyncHangCollectionClonerAfterHandlingBatchResponse fail point "
- "enabled for "
- << _sourceNss.toString() << ". Blocking until fail point is disabled.";
+ LOGV2(21137,
+ "initialSyncHangCollectionClonerAfterHandlingBatchResponse fail point "
+ "enabled for {sourceNss}. Blocking until fail point is disabled.",
+ "sourceNss"_attr = _sourceNss.toString());
mongo::sleepsecs(1);
}
},
@@ -336,8 +348,9 @@ void CollectionCloner::insertDocumentsCallback(const executor::TaskExecutor::Cal
stdx::lock_guard<Latch> lk(_mutex);
std::vector<BSONObj> docs;
if (_documentsToInsert.size() == 0) {
- warning() << "insertDocumentsCallback, but no documents to insert for ns:"
- << _sourceNss;
+ LOGV2_WARNING(21145,
+ "insertDocumentsCallback, but no documents to insert for ns:{sourceNss}",
+ "sourceNss"_attr = _sourceNss);
return;
}
_documentsToInsert.swap(docs);
@@ -353,8 +366,9 @@ void CollectionCloner::insertDocumentsCallback(const executor::TaskExecutor::Cal
initialSyncHangDuringCollectionClone.executeIf(
[&](const BSONObj&) {
- log() << "initial sync - initialSyncHangDuringCollectionClone fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21138,
+ "initial sync - initialSyncHangDuringCollectionClone fail point "
+ "enabled. Blocking until fail point is disabled.");
while (MONGO_unlikely(initialSyncHangDuringCollectionClone.shouldFail()) &&
!mustExit()) {
mongo::sleepsecs(1);
@@ -386,11 +400,11 @@ void CollectionCloner::killOldQueryCursor() {
auto id = _remoteCursorId;
auto cmdObj = BSON("killCursors" << nss.coll() << "cursors" << BSON_ARRAY(id));
- LOG(1) << "Attempting to kill old remote cursor with id: " << id;
+ LOGV2_DEBUG(21139, 1, "Attempting to kill old remote cursor with id: {id}", "id"_attr = id);
try {
getClient()->runCommand(nss.db().toString(), cmdObj, infoObj);
} catch (...) {
- log() << "Error while trying to kill remote cursor after transient query error";
+ LOGV2(21140, "Error while trying to kill remote cursor after transient query error");
}
// Clear the stored cursorId on success.
@@ -404,7 +418,7 @@ void CollectionCloner::forgetOldQueryCursor() {
// Throws.
void CollectionCloner::abortNonResumableClone(const Status& status) {
invariant(!_resumeSupported);
- log() << "Error during non-resumable clone: " << status;
+ LOGV2(21141, "Error during non-resumable clone: {status}", "status"_attr = status);
std::string message = str::stream()
<< "Collection clone failed and is not resumable. nss: " << _sourceNss;
uasserted(ErrorCodes::InitialSyncFailure, message);
diff --git a/src/mongo/db/repl/data_replicator_external_state_impl.cpp b/src/mongo/db/repl/data_replicator_external_state_impl.cpp
index 33ea1ea0d16..bed866625c6 100644
--- a/src/mongo/db/repl/data_replicator_external_state_impl.cpp
+++ b/src/mongo/db/repl/data_replicator_external_state_impl.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/repl/replication_coordinator_external_state.h"
#include "mongo/db/repl/replication_process.h"
#include "mongo/db/repl/storage_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -101,16 +102,22 @@ bool DataReplicatorExternalStateImpl::shouldStopFetching(
// If OplogQueryMetadata was provided, its values were used to determine if we should
// change sync sources.
if (oqMetadata) {
- log() << "Canceling oplog query due to OplogQueryMetadata. We have to choose a new "
- "sync source. Current source: "
- << source << ", OpTime " << oqMetadata->getLastOpApplied()
- << ", its sync source index:" << oqMetadata->getSyncSourceIndex();
+ LOGV2(21150,
+ "Canceling oplog query due to OplogQueryMetadata. We have to choose a new "
+ "sync source. Current source: {source}, OpTime {oqMetadata_getLastOpApplied}, "
+ "its sync source index:{oqMetadata_getSyncSourceIndex}",
+ "source"_attr = source,
+ "oqMetadata_getLastOpApplied"_attr = oqMetadata->getLastOpApplied(),
+ "oqMetadata_getSyncSourceIndex"_attr = oqMetadata->getSyncSourceIndex());
} else {
- log() << "Canceling oplog query due to ReplSetMetadata. We have to choose a new sync "
- "source. Current source: "
- << source << ", OpTime " << replMetadata.getLastOpVisible()
- << ", its sync source index:" << replMetadata.getSyncSourceIndex();
+ LOGV2(21151,
+ "Canceling oplog query due to ReplSetMetadata. We have to choose a new sync "
+ "source. Current source: {source}, OpTime {replMetadata_getLastOpVisible}, its "
+ "sync source index:{replMetadata_getSyncSourceIndex}",
+ "source"_attr = source,
+ "replMetadata_getLastOpVisible"_attr = replMetadata.getLastOpVisible(),
+ "replMetadata_getSyncSourceIndex"_attr = replMetadata.getSyncSourceIndex());
}
return true;
}
diff --git a/src/mongo/db/repl/database_cloner.cpp b/src/mongo/db/repl/database_cloner.cpp
index d896ee08d0e..5dbabe1cb92 100644
--- a/src/mongo/db/repl/database_cloner.cpp
+++ b/src/mongo/db/repl/database_cloner.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/commands/list_collections_filter.h"
#include "mongo/db/repl/database_cloner.h"
#include "mongo/db/repl/database_cloner_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -88,10 +89,13 @@ BaseCloner::AfterStageBehavior DatabaseCloner::listCollectionsStage() {
}
NamespaceString collectionNamespace(_dbName, result.getName());
if (collectionNamespace.isSystem() && !collectionNamespace.isLegalClientSystemNS()) {
- LOG(1) << "Skipping 'system' collection: " << collectionNamespace.ns();
+ LOGV2_DEBUG(21146,
+ 1,
+ "Skipping 'system' collection: {collectionNamespace_ns}",
+ "collectionNamespace_ns"_attr = collectionNamespace.ns());
continue;
}
- LOG(2) << "Allowing cloning of collectionInfo: " << info;
+ LOGV2_DEBUG(21147, 2, "Allowing cloning of collectionInfo: {info}", "info"_attr = info);
bool isDuplicate = seen.insert(result.getName().toString()).second;
uassert(51005,
@@ -137,10 +141,13 @@ void DatabaseCloner::postStage() {
}
auto collStatus = _currentCollectionCloner->run();
if (collStatus.isOK()) {
- LOG(1) << "collection clone finished: " << sourceNss;
+ LOGV2_DEBUG(
+ 21148, 1, "collection clone finished: {sourceNss}", "sourceNss"_attr = sourceNss);
} else {
- error() << "collection clone for '" << sourceNss << "' failed due to "
- << collStatus.toString();
+ LOGV2_ERROR(21149,
+ "collection clone for '{sourceNss}' failed due to {collStatus}",
+ "sourceNss"_attr = sourceNss,
+ "collStatus"_attr = collStatus.toString());
setInitialSyncFailedStatus(
{ErrorCodes::InitialSyncFailure,
collStatus
diff --git a/src/mongo/db/repl/drop_pending_collection_reaper.cpp b/src/mongo/db/repl/drop_pending_collection_reaper.cpp
index 4c380e4c8c5..cf3e1e54843 100644
--- a/src/mongo/db/repl/drop_pending_collection_reaper.cpp
+++ b/src/mongo/db/repl/drop_pending_collection_reaper.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -89,8 +90,11 @@ void DropPendingCollectionReaper::addDropPendingNamespace(
};
if (std::find_if(lowerBound, upperBound, matcher) != upperBound) {
- severe() << "Failed to add drop-pending collection " << dropPendingNamespace
- << " with drop optime " << dropOpTime << ": duplicate optime and namespace pair.";
+ LOGV2_FATAL(21156,
+ "Failed to add drop-pending collection {dropPendingNamespace} with drop optime "
+ "{dropOpTime}: duplicate optime and namespace pair.",
+ "dropPendingNamespace"_attr = dropPendingNamespace,
+ "dropOpTime"_attr = dropOpTime);
fassertFailedNoTrace(40448);
}
@@ -136,16 +140,23 @@ bool DropPendingCollectionReaper::rollBackDropPendingCollection(
auto matcher = [&pendingNss](const auto& pair) { return pair.second == pendingNss; };
auto it = std::find_if(lowerBound, upperBound, matcher);
if (it == upperBound) {
- warning() << "Cannot find drop-pending namespace at OpTime " << opTime
- << " for collection " << collectionNamespace << " to roll back.";
+ LOGV2_WARNING(21154,
+ "Cannot find drop-pending namespace at OpTime {opTime} for collection "
+ "{collectionNamespace} to roll back.",
+ "opTime"_attr = opTime,
+ "collectionNamespace"_attr = collectionNamespace);
return false;
}
_dropPendingNamespaces.erase(it);
}
- log() << "Rolling back collection drop for " << pendingNss << " with drop OpTime " << opTime
- << " to namespace " << collectionNamespace;
+ LOGV2(21152,
+ "Rolling back collection drop for {pendingNss} with drop OpTime {opTime} to namespace "
+ "{collectionNamespace}",
+ "pendingNss"_attr = pendingNss,
+ "opTime"_attr = opTime,
+ "collectionNamespace"_attr = collectionNamespace);
return true;
}
@@ -174,8 +185,12 @@ void DropPendingCollectionReaper::dropCollectionsOlderThan(OperationContext* opC
for (const auto& opTimeAndNamespace : toDrop) {
const auto& dropOpTime = opTimeAndNamespace.first;
const auto& nss = opTimeAndNamespace.second;
- log() << "Completing collection drop for " << nss << " with drop optime " << dropOpTime
- << " (notification optime: " << opTime << ")";
+ LOGV2(21153,
+ "Completing collection drop for {nss} with drop optime {dropOpTime} "
+ "(notification optime: {opTime})",
+ "nss"_attr = nss,
+ "dropOpTime"_attr = dropOpTime,
+ "opTime"_attr = opTime);
Status status = Status::OK();
try {
// dropCollection could throw an interrupt exception, since it acquires db locks.
@@ -184,9 +199,13 @@ void DropPendingCollectionReaper::dropCollectionsOlderThan(OperationContext* opC
status = exceptionToStatus();
}
if (!status.isOK()) {
- warning() << "Failed to remove drop-pending collection " << nss
- << " with drop optime " << dropOpTime
- << " (notification optime: " << opTime << "): " << status;
+ LOGV2_WARNING(21155,
+ "Failed to remove drop-pending collection {nss} with drop optime "
+ "{dropOpTime} (notification optime: {opTime}): {status}",
+ "nss"_attr = nss,
+ "dropOpTime"_attr = dropOpTime,
+ "opTime"_attr = opTime,
+ "status"_attr = status);
}
}
}
diff --git a/src/mongo/db/repl/idempotency_test.cpp b/src/mongo/db/repl/idempotency_test.cpp
index 4eacc99fb52..89b3a37de5b 100644
--- a/src/mongo/db/repl/idempotency_test.cpp
+++ b/src/mongo/db/repl/idempotency_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/db/catalog/index_catalog.h"
@@ -40,7 +42,9 @@
#include "mongo/db/repl/idempotency_update_sequence.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace repl {
@@ -114,7 +118,10 @@ std::vector<OplogEntry> RandomizedIdempotencyTest::createUpdateSequence(
std::string RandomizedIdempotencyTest::getStatesString(const std::vector<CollectionState>& state1,
const std::vector<CollectionState>& state2,
const std::vector<OplogEntry>& ops) {
- unittest::log() << IdempotencyTest::getStatesString(state1, state2, ops);
+ LOGV2(21157,
+ "{IdempotencyTest_getStatesString_state1_state2_ops}",
+ "IdempotencyTest_getStatesString_state1_state2_ops"_attr =
+ IdempotencyTest::getStatesString(state1, state2, ops));
StringBuilder sb;
sb << "Ran update ops: ";
sb << "[ ";
diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp
index 13f2f099ded..2d33f06f66e 100644
--- a/src/mongo/db/repl/initial_syncer.cpp
+++ b/src/mongo/db/repl/initial_syncer.cpp
@@ -63,6 +63,7 @@
#include "mongo/db/session_txn_record_gen.h"
#include "mongo/executor/task_executor.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/destructor_guard.h"
@@ -174,13 +175,13 @@ void pauseAtInitialSyncFuzzerSyncronizationPoints(std::string msg) {
// Set and unset by the InitialSyncTest fixture to cause initial sync to pause so that the
// Initial Sync Fuzzer can run commands on the sync source.
if (MONGO_unlikely(initialSyncFuzzerSynchronizationPoint1.shouldFail())) {
- log() << msg;
- log() << "initialSyncFuzzerSynchronizationPoint1 fail point enabled.";
+ LOGV2(21158, "{msg}", "msg"_attr = msg);
+ LOGV2(21159, "initialSyncFuzzerSynchronizationPoint1 fail point enabled.");
initialSyncFuzzerSynchronizationPoint1.pauseWhileSet();
}
if (MONGO_unlikely(initialSyncFuzzerSynchronizationPoint2.shouldFail())) {
- log() << "initialSyncFuzzerSynchronizationPoint2 fail point enabled.";
+ LOGV2(21160, "initialSyncFuzzerSynchronizationPoint2 fail point enabled.");
initialSyncFuzzerSynchronizationPoint2.pauseWhileSet();
}
}
@@ -446,7 +447,7 @@ BSONObj InitialSyncer::_getInitialSyncProgress_inlock() const {
}
return bob.obj();
} catch (const DBException& e) {
- log() << "Error creating initial sync progress object: " << e.toString();
+ LOGV2(21161, "Error creating initial sync progress object: {e}", "e"_attr = e.toString());
}
BSONObjBuilder bob;
_appendInitialSyncProgressMinimal_inlock(&bob);
@@ -495,7 +496,7 @@ void InitialSyncer::_setUp_inlock(OperationContext* opCtx, std::uint32_t initial
_storage->setInitialDataTimestamp(serviceCtx, Timestamp::kAllowUnstableCheckpointsSentinel);
_storage->setStableTimestamp(serviceCtx, Timestamp::min());
- LOG(1) << "Creating oplogBuffer.";
+ LOGV2_DEBUG(21162, 1, "Creating oplogBuffer.");
_oplogBuffer = _dataReplicatorExternalState->makeInitialSyncOplogBuffer(opCtx);
_oplogBuffer->startup(opCtx);
@@ -542,8 +543,11 @@ void InitialSyncer::_tearDown_inlock(OperationContext* opCtx,
invariant(currentLastAppliedOpTime == lastAppliedOpTime);
}
- log() << "initial sync done; took "
- << duration_cast<Seconds>(_stats.initialSyncEnd - _stats.initialSyncStart) << ".";
+ LOGV2(21163,
+ "initial sync done; took "
+ "{duration_cast_Seconds_stats_initialSyncEnd_stats_initialSyncStart}.",
+ "duration_cast_Seconds_stats_initialSyncEnd_stats_initialSyncStart"_attr =
+ duration_cast<Seconds>(_stats.initialSyncEnd - _stats.initialSyncStart));
initialSyncCompletes.increment();
}
@@ -560,8 +564,10 @@ void InitialSyncer::_startInitialSyncAttemptCallback(
return;
}
- log() << "Starting initial sync (attempt " << (initialSyncAttempt + 1) << " of "
- << initialSyncMaxAttempts << ")";
+ LOGV2(21164,
+ "Starting initial sync (attempt {initialSyncAttempt_1} of {initialSyncMaxAttempts})",
+ "initialSyncAttempt_1"_attr = (initialSyncAttempt + 1),
+ "initialSyncMaxAttempts"_attr = initialSyncMaxAttempts);
// This completion guard invokes _finishInitialSyncAttempt on destruction.
auto cancelRemainingWorkInLock = [this]() { _cancelRemainingWork_inlock(); };
@@ -577,15 +583,18 @@ void InitialSyncer::_startInitialSyncAttemptCallback(
_oplogApplier = {};
- LOG(2) << "Resetting sync source so a new one can be chosen for this initial sync attempt.";
+ LOGV2_DEBUG(21165,
+ 2,
+ "Resetting sync source so a new one can be chosen for this initial sync attempt.");
_syncSource = HostAndPort();
- LOG(2) << "Resetting all optimes before starting this initial sync attempt.";
+ LOGV2_DEBUG(21166, 2, "Resetting all optimes before starting this initial sync attempt.");
_opts.resetOptimes();
_lastApplied = {OpTime(), Date_t()};
_lastFetched = {};
- LOG(2) << "Resetting the oldest timestamp before starting this initial sync attempt.";
+ LOGV2_DEBUG(
+ 21167, 2, "Resetting the oldest timestamp before starting this initial sync attempt.");
auto storageEngine = getGlobalServiceContext()->getStorageEngine();
if (storageEngine) {
// Set the oldestTimestamp to one because WiredTiger does not allow us to set it to zero
@@ -595,9 +604,11 @@ void InitialSyncer::_startInitialSyncAttemptCallback(
storageEngine->setOldestTimestamp(kTimestampOne);
}
- LOG(2) << "Resetting feature compatibility version to last-stable. If the sync source is in "
- "latest feature compatibility version, we will find out when we clone the "
- "server configuration collection (admin.system.version).";
+ LOGV2_DEBUG(21168,
+ 2,
+ "Resetting feature compatibility version to last-stable. If the sync source is in "
+ "latest feature compatibility version, we will find out when we clone the "
+ "server configuration collection (admin.system.version).");
serverGlobalParams.featureCompatibility.reset();
// Clear the oplog buffer.
@@ -656,9 +667,17 @@ void InitialSyncer::_chooseSyncSourceCallback(
}
auto when = _exec->now() + _opts.syncSourceRetryWait;
- LOG(1) << "Error getting sync source: '" << syncSource.getStatus() << "', trying again in "
- << _opts.syncSourceRetryWait << " at " << when.toString() << ". Attempt "
- << (chooseSyncSourceAttempt + 1) << " of " << numInitialSyncConnectAttempts.load();
+ LOGV2_DEBUG(21169,
+ 1,
+ "Error getting sync source: '{syncSource_getStatus}', trying again in "
+ "{opts_syncSourceRetryWait} at {when}. Attempt {chooseSyncSourceAttempt_1} of "
+ "{numInitialSyncConnectAttempts_load}",
+ "syncSource_getStatus"_attr = syncSource.getStatus(),
+ "opts_syncSourceRetryWait"_attr = _opts.syncSourceRetryWait,
+ "when"_attr = when.toString(),
+ "chooseSyncSourceAttempt_1"_attr = (chooseSyncSourceAttempt + 1),
+ "numInitialSyncConnectAttempts_load"_attr =
+ numInitialSyncConnectAttempts.load());
auto status = _scheduleWorkAtAndSaveHandle_inlock(
when,
[=](const executor::TaskExecutor::CallbackArgs& args) {
@@ -678,8 +697,9 @@ void InitialSyncer::_chooseSyncSourceCallback(
if (MONGO_unlikely(initialSyncHangBeforeCreatingOplog.shouldFail())) {
// This log output is used in js tests so please leave it.
- log() << "initial sync - initialSyncHangBeforeCreatingOplog fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21170,
+ "initial sync - initialSyncHangBeforeCreatingOplog fail point "
+ "enabled. Blocking until fail point is disabled.");
lock.unlock();
while (MONGO_unlikely(initialSyncHangBeforeCreatingOplog.shouldFail()) &&
!_isShuttingDown()) {
@@ -714,8 +734,11 @@ void InitialSyncer::_chooseSyncSourceCallback(
Status InitialSyncer::_truncateOplogAndDropReplicatedDatabases() {
// truncate oplog; drop user databases.
- LOG(1) << "About to truncate the oplog, if it exists, ns:" << _opts.localOplogNS
- << ", and drop all user databases (so that we can clone them).";
+ LOGV2_DEBUG(21171,
+ 1,
+ "About to truncate the oplog, if it exists, ns:{opts_localOplogNS}, and drop all "
+ "user databases (so that we can clone them).",
+ "opts_localOplogNS"_attr = _opts.localOplogNS);
auto opCtx = makeOpCtx();
@@ -723,13 +746,21 @@ Status InitialSyncer::_truncateOplogAndDropReplicatedDatabases() {
UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx.get());
// 1.) Truncate the oplog.
- LOG(2) << "Truncating the existing oplog: " << _opts.localOplogNS;
+ LOGV2_DEBUG(21172,
+ 2,
+ "Truncating the existing oplog: {opts_localOplogNS}",
+ "opts_localOplogNS"_attr = _opts.localOplogNS);
Timer timer;
auto status = _storage->truncateCollection(opCtx.get(), _opts.localOplogNS);
- log() << "Initial syncer oplog truncation finished in: " << timer.millis() << "ms";
+ LOGV2(21173,
+ "Initial syncer oplog truncation finished in: {timer_millis}ms",
+ "timer_millis"_attr = timer.millis());
if (!status.isOK()) {
// 1a.) Create the oplog.
- LOG(2) << "Creating the oplog: " << _opts.localOplogNS;
+ LOGV2_DEBUG(21174,
+ 2,
+ "Creating the oplog: {opts_localOplogNS}",
+ "opts_localOplogNS"_attr = _opts.localOplogNS);
status = _storage->createOplog(opCtx.get(), _opts.localOplogNS);
if (!status.isOK()) {
return status;
@@ -737,7 +768,7 @@ Status InitialSyncer::_truncateOplogAndDropReplicatedDatabases() {
}
// 2.) Drop user databases.
- LOG(2) << "Dropping user databases";
+ LOGV2_DEBUG(21175, 2, "Dropping user databases");
return _storage->dropReplicatedDatabases(opCtx.get());
}
@@ -895,7 +926,7 @@ void InitialSyncer::_getBeginFetchingOpTimeCallback(
pauseAtInitialSyncFuzzerSyncronizationPoints(logMsg);
if (MONGO_unlikely(initialSyncHangAfterGettingBeginFetchingTimestamp.shouldFail())) {
- log() << "initialSyncHangAfterGettingBeginFetchingTimestamp fail point enabled.";
+ LOGV2(21176, "initialSyncHangAfterGettingBeginFetchingTimestamp fail point enabled.");
initialSyncHangAfterGettingBeginFetchingTimestamp.pauseWhileSet();
}
@@ -1064,10 +1095,16 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
<< _initialSyncState->beginFetchingTimestamp.toBSON());
invariant(!result.getValue().documents.empty());
- LOG(2) << "Setting begin applying timestamp to " << _initialSyncState->beginApplyingTimestamp
- << " using last oplog entry: " << redact(result.getValue().documents.front())
- << ", ns: " << _opts.localOplogNS << " and the begin fetching timestamp to "
- << _initialSyncState->beginFetchingTimestamp;
+ LOGV2_DEBUG(
+ 21177,
+ 2,
+ "Setting begin applying timestamp to {initialSyncState_beginApplyingTimestamp} using last "
+ "oplog entry: {result_getValue_documents_front}, ns: {opts_localOplogNS} and the begin "
+ "fetching timestamp to {initialSyncState_beginFetchingTimestamp}",
+ "initialSyncState_beginApplyingTimestamp"_attr = _initialSyncState->beginApplyingTimestamp,
+ "result_getValue_documents_front"_attr = redact(result.getValue().documents.front()),
+ "opts_localOplogNS"_attr = _opts.localOplogNS,
+ "initialSyncState_beginFetchingTimestamp"_attr = _initialSyncState->beginFetchingTimestamp);
const auto configResult = _dataReplicatorExternalState->getCurrentConfig();
status = configResult.getStatus();
@@ -1098,7 +1135,10 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
initialSyncOplogFetcherBatchSize,
OplogFetcher::StartingPoint::kEnqueueFirstDoc);
- LOG(2) << "Starting OplogFetcher: " << _oplogFetcher->toString();
+ LOGV2_DEBUG(21178,
+ 2,
+ "Starting OplogFetcher: {oplogFetcher}",
+ "oplogFetcher"_attr = _oplogFetcher->toString());
// _startupComponent_inlock is shutdown-aware.
status = _startupComponent_inlock(_oplogFetcher);
@@ -1113,8 +1153,9 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
// This could have been done with a scheduleWorkAt but this is used only by JS tests where
// we run with multiple threads so it's fine to spin on this thread.
// This log output is used in js tests so please leave it.
- log() << "initial sync - initialSyncHangBeforeCopyingDatabases fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21179,
+ "initial sync - initialSyncHangBeforeCopyingDatabases fail point "
+ "enabled. Blocking until fail point is disabled.");
while (MONGO_unlikely(initialSyncHangBeforeCopyingDatabases.shouldFail()) &&
!_isShuttingDown()) {
mongo::sleepsecs(1);
@@ -1122,7 +1163,11 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
lock.lock();
}
- LOG(2) << "Starting AllDatabaseCloner: " << _initialSyncState->allDatabaseCloner->toString();
+ LOGV2_DEBUG(21180,
+ 2,
+ "Starting AllDatabaseCloner: {initialSyncState_allDatabaseCloner}",
+ "initialSyncState_allDatabaseCloner"_attr =
+ _initialSyncState->allDatabaseCloner->toString());
auto [startClonerFuture, startCloner] =
_initialSyncState->allDatabaseCloner->runOnExecutorEvent(_clonerExec);
@@ -1166,8 +1211,11 @@ void InitialSyncer::_fcvFetcherCallback(const StatusWith<Fetcher::QueryResponse>
void InitialSyncer::_oplogFetcherCallback(const Status& oplogFetcherFinishStatus,
std::shared_ptr<OnCompletionGuard> onCompletionGuard) {
stdx::lock_guard<Latch> lock(_mutex);
- log() << "Finished fetching oplog during initial sync: " << redact(oplogFetcherFinishStatus)
- << ". Last fetched optime: " << _lastFetched.toString();
+ LOGV2(21181,
+ "Finished fetching oplog during initial sync: {oplogFetcherFinishStatus}. Last fetched "
+ "optime: {lastFetched}",
+ "oplogFetcherFinishStatus"_attr = redact(oplogFetcherFinishStatus),
+ "lastFetched"_attr = _lastFetched.toString());
auto status = _checkForShutdownAndConvertStatus_inlock(
oplogFetcherFinishStatus, "error fetching oplog during initial sync");
@@ -1182,8 +1230,9 @@ void InitialSyncer::_oplogFetcherCallback(const Status& oplogFetcherFinishStatus
// an OK status is when the 'stopReplProducer' fail point is enabled, which causes the
// OplogFetcher to ignore the current sync source response and return early.
if (status.isOK()) {
- log() << "Finished fetching oplog fetching early. Last fetched optime: "
- << _lastFetched.toString();
+ LOGV2(21182,
+ "Finished fetching oplog fetching early. Last fetched optime: {lastFetched}",
+ "lastFetched"_attr = _lastFetched.toString());
return;
}
@@ -1199,16 +1248,18 @@ void InitialSyncer::_oplogFetcherCallback(const Status& oplogFetcherFinishStatus
void InitialSyncer::_allDatabaseClonerCallback(
const Status& databaseClonerFinishStatus,
std::shared_ptr<OnCompletionGuard> onCompletionGuard) {
- log() << "Finished cloning data: " << redact(databaseClonerFinishStatus)
- << ". Beginning oplog replay.";
+ LOGV2(21183,
+ "Finished cloning data: {databaseClonerFinishStatus}. Beginning oplog replay.",
+ "databaseClonerFinishStatus"_attr = redact(databaseClonerFinishStatus));
_client->shutdownAndDisallowReconnect();
if (MONGO_unlikely(initialSyncHangAfterDataCloning.shouldFail())) {
// This could have been done with a scheduleWorkAt but this is used only by JS tests where
// we run with multiple threads so it's fine to spin on this thread.
// This log output is used in js tests so please leave it.
- log() << "initial sync - initialSyncHangAfterDataCloning fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21184,
+ "initial sync - initialSyncHangAfterDataCloning fail point "
+ "enabled. Blocking until fail point is disabled.");
while (MONGO_unlikely(initialSyncHangAfterDataCloning.shouldFail()) && !_isShuttingDown()) {
mongo::sleepsecs(1);
}
@@ -1309,7 +1360,10 @@ void InitialSyncer::_lastOplogEntryFetcherCallbackForStopTimestamp(
const auto& documents = result.getValue().documents;
invariant(!documents.empty());
const BSONObj oplogSeedDoc = documents.front();
- LOG(2) << "Inserting oplog seed document: " << oplogSeedDoc;
+ LOGV2_DEBUG(21185,
+ 2,
+ "Inserting oplog seed document: {oplogSeedDoc}",
+ "oplogSeedDoc"_attr = oplogSeedDoc);
auto opCtx = makeOpCtx();
// StorageInterface::insertDocument() has to be called outside the lock because we may
@@ -1333,8 +1387,9 @@ void InitialSyncer::_lastOplogEntryFetcherCallbackForStopTimestamp(
stdx::lock_guard<Latch> lock(_mutex);
_lastApplied = resultOpTimeAndWallTime;
- log() << "No need to apply operations. (currently at "
- << _initialSyncState->stopTimestamp.toBSON() << ")";
+ LOGV2(21186,
+ "No need to apply operations. (currently at {initialSyncState_stopTimestamp})",
+ "initialSyncState_stopTimestamp"_attr = _initialSyncState->stopTimestamp.toBSON());
// This sets the error in 'onCompletionGuard' and shuts down the OplogFetcher on error.
_scheduleRollbackCheckerCheckForRollback_inlock(lock, onCompletionGuard);
@@ -1353,7 +1408,9 @@ void InitialSyncer::_getNextApplierBatchCallback(
auto batchResult = _getNextApplierBatch_inlock();
if (!batchResult.isOK()) {
- warning() << "Failure creating next apply batch: " << redact(batchResult.getStatus());
+ LOGV2_WARNING(21196,
+ "Failure creating next apply batch: {batchResult_getStatus}",
+ "batchResult_getStatus"_attr = redact(batchResult.getStatus()));
onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, batchResult.getStatus());
return;
}
@@ -1364,8 +1421,9 @@ void InitialSyncer::_getNextApplierBatchCallback(
pauseAtInitialSyncFuzzerSyncronizationPoints(logMsg);
if (MONGO_unlikely(failInitialSyncBeforeApplyingBatch.shouldFail())) {
- log() << "initial sync - failInitialSyncBeforeApplyingBatch fail point enabled. Pausing"
- << "until fail point is disabled, then will fail initial sync.";
+ LOGV2(21187,
+ "initial sync - failInitialSyncBeforeApplyingBatch fail point enabled. Pausinguntil "
+ "fail point is disabled, then will fail initial sync.");
failInitialSyncBeforeApplyingBatch.pauseWhileSet();
status = Status(ErrorCodes::CallbackCanceled,
"failInitialSyncBeforeApplyingBatch fail point enabled");
@@ -1409,7 +1467,7 @@ void InitialSyncer::_getNextApplierBatchCallback(
"in the oplog buffer. Aborting this initial sync attempt. Last applied: "
<< _lastApplied.opTime.toString() << ". Last fetched: " << _lastFetched.toString()
<< ". Number of operations applied: " << _initialSyncState->appliedOps;
- log() << msg;
+ LOGV2(21188, "{msg}", "msg"_attr = msg);
status = Status(ErrorCodes::RemoteResultsUnavailable, msg);
onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, status);
return;
@@ -1441,12 +1499,13 @@ void InitialSyncer::_multiApplierCallback(const Status& multiApplierStatus,
// Set to cause initial sync to fassert instead of restart if applying a batch fails, so that
// tests can be robust to network errors but not oplog idempotency errors.
if (MONGO_unlikely(initialSyncFassertIfApplyingBatchFails.shouldFail())) {
- log() << "initialSyncFassertIfApplyingBatchFails fail point enabled.";
+ LOGV2(21189, "initialSyncFassertIfApplyingBatchFails fail point enabled.");
fassert(31210, status);
}
if (!status.isOK()) {
- error() << "Failed to apply batch due to '" << redact(status) << "'";
+ LOGV2_ERROR(
+ 21199, "Failed to apply batch due to '{status}'", "status"_attr = redact(status));
onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, status);
return;
}
@@ -1475,7 +1534,10 @@ void InitialSyncer::_rollbackCheckerCheckForRollbackCallback(
auto status = _checkForShutdownAndConvertStatus_inlock(result.getStatus(),
"error while getting last rollback ID");
if (_shouldRetryError(lock, status)) {
- LOG(1) << "Retrying rollback checker because of network error " << status;
+ LOGV2_DEBUG(21190,
+ 1,
+ "Retrying rollback checker because of network error {status}",
+ "status"_attr = status);
_scheduleRollbackCheckerCheckForRollback_inlock(lock, onCompletionGuard);
return;
}
@@ -1519,17 +1581,20 @@ void InitialSyncer::_finishInitialSyncAttempt(const StatusWith<OpTimeAndWallTime
auto scheduleResult = _exec->scheduleWork(
[=](const mongo::executor::TaskExecutor::CallbackArgs&) { _finishCallback(result); });
if (!scheduleResult.isOK()) {
- warning() << "Unable to schedule initial syncer completion task due to "
- << redact(scheduleResult.getStatus())
- << ". Running callback on current thread.";
+ LOGV2_WARNING(21197,
+ "Unable to schedule initial syncer completion task due to "
+ "{scheduleResult_getStatus}. Running callback on current thread.",
+ "scheduleResult_getStatus"_attr = redact(scheduleResult.getStatus()));
_finishCallback(result);
}
});
- log() << "Initial sync attempt finishing up.";
+ LOGV2(21191, "Initial sync attempt finishing up.");
stdx::lock_guard<Latch> lock(_mutex);
- log() << "Initial Sync Attempt Statistics: " << redact(_getInitialSyncProgress_inlock());
+ LOGV2(21192,
+ "Initial Sync Attempt Statistics: {getInitialSyncProgress_inlock}",
+ "getInitialSyncProgress_inlock"_attr = redact(_getInitialSyncProgress_inlock()));
auto runTime = _initialSyncState ? _initialSyncState->timer.millis() : 0;
int rollBackId = -1;
@@ -1552,7 +1617,7 @@ void InitialSyncer::_finishInitialSyncAttempt(const StatusWith<OpTimeAndWallTime
totalTimeUnreachableMillis});
if (MONGO_unlikely(failAndHangInitialSync.shouldFail())) {
- log() << "failAndHangInitialSync fail point enabled.";
+ LOGV2(21193, "failAndHangInitialSync fail point enabled.");
failAndHangInitialSync.pauseWhileSet();
result = Status(ErrorCodes::InternalError, "failAndHangInitialSync fail point enabled");
}
@@ -1570,15 +1635,19 @@ void InitialSyncer::_finishInitialSyncAttempt(const StatusWith<OpTimeAndWallTime
// startup.
initialSyncFailedAttempts.increment();
- error() << "Initial sync attempt failed -- attempts left: "
- << (_stats.maxFailedInitialSyncAttempts - _stats.failedInitialSyncAttempts)
- << " cause: " << redact(result.getStatus());
+ LOGV2_ERROR(21200,
+ "Initial sync attempt failed -- attempts left: "
+ "{stats_maxFailedInitialSyncAttempts_stats_failedInitialSyncAttempts} cause: "
+ "{result_getStatus}",
+ "stats_maxFailedInitialSyncAttempts_stats_failedInitialSyncAttempts"_attr =
+ (_stats.maxFailedInitialSyncAttempts - _stats.failedInitialSyncAttempts),
+ "result_getStatus"_attr = redact(result.getStatus()));
// Check if need to do more retries.
if (_stats.failedInitialSyncAttempts >= _stats.maxFailedInitialSyncAttempts) {
const std::string err =
"The maximum number of retries have been exhausted for initial sync.";
- severe() << err;
+ LOGV2_FATAL(21202, "{err}", "err"_attr = err);
initialSyncFailures.increment();
@@ -1626,8 +1695,9 @@ void InitialSyncer::_finishCallback(StatusWith<OpTimeAndWallTime> lastApplied) {
if (MONGO_unlikely(initialSyncHangBeforeFinish.shouldFail())) {
// This log output is used in js tests so please leave it.
- log() << "initial sync - initialSyncHangBeforeFinish fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21194,
+ "initial sync - initialSyncHangBeforeFinish fail point "
+ "enabled. Blocking until fail point is disabled.");
while (MONGO_unlikely(initialSyncHangBeforeFinish.shouldFail()) && !_isShuttingDown()) {
mongo::sleepsecs(1);
}
@@ -1637,8 +1707,9 @@ void InitialSyncer::_finishCallback(StatusWith<OpTimeAndWallTime> lastApplied) {
try {
onCompletion(lastApplied);
} catch (...) {
- warning() << "initial syncer finish callback threw exception: "
- << redact(exceptionToStatus());
+ LOGV2_WARNING(21198,
+ "initial syncer finish callback threw exception: {exceptionToStatus}",
+ "exceptionToStatus"_attr = redact(exceptionToStatus()));
}
// Destroy the remaining reference to the completion callback before we transition the state to
@@ -1704,7 +1775,7 @@ void InitialSyncer::_checkApplierProgressAndScheduleGetNextApplierBatch_inlock(
<< "Possible rollback on sync source " << _syncSource.toString() << ". Currently at "
<< _initialSyncState->stopTimestamp.toBSON() << ". Started at "
<< _initialSyncState->beginApplyingTimestamp.toBSON();
- error() << msg;
+ LOGV2_ERROR(21201, "{msg}", "msg"_attr = msg);
onCompletionGuard->setResultAndCancelRemainingWork_inlock(
lock, Status(ErrorCodes::OplogOutOfOrder, msg));
return;
@@ -1713,11 +1784,16 @@ void InitialSyncer::_checkApplierProgressAndScheduleGetNextApplierBatch_inlock(
if (_lastApplied.opTime.isNull()) {
// Check if any ops occurred while cloning or any ops need to be fetched.
invariant(_initialSyncState->beginFetchingTimestamp < _initialSyncState->stopTimestamp);
- log() << "Writing to the oplog and applying operations until "
- << _initialSyncState->stopTimestamp.toBSON()
- << " before initial sync can complete. (started fetching at "
- << _initialSyncState->beginFetchingTimestamp.toBSON() << " and applying at "
- << _initialSyncState->beginApplyingTimestamp.toBSON() << ")";
+ LOGV2(21195,
+ "Writing to the oplog and applying operations until {initialSyncState_stopTimestamp} "
+ "before initial sync can complete. (started fetching at "
+ "{initialSyncState_beginFetchingTimestamp} and applying at "
+ "{initialSyncState_beginApplyingTimestamp})",
+ "initialSyncState_stopTimestamp"_attr = _initialSyncState->stopTimestamp.toBSON(),
+ "initialSyncState_beginFetchingTimestamp"_attr =
+ _initialSyncState->beginFetchingTimestamp.toBSON(),
+ "initialSyncState_beginApplyingTimestamp"_attr =
+ _initialSyncState->beginApplyingTimestamp.toBSON());
// Fall through to scheduling _getNextApplierBatchCallback().
} else if (_lastApplied.opTime.getTimestamp() >= _initialSyncState->stopTimestamp) {
// Check for rollback if we have applied far enough to be consistent.
diff --git a/src/mongo/db/repl/insert_group.cpp b/src/mongo/db/repl/insert_group.cpp
index 24acf95b0d2..931ca0d3367 100644
--- a/src/mongo/db/repl/insert_group.cpp
+++ b/src/mongo/db/repl/insert_group.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/ops/write_ops.h"
#include "mongo/db/repl/oplog_applier_impl.h"
#include "mongo/db/repl/oplog_entry.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -139,9 +140,9 @@ StatusWith<InsertGroup::ConstIterator> InsertGroup::groupAndApplyInserts(ConstIt
// It's not an error during initial sync to encounter DuplicateKey errors.
if (Mode::kInitialSync == _mode && ErrorCodes::DuplicateKey == status) {
- LOG(2) << status;
+ LOGV2_DEBUG(21203, 2, "{status}", "status"_attr = status);
} else {
- error() << status;
+ LOGV2_ERROR(21204, "{status}", "status"_attr = status);
}
// Avoid quadratic run time from failed insert by not retrying until we
diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp
index b50a893efb8..b4af71d7fdb 100644
--- a/src/mongo/db/repl/isself.cpp
+++ b/src/mongo/db/repl/isself.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/auth/privilege.h"
#include "mongo/db/commands.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/net/socket_utils.h"
#include "mongo/util/scopeguard.h"
@@ -119,8 +120,10 @@ std::vector<std::string> getAddrsForHost(const std::string& iporhost,
int err = getaddrinfo(iporhost.c_str(), portNum.c_str(), &hints, &addrs);
if (err) {
- warning() << "getaddrinfo(\"" << iporhost << "\") failed: " << stringifyError(err)
- << std::endl;
+ LOGV2_WARNING(21207,
+ "getaddrinfo(\"{iporhost}\") failed: {stringifyError_err}",
+ "iporhost"_attr = iporhost,
+ "stringifyError_err"_attr = stringifyError(err));
return out;
}
@@ -134,7 +137,9 @@ std::vector<std::string> getAddrsForHost(const std::string& iporhost,
err = getnameinfo(
addr->ai_addr, addr->ai_addrlen, host, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST);
if (err) {
- warning() << "getnameinfo() failed: " << stringifyError(err) << std::endl;
+ LOGV2_WARNING(21208,
+ "getnameinfo() failed: {stringifyError_err}",
+ "stringifyError_err"_attr = stringifyError(err));
continue;
}
out.push_back(host);
@@ -147,7 +152,7 @@ std::vector<std::string> getAddrsForHost(const std::string& iporhost,
for (std::vector<std::string>::const_iterator o = out.begin(); o != out.end(); ++o) {
builder << " [ " << *o << "]";
}
- LOG(2) << builder.str();
+ LOGV2_DEBUG(21205, 2, "{builder_str}", "builder_str"_attr = builder.str());
}
return out;
@@ -210,7 +215,10 @@ bool isSelf(const HostAndPort& hostAndPort, ServiceContext* const ctx) {
return me;
} catch (const std::exception& e) {
- warning() << "couldn't check isSelf (" << hostAndPort << ") " << e.what() << std::endl;
+ LOGV2_WARNING(21209,
+ "couldn't check isSelf ({hostAndPort}) {e_what}",
+ "hostAndPort"_attr = hostAndPort,
+ "e_what"_attr = e.what());
}
return false;
@@ -229,7 +237,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) {
int err = getifaddrs(&addrs);
if (err) {
- warning() << "getifaddrs failure: " << errnoWithDescription(err) << std::endl;
+ LOGV2_WARNING(21210,
+ "getifaddrs failure: {errnoWithDescription_err}",
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
return out;
}
ON_BLOCK_EXIT([&] { freeifaddrs(addrs); });
@@ -251,7 +261,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) {
0,
NI_NUMERICHOST);
if (err) {
- warning() << "getnameinfo() failed: " << gai_strerror(err) << std::endl;
+ LOGV2_WARNING(21211,
+ "getnameinfo() failed: {gai_strerror_err}",
+ "gai_strerror_err"_attr = gai_strerror(err));
continue;
}
out.push_back(host);
@@ -288,7 +300,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) {
}
if (err != NO_ERROR) {
- warning() << "GetAdaptersAddresses() failed: " << errnoWithDescription(err) << std::endl;
+ LOGV2_WARNING(21212,
+ "GetAdaptersAddresses() failed: {errnoWithDescription_err}",
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
return out;
}
@@ -306,8 +320,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) {
boost::asio::detail::socket_ops::inet_ntop(
AF_INET, &(sock->sin_addr), addrstr, INET_ADDRSTRLEN, 0, ec);
if (ec) {
- warning() << "inet_ntop failed during IPv4 address conversion: " << ec.message()
- << std::endl;
+ LOGV2_WARNING(21213,
+ "inet_ntop failed during IPv4 address conversion: {ec_message}",
+ "ec_message"_attr = ec.message());
continue;
}
out.push_back(addrstr);
@@ -319,8 +334,9 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) {
boost::asio::detail::socket_ops::inet_ntop(
AF_INET6, &(sock->sin6_addr), addrstr, INET6_ADDRSTRLEN, 0, ec);
if (ec) {
- warning() << "inet_ntop failed during IPv6 address conversion: " << ec.message()
- << std::endl;
+ LOGV2_WARNING(21214,
+ "inet_ntop failed during IPv6 address conversion: {ec_message}",
+ "ec_message"_attr = ec.message());
continue;
}
out.push_back(addrstr);
@@ -336,7 +352,7 @@ std::vector<std::string> getBoundAddrs(const bool ipv6enabled) {
for (std::vector<std::string>::const_iterator o = out.begin(); o != out.end(); ++o) {
builder << " [ " << *o << "]";
}
- LOG(2) << builder.str();
+ LOGV2_DEBUG(21206, 2, "{builder_str}", "builder_str"_attr = builder.str());
}
return out;
}
diff --git a/src/mongo/db/repl/member_data.cpp b/src/mongo/db/repl/member_data.cpp
index 571e83d3a1c..56cc13619e3 100644
--- a/src/mongo/db/repl/member_data.cpp
+++ b/src/mongo/db/repl/member_data.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/repl/member_data.h"
#include "mongo/db/repl/rslog.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -69,8 +70,11 @@ bool MemberData::setUpValues(Date_t now, ReplSetHeartbeatResponse&& hbResponse)
}
// Log if the state changes
if (_lastResponse.getState() != hbResponse.getState()) {
- log() << "Member " << _hostAndPort.toString() << " is now in state "
- << hbResponse.getState().toString() << rsLog;
+ LOGV2_OPTIONS(21215,
+ {logv2::LogTag::kRS},
+ "Member {hostAndPort} is now in state {hbResponse_getState}",
+ "hostAndPort"_attr = _hostAndPort.toString(),
+ "hbResponse_getState"_attr = hbResponse.getState().toString());
}
bool opTimeAdvanced =
@@ -93,8 +97,11 @@ void MemberData::setDownValues(Date_t now, const std::string& heartbeatMessage)
_lastHeartbeatMessage = heartbeatMessage;
if (_lastResponse.getState() != MemberState::RS_DOWN) {
- log() << "Member " << _hostAndPort.toString() << " is now in state RS_DOWN - "
- << redact(heartbeatMessage) << rsLog;
+ LOGV2_OPTIONS(21216,
+ {logv2::LogTag::kRS},
+ "Member {hostAndPort} is now in state RS_DOWN - {heartbeatMessage}",
+ "hostAndPort"_attr = _hostAndPort.toString(),
+ "heartbeatMessage"_attr = redact(heartbeatMessage));
}
_lastResponse = ReplSetHeartbeatResponse();
@@ -116,8 +123,11 @@ void MemberData::setAuthIssue(Date_t now) {
_lastHeartbeatMessage.clear();
if (_lastResponse.getState() != MemberState::RS_UNKNOWN) {
- log() << "Member " << _hostAndPort.toString()
- << " is now in state RS_UNKNOWN due to authentication issue." << rsLog;
+ LOGV2_OPTIONS(
+ 21217,
+ {logv2::LogTag::kRS},
+ "Member {hostAndPort} is now in state RS_UNKNOWN due to authentication issue.",
+ "hostAndPort"_attr = _hostAndPort.toString());
}
_lastResponse = ReplSetHeartbeatResponse();
@@ -142,12 +152,16 @@ void MemberData::setLastDurableOpTimeAndWallTime(OpTimeAndWallTime opTime, Date_
if (_lastAppliedOpTime < opTime.opTime) {
// TODO(russotto): We think this should never happen, rollback or no rollback. Make this an
// invariant and see what happens.
- log() << "Durable progress (" << opTime.opTime << ") is ahead of the applied progress ("
- << _lastAppliedOpTime
- << ". This is likely due to a "
- "rollback."
- << " memberid: " << _memberId << _hostAndPort.toString()
- << " previous durable progress: " << _lastDurableOpTime;
+ LOGV2(21218,
+ "Durable progress ({opTime_opTime}) is ahead of the applied progress "
+ "({lastAppliedOpTime}. This is likely due to a "
+ "rollback. memberid: {memberId}{hostAndPort} previous durable progress: "
+ "{lastDurableOpTime}",
+ "opTime_opTime"_attr = opTime.opTime,
+ "lastAppliedOpTime"_attr = _lastAppliedOpTime,
+ "memberId"_attr = _memberId,
+ "hostAndPort"_attr = _hostAndPort.toString(),
+ "lastDurableOpTime"_attr = _lastDurableOpTime);
} else {
_lastDurableOpTime = opTime.opTime;
_lastDurableWallTime = opTime.wallTime;
diff --git a/src/mongo/db/repl/noop_writer.cpp b/src/mongo/db/repl/noop_writer.cpp
index 29ee8017bfb..67fba097925 100644
--- a/src/mongo/db/repl/noop_writer.cpp
+++ b/src/mongo/db/repl/noop_writer.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/repl/noop_writer.h"
#include "mongo/db/repl/oplog.h"
#include "mongo/db/repl/repl_server_parameters_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/log.h"
@@ -150,14 +151,14 @@ void NoopWriter::_writeNoop(OperationContext* opCtx) {
Lock::GlobalLock lock(
opCtx, MODE_IX, Date_t::now() + Milliseconds(1), Lock::InterruptBehavior::kLeaveUnlocked);
if (!lock.isLocked()) {
- LOG(1) << "Global lock is not available skipping noopWrite";
+ LOGV2_DEBUG(21219, 1, "Global lock is not available skipping noopWrite");
return;
}
auto replCoord = ReplicationCoordinator::get(opCtx);
// Its a proxy for being a primary
if (!replCoord->canAcceptWritesForDatabase(opCtx, "admin")) {
- LOG(1) << "Not a primary, skipping the noop write";
+ LOGV2_DEBUG(21220, 1, "Not a primary, skipping the noop write");
return;
}
@@ -165,14 +166,20 @@ void NoopWriter::_writeNoop(OperationContext* opCtx) {
// _lastKnownOpTime is not protected by lock as its used only by one thread.
if (lastAppliedOpTime != _lastKnownOpTime) {
- LOG(1) << "Not scheduling a noop write. Last known OpTime: " << _lastKnownOpTime
- << " != last primary OpTime: " << lastAppliedOpTime;
+ LOGV2_DEBUG(21221,
+ 1,
+ "Not scheduling a noop write. Last known OpTime: {lastKnownOpTime} != last "
+ "primary OpTime: {lastAppliedOpTime}",
+ "lastKnownOpTime"_attr = _lastKnownOpTime,
+ "lastAppliedOpTime"_attr = lastAppliedOpTime);
} else {
if (writePeriodicNoops.load()) {
const auto logLevel = getTestCommandsEnabled() ? 0 : 1;
- LOG(logLevel)
- << "Writing noop to oplog as there has been no writes to this replica set in over "
- << _writeInterval;
+ LOGV2_DEBUG(21222,
+ logSeverityV1toV2(logLevel).toInt(),
+ "Writing noop to oplog as there has been no writes to this replica set in "
+ "over {writeInterval}",
+ "writeInterval"_attr = _writeInterval);
writeConflictRetry(
opCtx, "writeNoop", NamespaceString::kRsOplogNamespace.ns(), [&opCtx] {
WriteUnitOfWork uow(opCtx);
@@ -184,7 +191,10 @@ void NoopWriter::_writeNoop(OperationContext* opCtx) {
}
_lastKnownOpTime = replCoord->getMyLastAppliedOpTime();
- LOG(1) << "Set last known op time to " << _lastKnownOpTime;
+ LOGV2_DEBUG(21223,
+ 1,
+ "Set last known op time to {lastKnownOpTime}",
+ "lastKnownOpTime"_attr = _lastKnownOpTime);
}
} // namespace repl
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 7e74528cf6d..c792ba15917 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -127,8 +127,11 @@ bool shouldBuildInForeground(OperationContext* opCtx,
const NamespaceString& indexNss,
repl::OplogApplication::Mode mode) {
if (mode == OplogApplication::Mode::kRecovering) {
- LOG(3) << "apply op: building background index " << index
- << " in the foreground because the node is in recovery";
+ LOGV2_DEBUG(21241,
+ 3,
+ "apply op: building background index {index} in the foreground because the "
+ "node is in recovery",
+ "index"_attr = index);
return true;
}
@@ -137,8 +140,11 @@ bool shouldBuildInForeground(OperationContext* opCtx,
const bool isPrimary =
repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, indexNss);
if (isPrimary) {
- LOG(3) << "apply op: not building background index " << index
- << " in a background thread because this is a primary";
+ LOGV2_DEBUG(21242,
+ 3,
+ "apply op: not building background index {index} in a background thread "
+ "because this is a primary",
+ "index"_attr = index);
return true;
}
@@ -262,7 +268,7 @@ void _logOpsInner(OperationContext* opCtx,
Status result = oplogCollection->insertDocumentsForOplog(opCtx, records, timestamps);
if (!result.isOK()) {
- severe() << "write to oplog failed: " << result.toString();
+ LOGV2_FATAL(21263, "write to oplog failed: {result}", "result"_attr = result.toString());
fassertFailed(17322);
}
@@ -279,7 +285,7 @@ void _logOpsInner(OperationContext* opCtx,
// Optionally hang before advancing lastApplied.
if (MONGO_unlikely(hangBeforeLogOpAdvancesLastApplied.shouldFail())) {
- log() << "hangBeforeLogOpAdvancesLastApplied fail point enabled.";
+ LOGV2(21243, "hangBeforeLogOpAdvancesLastApplied fail point enabled.");
hangBeforeLogOpAdvancesLastApplied.pauseWhileSet(opCtx);
}
@@ -417,8 +423,13 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
sleepBetweenInsertOpTimeGenerationAndLogOp.execute([&](const BSONObj& data) {
auto numMillis = data["waitForMillis"].numberInt();
- log() << "Sleeping for " << numMillis << "ms after receiving " << count << " optimes from "
- << opTimes.front() << " to " << opTimes.back();
+ LOGV2(21244,
+ "Sleeping for {numMillis}ms after receiving {count} optimes from {opTimes_front} to "
+ "{opTimes_back}",
+ "numMillis"_attr = numMillis,
+ "count"_attr = count,
+ "opTimes_front"_attr = opTimes.front(),
+ "opTimes_back"_attr = opTimes.back());
sleepmillis(numMillis);
});
@@ -470,7 +481,7 @@ long long getNewOplogSizeBytes(OperationContext* opCtx, const ReplSettings& repl
ProcessInfo pi;
if (pi.getAddrSize() == 32) {
const auto sz = 50LL * 1024LL * 1024LL;
- LOG(3) << "32bit system; choosing " << sz << " bytes oplog";
+ LOGV2_DEBUG(21245, 3, "32bit system; choosing {sz} bytes oplog", "sz"_attr = sz);
return sz;
}
// First choose a minimum size.
@@ -478,7 +489,7 @@ long long getNewOplogSizeBytes(OperationContext* opCtx, const ReplSettings& repl
#if defined(__APPLE__)
// typically these are desktops (dev machines), so keep it smallish
const auto sz = 192 * 1024 * 1024;
- LOG(3) << "Apple system; choosing " << sz << " bytes oplog";
+ LOGV2_DEBUG(21246, 3, "Apple system; choosing {sz} bytes oplog", "sz"_attr = sz);
return sz;
#else
long long lowerBound = 0;
@@ -487,14 +498,22 @@ long long getNewOplogSizeBytes(OperationContext* opCtx, const ReplSettings& repl
// in memory: 50MB minimum size
lowerBound = 50LL * 1024 * 1024;
bytes = pi.getMemSizeMB() * 1024 * 1024;
- LOG(3) << "Ephemeral storage system; lowerBound: " << lowerBound << " bytes, " << bytes
- << " bytes total memory";
+ LOGV2_DEBUG(
+ 21247,
+ 3,
+ "Ephemeral storage system; lowerBound: {lowerBound} bytes, {bytes} bytes total memory",
+ "lowerBound"_attr = lowerBound,
+ "bytes"_attr = bytes);
} else {
// disk: 990MB minimum size
lowerBound = 990LL * 1024 * 1024;
bytes = File::freeSpace(storageGlobalParams.dbpath); //-1 if call not supported.
- LOG(3) << "Disk storage system; lowerBound: " << lowerBound << " bytes, " << bytes
- << " bytes free space on device";
+ LOGV2_DEBUG(21248,
+ 3,
+ "Disk storage system; lowerBound: {lowerBound} bytes, {bytes} bytes free space "
+ "on device",
+ "lowerBound"_attr = lowerBound,
+ "bytes"_attr = bytes);
}
long long fivePct = static_cast<long long>(bytes * 0.05);
auto sz = std::max(fivePct, lowerBound);
@@ -531,7 +550,7 @@ void createOplog(OperationContext* opCtx,
stringstream ss;
ss << "cmdline oplogsize (" << n << ") different than existing (" << o
<< ") see: http://dochub.mongodb.org/core/increase-oplog";
- log() << ss.str() << endl;
+ LOGV2(21249, "{ss_str}", "ss_str"_attr = ss.str());
uasserted(13257, ss.str());
}
}
@@ -544,8 +563,10 @@ void createOplog(OperationContext* opCtx,
/* create an oplog collection, if it doesn't yet exist. */
const auto sz = getNewOplogSizeBytes(opCtx, replSettings);
- log() << "******" << endl;
- log() << "creating replication oplog of size: " << (int)(sz / (1024 * 1024)) << "MB..." << endl;
+ LOGV2(21250, "******");
+ LOGV2(21251,
+ "creating replication oplog of size: {int_sz_1024_1024}MB...",
+ "int_sz_1024_1024"_attr = (int)(sz / (1024 * 1024)));
CollectionOptions options;
options.capped = true;
@@ -565,7 +586,7 @@ void createOplog(OperationContext* opCtx,
/* sync here so we don't get any surprising lag later when we try to sync */
service->getStorageEngine()->flushAllFiles(opCtx, /*callerHoldsReadLock*/ false);
- log() << "******" << endl;
+ LOGV2(21252, "******");
}
void createOplog(OperationContext* opCtx) {
@@ -778,10 +799,11 @@ const StringMap<ApplyOpMetadata> kOpsMap = {
const auto& cmd = entry.getObject();
auto nss = extractNsFromUUIDorNs(opCtx, entry.getNss(), entry.getUuid(), cmd);
if (nss.isDropPendingNamespace()) {
- log()
- << "applyCommand: " << nss
- << " : collection is already in a drop-pending state: ignoring collection drop: "
- << redact(cmd);
+ LOGV2(21253,
+ "applyCommand: {nss} : collection is already in a drop-pending state: ignoring "
+ "collection drop: {cmd}",
+ "nss"_attr = nss,
+ "cmd"_attr = redact(cmd));
return Status::OK();
}
// Parse optime from oplog entry unless we are applying this command in standalone or on a
@@ -920,8 +942,12 @@ Status applyOperation_inlock(OperationContext* opCtx,
IncrementOpsAppliedStatsFn incrementOpsAppliedStats) {
// Get the single oplog entry to be applied or the first oplog entry of grouped inserts.
auto op = opOrGroupedInserts.getOp();
- LOG(3) << "applying op (or grouped inserts): " << redact(opOrGroupedInserts.toBSON())
- << ", oplog application mode: " << OplogApplication::modeToString(mode);
+ LOGV2_DEBUG(21254,
+ 3,
+ "applying op (or grouped inserts): {opOrGroupedInserts}, oplog application mode: "
+ "{OplogApplication_modeToString_mode}",
+ "opOrGroupedInserts"_attr = redact(opOrGroupedInserts.toBSON()),
+ "OplogApplication_modeToString_mode"_attr = OplogApplication::modeToString(mode));
// Choose opCounters based on running on standalone/primary or secondary by checking
// whether writes are replicated. Atomic applyOps command is an exception, which runs
@@ -1167,8 +1193,9 @@ Status applyOperation_inlock(OperationContext* opCtx,
UpdateResult res = update(opCtx, db, request);
if (res.numMatched == 0 && res.upserted.isEmpty()) {
- error() << "No document was updated even though we got a DuplicateKey "
- "error when inserting";
+ LOGV2_ERROR(21257,
+ "No document was updated even though we got a DuplicateKey "
+ "error when inserting");
fassertFailedNoTrace(28750);
}
wuow.commit();
@@ -1225,7 +1252,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
// was a simple { _id : ... } update criteria
string msg = str::stream()
<< "failed to apply update: " << redact(op.toBSON());
- error() << msg;
+ LOGV2_ERROR(21258, "{msg}", "msg"_attr = msg);
return Status(ErrorCodes::UpdateOperationFailed, msg);
}
@@ -1242,7 +1269,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
Helpers::findOne(opCtx, collection, updateCriteria, false).isNull())) {
string msg = str::stream()
<< "couldn't find doc: " << redact(op.toBSON());
- error() << msg;
+ LOGV2_ERROR(21259, "{msg}", "msg"_attr = msg);
return Status(ErrorCodes::UpdateOperationFailed, msg);
}
@@ -1255,7 +1282,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
if (!upsert) {
string msg = str::stream()
<< "update of non-mod failed: " << redact(op.toBSON());
- error() << msg;
+ LOGV2_ERROR(21260, "{msg}", "msg"_attr = msg);
return Status(ErrorCodes::UpdateOperationFailed, msg);
}
}
@@ -1324,8 +1351,12 @@ Status applyOperation_inlock(OperationContext* opCtx,
Status applyCommand_inlock(OperationContext* opCtx,
const OplogEntry& entry,
OplogApplication::Mode mode) {
- LOG(3) << "applying command op: " << redact(entry.toBSON())
- << ", oplog application mode: " << OplogApplication::modeToString(mode);
+ LOGV2_DEBUG(21255,
+ 3,
+ "applying command op: {entry}, oplog application mode: "
+ "{OplogApplication_modeToString_mode}",
+ "entry"_attr = redact(entry.toBSON()),
+ "OplogApplication_modeToString_mode"_attr = OplogApplication::modeToString(mode));
// Only commands are processed here.
invariant(entry.getOpType() == OpTypeEnum::kCommand);
@@ -1472,8 +1503,11 @@ Status applyCommand_inlock(OperationContext* opCtx,
cmd->parse(opCtx, OpMsgRequest::fromDBAndBody(nss.db(), o))->ns().toString();
auto swUUID = entry.getUuid();
if (!swUUID) {
- error() << "Failed command " << redact(o) << " on " << ns
- << "during oplog application. Expected a UUID.";
+ LOGV2_ERROR(
+ 21261,
+ "Failed command {o} on {ns}during oplog application. Expected a UUID.",
+ "o"_attr = redact(o),
+ "ns"_attr = ns);
}
BackgroundOperation::awaitNoBgOpInProgForNs(ns);
IndexBuildsCoordinator::get(opCtx)->awaitNoIndexBuildInProgressForCollection(
@@ -1492,8 +1526,12 @@ Status applyCommand_inlock(OperationContext* opCtx,
}
default: {
if (!curOpToApply.acceptableErrors.count(status.code())) {
- error() << "Failed command " << redact(o) << " on " << nss.db()
- << " with status " << status << " during oplog application";
+ LOGV2_ERROR(21262,
+ "Failed command {o} on {nss_db} with status {status} during oplog "
+ "application",
+ "o"_attr = redact(o),
+ "nss_db"_attr = nss.db(),
+ "status"_attr = status);
return status;
}
@@ -1527,7 +1565,7 @@ void initTimestampFromOplog(OperationContext* opCtx, const NamespaceString& oplo
c.findOne(oplogNss.ns(), Query().sort(reverseNaturalObj), nullptr, QueryOption_SlaveOk);
if (!lastOp.isEmpty()) {
- LOG(1) << "replSet setting last Timestamp";
+ LOGV2_DEBUG(21256, 1, "replSet setting last Timestamp");
const OpTime opTime = fassert(28696, OpTime::parseFromOplogEntry(lastOp));
setNewTimestamp(opCtx->getServiceContext(), opTime.getTimestamp());
}
diff --git a/src/mongo/db/repl/oplog_applier.cpp b/src/mongo/db/repl/oplog_applier.cpp
index f505933bbdc..294930161ec 100644
--- a/src/mongo/db/repl/oplog_applier.cpp
+++ b/src/mongo/db/repl/oplog_applier.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/repl/repl_server_parameters_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/time_support.h"
@@ -63,9 +64,9 @@ Future<void> OplogApplier::startup() {
auto callback =
[ this, promise = std::move(pf.promise) ](const CallbackArgs& args) mutable noexcept {
invariant(args.status);
- log() << "Starting oplog application";
+ LOGV2(21224, "Starting oplog application");
_run(_oplogBuffer);
- log() << "Finished oplog application";
+ LOGV2(21225, "Finished oplog application");
promise.setWith([] {});
};
invariant(_executor->scheduleWork(std::move(callback)).getStatus());
@@ -75,7 +76,7 @@ Future<void> OplogApplier::startup() {
void OplogApplier::shutdown() {
// Shutdown will hang if this failpoint is enabled.
if (globalFailPointRegistry().find("rsSyncApplyStop")->shouldFail()) {
- severe() << "Turn off rsSyncApplyStop before attempting clean shutdown";
+ LOGV2_FATAL(21227, "Turn off rsSyncApplyStop before attempting clean shutdown");
fassertFailedNoTrace(40304);
}
@@ -110,7 +111,10 @@ void OplogApplier::enqueue(OperationContext* opCtx,
OplogBuffer::Batch::const_iterator end) {
static Occasionally sampler;
if (sampler.tick()) {
- LOG(2) << "oplog buffer has " << _oplogBuffer->getSize() << " bytes";
+ LOGV2_DEBUG(21226,
+ 2,
+ "oplog buffer has {oplogBuffer_getSize} bytes",
+ "oplogBuffer_getSize"_attr = _oplogBuffer->getSize());
}
_oplogBuffer->push(opCtx, begin, end);
}
diff --git a/src/mongo/db/repl/oplog_applier_impl.cpp b/src/mongo/db/repl/oplog_applier_impl.cpp
index 1ac70f2a05e..e54bc128219 100644
--- a/src/mongo/db/repl/oplog_applier_impl.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/repl/insert_group.h"
#include "mongo/db/repl/transaction_oplog_application.h"
#include "mongo/db/stats/timer_stats.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/basic.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -125,7 +126,7 @@ Status finishAndLogApply(OperationContext* opCtx,
s << redact(entryOrGroupedInserts.toBSON());
s << ", took " << opDuration << "ms";
- log() << s.str();
+ LOGV2(21228, "{s_str}", "s_str"_attr = s.str());
}
}
return finalStatus;
@@ -434,8 +435,9 @@ void OplogApplierImpl::_run(OplogBuffer* oplogBuffer) {
// For pausing replication in tests.
if (MONGO_unlikely(rsSyncApplyStop.shouldFail())) {
- log() << "Oplog Applier - rsSyncApplyStop fail point enabled. Blocking until fail "
- "point is disabled.";
+ LOGV2(21229,
+ "Oplog Applier - rsSyncApplyStop fail point enabled. Blocking until fail "
+ "point is disabled.");
rsSyncApplyStop.pauseWhileSet(&opCtx);
}
@@ -602,7 +604,7 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx,
std::vector<OplogEntry> ops) {
invariant(!ops.empty());
- LOG(2) << "replication batch size is " << ops.size();
+ LOGV2_DEBUG(21230, 2, "replication batch size is {ops_size}", "ops_size"_attr = ops.size());
// Stop all readers until we're done. This also prevents doc-locking engines from deleting old
// entries from the oplog until we finish writing.
@@ -610,7 +612,7 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx,
invariant(_replCoord);
if (_replCoord->getApplierState() == ReplicationCoordinator::ApplierState::Stopped) {
- severe() << "attempting to replicate ops while primary";
+ LOGV2_FATAL(21234, "attempting to replicate ops while primary");
return {ErrorCodes::CannotApplyOplogWhilePrimary,
"attempting to replicate ops while primary"};
}
@@ -653,8 +655,9 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx,
// Use this fail point to hold the PBWM lock after we have written the oplog entries but
// before we have applied them.
if (MONGO_unlikely(pauseBatchApplicationAfterWritingOplogEntries.shouldFail())) {
- log() << "pauseBatchApplicationAfterWritingOplogEntries fail point enabled. Blocking "
- "until fail point is disabled.";
+ LOGV2(21231,
+ "pauseBatchApplicationAfterWritingOplogEntries fail point enabled. Blocking "
+ "until fail point is disabled.");
pauseBatchApplicationAfterWritingOplogEntries.pauseWhileSet(opCtx);
}
@@ -699,12 +702,17 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx,
for (auto it = statusVector.cbegin(); it != statusVector.cend(); ++it) {
const auto& status = *it;
if (!status.isOK()) {
- severe()
- << "Failed to apply batch of operations. Number of operations in batch: "
- << ops.size() << ". First operation: " << redact(ops.front().toBSON())
- << ". Last operation: " << redact(ops.back().toBSON())
- << ". Oplog application failed in writer thread "
- << std::distance(statusVector.cbegin(), it) << ": " << redact(status);
+ LOGV2_FATAL(21235,
+ "Failed to apply batch of operations. Number of operations in "
+ "batch: {ops_size}. First operation: {ops_front}. Last operation: "
+ "{ops_back}. Oplog application failed in writer thread "
+ "{std_distance_statusVector_cbegin_it}: {status}",
+ "ops_size"_attr = ops.size(),
+ "ops_front"_attr = redact(ops.front().toBSON()),
+ "ops_back"_attr = redact(ops.back().toBSON()),
+ "std_distance_statusVector_cbegin_it"_attr =
+ std::distance(statusVector.cbegin(), it),
+ "status"_attr = redact(status));
return status;
}
}
@@ -721,12 +729,14 @@ StatusWith<OpTime> OplogApplierImpl::_applyOplogBatch(OperationContext* opCtx,
// Use this fail point to hold the PBWM lock and prevent the batch from completing.
if (MONGO_unlikely(pauseBatchApplicationBeforeCompletion.shouldFail())) {
- log() << "pauseBatchApplicationBeforeCompletion fail point enabled. Blocking until fail "
- "point is disabled.";
+ LOGV2(21232,
+ "pauseBatchApplicationBeforeCompletion fail point enabled. Blocking until fail "
+ "point is disabled.");
while (MONGO_unlikely(pauseBatchApplicationBeforeCompletion.shouldFail())) {
if (inShutdown()) {
- severe() << "Turn off pauseBatchApplicationBeforeCompletion before attempting "
- "clean shutdown";
+ LOGV2_FATAL(21236,
+ "Turn off pauseBatchApplicationBeforeCompletion before attempting "
+ "clean shutdown");
fassertFailedNoTrace(50798);
}
sleepmillis(100);
@@ -904,10 +914,10 @@ Status applyOplogEntryOrGroupedInserts(OperationContext* opCtx,
auto applyStartTime = clockSource->now();
if (MONGO_unlikely(hangAfterRecordingOpApplicationStartTime.shouldFail())) {
- log() << "applyOplogEntryOrGroupedInserts - fail point "
- "hangAfterRecordingOpApplicationStartTime "
- "enabled. "
- << "Blocking until fail point is disabled. ";
+ LOGV2(21233,
+ "applyOplogEntryOrGroupedInserts - fail point "
+ "hangAfterRecordingOpApplicationStartTime "
+ "enabled. Blocking until fail point is disabled. ");
hangAfterRecordingOpApplicationStartTime.pauseWhileSet();
}
@@ -1046,8 +1056,10 @@ Status OplogApplierImpl::applyOplogBatchPerWorker(OperationContext* opCtx,
continue;
}
- severe() << "Error applying operation (" << redact(entry.toBSON())
- << "): " << causedBy(redact(status));
+ LOGV2_FATAL(21237,
+ "Error applying operation ({entry}): {causedBy_status}",
+ "entry"_attr = redact(entry.toBSON()),
+ "causedBy_status"_attr = causedBy(redact(status)));
return status;
}
} catch (const DBException& e) {
@@ -1058,8 +1070,10 @@ Status OplogApplierImpl::applyOplogBatchPerWorker(OperationContext* opCtx,
continue;
}
- severe() << "writer worker caught exception: " << redact(e)
- << " on: " << redact(entry.toBSON());
+ LOGV2_FATAL(21238,
+ "writer worker caught exception: {e} on: {entry}",
+ "e"_attr = redact(e),
+ "entry"_attr = redact(entry.toBSON()));
return e.toStatus();
}
}
diff --git a/src/mongo/db/repl/oplog_batcher.cpp b/src/mongo/db/repl/oplog_batcher.cpp
index 80f0ffbbec6..3d2348ad8a1 100644
--- a/src/mongo/db/repl/oplog_batcher.cpp
+++ b/src/mongo/db/repl/oplog_batcher.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/commands/txn_cmds_gen.h"
#include "mongo/db/repl/oplog_applier.h"
#include "mongo/db/repl/repl_server_parameters_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -173,7 +174,7 @@ StatusWith<std::vector<OplogEntry>> OplogBatcher::getNextApplierBatch(
std::string message = str::stream()
<< "expected oplog version " << OplogEntry::kOplogVersion << " but found version "
<< entry.getVersion() << " in oplog entry: " << redact(entry.toBSON());
- severe() << message;
+ LOGV2_FATAL(21240, "{message}", "message"_attr = message);
return {ErrorCodes::BadValue, message};
}
@@ -319,7 +320,9 @@ void OplogBatcher::_run(StorageInterface* storageInterface) {
// Check the oplog buffer after the applier state to ensure the producer is stopped.
if (isDraining && _oplogBuffer->isEmpty()) {
ops.setTermWhenExhausted(termWhenBufferIsEmpty);
- log() << "Oplog buffer has been drained in term " << termWhenBufferIsEmpty;
+ LOGV2(21239,
+ "Oplog buffer has been drained in term {termWhenBufferIsEmpty}",
+ "termWhenBufferIsEmpty"_attr = termWhenBufferIsEmpty);
} else {
// Don't emit empty batches.
continue;
diff --git a/src/mongo/db/repl/oplog_fetcher.cpp b/src/mongo/db/repl/oplog_fetcher.cpp
index afff88413c3..0609e46c634 100644
--- a/src/mongo/db/repl/oplog_fetcher.cpp
+++ b/src/mongo/db/repl/oplog_fetcher.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/repl/replication_auth.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/stats/timer_stats.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/fail_point.h"
@@ -467,7 +468,7 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons
[&](auto&&) {
status = {ErrorCodes::FailPointEnabled,
"stopReplProducerOnDocument fail point is enabled."};
- log() << status.reason();
+ LOGV2(21264, "{status_reason}", "status_reason"_attr = status.reason());
},
[&](const BSONObj& data) {
auto opCtx = cc().makeOperationContext();
@@ -485,17 +486,25 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons
auto firstDocToApply = documents.cbegin();
if (!documents.empty()) {
- LOG(2) << "oplog fetcher read " << documents.size()
- << " operations from remote oplog starting at " << documents.front()["ts"]
- << " and ending at " << documents.back()["ts"];
+ LOGV2_DEBUG(21265,
+ 2,
+ "oplog fetcher read {documents_size} operations from remote oplog starting at "
+ "{documents_front_ts} and ending at {documents_back_ts}",
+ "documents_size"_attr = documents.size(),
+ "documents_front_ts"_attr = documents.front()["ts"],
+ "documents_back_ts"_attr = documents.back()["ts"]);
} else {
- LOG(2) << "oplog fetcher read 0 operations from remote oplog";
+ LOGV2_DEBUG(21266, 2, "oplog fetcher read 0 operations from remote oplog");
}
auto oqMetadataResult = parseOplogQueryMetadata(queryResponse);
if (!oqMetadataResult.isOK()) {
- error() << "invalid oplog query metadata from sync source " << _getSource() << ": "
- << oqMetadataResult.getStatus() << ": " << queryResponse.otherFields.metadata;
+ LOGV2_ERROR(21276,
+ "invalid oplog query metadata from sync source {getSource}: "
+ "{oqMetadataResult_getStatus}: {queryResponse_otherFields_metadata}",
+ "getSource"_attr = _getSource(),
+ "oqMetadataResult_getStatus"_attr = oqMetadataResult.getStatus(),
+ "queryResponse_otherFields_metadata"_attr = queryResponse.otherFields.metadata);
return oqMetadataResult.getStatus();
}
auto oqMetadata = oqMetadataResult.getValue();
@@ -519,7 +528,10 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons
return status;
}
- LOG(1) << "oplog fetcher successfully fetched from " << _getSource();
+ LOGV2_DEBUG(21267,
+ 1,
+ "oplog fetcher successfully fetched from {getSource}",
+ "getSource"_attr = _getSource());
// We do not always enqueue the first document. We elect to skip it for the following
// reasons:
@@ -553,8 +565,12 @@ StatusWith<BSONObj> OplogFetcher::_onSuccessfulBatch(const Fetcher::QueryRespons
const auto& metadataObj = queryResponse.otherFields.metadata;
auto metadataResult = rpc::ReplSetMetadata::readFromMetadata(metadataObj);
if (!metadataResult.isOK()) {
- error() << "invalid replication metadata from sync source " << _getSource() << ": "
- << metadataResult.getStatus() << ": " << metadataObj;
+ LOGV2_ERROR(21277,
+ "invalid replication metadata from sync source {getSource}: "
+ "{metadataResult_getStatus}: {metadataObj}",
+ "getSource"_attr = _getSource(),
+ "metadataResult_getStatus"_attr = metadataResult.getStatus(),
+ "metadataObj"_attr = metadataObj);
return metadataResult.getStatus();
}
replSetMetadata = metadataResult.getValue();
@@ -838,7 +854,7 @@ void NewOplogFetcher::_runQuery(const executor::TaskExecutor::CallbackArgs& call
if (MONGO_unlikely(logAfterOplogFetcherConnCreated.shouldFail())) {
// Used in tests that wait for this failpoint to be entered to ensure the DBClientConnection
// was created.
- log() << "logAfterOplogFetcherConnCreated failpoint enabled.";
+ LOGV2(21268, "logAfterOplogFetcherConnCreated failpoint enabled.");
}
hangAfterOplogFetcherCallbackScheduled.pauseWhileSet();
@@ -1074,7 +1090,7 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) {
[&](auto&&) {
status = {ErrorCodes::FailPointEnabled,
"stopReplProducerOnDocument fail point is enabled."};
- log() << status.reason();
+ LOGV2(21269, "{status_reason}", "status_reason"_attr = status.reason());
},
[&](const BSONObj& data) {
auto opCtx = cc().makeOperationContext();
@@ -1091,17 +1107,25 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) {
auto firstDocToApply = documents.cbegin();
if (!documents.empty()) {
- LOG(2) << "oplog fetcher read " << documents.size()
- << " operations from remote oplog starting at " << documents.front()["ts"]
- << " and ending at " << documents.back()["ts"];
+ LOGV2_DEBUG(21270,
+ 2,
+ "oplog fetcher read {documents_size} operations from remote oplog starting at "
+ "{documents_front_ts} and ending at {documents_back_ts}",
+ "documents_size"_attr = documents.size(),
+ "documents_front_ts"_attr = documents.front()["ts"],
+ "documents_back_ts"_attr = documents.back()["ts"]);
} else {
- LOG(2) << "oplog fetcher read 0 operations from remote oplog";
+ LOGV2_DEBUG(21271, 2, "oplog fetcher read 0 operations from remote oplog");
}
auto oqMetadataResult = parseOplogQueryMetadata(_metadataObj);
if (!oqMetadataResult.isOK()) {
- error() << "invalid oplog query metadata from sync source " << _source << ": "
- << oqMetadataResult.getStatus() << ": " << _metadataObj;
+ LOGV2_ERROR(21278,
+ "invalid oplog query metadata from sync source {source}: "
+ "{oqMetadataResult_getStatus}: {metadataObj}",
+ "source"_attr = _source,
+ "oqMetadataResult_getStatus"_attr = oqMetadataResult.getStatus(),
+ "metadataObj"_attr = _metadataObj);
return oqMetadataResult.getStatus();
}
auto oqMetadata = oqMetadataResult.getValue();
@@ -1124,7 +1148,8 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) {
return status;
}
- LOG(1) << "oplog fetcher successfully fetched from " << _source;
+ LOGV2_DEBUG(
+ 21272, 1, "oplog fetcher successfully fetched from {source}", "source"_attr = _source);
// We do not always enqueue the first document. We elect to skip it for the following
// reasons:
@@ -1156,8 +1181,12 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) {
if (receivedReplMetadata) {
auto metadataResult = rpc::ReplSetMetadata::readFromMetadata(_metadataObj);
if (!metadataResult.isOK()) {
- error() << "invalid replication metadata from sync source " << _source << ": "
- << metadataResult.getStatus() << ": " << _metadataObj;
+ LOGV2_ERROR(21279,
+ "invalid replication metadata from sync source {source}: "
+ "{metadataResult_getStatus}: {metadataObj}",
+ "source"_attr = _source,
+ "metadataResult_getStatus"_attr = metadataResult.getStatus(),
+ "metadataObj"_attr = _metadataObj);
return metadataResult.getStatus();
}
replSetMetadata = metadataResult.getValue();
@@ -1210,7 +1239,10 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) {
}
auto lastDocOpTime = lastDocOpTimeRes.getValue();
- LOG(3) << "Oplog fetcher setting last fetched optime ahead after batch: " << lastDocOpTime;
+ LOGV2_DEBUG(21273,
+ 3,
+ "Oplog fetcher setting last fetched optime ahead after batch: {lastDocOpTime}",
+ "lastDocOpTime"_attr = lastDocOpTime);
stdx::lock_guard<Latch> lock(_mutex);
_lastFetched = lastDocOpTime;
@@ -1223,13 +1255,17 @@ Status NewOplogFetcher::_onSuccessfulBatch(const Documents& documents) {
bool NewOplogFetcher::OplogFetcherRestartDecisionDefault::shouldContinue(NewOplogFetcher* fetcher,
Status status) {
if (_numRestarts == _maxRestarts) {
- log() << "Error returned from oplog query (no more query restarts left): "
- << redact(status);
+ LOGV2(21274,
+ "Error returned from oplog query (no more query restarts left): {status}",
+ "status"_attr = redact(status));
return false;
}
- log() << "Recreating cursor for oplog fetcher due to error: " << redact(status)
- << ". Last fetched optime: " << fetcher->_getLastOpTimeFetched()
- << ". Attempts remaining: " << (_maxRestarts - _numRestarts);
+ LOGV2(21275,
+ "Recreating cursor for oplog fetcher due to error: {status}. Last fetched optime: "
+ "{fetcher_getLastOpTimeFetched}. Attempts remaining: {maxRestarts_numRestarts}",
+ "status"_attr = redact(status),
+ "fetcher_getLastOpTimeFetched"_attr = fetcher->_getLastOpTimeFetched(),
+ "maxRestarts_numRestarts"_attr = (_maxRestarts - _numRestarts));
_numRestarts++;
return true;
}
diff --git a/src/mongo/db/repl/repl_client_info.cpp b/src/mongo/db/repl/repl_client_info.cpp
index 0690e7b483e..119ec569a65 100644
--- a/src/mongo/db/repl/repl_client_info.cpp
+++ b/src/mongo/db/repl/repl_client_info.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/client.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/replication_coordinator.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/decorable.h"
#include "mongo/util/log.h"
@@ -103,10 +104,13 @@ void ReplClientInfo::setLastOpToSystemLastOpTime(OperationContext* opCtx) {
if (systemOpTime >= _lastOp) {
_lastOp = systemOpTime;
} else {
- log() << "Not setting the last OpTime for this Client from " << _lastOp
- << " to the current system time of " << systemOpTime
- << " as that would be moving the OpTime backwards. This should only happen if "
- "there was a rollback recently";
+ LOGV2(21280,
+ "Not setting the last OpTime for this Client from {lastOp} to the current system "
+ "time of {systemOpTime} as that would be moving the OpTime backwards. This "
+ "should only happen if "
+ "there was a rollback recently",
+ "lastOp"_attr = _lastOp,
+ "systemOpTime"_attr = systemOpTime);
}
lastOpInfo(opCtx).lastOpSetExplicitly = true;
@@ -122,7 +126,10 @@ void ReplClientInfo::setLastOpToSystemLastOpTimeIgnoringInterrupt(OperationConte
} catch (const ExceptionForCat<ErrorCategory::Interruption>& e) {
// In most cases, it is safe to ignore interruption errors because we cannot use the same
// OperationContext to wait for writeConcern anyways.
- LOG(2) << "Ignoring set last op interruption error: " << e.toStatus();
+ LOGV2_DEBUG(21281,
+ 2,
+ "Ignoring set last op interruption error: {e_toStatus}",
+ "e_toStatus"_attr = e.toStatus());
}
}
diff --git a/src/mongo/db/repl/repl_set_commands.cpp b/src/mongo/db/repl/repl_set_commands.cpp
index a9c7bdc5336..8203c36f567 100644
--- a/src/mongo/db/repl/repl_set_commands.cpp
+++ b/src/mongo/db/repl/repl_set_commands.cpp
@@ -62,6 +62,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/storage_engine.h"
#include "mongo/executor/network_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/session.h"
#include "mongo/transport/transport_layer.h"
#include "mongo/util/decimal_counter.h"
@@ -103,7 +104,7 @@ public:
const string&,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
- log() << "replSetTest command received: " << cmdObj.toString();
+ LOGV2(21573, "replSetTest command received: {cmdObj}", "cmdObj"_attr = cmdObj.toString());
auto replCoord = ReplicationCoordinator::get(getGlobalServiceContext());
@@ -120,8 +121,10 @@ public:
status = bsonExtractIntegerField(cmdObj, "timeoutMillis", &timeoutMillis);
uassertStatusOK(status);
Milliseconds timeout(timeoutMillis);
- log() << "replSetTest: waiting " << timeout << " for member state to become "
- << expectedState;
+ LOGV2(21574,
+ "replSetTest: waiting {timeout} for member state to become {expectedState}",
+ "timeout"_attr = timeout,
+ "expectedState"_attr = expectedState);
status = replCoord->waitForMemberState(expectedState, timeout);
@@ -132,7 +135,9 @@ public:
auto status = bsonExtractIntegerField(cmdObj, "waitForDrainFinish", &timeoutMillis);
uassertStatusOK(status);
Milliseconds timeout(timeoutMillis);
- log() << "replSetTest: waiting " << timeout << " for applier buffer to finish draining";
+ LOGV2(21575,
+ "replSetTest: waiting {timeout} for applier buffer to finish draining",
+ "timeout"_attr = timeout);
status = replCoord->waitForDrainFinish(timeout);
@@ -275,7 +280,7 @@ void parseReplSetSeedList(ReplicationCoordinatorExternalState* externalState,
seedSet.insert(m);
// uassert(13101, "can't use localhost in replset host list", !m.isLocalHost());
if (externalState->isSelf(m, getGlobalServiceContext())) {
- LOG(1) << "ignoring seed " << m.toString() << " (=self)";
+ LOGV2_DEBUG(21576, 1, "ignoring seed {m} (=self)", "m"_attr = m.toString());
} else {
seeds->push_back(m);
}
@@ -315,7 +320,7 @@ public:
"no configuration specified. "
"Using a default configuration for the set";
result.append("info2", noConfigMessage);
- log() << "initiate : " << noConfigMessage;
+ LOGV2(21577, "initiate : {noConfigMessage}", "noConfigMessage"_attr = noConfigMessage);
ReplicationCoordinatorExternalStateImpl externalState(
opCtx->getServiceContext(),
@@ -346,7 +351,9 @@ public:
}
b.appendArray("members", members.obj());
configObj = b.obj();
- log() << "created this configuration for initiation : " << configObj.toString();
+ LOGV2(21578,
+ "created this configuration for initiation : {configObj}",
+ "configObj"_attr = configObj.toString());
}
if (configObj.getField("version").eoo()) {
@@ -522,12 +529,12 @@ public:
uassertStatusOK(status);
}
- log() << "Attempting to step down in response to replSetStepDown command";
+ LOGV2(21579, "Attempting to step down in response to replSetStepDown command");
ReplicationCoordinator::get(opCtx)->stepDown(
opCtx, force, Seconds(secondaryCatchUpPeriodSecs), Seconds(stepDownForSecs));
- log() << "replSetStepDown command completed";
+ LOGV2(21580, "replSetStepDown command completed");
onExitGuard.dismiss();
return true;
@@ -726,13 +733,15 @@ public:
Status status = ReplicationCoordinator::get(opCtx)->checkReplEnabledForCommand(&result);
uassertStatusOK(status);
- log() << "Received replSetStepUp request";
+ LOGV2(21581, "Received replSetStepUp request");
const bool skipDryRun = cmdObj["skipDryRun"].trueValue();
status = ReplicationCoordinator::get(opCtx)->stepUpIfEligible(skipDryRun);
if (!status.isOK()) {
- log() << "replSetStepUp request failed" << causedBy(status);
+ LOGV2(21582,
+ "replSetStepUp request failed{causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
}
uassertStatusOK(status);
@@ -761,13 +770,15 @@ public:
BSONObjBuilder& result) override {
Status status = ReplicationCoordinator::get(opCtx)->checkReplEnabledForCommand(&result);
uassertStatusOK(status);
- log() << "Received replSetAbortPrimaryCatchUp request";
+ LOGV2(21583, "Received replSetAbortPrimaryCatchUp request");
status = ReplicationCoordinator::get(opCtx)->abortCatchupIfNeeded(
ReplicationCoordinator::PrimaryCatchUpConclusionReason::
kFailedWithReplSetAbortPrimaryCatchUpCmd);
if (!status.isOK()) {
- log() << "replSetAbortPrimaryCatchUp request failed" << causedBy(status);
+ LOGV2(21584,
+ "replSetAbortPrimaryCatchUp request failed{causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
}
uassertStatusOK(status);
return true;
diff --git a/src/mongo/db/repl/replication_consistency_markers_impl.cpp b/src/mongo/db/repl/replication_consistency_markers_impl.cpp
index 8d7046a89f2..6464b0311cc 100644
--- a/src/mongo/db/repl/replication_consistency_markers_impl.cpp
+++ b/src/mongo/db/repl/replication_consistency_markers_impl.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/repl/optime.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/repl/storage_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -93,7 +94,7 @@ void ReplicationConsistencyMarkersImpl::_updateMinValidDocument(
}
void ReplicationConsistencyMarkersImpl::initializeMinValidDocument(OperationContext* opCtx) {
- LOG(3) << "Initializing minValid document";
+ LOGV2_DEBUG(21282, 3, "Initializing minValid document");
// This initializes the values of the required fields if they are not already set.
// If one of the fields is already set, the $max will prefer the existing value since it
@@ -114,22 +115,25 @@ void ReplicationConsistencyMarkersImpl::initializeMinValidDocument(OperationCont
bool ReplicationConsistencyMarkersImpl::getInitialSyncFlag(OperationContext* opCtx) const {
auto doc = _getMinValidDocument(opCtx);
if (!doc) {
- LOG(3) << "No min valid document found, returning initial sync flag value of false.";
+ LOGV2_DEBUG(
+ 21283, 3, "No min valid document found, returning initial sync flag value of false.");
return false;
}
boost::optional<bool> flag = doc->getInitialSyncFlag();
if (!flag) {
- LOG(3) << "No initial sync flag set, returning initial sync flag value of false.";
+ LOGV2_DEBUG(
+ 21284, 3, "No initial sync flag set, returning initial sync flag value of false.");
return false;
}
- LOG(3) << "returning initial sync flag value of " << flag.get();
+ LOGV2_DEBUG(
+ 21285, 3, "returning initial sync flag value of {flag_get}", "flag_get"_attr = flag.get());
return flag.get();
}
void ReplicationConsistencyMarkersImpl::setInitialSyncFlag(OperationContext* opCtx) {
- LOG(3) << "setting initial sync flag";
+ LOGV2_DEBUG(21286, 3, "setting initial sync flag");
TimestampedBSONObj update;
update.obj = BSON("$set" << kInitialSyncFlag);
@@ -143,7 +147,7 @@ void ReplicationConsistencyMarkersImpl::setInitialSyncFlag(OperationContext* opC
}
void ReplicationConsistencyMarkersImpl::clearInitialSyncFlag(OperationContext* opCtx) {
- LOG(3) << "clearing initial sync flag";
+ LOGV2_DEBUG(21287, 3, "clearing initial sync flag");
auto replCoord = repl::ReplicationCoordinator::get(opCtx);
OpTimeAndWallTime opTimeAndWallTime = replCoord->getMyLastAppliedOpTimeAndWallTime();
@@ -184,15 +188,22 @@ OpTime ReplicationConsistencyMarkersImpl::getMinValid(OperationContext* opCtx) c
auto minValid = OpTime(doc->getMinValidTimestamp(), doc->getMinValidTerm());
- LOG(3) << "returning minvalid: " << minValid.toString() << "(" << minValid.toBSON() << ")";
+ LOGV2_DEBUG(21288,
+ 3,
+ "returning minvalid: {minValid}({minValid2})",
+ "minValid"_attr = minValid.toString(),
+ "minValid2"_attr = minValid.toBSON());
return minValid;
}
void ReplicationConsistencyMarkersImpl::setMinValid(OperationContext* opCtx,
const OpTime& minValid) {
- LOG(3) << "setting minvalid to exactly: " << minValid.toString() << "(" << minValid.toBSON()
- << ")";
+ LOGV2_DEBUG(21289,
+ 3,
+ "setting minvalid to exactly: {minValid}({minValid2})",
+ "minValid"_attr = minValid.toString(),
+ "minValid2"_attr = minValid.toBSON());
TimestampedBSONObj update;
update.obj =
BSON("$set" << BSON(MinValidDocument::kMinValidTimestampFieldName
@@ -209,8 +220,11 @@ void ReplicationConsistencyMarkersImpl::setMinValid(OperationContext* opCtx,
void ReplicationConsistencyMarkersImpl::setMinValidToAtLeast(OperationContext* opCtx,
const OpTime& minValid) {
- LOG(3) << "setting minvalid to at least: " << minValid.toString() << "(" << minValid.toBSON()
- << ")";
+ LOGV2_DEBUG(21290,
+ 3,
+ "setting minvalid to at least: {minValid}({minValid2})",
+ "minValid"_attr = minValid.toString(),
+ "minValid2"_attr = minValid.toBSON());
auto& termField = MinValidDocument::kMinValidTermFieldName;
auto& tsField = MinValidDocument::kMinValidTimestampFieldName;
@@ -250,7 +264,11 @@ void ReplicationConsistencyMarkersImpl::setAppliedThrough(OperationContext* opCt
const OpTime& optime,
bool setTimestamp) {
invariant(!optime.isNull());
- LOG(3) << "setting appliedThrough to: " << optime.toString() << "(" << optime.toBSON() << ")";
+ LOGV2_DEBUG(21291,
+ 3,
+ "setting appliedThrough to: {optime}({optime2})",
+ "optime"_attr = optime.toString(),
+ "optime2"_attr = optime.toBSON());
// We set the 'appliedThrough' to the provided timestamp. The 'appliedThrough' is only valid
// in checkpoints that contain all writes through this timestamp since it indicates the top of
@@ -266,7 +284,10 @@ void ReplicationConsistencyMarkersImpl::setAppliedThrough(OperationContext* opCt
void ReplicationConsistencyMarkersImpl::clearAppliedThrough(OperationContext* opCtx,
const Timestamp& writeTimestamp) {
- LOG(3) << "clearing appliedThrough at: " << writeTimestamp.toString();
+ LOGV2_DEBUG(21292,
+ 3,
+ "clearing appliedThrough at: {writeTimestamp}",
+ "writeTimestamp"_attr = writeTimestamp.toString());
TimestampedBSONObj update;
update.timestamp = writeTimestamp;
@@ -281,11 +302,15 @@ OpTime ReplicationConsistencyMarkersImpl::getAppliedThrough(OperationContext* op
auto appliedThrough = doc->getAppliedThrough();
if (!appliedThrough) {
- LOG(3) << "No appliedThrough OpTime set, returning empty appliedThrough OpTime.";
+ LOGV2_DEBUG(
+ 21293, 3, "No appliedThrough OpTime set, returning empty appliedThrough OpTime.");
return {};
}
- LOG(3) << "returning appliedThrough: " << appliedThrough->toString() << "("
- << appliedThrough->toBSON() << ")";
+ LOGV2_DEBUG(21294,
+ 3,
+ "returning appliedThrough: {appliedThrough}({appliedThrough2})",
+ "appliedThrough"_attr = appliedThrough->toString(),
+ "appliedThrough2"_attr = appliedThrough->toBSON());
return appliedThrough.get();
}
@@ -313,8 +338,11 @@ ReplicationConsistencyMarkersImpl::_getOplogTruncateAfterPointDocument(
void ReplicationConsistencyMarkersImpl::ensureFastCountOnOplogTruncateAfterPoint(
OperationContext* opCtx) {
- LOG(3) << "Updating cached fast-count on collection " << _oplogTruncateAfterPointNss
- << " in case an unclean shutdown caused it to become incorrect.";
+ LOGV2_DEBUG(21295,
+ 3,
+ "Updating cached fast-count on collection {oplogTruncateAfterPointNss} in case an "
+ "unclean shutdown caused it to become incorrect.",
+ "oplogTruncateAfterPointNss"_attr = _oplogTruncateAfterPointNss);
auto result = _storageInterface->findSingleton(opCtx, _oplogTruncateAfterPointNss);
@@ -354,7 +382,10 @@ void ReplicationConsistencyMarkersImpl::_upsertOplogTruncateAfterPointDocument(
void ReplicationConsistencyMarkersImpl::setOplogTruncateAfterPoint(OperationContext* opCtx,
const Timestamp& timestamp) {
- LOG(3) << "setting oplog truncate after point to: " << timestamp.toBSON();
+ LOGV2_DEBUG(21296,
+ 3,
+ "setting oplog truncate after point to: {timestamp}",
+ "timestamp"_attr = timestamp.toBSON());
_upsertOplogTruncateAfterPointDocument(
opCtx,
BSON("$set" << BSON(OplogTruncateAfterPointDocument::kOplogTruncateAfterPointFieldName
@@ -365,13 +396,14 @@ Timestamp ReplicationConsistencyMarkersImpl::getOplogTruncateAfterPoint(
OperationContext* opCtx) const {
auto doc = _getOplogTruncateAfterPointDocument(opCtx);
if (!doc) {
- LOG(3) << "Returning empty oplog truncate after point since document did not exist";
+ LOGV2_DEBUG(
+ 21297, 3, "Returning empty oplog truncate after point since document did not exist");
return {};
}
Timestamp out = doc->getOplogTruncateAfterPoint();
- LOG(3) << "returning oplog truncate after point: " << out;
+ LOGV2_DEBUG(21298, 3, "returning oplog truncate after point: {out}", "out"_attr = out);
return out;
}
diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
index 08bff69143a..29dfa758378 100644
--- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp
@@ -94,6 +94,7 @@
#include "mongo/executor/network_interface.h"
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/catalog_cache_loader.h"
@@ -238,13 +239,13 @@ void ReplicationCoordinatorExternalStateImpl::startSteadyStateReplication(
_bgSync =
std::make_unique<BackgroundSync>(replCoord, this, _replicationProcess, _oplogApplier.get());
- log() << "Starting replication fetcher thread";
+ LOGV2(21299, "Starting replication fetcher thread");
_bgSync->startup(opCtx);
- log() << "Starting replication applier thread";
+ LOGV2(21300, "Starting replication applier thread");
_oplogApplierShutdownFuture = _oplogApplier->startup();
- log() << "Starting replication reporter thread";
+ LOGV2(21301, "Starting replication reporter thread");
invariant(!_syncSourceFeedbackThread);
// Get the pointer while holding the lock so that _stopDataReplication_inlock() won't
// leave the unique pointer empty if the _syncSourceFeedbackThread's function starts
@@ -275,18 +276,18 @@ void ReplicationCoordinatorExternalStateImpl::_stopDataReplication_inlock(
// _syncSourceFeedbackThread should be joined before _bgSync's shutdown because it has
// a pointer of _bgSync.
if (oldSSF) {
- log() << "Stopping replication reporter thread";
+ LOGV2(21302, "Stopping replication reporter thread");
_syncSourceFeedback.shutdown();
oldSSF->join();
}
if (oldBgSync) {
- log() << "Stopping replication fetcher thread";
+ LOGV2(21303, "Stopping replication fetcher thread");
oldBgSync->shutdown(opCtx);
}
if (oldApplier) {
- log() << "Stopping replication applier thread";
+ LOGV2(21304, "Stopping replication applier thread");
oldApplier->shutdown();
}
@@ -321,11 +322,12 @@ void ReplicationCoordinatorExternalStateImpl::startThreads(const ReplSettings& s
return;
}
if (_inShutdown) {
- log() << "Not starting replication storage threads because replication is shutting down.";
+ LOGV2(21305,
+ "Not starting replication storage threads because replication is shutting down.");
return;
}
- log() << "Starting replication storage threads";
+ LOGV2(21306, "Starting replication storage threads");
_service->getStorageEngine()->setJournalListener(this);
_oplogApplierTaskExecutor =
@@ -383,7 +385,7 @@ void ReplicationCoordinatorExternalStateImpl::shutdown(OperationContext* opCtx)
_stopDataReplication_inlock(opCtx, lk);
- log() << "Stopping replication storage threads";
+ LOGV2(21307, "Stopping replication storage threads");
_taskExecutor->shutdown();
_oplogApplierTaskExecutor->shutdown();
@@ -396,7 +398,7 @@ void ReplicationCoordinatorExternalStateImpl::shutdown(OperationContext* opCtx)
// itself can block on the ReplicationCoordinator mutex. It is safe to access _noopWriter
// outside of _threadMutex because _noopWriter is protected by its own mutex.
invariant(_noopWriter);
- LOG(1) << "Stopping noop writer";
+ LOGV2_DEBUG(21308, 1, "Stopping noop writer");
_noopWriter->stopWritingPeriodicNoops();
// We must wait for _taskExecutor outside of _threadMutex, since _taskExecutor is used to run
@@ -877,7 +879,7 @@ void ReplicationCoordinatorExternalStateImpl::_dropAllTempCollections(OperationC
// replica set members.
if (*it == "local")
continue;
- LOG(2) << "Removing temporary collections from " << *it;
+ LOGV2_DEBUG(21309, 2, "Removing temporary collections from {it}", "it"_attr = *it);
AutoGetDb autoDb(opCtx, *it, MODE_IX);
invariant(autoDb.getDb(), str::stream() << "Unable to get reference to database " << *it);
autoDb.getDb()->clearTmpCollections(opCtx);
@@ -922,10 +924,11 @@ void ReplicationCoordinatorExternalStateImpl::notifyOplogMetadataWaiters(
_taskExecutor.get(),
[committedOpTime, reaper](const executor::TaskExecutor::CallbackArgs& args) {
if (MONGO_unlikely(dropPendingCollectionReaperHang.shouldFail())) {
- log() << "fail point dropPendingCollectionReaperHang enabled. "
- "Blocking until fail point is disabled. "
- "committedOpTime: "
- << committedOpTime;
+ LOGV2(21310,
+ "fail point dropPendingCollectionReaperHang enabled. "
+ "Blocking until fail point is disabled. "
+ "committedOpTime: {committedOpTime}",
+ "committedOpTime"_attr = committedOpTime);
dropPendingCollectionReaperHang.pauseWhileSet();
}
auto opCtx = cc().makeOperationContext();
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index f1db12180a2..43a9eab03a2 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -88,6 +88,7 @@
#include "mongo/db/write_concern_options.h"
#include "mongo/executor/connection_pool_stats.h"
#include "mongo/executor/network_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
@@ -443,12 +444,14 @@ bool ReplicationCoordinatorImpl::_startLoadLocalConfig(OperationContext* opCtx)
StatusWith<LastVote> lastVote = _externalState->loadLocalLastVoteDocument(opCtx);
if (!lastVote.isOK()) {
- severe() << "Error loading local voted for document at startup; " << lastVote.getStatus();
+ LOGV2_FATAL(21429,
+ "Error loading local voted for document at startup; {lastVote_getStatus}",
+ "lastVote_getStatus"_attr = lastVote.getStatus());
fassertFailedNoTrace(40367);
}
if (lastVote.getValue().getTerm() == OpTime::kInitialTerm) {
// This log line is checked in unit tests.
- log() << "Did not find local initialized voted for document at startup.";
+ LOGV2(21311, "Did not find local initialized voted for document at startup.");
}
{
stdx::lock_guard<Latch> lk(_mutex);
@@ -459,38 +462,45 @@ bool ReplicationCoordinatorImpl::_startLoadLocalConfig(OperationContext* opCtx)
auto status = _replicationProcess->refreshRollbackID(opCtx);
if (!status.isOK()) {
if (status == ErrorCodes::NamespaceNotFound) {
- log() << "Did not find local Rollback ID document at startup. Creating one.";
+ LOGV2(21312, "Did not find local Rollback ID document at startup. Creating one.");
auto initializingStatus = _replicationProcess->initializeRollbackID(opCtx);
fassert(40424, initializingStatus);
} else {
- severe() << "Error loading local Rollback ID document at startup; " << status;
+ LOGV2_FATAL(21430,
+ "Error loading local Rollback ID document at startup; {status}",
+ "status"_attr = status);
fassertFailedNoTrace(40428);
}
}
StatusWith<BSONObj> cfg = _externalState->loadLocalConfigDocument(opCtx);
if (!cfg.isOK()) {
- log() << "Did not find local replica set configuration document at startup; "
- << cfg.getStatus();
+ LOGV2(21313,
+ "Did not find local replica set configuration document at startup; {cfg_getStatus}",
+ "cfg_getStatus"_attr = cfg.getStatus());
return true;
}
ReplSetConfig localConfig;
status = localConfig.initialize(cfg.getValue());
if (!status.isOK()) {
if (status.code() == ErrorCodes::RepairedReplicaSetNode) {
- severe()
- << "This instance has been repaired and may contain modified replicated data that "
- "would not match other replica set members. To see your repaired data, start "
- "mongod without the --replSet option. When you are finished recovering your "
- "data and would like to perform a complete re-sync, please refer to the "
- "documentation here: "
- "https://docs.mongodb.com/manual/tutorial/resync-replica-set-member/";
+ LOGV2_FATAL(
+ 21431,
+ "This instance has been repaired and may contain modified replicated data that "
+ "would not match other replica set members. To see your repaired data, start "
+ "mongod without the --replSet option. When you are finished recovering your "
+ "data and would like to perform a complete re-sync, please refer to the "
+ "documentation here: "
+ "https://docs.mongodb.com/manual/tutorial/resync-replica-set-member/");
fassertFailedNoTrace(50923);
}
- error() << "Locally stored replica set configuration does not parse; See "
- "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config "
- "for information on how to recover from this. Got \""
- << status << "\" while parsing " << cfg.getValue();
+ LOGV2_ERROR(21414,
+ "Locally stored replica set configuration does not parse; See "
+ "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config "
+ "for information on how to recover from this. Got \"{status}\" while parsing "
+ "{cfg_getValue}",
+ "status"_attr = status,
+ "cfg_getValue"_attr = cfg.getValue());
fassertFailedNoTrace(28545);
}
@@ -535,7 +545,10 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig(
const StatusWith<OpTimeAndWallTime>& lastOpTimeAndWallTimeStatus,
const StatusWith<LastVote>& lastVoteStatus) {
if (!cbData.status.isOK()) {
- LOG(1) << "Loading local replica set configuration failed due to " << cbData.status;
+ LOGV2_DEBUG(21314,
+ 1,
+ "Loading local replica set configuration failed due to {cbData_status}",
+ "cbData_status"_attr = cbData.status);
return;
}
@@ -544,37 +557,51 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig(
if (!myIndex.isOK()) {
if (myIndex.getStatus() == ErrorCodes::NodeNotFound ||
myIndex.getStatus() == ErrorCodes::InvalidReplicaSetConfig) {
- warning() << "Locally stored replica set configuration does not have a valid entry "
- "for the current node; waiting for reconfig or remote heartbeat; Got \""
- << myIndex.getStatus() << "\" while validating " << localConfig.toBSON();
+ LOGV2_WARNING(21405,
+ "Locally stored replica set configuration does not have a valid entry "
+ "for the current node; waiting for reconfig or remote heartbeat; Got "
+ "\"{myIndex_getStatus}\" while validating {localConfig}",
+ "myIndex_getStatus"_attr = myIndex.getStatus(),
+ "localConfig"_attr = localConfig.toBSON());
myIndex = StatusWith<int>(-1);
} else {
- error() << "Locally stored replica set configuration is invalid; See "
- "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config"
- " for information on how to recover from this. Got \""
- << myIndex.getStatus() << "\" while validating " << localConfig.toBSON();
+ LOGV2_ERROR(21415,
+ "Locally stored replica set configuration is invalid; See "
+ "http://www.mongodb.org/dochub/core/recover-replica-set-from-invalid-config"
+ " for information on how to recover from this. Got \"{myIndex_getStatus}\" "
+ "while validating {localConfig}",
+ "myIndex_getStatus"_attr = myIndex.getStatus(),
+ "localConfig"_attr = localConfig.toBSON());
fassertFailedNoTrace(28544);
}
}
if (localConfig.getReplSetName() != _settings.ourSetName()) {
- warning() << "Local replica set configuration document reports set name of "
- << localConfig.getReplSetName() << ", but command line reports "
- << _settings.ourSetName() << "; waiting for reconfig or remote heartbeat";
+ LOGV2_WARNING(21406,
+ "Local replica set configuration document reports set name of "
+ "{localConfig_getReplSetName}, but command line reports "
+ "{settings_ourSetName}; waiting for reconfig or remote heartbeat",
+ "localConfig_getReplSetName"_attr = localConfig.getReplSetName(),
+ "settings_ourSetName"_attr = _settings.ourSetName());
myIndex = StatusWith<int>(-1);
}
if (serverGlobalParams.enableMajorityReadConcern && localConfig.getNumMembers() == 3 &&
localConfig.getNumDataBearingMembers() == 2) {
- log() << startupWarningsLog;
- log() << "** WARNING: This replica set has a Primary-Secondary-Arbiter architecture, but "
- "readConcern:majority is enabled "
- << startupWarningsLog;
- log() << "** for this node. This is not a recommended configuration. Please see "
- << startupWarningsLog;
- log() << "** https://dochub.mongodb.org/core/psa-disable-rc-majority"
- << startupWarningsLog;
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(21315, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 21316,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: This replica set has a Primary-Secondary-Arbiter architecture, but "
+ "readConcern:majority is enabled ");
+ LOGV2_OPTIONS(
+ 21317,
+ {logv2::LogTag::kStartupWarnings},
+ "** for this node. This is not a recommended configuration. Please see ");
+ LOGV2_OPTIONS(21318,
+ {logv2::LogTag::kStartupWarnings},
+ "** https://dochub.mongodb.org/core/psa-disable-rc-majority");
+ LOGV2_OPTIONS(21319, {logv2::LogTag::kStartupWarnings}, "");
}
// Do not check optime, if this node is an arbiter.
@@ -583,9 +610,12 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig(
OpTimeAndWallTime lastOpTimeAndWallTime = OpTimeAndWallTime();
if (!isArbiter) {
if (!lastOpTimeAndWallTimeStatus.isOK()) {
- warning() << "Failed to load timestamp and/or wall clock time of most recently applied "
- "operation: "
- << lastOpTimeAndWallTimeStatus.getStatus();
+ LOGV2_WARNING(
+ 21407,
+ "Failed to load timestamp and/or wall clock time of most recently applied "
+ "operation: {lastOpTimeAndWallTimeStatus_getStatus}",
+ "lastOpTimeAndWallTimeStatus_getStatus"_attr =
+ lastOpTimeAndWallTimeStatus.getStatus());
} else {
lastOpTimeAndWallTime = lastOpTimeAndWallTimeStatus.getValue();
}
@@ -646,7 +676,7 @@ void ReplicationCoordinatorImpl::_finishLoadLocalConfig(
// Step down is impossible, so we don't need to wait for the returned event.
_updateTerm_inlock(term);
}
- LOG(1) << "Current term is now " << term;
+ LOGV2_DEBUG(21320, 1, "Current term is now {term}", "term"_attr = term);
_performPostMemberStateUpdateAction(action);
if (!isArbiter) {
@@ -662,17 +692,21 @@ void ReplicationCoordinatorImpl::_stopDataReplication(OperationContext* opCtx) {
_initialSyncer.swap(initialSyncerCopy);
}
if (initialSyncerCopy) {
- LOG(1)
- << "ReplicationCoordinatorImpl::_stopDataReplication calling InitialSyncer::shutdown.";
+ LOGV2_DEBUG(
+ 21321,
+ 1,
+ "ReplicationCoordinatorImpl::_stopDataReplication calling InitialSyncer::shutdown.");
const auto status = initialSyncerCopy->shutdown();
if (!status.isOK()) {
- warning() << "InitialSyncer shutdown failed: " << status;
+ LOGV2_WARNING(21408, "InitialSyncer shutdown failed: {status}", "status"_attr = status);
}
initialSyncerCopy.reset();
// Do not return here, fall through.
}
- LOG(1) << "ReplicationCoordinatorImpl::_stopDataReplication calling "
- "ReplCoordExtState::stopDataReplication.";
+ LOGV2_DEBUG(21322,
+ 1,
+ "ReplicationCoordinatorImpl::_stopDataReplication calling "
+ "ReplCoordExtState::stopDataReplication.");
_externalState->stopDataReplication(opCtx);
}
@@ -694,7 +728,7 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx,
// Do initial sync.
if (!_externalState->getTaskExecutor()) {
- log() << "not running initial sync during test.";
+ LOGV2(21323, "not running initial sync during test.");
return;
}
@@ -702,16 +736,20 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx,
{
stdx::lock_guard<Latch> lock(_mutex);
if (opTimeStatus == ErrorCodes::CallbackCanceled) {
- log() << "Initial Sync has been cancelled: " << opTimeStatus.getStatus();
+ LOGV2(21324,
+ "Initial Sync has been cancelled: {opTimeStatus_getStatus}",
+ "opTimeStatus_getStatus"_attr = opTimeStatus.getStatus());
return;
} else if (!opTimeStatus.isOK()) {
if (_inShutdown) {
- log() << "Initial Sync failed during shutdown due to "
- << opTimeStatus.getStatus();
+ LOGV2(21325,
+ "Initial Sync failed during shutdown due to {opTimeStatus_getStatus}",
+ "opTimeStatus_getStatus"_attr = opTimeStatus.getStatus());
return;
} else {
- error() << "Initial sync failed, shutting down now. Restart the server "
- "to attempt a new initial sync.";
+ LOGV2_ERROR(21416,
+ "Initial sync failed, shutting down now. Restart the server "
+ "to attempt a new initial sync.");
fassertFailedWithStatusNoTrace(40088, opTimeStatus.getStatus());
}
}
@@ -743,7 +781,7 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx,
// Must take the lock to set _initialSyncer, but not call it.
stdx::lock_guard<Latch> lock(_mutex);
if (_inShutdown) {
- log() << "Initial Sync not starting because replication is shutting down.";
+ LOGV2(21326, "Initial Sync not starting because replication is shutting down.");
return;
}
initialSyncerCopy = std::make_shared<InitialSyncer>(
@@ -761,7 +799,7 @@ void ReplicationCoordinatorImpl::_startDataReplication(OperationContext* opCtx,
uassertStatusOK(initialSyncerCopy->startup(opCtx, numInitialSyncAttempts.load()));
} catch (const DBException& e) {
auto status = e.toStatus();
- log() << "Initial Sync failed to start: " << status;
+ LOGV2(21327, "Initial Sync failed to start: {status}", "status"_attr = status);
if (ErrorCodes::CallbackCanceled == status || ErrorCodes::isShutdownError(status.code())) {
return;
}
@@ -853,7 +891,7 @@ void ReplicationCoordinatorImpl::shutdown(OperationContext* opCtx) {
return;
}
- log() << "shutting down replication subsystems";
+ LOGV2(21328, "shutting down replication subsystems");
// Used to shut down outside of the lock.
std::shared_ptr<InitialSyncer> initialSyncerCopy;
@@ -862,9 +900,10 @@ void ReplicationCoordinatorImpl::shutdown(OperationContext* opCtx) {
fassert(28533, !_inShutdown);
_inShutdown = true;
if (_rsConfigState == kConfigPreStart) {
- warning() << "ReplicationCoordinatorImpl::shutdown() called before "
- "startup() finished. Shutting down without cleaning up the "
- "replication system";
+ LOGV2_WARNING(21409,
+ "ReplicationCoordinatorImpl::shutdown() called before "
+ "startup() finished. Shutting down without cleaning up the "
+ "replication system");
return;
}
if (_rsConfigState == kConfigStartingUp) {
@@ -885,10 +924,11 @@ void ReplicationCoordinatorImpl::shutdown(OperationContext* opCtx) {
// joining the replication executor is blocking so it must be run outside of the mutex
if (initialSyncerCopy) {
- LOG(1) << "ReplicationCoordinatorImpl::shutdown calling InitialSyncer::shutdown.";
+ LOGV2_DEBUG(
+ 21329, 1, "ReplicationCoordinatorImpl::shutdown calling InitialSyncer::shutdown.");
const auto status = initialSyncerCopy->shutdown();
if (!status.isOK()) {
- warning() << "InitialSyncer shutdown failed: " << status;
+ LOGV2_WARNING(21410, "InitialSyncer shutdown failed: {status}", "status"_attr = status);
}
initialSyncerCopy->join();
initialSyncerCopy.reset();
@@ -1068,7 +1108,9 @@ void ReplicationCoordinatorImpl::signalDrainComplete(OperationContext* opCtx,
auto status = _topCoord->completeTransitionToPrimary(firstOpTime);
if (status.code() == ErrorCodes::PrimarySteppedDown) {
- log() << "Transition to primary failed" << causedBy(status);
+ LOGV2(21330,
+ "Transition to primary failed{causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
return;
}
invariant(status);
@@ -1082,7 +1124,9 @@ void ReplicationCoordinatorImpl::signalDrainComplete(OperationContext* opCtx,
// Update _canAcceptNonLocalWrites
_updateMemberStateFromTopologyCoordinator(lk, opCtx);
- log() << "transition to primary complete; database writes are now permitted" << rsLog;
+ LOGV2_OPTIONS(21331,
+ {logv2::LogTag::kRS},
+ "transition to primary complete; database writes are now permitted");
_drainFinishedCond.notify_all();
_externalState->startNoopWriter(_getMyLastAppliedOpTime_inlock());
}
@@ -1178,7 +1222,7 @@ void ReplicationCoordinatorImpl::resetMyLastOpTimes() {
}
void ReplicationCoordinatorImpl::_resetMyLastOpTimes(WithLock lk) {
- LOG(1) << "resetting durable/applied optimes.";
+ LOGV2_DEBUG(21332, 1, "resetting durable/applied optimes.");
// Reset to uninitialized OpTime
bool isRollbackAllowed = true;
_setMyLastAppliedOpTimeAndWallTime(
@@ -1411,8 +1455,14 @@ Status ReplicationCoordinatorImpl::_waitUntilOpTime(OperationContext* opCtx,
// We just need to wait for the opTime to catch up to what we need (not majority RC).
auto future = _opTimeWaiterList.add_inlock(targetOpTime);
- LOG(3) << "waitUntilOpTime: OpID " << opCtx->getOpID() << " is waiting for OpTime "
- << targetOpTime << " until " << deadline.value_or(opCtx->getDeadline());
+ LOGV2_DEBUG(21333,
+ 3,
+ "waitUntilOpTime: OpID {opCtx_getOpID} is waiting for OpTime "
+ "{targetOpTime} until {deadline_value_or_opCtx_getDeadline}",
+ "opCtx_getOpID"_attr = opCtx->getOpID(),
+ "targetOpTime"_attr = targetOpTime,
+ "deadline_value_or_opCtx_getDeadline"_attr =
+ deadline.value_or(opCtx->getDeadline()));
lock.unlock();
auto waitStatus = futureGetNoThrowWithDeadline(
@@ -1455,12 +1505,19 @@ Status ReplicationCoordinatorImpl::_waitUntilMajorityOpTime(mongo::OperationCont
stdx::unique_lock lock(_mutex);
- LOG(1) << "waitUntilOpTime: waiting for optime:" << targetOpTime
- << " to be in a snapshot -- current snapshot: "
- << _getCurrentCommittedSnapshotOpTime_inlock();
+ LOGV2_DEBUG(21334,
+ 1,
+ "waitUntilOpTime: waiting for optime:{targetOpTime} to be in a snapshot -- current "
+ "snapshot: {getCurrentCommittedSnapshotOpTime_inlock}",
+ "targetOpTime"_attr = targetOpTime,
+ "getCurrentCommittedSnapshotOpTime_inlock"_attr =
+ _getCurrentCommittedSnapshotOpTime_inlock());
- LOG(3) << "waitUntilOpTime: waiting for a new snapshot until "
- << deadline.value_or(opCtx->getDeadline());
+ LOGV2_DEBUG(
+ 21335,
+ 3,
+ "waitUntilOpTime: waiting for a new snapshot until {deadline_value_or_opCtx_getDeadline}",
+ "deadline_value_or_opCtx_getDeadline"_attr = deadline.value_or(opCtx->getDeadline()));
try {
auto ok = opCtx->waitForConditionOrInterruptUntil(
@@ -1484,7 +1541,10 @@ Status ReplicationCoordinatorImpl::_waitUntilMajorityOpTime(mongo::OperationCont
// _currentCommittedSnapshot, _getCurrentCommittedSnapshotOpTime_inlock() also returns
// default OpTime{}. Hence this branch only runs if _currentCommittedSnapshot actually
// exists.
- LOG(3) << "Got notified of new snapshot: " << _currentCommittedSnapshot->toString();
+ LOGV2_DEBUG(21336,
+ 3,
+ "Got notified of new snapshot: {currentCommittedSnapshot}",
+ "currentCommittedSnapshot"_attr = _currentCommittedSnapshot->toString());
}
return Status::OK();
}
@@ -1638,8 +1698,13 @@ bool ReplicationCoordinatorImpl::_doneWaitingForReplication_inlock(
// Wait for the "current" snapshot to advance to/past the opTime.
const auto haveSnapshot = _currentCommittedSnapshot->opTime >= opTime;
if (!haveSnapshot) {
- LOG(1) << "Required snapshot optime: " << opTime << " is not yet part of the "
- << "current 'committed' snapshot: " << _currentCommittedSnapshot->opTime;
+ LOGV2_DEBUG(21337,
+ 1,
+ "Required snapshot optime: {opTime} is not yet part of the current "
+ "'committed' snapshot: {currentCommittedSnapshot_opTime}",
+ "opTime"_attr = opTime,
+ "currentCommittedSnapshot_opTime"_attr =
+ _currentCommittedSnapshot->opTime);
return false;
}
@@ -1650,14 +1715,16 @@ bool ReplicationCoordinatorImpl::_doneWaitingForReplication_inlock(
// removed from storage.
if (auto dropOpTime = _externalState->getEarliestDropPendingOpTime()) {
if (*dropOpTime <= opTime) {
- LOG(1) << "Unable to satisfy the requested majority write concern at "
- "'committed' optime "
- << opTime
- << ". There are still drop pending collections (earliest drop optime: "
- << *dropOpTime
- << ") that have to be removed from storage before we can "
- "satisfy the write concern "
- << writeConcern.toBSON();
+ LOGV2_DEBUG(21338,
+ 1,
+ "Unable to satisfy the requested majority write concern at "
+ "'committed' optime {opTime}. There are still drop pending collections "
+ "(earliest drop optime: {dropOpTime}) that have to be removed from "
+ "storage before we can "
+ "satisfy the write concern {writeConcern}",
+ "opTime"_attr = opTime,
+ "dropOpTime"_attr = *dropOpTime,
+ "writeConcern"_attr = writeConcern.toBSON());
return false;
}
}
@@ -1717,9 +1784,13 @@ ReplicationCoordinator::StatusAndDuration ReplicationCoordinatorImpl::awaitRepli
if (getTestCommandsEnabled() && !status.isOK()) {
stdx::lock_guard lock(_mutex);
- log() << "Replication failed for write concern: " << writeConcern.toBSON()
- << ", waiting for optime: " << opTime << ", opID: " << opCtx->getOpID()
- << ", progress: " << _getReplicationProgress(lock);
+ LOGV2(21339,
+ "Replication failed for write concern: {writeConcern}, waiting for optime: {opTime}, "
+ "opID: {opCtx_getOpID}, progress: {getReplicationProgress_lock}",
+ "writeConcern"_attr = writeConcern.toBSON(),
+ "opTime"_attr = opTime,
+ "opCtx_getOpID"_attr = opCtx->getOpID(),
+ "getReplicationProgress_lock"_attr = _getReplicationProgress(lock));
}
return {std::move(status), duration_cast<Milliseconds>(timer.elapsed())};
}
@@ -1862,7 +1933,7 @@ void ReplicationCoordinatorImpl::updateAndLogStateTransitionMetrics(
bob.appendNumber("userOpsKilled", userOpsKilled.get());
bob.appendNumber("userOpsRunning", userOpsRunning.get());
- log() << "State transition ops metrics: " << bob.obj();
+ LOGV2(21340, "State transition ops metrics: {bob_obj}", "bob_obj"_attr = bob.obj());
}
std::shared_ptr<IsMasterResponse> ReplicationCoordinatorImpl::_makeIsMasterResponse(
@@ -1954,12 +2025,16 @@ std::shared_ptr<const IsMasterResponse> ReplicationCoordinatorImpl::awaitIsMaste
if (MONGO_unlikely(waitForIsMasterResponse.shouldFail())) {
// Used in tests that wait for this failpoint to be entered before triggering a topology
// change.
- log() << "waitForIsMasterResponse failpoint enabled.";
+ LOGV2(21341, "waitForIsMasterResponse failpoint enabled.");
}
// Wait for a topology change with timeout set to deadline.
- LOG(1) << "Waiting for an isMaster response from a topology change or until deadline: "
- << deadline.get() << ". Current TopologyVersion counter is " << topologyVersionCounter;
+ LOGV2_DEBUG(21342,
+ 1,
+ "Waiting for an isMaster response from a topology change or until deadline: "
+ "{deadline_get}. Current TopologyVersion counter is {topologyVersionCounter}",
+ "deadline_get"_attr = deadline.get(),
+ "topologyVersionCounter"_attr = topologyVersionCounter);
auto statusWithIsMaster =
futureGetNoThrowWithDeadline(opCtx, future, deadline.get(), opCtx->getTimeoutError());
auto status = statusWithIsMaster.getStatus();
@@ -2050,7 +2125,7 @@ void ReplicationCoordinatorImpl::AutoGetRstlForStepUpStepDown::_killOpThreadFn()
invariant(!cc().isFromUserConnection());
- log() << "Starting to kill user operations";
+ LOGV2(21343, "Starting to kill user operations");
auto uniqueOpCtx = cc().makeOperationContext();
OperationContext* opCtx = uniqueOpCtx.get();
@@ -2078,7 +2153,7 @@ void ReplicationCoordinatorImpl::AutoGetRstlForStepUpStepDown::_killOpThreadFn()
stdx::unique_lock<Latch> lock(_mutex);
if (_stopKillingOps.wait_for(
lock, Milliseconds(10).toSystemDuration(), [this] { return _killSignaled; })) {
- log() << "Stopped killing user operations";
+ LOGV2(21344, "Stopped killing user operations");
_replCord->updateAndLogStateTransitionMetrics(
_stateTransition, getUserOpsKilled(), getUserOpsRunning());
_killSignaled = false;
@@ -2189,9 +2264,10 @@ void ReplicationCoordinatorImpl::stepDown(OperationContext* opCtx,
lk.unlock();
if (MONGO_unlikely(stepdownHangBeforePerformingPostMemberStateUpdateActions.shouldFail())) {
- log() << "stepping down from primary - "
- "stepdownHangBeforePerformingPostMemberStateUpdateActions fail point enabled. "
- "Blocking until fail point is disabled.";
+ LOGV2(21345,
+ "stepping down from primary - "
+ "stepdownHangBeforePerformingPostMemberStateUpdateActions fail point enabled. "
+ "Blocking until fail point is disabled.");
while (MONGO_unlikely(
stepdownHangBeforePerformingPostMemberStateUpdateActions.shouldFail())) {
mongo::sleepsecs(1);
@@ -2313,31 +2389,41 @@ void ReplicationCoordinatorImpl::_performElectionHandoff() {
auto candidateIndex = _topCoord->chooseElectionHandoffCandidate();
if (candidateIndex < 0) {
- log() << "Could not find node to hand off election to.";
+ LOGV2(21346, "Could not find node to hand off election to.");
return;
}
auto target = _rsConfig.getMemberAt(candidateIndex).getHostAndPort();
executor::RemoteCommandRequest request(
target, "admin", BSON("replSetStepUp" << 1 << "skipDryRun" << true), nullptr);
- log() << "Handing off election to " << target;
+ LOGV2(21347, "Handing off election to {target}", "target"_attr = target);
auto callbackHandleSW = _replExecutor->scheduleRemoteCommand(
request, [target](const executor::TaskExecutor::RemoteCommandCallbackArgs& callbackData) {
auto status = callbackData.response.status;
if (status.isOK()) {
- LOG(1) << "replSetStepUp request to " << target << " succeeded with response -- "
- << callbackData.response.data;
+ LOGV2_DEBUG(21348,
+ 1,
+ "replSetStepUp request to {target} succeeded with response -- "
+ "{callbackData_response_data}",
+ "target"_attr = target,
+ "callbackData_response_data"_attr = callbackData.response.data);
} else {
- log() << "replSetStepUp request to " << target << " failed due to " << status;
+ LOGV2(21349,
+ "replSetStepUp request to {target} failed due to {status}",
+ "target"_attr = target,
+ "status"_attr = status);
}
});
auto callbackHandleStatus = callbackHandleSW.getStatus();
if (!callbackHandleStatus.isOK()) {
- error() << "Failed to schedule ReplSetStepUp request to " << target
- << " for election handoff: " << callbackHandleStatus;
+ LOGV2_ERROR(21417,
+ "Failed to schedule ReplSetStepUp request to {target} for election handoff: "
+ "{callbackHandleStatus}",
+ "target"_attr = target,
+ "callbackHandleStatus"_attr = callbackHandleStatus);
}
}
@@ -2643,18 +2729,24 @@ Status ReplicationCoordinatorImpl::setMaintenanceMode(bool activate) {
int curMaintenanceCalls = _topCoord->getMaintenanceCount();
if (activate) {
- log() << "going into maintenance mode with " << curMaintenanceCalls
- << " other maintenance mode tasks in progress" << rsLog;
+ LOGV2_OPTIONS(21350,
+ {logv2::LogTag::kRS},
+ "going into maintenance mode with {curMaintenanceCalls} other maintenance "
+ "mode tasks in progress",
+ "curMaintenanceCalls"_attr = curMaintenanceCalls);
_topCoord->adjustMaintenanceCountBy(1);
} else if (curMaintenanceCalls > 0) {
invariant(_topCoord->getRole() == TopologyCoordinator::Role::kFollower);
_topCoord->adjustMaintenanceCountBy(-1);
- log() << "leaving maintenance mode (" << curMaintenanceCalls - 1
- << " other maintenance mode tasks ongoing)" << rsLog;
+ LOGV2_OPTIONS(21351,
+ {logv2::LogTag::kRS},
+ "leaving maintenance mode ({curMaintenanceCalls_1} other maintenance mode "
+ "tasks ongoing)",
+ "curMaintenanceCalls_1"_attr = curMaintenanceCalls - 1);
} else {
- warning() << "Attempted to leave maintenance mode but it is not currently active";
+ LOGV2_WARNING(21411, "Attempted to leave maintenance mode but it is not currently active");
return Status(ErrorCodes::OperationFailed, "already out of maintenance mode");
}
@@ -2707,8 +2799,9 @@ Status ReplicationCoordinatorImpl::processReplSetFreeze(int secs, BSONObjBuilder
Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCtx,
const ReplSetReconfigArgs& args,
BSONObjBuilder* resultObj) {
- log() << "replSetReconfig admin command received from client; new config: "
- << args.newConfigObj;
+ LOGV2(21352,
+ "replSetReconfig admin command received from client; new config: {args_newConfigObj}",
+ "args_newConfigObj"_attr = args.newConfigObj);
stdx::unique_lock<Latch> lk(_mutex);
@@ -2732,7 +2825,9 @@ Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCt
"Cannot run replSetReconfig because the node is currently updating "
"its configuration");
default:
- severe() << "Unexpected _rsConfigState " << int(_rsConfigState);
+ LOGV2_FATAL(21432,
+ "Unexpected _rsConfigState {int_rsConfigState}",
+ "int_rsConfigState"_attr = int(_rsConfigState));
fassertFailed(18914);
}
@@ -2767,41 +2862,49 @@ Status ReplicationCoordinatorImpl::processReplSetReconfig(OperationContext* opCt
// field passed in through its args. Instead, use this node's term.
Status status = newConfig.initialize(newConfigObj, topCoordTerm, oldConfig.getReplicaSetId());
if (!status.isOK()) {
- error() << "replSetReconfig got " << status << " while parsing " << newConfigObj;
+ LOGV2_ERROR(21418,
+ "replSetReconfig got {status} while parsing {newConfigObj}",
+ "status"_attr = status,
+ "newConfigObj"_attr = newConfigObj);
return Status(ErrorCodes::InvalidReplicaSetConfig, status.reason());
}
if (newConfig.getReplSetName() != _settings.ourSetName()) {
str::stream errmsg;
errmsg << "Attempting to reconfigure a replica set with name " << newConfig.getReplSetName()
<< ", but command line reports " << _settings.ourSetName() << "; rejecting";
- error() << std::string(errmsg);
+ LOGV2_ERROR(21419, "{std_string_errmsg}", "std_string_errmsg"_attr = std::string(errmsg));
return Status(ErrorCodes::InvalidReplicaSetConfig, errmsg);
}
StatusWith<int> myIndex = validateConfigForReconfig(
_externalState.get(), oldConfig, newConfig, opCtx->getServiceContext(), args.force);
if (!myIndex.isOK()) {
- error() << "replSetReconfig got " << myIndex.getStatus() << " while validating "
- << newConfigObj;
+ LOGV2_ERROR(21420,
+ "replSetReconfig got {myIndex_getStatus} while validating {newConfigObj}",
+ "myIndex_getStatus"_attr = myIndex.getStatus(),
+ "newConfigObj"_attr = newConfigObj);
return Status(ErrorCodes::NewReplicaSetConfigurationIncompatible,
myIndex.getStatus().reason());
}
- log() << "replSetReconfig config object with " << newConfig.getNumMembers()
- << " members parses ok";
+ LOGV2(21353,
+ "replSetReconfig config object with {newConfig_getNumMembers} members parses ok",
+ "newConfig_getNumMembers"_attr = newConfig.getNumMembers());
if (!args.force) {
status = checkQuorumForReconfig(
_replExecutor.get(), newConfig, myIndex.getValue(), _topCoord->getTerm());
if (!status.isOK()) {
- error() << "replSetReconfig failed; " << status;
+ LOGV2_ERROR(21421, "replSetReconfig failed; {status}", "status"_attr = status);
return status;
}
}
status = _externalState->storeLocalConfigDocument(opCtx, newConfig.toBSON());
if (!status.isOK()) {
- error() << "replSetReconfig failed to store config document; " << status;
+ LOGV2_ERROR(21422,
+ "replSetReconfig failed to store config document; {status}",
+ "status"_attr = status);
return status;
}
@@ -2825,8 +2928,11 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx,
// we have already set our ReplicationCoordinatorImpl::_rsConfigState state to
// "kConfigReconfiguring" which prevents new elections from happening.
if (electionFinishedEvent) {
- LOG(2) << "Waiting for election to complete before finishing reconfig to config with "
- << newConfig.getConfigVersionAndTerm();
+ LOGV2_DEBUG(21354,
+ 2,
+ "Waiting for election to complete before finishing reconfig to config with "
+ "{newConfig_getConfigVersionAndTerm}",
+ "newConfig_getConfigVersionAndTerm"_attr = newConfig.getConfigVersionAndTerm());
// Wait for the election to complete and the node's Role to be set to follower.
_replExecutor->waitForEvent(electionFinishedEvent);
}
@@ -2844,7 +2950,7 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx,
lk.lock();
if (_topCoord->isSteppingDownUnconditionally()) {
invariant(opCtx->lockState()->isRSTLExclusive());
- log() << "stepping down from primary, because we received a new config";
+ LOGV2(21355, "stepping down from primary, because we received a new config");
// We need to release the mutex before yielding locks for prepared transactions, which
// might check out sessions, to avoid deadlocks with checked-out sessions accessing
// this mutex.
@@ -2892,7 +2998,7 @@ void ReplicationCoordinatorImpl::_finishReplSetReconfig(OperationContext* opCtx,
Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCtx,
const BSONObj& configObj,
BSONObjBuilder* resultObj) {
- log() << "replSetInitiate admin command received from client";
+ LOGV2(21356, "replSetInitiate admin command received from client");
const auto replEnabled = _settings.usingReplSets();
stdx::unique_lock<Latch> lk(_mutex);
@@ -2925,27 +3031,33 @@ Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCt
ReplSetConfig newConfig;
Status status = newConfig.initializeForInitiate(configObj);
if (!status.isOK()) {
- error() << "replSet initiate got " << status << " while parsing " << configObj;
+ LOGV2_ERROR(21423,
+ "replSet initiate got {status} while parsing {configObj}",
+ "status"_attr = status,
+ "configObj"_attr = configObj);
return Status(ErrorCodes::InvalidReplicaSetConfig, status.reason());
}
if (newConfig.getReplSetName() != _settings.ourSetName()) {
str::stream errmsg;
errmsg << "Attempting to initiate a replica set with name " << newConfig.getReplSetName()
<< ", but command line reports " << _settings.ourSetName() << "; rejecting";
- error() << std::string(errmsg);
+ LOGV2_ERROR(21424, "{std_string_errmsg}", "std_string_errmsg"_attr = std::string(errmsg));
return Status(ErrorCodes::InvalidReplicaSetConfig, errmsg);
}
StatusWith<int> myIndex =
validateConfigForInitiate(_externalState.get(), newConfig, opCtx->getServiceContext());
if (!myIndex.isOK()) {
- error() << "replSet initiate got " << myIndex.getStatus() << " while validating "
- << configObj;
+ LOGV2_ERROR(21425,
+ "replSet initiate got {myIndex_getStatus} while validating {configObj}",
+ "myIndex_getStatus"_attr = myIndex.getStatus(),
+ "configObj"_attr = configObj);
return Status(ErrorCodes::InvalidReplicaSetConfig, myIndex.getStatus().reason());
}
- log() << "replSetInitiate config object with " << newConfig.getNumMembers()
- << " members parses ok";
+ LOGV2(21357,
+ "replSetInitiate config object with {newConfig_getNumMembers} members parses ok",
+ "newConfig_getNumMembers"_attr = newConfig.getNumMembers());
// In pv1, the TopologyCoordinator has not set the term yet. It will be set to kInitialTerm if
// the initiate succeeds so we pass that here.
@@ -2953,14 +3065,15 @@ Status ReplicationCoordinatorImpl::processReplSetInitiate(OperationContext* opCt
_replExecutor.get(), newConfig, myIndex.getValue(), OpTime::kInitialTerm);
if (!status.isOK()) {
- error() << "replSetInitiate failed; " << status;
+ LOGV2_ERROR(21426, "replSetInitiate failed; {status}", "status"_attr = status);
return status;
}
status = _externalState->initializeReplSetStorage(opCtx, newConfig.toBSON());
if (!status.isOK()) {
- error() << "replSetInitiate failed to store config document or create the oplog; "
- << status;
+ LOGV2_ERROR(21427,
+ "replSetInitiate failed to store config document or create the oplog; {status}",
+ "status"_attr = status);
return status;
}
@@ -3177,7 +3290,11 @@ ReplicationCoordinatorImpl::_updateMemberStateFromTopologyCoordinator(WithLock l
_cancelPriorityTakeover_inlock();
}
- log() << "transition to " << newState << " from " << _memberState << rsLog;
+ LOGV2_OPTIONS(21358,
+ {logv2::LogTag::kRS},
+ "transition to {newState} from {memberState}",
+ "newState"_attr = newState,
+ "memberState"_attr = _memberState);
// Initializes the featureCompatibilityVersion to the latest value, because arbiters do not
// receive the replicated version. This is to avoid bugs like SERVER-32639.
if (newState.arbiter()) {
@@ -3219,7 +3336,9 @@ void ReplicationCoordinatorImpl::_performPostMemberStateUpdateAction(
_startElectSelfV1(StartElectionReasonEnum::kElectionTimeout);
break;
default:
- severe() << "Unknown post member state update action " << static_cast<int>(action);
+ LOGV2_FATAL(21433,
+ "Unknown post member state update action {static_cast_int_action}",
+ "static_cast_int_action"_attr = static_cast<int>(action));
fassertFailed(26010);
}
}
@@ -3249,7 +3368,7 @@ void ReplicationCoordinatorImpl::_onFollowerModeStateChange() {
}
void ReplicationCoordinatorImpl::CatchupState::start_inlock() {
- log() << "Entering primary catch-up mode.";
+ LOGV2(21359, "Entering primary catch-up mode.");
// Reset the number of catchup operations performed before starting catchup.
_numCatchUpOps = 0;
@@ -3264,7 +3383,7 @@ void ReplicationCoordinatorImpl::CatchupState::start_inlock() {
// When catchUpTimeoutMillis is 0, we skip doing catchup entirely.
if (catchupTimeout == ReplSetConfig::kCatchUpDisabled) {
- log() << "Skipping primary catchup since the catchup timeout is 0.";
+ LOGV2(21360, "Skipping primary catchup since the catchup timeout is 0.");
abort_inlock(PrimaryCatchUpConclusionReason::kSkipped);
return;
}
@@ -3279,7 +3398,7 @@ void ReplicationCoordinatorImpl::CatchupState::start_inlock() {
if (cbData.myHandle.isCanceled()) {
return;
}
- log() << "Catchup timed out after becoming primary.";
+ LOGV2(21361, "Catchup timed out after becoming primary.");
abort_inlock(PrimaryCatchUpConclusionReason::kTimedOut);
};
@@ -3292,7 +3411,7 @@ void ReplicationCoordinatorImpl::CatchupState::start_inlock() {
auto timeoutDate = _repl->_replExecutor->now() + catchupTimeout;
auto status = _repl->_replExecutor->scheduleWorkAt(timeoutDate, std::move(timeoutCB));
if (!status.isOK()) {
- log() << "Failed to schedule catchup timeout work.";
+ LOGV2(21362, "Failed to schedule catchup timeout work.");
abort_inlock(PrimaryCatchUpConclusionReason::kFailedWithError);
return;
}
@@ -3305,7 +3424,7 @@ void ReplicationCoordinatorImpl::CatchupState::abort_inlock(PrimaryCatchUpConclu
ReplicationMetrics::get(getGlobalServiceContext())
.incrementNumCatchUpsConcludedForReason(reason);
- log() << "Exited primary catch-up mode.";
+ LOGV2(21363, "Exited primary catch-up mode.");
// Clean up its own members.
if (_timeoutCbh) {
_repl->_replExecutor->cancel(_timeoutCbh);
@@ -3331,8 +3450,11 @@ void ReplicationCoordinatorImpl::CatchupState::signalHeartbeatUpdate_inlock() {
// We've caught up.
const auto myLastApplied = _repl->_getMyLastAppliedOpTime_inlock();
if (*targetOpTime <= myLastApplied) {
- log() << "Caught up to the latest optime known via heartbeats after becoming primary. "
- << "Target optime: " << *targetOpTime << ". My Last Applied: " << myLastApplied;
+ LOGV2(21364,
+ "Caught up to the latest optime known via heartbeats after becoming primary. Target "
+ "optime: {targetOpTime}. My Last Applied: {myLastApplied}",
+ "targetOpTime"_attr = *targetOpTime,
+ "myLastApplied"_attr = myLastApplied);
// Report the number of ops applied during catchup in replSetGetStatus once the primary is
// caught up.
ReplicationMetrics::get(getGlobalServiceContext()).setNumCatchUpOps(_numCatchUpOps);
@@ -3348,12 +3470,17 @@ void ReplicationCoordinatorImpl::CatchupState::signalHeartbeatUpdate_inlock() {
ReplicationMetrics::get(getGlobalServiceContext()).setTargetCatchupOpTime(_targetOpTime);
- log() << "Heartbeats updated catchup target optime to " << _targetOpTime;
- log() << "Latest known optime per replica set member:";
+ LOGV2(21365,
+ "Heartbeats updated catchup target optime to {targetOpTime}",
+ "targetOpTime"_attr = _targetOpTime);
+ LOGV2(21366, "Latest known optime per replica set member:");
auto opTimesPerMember = _repl->_topCoord->latestKnownOpTimeSinceHeartbeatRestartPerMember();
for (auto&& pair : opTimesPerMember) {
- log() << "Member ID: " << pair.first
- << ", latest known optime: " << (pair.second ? (*pair.second).toString() : "unknown");
+ LOGV2(21367,
+ "Member ID: {pair_first}, latest known optime: {pair_second_pair_second_unknown}",
+ "pair_first"_attr = pair.first,
+ "pair_second_pair_second_unknown"_attr =
+ (pair.second ? (*pair.second).toString() : "unknown"));
}
if (_waiter) {
@@ -3370,8 +3497,11 @@ void ReplicationCoordinatorImpl::CatchupState::signalHeartbeatUpdate_inlock() {
// Double check the target time since stepdown may signal us too.
const auto myLastApplied = _repl->_getMyLastAppliedOpTime_inlock();
if (_targetOpTime <= myLastApplied) {
- log() << "Caught up to the latest known optime successfully after becoming primary. "
- << "Target optime: " << _targetOpTime << ". My Last Applied: " << myLastApplied;
+ LOGV2(21368,
+ "Caught up to the latest known optime successfully after becoming primary. "
+ "Target optime: {targetOpTime}. My Last Applied: {myLastApplied}",
+ "targetOpTime"_attr = _targetOpTime,
+ "myLastApplied"_attr = myLastApplied);
// Report the number of ops applied during catchup in replSetGetStatus once the primary
// is caught up.
ReplicationMetrics::get(getGlobalServiceContext()).setNumCatchUpOps(_numCatchUpOps);
@@ -3442,21 +3572,32 @@ ReplicationCoordinatorImpl::_setCurrentRSConfig(WithLock lk,
if (storageEngine && !storageEngine->isDurable() &&
(newConfig.getWriteConcernMajorityShouldJournal() &&
(!oldConfig.isInitialized() || !oldConfig.getWriteConcernMajorityShouldJournal()))) {
- log() << startupWarningsLog;
- log() << "** WARNING: This replica set node is running without journaling enabled but the "
- << startupWarningsLog;
- log() << "** writeConcernMajorityJournalDefault option to the replica set config "
- << startupWarningsLog;
- log() << "** is set to true. The writeConcernMajorityJournalDefault "
- << startupWarningsLog;
- log() << "** option to the replica set config must be set to false "
- << startupWarningsLog;
- log() << "** or w:majority write concerns will never complete."
- << startupWarningsLog;
- log() << "** In addition, this node's memory consumption may increase until all"
- << startupWarningsLog;
- log() << "** available free RAM is exhausted." << startupWarningsLog;
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(21369, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 21370,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: This replica set node is running without journaling enabled but the ");
+ LOGV2_OPTIONS(
+ 21371,
+ {logv2::LogTag::kStartupWarnings},
+ "** writeConcernMajorityJournalDefault option to the replica set config ");
+ LOGV2_OPTIONS(21372,
+ {logv2::LogTag::kStartupWarnings},
+ "** is set to true. The writeConcernMajorityJournalDefault ");
+ LOGV2_OPTIONS(21373,
+ {logv2::LogTag::kStartupWarnings},
+ "** option to the replica set config must be set to false ");
+ LOGV2_OPTIONS(21374,
+ {logv2::LogTag::kStartupWarnings},
+ "** or w:majority write concerns will never complete.");
+ LOGV2_OPTIONS(
+ 21375,
+ {logv2::LogTag::kStartupWarnings},
+ "** In addition, this node's memory consumption may increase until all");
+ LOGV2_OPTIONS(21376,
+ {logv2::LogTag::kStartupWarnings},
+ "** available free RAM is exhausted.");
+ LOGV2_OPTIONS(21377, {logv2::LogTag::kStartupWarnings}, "");
}
// Warn if using the in-memory (ephemeral) storage engine with
@@ -3464,44 +3605,66 @@ ReplicationCoordinatorImpl::_setCurrentRSConfig(WithLock lk,
if (storageEngine && storageEngine->isEphemeral() &&
(newConfig.getWriteConcernMajorityShouldJournal() &&
(!oldConfig.isInitialized() || !oldConfig.getWriteConcernMajorityShouldJournal()))) {
- log() << startupWarningsLog;
- log() << "** WARNING: This replica set node is using in-memory (ephemeral) storage with the"
- << startupWarningsLog;
- log() << "** writeConcernMajorityJournalDefault option to the replica set config "
- << startupWarningsLog;
- log() << "** set to true. The writeConcernMajorityJournalDefault option to the "
- << startupWarningsLog;
- log() << "** replica set config must be set to false " << startupWarningsLog;
- log() << "** or w:majority write concerns will never complete."
- << startupWarningsLog;
- log() << "** In addition, this node's memory consumption may increase until all"
- << startupWarningsLog;
- log() << "** available free RAM is exhausted." << startupWarningsLog;
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(21378, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 21379,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: This replica set node is using in-memory (ephemeral) storage with the");
+ LOGV2_OPTIONS(
+ 21380,
+ {logv2::LogTag::kStartupWarnings},
+ "** writeConcernMajorityJournalDefault option to the replica set config ");
+ LOGV2_OPTIONS(
+ 21381,
+ {logv2::LogTag::kStartupWarnings},
+ "** set to true. The writeConcernMajorityJournalDefault option to the ");
+ LOGV2_OPTIONS(21382,
+ {logv2::LogTag::kStartupWarnings},
+ "** replica set config must be set to false ");
+ LOGV2_OPTIONS(21383,
+ {logv2::LogTag::kStartupWarnings},
+ "** or w:majority write concerns will never complete.");
+ LOGV2_OPTIONS(
+ 21384,
+ {logv2::LogTag::kStartupWarnings},
+ "** In addition, this node's memory consumption may increase until all");
+ LOGV2_OPTIONS(21385,
+ {logv2::LogTag::kStartupWarnings},
+ "** available free RAM is exhausted.");
+ LOGV2_OPTIONS(21386, {logv2::LogTag::kStartupWarnings}, "");
}
// Since the ReplSetConfig always has a WriteConcernOptions, the only way to know if it has been
// customized is if it's different to the implicit defaults of { w: 1, wtimeout: 0 }.
if (const auto& wc = newConfig.getDefaultWriteConcern();
!(wc.wNumNodes == 1 && wc.wTimeout == 0)) {
- log() << startupWarningsLog;
- log() << "** WARNING: Replica set config contains customized getLastErrorDefaults,"
- << startupWarningsLog;
- log() << "** which are deprecated. Use setDefaultRWConcern instead to set a"
- << startupWarningsLog;
- log() << "** cluster-wide default writeConcern." << startupWarningsLog;
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(21387, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(21388,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: Replica set config contains customized getLastErrorDefaults,");
+ LOGV2_OPTIONS(21389,
+ {logv2::LogTag::kStartupWarnings},
+ "** which are deprecated. Use setDefaultRWConcern instead to set a");
+ LOGV2_OPTIONS(21390,
+ {logv2::LogTag::kStartupWarnings},
+ "** cluster-wide default writeConcern.");
+ LOGV2_OPTIONS(21391, {logv2::LogTag::kStartupWarnings}, "");
}
const bool horizonsChanged = _haveHorizonsChanged(oldConfig, newConfig, _selfIndex, myIndex);
- log() << "New replica set config in use: " << _rsConfig.toBSON() << rsLog;
+ LOGV2_OPTIONS(21392,
+ {logv2::LogTag::kRS},
+ "New replica set config in use: {rsConfig}",
+ "rsConfig"_attr = _rsConfig.toBSON());
_selfIndex = myIndex;
if (_selfIndex >= 0) {
- log() << "This node is " << _rsConfig.getMemberAt(_selfIndex).getHostAndPort()
- << " in the config";
+ LOGV2(21393,
+ "This node is {rsConfig_getMemberAt_selfIndex_getHostAndPort} in the config",
+ "rsConfig_getMemberAt_selfIndex_getHostAndPort"_attr =
+ _rsConfig.getMemberAt(_selfIndex).getHostAndPort());
} else {
- log() << "This node is not a member of the config";
+ LOGV2(21394, "This node is not a member of the config");
}
if (horizonsChanged) {
@@ -3736,9 +3899,11 @@ void ReplicationCoordinatorImpl::resetLastOpTimesFromOplog(OperationContext* opC
auto lastOpTimeAndWallTimeStatus = _externalState->loadLastOpTimeAndWallTime(opCtx);
OpTimeAndWallTime lastOpTimeAndWallTime = {OpTime(), Date_t()};
if (!lastOpTimeAndWallTimeStatus.getStatus().isOK()) {
- warning() << "Failed to load timestamp and/or wall clock time of most recently applied "
- "operation; "
- << lastOpTimeAndWallTimeStatus.getStatus();
+ LOGV2_WARNING(21412,
+ "Failed to load timestamp and/or wall clock time of most recently applied "
+ "operation; {lastOpTimeAndWallTimeStatus_getStatus}",
+ "lastOpTimeAndWallTimeStatus_getStatus"_attr =
+ lastOpTimeAndWallTimeStatus.getStatus());
} else {
lastOpTimeAndWallTime = lastOpTimeAndWallTimeStatus.getValue();
}
@@ -3899,7 +4064,7 @@ MONGO_FAIL_POINT_DEFINE(disableSnapshotting);
void ReplicationCoordinatorImpl::_setStableTimestampForStorage(WithLock lk) {
if (!_shouldSetStableTimestamp) {
- LOG(2) << "Not setting stable timestamp for storage.";
+ LOGV2_DEBUG(21395, 2, "Not setting stable timestamp for storage.");
return;
}
// Get the current stable optime.
@@ -3908,7 +4073,10 @@ void ReplicationCoordinatorImpl::_setStableTimestampForStorage(WithLock lk) {
// If there is a valid stable optime, set it for the storage engine, and then remove any
// old, unneeded stable optime candidates.
if (stableOpTime) {
- LOG(2) << "Setting replication's stable optime to " << stableOpTime.value();
+ LOGV2_DEBUG(21396,
+ 2,
+ "Setting replication's stable optime to {stableOpTime_value}",
+ "stableOpTime_value"_attr = stableOpTime.value());
if (!gTestingSnapshotBehaviorInIsolation) {
// Update committed snapshot and wake up any threads waiting on read concern or
@@ -3962,15 +4130,17 @@ void ReplicationCoordinatorImpl::finishRecoveryIfEligible(OperationContext* opCt
// We can only transition to SECONDARY from RECOVERING state.
MemberState state(getMemberState());
if (!state.recovering()) {
- LOG(2) << "We cannot transition to SECONDARY state since we are not currently in "
- "RECOVERING state. Current state: "
- << state.toString();
+ LOGV2_DEBUG(21397,
+ 2,
+ "We cannot transition to SECONDARY state since we are not currently in "
+ "RECOVERING state. Current state: {state}",
+ "state"_attr = state.toString());
return;
}
// Maintenance mode will force us to remain in RECOVERING state, no matter what.
if (getMaintenanceMode()) {
- LOG(1) << "We cannot transition to SECONDARY state while in maintenance mode.";
+ LOGV2_DEBUG(21398, 1, "We cannot transition to SECONDARY state while in maintenance mode.");
return;
}
@@ -3980,17 +4150,26 @@ void ReplicationCoordinatorImpl::finishRecoveryIfEligible(OperationContext* opCt
auto lastApplied = getMyLastAppliedOpTime();
auto minValid = _replicationProcess->getConsistencyMarkers()->getMinValid(opCtx);
if (lastApplied < minValid) {
- LOG(2) << "We cannot transition to SECONDARY state because our 'lastApplied' optime"
- " is less than the 'minValid' optime. minValid optime: "
- << minValid << ", lastApplied optime: " << lastApplied;
+ LOGV2_DEBUG(21399,
+ 2,
+ "We cannot transition to SECONDARY state because our 'lastApplied' optime"
+ " is less than the 'minValid' optime. minValid optime: {minValid}, lastApplied "
+ "optime: {lastApplied}",
+ "minValid"_attr = minValid,
+ "lastApplied"_attr = lastApplied);
return;
}
// Execute the transition to SECONDARY.
auto status = setFollowerMode(MemberState::RS_SECONDARY);
if (!status.isOK()) {
- warning() << "Failed to transition into " << MemberState(MemberState::RS_SECONDARY)
- << ". Current state: " << getMemberState() << causedBy(status);
+ LOGV2_WARNING(21413,
+ "Failed to transition into {MemberState_MemberState_RS_SECONDARY}. Current "
+ "state: {getMemberState}{causedBy_status}",
+ "MemberState_MemberState_RS_SECONDARY"_attr =
+ MemberState(MemberState::RS_SECONDARY),
+ "getMemberState"_attr = getMemberState(),
+ "causedBy_status"_attr = causedBy(status));
}
}
@@ -4057,7 +4236,9 @@ Status ReplicationCoordinatorImpl::processReplSetRequestVotes(
if (votedForCandidate) {
Status status = _externalState->storeLocalLastVoteDocument(opCtx, lastVote);
if (!status.isOK()) {
- error() << "replSetRequestVotes failed to store LastVote document; " << status;
+ LOGV2_ERROR(21428,
+ "replSetRequestVotes failed to store LastVote document; {status}",
+ "status"_attr = status);
return status;
}
}
@@ -4160,8 +4341,10 @@ Status ReplicationCoordinatorImpl::processHeartbeatV1(const ReplSetHeartbeatArgs
// a configuration that contains us. Chances are excellent that it will, since that
// is the only reason for a remote node to send this node a heartbeat request.
if (!senderHost.empty() && _seedList.insert(senderHost).second) {
- log() << "Scheduling heartbeat to fetch a new config from: " << senderHost
- << " since we are not a member of our current config.";
+ LOGV2(21400,
+ "Scheduling heartbeat to fetch a new config from: {senderHost} since we are not "
+ "a member of our current config.",
+ "senderHost"_attr = senderHost);
_scheduleHeartbeatToTarget_inlock(senderHost, -1, now);
}
} else if (result.isOK() &&
@@ -4171,9 +4354,12 @@ Status ReplicationCoordinatorImpl::processHeartbeatV1(const ReplSetHeartbeatArgs
// We cannot cancel the enqueued heartbeat, but either this one or the enqueued heartbeat
// will trigger reconfig, which cancels and reschedules all heartbeats.
if (args.hasSender()) {
- log() << "Scheduling heartbeat to fetch a newer config with term "
- << args.getConfigTerm() << " and version " << args.getConfigVersion()
- << " from member: " << senderHost;
+ LOGV2(21401,
+ "Scheduling heartbeat to fetch a newer config with term {args_getConfigTerm} and "
+ "version {args_getConfigVersion} from member: {senderHost}",
+ "args_getConfigTerm"_attr = args.getConfigTerm(),
+ "args_getConfigVersion"_attr = args.getConfigVersion(),
+ "senderHost"_attr = senderHost);
int senderIndex = _rsConfig.findMemberIndexByHostAndPort(senderHost);
_scheduleHeartbeatToTarget_inlock(senderHost, senderIndex, now);
}
@@ -4251,12 +4437,16 @@ EventHandle ReplicationCoordinatorImpl::_updateTerm_inlock(
_pendingTermUpdateDuringStepDown = term;
}
if (_topCoord->prepareForUnconditionalStepDown()) {
- log() << "stepping down from primary, because a new term has begun: " << term;
+ LOGV2(21402,
+ "stepping down from primary, because a new term has begun: {term}",
+ "term"_attr = term);
ReplicationMetrics::get(getServiceContext()).incrementNumStepDownsCausedByHigherTerm();
return _stepDownStart();
} else {
- LOG(2) << "Updated term but not triggering stepdown because we are already in the "
- "process of stepping down";
+ LOGV2_DEBUG(21403,
+ 2,
+ "Updated term but not triggering stepdown because we are already in the "
+ "process of stepping down");
}
}
return EventHandle();
@@ -4314,7 +4504,7 @@ bool ReplicationCoordinatorImpl::_updateCommittedSnapshot(
// If we are in ROLLBACK state, do not set any new _currentCommittedSnapshot, as it will be
// cleared at the end of rollback anyway.
if (_memberState.rollback()) {
- log() << "Not updating committed snapshot because we are in rollback";
+ LOGV2(21404, "Not updating committed snapshot because we are in rollback");
return false;
}
invariant(!newCommittedSnapshot.opTime.isNull());
diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp
index 6d44c96bc0e..61910c41c1e 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/repl/replication_metrics.h"
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/db/repl/vote_requester.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -55,7 +56,9 @@ public:
if (_dismissed) {
return;
}
- log() << "Lost " << (_isDryRun ? "dry run " : "") << "election due to internal error";
+ LOGV2(21434,
+ "Lost {isDryRun_dry_run}election due to internal error",
+ "isDryRun_dry_run"_attr = (_isDryRun ? "dry run " : ""));
_replCoord->_topCoord->processLoseElection();
_replCoord->_voteRequester.reset(nullptr);
if (_isDryRun && _replCoord->_electionDryRunFinishedEvent.isValid()) {
@@ -105,13 +108,15 @@ void ReplicationCoordinatorImpl::_startElectSelfV1_inlock(StartElectionReasonEnu
case kConfigInitiating:
case kConfigReconfiguring:
case kConfigHBReconfiguring:
- LOG(2) << "Not standing for election; processing a configuration change";
+ LOGV2_DEBUG(21435, 2, "Not standing for election; processing a configuration change");
// Transition out of candidate role.
_topCoord->processLoseElection();
return;
default:
- severe() << "Entered replica set election code while in illegal config state "
- << int(_rsConfigState);
+ LOGV2_FATAL(21452,
+ "Entered replica set election code while in illegal config state "
+ "{int_rsConfigState}",
+ "int_rsConfigState"_attr = int(_rsConfigState));
fassertFailed(28641);
}
@@ -134,8 +139,9 @@ void ReplicationCoordinatorImpl::_startElectSelfV1_inlock(StartElectionReasonEnu
const auto lastOpTime = _getMyLastAppliedOpTime_inlock();
if (lastOpTime == OpTime()) {
- log() << "not trying to elect self, "
- "do not yet have a complete set of data from any point in time";
+ LOGV2(21436,
+ "not trying to elect self, "
+ "do not yet have a complete set of data from any point in time");
return;
}
@@ -144,13 +150,17 @@ void ReplicationCoordinatorImpl::_startElectSelfV1_inlock(StartElectionReasonEnu
if (reason == StartElectionReasonEnum::kStepUpRequestSkipDryRun) {
long long newTerm = term + 1;
- log() << "skipping dry run and running for election in term " << newTerm;
+ LOGV2(21437,
+ "skipping dry run and running for election in term {newTerm}",
+ "newTerm"_attr = newTerm);
_startRealElection_inlock(newTerm, reason);
lossGuard.dismiss();
return;
}
- log() << "conducting a dry run election to see if we could be elected. current term: " << term;
+ LOGV2(21438,
+ "conducting a dry run election to see if we could be elected. current term: {term}",
+ "term"_attr = term);
_voteRequester.reset(new VoteRequester);
// Only set primaryIndex if the primary's vote is required during the dry run.
@@ -186,29 +196,34 @@ void ReplicationCoordinatorImpl::_processDryRunResult(long long originalTerm,
invariant(_voteRequester);
if (_topCoord->getTerm() != originalTerm) {
- log() << "not running for primary, we have been superseded already during dry run. "
- << "original term: " << originalTerm << ", current term: " << _topCoord->getTerm();
+ LOGV2(21439,
+ "not running for primary, we have been superseded already during dry run. original "
+ "term: {originalTerm}, current term: {topCoord_getTerm}",
+ "originalTerm"_attr = originalTerm,
+ "topCoord_getTerm"_attr = _topCoord->getTerm());
return;
}
const VoteRequester::Result endResult = _voteRequester->getResult();
if (endResult == VoteRequester::Result::kInsufficientVotes) {
- log() << "not running for primary, we received insufficient votes";
+ LOGV2(21440, "not running for primary, we received insufficient votes");
return;
} else if (endResult == VoteRequester::Result::kStaleTerm) {
- log() << "not running for primary, we have been superseded already";
+ LOGV2(21441, "not running for primary, we have been superseded already");
return;
} else if (endResult == VoteRequester::Result::kPrimaryRespondedNo) {
- log() << "not running for primary, the current primary responded no in the dry run";
+ LOGV2(21442, "not running for primary, the current primary responded no in the dry run");
return;
} else if (endResult != VoteRequester::Result::kSuccessfullyElected) {
- log() << "not running for primary, we received an unexpected problem";
+ LOGV2(21443, "not running for primary, we received an unexpected problem");
return;
}
long long newTerm = originalTerm + 1;
- log() << "dry election run succeeded, running for election in term " << newTerm;
+ LOGV2(21444,
+ "dry election run succeeded, running for election in term {newTerm}",
+ "newTerm"_attr = newTerm);
_startRealElection_inlock(newTerm, reason);
lossGuard.dismiss();
@@ -291,14 +306,18 @@ void ReplicationCoordinatorImpl::_writeLastVoteForMyElection(
}
if (!status.isOK()) {
- log() << "failed to store LastVote document when voting for myself: " << status;
+ LOGV2(21445,
+ "failed to store LastVote document when voting for myself: {status}",
+ "status"_attr = status);
return;
}
if (_topCoord->getTerm() != lastVote.getTerm()) {
- log() << "not running for primary, we have been superseded already while writing our last "
- "vote. election term: "
- << lastVote.getTerm() << ", current term: " << _topCoord->getTerm();
+ LOGV2(21446,
+ "not running for primary, we have been superseded already while writing our last "
+ "vote. election term: {lastVote_getTerm}, current term: {topCoord_getTerm}",
+ "lastVote_getTerm"_attr = lastVote.getTerm(),
+ "topCoord_getTerm"_attr = _topCoord->getTerm());
return;
}
_startVoteRequester_inlock(lastVote.getTerm(), reason);
@@ -336,8 +355,11 @@ void ReplicationCoordinatorImpl::_onVoteRequestComplete(long long newTerm,
invariant(_voteRequester);
if (_topCoord->getTerm() != newTerm) {
- log() << "not becoming primary, we have been superseded already during election. "
- << "election term: " << newTerm << ", current term: " << _topCoord->getTerm();
+ LOGV2(21447,
+ "not becoming primary, we have been superseded already during election. election "
+ "term: {newTerm}, current term: {topCoord_getTerm}",
+ "newTerm"_attr = newTerm,
+ "topCoord_getTerm"_attr = _topCoord->getTerm());
return;
}
@@ -346,13 +368,15 @@ void ReplicationCoordinatorImpl::_onVoteRequestComplete(long long newTerm,
switch (endResult) {
case VoteRequester::Result::kInsufficientVotes:
- log() << "not becoming primary, we received insufficient votes";
+ LOGV2(21448, "not becoming primary, we received insufficient votes");
return;
case VoteRequester::Result::kStaleTerm:
- log() << "not becoming primary, we have been superseded already";
+ LOGV2(21449, "not becoming primary, we have been superseded already");
return;
case VoteRequester::Result::kSuccessfullyElected:
- log() << "election succeeded, assuming primary role in term " << _topCoord->getTerm();
+ LOGV2(21450,
+ "election succeeded, assuming primary role in term {topCoord_getTerm}",
+ "topCoord_getTerm"_attr = _topCoord->getTerm());
ReplicationMetrics::get(getServiceContext())
.incrementNumElectionsSuccessfulForReason(reason);
break;
@@ -372,9 +396,10 @@ void ReplicationCoordinatorImpl::_onVoteRequestComplete(long long newTerm,
electionHangsBeforeUpdateMemberState.execute([&](const BSONObj& customWait) {
auto waitForMillis = Milliseconds(customWait["waitForMillis"].numberInt());
- log() << "election succeeded - electionHangsBeforeUpdateMemberState fail point "
- "enabled, sleeping "
- << waitForMillis;
+ LOGV2(21451,
+ "election succeeded - electionHangsBeforeUpdateMemberState fail point "
+ "enabled, sleeping {waitForMillis}",
+ "waitForMillis"_attr = waitForMillis);
sleepFor(waitForMillis);
});
diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
index bb44ed0bcd4..59db90faba0 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_elect_v1_test.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/repl/replication_metrics.h"
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/executor/network_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -129,7 +130,9 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyElectableNode) {
auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21453,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
NetworkInterfaceMock* net = getNet();
net->enterNetwork();
@@ -140,8 +143,10 @@ TEST_F(ReplCoordTest, ElectionSucceedsWhenNodeIsTheOnlyElectableNode) {
}
auto noi = net->getNextReadyRequest();
const auto& request = noi->getRequest();
- error() << "Black holing irrelevant request to " << request.target << ": "
- << request.cmdObj;
+ LOGV2_ERROR(21473,
+ "Black holing irrelevant request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
}
net->exitNetwork();
@@ -354,7 +359,9 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringDryRun)
auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21454,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
int voteRequests = 0;
NetworkInterfaceMock* net = getNet();
@@ -366,7 +373,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringDryRun)
ASSERT_TRUE(net->hasReadyRequests());
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21455,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (consumeHeartbeatV1(noi)) {
// The heartbeat has been consumed.
} else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") {
@@ -423,7 +433,9 @@ TEST_F(ReplCoordTest, ElectionFailsWhenDryRunResponseContainsANewerTerm) {
auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21456,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
int voteRequests = 0;
NetworkInterfaceMock* net = getNet();
@@ -435,7 +447,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenDryRunResponseContainsANewerTerm) {
ASSERT_TRUE(net->hasReadyRequests());
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21457,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (consumeHeartbeatV1(noi)) {
// The heartbeat has been consumed.
} else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") {
@@ -529,7 +544,10 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) {
for (int i = 0; i < 2; ++i) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21458,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
ReplSetHeartbeatArgsV1 hbArgs;
if (hbArgs.initialize(request.cmdObj).isOK()) {
ReplSetHeartbeatResponse hbResp;
@@ -543,8 +561,10 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) {
BSONObjBuilder respObj;
net->scheduleResponse(noi, net->now(), makeResponseStatus(hbResp.toBSON()));
} else {
- error() << "Black holing unexpected request to " << request.target << ": "
- << request.cmdObj;
+ LOGV2_ERROR(21474,
+ "Black holing unexpected request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
}
net->runReadyNetworkOperations();
@@ -554,7 +574,9 @@ TEST_F(ReplCoordTest, NodeWillNotStandForElectionDuringHeartbeatReconfig) {
// Advance the simulator clock sufficiently to trigger an election.
auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21459,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
net->enterNetwork();
while (net->now() < electionTimeoutWhen) {
@@ -607,7 +629,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenInsufficientVotesAreReceivedDuringRequest
while (net->hasReadyRequests()) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21460,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") {
net->blackHole(noi);
} else {
@@ -700,7 +725,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenVoteRequestResponseContainsANewerTerm) {
while (net->hasReadyRequests()) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21461,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") {
net->blackHole(noi);
} else {
@@ -796,7 +824,10 @@ TEST_F(ReplCoordTest, ElectionFailsWhenTermChangesDuringActualElection) {
while (net->hasReadyRequests()) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21462,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") {
net->blackHole(noi);
} else {
@@ -941,7 +972,11 @@ private:
noi = net->getNextReadyRequest();
auto&& request = noi->getRequest();
- log() << request.target << " processing " << request.cmdObj << " at " << net->now();
+ LOGV2(21463,
+ "{request_target} processing {request_cmdObj} at {net_now}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj,
+ "net_now"_attr = net->now());
// Make sure the heartbeat request is valid.
ReplSetHeartbeatArgsV1 hbArgs;
@@ -1549,10 +1584,16 @@ TEST_F(TakeoverTest, CatchupTakeoverDryRunFailsPrimarySaysNo) {
NetworkInterfaceMock::NetworkOperationIterator noi_primary;
Date_t until = net->now() + Seconds(1);
while (voteRequests < votesExpected) {
- unittest::log() << "request: " << voteRequests << " expected: " << votesExpected;
+ LOGV2(21464,
+ "request: {voteRequests} expected: {votesExpected}",
+ "voteRequests"_attr = voteRequests,
+ "votesExpected"_attr = votesExpected);
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21465,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (request.cmdObj.firstElement().fieldNameStringData() != "replSetRequestVotes") {
net->blackHole(noi);
} else {
@@ -2125,13 +2166,17 @@ protected:
auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21466,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
ASSERT(replCoord->getMemberState().secondary()) << replCoord->getMemberState().toString();
// Process requests until we're primary but leave the heartbeats for the notification
// of election win. Exit immediately on unexpected requests.
while (!replCoord->getMemberState().primary()) {
- log() << "Waiting on network in state " << replCoord->getMemberState();
+ LOGV2(21467,
+ "Waiting on network in state {replCoord_getMemberState}",
+ "replCoord_getMemberState"_attr = replCoord->getMemberState());
net->enterNetwork();
if (net->now() < electionTimeoutWhen) {
net->runUntil(electionTimeoutWhen);
@@ -2139,7 +2184,10 @@ protected:
// Peek the next request, don't consume it yet.
const NetworkOpIter noi = net->getFrontOfUnscheduledQueue();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21468,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (ReplSetHeartbeatArgsV1().initialize(request.cmdObj).isOK()) {
OpTime opTime(Timestamp(), getReplCoord()->getTerm());
net->scheduleResponse(
@@ -2204,13 +2252,18 @@ protected:
while (net->hasReadyRequests()) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing heartbeat " << request.cmdObj
- << " at " << net->now();
+ LOGV2(21469,
+ "{request_target} processing heartbeat {request_cmdObj} at {net_now}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj,
+ "net_now"_attr = net->now());
if (ReplSetHeartbeatArgsV1().initialize(request.cmdObj).isOK()) {
onHeartbeatRequest(noi);
} else {
- log() << "Black holing unexpected request to " << request.target << ": "
- << request.cmdObj;
+ LOGV2(21470,
+ "Black holing unexpected request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
}
net->runReadyNetworkOperations();
@@ -2227,7 +2280,11 @@ protected:
// Peek the next request
auto noi = net->getFrontOfUnscheduledQueue();
auto& request = noi->getRequest();
- log() << request.target << " at " << net->now() << " processing " << request.cmdObj;
+ LOGV2(21471,
+ "{request_target} at {net_now} processing {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "net_now"_attr = net->now(),
+ "request_cmdObj"_attr = request.cmdObj);
if (ReplSetHeartbeatArgsV1().initialize(request.cmdObj).isOK()) {
// Consume the next request
onHeartbeatRequest(net->getNextReadyRequest());
@@ -2434,7 +2491,9 @@ TEST_F(PrimaryCatchUpTest, HeartbeatTimeout) {
replyHeartbeatsAndRunUntil(catchupTimeoutTime, [this, time1](const NetworkOpIter noi) {
const RemoteCommandRequest& request = noi->getRequest();
if (request.target.host() == "node2") {
- log() << "Black holing heartbeat from " << request.target.host();
+ LOGV2(21472,
+ "Black holing heartbeat from {request_target_host}",
+ "request_target_host"_attr = request.target.host());
getNet()->blackHole(noi);
} else {
getNet()->scheduleResponse(noi, getNet()->now(), makeHeartbeatResponse(time1));
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
index db9d264aa16..3b928f80df0 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/db/repl/vote_requester.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
@@ -274,11 +275,13 @@ stdx::unique_lock<Latch> ReplicationCoordinatorImpl::_handleHeartbeatResponseAct
case HeartbeatResponseAction::StepDownSelf:
invariant(action.getPrimaryConfigIndex() == _selfIndex);
if (_topCoord->prepareForUnconditionalStepDown()) {
- log() << "Stepping down from primary in response to heartbeat";
+ LOGV2(21475, "Stepping down from primary in response to heartbeat");
_stepDownStart();
} else {
- LOG(2) << "Heartbeat would have triggered a stepdown, but we're already in the "
- "process of stepping down";
+ LOGV2_DEBUG(21476,
+ 2,
+ "Heartbeat would have triggered a stepdown, but we're already in the "
+ "process of stepping down");
}
break;
case HeartbeatResponseAction::PriorityTakeover: {
@@ -325,11 +328,18 @@ void remoteStepdownCallback(const executor::TaskExecutor::RemoteCommandCallbackA
}
if (status.isOK()) {
- LOG(1) << "stepdown of primary(" << cbData.request.target << ") succeeded with response -- "
- << cbData.response.data;
+ LOGV2_DEBUG(21477,
+ 1,
+ "stepdown of primary({cbData_request_target}) succeeded with response -- "
+ "{cbData_response_data}",
+ "cbData_request_target"_attr = cbData.request.target,
+ "cbData_response_data"_attr = cbData.response.data);
} else {
- warning() << "stepdown of primary(" << cbData.request.target << ") failed due to "
- << cbData.response.status;
+ LOGV2_WARNING(
+ 21486,
+ "stepdown of primary({cbData_request_target}) failed due to {cbData_response_status}",
+ "cbData_request_target"_attr = cbData.request.target,
+ "cbData_response_status"_attr = cbData.response.status);
}
}
} // namespace
@@ -344,7 +354,7 @@ void ReplicationCoordinatorImpl::_requestRemotePrimaryStepdown(const HostAndPort
20LL)),
nullptr);
- log() << "Requesting " << target << " step down from primary";
+ LOGV2(21478, "Requesting {target} step down from primary", "target"_attr = target);
auto cbh = _replExecutor->scheduleRemoteCommand(request, remoteStepdownCallback);
if (cbh.getStatus() != ErrorCodes::ShutdownInProgress) {
fassert(18808, cbh.getStatus());
@@ -375,8 +385,9 @@ void ReplicationCoordinatorImpl::_stepDownFinish(
if (MONGO_unlikely(blockHeartbeatStepdown.shouldFail())) {
// This log output is used in js tests so please leave it.
- log() << "stepDown - blockHeartbeatStepdown fail point enabled. "
- "Blocking until fail point is disabled.";
+ LOGV2(21479,
+ "stepDown - blockHeartbeatStepdown fail point enabled. "
+ "Blocking until fail point is disabled.");
auto inShutdown = [&] {
stdx::lock_guard<Latch> lk(_mutex);
@@ -458,8 +469,10 @@ void ReplicationCoordinatorImpl::_scheduleHeartbeatReconfig_inlock(const ReplSet
case kConfigPreStart:
case kConfigStartingUp:
case kConfigReplicationDisabled:
- severe() << "Reconfiguration request occurred while _rsConfigState == "
- << int(_rsConfigState) << "; aborting.";
+ LOGV2_FATAL(21491,
+ "Reconfiguration request occurred while _rsConfigState == "
+ "{int_rsConfigState}; aborting.",
+ "int_rsConfigState"_attr = int(_rsConfigState));
fassertFailed(18807);
}
_setConfigState_inlock(kConfigHBReconfiguring);
@@ -489,8 +502,10 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore(
const executor::TaskExecutor::CallbackArgs& cbd, const ReplSetConfig& newConfig) {
if (cbd.status.code() == ErrorCodes::CallbackCanceled) {
- log() << "The callback to persist the replica set configuration was canceled - "
- << "the configuration was not persisted but was used: " << newConfig.toBSON();
+ LOGV2(21480,
+ "The callback to persist the replica set configuration was canceled - the "
+ "configuration was not persisted but was used: {newConfig}",
+ "newConfig"_attr = newConfig.toBSON());
return;
}
@@ -513,9 +528,10 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore(
bool shouldStartDataReplication = false;
if (!myIndex.getStatus().isOK() && myIndex.getStatus() != ErrorCodes::NodeNotFound) {
- warning() << "Not persisting new configuration in heartbeat response to disk because "
- "it is invalid: "
- << myIndex.getStatus();
+ LOGV2_WARNING(21487,
+ "Not persisting new configuration in heartbeat response to disk because "
+ "it is invalid: {myIndex_getStatus}",
+ "myIndex_getStatus"_attr = myIndex.getStatus());
} else {
LOG_FOR_HEARTBEATS(2) << "Config with " << newConfig.getConfigVersionAndTerm()
<< " validated for reconfig; persisting to disk.";
@@ -527,9 +543,10 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigStore(
stdx::lock_guard<Latch> lk(_mutex);
isFirstConfig = !_rsConfig.isInitialized();
if (!status.isOK()) {
- error() << "Ignoring new configuration in heartbeat response because we failed to"
- " write it to stable storage; "
- << status;
+ LOGV2_ERROR(21488,
+ "Ignoring new configuration in heartbeat response because we failed to"
+ " write it to stable storage; {status}",
+ "status"_attr = status);
invariant(_rsConfigState == kConfigHBReconfiguring);
if (isFirstConfig) {
_setConfigState_inlock(kConfigUninitialized);
@@ -626,7 +643,8 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigFinish(
lk.lock();
if (_topCoord->isSteppingDownUnconditionally()) {
invariant(opCtx->lockState()->isRSTLExclusive());
- log() << "stepping down from primary, because we received a new config via heartbeat";
+ LOGV2(21481,
+ "stepping down from primary, because we received a new config via heartbeat");
// We need to release the mutex before yielding locks for prepared transactions, which
// might check out sessions, to avoid deadlocks with checked-out sessions accessing
// this mutex.
@@ -655,18 +673,24 @@ void ReplicationCoordinatorImpl::_heartbeatReconfigFinish(
if (!myIndex.isOK()) {
switch (myIndex.getStatus().code()) {
case ErrorCodes::NodeNotFound:
- log() << "Cannot find self in new replica set configuration; I must be removed; "
- << myIndex.getStatus();
+ LOGV2(21482,
+ "Cannot find self in new replica set configuration; I must be removed; "
+ "{myIndex_getStatus}",
+ "myIndex_getStatus"_attr = myIndex.getStatus());
break;
case ErrorCodes::InvalidReplicaSetConfig:
- error() << "Several entries in new config represent this node; "
- "Removing self until an acceptable configuration arrives; "
- << myIndex.getStatus();
+ LOGV2_ERROR(
+ 21489,
+ "Several entries in new config represent this node; "
+ "Removing self until an acceptable configuration arrives; {myIndex_getStatus}",
+ "myIndex_getStatus"_attr = myIndex.getStatus());
break;
default:
- error() << "Could not validate configuration received from remote node; "
- "Removing self until an acceptable configuration arrives; "
- << myIndex.getStatus();
+ LOGV2_ERROR(
+ 21490,
+ "Could not validate configuration received from remote node; "
+ "Removing self until an acceptable configuration arrives; {myIndex_getStatus}",
+ "myIndex_getStatus"_attr = myIndex.getStatus());
break;
}
myIndex = StatusWith<int>(-1);
@@ -778,7 +802,8 @@ void ReplicationCoordinatorImpl::_scheduleNextLivenessUpdate_inlock() {
}
auto nextTimeout = earliestDate + _rsConfig.getElectionTimeoutPeriod();
- LOG(3) << "scheduling next check at " << nextTimeout;
+ LOGV2_DEBUG(
+ 21483, 3, "scheduling next check at {nextTimeout}", "nextTimeout"_attr = nextTimeout);
// It is possible we will schedule the next timeout in the past.
// ThreadPoolTaskExecutor::_scheduleWorkAt() schedules its work immediately if it's given a
@@ -810,7 +835,7 @@ void ReplicationCoordinatorImpl::_cancelAndRescheduleLivenessUpdate_inlock(int u
void ReplicationCoordinatorImpl::_cancelPriorityTakeover_inlock() {
if (_priorityTakeoverCbh.isValid()) {
- log() << "Canceling priority takeover callback";
+ LOGV2(21484, "Canceling priority takeover callback");
_replExecutor->cancel(_priorityTakeoverCbh);
_priorityTakeoverCbh = CallbackHandle();
_priorityTakeoverWhen = Date_t();
@@ -819,7 +844,7 @@ void ReplicationCoordinatorImpl::_cancelPriorityTakeover_inlock() {
void ReplicationCoordinatorImpl::_cancelCatchupTakeover_inlock() {
if (_catchupTakeoverCbh.isValid()) {
- log() << "Canceling catchup takeover callback";
+ LOGV2(21485, "Canceling catchup takeover callback");
_replExecutor->cancel(_catchupTakeoverCbh);
_catchupTakeoverCbh = CallbackHandle();
_catchupTakeoverWhen = Date_t();
diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
index 5532d72f701..27271617d88 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat_v1_test.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/repl/replication_coordinator_test_fixture.h"
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/executor/network_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -718,7 +719,10 @@ TEST_F(ReplCoordHBV1Test,
enterNetwork();
const NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21492,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
getNet()->scheduleResponse(
noi,
getNet()->now(),
@@ -728,8 +732,10 @@ TEST_F(ReplCoordHBV1Test,
if (request.target != HostAndPort("node2", 12345) &&
request.cmdObj.firstElement().fieldNameStringData() != "replSetHeartbeat") {
- error() << "Black holing unexpected request to " << request.target << ": "
- << request.cmdObj;
+ LOGV2_ERROR(21496,
+ "Black holing unexpected request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj);
getNet()->blackHole(noi);
}
getNet()->runReadyNetworkOperations();
@@ -792,11 +798,16 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM
const RemoteCommandRequest& request = noi->getRequest();
if (request.target == host2 &&
request.cmdObj.firstElement().fieldNameStringData() == "replSetHeartbeat") {
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21493,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
net->scheduleResponse(noi, net->now(), heartbeatResponse);
} else {
- log() << "blackholing request to " << request.target.toString() << ": "
- << request.cmdObj;
+ LOGV2(21494,
+ "blackholing request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
}
net->runReadyNetworkOperations();
@@ -810,7 +821,7 @@ TEST_F(ReplCoordHBV1Test, IgnoreTheContentsOfMetadataWhenItsReplicaSetIdDoesNotM
ASSERT_OK(getReplCoord()->processReplSetGetStatus(
&statusBuilder, ReplicationCoordinator::ReplSetGetStatusResponseStyle::kBasic));
auto statusObj = statusBuilder.obj();
- unittest::log() << "replica set status = " << statusObj;
+ LOGV2(21495, "replica set status = {statusObj}", "statusObj"_attr = statusObj);
ASSERT_EQ(mongo::Array, statusObj["members"].type());
auto members = statusObj["members"].Array();
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index aefefa5177e..1f1e6c32160 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -63,6 +63,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/executor/network_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/stdx/future.h"
@@ -1320,7 +1321,10 @@ protected:
getNet()->runUntil(getNet()->now() + heartbeatInterval);
NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest();
RemoteCommandRequest request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21497,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
ReplSetHeartbeatArgsV1 hbArgs;
if (hbArgs.initialize(request.cmdObj).isOK()) {
ReplSetHeartbeatResponse hbResp;
@@ -1336,7 +1340,9 @@ protected:
}
while (getNet()->hasReadyRequests()) {
auto noi = getNet()->getNextReadyRequest();
- log() << "Blackholing network request " << noi->getRequest().cmdObj;
+ LOGV2(21498,
+ "Blackholing network request {noi_getRequest_cmdObj}",
+ "noi_getRequest_cmdObj"_attr = noi->getRequest().cmdObj);
getNet()->blackHole(noi);
}
@@ -1969,7 +1975,10 @@ protected:
ReplSetHeartbeatArgsV1 hbArgs;
ASSERT_OK(hbArgs.initialize(request.cmdObj));
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21499,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
// Catch up 'numNodesCaughtUp' nodes out of 5.
OpTime optimeResponse = (hbNum <= numNodesCaughtUp) ? optimePrimary : optimeLagged;
@@ -2365,7 +2374,10 @@ TEST_F(StepDownTest,
getNet()->runUntil(getNet()->now() + Milliseconds(2000));
NetworkInterfaceMock::NetworkOperationIterator noi = getNet()->getNextReadyRequest();
RemoteCommandRequest request = noi->getRequest();
- log() << "HB1: " << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21500,
+ "HB1: {request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
ReplSetHeartbeatArgsV1 hbArgs;
if (hbArgs.initialize(request.cmdObj).isOK()) {
ReplSetHeartbeatResponse hbResp;
@@ -2651,7 +2663,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) {
long long memberId = entry[UpdatePositionArgs::kMemberIdFieldName].Number();
memberIds.insert(memberId);
if (memberId == 0) {
- log() << 0;
+ LOGV2(21501, "{_0}", "_0"_attr = 0);
ASSERT_OK(bsonExtractOpTimeField(
entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime));
ASSERT_OK(bsonExtractOpTimeField(
@@ -2659,7 +2671,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) {
ASSERT_EQUALS(optime1, appliedOpTime);
ASSERT_EQUALS(optime1, durableOpTime);
} else if (memberId == 1) {
- log() << 1;
+ LOGV2(21502, "{_1}", "_1"_attr = 1);
ASSERT_OK(bsonExtractOpTimeField(
entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime));
ASSERT_OK(bsonExtractOpTimeField(
@@ -2667,7 +2679,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) {
ASSERT_EQUALS(optime2, appliedOpTime);
ASSERT_EQUALS(OpTime(), durableOpTime);
} else if (memberId == 2) {
- log() << 2;
+ LOGV2(21503, "{_2}", "_2"_attr = 2);
ASSERT_OK(bsonExtractOpTimeField(
entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime));
ASSERT_OK(bsonExtractOpTimeField(
@@ -2675,7 +2687,7 @@ TEST_F(ReplCoordTest, NodeIncludesOtherMembersProgressInUpdatePositionCommand) {
ASSERT_EQUALS(optime3, appliedOpTime);
ASSERT_EQUALS(optime3, durableOpTime);
} else {
- log() << 3;
+ LOGV2(21504, "{_3}", "_3"_attr = 3);
ASSERT_EQUALS(3, memberId);
ASSERT_OK(bsonExtractOpTimeField(
entry, UpdatePositionArgs::kAppliedOpTimeFieldName, &appliedOpTime));
@@ -3778,8 +3790,9 @@ TEST_F(ReplCoordTest, AwaitIsMasterResponseReturnsOnElectionWin) {
waitForIsMasterFailPoint->waitForTimesEntered(timesEnteredFailPoint + 1);
auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- unittest::log() << "Election timeout scheduled at " << electionTimeoutWhen
- << " (simulator time)";
+ LOGV2(21505,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
simulateSuccessfulV1ElectionWithoutExitingDrainMode(electionTimeoutWhen, opCtx.get());
waitForIsMasterFailPoint->waitForTimesEntered(timesEnteredFailPoint + 2);
@@ -5682,7 +5695,7 @@ TEST_F(ReplCoordTest, PrepareOplogQueryMetadata) {
&metadataBob);
BSONObj metadata = metadataBob.done();
- log() << metadata;
+ LOGV2(21506, "{metadata}", "metadata"_attr = metadata);
auto oqMetadata = rpc::OplogQueryMetadata::readFromMetadata(metadata);
ASSERT_OK(oqMetadata.getStatus());
@@ -5788,12 +5801,16 @@ TEST_F(ReplCoordTest,
const auto& request = noi->getRequest();
ASSERT_EQUALS(HostAndPort("node2", 12345), request.target);
ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData());
- log() << "black holing " << noi->getRequest().cmdObj;
+ LOGV2(21507,
+ "black holing {noi_getRequest_cmdObj}",
+ "noi_getRequest_cmdObj"_attr = noi->getRequest().cmdObj);
net->blackHole(noi);
// Advance simulator clock to some time before the first scheduled election.
auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest();
- log() << "Election initially scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21508,
+ "Election initially scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
ASSERT_GREATER_THAN(electionTimeoutWhen, net->now());
auto until = net->now() + (electionTimeoutWhen - net->now()) / 2;
net->runUntil(until);
@@ -5877,7 +5894,7 @@ TEST_F(ReplCoordTest,
ASSERT_TRUE(net->hasReadyRequests());
auto noi = net->getNextReadyRequest();
auto&& request = noi->getRequest();
- log() << "processing " << request.cmdObj;
+ LOGV2(21509, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj);
ASSERT_EQUALS(HostAndPort("node2", 12345), request.target);
ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData());
@@ -5934,7 +5951,7 @@ TEST_F(ReplCoordTest,
ASSERT_TRUE(net->hasReadyRequests());
auto noi = net->getNextReadyRequest();
auto&& request = noi->getRequest();
- log() << "processing " << request.cmdObj;
+ LOGV2(21510, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj);
ASSERT_EQUALS(HostAndPort("node2", 12345), request.target);
ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData());
@@ -5987,7 +6004,7 @@ TEST_F(ReplCoordTest,
ASSERT_TRUE(net->hasReadyRequests());
auto noi = net->getNextReadyRequest();
auto&& request = noi->getRequest();
- log() << "processing " << request.cmdObj;
+ LOGV2(21511, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj);
ASSERT_EQUALS(HostAndPort("node2", 12345), request.target);
ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData());
@@ -6035,7 +6052,7 @@ TEST_F(ReplCoordTest,
ASSERT_TRUE(net->hasReadyRequests());
auto noi = net->getNextReadyRequest();
auto&& request = noi->getRequest();
- log() << "processing " << request.cmdObj;
+ LOGV2(21512, "processing {request_cmdObj}", "request_cmdObj"_attr = request.cmdObj);
ASSERT_EQUALS(HostAndPort("node2", 12345), request.target);
ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData());
@@ -6097,12 +6114,16 @@ TEST_F(ReplCoordTest, CancelAndRescheduleElectionTimeoutLogging) {
const auto& request = noi->getRequest();
ASSERT_EQUALS(HostAndPort("node2", 12345), request.target);
ASSERT_EQUALS("replSetHeartbeat", request.cmdObj.firstElement().fieldNameStringData());
- log() << "black holing " << noi->getRequest().cmdObj;
+ LOGV2(21513,
+ "black holing {noi_getRequest_cmdObj}",
+ "noi_getRequest_cmdObj"_attr = noi->getRequest().cmdObj);
net->blackHole(noi);
// Advance simulator clock to some time after the first scheduled election.
auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest();
- log() << "Election initially scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21514,
+ "Election initially scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
ASSERT_GREATER_THAN(electionTimeoutWhen, net->now());
auto until = electionTimeoutWhen + Milliseconds(1);
net->runUntil(until);
diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
index f773b0d03ff..4d2c4c82dd4 100644
--- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
+++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp
@@ -52,6 +52,7 @@
#include "mongo/executor/network_interface_mock.h"
#include "mongo/executor/thread_pool_mock.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -217,7 +218,10 @@ void ReplCoordTest::assertStartSuccess(const BSONObj& configDoc, const HostAndPo
executor::RemoteCommandResponse ReplCoordTest::makeResponseStatus(const BSONObj& doc,
Milliseconds millis) {
- log() << "Responding with " << doc << " (elapsed: " << millis << ")";
+ LOGV2(21515,
+ "Responding with {doc} (elapsed: {millis})",
+ "doc"_attr = doc,
+ "millis"_attr = millis);
return RemoteCommandResponse(doc, millis);
}
@@ -229,7 +233,10 @@ void ReplCoordTest::simulateEnoughHeartbeatsForAllNodesUp() {
for (int i = 0; i < rsConfig.getNumMembers() - 1; ++i) {
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21516,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
ReplSetHeartbeatArgsV1 hbArgs;
if (hbArgs.initialize(request.cmdObj).isOK()) {
ReplSetHeartbeatResponse hbResp;
@@ -243,8 +250,10 @@ void ReplCoordTest::simulateEnoughHeartbeatsForAllNodesUp() {
BSONObjBuilder respObj;
net->scheduleResponse(noi, net->now(), makeResponseStatus(hbResp.toBSON()));
} else {
- error() << "Black holing unexpected request to " << request.target << ": "
- << request.cmdObj;
+ LOGV2_ERROR(21526,
+ "Black holing unexpected request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
}
net->runReadyNetworkOperations();
@@ -260,12 +269,15 @@ void ReplCoordTest::simulateSuccessfulDryRun(
auto electionTimeoutWhen = replCoord->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21517,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
int voteRequests = 0;
int votesExpected = rsConfig.getNumMembers() / 2;
- log() << "Simulating dry run responses - expecting " << votesExpected
- << " replSetRequestVotes requests";
+ LOGV2(21518,
+ "Simulating dry run responses - expecting {votesExpected} replSetRequestVotes requests",
+ "votesExpected"_attr = votesExpected);
net->enterNetwork();
while (voteRequests < votesExpected) {
if (net->now() < electionTimeoutWhen) {
@@ -273,7 +285,10 @@ void ReplCoordTest::simulateSuccessfulDryRun(
}
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21519,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
if (request.cmdObj.firstElement().fieldNameStringData() == "replSetRequestVotes") {
ASSERT_TRUE(request.cmdObj.getBoolField("dryRun"));
onDryRunRequest(request);
@@ -288,17 +303,20 @@ void ReplCoordTest::simulateSuccessfulDryRun(
} else if (consumeHeartbeatV1(noi)) {
// The heartbeat has been consumed.
} else {
- error() << "Black holing unexpected request to " << request.target << ": "
- << request.cmdObj;
+ LOGV2_ERROR(21527,
+ "Black holing unexpected request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
}
net->runReadyNetworkOperations();
}
net->exitNetwork();
- log() << "Simulating dry run responses - scheduled " << voteRequests
- << " replSetRequestVotes responses";
+ LOGV2(21520,
+ "Simulating dry run responses - scheduled {voteRequests} replSetRequestVotes responses",
+ "voteRequests"_attr = voteRequests);
getReplCoord()->waitForElectionDryRunFinish_forTest();
- log() << "Simulating dry run responses - dry run completed";
+ LOGV2(21521, "Simulating dry run responses - dry run completed");
}
void ReplCoordTest::simulateSuccessfulDryRun() {
@@ -309,7 +327,9 @@ void ReplCoordTest::simulateSuccessfulDryRun() {
void ReplCoordTest::simulateSuccessfulV1Election() {
auto electionTimeoutWhen = getReplCoord()->getElectionTimeout_forTest();
ASSERT_NOT_EQUALS(Date_t(), electionTimeoutWhen);
- log() << "Election timeout scheduled at " << electionTimeoutWhen << " (simulator time)";
+ LOGV2(21522,
+ "Election timeout scheduled at {electionTimeoutWhen} (simulator time)",
+ "electionTimeoutWhen"_attr = electionTimeoutWhen);
simulateSuccessfulV1ElectionAt(electionTimeoutWhen);
}
@@ -325,14 +345,19 @@ void ReplCoordTest::simulateSuccessfulV1ElectionWithoutExitingDrainMode(Date_t e
// Process requests until we're primary and consume the heartbeats for the notification
// of election win.
while (!replCoord->getMemberState().primary() || hasReadyRequests) {
- log() << "Waiting on network in state " << replCoord->getMemberState();
+ LOGV2(21523,
+ "Waiting on network in state {replCoord_getMemberState}",
+ "replCoord_getMemberState"_attr = replCoord->getMemberState());
getNet()->enterNetwork();
if (net->now() < electionTime) {
net->runUntil(electionTime);
}
const NetworkInterfaceMock::NetworkOperationIterator noi = net->getNextReadyRequest();
const RemoteCommandRequest& request = noi->getRequest();
- log() << request.target.toString() << " processing " << request.cmdObj;
+ LOGV2(21524,
+ "{request_target} processing {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
ReplSetHeartbeatArgsV1 hbArgs;
Status status = hbArgs.initialize(request.cmdObj);
if (status.isOK()) {
@@ -354,8 +379,10 @@ void ReplCoordTest::simulateSuccessfulV1ElectionWithoutExitingDrainMode(Date_t e
<< "term" << request.cmdObj["term"].Long()
<< "voteGranted" << true)));
} else {
- error() << "Black holing unexpected request to " << request.target << ": "
- << request.cmdObj;
+ LOGV2_ERROR(21528,
+ "Black holing unexpected request to {request_target}: {request_cmdObj}",
+ "request_target"_attr = request.target,
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
}
net->runReadyNetworkOperations();
@@ -464,7 +491,10 @@ void ReplCoordTest::simulateCatchUpAbort() {
auto noi = net->getNextReadyRequest();
auto request = noi->getRequest();
// Black hole heartbeat requests caused by time advance.
- log() << "Black holing request to " << request.target.toString() << " : " << request.cmdObj;
+ LOGV2(21525,
+ "Black holing request to {request_target} : {request_cmdObj}",
+ "request_target"_attr = request.target.toString(),
+ "request_cmdObj"_attr = request.cmdObj);
net->blackHole(noi);
if (net->now() < heartbeatTimeoutWhen) {
net->runUntil(heartbeatTimeoutWhen);
diff --git a/src/mongo/db/repl/replication_process.cpp b/src/mongo/db/repl/replication_process.cpp
index 117972289af..194c0194d12 100644
--- a/src/mongo/db/repl/replication_process.cpp
+++ b/src/mongo/db/repl/replication_process.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/repl/rollback_gen.h"
#include "mongo/db/repl/storage_interface.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -92,9 +93,14 @@ Status ReplicationProcess::refreshRollbackID(OperationContext* opCtx) {
}
if (kUninitializedRollbackId == _rbid) {
- log() << "Rollback ID is " << rbidResult.getValue();
+ LOGV2(21529,
+ "Rollback ID is {rbidResult_getValue}",
+ "rbidResult_getValue"_attr = rbidResult.getValue());
} else {
- log() << "Rollback ID is " << rbidResult.getValue() << " (previously " << _rbid << ")";
+ LOGV2(21530,
+ "Rollback ID is {rbidResult_getValue} (previously {rbid})",
+ "rbidResult_getValue"_attr = rbidResult.getValue(),
+ "rbid"_attr = _rbid);
}
_rbid = rbidResult.getValue();
@@ -106,7 +112,7 @@ int ReplicationProcess::getRollbackID() const {
if (kUninitializedRollbackId == _rbid) {
// This may happen when serverStatus is called by an internal client before we have a chance
// to read the rollback ID from storage.
- warning() << "Rollback ID is not initialized yet.";
+ LOGV2_WARNING(21533, "Rollback ID is not initialized yet.");
}
return _rbid;
}
@@ -122,11 +128,15 @@ Status ReplicationProcess::initializeRollbackID(OperationContext* opCtx) {
auto initRbidSW = _storageInterface->initializeRollbackID(opCtx);
if (initRbidSW.isOK()) {
- log() << "Initialized the rollback ID to " << initRbidSW.getValue();
+ LOGV2(21531,
+ "Initialized the rollback ID to {initRbidSW_getValue}",
+ "initRbidSW_getValue"_attr = initRbidSW.getValue());
_rbid = initRbidSW.getValue();
invariant(kUninitializedRollbackId != _rbid);
} else {
- warning() << "Failed to initialize the rollback ID: " << initRbidSW.getStatus().reason();
+ LOGV2_WARNING(21534,
+ "Failed to initialize the rollback ID: {initRbidSW_getStatus_reason}",
+ "initRbidSW_getStatus_reason"_attr = initRbidSW.getStatus().reason());
}
return initRbidSW.getStatus();
}
@@ -139,11 +149,15 @@ Status ReplicationProcess::incrementRollbackID(OperationContext* opCtx) {
// If the rollback ID was incremented successfully, cache the new value in _rbid to be returned
// the next time getRollbackID() is called.
if (status.isOK()) {
- log() << "Incremented the rollback ID to " << status.getValue();
+ LOGV2(21532,
+ "Incremented the rollback ID to {status_getValue}",
+ "status_getValue"_attr = status.getValue());
_rbid = status.getValue();
invariant(kUninitializedRollbackId != _rbid);
} else {
- warning() << "Failed to increment the rollback ID: " << status.getStatus().reason();
+ LOGV2_WARNING(21535,
+ "Failed to increment the rollback ID: {status_getStatus_reason}",
+ "status_getStatus_reason"_attr = status.getStatus().reason());
}
return status.getStatus();
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index 3c7b47d3285..f28c9aaa2d1 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/storage/storage_parameters_gen.h"
#include "mongo/db/transaction_history_iterator.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/timer.h"
@@ -90,8 +91,12 @@ public:
void onBatchEnd(const StatusWith<OpTime>&, const std::vector<OplogEntry>&) final {}
void complete(const OpTime& applyThroughOpTime) const {
- log() << "Applied " << _numOpsApplied << " operations in " << _numBatches
- << " batches. Last operation applied with optime: " << applyThroughOpTime;
+ LOGV2(21536,
+ "Applied {numOpsApplied} operations in {numBatches} batches. Last operation applied "
+ "with optime: {applyThroughOpTime}",
+ "numOpsApplied"_attr = _numOpsApplied,
+ "numBatches"_attr = _numBatches,
+ "applyThroughOpTime"_attr = applyThroughOpTime);
}
private:
@@ -134,16 +139,21 @@ public:
ss << " and <= " << _oplogApplicationEndPoint->toBSON();
}
- severe() << "Couldn't find any entries in the oplog" << ss.str()
- << ", which should be impossible.";
+ LOGV2_FATAL(
+ 21559,
+ "Couldn't find any entries in the oplog{ss_str}, which should be impossible.",
+ "ss_str"_attr = ss.str());
fassertFailedNoTrace(40293);
}
auto firstTimestampFound =
fassert(40291, OpTime::parseFromOplogEntry(_cursor->nextSafe())).getTimestamp();
if (firstTimestampFound != _oplogApplicationStartPoint) {
- severe() << "Oplog entry at " << _oplogApplicationStartPoint.toBSON()
- << " is missing; actual entry found is " << firstTimestampFound.toBSON();
+ LOGV2_FATAL(21560,
+ "Oplog entry at {oplogApplicationStartPoint} is missing; actual entry "
+ "found is {firstTimestampFound}",
+ "oplogApplicationStartPoint"_attr = _oplogApplicationStartPoint.toBSON(),
+ "firstTimestampFound"_attr = firstTimestampFound.toBSON());
fassertFailedNoTrace(40292);
}
}
@@ -210,8 +220,9 @@ private:
boost::optional<Timestamp> recoverFromOplogPrecursor(OperationContext* opCtx,
StorageInterface* storageInterface) {
if (!storageInterface->supportsRecoveryTimestamp(opCtx->getServiceContext())) {
- severe() << "Cannot recover from the oplog with a storage engine that does not support "
- << "recover to stable timestamp.";
+ LOGV2_FATAL(21561,
+ "Cannot recover from the oplog with a storage engine that does not support "
+ "recover to stable timestamp.");
fassertFailedNoTrace(50805);
}
@@ -220,7 +231,8 @@ boost::optional<Timestamp> recoverFromOplogPrecursor(OperationContext* opCtx,
// happen.
auto recoveryTS = storageInterface->getRecoveryTimestamp(opCtx->getServiceContext());
if (recoveryTS && recoveryTS->isNull()) {
- severe() << "Cannot recover from the oplog with stable checkpoint at null timestamp.";
+ LOGV2_FATAL(21562,
+ "Cannot recover from the oplog with stable checkpoint at null timestamp.");
fassertFailedNoTrace(50806);
}
@@ -238,36 +250,44 @@ void ReplicationRecoveryImpl::_assertNoRecoveryNeededOnUnstableCheckpoint(Operat
invariant(!_storageInterface->getRecoveryTimestamp(opCtx->getServiceContext()));
if (_consistencyMarkers->getInitialSyncFlag(opCtx)) {
- severe() << "Unexpected recovery needed, initial sync flag set.";
+ LOGV2_FATAL(21563, "Unexpected recovery needed, initial sync flag set.");
fassertFailedNoTrace(31362);
}
const auto truncateAfterPoint = _consistencyMarkers->getOplogTruncateAfterPoint(opCtx);
if (!truncateAfterPoint.isNull()) {
- severe() << "Unexpected recovery needed, oplog requires truncation. Truncate after point: "
- << truncateAfterPoint.toString();
+ LOGV2_FATAL(21564,
+ "Unexpected recovery needed, oplog requires truncation. Truncate after point: "
+ "{truncateAfterPoint}",
+ "truncateAfterPoint"_attr = truncateAfterPoint.toString());
fassertFailedNoTrace(31363);
}
auto topOfOplogSW = _getTopOfOplog(opCtx);
if (!topOfOplogSW.isOK()) {
- severe() << "Recovery not possible, no oplog found: " << topOfOplogSW.getStatus();
+ LOGV2_FATAL(21565,
+ "Recovery not possible, no oplog found: {topOfOplogSW_getStatus}",
+ "topOfOplogSW_getStatus"_attr = topOfOplogSW.getStatus());
fassertFailedNoTrace(31364);
}
const auto topOfOplog = topOfOplogSW.getValue();
const auto appliedThrough = _consistencyMarkers->getAppliedThrough(opCtx);
if (!appliedThrough.isNull() && appliedThrough != topOfOplog) {
- severe() << "Unexpected recovery needed, appliedThrough is not at top of oplog, indicating "
- "oplog has not been fully applied. appliedThrough: "
- << appliedThrough.toString();
+ LOGV2_FATAL(21566,
+ "Unexpected recovery needed, appliedThrough is not at top of oplog, indicating "
+ "oplog has not been fully applied. appliedThrough: {appliedThrough}",
+ "appliedThrough"_attr = appliedThrough.toString());
fassertFailedNoTrace(31365);
}
const auto minValid = _consistencyMarkers->getMinValid(opCtx);
if (minValid > topOfOplog) {
- severe() << "Unexpected recovery needed, top of oplog is not consistent. topOfOplog: "
- << topOfOplog << ", minValid: " << minValid;
+ LOGV2_FATAL(21567,
+ "Unexpected recovery needed, top of oplog is not consistent. topOfOplog: "
+ "{topOfOplog}, minValid: {minValid}",
+ "topOfOplog"_attr = topOfOplog,
+ "minValid"_attr = minValid);
fassertFailedNoTrace(31366);
}
}
@@ -287,21 +307,25 @@ void ReplicationRecoveryImpl::recoverFromOplogAsStandalone(OperationContext* opC
if (gTakeUnstableCheckpointOnShutdown) {
// Ensure 'recoverFromOplogAsStandalone' with 'takeUnstableCheckpointOnShutdown'
// is safely idempotent when it succeeds.
- log() << "Recovering from unstable checkpoint with 'takeUnstableCheckpointOnShutdown'."
- << " Confirming that no oplog recovery is needed.";
+ LOGV2(21537,
+ "Recovering from unstable checkpoint with 'takeUnstableCheckpointOnShutdown'. "
+ "Confirming that no oplog recovery is needed.");
_assertNoRecoveryNeededOnUnstableCheckpoint(opCtx);
- log() << "Not doing any oplog recovery since there is an unstable checkpoint that is "
- << "up to date.";
+ LOGV2(21538,
+ "Not doing any oplog recovery since there is an unstable checkpoint that is up "
+ "to date.");
} else {
- severe() << "Cannot use 'recoverFromOplogAsStandalone' without a stable checkpoint.";
+ LOGV2_FATAL(21568,
+ "Cannot use 'recoverFromOplogAsStandalone' without a stable checkpoint.");
fassertFailedNoTrace(31229);
}
}
reconstructPreparedTransactions(opCtx, OplogApplication::Mode::kRecovering);
- warning() << "Setting mongod to readOnly mode as a result of specifying "
- "'recoverFromOplogAsStandalone'.";
+ LOGV2_WARNING(21558,
+ "Setting mongod to readOnly mode as a result of specifying "
+ "'recoverFromOplogAsStandalone'.");
storageGlobalParams.readOnly = true;
}
@@ -313,7 +337,7 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time
auto recoveryTS = recoverFromOplogPrecursor(opCtx, _storageInterface);
if (!recoveryTS) {
- severe() << "Cannot use 'recoverToOplogTimestamp' without a stable checkpoint.";
+ LOGV2_FATAL(21569, "Cannot use 'recoverToOplogTimestamp' without a stable checkpoint.");
fassertFailedNoTrace(31399);
}
@@ -322,15 +346,18 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time
Timestamp startPoint = _consistencyMarkers->getAppliedThrough(opCtx).getTimestamp();
if (startPoint.isNull()) {
- log() << "No stored oplog entries to apply for recovery.";
+ LOGV2(21539, "No stored oplog entries to apply for recovery.");
return;
}
invariant(!endPoint.isNull());
if (startPoint == endPoint) {
- log() << "No oplog entries to apply for recovery. Start point '" << startPoint
- << "' is at the end point '" << endPoint << "' in the oplog.";
+ LOGV2(21540,
+ "No oplog entries to apply for recovery. Start point '{startPoint}' is at the end "
+ "point '{endPoint}' in the oplog.",
+ "startPoint"_attr = startPoint,
+ "endPoint"_attr = endPoint);
return;
} else if (startPoint > endPoint) {
uasserted(ErrorCodes::BadValue,
@@ -341,8 +368,11 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time
Timestamp appliedUpTo = _applyOplogOperations(opCtx, startPoint, endPoint);
if (appliedUpTo.isNull()) {
- log() << "No stored oplog entries to apply for recovery between " << startPoint.toString()
- << " (inclusive) and " << endPoint.toString() << " (inclusive).";
+ LOGV2(21541,
+ "No stored oplog entries to apply for recovery between {startPoint} (inclusive) and "
+ "{endPoint} (inclusive).",
+ "startPoint"_attr = startPoint.toString(),
+ "endPoint"_attr = endPoint.toString());
} else {
invariant(appliedUpTo <= endPoint);
}
@@ -353,7 +383,7 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time
void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
boost::optional<Timestamp> stableTimestamp) try {
if (_consistencyMarkers->getInitialSyncFlag(opCtx)) {
- log() << "No recovery needed. Initial sync flag set.";
+ LOGV2(21542, "No recovery needed. Initial sync flag set.");
return; // Initial Sync will take over so no cleanup is needed.
}
@@ -393,7 +423,7 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
topOfOplogSW.getStatus() == ErrorCodes::NamespaceNotFound) {
// Oplog is empty. There are no oplog entries to apply, so we exit recovery and go into
// initial sync.
- log() << "No oplog entries to apply for recovery. Oplog is empty.";
+ LOGV2(21543, "No oplog entries to apply for recovery. Oplog is empty.");
return;
}
fassert(40290, topOfOplogSW);
@@ -406,7 +436,9 @@ void ReplicationRecoveryImpl::recoverFromOplog(OperationContext* opCtx,
_recoverFromUnstableCheckpoint(opCtx, appliedThrough, topOfOplog);
}
} catch (...) {
- severe() << "Caught exception during replication recovery: " << exceptionToStatus();
+ LOGV2_FATAL(21570,
+ "Caught exception during replication recovery: {exceptionToStatus}",
+ "exceptionToStatus"_attr = exceptionToStatus());
std::terminate();
}
@@ -419,11 +451,17 @@ void ReplicationRecoveryImpl::_recoverFromStableTimestamp(OperationContext* opCt
const auto truncateAfterPoint = _consistencyMarkers->getOplogTruncateAfterPoint(opCtx);
- log() << "Recovering from stable timestamp: " << stableTimestamp
- << " (top of oplog: " << topOfOplog << ", appliedThrough: " << appliedThrough
- << ", TruncateAfter: " << truncateAfterPoint << ")";
-
- log() << "Starting recovery oplog application at the stable timestamp: " << stableTimestamp;
+ LOGV2(21544,
+ "Recovering from stable timestamp: {stableTimestamp} (top of oplog: {topOfOplog}, "
+ "appliedThrough: {appliedThrough}, TruncateAfter: {truncateAfterPoint})",
+ "stableTimestamp"_attr = stableTimestamp,
+ "topOfOplog"_attr = topOfOplog,
+ "appliedThrough"_attr = appliedThrough,
+ "truncateAfterPoint"_attr = truncateAfterPoint);
+
+ LOGV2(21545,
+ "Starting recovery oplog application at the stable timestamp: {stableTimestamp}",
+ "stableTimestamp"_attr = stableTimestamp);
_applyToEndOfOplog(opCtx, stableTimestamp, topOfOplog.getTimestamp());
}
@@ -431,18 +469,24 @@ void ReplicationRecoveryImpl::_recoverFromUnstableCheckpoint(OperationContext* o
OpTime appliedThrough,
OpTime topOfOplog) {
invariant(!topOfOplog.isNull());
- log() << "Recovering from an unstable checkpoint (top of oplog: " << topOfOplog
- << ", appliedThrough: " << appliedThrough << ")";
+ LOGV2(21546,
+ "Recovering from an unstable checkpoint (top of oplog: {topOfOplog}, appliedThrough: "
+ "{appliedThrough})",
+ "topOfOplog"_attr = topOfOplog,
+ "appliedThrough"_attr = appliedThrough);
if (appliedThrough.isNull()) {
// The appliedThrough would be null if we shut down cleanly or crashed as a primary. Either
// way we are consistent at the top of the oplog.
- log() << "No oplog entries to apply for recovery. appliedThrough is null.";
+ LOGV2(21547, "No oplog entries to apply for recovery. appliedThrough is null.");
} else {
// If the appliedThrough is not null, then we shut down uncleanly during secondary oplog
// application and must apply from the appliedThrough to the top of the oplog.
- log() << "Starting recovery oplog application at the appliedThrough: " << appliedThrough
- << ", through the top of the oplog: " << topOfOplog;
+ LOGV2(21548,
+ "Starting recovery oplog application at the appliedThrough: {appliedThrough}, "
+ "through the top of the oplog: {topOfOplog}",
+ "appliedThrough"_attr = appliedThrough,
+ "topOfOplog"_attr = topOfOplog);
// When `recoverFromOplog` truncates the oplog, that also happens to set the "oldest
// timestamp" to the truncation point[1]. `_applyToEndOfOplog` will then perform writes
@@ -492,11 +536,15 @@ void ReplicationRecoveryImpl::_applyToEndOfOplog(OperationContext* opCtx,
// Check if we have any unapplied ops in our oplog. It is important that this is done after
// deleting the ragged end of the oplog.
if (oplogApplicationStartPoint == topOfOplog) {
- log() << "No oplog entries to apply for recovery. Start point is at the top of the oplog.";
+ LOGV2(21549,
+ "No oplog entries to apply for recovery. Start point is at the top of the oplog.");
return; // We've applied all the valid oplog we have.
} else if (oplogApplicationStartPoint > topOfOplog) {
- severe() << "Applied op " << oplogApplicationStartPoint.toBSON()
- << " not found. Top of oplog is " << topOfOplog.toBSON() << '.';
+ LOGV2_FATAL(
+ 21571,
+ "Applied op {oplogApplicationStartPoint} not found. Top of oplog is {topOfOplog}.",
+ "oplogApplicationStartPoint"_attr = oplogApplicationStartPoint.toBSON(),
+ "topOfOplog"_attr = topOfOplog.toBSON());
fassertFailedNoTrace(40313);
}
@@ -511,8 +559,10 @@ void ReplicationRecoveryImpl::_applyToEndOfOplog(OperationContext* opCtx,
Timestamp ReplicationRecoveryImpl::_applyOplogOperations(OperationContext* opCtx,
const Timestamp& startPoint,
const Timestamp& endPoint) {
- log() << "Replaying stored operations from " << startPoint << " (inclusive) to " << endPoint
- << " (inclusive).";
+ LOGV2(21550,
+ "Replaying stored operations from {startPoint} (inclusive) to {endPoint} (inclusive).",
+ "startPoint"_attr = startPoint,
+ "endPoint"_attr = endPoint);
OplogBufferLocalOplog oplogBuffer(startPoint, endPoint);
oplogBuffer.startup(opCtx);
@@ -616,9 +666,10 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx,
const auto tsElem = entry["ts"];
if (count == 1) {
if (tsElem.eoo()) {
- LOG(2) << "Oplog tail entry: " << redact(entry);
+ LOGV2_DEBUG(21551, 2, "Oplog tail entry: {entry}", "entry"_attr = redact(entry));
} else {
- LOG(2) << "Oplog tail entry ts field: " << tsElem;
+ LOGV2_DEBUG(
+ 21552, 2, "Oplog tail entry ts field: {tsElem}", "tsElem"_attr = tsElem);
topOfOplog = tsElem.timestamp();
}
}
@@ -627,24 +678,35 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx,
// If count == 1, that means that we have nothing to delete because everything in the
// oplog is <= truncateTimestamp.
if (count != 1) {
- log() << "Truncating oplog from [" << Timestamp(previousRecordId.repr()) << " to "
- << topOfOplog << "]. Truncate after point is " << truncateTimestamp;
+ LOGV2(21553,
+ "Truncating oplog from [{Timestamp_previousRecordId_repr} to {topOfOplog}]. "
+ "Truncate after point is {truncateTimestamp}",
+ "Timestamp_previousRecordId_repr"_attr = Timestamp(previousRecordId.repr()),
+ "topOfOplog"_attr = topOfOplog,
+ "truncateTimestamp"_attr = truncateTimestamp);
invariant(!previousRecordId.isNull());
oplogCollection->cappedTruncateAfter(opCtx, previousRecordId, /*inclusive*/ true);
} else {
- log() << "There is no oplog after " << truncateTimestamp
- << " to truncate. The top of the oplog is " << topOfOplog;
+ LOGV2(21554,
+ "There is no oplog after {truncateTimestamp} to truncate. The top of the "
+ "oplog is {topOfOplog}",
+ "truncateTimestamp"_attr = truncateTimestamp,
+ "topOfOplog"_attr = topOfOplog);
}
- log() << "Replication recovery oplog truncation finished in: " << timer.millis()
- << "ms";
+ LOGV2(21555,
+ "Replication recovery oplog truncation finished in: {timer_millis}ms",
+ "timer_millis"_attr = timer.millis());
return;
}
previousRecordId = id;
}
- severe() << "Reached end of oplog looking for oplog entry before " << truncateTimestamp.toBSON()
- << " but couldn't find any after looking through " << count << " entries.";
+ LOGV2_FATAL(21572,
+ "Reached end of oplog looking for oplog entry before {truncateTimestamp} but "
+ "couldn't find any after looking through {count} entries.",
+ "truncateTimestamp"_attr = truncateTimestamp.toBSON(),
+ "count"_attr = count);
fassertFailedNoTrace(40296);
}
@@ -661,14 +723,18 @@ void ReplicationRecoveryImpl::_truncateOplogIfNeededAndThenClearOplogTruncateAft
AutoGetCollectionForRead oplog(opCtx, NamespaceString::kRsOplogNamespace);
invariant(oplog.getCollection());
- log() << "The oplog truncation point (" << truncatePoint
- << ") is equal to or earlier than the stable timestamp (" << stableTimestamp.get()
- << "), so truncating after the stable timestamp instead";
+ LOGV2(21556,
+ "The oplog truncation point ({truncatePoint}) is equal to or earlier than the stable "
+ "timestamp ({stableTimestamp_get}), so truncating after the stable timestamp instead",
+ "truncatePoint"_attr = truncatePoint,
+ "stableTimestamp_get"_attr = stableTimestamp.get());
truncatePoint = stableTimestamp.get();
}
- log() << "Removing unapplied oplog entries starting after: " << truncatePoint.toBSON();
+ LOGV2(21557,
+ "Removing unapplied oplog entries starting after: {truncatePoint}",
+ "truncatePoint"_attr = truncatePoint.toBSON());
_truncateOplogTo(opCtx, truncatePoint);
// Clear the oplogTruncateAfterPoint now that we have removed any holes that might exist in the
diff --git a/src/mongo/db/repl/reporter.cpp b/src/mongo/db/repl/reporter.cpp
index f66eb930893..2d23ef4e256 100644
--- a/src/mongo/db/repl/reporter.cpp
+++ b/src/mongo/db/repl/reporter.cpp
@@ -37,6 +37,7 @@
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/commands/server_status_metric.h"
#include "mongo/db/repl/update_position_args.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/destructor_guard.h"
@@ -190,8 +191,11 @@ Status Reporter::trigger() {
_status = scheduleResult.getStatus();
if (!_status.isOK()) {
- LOG(2) << "Reporter failed to schedule callback to prepare and send update command: "
- << _status;
+ LOGV2_DEBUG(
+ 21585,
+ 2,
+ "Reporter failed to schedule callback to prepare and send update command: {status}",
+ "status"_attr = _status);
return _status;
}
@@ -212,8 +216,11 @@ StatusWith<BSONObj> Reporter::_prepareCommand() {
// If there was an error in preparing the command, abort and return that error.
if (!prepareResult.isOK()) {
- LOG(2) << "Reporter failed to prepare update command with status: "
- << prepareResult.getStatus();
+ LOGV2_DEBUG(
+ 21586,
+ 2,
+ "Reporter failed to prepare update command with status: {prepareResult_getStatus}",
+ "prepareResult_getStatus"_attr = prepareResult.getStatus());
_status = prepareResult.getStatus();
return _status;
}
@@ -222,8 +229,12 @@ StatusWith<BSONObj> Reporter::_prepareCommand() {
}
void Reporter::_sendCommand_inlock(BSONObj commandRequest, Milliseconds netTimeout) {
- LOG(2) << "Reporter sending slave oplog progress to upstream updater " << _target << ": "
- << commandRequest;
+ LOGV2_DEBUG(
+ 21587,
+ 2,
+ "Reporter sending slave oplog progress to upstream updater {target}: {commandRequest}",
+ "target"_attr = _target,
+ "commandRequest"_attr = commandRequest);
auto scheduleResult = _executor->scheduleRemoteCommand(
executor::RemoteCommandRequest(_target, "admin", commandRequest, nullptr, netTimeout),
@@ -233,7 +244,8 @@ void Reporter::_sendCommand_inlock(BSONObj commandRequest, Milliseconds netTimeo
_status = scheduleResult.getStatus();
if (!_status.isOK()) {
- LOG(2) << "Reporter failed to schedule with status: " << _status;
+ LOGV2_DEBUG(
+ 21588, 2, "Reporter failed to schedule with status: {status}", "status"_attr = _status);
if (_status != ErrorCodes::ShutdownInProgress) {
fassert(34434, _status);
}
@@ -272,8 +284,10 @@ void Reporter::_processResponseCallback(
// sync target.
if (_status == ErrorCodes::InvalidReplicaSetConfig &&
_isTargetConfigNewerThanRequest(commandResult, rcbd.request.cmdObj)) {
- LOG(1) << "Reporter found newer configuration on sync source: " << _target
- << ". Retrying.";
+ LOGV2_DEBUG(21589,
+ 1,
+ "Reporter found newer configuration on sync source: {target}. Retrying.",
+ "target"_attr = _target);
_status = Status::OK();
// Do not resend update command immediately.
_isWaitingToSendReporter = false;
diff --git a/src/mongo/db/repl/roll_back_local_operations.cpp b/src/mongo/db/repl/roll_back_local_operations.cpp
index 1e5b102a595..04ea36b725d 100644
--- a/src/mongo/db/repl/roll_back_local_operations.cpp
+++ b/src/mongo/db/repl/roll_back_local_operations.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/repl/roll_back_local_operations.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -114,7 +115,10 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollBackLocalOperations
while (getTimestamp(_localOplogValue) > getTimestamp(operation)) {
_scanned++;
- LOG(2) << "Local oplog entry to roll back: " << redact(_localOplogValue.first);
+ LOGV2_DEBUG(21656,
+ 2,
+ "Local oplog entry to roll back: {localOplogValue_first}",
+ "localOplogValue_first"_attr = redact(_localOplogValue.first));
auto status = _rollbackOperation(_localOplogValue.first);
if (!status.isOK()) {
invariant(ErrorCodes::NoSuchKey != status.code());
diff --git a/src/mongo/db/repl/roll_back_local_operations_test.cpp b/src/mongo/db/repl/roll_back_local_operations_test.cpp
index 6d4261938ea..659ac806d09 100644
--- a/src/mongo/db/repl/roll_back_local_operations_test.cpp
+++ b/src/mongo/db/repl/roll_back_local_operations_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <iterator>
@@ -39,7 +41,9 @@
#include "mongo/db/repl/oplog_interface_mock.h"
#include "mongo/db/repl/oplog_interface_remote.h"
#include "mongo/db/repl/roll_back_local_operations.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace {
@@ -326,14 +330,15 @@ public:
int batchSize) override {
if (_initFailuresLeft > 0) {
_initFailuresLeft--;
- unittest::log()
- << "Throwing DBException on DBClientCursorForTest::query(). Failures left: "
- << _initFailuresLeft;
+ LOGV2(21657,
+ "Throwing DBException on DBClientCursorForTest::query(). Failures left: "
+ "{initFailuresLeft}",
+ "initFailuresLeft"_attr = _initFailuresLeft);
uasserted(50852, "Simulated network error");
MONGO_UNREACHABLE;
}
- unittest::log() << "Returning success on DBClientCursorForTest::query()";
+ LOGV2(21658, "Returning success on DBClientCursorForTest::query()");
BSONArrayBuilder builder;
builder.append(makeOp(1));
diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp
index b61005e8878..aa5d60beb85 100644
--- a/src/mongo/db/repl/rollback_impl.cpp
+++ b/src/mongo/db/repl/rollback_impl.cpp
@@ -62,6 +62,7 @@
#include "mongo/db/session_txn_record_gen.h"
#include "mongo/db/storage/remove_saver.h"
#include "mongo/db/transaction_history_iterator.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_config_version.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -99,10 +100,11 @@ boost::optional<long long> _parseDroppedCollectionCount(const OplogEntry& oplogE
auto obj2 = oplogEntry.getObject2();
if (!obj2) {
- warning() << "Unable to get collection count from " << desc
- << " without the o2 "
- "field. oplog op: "
- << redact(oplogEntry.toBSON());
+ LOGV2_WARNING(21634,
+ "Unable to get collection count from {desc} without the o2 "
+ "field. oplog op: {oplogEntry}",
+ "desc"_attr = desc,
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
return boost::none;
}
@@ -110,19 +112,30 @@ boost::optional<long long> _parseDroppedCollectionCount(const OplogEntry& oplogE
// TODO: Use IDL to parse o2 object. See txn_cmds.idl for example.
auto status = bsonExtractIntegerField(*obj2, kNumRecordsFieldName, &count);
if (!status.isOK()) {
- warning() << "Failed to parse " << desc << " for collection count: " << status
- << ". oplog op: " << redact(oplogEntry.toBSON());
+ LOGV2_WARNING(
+ 21635,
+ "Failed to parse {desc} for collection count: {status}. oplog op: {oplogEntry}",
+ "desc"_attr = desc,
+ "status"_attr = status,
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
return boost::none;
}
if (count < 0) {
- warning() << "Invalid collection count found in " << desc << ": " << count
- << ". oplog op: " << redact(oplogEntry.toBSON());
+ LOGV2_WARNING(21636,
+ "Invalid collection count found in {desc}: {count}. oplog op: {oplogEntry}",
+ "desc"_attr = desc,
+ "count"_attr = count,
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
return boost::none;
}
- LOG(2) << "Parsed collection count of " << count << " from " << desc
- << ". oplog op: " << redact(oplogEntry.toBSON());
+ LOGV2_DEBUG(21590,
+ 2,
+ "Parsed collection count of {count} from {desc}. oplog op: {oplogEntry}",
+ "count"_attr = count,
+ "desc"_attr = desc,
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
return count;
}
@@ -182,8 +195,9 @@ Status RollbackImpl::runRollback(OperationContext* opCtx) {
_listener->onTransitionToRollback();
if (MONGO_unlikely(rollbackHangAfterTransitionToRollback.shouldFail())) {
- log() << "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail "
- "point is disabled (rollback_impl).";
+ LOGV2(21591,
+ "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail "
+ "point is disabled (rollback_impl).");
rollbackHangAfterTransitionToRollback.pauseWhileSet(opCtx);
}
@@ -251,7 +265,7 @@ Status RollbackImpl::runRollback(OperationContext* opCtx) {
}
_listener->onRollbackOpObserver(_observerInfo);
- log() << "Rollback complete";
+ LOGV2(21592, "Rollback complete");
return Status::OK();
}
@@ -308,7 +322,7 @@ Status RollbackImpl::_transitionToRollback(OperationContext* opCtx) {
return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down");
}
- log() << "transition to ROLLBACK";
+ LOGV2(21593, "transition to ROLLBACK");
{
ReplicationStateTransitionLockGuard rstlLock(
opCtx, MODE_X, ReplicationStateTransitionLockGuard::EnqueueOnly());
@@ -327,7 +341,7 @@ Status RollbackImpl::_transitionToRollback(OperationContext* opCtx) {
<< "Cannot transition from "
<< _replicationCoordinator->getMemberState().toString() << " to "
<< MemberState(MemberState::RS_ROLLBACK).toString());
- log() << status;
+ LOGV2(21594, "{status}", "status"_attr = status);
return status;
}
}
@@ -350,14 +364,19 @@ Status RollbackImpl::_awaitBgIndexCompletion(OperationContext* opCtx) {
// Wait for all background operations to complete by waiting on each database.
std::vector<StringData> dbNames(dbs.begin(), dbs.end());
- log() << "Waiting for all background operations to complete before starting rollback";
+ LOGV2(21595, "Waiting for all background operations to complete before starting rollback");
for (auto db : dbNames) {
auto numInProg = BackgroundOperation::numInProgForDb(db);
auto numInProgInCoordinator = IndexBuildsCoordinator::get(opCtx)->numInProgForDb(db);
if (numInProg > 0 || numInProgInCoordinator > 0) {
- LOG(1) << "Waiting for "
- << (numInProg > numInProgInCoordinator ? numInProg : numInProgInCoordinator)
- << " background operations to complete on database '" << db << "'";
+ LOGV2_DEBUG(
+ 21596,
+ 1,
+ "Waiting for {numInProg_numInProgInCoordinator_numInProg_numInProgInCoordinator} "
+ "background operations to complete on database '{db}'",
+ "numInProg_numInProgInCoordinator_numInProg_numInProgInCoordinator"_attr =
+ (numInProg > numInProgInCoordinator ? numInProg : numInProgInCoordinator),
+ "db"_attr = db);
BackgroundOperation::awaitNoBgOpInProgForDb(db);
IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(db);
}
@@ -368,7 +387,7 @@ Status RollbackImpl::_awaitBgIndexCompletion(OperationContext* opCtx) {
}
}
- log() << "Finished waiting for background operations to complete before rollback";
+ LOGV2(21597, "Finished waiting for background operations to complete before rollback");
return Status::OK();
}
@@ -478,7 +497,7 @@ void RollbackImpl::_runPhaseFromAbortToReconstructPreparedTxns(
status = _writeRollbackFiles(opCtx);
fassert(31228, status);
} else {
- log() << "Not writing rollback files. 'createRollbackDataFiles' set to false.";
+ LOGV2(21598, "Not writing rollback files. 'createRollbackDataFiles' set to false.");
}
// If there were rolled back operations on any session, invalidate all sessions.
@@ -497,16 +516,24 @@ void RollbackImpl::_runPhaseFromAbortToReconstructPreparedTxns(
// Log the total number of insert and update operations that have been rolled back as a
// result of recovering to the stable timestamp.
- log() << "Rollback reverted " << _observerInfo.rollbackCommandCounts[kInsertCmdName]
- << " insert operations, " << _observerInfo.rollbackCommandCounts[kUpdateCmdName]
- << " update operations and " << _observerInfo.rollbackCommandCounts[kDeleteCmdName]
- << " delete operations.";
+ LOGV2(21599,
+ "Rollback reverted {observerInfo_rollbackCommandCounts_kInsertCmdName} insert "
+ "operations, {observerInfo_rollbackCommandCounts_kUpdateCmdName} update operations and "
+ "{observerInfo_rollbackCommandCounts_kDeleteCmdName} delete operations.",
+ "observerInfo_rollbackCommandCounts_kInsertCmdName"_attr =
+ _observerInfo.rollbackCommandCounts[kInsertCmdName],
+ "observerInfo_rollbackCommandCounts_kUpdateCmdName"_attr =
+ _observerInfo.rollbackCommandCounts[kUpdateCmdName],
+ "observerInfo_rollbackCommandCounts_kDeleteCmdName"_attr =
+ _observerInfo.rollbackCommandCounts[kDeleteCmdName]);
// During replication recovery, we truncate all oplog entries with timestamps greater than the
// oplog truncate after point. If we entered rollback, we are guaranteed to have at least one
// oplog entry after the common point.
- log() << "Marking to truncate all oplog entries with timestamps greater than "
- << commonPoint.getOpTime().getTimestamp();
+ LOGV2(21600,
+ "Marking to truncate all oplog entries with timestamps greater than "
+ "{commonPoint_getOpTime_getTimestamp}",
+ "commonPoint_getOpTime_getTimestamp"_attr = commonPoint.getOpTime().getTimestamp());
Timestamp truncatePoint = commonPoint.getOpTime().getTimestamp();
// Persist the truncate point to the 'oplogTruncateAfterPoint' document. We save this value so
@@ -568,9 +595,14 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) {
// if we just set the collection count here.
if (sizeRecoveryState(opCtx->getServiceContext())
.collectionAlwaysNeedsSizeAdjustment(ident)) {
- LOG(2) << "Not setting collection count to " << newCount << " for " << nss.ns() << " ("
- << uuid.toString() << ") [" << ident
- << "] because it is marked for size adjustment.";
+ LOGV2_DEBUG(21601,
+ 2,
+ "Not setting collection count to {newCount} for {nss_ns} ({uuid}) "
+ "[{ident}] because it is marked for size adjustment.",
+ "newCount"_attr = newCount,
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid.toString(),
+ "ident"_attr = ident);
continue;
}
@@ -578,8 +610,10 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) {
// (most likely due to a 4.0 drop oplog entry without the count information), we will
// determine the correct count here post-recovery using a collection scan.
if (kCollectionScanRequired == newCount) {
- log() << "Scanning collection " << nss.ns() << " (" << uuid.toString()
- << ") to fix collection count.";
+ LOGV2(21602,
+ "Scanning collection {nss_ns} ({uuid}) to fix collection count.",
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid.toString());
AutoGetCollectionForRead autoCollToScan(opCtx, nss);
auto collToScan = autoCollToScan.getCollection();
invariant(coll == collToScan,
@@ -596,9 +630,13 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) {
if (PlanExecutor::IS_EOF != state) {
// We ignore errors here because crashing or leaving rollback would only leave
// collection counts more inaccurate.
- warning() << "Failed to set count of " << nss.ns() << " (" << uuid.toString()
- << ") [" << ident
- << "] due to failed collection scan: " << exec->statestr(state);
+ LOGV2_WARNING(21637,
+ "Failed to set count of {nss_ns} ({uuid}) [{ident}] due to failed "
+ "collection scan: {exec_statestr_state}",
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid.toString(),
+ "ident"_attr = ident,
+ "exec_statestr_state"_attr = exec->statestr(state));
continue;
}
newCount = countFromScan;
@@ -609,11 +647,22 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) {
if (!status.isOK()) {
// We ignore errors here because crashing or leaving rollback would only leave
// collection counts more inaccurate.
- warning() << "Failed to set count of " << nss.ns() << " (" << uuid.toString() << ") ["
- << ident << "] to " << newCount << ". Received: " << status;
+ LOGV2_WARNING(21638,
+ "Failed to set count of {nss_ns} ({uuid}) [{ident}] to {newCount}. "
+ "Received: {status}",
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid.toString(),
+ "ident"_attr = ident,
+ "newCount"_attr = newCount,
+ "status"_attr = status);
} else {
- LOG(2) << "Set collection count of " << nss.ns() << " (" << uuid.toString() << ") ["
- << ident << "] to " << newCount << ".";
+ LOGV2_DEBUG(21603,
+ 2,
+ "Set collection count of {nss_ns} ({uuid}) [{ident}] to {newCount}.",
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid.toString(),
+ "ident"_attr = ident,
+ "newCount"_attr = newCount);
}
}
}
@@ -622,7 +671,7 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
const auto& catalog = CollectionCatalog::get(opCtx);
auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
- log() << "finding record store counts";
+ LOGV2(21604, "finding record store counts");
for (const auto& uiCount : _countDiffs) {
auto uuid = uiCount.first;
auto countDiff = uiCount.second;
@@ -662,10 +711,13 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
}
if (oldCount > static_cast<uint64_t>(std::numeric_limits<long long>::max())) {
- warning() << "Count for " << nss->ns() << " (" << uuid.toString() << ") was "
- << oldCount
- << " which is larger than the maximum int64_t value. Not attempting to fix "
- "count during rollback.";
+ LOGV2_WARNING(21639,
+ "Count for {nss_ns} ({uuid}) was {oldCount} which is larger than the "
+ "maximum int64_t value. Not attempting to fix "
+ "count during rollback.",
+ "nss_ns"_attr = nss->ns(),
+ "uuid"_attr = uuid.toString(),
+ "oldCount"_attr = oldCount);
continue;
}
@@ -673,17 +725,28 @@ Status RollbackImpl::_findRecordStoreCounts(OperationContext* opCtx) {
auto newCount = oldCountSigned + countDiff;
if (newCount < 0) {
- warning() << "Attempted to set count for " << nss->ns() << " (" << uuid.toString()
- << ") to " << newCount
- << " but set it to 0 instead. This is likely due to the count previously "
- "becoming inconsistent from an unclean shutdown or a rollback that could "
- "not fix the count correctly. Old count: "
- << oldCount << ". Count change: " << countDiff;
+ LOGV2_WARNING(
+ 21640,
+ "Attempted to set count for {nss_ns} ({uuid}) to {newCount} but set it to 0 "
+ "instead. This is likely due to the count previously "
+ "becoming inconsistent from an unclean shutdown or a rollback that could "
+ "not fix the count correctly. Old count: {oldCount}. Count change: {countDiff}",
+ "nss_ns"_attr = nss->ns(),
+ "uuid"_attr = uuid.toString(),
+ "newCount"_attr = newCount,
+ "oldCount"_attr = oldCount,
+ "countDiff"_attr = countDiff);
newCount = 0;
}
- LOG(2) << "Record count of " << nss->ns() << " (" << uuid.toString()
- << ") before rollback is " << oldCount << ". Setting it to " << newCount
- << ", due to change of " << countDiff;
+ LOGV2_DEBUG(21605,
+ 2,
+ "Record count of {nss_ns} ({uuid}) before rollback is {oldCount}. Setting it "
+ "to {newCount}, due to change of {countDiff}",
+ "nss_ns"_attr = nss->ns(),
+ "uuid"_attr = uuid.toString(),
+ "oldCount"_attr = oldCount,
+ "newCount"_attr = newCount,
+ "countDiff"_attr = countDiff);
_newCounts[uuid] = newCount;
}
@@ -774,15 +837,17 @@ Status RollbackImpl::_processRollbackOp(OperationContext* opCtx, const OplogEntr
idVal == ShardIdentityType::IdName) {
// Check if the creation of the shard identity document is being rolled back.
_observerInfo.shardIdentityRolledBack = true;
- warning() << "Shard identity document rollback detected. oplog op: "
- << redact(oplogEntry.toBSON());
+ LOGV2_WARNING(21641,
+ "Shard identity document rollback detected. oplog op: {oplogEntry}",
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
} else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer &&
opNss == VersionType::ConfigNS) {
// Check if the creation of the config server config version document is being rolled
// back.
_observerInfo.configServerConfigVersionRolledBack = true;
- warning() << "Config version document rollback detected. oplog op: "
- << redact(oplogEntry.toBSON());
+ LOGV2_WARNING(21642,
+ "Config version document rollback detected. oplog op: {oplogEntry}",
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
}
// Rolling back an insert must decrement the count by 1.
@@ -902,7 +967,7 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollbackImpl::_findComm
return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down");
}
- log() << "finding common point";
+ LOGV2(21606, "finding common point");
// We save some aggregate information about all operations that are rolled back, so that we can
// pass this information to the rollback op observer. In most cases, other subsystems do not
@@ -934,7 +999,9 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollbackImpl::_findComm
auto stableTimestamp =
_storageInterface->getLastStableRecoveryTimestamp(opCtx->getServiceContext());
- log() << "Rollback common point is " << commonPointOpTime;
+ LOGV2(21607,
+ "Rollback common point is {commonPointOpTime}",
+ "commonPointOpTime"_attr = commonPointOpTime);
// Rollback common point should be >= the replication commit point.
invariant(commonPointOpTime.getTimestamp() >= lastCommittedOpTime.getTimestamp());
@@ -949,8 +1016,11 @@ StatusWith<RollBackLocalOperations::RollbackCommonPoint> RollbackImpl::_findComm
if (commonPointOpTime.getTimestamp() < *stableTimestamp) {
// This is an fassert rather than an invariant, since it can happen if the server was
// recently upgraded to enableMajorityReadConcern=true.
- severe() << "Common point must be at least stable timestamp, common point: "
- << commonPointOpTime.getTimestamp() << ", stable timestamp: " << *stableTimestamp;
+ LOGV2_FATAL(21644,
+ "Common point must be at least stable timestamp, common point: "
+ "{commonPointOpTime_getTimestamp}, stable timestamp: {stableTimestamp}",
+ "commonPointOpTime_getTimestamp"_attr = commonPointOpTime.getTimestamp(),
+ "stableTimestamp"_attr = *stableTimestamp);
fassertFailedNoTrace(51121);
}
@@ -996,11 +1066,13 @@ Status RollbackImpl::_checkAgainstTimeLimit(
}
} else {
- warning()
- << "Wall clock times on oplog entries not monotonically increasing. This "
- "might indicate a backward clock skew. Time at first oplog after common point: "
- << firstOpWallClockTimeAfterCommonPoint
- << ". Time at top of oplog: " << topOfOplogWallTime;
+ LOGV2_WARNING(
+ 21643,
+ "Wall clock times on oplog entries not monotonically increasing. This "
+ "might indicate a backward clock skew. Time at first oplog after common point: "
+ "{firstOpWallClockTimeAfterCommonPoint}. Time at top of oplog: {topOfOplogWallTime}",
+ "firstOpWallClockTimeAfterCommonPoint"_attr = firstOpWallClockTimeAfterCommonPoint,
+ "topOfOplogWallTime"_attr = topOfOplogWallTime);
}
return Status::OK();
@@ -1016,8 +1088,13 @@ boost::optional<BSONObj> RollbackImpl::_findDocumentById(OperationContext* opCtx
} else if (document.getStatus().code() == ErrorCodes::NoSuchKey) {
return boost::none;
} else {
- severe() << "Rollback failed to read document with " << redact(id) << " in namespace "
- << nss.ns() << " with uuid " << uuid.toString() << causedBy(document.getStatus());
+ LOGV2_FATAL(21645,
+ "Rollback failed to read document with {id} in namespace {nss_ns} with uuid "
+ "{uuid}{causedBy_document_getStatus}",
+ "id"_attr = redact(id),
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid.toString(),
+ "causedBy_document_getStatus"_attr = causedBy(document.getStatus()));
fassert(50751, document.getStatus());
}
@@ -1034,10 +1111,12 @@ Status RollbackImpl::_writeRollbackFiles(OperationContext* opCtx) {
// Drop-pending collections are not visible to rollback via the catalog when they are
// managed by the storage engine. See StorageEngine::supportsPendingDrops().
if (!nss && storageEngine->supportsPendingDrops()) {
- log() << "The collection with UUID " << uuid
- << " is missing in the CollectionCatalog. This could be due to a dropped "
- " collection. Not writing rollback file for uuid "
- << uuid;
+ LOGV2(21608,
+ "The collection with UUID {uuid} is missing in the CollectionCatalog. This could "
+ "be due to a dropped "
+ " collection. Not writing rollback file for uuid {uuid2}",
+ "uuid"_attr = uuid,
+ "uuid2"_attr = uuid);
continue;
}
@@ -1056,8 +1135,12 @@ void RollbackImpl::_writeRollbackFileForNamespace(OperationContext* opCtx,
NamespaceString nss,
const SimpleBSONObjUnorderedSet& idSet) {
RemoveSaver removeSaver(kRollbackRemoveSaverType, uuid.toString(), kRollbackRemoveSaverWhy);
- log() << "Preparing to write deleted documents to a rollback file for collection " << nss.ns()
- << " with uuid " << uuid.toString() << " to " << removeSaver.file().generic_string();
+ LOGV2(21609,
+ "Preparing to write deleted documents to a rollback file for collection {nss_ns} with "
+ "uuid {uuid} to {removeSaver_file_generic_string}",
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid.toString(),
+ "removeSaver_file_generic_string"_attr = removeSaver.file().generic_string());
// The RemoveSaver will save the data files in a directory structure similar to the following:
//
@@ -1106,7 +1189,7 @@ Status RollbackImpl::_triggerOpObserver(OperationContext* opCtx) {
if (_isInShutdown()) {
return Status(ErrorCodes::ShutdownInProgress, "rollback shutting down");
}
- log() << "Triggering the rollback op observer";
+ LOGV2(21610, "Triggering the rollback op observer");
opCtx->getServiceContext()->getOpObserver()->onReplicationRollback(opCtx, _observerInfo);
return Status::OK();
}
@@ -1115,16 +1198,22 @@ void RollbackImpl::_transitionFromRollbackToSecondary(OperationContext* opCtx) {
invariant(opCtx);
invariant(_replicationCoordinator->getMemberState() == MemberState(MemberState::RS_ROLLBACK));
- log() << "transition to SECONDARY";
+ LOGV2(21611, "transition to SECONDARY");
ReplicationStateTransitionLockGuard transitionGuard(opCtx, MODE_X);
auto status = _replicationCoordinator->setFollowerMode(MemberState::RS_SECONDARY);
if (!status.isOK()) {
- severe() << "Failed to transition into " << MemberState(MemberState::RS_SECONDARY)
- << "; expected to be in state " << MemberState(MemberState::RS_ROLLBACK)
- << "; found self in " << _replicationCoordinator->getMemberState()
- << causedBy(status);
+ LOGV2_FATAL(
+ 21646,
+ "Failed to transition into {MemberState_MemberState_RS_SECONDARY}; expected to be in "
+ "state {MemberState_MemberState_RS_ROLLBACK}; found self in "
+ "{replicationCoordinator_getMemberState}{causedBy_status}",
+ "MemberState_MemberState_RS_SECONDARY"_attr = MemberState(MemberState::RS_SECONDARY),
+ "MemberState_MemberState_RS_ROLLBACK"_attr = MemberState(MemberState::RS_ROLLBACK),
+ "replicationCoordinator_getMemberState"_attr =
+ _replicationCoordinator->getMemberState(),
+ "causedBy_status"_attr = causedBy(status));
fassertFailedNoTrace(40408);
}
}
@@ -1150,21 +1239,36 @@ void RollbackImpl::_resetDropPendingState(OperationContext* opCtx) {
}
void RollbackImpl::_summarizeRollback(OperationContext* opCtx) const {
- log() << "Rollback summary:";
- log() << "\tstart time: " << _rollbackStats.startTime;
- log() << "\tend time: " << opCtx->getServiceContext()->getFastClockSource()->now();
- log() << "\tsync source: " << _remoteOplog->hostAndPort().toString();
- log() << "\trollback data file directory: "
- << _rollbackStats.rollbackDataFileDirectory.value_or("none; no files written");
+ LOGV2(21612, "Rollback summary:");
+ LOGV2(21613,
+ "\tstart time: {rollbackStats_startTime}",
+ "rollbackStats_startTime"_attr = _rollbackStats.startTime);
+ LOGV2(21614,
+ "\tend time: {opCtx_getServiceContext_getFastClockSource_now}",
+ "opCtx_getServiceContext_getFastClockSource_now"_attr =
+ opCtx->getServiceContext()->getFastClockSource()->now());
+ LOGV2(21615,
+ "\tsync source: {remoteOplog_hostAndPort}",
+ "remoteOplog_hostAndPort"_attr = _remoteOplog->hostAndPort().toString());
+ LOGV2(21616,
+ "\trollback data file directory: "
+ "{rollbackStats_rollbackDataFileDirectory_value_or_none_no_files_written}",
+ "rollbackStats_rollbackDataFileDirectory_value_or_none_no_files_written"_attr =
+ _rollbackStats.rollbackDataFileDirectory.value_or("none; no files written"));
if (_rollbackStats.rollbackId) {
- log() << "\trollback id: " << *_rollbackStats.rollbackId;
+ LOGV2(21617,
+ "\trollback id: {rollbackStats_rollbackId}",
+ "rollbackStats_rollbackId"_attr = *_rollbackStats.rollbackId);
}
if (_rollbackStats.lastLocalOptime) {
- log() << "\tlast optime on branch of history rolled back: "
- << *_rollbackStats.lastLocalOptime;
+ LOGV2(21618,
+ "\tlast optime on branch of history rolled back: {rollbackStats_lastLocalOptime}",
+ "rollbackStats_lastLocalOptime"_attr = *_rollbackStats.lastLocalOptime);
}
if (_rollbackStats.commonPoint) {
- log() << "\tcommon point optime: " << *_rollbackStats.commonPoint;
+ LOGV2(21619,
+ "\tcommon point optime: {rollbackStats_commonPoint}",
+ "rollbackStats_commonPoint"_attr = *_rollbackStats.commonPoint);
}
if (_rollbackStats.lastLocalWallClockTime &&
_rollbackStats.firstOpWallClockTimeAfterCommonPoint) {
@@ -1175,36 +1279,62 @@ void RollbackImpl::_summarizeRollback(OperationContext* opCtx) const {
unsigned long long diff =
durationCount<Seconds>(Milliseconds(lastWall - firstOpWallClockTimeAfterCommonPoint));
- log() << "\tlast wall clock time on the branch of history rolled back: " << lastWall;
- log() << "\twall clock time of the first operation after the common point: "
- << firstOpWallClockTimeAfterCommonPoint;
- log() << "\tdifference in wall clock times: " << diff << " second(s)";
+ LOGV2(21620,
+ "\tlast wall clock time on the branch of history rolled back: {lastWall}",
+ "lastWall"_attr = lastWall);
+ LOGV2(21621,
+ "\twall clock time of the first operation after the common point: "
+ "{firstOpWallClockTimeAfterCommonPoint}",
+ "firstOpWallClockTimeAfterCommonPoint"_attr = firstOpWallClockTimeAfterCommonPoint);
+ LOGV2(21622, "\tdifference in wall clock times: {diff} second(s)", "diff"_attr = diff);
}
if (_rollbackStats.truncateTimestamp) {
- log() << "\ttruncate timestamp: " << *_rollbackStats.truncateTimestamp;
+ LOGV2(21623,
+ "\ttruncate timestamp: {rollbackStats_truncateTimestamp}",
+ "rollbackStats_truncateTimestamp"_attr = *_rollbackStats.truncateTimestamp);
}
if (_rollbackStats.stableTimestamp) {
- log() << "\tstable timestamp: " << *_rollbackStats.stableTimestamp;
+ LOGV2(21624,
+ "\tstable timestamp: {rollbackStats_stableTimestamp}",
+ "rollbackStats_stableTimestamp"_attr = *_rollbackStats.stableTimestamp);
}
- log() << "\tshard identity document rolled back: " << std::boolalpha
- << _observerInfo.shardIdentityRolledBack;
- log() << "\tconfig server config version document rolled back: " << std::boolalpha
- << _observerInfo.configServerConfigVersionRolledBack;
- log() << "\taffected sessions: " << (_observerInfo.rollbackSessionIds.empty() ? "none" : "");
+ LOGV2(21625,
+ "\tshard identity document rolled back: {observerInfo_shardIdentityRolledBack}",
+ "observerInfo_shardIdentityRolledBack"_attr = _observerInfo.shardIdentityRolledBack);
+ LOGV2(21626,
+ "\tconfig server config version document rolled back: "
+ "{observerInfo_configServerConfigVersionRolledBack}",
+ "observerInfo_configServerConfigVersionRolledBack"_attr =
+ _observerInfo.configServerConfigVersionRolledBack);
+ LOGV2(21627,
+ "\taffected sessions: {observerInfo_rollbackSessionIds_empty_none}",
+ "observerInfo_rollbackSessionIds_empty_none"_attr =
+ (_observerInfo.rollbackSessionIds.empty() ? "none" : ""));
for (const auto& sessionId : _observerInfo.rollbackSessionIds) {
- log() << "\t\t" << sessionId;
+ LOGV2(21628, "\t\t{sessionId}", "sessionId"_attr = sessionId);
}
- log() << "\taffected namespaces: " << (_observerInfo.rollbackNamespaces.empty() ? "none" : "");
+ LOGV2(21629,
+ "\taffected namespaces: {observerInfo_rollbackNamespaces_empty_none}",
+ "observerInfo_rollbackNamespaces_empty_none"_attr =
+ (_observerInfo.rollbackNamespaces.empty() ? "none" : ""));
for (const auto& nss : _observerInfo.rollbackNamespaces) {
- log() << "\t\t" << nss.ns();
+ LOGV2(21630, "\t\t{nss_ns}", "nss_ns"_attr = nss.ns());
}
- log() << "\tcounts of interesting commands rolled back: "
- << (_observerInfo.rollbackCommandCounts.empty() ? "none" : "");
+ LOGV2(21631,
+ "\tcounts of interesting commands rolled back: "
+ "{observerInfo_rollbackCommandCounts_empty_none}",
+ "observerInfo_rollbackCommandCounts_empty_none"_attr =
+ (_observerInfo.rollbackCommandCounts.empty() ? "none" : ""));
for (const auto& entry : _observerInfo.rollbackCommandCounts) {
- log() << "\t\t" << entry.first << ": " << entry.second;
+ LOGV2(21632,
+ "\t\t{entry_first}: {entry_second}",
+ "entry_first"_attr = entry.first,
+ "entry_second"_attr = entry.second);
}
- log() << "\ttotal number of entries rolled back (including no-ops): "
- << _observerInfo.numberOfEntriesObserved;
+ LOGV2(21633,
+ "\ttotal number of entries rolled back (including no-ops): "
+ "{observerInfo_numberOfEntriesObserved}",
+ "observerInfo_numberOfEntriesObserved"_attr = _observerInfo.numberOfEntriesObserved);
}
} // namespace repl
diff --git a/src/mongo/db/repl/rollback_impl_test.cpp b/src/mongo/db/repl/rollback_impl_test.cpp
index e33b10f60cc..fa5b5af0a96 100644
--- a/src/mongo/db/repl/rollback_impl_test.cpp
+++ b/src/mongo/db/repl/rollback_impl_test.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/s/shard_identity_rollback_notifier.h"
#include "mongo/db/s/type_shard_identity.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_config_version.h"
#include "mongo/stdx/thread.h"
#include "mongo/transport/session.h"
@@ -113,10 +114,15 @@ protected:
UUID uuid,
NamespaceString nss,
const SimpleBSONObjUnorderedSet& idSet) final {
- log() << "Simulating writing a rollback file for namespace " << nss.ns() << " with uuid "
- << uuid;
+ LOGV2(21647,
+ "Simulating writing a rollback file for namespace {nss_ns} with uuid {uuid}",
+ "nss_ns"_attr = nss.ns(),
+ "uuid"_attr = uuid);
for (auto&& id : idSet) {
- log() << "Looking up " << id.jsonString(JsonStringFormat::LegacyStrict);
+ LOGV2(21648,
+ "Looking up {id_jsonString_JsonStringFormat_LegacyStrict}",
+ "id_jsonString_JsonStringFormat_LegacyStrict"_attr =
+ id.jsonString(JsonStringFormat::LegacyStrict));
auto document = _findDocumentById(opCtx, uuid, nss, id.firstElement());
if (document) {
_uuidToObjsMap[uuid].push_back(*document);
@@ -531,12 +537,12 @@ TEST_F(RollbackImplTest, RollbackKillsNecessaryOperations) {
}
// We assume that an interrupted opCtx would release its locks.
- unittest::log() << "Both opCtx's marked for kill";
+ LOGV2(21649, "Both opCtx's marked for kill");
ASSERT_EQ(ErrorCodes::InterruptedDueToReplStateChange, writeOpCtx->checkForInterruptNoAssert());
globalWrite = boost::none;
ASSERT_EQ(ErrorCodes::InterruptedDueToReplStateChange, readOpCtx->checkForInterruptNoAssert());
globalRead = boost::none;
- unittest::log() << "Both opCtx's were interrupted";
+ LOGV2(21650, "Both opCtx's were interrupted");
rollbackThread.join();
ASSERT_OK(status);
@@ -879,7 +885,7 @@ DEATH_TEST_F(RollbackImplTest,
_storageInterface->setStableTimestamp(nullptr, Timestamp(1, 1));
auto status = _rollback->runRollback(_opCtx.get());
- unittest::log() << "Mongod did not crash. Status: " << status;
+ LOGV2(21651, "Mongod did not crash. Status: {status}", "status"_attr = status);
MONGO_UNREACHABLE;
}
@@ -1234,7 +1240,7 @@ DEATH_TEST_F(RollbackImplTest,
}
auto status = _rollback->runRollback(_opCtx.get());
- unittest::log() << "mongod did not crash when expected; status: " << status;
+ LOGV2(21652, "mongod did not crash when expected; status: {status}", "status"_attr = status);
}
DEATH_TEST_F(RollbackImplTest,
@@ -1248,7 +1254,7 @@ DEATH_TEST_F(RollbackImplTest,
_storageInterface->setStableTimestamp(nullptr, Timestamp(1, 1));
auto status = _rollback->runRollback(_opCtx.get());
- unittest::log() << "mongod did not crash when expected; status: " << status;
+ LOGV2(21653, "mongod did not crash when expected; status: {status}", "status"_attr = status);
}
TEST_F(RollbackImplTest, RollbackSetsMultipleCollectionCounts) {
@@ -1753,7 +1759,9 @@ DEATH_TEST_F(RollbackImplObserverInfoTest,
Timestamp(2, 2), boost::none, "admin.$cmd", BSON("applyOps" << subops.arr()), 2);
auto status = _rollback->_namespacesForOp_forTest(OplogEntry(applyOpsCmdOp.first));
- unittest::log() << "Mongod did not crash. Status: " << status.getStatus();
+ LOGV2(21654,
+ "Mongod did not crash. Status: {status_getStatus}",
+ "status_getStatus"_attr = status.getStatus());
MONGO_UNREACHABLE;
}
@@ -1855,7 +1863,7 @@ DEATH_TEST_F(RollbackImplObserverInfoTest,
ASSERT_OK(_insertOplogEntry(unknownCmdOp.first));
auto status = _rollback->runRollback(_opCtx.get());
- unittest::log() << "Mongod did not crash. Status: " << status;
+ LOGV2(21655, "Mongod did not crash. Status: {status}", "status"_attr = status);
MONGO_UNREACHABLE;
}
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index 647247a228c..aad64b6db3c 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -77,6 +77,7 @@
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/remove_saver.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/util/exit.h"
@@ -134,9 +135,12 @@ void FixUpInfo::removeRedundantOperations() {
}
bool FixUpInfo::removeRedundantIndexCommands(UUID uuid, std::string indexName) {
- LOG(2) << "Attempting to remove redundant index operations from the set of indexes to create "
- "for collection "
- << uuid << ", for index '" << indexName << "'";
+ LOGV2_DEBUG(21659,
+ 2,
+ "Attempting to remove redundant index operations from the set of indexes to create "
+ "for collection {uuid}, for index '{indexName}'",
+ "uuid"_attr = uuid,
+ "indexName"_attr = indexName);
// See if there are any indexes to create for this collection.
auto indexes = indexesToCreate.find(uuid);
@@ -144,10 +148,12 @@ bool FixUpInfo::removeRedundantIndexCommands(UUID uuid, std::string indexName) {
// There are no indexes to create for this collection UUID, so there are no index creation
// operations to remove.
if (indexes == indexesToCreate.end()) {
- LOG(2)
- << "Collection " << uuid
- << " has no indexes to create. Not removing any index creation operations for index '"
- << indexName << "'.";
+ LOGV2_DEBUG(21660,
+ 2,
+ "Collection {uuid} has no indexes to create. Not removing any index creation "
+ "operations for index '{indexName}'.",
+ "uuid"_attr = uuid,
+ "indexName"_attr = indexName);
return false;
}
@@ -158,15 +164,23 @@ bool FixUpInfo::removeRedundantIndexCommands(UUID uuid, std::string indexName) {
// If this index was not previously added to the set of indexes that need to be created for this
// collection, then we do nothing.
if (indexesToCreateForColl->find(indexName) == indexesToCreateForColl->end()) {
- LOG(2) << "Index '" << indexName << "' was not previously set to be created for collection "
- << uuid << ". Not removing any index creation operations.";
+ LOGV2_DEBUG(21661,
+ 2,
+ "Index '{indexName}' was not previously set to be created for collection "
+ "{uuid}. Not removing any index creation operations.",
+ "indexName"_attr = indexName,
+ "uuid"_attr = uuid);
return false;
}
// This index was previously added to the set of indexes to create for this collection, so we
// remove it from that set.
- LOG(2) << "Index '" << indexName << "' was previously set to be created for collection " << uuid
- << ". Removing this redundant index creation operation.";
+ LOGV2_DEBUG(21662,
+ 2,
+ "Index '{indexName}' was previously set to be created for collection {uuid}. "
+ "Removing this redundant index creation operation.",
+ "indexName"_attr = indexName,
+ "uuid"_attr = uuid);
indexesToCreateForColl->erase(indexName);
// If there are now no remaining indexes to create for this collection, remove it from
// the set of collections that we need to create indexes for.
@@ -206,7 +220,7 @@ Status FixUpInfo::recordDropTargetInfo(const BSONElement& dropTarget,
<< "Unable to roll back renameCollection. Cannot parse "
"dropTarget UUID. Returned status: "
<< redact(dropTargetUUIDStatus.getStatus()) << ", oplog entry: " << redact(obj);
- error() << message;
+ LOGV2_ERROR(21729, "{message}", "message"_attr = message);
return dropTargetUUIDStatus.getStatus();
}
UUID dropTargetUUID = dropTargetUUIDStatus.getValue();
@@ -253,8 +267,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
const OplogEntry oplogEntry(fixedObj);
if (isNestedApplyOpsCommand) {
- LOG(2) << "Updating rollback FixUpInfo for nested applyOps oplog entry: "
- << redact(oplogEntry.toBSON());
+ LOGV2_DEBUG(21663,
+ 2,
+ "Updating rollback FixUpInfo for nested applyOps oplog entry: {oplogEntry}",
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
}
// Extract the op's collection namespace and UUID.
@@ -371,9 +387,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
string indexName;
auto status = bsonExtractStringField(obj, "index", &indexName);
if (!status.isOK()) {
- severe()
- << "Missing index name in dropIndexes operation on rollback, document: "
- << redact(oplogEntry.toBSON());
+ LOGV2_FATAL(21731,
+ "Missing index name in dropIndexes operation on rollback, "
+ "document: {oplogEntry}",
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
throw RSFatalException(
"Missing index name in dropIndexes operation on rollback.");
}
@@ -409,9 +426,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
string indexName;
auto status = bsonExtractStringField(obj, "name", &indexName);
if (!status.isOK()) {
- severe()
- << "Missing index name in createIndexes operation on rollback, document: "
- << redact(oplogEntry.toBSON());
+ LOGV2_FATAL(21732,
+ "Missing index name in createIndexes operation on rollback, "
+ "document: {oplogEntry}",
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
throw RSFatalException(
"Missing index name in createIndexes operation on rollback.");
}
@@ -457,9 +475,12 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
auto buildUUID = indexBuildOplogEntry.buildUUID;
auto existingIt = buildsToRestart.find(buildUUID);
if (existingIt != buildsToRestart.end()) {
- LOG(2) << "Index build that was previously marked to be restarted will now be "
- "dropped due to a rolled-back 'startIndexBuild' oplog entry: "
- << buildUUID;
+ LOGV2_DEBUG(
+ 21664,
+ 2,
+ "Index build that was previously marked to be restarted will now be "
+ "dropped due to a rolled-back 'startIndexBuild' oplog entry: {buildUUID}",
+ "buildUUID"_attr = buildUUID);
buildsToRestart.erase(existingIt);
// If the index build was committed or aborted, we must mark the index as
@@ -500,8 +521,11 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
"UUID is already marked to be restarted: "
<< buildUUID);
- LOG(2) << "Index build will be restarted after a rolled-back 'abortIndexBuild': "
- << buildUUID;
+ LOGV2_DEBUG(21665,
+ 2,
+ "Index build will be restarted after a rolled-back 'abortIndexBuild': "
+ "{buildUUID}",
+ "buildUUID"_attr = buildUUID);
IndexBuildDetails details{*uuid};
for (auto& spec : indexBuildOplogEntry.indexSpecs) {
invariant(spec.isOwned());
@@ -542,8 +566,11 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
"UUID is already marked to be restarted: "
<< buildUUID);
- LOG(2) << "Index build will be restarted after a rolled-back 'commitIndexBuild': "
- << buildUUID;
+ LOGV2_DEBUG(21666,
+ 2,
+ "Index build will be restarted after a rolled-back 'commitIndexBuild': "
+ "{buildUUID}",
+ "buildUUID"_attr = buildUUID);
IndexBuildDetails details{*uuid};
for (auto& spec : indexBuildOplogEntry.indexSpecs) {
@@ -571,7 +598,7 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
if (ns.empty()) {
std::string message = str::stream()
<< "Collection name missing from oplog entry: " << redact(obj);
- log() << message;
+ LOGV2(21667, "{message}", "message"_attr = message);
return Status(ErrorCodes::UnrecoverableRollbackError, message);
}
@@ -650,7 +677,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
}
// Some collMod fields cannot be rolled back, such as the index field.
string message = "Cannot roll back a collMod command: ";
- severe() << message << redact(obj);
+ LOGV2_FATAL(21733,
+ "{message}{obj}",
+ "message"_attr = message,
+ "obj"_attr = redact(obj));
throw RSFatalException(message);
}
return Status::OK();
@@ -687,7 +717,7 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
std::string message = str::stream()
<< "Expected applyOps argument to be an array; found "
<< redact(operations);
- severe() << message;
+ LOGV2_FATAL(21734, "{message}", "message"_attr = message);
return Status(ErrorCodes::UnrecoverableRollbackError, message);
}
for (const auto& subopElement : operations.Array()) {
@@ -695,7 +725,7 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
std::string message = str::stream()
<< "Expected applyOps operations to be of Object type, but found "
<< redact(subopElement);
- severe() << message;
+ LOGV2_FATAL(21735, "{message}", "message"_attr = message);
return Status(ErrorCodes::UnrecoverableRollbackError, message);
}
// In applyOps, the object contains an array of different oplog entries, we
@@ -729,7 +759,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
default: {
std::string message = str::stream() << "Can't roll back this command yet: "
<< " cmdname = " << first.fieldName();
- severe() << message << " document: " << redact(obj);
+ LOGV2_FATAL(21736,
+ "{message} document: {obj}",
+ "message"_attr = message,
+ "obj"_attr = redact(obj));
throw RSFatalException(message);
}
}
@@ -742,7 +775,10 @@ Status rollback_internal::updateFixUpInfoFromLocalOplogEntry(OperationContext* o
doc._id = oplogEntry.getIdElement();
if (doc._id.eoo()) {
std::string message = str::stream() << "Cannot roll back op with no _id. ns: " << nss.ns();
- severe() << message << ", document: " << redact(oplogEntry.toBSON());
+ LOGV2_FATAL(21737,
+ "{message}, document: {oplogEntry}",
+ "message"_attr = message,
+ "oplogEntry"_attr = redact(oplogEntry.toBSON()));
throw RSFatalException(message);
}
fixUpInfo.docsToRefetch.insert(doc);
@@ -779,7 +815,7 @@ void checkRbidAndUpdateMinValid(OperationContext* opCtx,
// RECOVERING state to SECONDARY state until we have reached the minValid oplog entry.
OpTime minValid = fassert(40492, OpTime::parseFromOplogEntry(newMinValidDoc));
- log() << "Setting minvalid to " << minValid;
+ LOGV2(21668, "Setting minvalid to {minValid}", "minValid"_attr = minValid);
// This method is only used with storage engines that do not support recover to stable
// timestamp. As a result, the timestamp on the 'appliedThrough' update does not matter.
@@ -790,8 +826,9 @@ void checkRbidAndUpdateMinValid(OperationContext* opCtx,
if (MONGO_unlikely(rollbackHangThenFailAfterWritingMinValid.shouldFail())) {
// This log output is used in jstests so please leave it.
- log() << "rollback - rollbackHangThenFailAfterWritingMinValid fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21669,
+ "rollback - rollbackHangThenFailAfterWritingMinValid fail point "
+ "enabled. Blocking until fail point is disabled.");
while (MONGO_unlikely(rollbackHangThenFailAfterWritingMinValid.shouldFail())) {
invariant(!globalInShutdownDeprecated()); // It is an error to shutdown while enabled.
mongo::sleepsecs(1);
@@ -813,8 +850,10 @@ void dropIndex(OperationContext* opCtx,
auto indexDescriptor =
indexCatalog->findIndexByName(opCtx, indexName, includeUnfinishedIndexes);
if (!indexDescriptor) {
- warning() << "Rollback failed to drop index " << indexName << " in " << nss.toString()
- << ": index not found.";
+ LOGV2_WARNING(21725,
+ "Rollback failed to drop index {indexName} in {nss}: index not found.",
+ "indexName"_attr = indexName,
+ "nss"_attr = nss.toString());
return;
}
WriteUnitOfWork wunit(opCtx);
@@ -822,14 +861,20 @@ void dropIndex(OperationContext* opCtx,
if (entry->isReady(opCtx)) {
auto status = indexCatalog->dropIndex(opCtx, indexDescriptor);
if (!status.isOK()) {
- severe() << "Rollback failed to drop index " << indexName << " in " << nss.toString()
- << ": " << redact(status);
+ LOGV2_FATAL(21738,
+ "Rollback failed to drop index {indexName} in {nss}: {status}",
+ "indexName"_attr = indexName,
+ "nss"_attr = nss.toString(),
+ "status"_attr = redact(status));
}
} else {
auto status = indexCatalog->dropUnfinishedIndex(opCtx, indexDescriptor);
if (!status.isOK()) {
- severe() << "Rollback failed to drop unfinished index " << indexName << " in "
- << nss.toString() << ": " << redact(status);
+ LOGV2_FATAL(21739,
+ "Rollback failed to drop unfinished index {indexName} in {nss}: {status}",
+ "indexName"_attr = indexName,
+ "nss"_attr = nss.toString(),
+ "status"_attr = redact(status));
}
}
wunit.commit();
@@ -849,29 +894,43 @@ void rollbackCreateIndexes(OperationContext* opCtx, UUID uuid, std::set<std::str
// If we cannot find the collection, we skip over dropping the index.
if (!collection) {
- LOG(2) << "Cannot find the collection with uuid: " << uuid.toString()
- << " in CollectionCatalog during roll back of a createIndexes command.";
+ LOGV2_DEBUG(21670,
+ 2,
+ "Cannot find the collection with uuid: {uuid} in CollectionCatalog during roll "
+ "back of a createIndexes command.",
+ "uuid"_attr = uuid.toString());
return;
}
// If we cannot find the index catalog, we skip over dropping the index.
auto indexCatalog = collection->getIndexCatalog();
if (!indexCatalog) {
- LOG(2) << "Cannot find the index catalog in collection with uuid: " << uuid.toString()
- << " during roll back of a createIndexes command.";
+ LOGV2_DEBUG(21671,
+ 2,
+ "Cannot find the index catalog in collection with uuid: {uuid} during roll "
+ "back of a createIndexes command.",
+ "uuid"_attr = uuid.toString());
return;
}
for (auto itIndex = indexNames.begin(); itIndex != indexNames.end(); itIndex++) {
const string& indexName = *itIndex;
- log() << "Dropping index in rollback for collection: " << *nss << ", UUID: " << uuid
- << ", index: " << indexName;
+ LOGV2(21672,
+ "Dropping index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid,
+ "indexName"_attr = indexName);
dropIndex(opCtx, indexCatalog, indexName, *nss);
- LOG(1) << "Dropped index in rollback for collection: " << *nss << ", UUID: " << uuid
- << ", index: " << indexName;
+ LOGV2_DEBUG(
+ 21673,
+ 1,
+ "Dropped index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid,
+ "indexName"_attr = indexName);
}
}
@@ -891,8 +950,11 @@ void rollbackDropIndexes(OperationContext* opCtx,
// If we cannot find the collection, we skip over dropping the index.
if (!collection) {
- LOG(2) << "Cannot find the collection with uuid: " << uuid.toString()
- << "in CollectionCatalog during roll back of a dropIndexes command.";
+ LOGV2_DEBUG(21674,
+ 2,
+ "Cannot find the collection with uuid: {uuid}in CollectionCatalog during roll "
+ "back of a dropIndexes command.",
+ "uuid"_attr = uuid.toString());
return;
}
@@ -900,13 +962,21 @@ void rollbackDropIndexes(OperationContext* opCtx,
const string indexName = itIndex->first;
BSONObj indexSpec = itIndex->second;
- log() << "Creating index in rollback for collection: " << *nss << ", UUID: " << uuid
- << ", index: " << indexName;
+ LOGV2(21675,
+ "Creating index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid,
+ "indexName"_attr = indexName);
createIndexForApplyOps(opCtx, indexSpec, *nss, OplogApplication::Mode::kRecovering);
- LOG(1) << "Created index in rollback for collection: " << *nss << ", UUID: " << uuid
- << ", index: " << indexName;
+ LOGV2_DEBUG(
+ 21676,
+ 1,
+ "Created index in rollback for collection: {nss}, UUID: {uuid}, index: {indexName}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid,
+ "indexName"_attr = indexName);
}
}
@@ -919,10 +989,14 @@ void dropCollection(OperationContext* opCtx,
Database* db) {
if (RollbackImpl::shouldCreateDataFiles()) {
RemoveSaver removeSaver("rollback", "", collection->uuid().toString());
- log() << "Rolling back createCollection on " << nss
- << ": Preparing to write documents to a rollback file for a collection " << nss
- << " with uuid " << collection->uuid() << " to "
- << removeSaver.file().generic_string();
+ LOGV2(21677,
+ "Rolling back createCollection on {nss}: Preparing to write documents to a rollback "
+ "file for a collection {nss2} with uuid {collection_uuid} to "
+ "{removeSaver_file_generic_string}",
+ "nss"_attr = nss,
+ "nss2"_attr = nss,
+ "collection_uuid"_attr = collection->uuid(),
+ "removeSaver_file_generic_string"_attr = removeSaver.file().generic_string());
// Performs a collection scan and writes all documents in the collection to disk
// in order to keep an archive of items that were rolled back.
@@ -933,8 +1007,11 @@ void dropCollection(OperationContext* opCtx,
while (PlanExecutor::ADVANCED == (execState = exec->getNext(&curObj, nullptr))) {
auto status = removeSaver.goingToDelete(curObj);
if (!status.isOK()) {
- severe() << "Rolling back createCollection on " << nss
- << " failed to write document to remove saver file: " << redact(status);
+ LOGV2_FATAL(21740,
+ "Rolling back createCollection on {nss} failed to write document to "
+ "remove saver file: {status}",
+ "nss"_attr = nss,
+ "status"_attr = redact(status));
throw RSFatalException(
"Rolling back createCollection. Failed to write document to remove saver "
"file.");
@@ -951,13 +1028,18 @@ void dropCollection(OperationContext* opCtx,
if (execState == PlanExecutor::FAILURE &&
WorkingSetCommon::isValidStatusMemberObject(curObj)) {
Status errorStatus = WorkingSetCommon::getMemberObjectStatus(curObj);
- severe() << "Rolling back createCollection on " << nss << " failed with "
- << redact(errorStatus) << ". A full resync is necessary.";
+ LOGV2_FATAL(21741,
+ "Rolling back createCollection on {nss} failed with {errorStatus}. A "
+ "full resync is necessary.",
+ "nss"_attr = nss,
+ "errorStatus"_attr = redact(errorStatus));
throw RSFatalException(
"Rolling back createCollection failed. A full resync is necessary.");
} else {
- severe() << "Rolling back createCollection on " << nss
- << " failed. A full resync is necessary.";
+ LOGV2_FATAL(
+ 21742,
+ "Rolling back createCollection on {nss} failed. A full resync is necessary.",
+ "nss"_attr = nss);
throw RSFatalException(
"Rolling back createCollection failed. A full resync is necessary.");
}
@@ -992,17 +1074,27 @@ void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Datab
// namespace.
auto tmpNameResult = db->makeUniqueCollectionNamespace(opCtx, "rollback.tmp%%%%%");
if (!tmpNameResult.isOK()) {
- severe() << "Unable to generate temporary namespace to rename collection " << info.renameTo
- << " out of the way. " << tmpNameResult.getStatus().reason();
+ LOGV2_FATAL(21743,
+ "Unable to generate temporary namespace to rename collection {info_renameTo} "
+ "out of the way. {tmpNameResult_getStatus_reason}",
+ "info_renameTo"_attr = info.renameTo,
+ "tmpNameResult_getStatus_reason"_attr = tmpNameResult.getStatus().reason());
throw RSFatalException(
"Unable to generate temporary namespace to rename collection out of the way.");
}
const auto& tempNss = tmpNameResult.getValue();
- LOG(2) << "Attempted to rename collection from " << info.renameFrom << " to " << info.renameTo
- << " but " << info.renameTo << " exists already. Temporarily renaming collection "
- << info.renameTo << " with UUID " << collection->uuid() << " out of the way to "
- << tempNss;
+ LOGV2_DEBUG(21678,
+ 2,
+ "Attempted to rename collection from {info_renameFrom} to {info_renameTo} but "
+ "{info_renameTo2} exists already. Temporarily renaming collection {info_renameTo3} "
+ "with UUID {collection_uuid} out of the way to {tempNss}",
+ "info_renameFrom"_attr = info.renameFrom,
+ "info_renameTo"_attr = info.renameTo,
+ "info_renameTo2"_attr = info.renameTo,
+ "info_renameTo3"_attr = info.renameTo,
+ "collection_uuid"_attr = collection->uuid(),
+ "tempNss"_attr = tempNss);
// Renaming the collection that was clashing with the attempted rename
// operation to a different collection name.
@@ -1010,8 +1102,10 @@ void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Datab
auto renameStatus = renameCollectionForRollback(opCtx, tempNss, uuid);
if (!renameStatus.isOK()) {
- severe() << "Unable to rename collection " << info.renameTo << " out of the way to "
- << tempNss;
+ LOGV2_FATAL(21744,
+ "Unable to rename collection {info_renameTo} out of the way to {tempNss}",
+ "info_renameTo"_attr = info.renameTo,
+ "tempNss"_attr = tempNss);
throw RSFatalException("Unable to rename collection out of the way");
}
}
@@ -1023,8 +1117,12 @@ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollecti
auto dbName = info.renameFrom.db();
- log() << "Attempting to rename collection with UUID: " << uuid << ", from: " << info.renameFrom
- << ", to: " << info.renameTo;
+ LOGV2(21679,
+ "Attempting to rename collection with UUID: {uuid}, from: {info_renameFrom}, to: "
+ "{info_renameTo}",
+ "uuid"_attr = uuid,
+ "info_renameFrom"_attr = info.renameFrom,
+ "info_renameTo"_attr = info.renameTo);
Lock::DBLock dbLock(opCtx, dbName, MODE_X);
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->openDb(opCtx, dbName);
@@ -1044,20 +1142,30 @@ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollecti
status = renameCollectionForRollback(opCtx, info.renameTo, uuid);
if (!status.isOK()) {
- severe() << "Rename collection failed to roll back twice. We were unable to rename "
- << "collection " << info.renameFrom << " to " << info.renameTo << ". "
- << status.toString();
+ LOGV2_FATAL(21745,
+ "Rename collection failed to roll back twice. We were unable to rename "
+ "collection {info_renameFrom} to {info_renameTo}. {status}",
+ "info_renameFrom"_attr = info.renameFrom,
+ "info_renameTo"_attr = info.renameTo,
+ "status"_attr = status.toString());
throw RSFatalException(
"Rename collection failed to roll back twice. We were unable to rename "
"the collection.");
}
} else if (!status.isOK()) {
- severe() << "Unable to roll back renameCollection command: " << status.toString();
+ LOGV2_FATAL(21746,
+ "Unable to roll back renameCollection command: {status}",
+ "status"_attr = status.toString());
throw RSFatalException("Unable to rollback renameCollection command");
}
- LOG(1) << "Renamed collection with UUID: " << uuid << ", from: " << info.renameFrom
- << ", to: " << info.renameTo;
+ LOGV2_DEBUG(
+ 21680,
+ 1,
+ "Renamed collection with UUID: {uuid}, from: {info_renameFrom}, to: {info_renameTo}",
+ "uuid"_attr = uuid,
+ "info_renameFrom"_attr = info.renameFrom,
+ "info_renameTo"_attr = info.renameTo);
}
Status _syncRollback(OperationContext* opCtx,
@@ -1071,7 +1179,10 @@ Status _syncRollback(OperationContext* opCtx,
FixUpInfo how;
how.localTopOfOplog = replCoord->getMyLastAppliedOpTime();
- log() << "Starting rollback. Sync source: " << rollbackSource.getSource() << rsLog;
+ LOGV2_OPTIONS(21681,
+ {logv2::LogTag::kRS},
+ "Starting rollback. Sync source: {rollbackSource_getSource}",
+ "rollbackSource_getSource"_attr = rollbackSource.getSource());
how.rbid = rollbackSource.getRollbackId();
uassert(
40506, "Upstream node rolled back. Need to retry our rollback.", how.rbid == requiredRBID);
@@ -1085,7 +1196,7 @@ Status _syncRollback(OperationContext* opCtx,
// they may be made redundant by a rolled-back startIndexBuild oplog entry.
how.indexBuildsToRestart.insert(abortedIndexBuilds.begin(), abortedIndexBuilds.end());
- log() << "Finding the Common Point";
+ LOGV2(21682, "Finding the Common Point");
try {
auto processOperationForFixUp = [&how, &opCtx, &localOplog](const BSONObj& operation) {
@@ -1122,7 +1233,7 @@ Status _syncRollback(OperationContext* opCtx,
OpTime lastCommittedOpTime = replCoord->getLastCommittedOpTime();
OpTime committedSnapshot = replCoord->getCurrentCommittedSnapshotOpTime();
- log() << "Rollback common point is " << commonPoint;
+ LOGV2(21683, "Rollback common point is {commonPoint}", "commonPoint"_attr = commonPoint);
// Rollback common point should be >= the replication commit point.
invariant(commonPoint.getTimestamp() >= lastCommittedOpTime.getTimestamp());
@@ -1140,8 +1251,9 @@ Status _syncRollback(OperationContext* opCtx,
syncFixUp(opCtx, how, rollbackSource, replCoord, replicationProcess);
if (MONGO_unlikely(rollbackExitEarlyAfterCollectionDrop.shouldFail())) {
- log() << "rollbackExitEarlyAfterCollectionDrop fail point enabled. Returning early "
- "until fail point is disabled.";
+ LOGV2(21684,
+ "rollbackExitEarlyAfterCollectionDrop fail point enabled. Returning early "
+ "until fail point is disabled.");
return Status(ErrorCodes::NamespaceNotFound,
str::stream() << "Failing rollback because "
"rollbackExitEarlyAfterCollectionDrop fail point "
@@ -1164,8 +1276,9 @@ Status _syncRollback(OperationContext* opCtx,
if (MONGO_unlikely(rollbackHangBeforeFinish.shouldFail())) {
// This log output is used in js tests so please leave it.
- log() << "rollback - rollbackHangBeforeFinish fail point "
- "enabled. Blocking until fail point is disabled.";
+ LOGV2(21685,
+ "rollback - rollbackHangBeforeFinish fail point "
+ "enabled. Blocking until fail point is disabled.");
while (MONGO_unlikely(rollbackHangBeforeFinish.shouldFail())) {
invariant(!globalInShutdownDeprecated()); // It is an error to shutdown while enabled.
mongo::sleepsecs(1);
@@ -1191,7 +1304,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// Fetches all the goodVersions of each document from the current sync source.
unsigned long long numFetched = 0;
- log() << "Starting refetching documents";
+ LOGV2(21686, "Starting refetching documents");
for (auto&& doc : fixUpInfo.docsToRefetch) {
invariant(!doc._id.eoo()); // This is checked when we insert to the set.
@@ -1201,10 +1314,18 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
try {
if (nss) {
- LOG(2) << "Refetching document, collection: " << *nss << ", UUID: " << uuid << ", "
- << redact(doc._id);
+ LOGV2_DEBUG(21687,
+ 2,
+ "Refetching document, collection: {nss}, UUID: {uuid}, {doc_id}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid,
+ "doc_id"_attr = redact(doc._id));
} else {
- LOG(2) << "Refetching document, UUID: " << uuid << ", " << redact(doc._id);
+ LOGV2_DEBUG(21688,
+ 2,
+ "Refetching document, UUID: {uuid}, {doc_id}",
+ "uuid"_attr = uuid,
+ "doc_id"_attr = redact(doc._id));
}
// TODO : Slow. Lots of round trips.
numFetched++;
@@ -1253,27 +1374,34 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
ex.code() == ErrorCodes::NamespaceNotFound)
continue;
- log() << "Rollback couldn't re-fetch from uuid: " << uuid << " _id: " << redact(doc._id)
- << ' ' << numFetched << '/' << fixUpInfo.docsToRefetch.size() << ": "
- << redact(ex);
+ LOGV2(21689,
+ "Rollback couldn't re-fetch from uuid: {uuid} _id: {doc_id} "
+ "{numFetched}/{fixUpInfo_docsToRefetch_size}: {ex}",
+ "uuid"_attr = uuid,
+ "doc_id"_attr = redact(doc._id),
+ "numFetched"_attr = numFetched,
+ "fixUpInfo_docsToRefetch_size"_attr = fixUpInfo.docsToRefetch.size(),
+ "ex"_attr = redact(ex));
throw;
}
}
- log() << "Finished refetching documents. Total size of documents refetched: "
- << goodVersions.size();
+ LOGV2(21690,
+ "Finished refetching documents. Total size of documents refetched: {goodVersions_size}",
+ "goodVersions_size"_attr = goodVersions.size());
// We must start taking unstable checkpoints before rolling back oplog entries. Otherwise, a
// stable checkpoint could include the fixup write (since it is untimestamped) but not the write
// being rolled back (if it is after the stable timestamp), leading to inconsistent state. An
// unstable checkpoint will include both writes.
if (!serverGlobalParams.enableMajorityReadConcern) {
- log() << "Setting initialDataTimestamp to 0 so that we start taking unstable checkpoints.";
+ LOGV2(21691,
+ "Setting initialDataTimestamp to 0 so that we start taking unstable checkpoints.");
opCtx->getServiceContext()->getStorageEngine()->setInitialDataTimestamp(
Timestamp::kAllowUnstableCheckpointsSentinel);
}
- log() << "Checking the RollbackID and updating the MinValid if necessary";
+ LOGV2(21692, "Checking the RollbackID and updating the MinValid if necessary");
checkRbidAndUpdateMinValid(opCtx, fixUpInfo.rbid, rollbackSource, replicationProcess);
@@ -1288,7 +1416,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// indexes.
// We drop indexes before renaming collections so that if a collection name gets longer,
// any indexes with names that are now too long will already be dropped.
- log() << "Rolling back createIndexes and startIndexBuild operations";
+ LOGV2(21693, "Rolling back createIndexes and startIndexBuild operations");
for (auto it = fixUpInfo.indexesToDrop.begin(); it != fixUpInfo.indexesToDrop.end(); it++) {
UUID uuid = it->first;
@@ -1301,7 +1429,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// rolled-back, but the unfinished index still exists in the catalog. Drop these before any
// collection drops, because one of the preconditions of dropping a collection is that there are
// no unfinished indxes.
- log() << "Rolling back unfinished startIndexBuild operations";
+ LOGV2(21694, "Rolling back unfinished startIndexBuild operations");
for (auto index : fixUpInfo.unfinishedIndexesToDrop) {
UUID uuid = index.first;
std::set<std::string> indexNames = index.second;
@@ -1309,7 +1437,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
rollbackCreateIndexes(opCtx, uuid, indexNames);
}
- log() << "Dropping collections to roll back create operations";
+ LOGV2(21695, "Dropping collections to roll back create operations");
// Drops collections before updating individual documents. We drop these collections before
// rolling back any other commands to prevent namespace collisions that may occur
@@ -1332,9 +1460,12 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// Do not attempt to acquire the database lock with an empty namespace. We should survive
// an attempt to drop a non-existent collection.
if (!nss) {
- log() << "This collection does not exist, UUID: " << uuid;
+ LOGV2(21696, "This collection does not exist, UUID: {uuid}", "uuid"_attr = uuid);
} else {
- log() << "Dropping collection: " << *nss << ", UUID: " << uuid;
+ LOGV2(21697,
+ "Dropping collection: {nss}, UUID: {uuid}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid);
AutoGetDb dbLock(opCtx, nss->db(), MODE_X);
Database* db = dbLock.getDb();
@@ -1342,7 +1473,11 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
Collection* collection =
CollectionCatalog::get(opCtx).lookupCollectionByUUID(opCtx, uuid);
dropCollection(opCtx, *nss, collection, db);
- LOG(1) << "Dropped collection: " << *nss << ", UUID: " << uuid;
+ LOGV2_DEBUG(21698,
+ 1,
+ "Dropped collection: {nss}, UUID: {uuid}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid);
}
}
}
@@ -1352,7 +1487,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
}
// Rolling back renameCollection commands.
- log() << "Rolling back renameCollection commands and collection drop commands.";
+ LOGV2(21699, "Rolling back renameCollection commands and collection drop commands.");
for (auto it = fixUpInfo.collectionsToRename.begin(); it != fixUpInfo.collectionsToRename.end();
it++) {
@@ -1363,16 +1498,21 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
rollbackRenameCollection(opCtx, uuid, info);
}
- log() << "Rolling back collections pending being dropped: Removing them from the list of "
- "drop-pending collections in the DropPendingCollectionReaper.";
+ LOGV2(21700,
+ "Rolling back collections pending being dropped: Removing them from the list of "
+ "drop-pending collections in the DropPendingCollectionReaper.");
// Roll back any drop-pending collections. This must be done first so that the collection
// exists when we attempt to resync its metadata or insert documents into it.
for (const auto& collPair : fixUpInfo.collectionsToRemoveFromDropPendingCollections) {
const auto& optime = collPair.second.first;
const auto& collectionNamespace = collPair.second.second;
- LOG(1) << "Rolling back collection pending being dropped for OpTime: " << optime
- << ", collection: " << collectionNamespace;
+ LOGV2_DEBUG(21701,
+ 1,
+ "Rolling back collection pending being dropped for OpTime: {optime}, "
+ "collection: {collectionNamespace}",
+ "optime"_attr = optime,
+ "collectionNamespace"_attr = collectionNamespace);
DropPendingCollectionReaper::get(opCtx)->rollBackDropPendingCollection(
opCtx, optime, collectionNamespace);
}
@@ -1391,7 +1531,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
CollectionCatalog::get(opCtx).lookupNSSByUUID(opCtx, uuid);
invariant(nss);
- log() << "Resyncing collection metadata for collection: " << *nss << ", UUID: " << uuid;
+ LOGV2(21702,
+ "Resyncing collection metadata for collection: {nss}, UUID: {uuid}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid);
Lock::DBLock dbLock(opCtx, nss->db(), MODE_X);
@@ -1411,9 +1554,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// is rolled back upstream and we restart, we expect to still have the
// collection.
- log() << nss->ns()
- << " not found on remote host, so we do not roll back collmod "
- "operation. Instead, we will drop the collection soon.";
+ LOGV2(21703,
+ "{nss_ns} not found on remote host, so we do not roll back collmod "
+ "operation. Instead, we will drop the collection soon.",
+ "nss_ns"_attr = nss->ns());
continue;
}
@@ -1460,22 +1604,29 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
wuow.commit();
- LOG(1) << "Resynced collection metadata for collection: " << *nss << ", UUID: " << uuid
- << ", with: " << redact(info) << ", to: "
- << redact(DurableCatalog::get(opCtx)
- ->getCollectionOptions(opCtx, collection->getCatalogId())
- .toBSON());
+ LOGV2_DEBUG(
+ 21704,
+ 1,
+ "Resynced collection metadata for collection: {nss}, UUID: {uuid}, with: {info}, "
+ "to: {DurableCatalog_get_opCtx_getCollectionOptions_opCtx_collection_getCatalogId}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid,
+ "info"_attr = redact(info),
+ "DurableCatalog_get_opCtx_getCollectionOptions_opCtx_collection_getCatalogId"_attr =
+ redact(DurableCatalog::get(opCtx)
+ ->getCollectionOptions(opCtx, collection->getCatalogId())
+ .toBSON()));
}
// Since we read from the sync source to retrieve the metadata of the
// collection, we must check if the sync source rolled back as well as update
// minValid if necessary.
- log() << "Rechecking the Rollback ID and minValid";
+ LOGV2(21705, "Rechecking the Rollback ID and minValid");
checkRbidAndUpdateMinValid(opCtx, fixUpInfo.rbid, rollbackSource, replicationProcess);
}
// Rolls back dropIndexes commands by re-creating the indexes that were dropped.
- log() << "Rolling back dropIndexes commands.";
+ LOGV2(21706, "Rolling back dropIndexes commands.");
for (auto it = fixUpInfo.indexesToCreate.begin(); it != fixUpInfo.indexesToCreate.end(); it++) {
UUID uuid = it->first;
@@ -1484,12 +1635,13 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
rollbackDropIndexes(opCtx, uuid, indexNames);
}
- log() << "Restarting rolled-back committed or aborted index builds.";
+ LOGV2(21707, "Restarting rolled-back committed or aborted index builds.");
IndexBuildsCoordinator::get(opCtx)->restartIndexBuildsForRecovery(
opCtx, fixUpInfo.indexBuildsToRestart);
- log() << "Deleting and updating documents to roll back insert, update and remove "
- "operations";
+ LOGV2(21708,
+ "Deleting and updating documents to roll back insert, update and remove "
+ "operations");
unsigned deletes = 0, updates = 0;
time_t lastProgressUpdate = time(nullptr);
time_t progressUpdateGap = 10;
@@ -1510,18 +1662,24 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
if (RollbackImpl::shouldCreateDataFiles()) {
removeSaver = std::make_unique<RemoveSaver>("rollback", "", uuid.toString());
- log() << "Preparing to write deleted documents to a rollback file for collection "
- << *nss << " with uuid " << uuid.toString() << " to "
- << removeSaver->file().generic_string();
+ LOGV2(21709,
+ "Preparing to write deleted documents to a rollback file for collection {nss} "
+ "with uuid {uuid} to {removeSaver_file_generic_string}",
+ "nss"_attr = *nss,
+ "uuid"_attr = uuid.toString(),
+ "removeSaver_file_generic_string"_attr = removeSaver->file().generic_string());
}
const auto& goodVersionsByDocID = nsAndGoodVersionsByDocID.second;
for (const auto& idAndDoc : goodVersionsByDocID) {
time_t now = time(nullptr);
if (now - lastProgressUpdate > progressUpdateGap) {
- log() << deletes << " delete and " << updates
- << " update operations processed out of " << goodVersions.size()
- << " total operations.";
+ LOGV2(21710,
+ "{deletes} delete and {updates} update operations processed out of "
+ "{goodVersions_size} total operations.",
+ "deletes"_attr = deletes,
+ "updates"_attr = updates,
+ "goodVersions_size"_attr = goodVersions.size());
lastProgressUpdate = now;
}
const DocID& doc = idAndDoc.first;
@@ -1546,21 +1704,31 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
if (found) {
auto status = removeSaver->goingToDelete(obj);
if (!status.isOK()) {
- severe() << "Rollback cannot write document in namespace " << nss->ns()
- << " to archive file: " << redact(status);
+ LOGV2_FATAL(21747,
+ "Rollback cannot write document in namespace {nss_ns} to "
+ "archive file: {status}",
+ "nss_ns"_attr = nss->ns(),
+ "status"_attr = redact(status));
throw RSFatalException(str::stream()
<< "Rollback cannot write document in namespace "
<< nss->ns() << " to archive file.");
}
} else {
- error() << "Rollback cannot find object: " << pattern << " in namespace "
- << nss->ns();
+ LOGV2_ERROR(21730,
+ "Rollback cannot find object: {pattern} in namespace {nss_ns}",
+ "pattern"_attr = pattern,
+ "nss_ns"_attr = nss->ns());
}
}
if (idAndDoc.second.isEmpty()) {
- LOG(2) << "Deleting document with: " << redact(doc._id)
- << ", from collection: " << doc.ns << ", with UUID: " << uuid;
+ LOGV2_DEBUG(21711,
+ 2,
+ "Deleting document with: {doc_id}, from collection: {doc_ns}, with "
+ "UUID: {uuid}",
+ "doc_id"_attr = redact(doc._id),
+ "doc_ns"_attr = doc.ns,
+ "uuid"_attr = uuid);
// If the document could not be found on the primary, deletes the document.
// TODO 1.6 : can't delete from a capped collection. Need to handle that
// here.
@@ -1580,8 +1748,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
const auto findOneStart = clock->now();
RecordId loc = Helpers::findOne(opCtx, collection, pattern, false);
if (clock->now() - findOneStart > Milliseconds(200))
- warning() << "Roll back slow no _id index for " << nss->ns()
- << " perhaps?";
+ LOGV2_WARNING(
+ 21726,
+ "Roll back slow no _id index for {nss_ns} perhaps?",
+ "nss_ns"_attr = nss->ns());
// Would be faster but requires index:
// RecordId loc = Helpers::findById(nsd, pattern);
if (!loc.isNull()) {
@@ -1614,11 +1784,15 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// inconsistent. We rely on age-out to make these problems go away
// eventually.
- warning() << "Ignoring failure to roll back change to capped "
- << "collection " << nss->ns() << " with _id "
- << redact(idAndDoc.first._id.toString(
- /*includeFieldName*/ false))
- << ": " << redact(e);
+ LOGV2_WARNING(21727,
+ "Ignoring failure to roll back change to capped "
+ "collection {nss_ns} with _id "
+ "{idAndDoc_first_id_includeFieldName_false}: {e}",
+ "nss_ns"_attr = nss->ns(),
+ "idAndDoc_first_id_includeFieldName_false"_attr =
+ redact(idAndDoc.first._id.toString(
+ /*includeFieldName*/ false)),
+ "e"_attr = redact(e));
}
} else {
deleteObjects(opCtx,
@@ -1630,9 +1804,14 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
}
}
} else {
- LOG(2) << "Updating document with: " << redact(doc._id)
- << ", from collection: " << doc.ns << ", UUID: " << uuid
- << ", to: " << redact(idAndDoc.second);
+ LOGV2_DEBUG(21712,
+ 2,
+ "Updating document with: {doc_id}, from collection: {doc_ns}, "
+ "UUID: {uuid}, to: {idAndDoc_second}",
+ "doc_id"_attr = redact(doc._id),
+ "doc_ns"_attr = doc.ns,
+ "uuid"_attr = uuid,
+ "idAndDoc_second"_attr = redact(idAndDoc.second));
// TODO faster...
updates++;
@@ -1646,23 +1825,31 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
update(opCtx, ctx.db(), request);
}
} catch (const DBException& e) {
- log() << "Exception in rollback ns:" << nss->ns() << ' ' << pattern.toString()
- << ' ' << redact(e) << " ndeletes:" << deletes;
+ LOGV2(21713,
+ "Exception in rollback ns:{nss_ns} {pattern} {e} ndeletes:{deletes}",
+ "nss_ns"_attr = nss->ns(),
+ "pattern"_attr = pattern.toString(),
+ "e"_attr = redact(e),
+ "deletes"_attr = deletes);
throw;
}
}
}
- log() << "Rollback deleted " << deletes << " documents and updated " << updates
- << " documents.";
+ LOGV2(21714,
+ "Rollback deleted {deletes} documents and updated {updates} documents.",
+ "deletes"_attr = deletes,
+ "updates"_attr = updates);
if (!serverGlobalParams.enableMajorityReadConcern) {
// When majority read concern is disabled, the stable timestamp may be ahead of the common
// point. Force the stable timestamp back to the common point, to allow writes after the
// common point.
const bool force = true;
- log() << "Forcing the stable timestamp to the common point: "
- << fixUpInfo.commonPoint.getTimestamp();
+ LOGV2(21715,
+ "Forcing the stable timestamp to the common point: "
+ "{fixUpInfo_commonPoint_getTimestamp}",
+ "fixUpInfo_commonPoint_getTimestamp"_attr = fixUpInfo.commonPoint.getTimestamp());
opCtx->getServiceContext()->getStorageEngine()->setStableTimestamp(
fixUpInfo.commonPoint.getTimestamp(), force);
@@ -1676,22 +1863,28 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
auto syncSourceTopOfOplog = OpTime::parseFromOplogEntry(rollbackSource.getLastOperation())
.getValue()
.getTimestamp();
- log() << "Setting initialDataTimestamp to the max of local top of oplog and sync source "
- "top of oplog. Local top of oplog: "
- << fixUpInfo.localTopOfOplog.getTimestamp()
- << ", sync source top of oplog: " << syncSourceTopOfOplog;
+ LOGV2(21716,
+ "Setting initialDataTimestamp to the max of local top of oplog and sync source "
+ "top of oplog. Local top of oplog: {fixUpInfo_localTopOfOplog_getTimestamp}, sync "
+ "source top of oplog: {syncSourceTopOfOplog}",
+ "fixUpInfo_localTopOfOplog_getTimestamp"_attr =
+ fixUpInfo.localTopOfOplog.getTimestamp(),
+ "syncSourceTopOfOplog"_attr = syncSourceTopOfOplog);
opCtx->getServiceContext()->getStorageEngine()->setInitialDataTimestamp(
std::max(fixUpInfo.localTopOfOplog.getTimestamp(), syncSourceTopOfOplog));
// Take an unstable checkpoint to ensure that all of the writes performed during rollback
// are persisted to disk before truncating oplog.
- log() << "Waiting for an unstable checkpoint";
+ LOGV2(21717, "Waiting for an unstable checkpoint");
const bool stableCheckpoint = false;
opCtx->recoveryUnit()->waitUntilUnjournaledWritesDurable(opCtx, stableCheckpoint);
}
- log() << "Truncating the oplog at " << fixUpInfo.commonPoint.toString() << " ("
- << fixUpInfo.commonPointOurDiskloc << "), non-inclusive";
+ LOGV2(21718,
+ "Truncating the oplog at {fixUpInfo_commonPoint} ({fixUpInfo_commonPointOurDiskloc}), "
+ "non-inclusive",
+ "fixUpInfo_commonPoint"_attr = fixUpInfo.commonPoint.toString(),
+ "fixUpInfo_commonPointOurDiskloc"_attr = fixUpInfo.commonPointOurDiskloc);
// Cleans up the oplog.
{
@@ -1718,24 +1911,28 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
// This is done using an untimestamped write, since timestamping the write with the common
// point TS would be incorrect (since this is equal to the stable timestamp), and this write
// will be included in the unstable checkpoint regardless of its timestamp.
- log() << "Setting appliedThrough to the common point: " << fixUpInfo.commonPoint;
+ LOGV2(21719,
+ "Setting appliedThrough to the common point: {fixUpInfo_commonPoint}",
+ "fixUpInfo_commonPoint"_attr = fixUpInfo.commonPoint);
const bool setTimestamp = false;
replicationProcess->getConsistencyMarkers()->setAppliedThrough(
opCtx, fixUpInfo.commonPoint, setTimestamp);
// Take an unstable checkpoint to ensure the appliedThrough write is persisted to disk.
- log() << "Waiting for an unstable checkpoint";
+ LOGV2(21720, "Waiting for an unstable checkpoint");
const bool stableCheckpoint = false;
opCtx->recoveryUnit()->waitUntilUnjournaledWritesDurable(opCtx, stableCheckpoint);
// Ensure that appliedThrough is unset in the next stable checkpoint.
- log() << "Clearing appliedThrough";
+ LOGV2(21721, "Clearing appliedThrough");
replicationProcess->getConsistencyMarkers()->clearAppliedThrough(opCtx, Timestamp());
}
Status status = AuthorizationManager::get(opCtx->getServiceContext())->initialize(opCtx);
if (!status.isOK()) {
- severe() << "Failed to reinitialize auth data after rollback: " << redact(status);
+ LOGV2_FATAL(21748,
+ "Failed to reinitialize auth data after rollback: {status}",
+ "status"_attr = redact(status));
fassertFailedNoTrace(40496);
}
@@ -1790,8 +1987,12 @@ Status syncRollback(OperationContext* opCtx,
replCoord,
replicationProcess);
- log() << "Rollback finished. The final minValid is: "
- << replicationProcess->getConsistencyMarkers()->getMinValid(opCtx) << rsLog;
+ LOGV2_OPTIONS(21722,
+ {logv2::LogTag::kRS},
+ "Rollback finished. The final minValid is: "
+ "{replicationProcess_getConsistencyMarkers_getMinValid_opCtx}",
+ "replicationProcess_getConsistencyMarkers_getMinValid_opCtx"_attr =
+ replicationProcess->getConsistencyMarkers()->getMinValid(opCtx));
return status;
}
@@ -1821,15 +2022,21 @@ void rollback(OperationContext* opCtx,
auto status = replCoord->setFollowerModeStrict(opCtx, MemberState::RS_ROLLBACK);
if (!status.isOK()) {
- log() << "Cannot transition from " << replCoord->getMemberState().toString() << " to "
- << MemberState(MemberState::RS_ROLLBACK).toString() << causedBy(status);
+ LOGV2(21723,
+ "Cannot transition from {replCoord_getMemberState} to "
+ "{MemberState_MemberState_RS_ROLLBACK}{causedBy_status}",
+ "replCoord_getMemberState"_attr = replCoord->getMemberState().toString(),
+ "MemberState_MemberState_RS_ROLLBACK"_attr =
+ MemberState(MemberState::RS_ROLLBACK).toString(),
+ "causedBy_status"_attr = causedBy(status));
return;
}
}
if (MONGO_unlikely(rollbackHangAfterTransitionToRollback.shouldFail())) {
- log() << "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail "
- "point is disabled (rs_rollback).";
+ LOGV2(21724,
+ "rollbackHangAfterTransitionToRollback fail point enabled. Blocking until fail "
+ "point is disabled (rs_rollback).");
rollbackHangAfterTransitionToRollback.pauseWhileSet(opCtx);
}
@@ -1846,8 +2053,9 @@ void rollback(OperationContext* opCtx,
// WARNING: these statuses sometimes have location codes which are lost with uassertStatusOK
// so we need to check here first.
if (ErrorCodes::UnrecoverableRollbackError == status.code()) {
- severe() << "Unable to complete rollback. A full resync may be needed: "
- << redact(status);
+ LOGV2_FATAL(21749,
+ "Unable to complete rollback. A full resync may be needed: {status}",
+ "status"_attr = redact(status));
fassertFailedNoTrace(40507);
}
@@ -1858,9 +2066,14 @@ void rollback(OperationContext* opCtx,
// above.
invariant(ex.code() != ErrorCodes::UnrecoverableRollbackError);
- warning() << "Rollback cannot complete at this time (retrying later): " << redact(ex)
- << " appliedThrough= " << replCoord->getMyLastAppliedOpTime() << " minvalid= "
- << replicationProcess->getConsistencyMarkers()->getMinValid(opCtx);
+ LOGV2_WARNING(21728,
+ "Rollback cannot complete at this time (retrying later): {ex} "
+ "appliedThrough= {replCoord_getMyLastAppliedOpTime} minvalid= "
+ "{replicationProcess_getConsistencyMarkers_getMinValid_opCtx}",
+ "ex"_attr = redact(ex),
+ "replCoord_getMyLastAppliedOpTime"_attr = replCoord->getMyLastAppliedOpTime(),
+ "replicationProcess_getConsistencyMarkers_getMinValid_opCtx"_attr =
+ replicationProcess->getConsistencyMarkers()->getMinValid(opCtx));
// Sleep a bit to allow upstream node to coalesce, if that was the cause of the failure. If
// we failed in a way that will keep failing, but wasn't flagged as a fatal failure, this
@@ -1882,17 +2095,24 @@ void rollback(OperationContext* opCtx,
// then we must shut down to clear the in-memory ShardingState associated with the
// shardIdentity document.
if (ShardIdentityRollbackNotifier::get(opCtx)->didRollbackHappen()) {
- severe() << "shardIdentity document rollback detected. Shutting down to clear "
+ LOGV2_FATAL(21750,
+ "shardIdentity document rollback detected. Shutting down to clear "
"in-memory sharding state. Restarting this process should safely return it "
- "to a healthy state";
+ "to a healthy state");
fassertFailedNoTrace(40498);
}
auto status = replCoord->setFollowerMode(MemberState::RS_RECOVERING);
if (!status.isOK()) {
- severe() << "Failed to transition into " << MemberState(MemberState::RS_RECOVERING)
- << "; expected to be in state " << MemberState(MemberState::RS_ROLLBACK)
- << "; found self in " << replCoord->getMemberState() << causedBy(status);
+ LOGV2_FATAL(
+ 21751,
+ "Failed to transition into {MemberState_MemberState_RS_RECOVERING}; expected to be in "
+ "state {MemberState_MemberState_RS_ROLLBACK}; found self in "
+ "{replCoord_getMemberState}{causedBy_status}",
+ "MemberState_MemberState_RS_RECOVERING"_attr = MemberState(MemberState::RS_RECOVERING),
+ "MemberState_MemberState_RS_ROLLBACK"_attr = MemberState(MemberState::RS_ROLLBACK),
+ "replCoord_getMemberState"_attr = replCoord->getMemberState(),
+ "causedBy_status"_attr = causedBy(status));
fassertFailedNoTrace(40499);
}
}
diff --git a/src/mongo/db/repl/scatter_gather_runner.cpp b/src/mongo/db/repl/scatter_gather_runner.cpp
index 18e3bc761b9..9986987b3f4 100644
--- a/src/mongo/db/repl/scatter_gather_runner.cpp
+++ b/src/mongo/db/repl/scatter_gather_runner.cpp
@@ -38,6 +38,7 @@
#include "mongo/base/status_with.h"
#include "mongo/db/repl/scatter_gather_algorithm.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -105,8 +106,10 @@ StatusWith<EventHandle> ScatterGatherRunner::RunnerImpl::start(
std::vector<RemoteCommandRequest> requests = _algorithm->getRequests();
for (size_t i = 0; i < requests.size(); ++i) {
- log() << "Scheduling remote command request for " << _logMessage << ": "
- << requests[i].toString();
+ LOGV2(21752,
+ "Scheduling remote command request for {logMessage}: {requests_i}",
+ "logMessage"_attr = _logMessage,
+ "requests_i"_attr = requests[i].toString());
const StatusWith<CallbackHandle> cbh =
_executor->scheduleRemoteCommand(requests[i], processResponseCB);
if (cbh.getStatus() == ErrorCodes::ShutdownInProgress) {
diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp
index 17af180cd45..92841eeacae 100644
--- a/src/mongo/db/repl/storage_interface_impl.cpp
+++ b/src/mongo/db/repl/storage_interface_impl.cpp
@@ -76,6 +76,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/storage/oplog_cap_maintainer_thread.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/background.h"
#include "mongo/util/log.h"
@@ -190,7 +191,10 @@ StorageInterfaceImpl::createCollectionForBulkLoading(
const BSONObj idIndexSpec,
const std::vector<BSONObj>& secondaryIndexSpecs) {
- LOG(2) << "StorageInterfaceImpl::createCollectionForBulkLoading called for ns: " << nss.ns();
+ LOGV2_DEBUG(21753,
+ 2,
+ "StorageInterfaceImpl::createCollectionForBulkLoading called for ns: {nss_ns}",
+ "nss_ns"_attr = nss.ns());
class StashClient {
public:
@@ -384,7 +388,9 @@ Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) {
std::vector<std::string> dbNames =
opCtx->getServiceContext()->getStorageEngine()->listDatabases();
invariant(!dbNames.empty());
- log() << "dropReplicatedDatabases - dropping " << dbNames.size() << " databases";
+ LOGV2(21754,
+ "dropReplicatedDatabases - dropping {dbNames_size} databases",
+ "dbNames_size"_attr = dbNames.size());
ReplicationCoordinator::get(opCtx)->dropAllSnapshots();
@@ -401,14 +407,17 @@ Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) {
} else {
// This is needed since dropDatabase can't be rolled back.
// This is safe be replaced by "invariant(db);dropDatabase(opCtx, db);" once fixed.
- log() << "dropReplicatedDatabases - database disappeared after retrieving list of "
- "database names but before drop: "
- << dbName;
+ LOGV2(21755,
+ "dropReplicatedDatabases - database disappeared after retrieving list of "
+ "database names but before drop: {dbName}",
+ "dbName"_attr = dbName);
}
});
}
invariant(hasLocalDatabase, "local database missing");
- log() << "dropReplicatedDatabases - dropped " << dbNames.size() << " databases";
+ LOGV2(21756,
+ "dropReplicatedDatabases - dropped {dbNames_size} databases",
+ "dbNames_size"_attr = dbNames.size());
return Status::OK();
}
diff --git a/src/mongo/db/repl/storage_interface_mock.cpp b/src/mongo/db/repl/storage_interface_mock.cpp
index e9fa17504be..30d60626641 100644
--- a/src/mongo/db/repl/storage_interface_mock.cpp
+++ b/src/mongo/db/repl/storage_interface_mock.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/repl/storage_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -103,14 +104,14 @@ bool StorageInterfaceMock::supportsDocLocking(ServiceContext* serviceCtx) const
}
Status CollectionBulkLoaderMock::init(const std::vector<BSONObj>& secondaryIndexSpecs) {
- LOG(1) << "CollectionBulkLoaderMock::init called";
+ LOGV2_DEBUG(21757, 1, "CollectionBulkLoaderMock::init called");
stats->initCalled = true;
return Status::OK();
};
Status CollectionBulkLoaderMock::insertDocuments(const std::vector<BSONObj>::const_iterator begin,
const std::vector<BSONObj>::const_iterator end) {
- LOG(1) << "CollectionBulkLoaderMock::insertDocuments called";
+ LOGV2_DEBUG(21758, 1, "CollectionBulkLoaderMock::insertDocuments called");
const auto status = insertDocsFn(begin, end);
// Only count if it succeeds.
@@ -121,7 +122,7 @@ Status CollectionBulkLoaderMock::insertDocuments(const std::vector<BSONObj>::con
};
Status CollectionBulkLoaderMock::commit() {
- LOG(1) << "CollectionBulkLoaderMock::commit called";
+ LOGV2_DEBUG(21759, 1, "CollectionBulkLoaderMock::commit called");
stats->commitCalled = true;
return commitFn();
};
diff --git a/src/mongo/db/repl/sync_source_feedback.cpp b/src/mongo/db/repl/sync_source_feedback.cpp
index 03b5af98376..0fc2f3f16ac 100644
--- a/src/mongo/db/repl/sync_source_feedback.cpp
+++ b/src/mongo/db/repl/sync_source_feedback.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/repl/reporter.h"
#include "mongo/executor/task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/log.h"
#include "mongo/util/net/hostandport.h"
@@ -104,8 +105,11 @@ void SyncSourceFeedback::forwardSlaveProgress() {
if (_reporter) {
auto triggerStatus = _reporter->trigger();
if (!triggerStatus.isOK()) {
- warning() << "unable to forward slave progress to " << _reporter->getTarget()
- << ": " << triggerStatus;
+ LOGV2_WARNING(
+ 21764,
+ "unable to forward slave progress to {reporter_getTarget}: {triggerStatus}",
+ "reporter_getTarget"_attr = _reporter->getTarget(),
+ "triggerStatus"_attr = triggerStatus);
}
}
}
@@ -116,15 +120,21 @@ Status SyncSourceFeedback::_updateUpstream(Reporter* reporter) {
auto triggerStatus = reporter->trigger();
if (!triggerStatus.isOK()) {
- warning() << "unable to schedule reporter to update replication progress on " << syncTarget
- << ": " << triggerStatus;
+ LOGV2_WARNING(21765,
+ "unable to schedule reporter to update replication progress on {syncTarget}: "
+ "{triggerStatus}",
+ "syncTarget"_attr = syncTarget,
+ "triggerStatus"_attr = triggerStatus);
return triggerStatus;
}
auto status = reporter->join();
if (!status.isOK()) {
- log() << "SyncSourceFeedback error sending update to " << syncTarget << ": " << status;
+ LOGV2(21760,
+ "SyncSourceFeedback error sending update to {syncTarget}: {status}",
+ "syncTarget"_attr = syncTarget,
+ "status"_attr = status);
}
// Sync source blacklisting will be done in BackgroundSync and SyncSourceResolver.
@@ -202,15 +212,19 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor,
}
if (syncTarget != target) {
- LOG(1) << "setting syncSourceFeedback to " << target;
+ LOGV2_DEBUG(21761, 1, "setting syncSourceFeedback to {target}", "target"_attr = target);
syncTarget = target;
// Update keepalive value from config.
auto oldKeepAliveInterval = keepAliveInterval;
keepAliveInterval = calculateKeepAliveInterval(replCoord->getConfig());
if (oldKeepAliveInterval != keepAliveInterval) {
- LOG(1) << "new syncSourceFeedback keep alive duration = " << keepAliveInterval
- << " (previously " << oldKeepAliveInterval << ")";
+ LOGV2_DEBUG(21762,
+ 1,
+ "new syncSourceFeedback keep alive duration = {keepAliveInterval} "
+ "(previously {oldKeepAliveInterval})",
+ "keepAliveInterval"_attr = keepAliveInterval,
+ "oldKeepAliveInterval"_attr = oldKeepAliveInterval);
}
}
@@ -233,9 +247,12 @@ void SyncSourceFeedback::run(executor::TaskExecutor* executor,
auto status = _updateUpstream(&reporter);
if (!status.isOK()) {
- LOG(1) << "The replication progress command (replSetUpdatePosition) failed and will be "
- "retried: "
- << status;
+ LOGV2_DEBUG(
+ 21763,
+ 1,
+ "The replication progress command (replSetUpdatePosition) failed and will be "
+ "retried: {status}",
+ "status"_attr = status);
}
}
}
diff --git a/src/mongo/db/repl/sync_source_resolver.cpp b/src/mongo/db/repl/sync_source_resolver.cpp
index a6c87de8731..8ecdad2ebe4 100644
--- a/src/mongo/db/repl/sync_source_resolver.cpp
+++ b/src/mongo/db/repl/sync_source_resolver.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/repl/oplog_entry.h"
#include "mongo/db/repl/replication_process.h"
#include "mongo/db/repl/sync_source_selector.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/destructor_guard.h"
@@ -224,8 +225,11 @@ Status SyncSourceResolver::_scheduleFetcher(std::unique_ptr<Fetcher> fetcher) {
_shuttingDownFetcher = std::move(_fetcher);
_fetcher = std::move(fetcher);
} else {
- error() << "Error scheduling fetcher to evaluate host as sync source, host:"
- << fetcher->getSource() << ", error: " << status;
+ LOGV2_ERROR(21776,
+ "Error scheduling fetcher to evaluate host as sync source, "
+ "host:{fetcher_getSource}, error: {status}",
+ "fetcher_getSource"_attr = fetcher->getSource(),
+ "status"_attr = status);
}
return status;
}
@@ -235,8 +239,12 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida
if (queryResponse.documents.empty()) {
// Remote oplog is empty.
const auto until = _taskExecutor->now() + kOplogEmptyBlacklistDuration;
- log() << "Blacklisting " << candidate << " due to empty oplog for "
- << kOplogEmptyBlacklistDuration << " until: " << until;
+ LOGV2(21766,
+ "Blacklisting {candidate} due to empty oplog for {kOplogEmptyBlacklistDuration} "
+ "until: {until}",
+ "candidate"_attr = candidate,
+ "kOplogEmptyBlacklistDuration"_attr = kOplogEmptyBlacklistDuration,
+ "until"_attr = until);
_syncSourceSelector->blacklistSyncSource(candidate, until);
return OpTime();
}
@@ -245,8 +253,13 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida
if (firstObjFound.isEmpty()) {
// First document in remote oplog is empty.
const auto until = _taskExecutor->now() + kFirstOplogEntryEmptyBlacklistDuration;
- log() << "Blacklisting " << candidate << " due to empty first document for "
- << kFirstOplogEntryEmptyBlacklistDuration << " until: " << until;
+ LOGV2(21767,
+ "Blacklisting {candidate} due to empty first document for "
+ "{kFirstOplogEntryEmptyBlacklistDuration} until: {until}",
+ "candidate"_attr = candidate,
+ "kFirstOplogEntryEmptyBlacklistDuration"_attr =
+ kFirstOplogEntryEmptyBlacklistDuration,
+ "until"_attr = until);
_syncSourceSelector->blacklistSyncSource(candidate, until);
return OpTime();
}
@@ -254,10 +267,16 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida
const auto remoteEarliestOpTime = OpTime::parseFromOplogEntry(firstObjFound);
if (!remoteEarliestOpTime.isOK()) {
const auto until = _taskExecutor->now() + kFirstOplogEntryNullTimestampBlacklistDuration;
- log() << "Blacklisting " << candidate << " due to error parsing OpTime from the oldest"
- << " oplog entry for " << kFirstOplogEntryNullTimestampBlacklistDuration
- << " until: " << until << ". Error: " << remoteEarliestOpTime.getStatus()
- << ", Entry: " << redact(firstObjFound);
+ LOGV2(21768,
+ "Blacklisting {candidate} due to error parsing OpTime from the oldest oplog entry "
+ "for {kFirstOplogEntryNullTimestampBlacklistDuration} until: {until}. Error: "
+ "{remoteEarliestOpTime_getStatus}, Entry: {firstObjFound}",
+ "candidate"_attr = candidate,
+ "kFirstOplogEntryNullTimestampBlacklistDuration"_attr =
+ kFirstOplogEntryNullTimestampBlacklistDuration,
+ "until"_attr = until,
+ "remoteEarliestOpTime_getStatus"_attr = remoteEarliestOpTime.getStatus(),
+ "firstObjFound"_attr = redact(firstObjFound));
_syncSourceSelector->blacklistSyncSource(candidate, until);
return OpTime();
}
@@ -265,8 +284,13 @@ OpTime SyncSourceResolver::_parseRemoteEarliestOpTime(const HostAndPort& candida
if (remoteEarliestOpTime.getValue().isNull()) {
// First document in remote oplog is empty.
const auto until = _taskExecutor->now() + kFirstOplogEntryNullTimestampBlacklistDuration;
- log() << "Blacklisting " << candidate << " due to null timestamp in first document for "
- << kFirstOplogEntryNullTimestampBlacklistDuration << " until: " << until;
+ LOGV2(21769,
+ "Blacklisting {candidate} due to null timestamp in first document for "
+ "{kFirstOplogEntryNullTimestampBlacklistDuration} until: {until}",
+ "candidate"_attr = candidate,
+ "kFirstOplogEntryNullTimestampBlacklistDuration"_attr =
+ kFirstOplogEntryNullTimestampBlacklistDuration,
+ "until"_attr = until);
_syncSourceSelector->blacklistSyncSource(candidate, until);
return OpTime();
}
@@ -295,8 +319,13 @@ void SyncSourceResolver::_firstOplogEntryFetcherCallback(
if (!queryResult.isOK()) {
// We got an error.
const auto until = _taskExecutor->now() + kFetcherErrorBlacklistDuration;
- log() << "Blacklisting " << candidate << " due to error: '" << queryResult.getStatus()
- << "' for " << kFetcherErrorBlacklistDuration << " until: " << until;
+ LOGV2(21770,
+ "Blacklisting {candidate} due to error: '{queryResult_getStatus}' for "
+ "{kFetcherErrorBlacklistDuration} until: {until}",
+ "candidate"_attr = candidate,
+ "queryResult_getStatus"_attr = queryResult.getStatus(),
+ "kFetcherErrorBlacklistDuration"_attr = kFetcherErrorBlacklistDuration,
+ "until"_attr = until);
_syncSourceSelector->blacklistSyncSource(candidate, until);
_chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore();
@@ -316,11 +345,16 @@ void SyncSourceResolver::_firstOplogEntryFetcherCallback(
const auto blacklistDuration = kTooStaleBlacklistDuration;
const auto until = _taskExecutor->now() + Minutes(1);
- log() << "We are too stale to use " << candidate << " as a sync source. "
- << "Blacklisting this sync source"
- << " because our last fetched timestamp: " << _lastOpTimeFetched.getTimestamp()
- << " is before their earliest timestamp: " << remoteEarliestOpTime.getTimestamp()
- << " for " << blacklistDuration << " until: " << until;
+ LOGV2(21771,
+ "We are too stale to use {candidate} as a sync source. Blacklisting this sync source "
+ "because our last fetched timestamp: {lastOpTimeFetched_getTimestamp} is before "
+ "their earliest timestamp: {remoteEarliestOpTime_getTimestamp} for "
+ "{blacklistDuration} until: {until}",
+ "candidate"_attr = candidate,
+ "lastOpTimeFetched_getTimestamp"_attr = _lastOpTimeFetched.getTimestamp(),
+ "remoteEarliestOpTime_getTimestamp"_attr = remoteEarliestOpTime.getTimestamp(),
+ "blacklistDuration"_attr = blacklistDuration,
+ "until"_attr = until);
_syncSourceSelector->blacklistSyncSource(candidate, until);
@@ -386,8 +420,13 @@ void SyncSourceResolver::_rbidRequestCallback(
rbid = rbidReply.response.data["rbid"].Int();
} catch (const DBException& ex) {
const auto until = _taskExecutor->now() + kFetcherErrorBlacklistDuration;
- log() << "Blacklisting " << candidate << " due to error: '" << ex << "' for "
- << kFetcherErrorBlacklistDuration << " until: " << until;
+ LOGV2(21772,
+ "Blacklisting {candidate} due to error: '{ex}' for {kFetcherErrorBlacklistDuration} "
+ "until: {until}",
+ "candidate"_attr = candidate,
+ "ex"_attr = ex,
+ "kFetcherErrorBlacklistDuration"_attr = kFetcherErrorBlacklistDuration,
+ "until"_attr = until);
_syncSourceSelector->blacklistSyncSource(candidate, until);
_chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore();
return;
@@ -456,9 +495,15 @@ void SyncSourceResolver::_requiredOpTimeFetcherCallback(
if (!queryResult.isOK()) {
// We got an error.
const auto until = _taskExecutor->now() + kFetcherErrorBlacklistDuration;
- log() << "Blacklisting " << candidate << " due to required optime fetcher error: '"
- << queryResult.getStatus() << "' for " << kFetcherErrorBlacklistDuration
- << " until: " << until << ". required optime: " << _requiredOpTime;
+ LOGV2(21773,
+ "Blacklisting {candidate} due to required optime fetcher error: "
+ "'{queryResult_getStatus}' for {kFetcherErrorBlacklistDuration} until: {until}. "
+ "required optime: {requiredOpTime}",
+ "candidate"_attr = candidate,
+ "queryResult_getStatus"_attr = queryResult.getStatus(),
+ "kFetcherErrorBlacklistDuration"_attr = kFetcherErrorBlacklistDuration,
+ "until"_attr = until,
+ "requiredOpTime"_attr = _requiredOpTime);
_syncSourceSelector->blacklistSyncSource(candidate, until);
_chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore();
@@ -469,13 +514,18 @@ void SyncSourceResolver::_requiredOpTimeFetcherCallback(
auto status = _compareRequiredOpTimeWithQueryResponse(queryResponse);
if (!status.isOK()) {
const auto until = _taskExecutor->now() + kNoRequiredOpTimeBlacklistDuration;
- warning() << "We cannot use " << candidate.toString()
- << " as a sync source because it does not contain the necessary "
- "operations for us to reach a consistent state: "
- << status << " last fetched optime: " << _lastOpTimeFetched
- << ". required optime: " << _requiredOpTime
- << ". Blacklisting this sync source for " << kNoRequiredOpTimeBlacklistDuration
- << " until: " << until;
+ LOGV2_WARNING(
+ 21774,
+ "We cannot use {candidate} as a sync source because it does not contain the necessary "
+ "operations for us to reach a consistent state: {status} last fetched optime: "
+ "{lastOpTimeFetched}. required optime: {requiredOpTime}. Blacklisting this sync source "
+ "for {kNoRequiredOpTimeBlacklistDuration} until: {until}",
+ "candidate"_attr = candidate.toString(),
+ "status"_attr = status,
+ "lastOpTimeFetched"_attr = _lastOpTimeFetched,
+ "requiredOpTime"_attr = _requiredOpTime,
+ "kNoRequiredOpTimeBlacklistDuration"_attr = kNoRequiredOpTimeBlacklistDuration,
+ "until"_attr = until);
_syncSourceSelector->blacklistSyncSource(candidate, until);
_chooseAndProbeNextSyncSource(earliestOpTimeSeen).transitional_ignore();
@@ -532,8 +582,9 @@ Status SyncSourceResolver::_finishCallback(const SyncSourceResolverResponse& res
try {
_onCompletion(response);
} catch (...) {
- warning() << "sync source resolver finish callback threw exception: "
- << exceptionToStatus();
+ LOGV2_WARNING(21775,
+ "sync source resolver finish callback threw exception: {exceptionToStatus}",
+ "exceptionToStatus"_attr = exceptionToStatus());
}
stdx::lock_guard<Latch> lock(_mutex);
diff --git a/src/mongo/db/repl/task_runner.cpp b/src/mongo/db/repl/task_runner.cpp
index 86edc6da9c5..5889b149393 100644
--- a/src/mongo/db/repl/task_runner.cpp
+++ b/src/mongo/db/repl/task_runner.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/client.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/destructor_guard.h"
@@ -65,7 +66,9 @@ TaskRunner::NextAction runSingleTask(const TaskRunner::Task& task,
try {
return task(opCtx, status);
} catch (...) {
- log() << "Unhandled exception in task runner: " << redact(exceptionToStatus());
+ LOGV2(21777,
+ "Unhandled exception in task runner: {exceptionToStatus}",
+ "exceptionToStatus"_attr = redact(exceptionToStatus()));
}
return TaskRunner::NextAction::kCancel;
}
diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp
index a4e4ab8f9e9..fb7d8c65bd3 100644
--- a/src/mongo/db/repl/topology_coordinator.cpp
+++ b/src/mongo/db/repl/topology_coordinator.cpp
@@ -53,6 +53,7 @@
#include "mongo/db/repl/isself.h"
#include "mongo/db/repl/member_data.h"
#include "mongo/db/repl/rslog.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/util/assert_util.h"
@@ -201,7 +202,8 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
ChainingPreference chainingPreference) {
// If we are not a member of the current replica set configuration, no sync source is valid.
if (_selfIndex == -1) {
- LOG(1) << "Cannot sync from any members because we are not in the replica set config";
+ LOGV2_DEBUG(
+ 21778, 1, "Cannot sync from any members because we are not in the replica set config");
return HostAndPort();
}
@@ -209,31 +211,38 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
const auto& data = sfp.getData();
const auto hostAndPortElem = data["hostAndPort"];
if (!hostAndPortElem) {
- severe() << "'forceSyncSoureCandidate' parameter set with invalid host and port: "
- << data;
+ LOGV2_FATAL(
+ 21839,
+ "'forceSyncSoureCandidate' parameter set with invalid host and port: {data}",
+ "data"_attr = data);
fassertFailed(50835);
}
const auto hostAndPort = HostAndPort(hostAndPortElem.checkAndGetStringData());
const int syncSourceIndex = _rsConfig.findMemberIndexByHostAndPort(hostAndPort);
if (syncSourceIndex < 0) {
- log() << "'forceSyncSourceCandidate' failed due to host and port not in "
- "replica set config: "
- << hostAndPort.toString();
+ LOGV2(21779,
+ "'forceSyncSourceCandidate' failed due to host and port not in "
+ "replica set config: {hostAndPort}",
+ "hostAndPort"_attr = hostAndPort.toString());
fassertFailed(50836);
}
if (_memberIsBlacklisted(_rsConfig.getMemberAt(syncSourceIndex), now)) {
- log() << "Cannot select a sync source because forced candidate is blacklisted: "
- << hostAndPort.toString();
+ LOGV2(21780,
+ "Cannot select a sync source because forced candidate is blacklisted: "
+ "{hostAndPort}",
+ "hostAndPort"_attr = hostAndPort.toString());
_syncSource = HostAndPort();
return _syncSource;
}
_syncSource = _rsConfig.getMemberAt(syncSourceIndex).getHostAndPort();
- log() << "choosing sync source candidate due to 'forceSyncSourceCandidate' parameter: "
- << _syncSource;
+ LOGV2(21781,
+ "choosing sync source candidate due to 'forceSyncSourceCandidate' parameter: "
+ "{syncSource}",
+ "syncSource"_attr = _syncSource);
std::string msg(str::stream() << "syncing from: " << _syncSource.toString()
<< " by 'forceSyncSourceCandidate' parameter");
setMyHeartbeatMessage(now, msg);
@@ -245,7 +254,9 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
invariant(_forceSyncSourceIndex < _rsConfig.getNumMembers());
_syncSource = _rsConfig.getMemberAt(_forceSyncSourceIndex).getHostAndPort();
_forceSyncSourceIndex = -1;
- log() << "choosing sync source candidate by request: " << _syncSource;
+ LOGV2(21782,
+ "choosing sync source candidate by request: {syncSource}",
+ "syncSource"_attr = _syncSource);
std::string msg(str::stream()
<< "syncing from: " << _syncSource.toString() << " by request");
setMyHeartbeatMessage(now, msg);
@@ -258,7 +269,9 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
if (needMorePings > 0) {
static Occasionally sampler;
if (sampler.tick()) {
- log() << "waiting for " << needMorePings << " pings from other members before syncing";
+ LOGV2(21783,
+ "waiting for {needMorePings} pings from other members before syncing",
+ "needMorePings"_attr = needMorePings);
}
_syncSource = HostAndPort();
return _syncSource;
@@ -268,19 +281,26 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
if (chainingPreference == ChainingPreference::kUseConfiguration &&
!_rsConfig.isChainingAllowed()) {
if (_currentPrimaryIndex == -1) {
- LOG(1) << "Cannot select a sync source because chaining is"
- " not allowed and primary is unknown/down";
+ LOGV2_DEBUG(21784,
+ 1,
+ "Cannot select a sync source because chaining is"
+ " not allowed and primary is unknown/down");
_syncSource = HostAndPort();
return _syncSource;
} else if (_memberIsBlacklisted(*_currentPrimaryMember(), now)) {
- LOG(1) << "Cannot select a sync source because chaining is not allowed and primary "
- "member is blacklisted: "
- << _currentPrimaryMember()->getHostAndPort();
+ LOGV2_DEBUG(21785,
+ 1,
+ "Cannot select a sync source because chaining is not allowed and primary "
+ "member is blacklisted: {currentPrimaryMember_getHostAndPort}",
+ "currentPrimaryMember_getHostAndPort"_attr =
+ _currentPrimaryMember()->getHostAndPort());
_syncSource = HostAndPort();
return _syncSource;
} else if (_currentPrimaryIndex == _selfIndex) {
- LOG(1)
- << "Cannot select a sync source because chaining is not allowed and we are primary";
+ LOGV2_DEBUG(
+ 21786,
+ 1,
+ "Cannot select a sync source because chaining is not allowed and we are primary");
_syncSource = HostAndPort();
return _syncSource;
} else if (_memberData.at(_currentPrimaryIndex).getLastAppliedOpTime() <
@@ -295,8 +315,9 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
return _syncSource;
} else {
_syncSource = _currentPrimaryMember()->getHostAndPort();
- log() << "chaining not allowed, choosing primary as sync source candidate: "
- << _syncSource;
+ LOGV2(21787,
+ "chaining not allowed, choosing primary as sync source candidate: {syncSource}",
+ "syncSource"_attr = _syncSource);
std::string msg(str::stream() << "syncing from primary: " << _syncSource.toString());
setMyHeartbeatMessage(now, msg);
return _syncSource;
@@ -347,14 +368,20 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
// Candidate must be up to be considered.
if (!it->up()) {
- LOG(2) << "Cannot select sync source because it is not up: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21788,
+ 2,
+ "Cannot select sync source because it is not up: "
+ "{itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort());
continue;
}
// Candidate must be PRIMARY or SECONDARY state to be considered.
if (!it->getState().readable()) {
- LOG(2) << "Cannot select sync source because it is not readable: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21789,
+ 2,
+ "Cannot select sync source because it is not readable: "
+ "{itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort());
continue;
}
@@ -362,61 +389,94 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
if (attempts == 0) {
// Candidate must be a voter if we are a voter.
if (_selfConfig().isVoter() && !itMemberConfig.isVoter()) {
- LOG(2) << "Cannot select sync source because we are a voter and it is not: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21790,
+ 2,
+ "Cannot select sync source because we are a voter and it is not: "
+ "{itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr =
+ itMemberConfig.getHostAndPort());
continue;
}
// Candidates must not be hidden.
if (itMemberConfig.isHidden()) {
- LOG(2) << "Cannot select sync source because it is hidden: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21791,
+ 2,
+ "Cannot select sync source because it is hidden: "
+ "{itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr =
+ itMemberConfig.getHostAndPort());
continue;
}
// Candidates cannot be excessively behind.
if (it->getHeartbeatAppliedOpTime() < oldestSyncOpTime) {
- LOG(2) << "Cannot select sync source because it is too far behind."
- << "Latest optime of sync candidate " << itMemberConfig.getHostAndPort()
- << ": " << it->getHeartbeatAppliedOpTime()
- << ", oldest acceptable optime: " << oldestSyncOpTime;
+ LOGV2_DEBUG(
+ 21792,
+ 2,
+ "Cannot select sync source because it is too far behind.Latest optime of "
+ "sync candidate {itMemberConfig_getHostAndPort}: "
+ "{it_getHeartbeatAppliedOpTime}, oldest acceptable optime: "
+ "{oldestSyncOpTime}",
+ "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort(),
+ "it_getHeartbeatAppliedOpTime"_attr = it->getHeartbeatAppliedOpTime(),
+ "oldestSyncOpTime"_attr = oldestSyncOpTime);
continue;
}
// Candidate must not have a configured delay larger than ours.
if (_selfConfig().getSlaveDelay() < itMemberConfig.getSlaveDelay()) {
- LOG(2) << "Cannot select sync source with larger slaveDelay than ours: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21793,
+ 2,
+ "Cannot select sync source with larger slaveDelay than ours: "
+ "{itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr =
+ itMemberConfig.getHostAndPort());
continue;
}
}
// Candidate must build indexes if we build indexes, to be considered.
if (_selfConfig().shouldBuildIndexes()) {
if (!itMemberConfig.shouldBuildIndexes()) {
- LOG(2) << "Cannot select sync source with shouldBuildIndex differences: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21794,
+ 2,
+ "Cannot select sync source with shouldBuildIndex differences: "
+ "{itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr =
+ itMemberConfig.getHostAndPort());
continue;
}
}
// Only select a candidate that is ahead of me.
if (it->getHeartbeatAppliedOpTime() <= lastOpTimeFetched) {
- LOG(1) << "Cannot select this sync source. Sync source must be ahead of me. "
- << "Sync candidate: " << itMemberConfig.getHostAndPort()
- << ", my last fetched oplog optime: " << lastOpTimeFetched.toBSON()
- << ", latest oplog optime of sync candidate: "
- << it->getHeartbeatAppliedOpTime().toBSON();
+ LOGV2_DEBUG(21795,
+ 1,
+ "Cannot select this sync source. Sync source must be ahead of me. Sync "
+ "candidate: {itMemberConfig_getHostAndPort}, my last fetched oplog "
+ "optime: {lastOpTimeFetched}, latest oplog optime of sync candidate: "
+ "{it_getHeartbeatAppliedOpTime}",
+ "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort(),
+ "lastOpTimeFetched"_attr = lastOpTimeFetched.toBSON(),
+ "it_getHeartbeatAppliedOpTime"_attr =
+ it->getHeartbeatAppliedOpTime().toBSON());
continue;
}
// Candidate cannot be more latent than anything we've already considered.
if ((closestIndex != -1) &&
(_getPing(itMemberConfig.getHostAndPort()) >
_getPing(_rsConfig.getMemberAt(closestIndex).getHostAndPort()))) {
- LOG(2) << "Cannot select sync source with higher latency than the best candidate: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21796,
+ 2,
+ "Cannot select sync source with higher latency than the best "
+ "candidate: {itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort());
continue;
}
// Candidate cannot be blacklisted.
if (_memberIsBlacklisted(itMemberConfig, now)) {
- LOG(1) << "Cannot select sync source which is blacklisted: "
- << itMemberConfig.getHostAndPort();
+ LOGV2_DEBUG(21797,
+ 1,
+ "Cannot select sync source which is blacklisted: "
+ "{itMemberConfig_getHostAndPort}",
+ "itMemberConfig_getHostAndPort"_attr = itMemberConfig.getHostAndPort());
continue;
}
@@ -432,7 +492,7 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
std::string msg("could not find member to sync from");
// Only log when we had a valid sync source before
if (!_syncSource.empty()) {
- log() << msg << rsLog;
+ LOGV2_OPTIONS(21798, {logv2::LogTag::kRS}, "{msg}", "msg"_attr = msg);
}
setMyHeartbeatMessage(now, msg);
@@ -440,7 +500,7 @@ HostAndPort TopologyCoordinator::chooseNewSyncSource(Date_t now,
return _syncSource;
}
_syncSource = _rsConfig.getMemberAt(closestIndex).getHostAndPort();
- log() << "sync source candidate: " << _syncSource;
+ LOGV2(21799, "sync source candidate: {syncSource}", "syncSource"_attr = _syncSource);
std::string msg(str::stream() << "syncing from: " << _syncSource.toString(), 0);
setMyHeartbeatMessage(now, msg);
return _syncSource;
@@ -458,14 +518,18 @@ bool TopologyCoordinator::_memberIsBlacklisted(const MemberConfig& memberConfig,
}
void TopologyCoordinator::blacklistSyncSource(const HostAndPort& host, Date_t until) {
- LOG(2) << "blacklisting " << host << " until " << until.toString();
+ LOGV2_DEBUG(21800,
+ 2,
+ "blacklisting {host} until {until}",
+ "host"_attr = host,
+ "until"_attr = until.toString());
_syncSourceBlacklist[host] = until;
}
void TopologyCoordinator::unblacklistSyncSource(const HostAndPort& host, Date_t now) {
std::map<HostAndPort, Date_t>::iterator hostItr = _syncSourceBlacklist.find(host);
if (hostItr != _syncSourceBlacklist.end() && now >= hostItr->second) {
- LOG(2) << "unblacklisting " << host;
+ LOGV2_DEBUG(21801, 2, "unblacklisting {host}", "host"_attr = host);
_syncSourceBlacklist.erase(hostItr);
}
}
@@ -549,9 +613,14 @@ void TopologyCoordinator::prepareSyncFromResponse(const HostAndPort& target,
}
const OpTime lastOpApplied = getMyLastAppliedOpTime();
if (hbdata.getHeartbeatAppliedOpTime().getSecs() + 10 < lastOpApplied.getSecs()) {
- warning() << "attempting to sync from " << target << ", but its latest opTime is "
- << hbdata.getHeartbeatAppliedOpTime().getSecs() << " and ours is "
- << lastOpApplied.getSecs() << " so this may not work";
+ LOGV2_WARNING(21837,
+ "attempting to sync from {target}, but its latest opTime is "
+ "{hbdata_getHeartbeatAppliedOpTime_getSecs} and ours is "
+ "{lastOpApplied_getSecs} so this may not work",
+ "target"_attr = target,
+ "hbdata_getHeartbeatAppliedOpTime_getSecs"_attr =
+ hbdata.getHeartbeatAppliedOpTime().getSecs(),
+ "lastOpApplied_getSecs"_attr = lastOpApplied.getSecs());
response->append("warning",
str::stream() << "requested member \"" << target.toString()
<< "\" is more than 10 seconds behind us");
@@ -575,8 +644,10 @@ Status TopologyCoordinator::prepareHeartbeatResponseV1(Date_t now,
// Verify that replica set names match
const std::string rshb = args.getSetName();
if (ourSetName != rshb) {
- log() << "replSet set names do not match, ours: " << ourSetName
- << "; remote node's: " << rshb;
+ LOGV2(21802,
+ "replSet set names do not match, ours: {ourSetName}; remote node's: {rshb}",
+ "ourSetName"_attr = ourSetName,
+ "rshb"_attr = rshb);
return Status(ErrorCodes::InconsistentReplicaSetNames,
str::stream() << "Our set name of " << ourSetName << " does not match name "
<< rshb << " reported by remote node");
@@ -761,9 +832,9 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse(
// Could be we got the newer version before we got the response, or the
// target erroneously sent us one, even though it isn't newer.
if (newConfig.getConfigVersionAndTerm() < currentConfigVersionAndTerm) {
- LOG(1) << "Config version from heartbeat was older than ours.";
+ LOGV2_DEBUG(21803, 1, "Config version from heartbeat was older than ours.");
} else {
- LOG(2) << "Config from heartbeat response was same as ours.";
+ LOGV2_DEBUG(21804, 2, "Config from heartbeat response was same as ours.");
}
if (shouldLog(MongoLogDefaultComponent_component,
::mongo::LogstreamBuilder::severityCast(2))) {
@@ -785,18 +856,24 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse(
}
// If we're not in the config, we don't need to respond to heartbeats.
if (_selfIndex == -1) {
- LOG(1) << "Could not find ourself in current config so ignoring heartbeat from " << target
- << " -- current config: " << _rsConfig.toBSON();
+ LOGV2_DEBUG(21805,
+ 1,
+ "Could not find ourself in current config so ignoring heartbeat from {target} "
+ "-- current config: {rsConfig}",
+ "target"_attr = target,
+ "rsConfig"_attr = _rsConfig.toBSON());
HeartbeatResponseAction nextAction = HeartbeatResponseAction::makeNoAction();
nextAction.setNextHeartbeatStartDate(nextHeartbeatStartDate);
return nextAction;
}
const int memberIndex = _rsConfig.findMemberIndexByHostAndPort(target);
if (memberIndex == -1) {
- LOG(1) << "Could not find " << target
- << " in current config so ignoring --"
- " current config: "
- << _rsConfig.toBSON();
+ LOGV2_DEBUG(21806,
+ 1,
+ "Could not find {target} in current config so ignoring --"
+ " current config: {rsConfig}",
+ "target"_attr = target,
+ "rsConfig"_attr = _rsConfig.toBSON());
HeartbeatResponseAction nextAction = HeartbeatResponseAction::makeNoAction();
nextAction.setNextHeartbeatStartDate(nextHeartbeatStartDate);
return nextAction;
@@ -816,13 +893,20 @@ HeartbeatResponseAction TopologyCoordinator::processHeartbeatResponse(
else if (hbStats.failed() || (alreadyElapsed >= _rsConfig.getHeartbeatTimeoutPeriod())) {
hbData.setDownValues(now, hbResponse.getStatus().reason());
} else {
- LOG(3) << "Bad heartbeat response from " << target
- << "; trying again; Retries left: " << (hbStats.retriesLeft()) << "; "
- << alreadyElapsed << " have already elapsed";
+ LOGV2_DEBUG(21807,
+ 3,
+ "Bad heartbeat response from {target}; trying again; Retries left: "
+ "{hbStats_retriesLeft}; {alreadyElapsed} have already elapsed",
+ "target"_attr = target,
+ "hbStats_retriesLeft"_attr = (hbStats.retriesLeft()),
+ "alreadyElapsed"_attr = alreadyElapsed);
}
} else {
ReplSetHeartbeatResponse hbr = std::move(hbResponse.getValue());
- LOG(3) << "setUpValues: heartbeat response good for member _id:" << member.getId();
+ LOGV2_DEBUG(21808,
+ 3,
+ "setUpValues: heartbeat response good for member _id:{member_getId}",
+ "member_getId"_attr = member.getId());
advancedOpTime = hbData.setUpValues(now, std::move(hbr));
}
@@ -932,7 +1016,7 @@ HeartbeatResponseAction TopologyCoordinator::checkMemberTimeouts(Date_t now) {
}
}
if (stepdown) {
- log() << "can't see a majority of the set, relinquishing primary";
+ LOGV2(21809, "can't see a majority of the set, relinquishing primary");
return HeartbeatResponseAction::makeStepDownSelfAction(_selfIndex);
}
return HeartbeatResponseAction::makeNoAction();
@@ -981,13 +1065,20 @@ std::pair<MemberId, Date_t> TopologyCoordinator::getStalestLiveMember() const {
// Already stale.
continue;
}
- LOG(3) << "memberData lastupdate is: " << memberData.getLastUpdate();
+ LOGV2_DEBUG(21810,
+ 3,
+ "memberData lastupdate is: {memberData_getLastUpdate}",
+ "memberData_getLastUpdate"_attr = memberData.getLastUpdate());
if (earliestDate > memberData.getLastUpdate()) {
earliestDate = memberData.getLastUpdate();
earliestMemberId = memberData.getMemberId();
}
}
- LOG(3) << "stalest member " << earliestMemberId << " date: " << earliestDate;
+ LOGV2_DEBUG(21811,
+ 3,
+ "stalest member {earliestMemberId} date: {earliestDate}",
+ "earliestMemberId"_attr = earliestMemberId,
+ "earliestDate"_attr = earliestDate);
return std::make_pair(earliestMemberId, earliestDate);
}
@@ -1071,10 +1162,15 @@ StatusWith<bool> TopologyCoordinator::setLastOptime(const UpdatePositionArgs::Up
return false;
}
- LOG(2) << "received notification that node with memberID " << memberId
- << " in config with version " << args.cfgver
- << " has reached optime: " << args.appliedOpTime
- << " and is durable through: " << args.durableOpTime;
+ LOGV2_DEBUG(21812,
+ 2,
+ "received notification that node with memberID {memberId} in config with version "
+ "{args_cfgver} has reached optime: {args_appliedOpTime} and is durable through: "
+ "{args_durableOpTime}",
+ "memberId"_attr = memberId,
+ "args_cfgver"_attr = args.cfgver,
+ "args_appliedOpTime"_attr = args.appliedOpTime,
+ "args_durableOpTime"_attr = args.durableOpTime);
// If we're in FCV 4.4, allow replSetUpdatePosition commands between config versions.
if (!serverGlobalParams.featureCompatibility.isVersion(
@@ -1084,7 +1180,7 @@ StatusWith<bool> TopologyCoordinator::setLastOptime(const UpdatePositionArgs::Up
<< "Received replSetUpdatePosition for node with memberId " << memberId
<< " whose config version of " << args.cfgver
<< " doesn't match our config version of " << _rsConfig.getConfigVersion();
- LOG(1) << errmsg;
+ LOGV2_DEBUG(21813, 1, "{errmsg}", "errmsg"_attr = errmsg);
*configVersion = _rsConfig.getConfigVersion();
return Status(ErrorCodes::InvalidReplicaSetConfig, errmsg);
}
@@ -1099,16 +1195,23 @@ StatusWith<bool> TopologyCoordinator::setLastOptime(const UpdatePositionArgs::Up
std::string errmsg = str::stream()
<< "Received replSetUpdatePosition for node with memberId " << memberId
<< " which doesn't exist in our config";
- LOG(1) << errmsg;
+ LOGV2_DEBUG(21814, 1, "{errmsg}", "errmsg"_attr = errmsg);
return Status(ErrorCodes::NodeNotFound, errmsg);
}
invariant(memberId == memberData->getMemberId());
- LOG(3) << "Node with memberID " << memberId << " currently has optime "
- << memberData->getLastAppliedOpTime() << " durable through "
- << memberData->getLastDurableOpTime() << "; updating to optime " << args.appliedOpTime
- << " and durable through " << args.durableOpTime;
+ LOGV2_DEBUG(
+ 21815,
+ 3,
+ "Node with memberID {memberId} currently has optime {memberData_getLastAppliedOpTime} "
+ "durable through {memberData_getLastDurableOpTime}; updating to optime "
+ "{args_appliedOpTime} and durable through {args_durableOpTime}",
+ "memberId"_attr = memberId,
+ "memberData_getLastAppliedOpTime"_attr = memberData->getLastAppliedOpTime(),
+ "memberData_getLastDurableOpTime"_attr = memberData->getLastDurableOpTime(),
+ "args_appliedOpTime"_attr = args.appliedOpTime,
+ "args_durableOpTime"_attr = args.durableOpTime);
bool advancedOpTime = memberData->advanceLastAppliedOpTimeAndWallTime(
{args.appliedOpTime, args.appliedWallTime}, now);
@@ -1401,15 +1504,19 @@ void TopologyCoordinator::changeMemberState_forTest(const MemberState& newMember
updateConfig(ReplSetConfig(), -1, Date_t());
break;
default:
- severe() << "Cannot switch to state " << newMemberState;
+ LOGV2_FATAL(21840,
+ "Cannot switch to state {newMemberState}",
+ "newMemberState"_attr = newMemberState);
MONGO_UNREACHABLE;
}
if (getMemberState() != newMemberState.s) {
- severe() << "Expected to enter state " << newMemberState << " but am now in "
- << getMemberState();
+ LOGV2_FATAL(21841,
+ "Expected to enter state {newMemberState} but am now in {getMemberState}",
+ "newMemberState"_attr = newMemberState,
+ "getMemberState"_attr = getMemberState());
MONGO_UNREACHABLE;
}
- log() << newMemberState;
+ LOGV2(21816, "{newMemberState}", "newMemberState"_attr = newMemberState);
}
void TopologyCoordinator::setCurrentPrimary_forTest(int primaryIndex,
@@ -1823,13 +1930,13 @@ TopologyCoordinator::prepareFreezeResponse(Date_t now, int secs, BSONObjBuilder*
std::string msg = str::stream()
<< "cannot freeze node when primary or running for election. state: "
<< (_role == TopologyCoordinator::Role::kLeader ? "Primary" : "Running-Election");
- log() << msg;
+ LOGV2(21817, "{msg}", "msg"_attr = msg);
return Status(ErrorCodes::NotSecondary, msg);
}
if (secs == 0) {
_stepDownUntil = now;
- log() << "'unfreezing'";
+ LOGV2(21818, "'unfreezing'");
response->append("info", "unfreezing");
return PrepareFreezeResponseResult::kSingleNodeSelfElect;
} else {
@@ -1837,7 +1944,7 @@ TopologyCoordinator::prepareFreezeResponse(Date_t now, int secs, BSONObjBuilder*
response->append("warning", "you really want to freeze for only 1 second?");
_stepDownUntil = std::max(_stepDownUntil, now + Seconds(secs));
- log() << "'freezing' for " << secs << " seconds";
+ LOGV2(21819, "'freezing' for {secs} seconds", "secs"_attr = secs);
}
return PrepareFreezeResponseResult::kNoAction;
@@ -1914,7 +2021,10 @@ void TopologyCoordinator::updateConfig(const ReplSetConfig& newConfig, int selfI
// Reset term on startup.
if (!_rsConfig.isInitialized()) {
_term = OpTime::kInitialTerm;
- LOG(1) << "Updated term in topology coordinator to " << _term << " due to new config";
+ LOGV2_DEBUG(21820,
+ 1,
+ "Updated term in topology coordinator to {term} due to new config",
+ "term"_attr = _term);
}
_updateHeartbeatDataForReconfig(newConfig, selfIndex, now);
@@ -1924,9 +2034,9 @@ void TopologyCoordinator::updateConfig(const ReplSetConfig& newConfig, int selfI
if (_role == Role::kLeader) {
if (_selfIndex == -1) {
- log() << "Could not remain primary because no longer a member of the replica set";
+ LOGV2(21821, "Could not remain primary because no longer a member of the replica set");
} else if (!_selfConfig().isElectable()) {
- log() << " Could not remain primary because no longer electable";
+ LOGV2(21822, " Could not remain primary because no longer electable");
} else {
// Don't stepdown if you don't have to.
_currentPrimaryIndex = _selfIndex;
@@ -2109,7 +2219,9 @@ std::string TopologyCoordinator::_getUnelectableReasonString(const UnelectableRe
ss << "node is not a member of a valid replica set configuration";
}
if (!hasWrittenToStream) {
- severe() << "Invalid UnelectableReasonMask value 0x" << integerToHex(ur);
+ LOGV2_FATAL(21842,
+ "Invalid UnelectableReasonMask value 0x{integerToHex_ur}",
+ "integerToHex_ur"_attr = integerToHex(ur));
fassertFailed(26011);
}
ss << " (mask 0x" << integerToHex(ur) << ")";
@@ -2422,7 +2534,7 @@ void TopologyCoordinator::finishUnconditionalStepDown() {
// two other nodes think they are primary (asynchronously polled)
// -- wait for things to settle down.
remotePrimaryIndex = -1;
- warning() << "two remote primaries (transiently)";
+ LOGV2_WARNING(21838, "two remote primaries (transiently)");
break;
}
remotePrimaryIndex = itIndex;
@@ -2494,8 +2606,12 @@ bool TopologyCoordinator::advanceLastCommittedOpTimeAndWallTime(OpTimeAndWallTim
// This check is performed to ensure primaries do not commit an OpTime from a previous term.
if (_iAmPrimary() && committedOpTime.opTime < _firstOpTimeOfMyTerm) {
- LOG(1) << "Ignoring older committed snapshot from before I became primary, optime: "
- << committedOpTime.opTime << ", firstOpTimeOfMyTerm: " << _firstOpTimeOfMyTerm;
+ LOGV2_DEBUG(21823,
+ 1,
+ "Ignoring older committed snapshot from before I became primary, optime: "
+ "{committedOpTime_opTime}, firstOpTimeOfMyTerm: {firstOpTimeOfMyTerm}",
+ "committedOpTime_opTime"_attr = committedOpTime.opTime,
+ "firstOpTimeOfMyTerm"_attr = _firstOpTimeOfMyTerm);
return false;
}
@@ -2505,11 +2621,15 @@ bool TopologyCoordinator::advanceLastCommittedOpTimeAndWallTime(OpTimeAndWallTim
if (fromSyncSource) {
committedOpTime = std::min(committedOpTime, getMyLastAppliedOpTimeAndWallTime());
} else {
- LOG(1) << "Ignoring commit point with different term than my lastApplied, since it "
- "may "
- "not be on the same oplog branch as mine. optime: "
- << committedOpTime
- << ", my last applied: " << getMyLastAppliedOpTimeAndWallTime();
+ LOGV2_DEBUG(21824,
+ 1,
+ "Ignoring commit point with different term than my lastApplied, since it "
+ "may "
+ "not be on the same oplog branch as mine. optime: {committedOpTime}, my "
+ "last applied: {getMyLastAppliedOpTimeAndWallTime}",
+ "committedOpTime"_attr = committedOpTime,
+ "getMyLastAppliedOpTimeAndWallTime"_attr =
+ getMyLastAppliedOpTimeAndWallTime());
return false;
}
}
@@ -2519,12 +2639,19 @@ bool TopologyCoordinator::advanceLastCommittedOpTimeAndWallTime(OpTimeAndWallTim
}
if (committedOpTime.opTime < _lastCommittedOpTimeAndWallTime.opTime) {
- LOG(1) << "Ignoring older committed snapshot optime: " << committedOpTime
- << ", currentCommittedOpTime: " << _lastCommittedOpTimeAndWallTime;
+ LOGV2_DEBUG(21825,
+ 1,
+ "Ignoring older committed snapshot optime: {committedOpTime}, "
+ "currentCommittedOpTime: {lastCommittedOpTimeAndWallTime}",
+ "committedOpTime"_attr = committedOpTime,
+ "lastCommittedOpTimeAndWallTime"_attr = _lastCommittedOpTimeAndWallTime);
return false;
}
- LOG(2) << "Updating _lastCommittedOpTimeAndWallTime to " << committedOpTime;
+ LOGV2_DEBUG(21826,
+ 2,
+ "Updating _lastCommittedOpTimeAndWallTime to {committedOpTime}",
+ "committedOpTime"_attr = committedOpTime);
_lastCommittedOpTimeAndWallTime = committedOpTime;
return true;
}
@@ -2586,7 +2713,8 @@ TopologyCoordinator::UpdateTermResult TopologyCoordinator::updateTerm(long long
if (_iAmPrimary()) {
return TopologyCoordinator::UpdateTermResult::kTriggerStepDown;
}
- LOG(1) << "Updating term from " << _term << " to " << term;
+ LOGV2_DEBUG(
+ 21827, 1, "Updating term from {term} to {term2}", "term"_attr = _term, "term2"_attr = term);
_term = term;
return TopologyCoordinator::UpdateTermResult::kUpdatedTerm;
}
@@ -2611,15 +2739,17 @@ bool TopologyCoordinator::shouldChangeSyncSource(
// progress, return true.
if (_selfIndex == -1) {
- log() << "Not choosing new sync source because we are not in the config.";
+ LOGV2(21828, "Not choosing new sync source because we are not in the config.");
return false;
}
// If the user requested a sync source change, return true.
if (_forceSyncSourceIndex != -1) {
- log() << "Choosing new sync source because the user has requested to use "
- << _rsConfig.getMemberAt(_forceSyncSourceIndex).getHostAndPort()
- << " as a sync source";
+ LOGV2(21829,
+ "Choosing new sync source because the user has requested to use "
+ "{rsConfig_getMemberAt_forceSyncSourceIndex_getHostAndPort} as a sync source",
+ "rsConfig_getMemberAt_forceSyncSourceIndex_getHostAndPort"_attr =
+ _rsConfig.getMemberAt(_forceSyncSourceIndex).getHostAndPort());
return true;
}
@@ -2628,9 +2758,13 @@ bool TopologyCoordinator::shouldChangeSyncSource(
if (!serverGlobalParams.featureCompatibility.isVersion(
ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44)) {
if (replMetadata.getConfigVersion() != _rsConfig.getConfigVersion()) {
- log() << "Choosing new sync source because the config version supplied by "
- << currentSource << ", " << replMetadata.getConfigVersion()
- << ", does not match ours, " << _rsConfig.getConfigVersion();
+ LOGV2(
+ 21830,
+ "Choosing new sync source because the config version supplied by {currentSource}, "
+ "{replMetadata_getConfigVersion}, does not match ours, {rsConfig_getConfigVersion}",
+ "currentSource"_attr = currentSource,
+ "replMetadata_getConfigVersion"_attr = replMetadata.getConfigVersion(),
+ "rsConfig_getConfigVersion"_attr = _rsConfig.getConfigVersion());
return true;
}
}
@@ -2639,8 +2773,9 @@ bool TopologyCoordinator::shouldChangeSyncSource(
// from a node that is not in our config.
const int currentSourceIndex = _rsConfig.findMemberIndexByHostAndPort(currentSource);
if (currentSourceIndex == -1) {
- log() << "Choosing new sync source because " << currentSource.toString()
- << " is not in our config";
+ LOGV2(21831,
+ "Choosing new sync source because {currentSource} is not in our config",
+ "currentSource"_attr = currentSource.toString());
return true;
}
@@ -2689,15 +2824,17 @@ bool TopologyCoordinator::shouldChangeSyncSource(
} else {
logMessage << " (sync source does not know the primary)";
}
- log() << logMessage.str();
+ LOGV2(21832, "{logMessage_str}", "logMessage_str"_attr = logMessage.str());
return true;
}
if (MONGO_unlikely(disableMaxSyncSourceLagSecs.shouldFail())) {
- log() << "disableMaxSyncSourceLagSecs fail point enabled - not checking the most recent "
- "OpTime, "
- << currentSourceOpTime.toString() << ", of our current sync source, " << currentSource
- << ", against the OpTimes of the other nodes in this replica set.";
+ LOGV2(21833,
+ "disableMaxSyncSourceLagSecs fail point enabled - not checking the most recent "
+ "OpTime, {currentSourceOpTime}, of our current sync source, {currentSource}, against "
+ "the OpTimes of the other nodes in this replica set.",
+ "currentSourceOpTime"_attr = currentSourceOpTime.toString(),
+ "currentSource"_attr = currentSource);
} else {
unsigned int currentSecs = currentSourceOpTime.getSecs();
unsigned int goalSecs = currentSecs + durationCount<Seconds>(_options.maxSyncSourceLagSecs);
@@ -2711,13 +2848,19 @@ bool TopologyCoordinator::shouldChangeSyncSource(
(candidateConfig.shouldBuildIndexes() || !_selfConfig().shouldBuildIndexes()) &&
it->getState().readable() && !_memberIsBlacklisted(candidateConfig, now) &&
goalSecs < it->getHeartbeatAppliedOpTime().getSecs()) {
- log() << "Choosing new sync source because the most recent OpTime of our sync "
- "source, "
- << currentSource << ", is " << currentSourceOpTime.toString()
- << " which is more than " << _options.maxSyncSourceLagSecs
- << " behind member " << candidateConfig.getHostAndPort().toString()
- << " whose most recent OpTime is "
- << it->getHeartbeatAppliedOpTime().toString();
+ LOGV2(
+ 21834,
+ "Choosing new sync source because the most recent OpTime of our sync "
+ "source, {currentSource}, is {currentSourceOpTime} which is more than "
+ "{options_maxSyncSourceLagSecs} behind member {candidateConfig_getHostAndPort} "
+ "whose most recent OpTime is {it_getHeartbeatAppliedOpTime}",
+ "currentSource"_attr = currentSource,
+ "currentSourceOpTime"_attr = currentSourceOpTime.toString(),
+ "options_maxSyncSourceLagSecs"_attr = _options.maxSyncSourceLagSecs,
+ "candidateConfig_getHostAndPort"_attr =
+ candidateConfig.getHostAndPort().toString(),
+ "it_getHeartbeatAppliedOpTime"_attr =
+ it->getHeartbeatAppliedOpTime().toString());
invariant(itIndex != _selfIndex);
return true;
}
@@ -2751,7 +2894,7 @@ void TopologyCoordinator::processReplSetRequestVotes(const ReplSetRequestVotesAr
response->setTerm(_term);
if (MONGO_unlikely(voteNoInElection.shouldFail())) {
- log() << "failpoint voteNoInElection enabled";
+ LOGV2(21835, "failpoint voteNoInElection enabled");
response->setVoteGranted(false);
response->setReason(str::stream() << "forced to vote no during dry run election due to "
"failpoint voteNoInElection set");
@@ -2759,7 +2902,7 @@ void TopologyCoordinator::processReplSetRequestVotes(const ReplSetRequestVotesAr
}
if (MONGO_unlikely(voteYesInDryRunButNoInRealElection.shouldFail())) {
- log() << "failpoint voteYesInDryRunButNoInRealElection enabled";
+ LOGV2(21836, "failpoint voteYesInDryRunButNoInRealElection enabled");
if (args.isADryRun()) {
response->setVoteGranted(true);
response->setReason(str::stream() << "forced to vote yes in dry run due to failpoint "
diff --git a/src/mongo/db/repl/topology_coordinator_v1_test.cpp b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
index 9fc313a6042..cf41b85b78d 100644
--- a/src/mongo/db/repl/topology_coordinator_v1_test.cpp
+++ b/src/mongo/db/repl/topology_coordinator_v1_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <iostream>
@@ -42,10 +44,12 @@
#include "mongo/db/server_options.h"
#include "mongo/executor/task_executor.h"
#include "mongo/logger/logger.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/oplog_query_metadata.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
+#include "mongo/util/log.h"
#include "mongo/util/log_global_settings.h"
#include "mongo/util/net/hostandport.h"
#include "mongo/util/scopeguard.h"
@@ -1626,7 +1630,7 @@ TEST_F(TopoCoordTest, ReplSetGetStatus) {
&resultStatus);
ASSERT_OK(resultStatus);
BSONObj rsStatus = statusBuilder.obj();
- unittest::log() << rsStatus;
+ LOGV2(21843, "{rsStatus}", "rsStatus"_attr = rsStatus);
// Test results for all non-self members
ASSERT_EQUALS(setName, rsStatus["set"].String());
@@ -1742,7 +1746,7 @@ TEST_F(TopoCoordTest, ReplSetGetStatus) {
&resultStatus);
ASSERT_OK(resultStatus);
rsStatus = statusBuilder2.obj();
- unittest::log() << rsStatus;
+ LOGV2(21844, "{rsStatus}", "rsStatus"_attr = rsStatus);
ASSERT_EQUALS(setName, rsStatus["set"].String());
ASSERT_FALSE(rsStatus.hasField("lastStableRecoveryTimestamp"));
ASSERT_FALSE(rsStatus.hasField("electionCandidateMetrics"));
diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp
index 83bbe54deb9..3d2f77905dc 100644
--- a/src/mongo/db/repl/transaction_oplog_application.cpp
+++ b/src/mongo/db/repl/transaction_oplog_application.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/session_catalog_mongod.h"
#include "mongo/db/transaction_history_iterator.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -78,14 +79,20 @@ Status _applyOperationsForTransaction(OperationContext* opCtx,
oplogApplicationMode == repl::OplogApplication::Mode::kRecovering);
if (!ignoreException) {
- LOG(1) << "Error applying operation in transaction. " << redact(ex)
- << "- oplog entry: " << redact(op.toBSON());
+ LOGV2_DEBUG(21845,
+ 1,
+ "Error applying operation in transaction. {ex}- oplog entry: {op}",
+ "ex"_attr = redact(ex),
+ "op"_attr = redact(op.toBSON()));
return exceptionToStatus();
}
- LOG(1) << "Encountered but ignoring error: " << redact(ex)
- << " while applying operations for transaction because we are either in initial "
- "sync or recovering mode - oplog entry: "
- << redact(op.toBSON());
+ LOGV2_DEBUG(21846,
+ 1,
+ "Encountered but ignoring error: {ex} while applying operations for "
+ "transaction because we are either in initial "
+ "sync or recovering mode - oplog entry: {op}",
+ "ex"_attr = redact(ex),
+ "op"_attr = redact(op.toBSON()));
}
}
return Status::OK();
@@ -379,8 +386,10 @@ Status _applyPrepareTransaction(OperationContext* opCtx,
auto ns = op.getNss();
auto uuid = *op.getUuid();
if (BackgroundOperation::inProgForNs(ns)) {
- warning() << "blocking replication until index builds are finished on "
- << redact(ns.toString()) << ", due to prepared transaction";
+ LOGV2_WARNING(21849,
+ "blocking replication until index builds are finished on {ns}, due "
+ "to prepared transaction",
+ "ns"_attr = redact(ns.toString()));
BackgroundOperation::awaitNoBgOpInProgForNs(ns);
IndexBuildsCoordinator::get(opCtx)->awaitNoIndexBuildInProgressForCollection(uuid);
}
@@ -411,7 +420,7 @@ Status _applyPrepareTransaction(OperationContext* opCtx,
fassert(31137, status);
if (MONGO_unlikely(applyOpsHangBeforePreparingTransaction.shouldFail())) {
- LOG(0) << "Hit applyOpsHangBeforePreparingTransaction failpoint";
+ LOGV2(21847, "Hit applyOpsHangBeforePreparingTransaction failpoint");
applyOpsHangBeforePreparingTransaction.pauseWhileSet(opCtx);
}
@@ -460,10 +469,11 @@ Status applyPrepareTransaction(OperationContext* opCtx,
switch (mode) {
case repl::OplogApplication::Mode::kRecovering: {
if (!serverGlobalParams.enableMajorityReadConcern) {
- error()
- << "Cannot replay a prepared transaction when 'enableMajorityReadConcern' is "
- "set to false. Restart the server with --enableMajorityReadConcern=true "
- "to complete recovery.";
+ LOGV2_ERROR(
+ 21850,
+ "Cannot replay a prepared transaction when 'enableMajorityReadConcern' is "
+ "set to false. Restart the server with --enableMajorityReadConcern=true "
+ "to complete recovery.");
fassertFailed(51146);
}
@@ -490,7 +500,7 @@ Status applyPrepareTransaction(OperationContext* opCtx,
void reconstructPreparedTransactions(OperationContext* opCtx, repl::OplogApplication::Mode mode) {
if (MONGO_unlikely(skipReconstructPreparedTransactions.shouldFail())) {
- log() << "Hit skipReconstructPreparedTransactions failpoint";
+ LOGV2(21848, "Hit skipReconstructPreparedTransactions failpoint");
return;
}
// Read the transactions table and the oplog collection without a timestamp.
diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp
index 25109941176..212b6d79713 100644
--- a/src/mongo/db/s/balancer/balancer.cpp
+++ b/src/mongo/db/s/balancer/balancer.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/s/balancer/balancer_chunk_selection_policy_impl.h"
#include "mongo/db/s/balancer/cluster_statistics_impl.h"
#include "mongo/db/s/sharding_logging.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog_cache.h"
@@ -157,7 +158,7 @@ void warnOnMultiVersion(const vector<ClusterStatistics::ShardStatistics>& cluste
sb << stat.shardId << " is at " << stat.mongoVersion << "; ";
}
- warning() << sb.str();
+ LOGV2_WARNING(21875, "{sb_str}", "sb_str"_attr = sb.str());
}
} // namespace
@@ -247,7 +248,10 @@ Status Balancer::rebalanceSingleChunk(OperationContext* opCtx, const ChunkType&
auto migrateInfo = std::move(migrateStatus.getValue());
if (!migrateInfo) {
- LOG(1) << "Unable to find more appropriate location for chunk " << redact(chunk.toString());
+ LOGV2_DEBUG(21854,
+ 1,
+ "Unable to find more appropriate location for chunk {chunk}",
+ "chunk"_attr = redact(chunk.toString()));
return Status::OK();
}
@@ -307,14 +311,14 @@ void Balancer::_mainThread() {
_state = kStopped;
_joinCond.notify_all();
- LOG(1) << "Balancer thread terminated";
+ LOGV2_DEBUG(21855, 1, "Balancer thread terminated");
});
Client::initThread("Balancer");
auto opCtx = cc().makeOperationContext();
auto shardingContext = Grid::get(opCtx.get());
- log() << "CSRS balancer is starting";
+ LOGV2(21856, "CSRS balancer is starting");
{
stdx::lock_guard<Latch> scopedLock(_mutex);
@@ -327,9 +331,13 @@ void Balancer::_mainThread() {
while (!_stopRequested()) {
Status refreshStatus = balancerConfig->refreshAndCheck(opCtx.get());
if (!refreshStatus.isOK()) {
- warning() << "Balancer settings could not be loaded and will be retried in "
- << durationCount<Seconds>(kInitBackoffInterval) << " seconds"
- << causedBy(refreshStatus);
+ LOGV2_WARNING(
+ 21876,
+ "Balancer settings could not be loaded and will be retried in "
+ "{durationCount_Seconds_kInitBackoffInterval} seconds{causedBy_refreshStatus}",
+ "durationCount_Seconds_kInitBackoffInterval"_attr =
+ durationCount<Seconds>(kInitBackoffInterval),
+ "causedBy_refreshStatus"_attr = causedBy(refreshStatus));
_sleepFor(opCtx.get(), kInitBackoffInterval);
continue;
@@ -338,13 +346,13 @@ void Balancer::_mainThread() {
break;
}
- log() << "CSRS balancer thread is recovering";
+ LOGV2(21857, "CSRS balancer thread is recovering");
_migrationManager.finishRecovery(opCtx.get(),
balancerConfig->getMaxChunkSizeBytes(),
balancerConfig->getSecondaryThrottle());
- log() << "CSRS balancer thread is recovered";
+ LOGV2(21858, "CSRS balancer thread is recovered");
// Main balancer loop
while (!_stopRequested()) {
@@ -359,22 +367,28 @@ void Balancer::_mainThread() {
Status refreshStatus = balancerConfig->refreshAndCheck(opCtx.get());
if (!refreshStatus.isOK()) {
- warning() << "Skipping balancing round" << causedBy(refreshStatus);
+ LOGV2_WARNING(21877,
+ "Skipping balancing round{causedBy_refreshStatus}",
+ "causedBy_refreshStatus"_attr = causedBy(refreshStatus));
_endRound(opCtx.get(), kBalanceRoundDefaultInterval);
continue;
}
if (!balancerConfig->shouldBalance()) {
- LOG(1) << "Skipping balancing round because balancing is disabled";
+ LOGV2_DEBUG(21859, 1, "Skipping balancing round because balancing is disabled");
_endRound(opCtx.get(), kBalanceRoundDefaultInterval);
continue;
}
{
- LOG(1) << "*** start balancing round. "
- << "waitForDelete: " << balancerConfig->waitForDelete()
- << ", secondaryThrottle: "
- << balancerConfig->getSecondaryThrottle().toBSON();
+ LOGV2_DEBUG(
+ 21860,
+ 1,
+ "*** start balancing round. waitForDelete: {balancerConfig_waitForDelete}, "
+ "secondaryThrottle: {balancerConfig_getSecondaryThrottle}",
+ "balancerConfig_waitForDelete"_attr = balancerConfig->waitForDelete(),
+ "balancerConfig_getSecondaryThrottle"_attr =
+ balancerConfig->getSecondaryThrottle().toBSON());
static Occasionally sampler;
if (sampler.tick()) {
@@ -383,16 +397,18 @@ void Balancer::_mainThread() {
Status status = _enforceTagRanges(opCtx.get());
if (!status.isOK()) {
- warning() << "Failed to enforce tag ranges" << causedBy(status);
+ LOGV2_WARNING(21878,
+ "Failed to enforce tag ranges{causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
} else {
- LOG(1) << "Done enforcing tag range boundaries.";
+ LOGV2_DEBUG(21861, 1, "Done enforcing tag range boundaries.");
}
const auto candidateChunks =
uassertStatusOK(_chunkSelectionPolicy->selectChunksToMove(opCtx.get()));
if (candidateChunks.empty()) {
- LOG(1) << "no need to move any chunk";
+ LOGV2_DEBUG(21862, 1, "no need to move any chunk");
_balancedLastTime = 0;
} else {
_balancedLastTime = _moveChunks(opCtx.get(), candidateChunks);
@@ -405,7 +421,7 @@ void Balancer::_mainThread() {
.ignore();
}
- LOG(1) << "*** End of balancing round";
+ LOGV2_DEBUG(21863, 1, "*** End of balancing round");
}
Milliseconds balancerInterval =
@@ -413,16 +429,19 @@ void Balancer::_mainThread() {
overrideBalanceRoundInterval.execute([&](const BSONObj& data) {
balancerInterval = Milliseconds(data["intervalMs"].numberInt());
- log() << "overrideBalanceRoundInterval: using shorter balancing interval: "
- << balancerInterval;
+ LOGV2(21864,
+ "overrideBalanceRoundInterval: using shorter balancing interval: "
+ "{balancerInterval}",
+ "balancerInterval"_attr = balancerInterval);
});
_endRound(opCtx.get(), balancerInterval);
} catch (const DBException& e) {
- log() << "caught exception while doing balance: " << e.what();
+ LOGV2(
+ 21865, "caught exception while doing balance: {e_what}", "e_what"_attr = e.what());
// Just to match the opening statement if in log level 1
- LOG(1) << "*** End of balancing round";
+ LOGV2_DEBUG(21866, 1, "*** End of balancing round");
// This round failed, tell the world!
roundDetails.setFailed(e.what());
@@ -451,7 +470,7 @@ void Balancer::_mainThread() {
_threadOperationContext = nullptr;
}
- log() << "CSRS balancer is now stopped";
+ LOGV2(21867, "CSRS balancer is now stopped");
}
bool Balancer::_stopRequested() {
@@ -516,8 +535,11 @@ bool Balancer::_checkOIDs(OperationContext* opCtx) {
if (oids.count(x) == 0) {
oids[x] = shardId;
} else {
- log() << "error: 2 machines have " << x << " as oid machine piece: " << shardId
- << " and " << oids[x];
+ LOGV2(21868,
+ "error: 2 machines have {x} as oid machine piece: {shardId} and {oids_x}",
+ "x"_attr = x,
+ "shardId"_attr = shardId,
+ "oids_x"_attr = oids[x]);
result = uassertStatusOK(s->runCommandWithFixedRetryAttempts(
opCtx,
@@ -542,7 +564,7 @@ bool Balancer::_checkOIDs(OperationContext* opCtx) {
return false;
}
} else {
- log() << "warning: oidMachine not set on: " << s->toString();
+ LOGV2(21869, "warning: oidMachine not set on: {s}", "s"_attr = s->toString());
}
}
@@ -574,8 +596,11 @@ Status Balancer::_enforceTagRanges(OperationContext* opCtx) {
ChunkRange(splitInfo.minKey, splitInfo.maxKey),
splitInfo.splitKeys);
if (!splitStatus.isOK()) {
- warning() << "Failed to enforce tag range for chunk " << redact(splitInfo.toString())
- << causedBy(redact(splitStatus.getStatus()));
+ LOGV2_WARNING(
+ 21879,
+ "Failed to enforce tag range for chunk {splitInfo}{causedBy_splitStatus_getStatus}",
+ "splitInfo"_attr = redact(splitInfo.toString()),
+ "causedBy_splitStatus_getStatus"_attr = causedBy(redact(splitStatus.getStatus())));
}
}
@@ -588,7 +613,7 @@ int Balancer::_moveChunks(OperationContext* opCtx,
// If the balancer was disabled since we started this round, don't start new chunk moves
if (_stopRequested() || !balancerConfig->shouldBalance()) {
- LOG(1) << "Skipping balancing round because balancer was stopped";
+ LOGV2_DEBUG(21870, 1, "Skipping balancing round because balancer was stopped");
return 0;
}
@@ -626,15 +651,20 @@ int Balancer::_moveChunks(OperationContext* opCtx,
if (status == ErrorCodes::ChunkTooBig || status == ErrorCodes::ExceededMemoryLimit) {
numChunksProcessed++;
- log() << "Performing a split because migration " << redact(requestIt->toString())
- << " failed for size reasons" << causedBy(redact(status));
+ LOGV2(21871,
+ "Performing a split because migration {requestIt} failed for size "
+ "reasons{causedBy_status}",
+ "requestIt"_attr = redact(requestIt->toString()),
+ "causedBy_status"_attr = causedBy(redact(status)));
_splitOrMarkJumbo(opCtx, requestIt->nss, requestIt->minKey);
continue;
}
- log() << "Balancer move " << redact(requestIt->toString()) << " failed"
- << causedBy(redact(status));
+ LOGV2(21872,
+ "Balancer move {requestIt} failed{causedBy_status}",
+ "requestIt"_attr = redact(requestIt->toString()),
+ "causedBy_status"_attr = causedBy(redact(status)));
}
return numChunksProcessed;
@@ -660,7 +690,8 @@ void Balancer::_splitOrMarkJumbo(OperationContext* opCtx,
boost::none));
if (splitPoints.empty()) {
- log() << "Marking chunk " << redact(chunk.toString()) << " as jumbo.";
+ LOGV2(
+ 21873, "Marking chunk {chunk} as jumbo.", "chunk"_attr = redact(chunk.toString()));
chunk.markAsJumbo();
auto status = Grid::get(opCtx)->catalogClient()->updateConfigDocument(
@@ -671,9 +702,12 @@ void Balancer::_splitOrMarkJumbo(OperationContext* opCtx,
false,
ShardingCatalogClient::kMajorityWriteConcern);
if (!status.isOK()) {
- log() << "Couldn't set jumbo for chunk with namespace " << redact(nss.ns())
- << " and min key " << redact(chunk.getMin())
- << causedBy(redact(status.getStatus()));
+ LOGV2(21874,
+ "Couldn't set jumbo for chunk with namespace {nss_ns} and min key "
+ "{chunk_getMin}{causedBy_status_getStatus}",
+ "nss_ns"_attr = redact(nss.ns()),
+ "chunk_getMin"_attr = redact(chunk.getMin()),
+ "causedBy_status_getStatus"_attr = causedBy(redact(status.getStatus())));
}
return;
diff --git a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp
index f387556b02b..9f50b4f5169 100644
--- a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp
+++ b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp
@@ -39,6 +39,7 @@
#include "mongo/base/status_with.h"
#include "mongo/bson/bsonobj_comparator_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_collection.h"
@@ -218,8 +219,12 @@ StatusWith<SplitInfoVector> BalancerChunkSelectionPolicyImpl::selectChunksToSpli
// Namespace got dropped before we managed to get to it, so just skip it
continue;
} else if (!candidatesStatus.isOK()) {
- warning() << "Unable to enforce tag range policy for collection " << nss.ns()
- << causedBy(candidatesStatus.getStatus());
+ LOGV2_WARNING(21852,
+ "Unable to enforce tag range policy for collection "
+ "{nss_ns}{causedBy_candidatesStatus_getStatus}",
+ "nss_ns"_attr = nss.ns(),
+ "causedBy_candidatesStatus_getStatus"_attr =
+ causedBy(candidatesStatus.getStatus()));
continue;
}
@@ -282,7 +287,8 @@ StatusWith<MigrateInfoVector> BalancerChunkSelectionPolicyImpl::selectChunksToMo
const NamespaceString nss(coll.getNs());
if (!coll.getAllowBalance()) {
- LOG(1) << "Not balancing collection " << nss << "; explicitly disabled.";
+ LOGV2_DEBUG(
+ 21851, 1, "Not balancing collection {nss}; explicitly disabled.", "nss"_attr = nss);
continue;
}
@@ -292,8 +298,12 @@ StatusWith<MigrateInfoVector> BalancerChunkSelectionPolicyImpl::selectChunksToMo
// Namespace got dropped before we managed to get to it, so just skip it
continue;
} else if (!candidatesStatus.isOK()) {
- warning() << "Unable to balance collection " << nss.ns()
- << causedBy(candidatesStatus.getStatus());
+ LOGV2_WARNING(
+ 21853,
+ "Unable to balance collection {nss_ns}{causedBy_candidatesStatus_getStatus}",
+ "nss_ns"_attr = nss.ns(),
+ "causedBy_candidatesStatus_getStatus"_attr =
+ causedBy(candidatesStatus.getStatus()));
continue;
}
diff --git a/src/mongo/db/s/balancer/balancer_policy.cpp b/src/mongo/db/s/balancer/balancer_policy.cpp
index 022379992f0..44e3f1302b5 100644
--- a/src/mongo/db/s/balancer/balancer_policy.cpp
+++ b/src/mongo/db/s/balancer/balancer_policy.cpp
@@ -36,6 +36,7 @@
#include <random>
#include "mongo/db/s/balancer/type_migration.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/catalog/type_tags.h"
#include "mongo/util/fail_point.h"
@@ -342,8 +343,11 @@ MigrateInfo chooseRandomMigration(const ShardStatisticsVector& shardStats,
const int destIndex = indices[choice];
const auto& destShardId = shardStats[destIndex].shardId;
- LOG(1) << "balancerShouldReturnRandomMigrations: source: " << sourceShardId
- << " dest: " << destShardId;
+ LOGV2_DEBUG(21880,
+ 1,
+ "balancerShouldReturnRandomMigrations: source: {sourceShardId} dest: {destShardId}",
+ "sourceShardId"_attr = sourceShardId,
+ "destShardId"_attr = destShardId);
const auto& chunks = distribution.getChunks(sourceShardId);
@@ -361,7 +365,7 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt
if (MONGO_unlikely(balancerShouldReturnRandomMigrations.shouldFail()) &&
!distribution.nss().isConfigDB()) {
- LOG(1) << "balancerShouldReturnRandomMigrations failpoint is set";
+ LOGV2_DEBUG(21881, 1, "balancerShouldReturnRandomMigrations failpoint is set");
if (shardStats.size() < 2)
return migrations;
@@ -402,8 +406,10 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt
_getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards);
if (!to.isValid()) {
if (migrations.empty()) {
- warning() << "Chunk " << redact(chunk.toString())
- << " is on a draining shard, but no appropriate recipient found";
+ LOGV2_WARNING(21889,
+ "Chunk {chunk} is on a draining shard, but no appropriate "
+ "recipient found",
+ "chunk"_attr = redact(chunk.toString()));
}
continue;
}
@@ -417,8 +423,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt
}
if (migrations.empty()) {
- warning() << "Unable to find any chunk to move from draining shard " << stat.shardId
- << ". numJumboChunks: " << numJumboChunks;
+ LOGV2_WARNING(21890,
+ "Unable to find any chunk to move from draining shard "
+ "{stat_shardId}. numJumboChunks: {numJumboChunks}",
+ "stat_shardId"_attr = stat.shardId,
+ "numJumboChunks"_attr = numJumboChunks);
}
}
}
@@ -441,8 +450,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt
continue;
if (chunk.getJumbo()) {
- warning() << "Chunk " << redact(chunk.toString()) << " violates zone "
- << redact(tag) << ", but it is jumbo and cannot be moved";
+ LOGV2_WARNING(
+ 21891,
+ "Chunk {chunk} violates zone {tag}, but it is jumbo and cannot be moved",
+ "chunk"_attr = redact(chunk.toString()),
+ "tag"_attr = redact(tag));
continue;
}
@@ -450,8 +462,11 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt
_getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards);
if (!to.isValid()) {
if (migrations.empty()) {
- warning() << "Chunk " << redact(chunk.toString()) << " violates zone "
- << redact(tag) << ", but no appropriate recipient found";
+ LOGV2_WARNING(
+ 21892,
+ "Chunk {chunk} violates zone {tag}, but no appropriate recipient found",
+ "chunk"_attr = redact(chunk.toString()),
+ "tag"_attr = redact(tag));
}
continue;
}
@@ -490,10 +505,14 @@ vector<MigrateInfo> BalancerPolicy::balance(const ShardStatisticsVector& shardSt
// should not be possible so warn the operator to correct it.
if (totalNumberOfShardsWithTag == 0) {
if (!tag.empty()) {
- warning() << "Zone " << redact(tag) << " in collection " << distribution.nss()
- << " has no assigned shards and chunks which fall into it cannot be "
- "balanced. This should be corrected by either assigning shards to the "
- "zone or by deleting it.";
+ LOGV2_WARNING(
+ 21893,
+ "Zone {tag} in collection {distribution_nss} has no assigned shards and chunks "
+ "which fall into it cannot be "
+ "balanced. This should be corrected by either assigning shards to the "
+ "zone or by deleting it.",
+ "tag"_attr = redact(tag),
+ "distribution_nss"_attr = distribution.nss());
}
continue;
}
@@ -552,7 +571,7 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats,
const ShardId to = _getLeastLoadedReceiverShard(shardStats, distribution, tag, *usedShards);
if (!to.isValid()) {
if (migrations->empty()) {
- log() << "No available shards to take chunks for zone [" << tag << "]";
+ LOGV2(21882, "No available shards to take chunks for zone [{tag}]", "tag"_attr = tag);
}
return false;
}
@@ -565,12 +584,22 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats,
const size_t imbalance = max - idealNumberOfChunksPerShardForTag;
- LOG(1) << "collection : " << distribution.nss().ns();
- LOG(1) << "zone : " << tag;
- LOG(1) << "donor : " << from << " chunks on " << max;
- LOG(1) << "receiver : " << to << " chunks on " << min;
- LOG(1) << "ideal : " << idealNumberOfChunksPerShardForTag;
- LOG(1) << "threshold : " << kDefaultImbalanceThreshold;
+ LOGV2_DEBUG(21883,
+ 1,
+ "collection : {distribution_nss_ns}",
+ "distribution_nss_ns"_attr = distribution.nss().ns());
+ LOGV2_DEBUG(21884, 1, "zone : {tag}", "tag"_attr = tag);
+ LOGV2_DEBUG(
+ 21885, 1, "donor : {from} chunks on {max}", "from"_attr = from, "max"_attr = max);
+ LOGV2_DEBUG(21886, 1, "receiver : {to} chunks on {min}", "to"_attr = to, "min"_attr = min);
+ LOGV2_DEBUG(21887,
+ 1,
+ "ideal : {idealNumberOfChunksPerShardForTag}",
+ "idealNumberOfChunksPerShardForTag"_attr = idealNumberOfChunksPerShardForTag);
+ LOGV2_DEBUG(21888,
+ 1,
+ "threshold : {kDefaultImbalanceThreshold}",
+ "kDefaultImbalanceThreshold"_attr = kDefaultImbalanceThreshold);
// Check whether it is necessary to balance within this zone
if (imbalance < kDefaultImbalanceThreshold)
@@ -596,9 +625,13 @@ bool BalancerPolicy::_singleZoneBalance(const ShardStatisticsVector& shardStats,
}
if (numJumboChunks) {
- warning() << "Shard: " << from << ", collection: " << distribution.nss().ns()
- << " has only jumbo chunks for zone \'" << tag
- << "\' and cannot be balanced. Jumbo chunks count: " << numJumboChunks;
+ LOGV2_WARNING(21894,
+ "Shard: {from}, collection: {distribution_nss_ns} has only jumbo chunks for "
+ "zone \'{tag}\' and cannot be balanced. Jumbo chunks count: {numJumboChunks}",
+ "from"_attr = from,
+ "distribution_nss_ns"_attr = distribution.nss().ns(),
+ "tag"_attr = tag,
+ "numJumboChunks"_attr = numJumboChunks);
}
return false;
diff --git a/src/mongo/db/s/balancer/cluster_statistics_impl.cpp b/src/mongo/db/s/balancer/cluster_statistics_impl.cpp
index 9fd3ebf675d..73e47dd5c9d 100644
--- a/src/mongo/db/s/balancer/cluster_statistics_impl.cpp
+++ b/src/mongo/db/s/balancer/cluster_statistics_impl.cpp
@@ -38,6 +38,7 @@
#include "mongo/base/status_with.h"
#include "mongo/bson/util/bson_extract.h"
#include "mongo/client/read_preference.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
@@ -141,8 +142,12 @@ StatusWith<std::vector<ShardStatistics>> ClusterStatisticsImpl::getStats(Operati
} else {
// Since the mongod version is only used for reporting, there is no need to fail the
// entire round if it cannot be retrieved, so just leave it empty
- log() << "Unable to obtain shard version for " << shard.getName()
- << causedBy(mongoDVersionStatus.getStatus());
+ LOGV2(21895,
+ "Unable to obtain shard version for "
+ "{shard_getName}{causedBy_mongoDVersionStatus_getStatus}",
+ "shard_getName"_attr = shard.getName(),
+ "causedBy_mongoDVersionStatus_getStatus"_attr =
+ causedBy(mongoDVersionStatus.getStatus()));
}
std::set<std::string> shardTags;
diff --git a/src/mongo/db/s/balancer/migration_manager.cpp b/src/mongo/db/s/balancer/migration_manager.cpp
index ae0997fa9de..a14202c643d 100644
--- a/src/mongo/db/s/balancer/migration_manager.cpp
+++ b/src/mongo/db/s/balancer/migration_manager.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/s/balancer/scoped_migration_request.h"
#include "mongo/db/s/balancer/type_migration.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_registry.h"
@@ -234,9 +235,12 @@ void MigrationManager::startRecoveryAndAcquireDistLocks(OperationContext* opCtx)
boost::none);
if (!statusWithMigrationsQueryResponse.isOK()) {
- log() << "Unable to read config.migrations collection documents for balancer migration"
- << " recovery. Abandoning balancer recovery."
- << causedBy(redact(statusWithMigrationsQueryResponse.getStatus()));
+ LOGV2(21896,
+ "Unable to read config.migrations collection documents for balancer migration "
+ "recovery. Abandoning balancer "
+ "recovery.{causedBy_statusWithMigrationsQueryResponse_getStatus}",
+ "causedBy_statusWithMigrationsQueryResponse_getStatus"_attr =
+ causedBy(redact(statusWithMigrationsQueryResponse.getStatus())));
return;
}
@@ -246,9 +250,13 @@ void MigrationManager::startRecoveryAndAcquireDistLocks(OperationContext* opCtx)
// The format of this migration document is incorrect. The balancer holds a distlock for
// this migration, but without parsing the migration document we cannot identify which
// distlock must be released. So we must release all distlocks.
- log() << "Unable to parse config.migrations document '" << redact(migration.toString())
- << "' for balancer migration recovery. Abandoning balancer recovery."
- << causedBy(redact(statusWithMigrationType.getStatus()));
+ LOGV2(21897,
+ "Unable to parse config.migrations document '{migration}' for balancer migration "
+ "recovery. Abandoning balancer "
+ "recovery.{causedBy_statusWithMigrationType_getStatus}",
+ "migration"_attr = redact(migration.toString()),
+ "causedBy_statusWithMigrationType_getStatus"_attr =
+ causedBy(redact(statusWithMigrationType.getStatus())));
return;
}
MigrationType migrateType = std::move(statusWithMigrationType.getValue());
@@ -265,11 +273,13 @@ void MigrationManager::startRecoveryAndAcquireDistLocks(OperationContext* opCtx)
auto statusWithDistLockHandle = distLockManager->tryLockWithLocalWriteConcern(
opCtx, migrateType.getNss().ns(), whyMessage, _lockSessionID);
if (!statusWithDistLockHandle.isOK()) {
- log() << "Failed to acquire distributed lock for collection '"
- << migrateType.getNss().ns()
- << "' during balancer recovery of an active migration. Abandoning"
- << " balancer recovery."
- << causedBy(redact(statusWithDistLockHandle.getStatus()));
+ LOGV2(21898,
+ "Failed to acquire distributed lock for collection '{migrateType_getNss_ns}' "
+ "during balancer recovery of an active migration. Abandoning balancer "
+ "recovery.{causedBy_statusWithDistLockHandle_getStatus}",
+ "migrateType_getNss_ns"_attr = migrateType.getNss().ns(),
+ "causedBy_statusWithDistLockHandle_getStatus"_attr =
+ causedBy(redact(statusWithDistLockHandle.getStatus())));
return;
}
}
@@ -320,9 +330,12 @@ void MigrationManager::finishRecovery(OperationContext* opCtx,
// This shouldn't happen because the collection was intact and sharded when the previous
// config primary was active and the dist locks have been held by the balancer
// throughout. Abort migration recovery.
- log() << "Unable to reload chunk metadata for collection '" << nss
- << "' during balancer recovery. Abandoning recovery."
- << causedBy(redact(routingInfoStatus.getStatus()));
+ LOGV2(21899,
+ "Unable to reload chunk metadata for collection '{nss}' during balancer "
+ "recovery. Abandoning recovery.{causedBy_routingInfoStatus_getStatus}",
+ "nss"_attr = nss,
+ "causedBy_routingInfoStatus_getStatus"_attr =
+ causedBy(redact(routingInfoStatus.getStatus())));
return;
}
diff --git a/src/mongo/db/s/balancer/scoped_migration_request.cpp b/src/mongo/db/s/balancer/scoped_migration_request.cpp
index 3333b5f3ab8..b06cb1fa9f0 100644
--- a/src/mongo/db/s/balancer/scoped_migration_request.cpp
+++ b/src/mongo/db/s/balancer/scoped_migration_request.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/s/balancer/type_migration.h"
#include "mongo/db/write_concern_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -68,8 +69,11 @@ ScopedMigrationRequest::~ScopedMigrationRequest() {
_opCtx, MigrationType::ConfigNS, migrationDocumentIdentifier, kMajorityWriteConcern);
if (!result.isOK()) {
- LOG(0) << "Failed to remove config.migrations document for migration '"
- << migrationDocumentIdentifier.toString() << "'" << causedBy(redact(result));
+ LOGV2(21900,
+ "Failed to remove config.migrations document for migration "
+ "'{migrationDocumentIdentifier}'{causedBy_result}",
+ "migrationDocumentIdentifier"_attr = migrationDocumentIdentifier.toString(),
+ "causedBy_result"_attr = causedBy(redact(result)));
}
}
@@ -141,10 +145,13 @@ StatusWith<ScopedMigrationRequest> ScopedMigrationRequest::writeMigration(
MigrateInfo activeMigrateInfo = statusWithActiveMigration.getValue().toMigrateInfo();
if (activeMigrateInfo.to != migrateInfo.to ||
activeMigrateInfo.from != migrateInfo.from) {
- log() << "Failed to write document '" << redact(migrateInfo.toString())
- << "' to config.migrations because there is already an active migration for"
- << " that chunk: '" << redact(activeMigrateInfo.toString()) << "'."
- << causedBy(redact(result));
+ LOGV2(21901,
+ "Failed to write document '{migrateInfo}' to config.migrations because there "
+ "is already an active migration for that chunk: "
+ "'{activeMigrateInfo}'.{causedBy_result}",
+ "migrateInfo"_attr = redact(migrateInfo.toString()),
+ "activeMigrateInfo"_attr = redact(activeMigrateInfo.toString()),
+ "causedBy_result"_attr = causedBy(redact(result)));
return result;
}
@@ -195,8 +202,12 @@ Status ScopedMigrationRequest::tryToRemoveMigration() {
void ScopedMigrationRequest::keepDocumentOnDestruct() {
invariant(_opCtx);
_opCtx = nullptr;
- LOG(1) << "Keeping config.migrations document with namespace '" << _nss << "' and minKey '"
- << _minKey << "' for balancer recovery";
+ LOGV2_DEBUG(21902,
+ 1,
+ "Keeping config.migrations document with namespace '{nss}' and minKey '{minKey}' "
+ "for balancer recovery",
+ "nss"_attr = _nss,
+ "minKey"_attr = _minKey);
}
} // namespace mongo
diff --git a/src/mongo/db/s/chunk_splitter.cpp b/src/mongo/db/s/chunk_splitter.cpp
index f49d08743a7..3c420e838fb 100644
--- a/src/mongo/db/s/chunk_splitter.cpp
+++ b/src/mongo/db/s/chunk_splitter.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/s/split_chunk.h"
#include "mongo/db/s/split_vector.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog_cache.h"
@@ -204,8 +205,11 @@ bool isAutoBalanceEnabled(OperationContext* opCtx,
auto collStatus = Grid::get(opCtx)->catalogClient()->getCollection(opCtx, nss);
if (!collStatus.isOK()) {
- log() << "Auto-split for " << nss << " failed to load collection metadata"
- << causedBy(redact(collStatus.getStatus()));
+ LOGV2(21903,
+ "Auto-split for {nss} failed to load collection "
+ "metadata{causedBy_collStatus_getStatus}",
+ "nss"_attr = nss,
+ "causedBy_collStatus_getStatus"_attr = causedBy(redact(collStatus.getStatus())));
return false;
}
@@ -245,7 +249,7 @@ void ChunkSplitter::onStepUp() {
}
_isPrimary = true;
- log() << "The ChunkSplitter has started and will accept autosplit tasks.";
+ LOGV2(21904, "The ChunkSplitter has started and will accept autosplit tasks.");
}
void ChunkSplitter::onStepDown() {
@@ -255,8 +259,9 @@ void ChunkSplitter::onStepDown() {
}
_isPrimary = false;
- log() << "The ChunkSplitter has stopped and will no longer run new autosplit tasks. Any "
- << "autosplit tasks that have already started will be allowed to finish.";
+ LOGV2(21905,
+ "The ChunkSplitter has stopped and will no longer run new autosplit tasks. Any autosplit "
+ "tasks that have already started will be allowed to finish.");
}
void ChunkSplitter::waitForIdle() {
@@ -312,9 +317,13 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp
const uint64_t maxChunkSizeBytes = balancerConfig->getMaxChunkSizeBytes();
- LOG(1) << "about to initiate autosplit: " << redact(chunk.toString())
- << " dataWritten since last check: " << dataWritten
- << " maxChunkSizeBytes: " << maxChunkSizeBytes;
+ LOGV2_DEBUG(21906,
+ 1,
+ "about to initiate autosplit: {chunk} dataWritten since last check: "
+ "{dataWritten} maxChunkSizeBytes: {maxChunkSizeBytes}",
+ "chunk"_attr = redact(chunk.toString()),
+ "dataWritten"_attr = dataWritten,
+ "maxChunkSizeBytes"_attr = maxChunkSizeBytes);
chunkSplitStateDriver->prepareSplit();
auto splitPoints = uassertStatusOK(splitVector(opCtx.get(),
@@ -328,9 +337,11 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp
maxChunkSizeBytes));
if (splitPoints.empty()) {
- LOG(1)
- << "ChunkSplitter attempted split but not enough split points were found for chunk "
- << redact(chunk.toString());
+ LOGV2_DEBUG(21907,
+ 1,
+ "ChunkSplitter attempted split but not enough split points were found for "
+ "chunk {chunk}",
+ "chunk"_attr = redact(chunk.toString()));
// Reset our size estimate that we had prior to splitVector to 0, while still counting
// the bytes that have been written in parallel to this split task
chunkSplitStateDriver->abandonPrepare();
@@ -377,12 +388,19 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp
const bool shouldBalance = isAutoBalanceEnabled(opCtx.get(), nss, balancerConfig);
- log() << "autosplitted " << nss << " chunk: " << redact(chunk.toString()) << " into "
- << (splitPoints.size() + 1) << " parts (maxChunkSizeBytes " << maxChunkSizeBytes
- << ")"
- << (topChunkMinKey.isEmpty() ? ""
- : " (top chunk migration suggested" +
- (std::string)(shouldBalance ? ")" : ", but no migrations allowed)"));
+ LOGV2(
+ 21908,
+ "autosplitted {nss} chunk: {chunk} into {splitPoints_size_1} parts (maxChunkSizeBytes "
+ "{maxChunkSizeBytes}){topChunkMinKey_isEmpty_top_chunk_migration_suggested_std_string_"
+ "shouldBalance_but_no_migrations_allowed}",
+ "nss"_attr = nss,
+ "chunk"_attr = redact(chunk.toString()),
+ "splitPoints_size_1"_attr = (splitPoints.size() + 1),
+ "maxChunkSizeBytes"_attr = maxChunkSizeBytes,
+ "topChunkMinKey_isEmpty_top_chunk_migration_suggested_std_string_shouldBalance_but_no_migrations_allowed"_attr =
+ (topChunkMinKey.isEmpty() ? ""
+ : " (top chunk migration suggested" +
+ (std::string)(shouldBalance ? ")" : ", but no migrations allowed)")));
// Because the ShardServerOpObserver uses the metadata from the CSS for tracking incoming
// writes, if we split a chunk but do not force a CSS refresh, subsequent inserts will see
@@ -403,13 +421,20 @@ void ChunkSplitter::_runAutosplit(std::shared_ptr<ChunkSplitStateDriver> chunkSp
// assumption that succeeding inserts will fall on the top chunk.
moveChunk(opCtx.get(), nss, topChunkMinKey);
} catch (const DBException& ex) {
- log() << "Top-chunk optimization failed to move chunk "
- << redact(ChunkRange(min, max).toString()) << " in collection " << nss
- << " after a successful split" << causedBy(redact(ex.toStatus()));
+ LOGV2(21909,
+ "Top-chunk optimization failed to move chunk {ChunkRange_min_max} in collection "
+ "{nss} after a successful split{causedBy_ex_toStatus}",
+ "ChunkRange_min_max"_attr = redact(ChunkRange(min, max).toString()),
+ "nss"_attr = nss,
+ "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus())));
}
} catch (const DBException& ex) {
- log() << "Unable to auto-split chunk " << redact(ChunkRange(min, max).toString())
- << " in namespace " << nss << causedBy(redact(ex.toStatus()));
+ LOGV2(21910,
+ "Unable to auto-split chunk {ChunkRange_min_max} in namespace "
+ "{nss}{causedBy_ex_toStatus}",
+ "ChunkRange_min_max"_attr = redact(ChunkRange(min, max).toString()),
+ "nss"_attr = nss,
+ "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus())));
}
}
diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp
index 444fd536a50..b7b565f6726 100644
--- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp
+++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/s/shard_filtering_metadata_refresh.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/request_types/migration_secondary_throttle_options.h"
#include "mongo/util/log.h"
@@ -80,8 +81,9 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx,
auto* const css = CollectionShardingRuntime::get(opCtx, ns);
const auto metadata = css->getCurrentMetadata();
if (!metadata->isSharded()) {
- LOG(0) << "skipping orphaned data cleanup for " << ns.ns()
- << ", collection is not sharded";
+ LOGV2(21911,
+ "skipping orphaned data cleanup for {ns_ns}, collection is not sharded",
+ "ns_ns"_attr = ns.ns());
return CleanupResult::kDone;
}
@@ -92,7 +94,7 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx,
<< "could not cleanup orphaned data, start key " << startingFromKey
<< " does not match shard key pattern " << keyPattern;
- log() << *errMsg;
+ LOGV2(21912, "{errMsg}", "errMsg"_attr = *errMsg);
return CleanupResult::kError;
}
} else {
@@ -101,8 +103,12 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx,
targetRange = css->getNextOrphanRange(startingFromKey);
if (!targetRange) {
- LOG(1) << "cleanupOrphaned requested for " << ns.toString() << " starting from "
- << redact(startingFromKey) << ", no orphan ranges remain";
+ LOGV2_DEBUG(21913,
+ 1,
+ "cleanupOrphaned requested for {ns} starting from {startingFromKey}, no "
+ "orphan ranges remain",
+ "ns"_attr = ns.toString(),
+ "startingFromKey"_attr = redact(startingFromKey));
return CleanupResult::kDone;
}
@@ -115,16 +121,21 @@ CleanupResult cleanupOrphanedData(OperationContext* opCtx,
// Sleep waiting for our own deletion. We don't actually care about any others, so there is no
// need to call css::waitForClean() here.
- LOG(1) << "cleanupOrphaned requested for " << ns.toString() << " starting from "
- << redact(startingFromKey) << ", removing next orphan range "
- << redact(targetRange->toString()) << "; waiting...";
+ LOGV2_DEBUG(21914,
+ 1,
+ "cleanupOrphaned requested for {ns} starting from {startingFromKey}, removing next "
+ "orphan range {targetRange}; waiting...",
+ "ns"_attr = ns.toString(),
+ "startingFromKey"_attr = redact(startingFromKey),
+ "targetRange"_attr = redact(targetRange->toString()));
Status result = cleanupCompleteFuture.getNoThrow(opCtx);
- LOG(1) << "Finished waiting for last " << ns.toString() << " orphan range cleanup";
+ LOGV2_DEBUG(
+ 21915, 1, "Finished waiting for last {ns} orphan range cleanup", "ns"_attr = ns.toString());
if (!result.isOK()) {
- log() << redact(result.reason());
+ LOGV2(21916, "{result_reason}", "result_reason"_attr = redact(result.reason()));
*errMsg = result.reason();
return CleanupResult::kError;
}
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index f5d679b83b4..d2ce632ad95 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/s/sharded_connection_info.h"
#include "mongo/db/s/sharding_runtime_d_params_gen.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/duration.h"
#include "mongo/util/log.h"
@@ -205,7 +206,10 @@ void CollectionShardingRuntime::setFilteringMetadata(OperationContext* opCtx,
stdx::lock_guard lk(_metadataManagerLock);
if (!newMetadata.isSharded()) {
- LOG(0) << "Marking collection " << _nss.ns() << " as " << newMetadata.toStringBasic();
+ LOGV2(21917,
+ "Marking collection {nss_ns} as {newMetadata_Basic}",
+ "nss_ns"_attr = _nss.ns(),
+ "newMetadata_Basic"_attr = newMetadata.toStringBasic());
_metadataType = MetadataType::kUnsharded;
_metadataManager.reset();
++_numMetadataManagerChanges;
@@ -269,13 +273,18 @@ Status CollectionShardingRuntime::waitForClean(OperationContext* opCtx,
stillScheduled = self->_metadataManager->trackOrphanedDataCleanup(orphanRange);
if (!stillScheduled) {
- log() << "Finished deleting " << nss.ns() << " range "
- << redact(orphanRange.toString());
+ LOGV2(21918,
+ "Finished deleting {nss_ns} range {orphanRange}",
+ "nss_ns"_attr = nss.ns(),
+ "orphanRange"_attr = redact(orphanRange.toString()));
return Status::OK();
}
}
- log() << "Waiting for deletion of " << nss.ns() << " range " << orphanRange;
+ LOGV2(21919,
+ "Waiting for deletion of {nss_ns} range {orphanRange}",
+ "nss_ns"_attr = nss.ns(),
+ "orphanRange"_attr = orphanRange);
Status result = stillScheduled->getNoThrow(opCtx);
diff --git a/src/mongo/db/s/config/configsvr_add_shard_command.cpp b/src/mongo/db/s/config/configsvr_add_shard_command.cpp
index bf61721b30f..6f6b449b0cf 100644
--- a/src/mongo/db/s/config/configsvr_add_shard_command.cpp
+++ b/src/mongo/db/s/config/configsvr_add_shard_command.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/repl/repl_set_config.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/config/sharding_catalog_manager.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/add_shard_request_type.h"
@@ -129,8 +130,10 @@ public:
parsedRequest.hasMaxSize() ? parsedRequest.getMaxSize() : kMaxSizeMBDefault);
if (!addShardResult.isOK()) {
- log() << "addShard request '" << parsedRequest << "'"
- << "failed" << causedBy(addShardResult.getStatus());
+ LOGV2(21920,
+ "addShard request '{parsedRequest}'failed{causedBy_addShardResult_getStatus}",
+ "parsedRequest"_attr = parsedRequest,
+ "causedBy_addShardResult_getStatus"_attr = causedBy(addShardResult.getStatus()));
uassertStatusOK(addShardResult.getStatus());
}
diff --git a/src/mongo/db/s/config/configsvr_move_primary_command.cpp b/src/mongo/db/s/config/configsvr_move_primary_command.cpp
index fe5c843303e..1595d7fdcdd 100644
--- a/src/mongo/db/s/config/configsvr_move_primary_command.cpp
+++ b/src/mongo/db/s/config/configsvr_move_primary_command.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/s/config/sharding_catalog_manager.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_registry.h"
@@ -158,8 +159,13 @@ public:
const auto toShard = [&]() {
auto toShardStatus = shardRegistry->getShard(opCtx, to);
if (!toShardStatus.isOK()) {
- log() << "Could not move database '" << dbname << "' to shard '" << to
- << causedBy(toShardStatus.getStatus());
+ LOGV2(21921,
+ "Could not move database '{dbname}' to shard "
+ "'{to}{causedBy_toShardStatus_getStatus}",
+ "dbname"_attr = dbname,
+ "to"_attr = to,
+ "causedBy_toShardStatus_getStatus"_attr =
+ causedBy(toShardStatus.getStatus()));
uassertStatusOKWithContext(toShardStatus.getStatus(),
str::stream() << "Could not move database '" << dbname
<< "' to shard '" << to << "'");
diff --git a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
index 3b6a9337014..3d862d632d1 100644
--- a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
+++ b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/s/config/sharding_catalog_manager.h"
#include "mongo/db/s/shard_key_util.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/dist_lock_manager.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/refine_collection_shard_key_gen.h"
@@ -148,7 +149,9 @@ public:
collType.getUnique(),
false); // createIndexIfPossible
- LOG(0) << "CMD: refineCollectionShardKey: " << request().toBSON({});
+ LOGV2(21922,
+ "CMD: refineCollectionShardKey: {request}",
+ "request"_attr = request().toBSON({}));
audit::logRefineCollectionShardKey(opCtx->getClient(), nss.ns(), proposedKey);
diff --git a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp
index 9fd9e7298b4..2b3cfc9a1ae 100644
--- a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp
+++ b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/s/config/sharding_catalog_manager.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_registry.h"
@@ -116,7 +117,7 @@ public:
try {
return shardingCatalogManager->removeShard(opCtx, shardId);
} catch (const DBException& ex) {
- LOG(0) << "Failed to remove shard due to " << redact(ex);
+ LOGV2(21923, "Failed to remove shard due to {ex}", "ex"_attr = redact(ex));
throw;
}
}();
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
index 38ef0df3f11..b1d23be5b0c 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
@@ -56,6 +56,7 @@
#include "mongo/db/s/sharding_logging.h"
#include "mongo/executor/network_interface.h"
#include "mongo/executor/task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog/sharding_catalog_client_impl.h"
@@ -421,15 +422,16 @@ void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const Names
BSONObj(),
ShardingCatalogClient::kMajorityWriteConcern));
- LOG(1) << "dropCollection " << nss.ns() << " started";
+ LOGV2_DEBUG(21924, 1, "dropCollection {nss_ns} started", "nss_ns"_attr = nss.ns());
sendDropCollectionToAllShards(opCtx, nss);
- LOG(1) << "dropCollection " << nss.ns() << " shard data deleted";
+ LOGV2_DEBUG(21925, 1, "dropCollection {nss_ns} shard data deleted", "nss_ns"_attr = nss.ns());
removeChunksAndTagsForDroppedCollection(opCtx, nss);
- LOG(1) << "dropCollection " << nss.ns() << " chunk and tag data deleted";
+ LOGV2_DEBUG(
+ 21926, 1, "dropCollection {nss_ns} chunk and tag data deleted", "nss_ns"_attr = nss.ns());
// Mark the collection as dropped
CollectionType coll;
@@ -442,11 +444,12 @@ void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const Names
uassertStatusOK(ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection(
opCtx, nss, coll, upsert));
- LOG(1) << "dropCollection " << nss.ns() << " collection marked as dropped";
+ LOGV2_DEBUG(
+ 21927, 1, "dropCollection {nss_ns} collection marked as dropped", "nss_ns"_attr = nss.ns());
sendSSVToAllShards(opCtx, nss);
- LOG(1) << "dropCollection " << nss.ns() << " completed";
+ LOGV2_DEBUG(21928, 1, "dropCollection {nss_ns} completed", "nss_ns"_attr = nss.ns());
ShardingLogging::get(opCtx)->logChange(
opCtx, "dropCollection", nss.ns(), BSONObj(), ShardingCatalogClient::kMajorityWriteConcern);
@@ -455,8 +458,10 @@ void ShardingCatalogManager::dropCollection(OperationContext* opCtx, const Names
void ShardingCatalogManager::ensureDropCollectionCompleted(OperationContext* opCtx,
const NamespaceString& nss) {
- LOG(1) << "Ensuring config entries for " << nss.ns()
- << " from previous dropCollection are cleared";
+ LOGV2_DEBUG(21929,
+ 1,
+ "Ensuring config entries for {nss_ns} from previous dropCollection are cleared",
+ "nss_ns"_attr = nss.ns());
sendDropCollectionToAllShards(opCtx, nss);
removeChunksAndTagsForDroppedCollection(opCtx, nss);
sendSSVToAllShards(opCtx, nss);
@@ -479,7 +484,7 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio
.docs;
if (shardedColls.empty()) {
- LOG(0) << "all sharded collections already have UUIDs";
+ LOGV2(21930, "all sharded collections already have UUIDs");
// We did a local read of the collections collection above and found that all sharded
// collections already have UUIDs. However, the data may not be majority committed (a
@@ -491,8 +496,10 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio
}
// Generate and persist a new UUID for each collection that did not have a UUID.
- LOG(0) << "generating UUIDs for " << shardedColls.size()
- << " sharded collections that do not yet have a UUID";
+ LOGV2(
+ 21931,
+ "generating UUIDs for {shardedColls_size} sharded collections that do not yet have a UUID",
+ "shardedColls_size"_attr = shardedColls.size());
for (auto& coll : shardedColls) {
auto collType = uassertStatusOK(CollectionType::fromBSON(coll));
invariant(!collType.getUUID());
@@ -502,8 +509,12 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio
uassertStatusOK(ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection(
opCtx, collType.getNs(), collType, false /* upsert */));
- LOG(2) << "updated entry in config.collections for sharded collection " << collType.getNs()
- << " with generated UUID " << uuid;
+ LOGV2_DEBUG(21932,
+ 2,
+ "updated entry in config.collections for sharded collection {collType_getNs} "
+ "with generated UUID {uuid}",
+ "collType_getNs"_attr = collType.getNs(),
+ "uuid"_attr = uuid);
}
}
@@ -617,9 +628,12 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx,
true /* startTransaction */,
txnNumber));
- log() << "refineCollectionShardKey: updated collection entry for '" << nss.ns()
- << "': took " << executionTimer.millis()
- << " ms. Total time taken: " << totalTimer.millis() << " ms.";
+ LOGV2(21933,
+ "refineCollectionShardKey: updated collection entry for '{nss_ns}': took "
+ "{executionTimer_millis} ms. Total time taken: {totalTimer_millis} ms.",
+ "nss_ns"_attr = nss.ns(),
+ "executionTimer_millis"_attr = executionTimer.millis(),
+ "totalTimer_millis"_attr = totalTimer.millis());
executionTimer.reset();
// Update all config.chunks entries for the given namespace by setting (i) their epoch to
@@ -627,7 +641,7 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx,
// MinKey (except for the global max chunk where the max bounds are set to MaxKey), and
// unsetting (iii) their jumbo field.
if (MONGO_unlikely(hangRefineCollectionShardKeyBeforeUpdatingChunks.shouldFail())) {
- log() << "Hit hangRefineCollectionShardKeyBeforeUpdatingChunks failpoint";
+ LOGV2(21934, "Hit hangRefineCollectionShardKeyBeforeUpdatingChunks failpoint");
hangRefineCollectionShardKeyBeforeUpdatingChunks.pauseWhileSet(opCtx);
}
@@ -653,9 +667,12 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx,
false, // startTransaction
txnNumber));
- log() << "refineCollectionShardKey: updated chunk entries for '" << nss.ns() << "': took "
- << executionTimer.millis() << " ms. Total time taken: " << totalTimer.millis()
- << " ms.";
+ LOGV2(21935,
+ "refineCollectionShardKey: updated chunk entries for '{nss_ns}': took "
+ "{executionTimer_millis} ms. Total time taken: {totalTimer_millis} ms.",
+ "nss_ns"_attr = nss.ns(),
+ "executionTimer_millis"_attr = executionTimer.millis(),
+ "totalTimer_millis"_attr = totalTimer.millis());
executionTimer.reset();
// Update all config.tags entries for the given namespace by setting their bounds for each
@@ -680,12 +697,15 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx,
false, // startTransaction
txnNumber));
- log() << "refineCollectionShardKey: updated zone entries for '" << nss.ns() << "': took "
- << executionTimer.millis() << " ms. Total time taken: " << totalTimer.millis()
- << " ms.";
+ LOGV2(21936,
+ "refineCollectionShardKey: updated zone entries for '{nss_ns}': took "
+ "{executionTimer_millis} ms. Total time taken: {totalTimer_millis} ms.",
+ "nss_ns"_attr = nss.ns(),
+ "executionTimer_millis"_attr = executionTimer.millis(),
+ "totalTimer_millis"_attr = totalTimer.millis());
if (MONGO_unlikely(hangRefineCollectionShardKeyBeforeCommit.shouldFail())) {
- log() << "Hit hangRefineCollectionShardKeyBeforeCommit failpoint";
+ LOGV2(21937, "Hit hangRefineCollectionShardKeyBeforeCommit failpoint");
hangRefineCollectionShardKeyBeforeCommit.pauseWhileSet(opCtx);
}
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp
index 4028d41a34d..c46a65966a7 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/server_options.h"
#include "mongo/db/write_concern.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard.h"
@@ -150,7 +151,7 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx,
// Pick a primary shard for the new database.
DatabaseType db(dbName.toString(), shardPtr->getId(), false, databaseVersion::makeNew());
- log() << "Registering new database " << db << " in sharding catalog";
+ LOGV2(21938, "Registering new database {db} in sharding catalog", "db"_attr = db);
// Do this write with majority writeConcern to guarantee that the shard sees the write when it
// receives the _flushDatabaseCacheUpdates.
@@ -214,7 +215,7 @@ void ShardingCatalogManager::enableSharding(OperationContext* opCtx,
Milliseconds{30000}),
&unusedResult));
- log() << "Enabling sharding for database [" << dbName << "] in config db";
+ LOGV2(21939, "Enabling sharding for database [{dbName}] in config db", "dbName"_attr = dbName);
uassertStatusOK(Grid::get(opCtx)->catalogClient()->updateConfigDocument(
opCtx,
@@ -303,8 +304,10 @@ Status ShardingCatalogManager::commitMovePrimary(OperationContext* opCtx,
ShardingCatalogClient::kLocalWriteConcern);
if (!updateStatus.isOK()) {
- log() << "error committing movePrimary: " << dbname
- << causedBy(redact(updateStatus.getStatus()));
+ LOGV2(21940,
+ "error committing movePrimary: {dbname}{causedBy_updateStatus_getStatus}",
+ "dbname"_attr = dbname,
+ "causedBy_updateStatus_getStatus"_attr = causedBy(redact(updateStatus.getStatus())));
return updateStatus.getStatus();
}
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
index c388e826010..b2148656e52 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
@@ -59,6 +59,7 @@
#include "mongo/db/s/type_shard_identity.h"
#include "mongo/db/wire_version.h"
#include "mongo/executor/task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/config_server_version.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
@@ -161,7 +162,9 @@ StatusWith<Shard::CommandResponse> ShardingCatalogManager::_runCommandForAddShar
_executorForAddShard->wait(swCallbackHandle.getValue());
if (response.status == ErrorCodes::ExceededTimeLimit) {
- LOG(0) << "Operation timed out with status " << redact(response.status);
+ LOGV2(21941,
+ "Operation timed out with status {response_status}",
+ "response_status"_attr = redact(response.status));
}
if (!response.isOK()) {
@@ -672,7 +675,9 @@ StatusWith<std::string> ShardingCatalogManager::addShard(
return versionResponse.getValue().commandStatus;
}
- log() << "going to insert new entry for shard into config.shards: " << shardType.toString();
+ LOGV2(21942,
+ "going to insert new entry for shard into config.shards: {shardType}",
+ "shardType"_attr = shardType.toString());
Status result = Grid::get(opCtx)->catalogClient()->insertConfigDocument(
opCtx,
@@ -680,7 +685,10 @@ StatusWith<std::string> ShardingCatalogManager::addShard(
shardType.toBSON(),
ShardingCatalogClient::kLocalWriteConcern);
if (!result.isOK()) {
- log() << "error adding shard: " << shardType.toBSON() << " err: " << result.reason();
+ LOGV2(21943,
+ "error adding shard: {shardType} err: {result_reason}",
+ "shardType"_attr = shardType.toBSON(),
+ "result_reason"_attr = result.reason());
return result;
}
}
@@ -698,8 +706,11 @@ StatusWith<std::string> ShardingCatalogManager::addShard(
true,
ShardingCatalogClient::kLocalWriteConcern);
if (!status.isOK()) {
- log() << "adding shard " << shardConnectionString.toString()
- << " even though could not add database " << dbName;
+ LOGV2(21944,
+ "adding shard {shardConnectionString} even though could not add database "
+ "{dbName}",
+ "shardConnectionString"_attr = shardConnectionString.toString(),
+ "dbName"_attr = dbName);
}
}
}
@@ -773,7 +784,7 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx,
auto* const catalogClient = Grid::get(opCtx)->catalogClient();
if (!isShardCurrentlyDraining) {
- log() << "going to start draining shard: " << name;
+ LOGV2(21945, "going to start draining shard: {name}", "name"_attr = name);
// Record start in changelog
uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked(
@@ -811,9 +822,9 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx,
if (chunkCount > 0 || databaseCount > 0) {
// Still more draining to do
- LOG(0) << "chunkCount: " << chunkCount;
- LOG(0) << "databaseCount: " << databaseCount;
- LOG(0) << "jumboCount: " << jumboCount;
+ LOGV2(21946, "chunkCount: {chunkCount}", "chunkCount"_attr = chunkCount);
+ LOGV2(21947, "databaseCount: {databaseCount}", "databaseCount"_attr = databaseCount);
+ LOGV2(21948, "jumboCount: {jumboCount}", "jumboCount"_attr = jumboCount);
return {RemoveShardProgress::ONGOING,
boost::optional<RemoveShardProgress::DrainingShardUsage>(
@@ -821,7 +832,7 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx,
}
// Draining is done, now finish removing the shard.
- log() << "going to remove shard: " << name;
+ LOGV2(21949, "going to remove shard: {name}", "name"_attr = name);
audit::logRemoveShard(opCtx->getClient(), name);
uassertStatusOKWithContext(
diff --git a/src/mongo/db/s/database_sharding_state.cpp b/src/mongo/db/s/database_sharding_state.cpp
index 9580cf6026a..ed018daec96 100644
--- a/src/mongo/db/s/database_sharding_state.cpp
+++ b/src/mongo/db/s/database_sharding_state.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/s/operation_sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/database_version_helpers.h"
#include "mongo/s/stale_exception.h"
#include "mongo/util/fail_point.h"
@@ -120,8 +121,12 @@ void DatabaseShardingState::setDbVersion(OperationContext* opCtx,
boost::optional<DatabaseVersion> newDbVersion,
DSSLock&) {
invariant(opCtx->lockState()->isDbLockedForMode(_dbName, MODE_X));
- log() << "setting this node's cached database version for " << _dbName << " to "
- << (newDbVersion ? newDbVersion->toBSON() : BSONObj());
+ LOGV2(21950,
+ "setting this node's cached database version for {dbName} to "
+ "{newDbVersion_newDbVersion_BSONObj}",
+ "dbName"_attr = _dbName,
+ "newDbVersion_newDbVersion_BSONObj"_attr =
+ (newDbVersion ? newDbVersion->toBSON() : BSONObj()));
_dbVersion = newDbVersion;
}
diff --git a/src/mongo/db/s/flush_database_cache_updates_command.cpp b/src/mongo/db/s/flush_database_cache_updates_command.cpp
index 5e4fadfaae0..e96159b3cbd 100644
--- a/src/mongo/db/s/flush_database_cache_updates_command.cpp
+++ b/src/mongo/db/s/flush_database_cache_updates_command.cpp
@@ -50,6 +50,7 @@
#include "mongo/s/request_types/flush_database_cache_updates_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -133,7 +134,10 @@ public:
oss.waitForMigrationCriticalSectionSignal(opCtx);
if (request().getSyncFromConfig()) {
- LOG(1) << "Forcing remote routing table refresh for " << _dbName();
+ LOGV2_DEBUG(21981,
+ 1,
+ "Forcing remote routing table refresh for {dbName}",
+ "dbName"_attr = _dbName());
forceDatabaseRefresh(opCtx, _dbName());
}
diff --git a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
index f2791bf1fbd..2a2fd18a89f 100644
--- a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
+++ b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/s/shard_filtering_metadata_refresh.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog_cache_loader.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/flush_routing_table_cache_updates_gen.h"
@@ -132,7 +133,8 @@ public:
oss.waitForMigrationCriticalSectionSignal(opCtx);
if (request().getSyncFromConfig()) {
- LOG(1) << "Forcing remote routing table refresh for " << ns();
+ LOGV2_DEBUG(
+ 21982, 1, "Forcing remote routing table refresh for {ns}", "ns"_attr = ns());
forceShardFilteringMetadataRefresh(opCtx, ns());
}
diff --git a/src/mongo/db/s/merge_chunks_command.cpp b/src/mongo/db/s/merge_chunks_command.cpp
index d6db92888e2..5fd4574590b 100644
--- a/src/mongo/db/s/merge_chunks_command.cpp
+++ b/src/mongo/db/s/merge_chunks_command.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/shard_filtering_metadata_refresh.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
@@ -227,8 +228,11 @@ void mergeChunks(OperationContext* opCtx,
if ((!commandStatus.isOK() || !writeConcernStatus.isOK()) &&
checkMetadataForSuccess(opCtx, nss, epoch, ChunkRange(minKey, maxKey))) {
- LOG(1) << "mergeChunk [" << redact(minKey) << "," << redact(maxKey)
- << ") has already been committed.";
+ LOGV2_DEBUG(21983,
+ 1,
+ "mergeChunk [{minKey},{maxKey}) has already been committed.",
+ "minKey"_attr = redact(minKey),
+ "maxKey"_attr = redact(maxKey));
return;
}
diff --git a/src/mongo/db/s/metadata_manager.cpp b/src/mongo/db/s/metadata_manager.cpp
index f038c328052..ca3c324e7f8 100644
--- a/src/mongo/db/s/metadata_manager.cpp
+++ b/src/mongo/db/s/metadata_manager.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/range_arithmetic.h"
#include "mongo/db/s/range_deletion_util.h"
#include "mongo/db/s/sharding_runtime_d_params_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/fail_point.h"
@@ -167,14 +168,21 @@ void MetadataManager::setFilteringMetadata(CollectionMetadata remoteMetadata) {
// We already have the same or newer version
if (activeMetadata.getCollVersion().epoch() == remoteMetadata.getCollVersion().epoch() &&
activeMetadata.getCollVersion() >= remoteMetadata.getCollVersion()) {
- LOG(1) << "Ignoring update of active metadata " << activeMetadata.toStringBasic()
- << " with an older " << remoteMetadata.toStringBasic();
+ LOGV2_DEBUG(21984,
+ 1,
+ "Ignoring update of active metadata {activeMetadata_Basic} with an older "
+ "{remoteMetadata_Basic}",
+ "activeMetadata_Basic"_attr = activeMetadata.toStringBasic(),
+ "remoteMetadata_Basic"_attr = remoteMetadata.toStringBasic());
return;
}
- LOG(0) << "Updating metadata for collection " << _nss.ns() << " from "
- << activeMetadata.toStringBasic() << " to " << remoteMetadata.toStringBasic()
- << " due to version change";
+ LOGV2(21985,
+ "Updating metadata for collection {nss_ns} from {activeMetadata_Basic} to "
+ "{remoteMetadata_Basic} due to version change",
+ "nss_ns"_attr = _nss.ns(),
+ "activeMetadata_Basic"_attr = activeMetadata.toStringBasic(),
+ "remoteMetadata_Basic"_attr = remoteMetadata.toStringBasic());
// Resolve any receiving chunks, which might have completed by now
for (auto it = _receivingChunks.begin(); it != _receivingChunks.end();) {
@@ -187,8 +195,12 @@ void MetadataManager::setFilteringMetadata(CollectionMetadata remoteMetadata) {
// The remote metadata contains a chunk we were earlier in the process of receiving, so we
// deem it successfully received
- LOG(2) << "Verified chunk " << redact(receivingRange.toString()) << " for collection "
- << _nss.ns() << " has been migrated to this shard earlier";
+ LOGV2_DEBUG(21986,
+ 2,
+ "Verified chunk {receivingRange} for collection {nss_ns} has been migrated to "
+ "this shard earlier",
+ "receivingRange"_attr = redact(receivingRange.toString()),
+ "nss_ns"_attr = _nss.ns());
_receivingChunks.erase(it);
it = _receivingChunks.begin();
@@ -279,8 +291,11 @@ SharedSemiFuture<void> MetadataManager::beginReceive(ChunkRange const& range) {
_receivingChunks.emplace(range.getMin().getOwned(), range.getMax().getOwned());
- log() << "Scheduling deletion of any documents in " << _nss.ns() << " range "
- << redact(range.toString()) << " before migrating in a chunk covering the range";
+ LOGV2(21987,
+ "Scheduling deletion of any documents in {nss_ns} range {range} before migrating in a "
+ "chunk covering the range",
+ "nss_ns"_attr = _nss.ns(),
+ "range"_attr = redact(range.toString()));
return _submitRangeForDeletion(
lg, SemiFuture<void>::makeReady(), range, Seconds(orphanCleanupDelaySecs.load()));
@@ -292,8 +307,11 @@ void MetadataManager::forgetReceive(ChunkRange const& range) {
// This is potentially a partially received chunk, which needs to be cleaned up. We know none
// of these documents are in use, so they can go straight to the deletion queue.
- log() << "Abandoning in-migration of " << _nss.ns() << " range " << range
- << "; scheduling deletion of any documents already copied";
+ LOGV2(21988,
+ "Abandoning in-migration of {nss_ns} range {range}; scheduling deletion of any documents "
+ "already copied",
+ "nss_ns"_attr = _nss.ns(),
+ "range"_attr = range);
invariant(!_overlapsInUseChunk(lg, range));
@@ -327,8 +345,11 @@ SharedSemiFuture<void> MetadataManager::cleanUpRange(ChunkRange const& range,
shouldDelayBeforeDeletion ? Seconds(orphanCleanupDelaySecs.load()) : Seconds(0);
if (overlapMetadata) {
- log() << "Deletion of " << _nss.ns() << " range " << redact(range.toString())
- << " will be scheduled after all possibly dependent queries finish";
+ LOGV2(21989,
+ "Deletion of {nss_ns} range {range} will be scheduled after all possibly dependent "
+ "queries finish",
+ "nss_ns"_attr = _nss.ns(),
+ "range"_attr = redact(range.toString()));
++overlapMetadata->numContingentRangeDeletionTasks;
// Schedule the range for deletion once the overlapping metadata object is destroyed
// (meaning no more queries can be using the range) and obtain a future which will be
@@ -339,7 +360,10 @@ SharedSemiFuture<void> MetadataManager::cleanUpRange(ChunkRange const& range,
delayForActiveQueriesOnSecondariesToComplete);
} else {
// No running queries can depend on this range, so queue it for deletion immediately.
- log() << "Scheduling deletion of " << _nss.ns() << " range " << redact(range.toString());
+ LOGV2(21990,
+ "Scheduling deletion of {nss_ns} range {range}",
+ "nss_ns"_attr = _nss.ns(),
+ "range"_attr = redact(range.toString()));
return _submitRangeForDeletion(
lg, SemiFuture<void>::makeReady(), range, delayForActiveQueriesOnSecondariesToComplete);
diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
index 454fe2ac76b..76dd0bcde8e 100644
--- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
+++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp
@@ -52,6 +52,7 @@
#include "mongo/executor/remote_command_response.h"
#include "mongo/executor/task_executor.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
@@ -182,7 +183,9 @@ void LogTransactionOperationsForShardingHandler::commit(boost::optional<Timestam
auto idElement = documentKey["_id"];
if (idElement.eoo()) {
- warning() << "Received a document with no id, ignoring: " << redact(documentKey);
+ LOGV2_WARNING(21994,
+ "Received a document with no id, ignoring: {documentKey}",
+ "documentKey"_attr = redact(documentKey));
continue;
}
@@ -396,7 +399,9 @@ void MigrationChunkClonerSourceLegacy::cancelClone(OperationContext* opCtx) {
kRecvChunkAbort, _args.getNss(), _sessionId))
.getStatus();
if (!status.isOK()) {
- LOG(0) << "Failed to cancel migration " << causedBy(redact(status));
+ LOGV2(21991,
+ "Failed to cancel migration {causedBy_status}",
+ "causedBy_status"_attr = causedBy(redact(status)));
}
}
// Intentional fall through
@@ -419,8 +424,10 @@ void MigrationChunkClonerSourceLegacy::onInsertOp(OperationContext* opCtx,
BSONElement idElement = insertedDoc["_id"];
if (idElement.eoo()) {
- warning() << "logInsertOp got a document with no _id field, ignoring inserted document: "
- << redact(insertedDoc);
+ LOGV2_WARNING(21995,
+ "logInsertOp got a document with no _id field, ignoring inserted document: "
+ "{insertedDoc}",
+ "insertedDoc"_attr = redact(insertedDoc));
return;
}
@@ -450,8 +457,10 @@ void MigrationChunkClonerSourceLegacy::onUpdateOp(OperationContext* opCtx,
BSONElement idElement = postImageDoc["_id"];
if (idElement.eoo()) {
- warning() << "logUpdateOp got a document with no _id field, ignoring updatedDoc: "
- << redact(postImageDoc);
+ LOGV2_WARNING(
+ 21996,
+ "logUpdateOp got a document with no _id field, ignoring updatedDoc: {postImageDoc}",
+ "postImageDoc"_attr = redact(postImageDoc));
return;
}
@@ -488,8 +497,10 @@ void MigrationChunkClonerSourceLegacy::onDeleteOp(OperationContext* opCtx,
BSONElement idElement = deletedDocId["_id"];
if (idElement.eoo()) {
- warning() << "logDeleteOp got a document with no _id field, ignoring deleted doc: "
- << redact(deletedDocId);
+ LOGV2_WARNING(
+ 21997,
+ "logDeleteOp got a document with no _id field, ignoring deleted doc: {deletedDocId}",
+ "deletedDocId"_attr = redact(deletedDocId));
return;
}
@@ -994,13 +1005,19 @@ Status MigrationChunkClonerSourceLegacy::_checkRecipientCloningStatus(OperationC
const std::size_t cloneLocsRemaining = _cloneLocs.size();
if (_forceJumbo && _jumboChunkCloneState) {
- log() << "moveChunk data transfer progress: " << redact(res)
- << " mem used: " << _memoryUsed
- << " documents cloned so far: " << _jumboChunkCloneState->docsCloned;
+ LOGV2(21992,
+ "moveChunk data transfer progress: {res} mem used: {memoryUsed} documents cloned "
+ "so far: {jumboChunkCloneState_docsCloned}",
+ "res"_attr = redact(res),
+ "memoryUsed"_attr = _memoryUsed,
+ "jumboChunkCloneState_docsCloned"_attr = _jumboChunkCloneState->docsCloned);
} else {
- log() << "moveChunk data transfer progress: " << redact(res)
- << " mem used: " << _memoryUsed
- << " documents remaining to clone: " << cloneLocsRemaining;
+ LOGV2(21993,
+ "moveChunk data transfer progress: {res} mem used: {memoryUsed} documents "
+ "remaining to clone: {cloneLocsRemaining}",
+ "res"_attr = redact(res),
+ "memoryUsed"_attr = _memoryUsed,
+ "cloneLocsRemaining"_attr = cloneLocsRemaining);
}
if (res["state"].String() == "steady") {
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index a11bb49b8a4..54f4a01e87b 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -63,6 +63,7 @@
#include "mongo/db/session_catalog_mongod.h"
#include "mongo/db/storage/remove_saver.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
@@ -240,7 +241,7 @@ void MigrationDestinationManager::setState(State newState) {
}
void MigrationDestinationManager::_setStateFail(StringData msg) {
- log() << msg;
+ LOGV2(21998, "{msg}", "msg"_attr = msg);
{
stdx::lock_guard<Latch> sl(_mutex);
_errmsg = msg.toString();
@@ -252,7 +253,7 @@ void MigrationDestinationManager::_setStateFail(StringData msg) {
}
void MigrationDestinationManager::_setStateFailWarn(StringData msg) {
- warning() << msg;
+ LOGV2_WARNING(22010, "{msg}", "msg"_attr = msg);
{
stdx::lock_guard<Latch> sl(_mutex);
_errmsg = msg.toString();
@@ -436,7 +437,9 @@ repl::OpTime MigrationDestinationManager::cloneDocumentsFromDonor(
} catch (...) {
stdx::lock_guard<Client> lk(*opCtx->getClient());
opCtx->getServiceContext()->killOperation(lk, opCtx, ErrorCodes::Error(51008));
- log() << "Batch insertion failed " << causedBy(redact(exceptionToStatus()));
+ LOGV2(21999,
+ "Batch insertion failed {causedBy_exceptionToStatus}",
+ "causedBy_exceptionToStatus"_attr = causedBy(redact(exceptionToStatus())));
}
}};
auto inserterThreadJoinGuard = makeGuard([&] {
@@ -813,9 +816,15 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
invariant(!_min.isEmpty());
invariant(!_max.isEmpty());
- log() << "Starting receiving end of migration of chunk " << redact(_min) << " -> "
- << redact(_max) << " for collection " << _nss.ns() << " from " << _fromShard
- << " at epoch " << _epoch.toString() << " with session id " << *_sessionId;
+ LOGV2(22000,
+ "Starting receiving end of migration of chunk {min} -> {max} for collection {nss_ns} "
+ "from {fromShard} at epoch {epoch} with session id {sessionId}",
+ "min"_attr = redact(_min),
+ "max"_attr = redact(_max),
+ "nss_ns"_attr = _nss.ns(),
+ "fromShard"_attr = _fromShard,
+ "epoch"_attr = _epoch.toString(),
+ "sessionId"_attr = *_sessionId);
MoveTimingHelper timing(
outerOpCtx, "to", _nss.ns(), _min, _max, 6 /* steps */, &_errmsg, ShardId(), ShardId());
@@ -823,7 +832,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
const auto initialState = getState();
if (initialState == ABORT) {
- error() << "Migration abort requested before it started";
+ LOGV2_ERROR(22013, "Migration abort requested before it started");
return;
}
@@ -843,9 +852,11 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
if (_enableResumableRangeDeleter) {
while (migrationutil::checkForConflictingDeletions(
outerOpCtx, range, donorCollectionOptionsAndIndexes.uuid)) {
- LOG(0) << "Migration paused because range overlaps with a "
- "range that is scheduled for deletion: collection: "
- << _nss.ns() << " range: " << redact(range.toString());
+ LOGV2(22001,
+ "Migration paused because range overlaps with a "
+ "range that is scheduled for deletion: collection: {nss_ns} range: {range}",
+ "nss_ns"_attr = _nss.ns(),
+ "range"_attr = redact(range.toString()));
auto status = CollectionShardingRuntime::waitForClean(
outerOpCtx, _nss, donorCollectionOptionsAndIndexes.uuid, range);
@@ -984,8 +995,9 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(),
_writeConcern);
if (replStatus.status.code() == ErrorCodes::WriteConcernFailed) {
- warning() << "secondaryThrottle on, but doc insert timed out; "
- "continuing";
+ LOGV2_WARNING(22011,
+ "secondaryThrottle on, but doc insert timed out; "
+ "continuing");
} else {
uassertStatusOK(replStatus.status);
}
@@ -1059,7 +1071,8 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
opCtx->checkForInterrupt();
if (getState() == ABORT) {
- log() << "Migration aborted while waiting for replication at catch up stage";
+ LOGV2(22002,
+ "Migration aborted while waiting for replication at catch up stage");
return;
}
@@ -1067,7 +1080,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
break;
if (i > 100) {
- log() << "secondaries having hard time keeping up with migrate";
+ LOGV2(22003, "secondaries having hard time keeping up with migrate");
}
sleepmillis(20);
@@ -1087,14 +1100,14 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
// Pause to wait for replication. This will prevent us from going into critical section
// until we're ready.
- log() << "Waiting for replication to catch up before entering critical section";
+ LOGV2(22004, "Waiting for replication to catch up before entering critical section");
auto awaitReplicationResult = repl::ReplicationCoordinator::get(opCtx)->awaitReplication(
opCtx, lastOpApplied, _writeConcern);
uassertStatusOKWithContext(awaitReplicationResult.status,
awaitReplicationResult.status.codeString());
- log() << "Chunk data replicated successfully.";
+ LOGV2(22005, "Chunk data replicated successfully.");
}
{
@@ -1131,7 +1144,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx) {
}
if (getState() == ABORT) {
- log() << "Migration aborted while transferring mods";
+ LOGV2(22006, "Migration aborted while transferring mods");
return;
}
@@ -1254,7 +1267,7 @@ bool MigrationDestinationManager::_applyMigrateOp(OperationContext* opCtx,
const std::string errMsg = str::stream()
<< "cannot migrate chunk, local document " << redact(localDoc)
<< " has same _id as reloaded remote document " << redact(updatedDoc);
- warning() << errMsg;
+ LOGV2_WARNING(22012, "{errMsg}", "errMsg"_attr = errMsg);
// Exception will abort migration cleanly
uasserted(16977, errMsg);
@@ -1277,14 +1290,22 @@ bool MigrationDestinationManager::_flushPendingWrites(OperationContext* opCtx,
repl::OpTime op(lastOpApplied);
static Occasionally sampler;
if (sampler.tick()) {
- log() << "migrate commit waiting for a majority of slaves for '" << _nss.ns() << "' "
- << redact(_min) << " -> " << redact(_max) << " waiting for: " << op;
+ LOGV2(22007,
+ "migrate commit waiting for a majority of slaves for '{nss_ns}' {min} -> {max} "
+ "waiting for: {op}",
+ "nss_ns"_attr = _nss.ns(),
+ "min"_attr = redact(_min),
+ "max"_attr = redact(_max),
+ "op"_attr = op);
}
return false;
}
- log() << "migrate commit succeeded flushing to secondaries for '" << _nss.ns() << "' "
- << redact(_min) << " -> " << redact(_max);
+ LOGV2(22008,
+ "migrate commit succeeded flushing to secondaries for '{nss_ns}' {min} -> {max}",
+ "nss_ns"_attr = _nss.ns(),
+ "min"_attr = redact(_min),
+ "max"_attr = redact(_max));
return true;
}
@@ -1330,8 +1351,10 @@ void MigrationDestinationManager::_forgetPending(OperationContext* opCtx, ChunkR
// checking this here is that in the future we shouldn't have this problem.
if (!optMetadata || !(*optMetadata)->isSharded() ||
(*optMetadata)->getCollVersion().epoch() != _epoch) {
- LOG(0) << "No need to forget pending chunk " << redact(range.toString())
- << " because the epoch for " << _nss.ns() << " changed";
+ LOGV2(22009,
+ "No need to forget pending chunk {range} because the epoch for {nss_ns} changed",
+ "range"_attr = redact(range.toString()),
+ "nss_ns"_attr = _nss.ns());
return;
}
diff --git a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp
index acfdbb306f1..50d63eec920 100644
--- a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp
+++ b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/s/shard_filtering_metadata_refresh.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/start_chunk_clone_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/request_types/migration_secondary_throttle_options.h"
#include "mongo/util/assert_util.h"
@@ -202,7 +203,7 @@ public:
Status const status = mdm->startCommit(sessionId);
mdm->report(result, opCtx, false);
if (!status.isOK()) {
- log() << status.reason();
+ LOGV2(22014, "{status_reason}", "status_reason"_attr = status.reason());
uassertStatusOK(status);
}
return true;
@@ -250,7 +251,7 @@ public:
Status const status = mdm->abort(migrationSessionIdStatus.getValue());
mdm->report(result, opCtx, false);
if (!status.isOK()) {
- log() << status.reason();
+ LOGV2(22015, "{status_reason}", "status_reason"_attr = status.reason());
uassertStatusOK(status);
}
} else if (migrationSessionIdStatus == ErrorCodes::NoSuchKey) {
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp
index 34012e759d4..c94b0777ad2 100644
--- a/src/mongo/db/s/migration_source_manager.cpp
+++ b/src/mongo/db/s/migration_source_manager.cpp
@@ -57,6 +57,7 @@
#include "mongo/db/s/sharding_statistics.h"
#include "mongo/executor/task_executor.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_shard_collection.h"
#include "mongo/s/catalog_cache_loader.h"
@@ -164,8 +165,11 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx,
"Destination shard cannot be the same as source",
_args.getFromShardId() != _args.getToShardId());
- log() << "Starting chunk migration " << redact(_args.toString())
- << " with expected collection version epoch " << _args.getVersionEpoch();
+ LOGV2(22016,
+ "Starting chunk migration {args} with expected collection version epoch "
+ "{args_getVersionEpoch}",
+ "args"_attr = redact(_args.toString()),
+ "args_getVersionEpoch"_attr = _args.getVersionEpoch());
// Force refresh of the metadata to ensure we have the latest
forceShardFilteringMetadataRefresh(_opCtx, getNss());
@@ -391,7 +395,7 @@ Status MigrationSourceManager::enterCriticalSection() {
<< signalStatus.toString()};
}
- log() << "Migration successfully entered critical section";
+ LOGV2(22017, "Migration successfully entered critical section");
scopedGuard.dismiss();
return Status::OK();
@@ -502,8 +506,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() {
}
// Migration succeeded
- LOG(0) << "Migration succeeded and updated collection version to "
- << refreshedMetadata->getCollVersion();
+ LOGV2(
+ 22018,
+ "Migration succeeded and updated collection version to {refreshedMetadata_getCollVersion}",
+ "refreshedMetadata_getCollVersion"_attr = refreshedMetadata->getCollVersion());
if (_enableResumableRangeDeleter) {
_coordinator->setMigrationDecision(
@@ -547,8 +553,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() {
if (_enableResumableRangeDeleter) {
if (_args.getWaitForDelete()) {
- log() << "Waiting for cleanup of " << getNss().ns() << " range "
- << redact(range.toString());
+ LOGV2(22019,
+ "Waiting for cleanup of {getNss_ns} range {range}",
+ "getNss_ns"_attr = getNss().ns(),
+ "range"_attr = redact(range.toString()));
invariant(_scheduledRangeDeletionOnSuccess);
auto scheduleSW = _scheduledRangeDeletionOnSuccess->getNoThrow(_opCtx);
@@ -575,8 +583,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() {
}();
if (_args.getWaitForDelete()) {
- log() << "Waiting for cleanup of " << getNss().ns() << " range "
- << redact(range.toString());
+ LOGV2(22020,
+ "Waiting for cleanup of {getNss_ns} range {range}",
+ "getNss_ns"_attr = getNss().ns(),
+ "range"_attr = redact(range.toString()));
auto deleteStatus = cleanupCompleteFuture.getNoThrow(_opCtx);
@@ -592,8 +602,10 @@ Status MigrationSourceManager::commitChunkMetadataOnConfig() {
return {ErrorCodes::OrphanedRangeCleanUpFailed,
orphanedRangeCleanUpErrMsg + redact(cleanupCompleteFuture.getNoThrow(_opCtx))};
} else {
- log() << "Leaving cleanup of " << getNss().ns() << " range " << redact(range.toString())
- << " to complete in background";
+ LOGV2(22021,
+ "Leaving cleanup of {getNss_ns} range {range} to complete in background",
+ "getNss_ns"_attr = getNss().ns(),
+ "range"_attr = redact(range.toString()));
}
}
@@ -616,8 +628,10 @@ void MigrationSourceManager::cleanupOnError() {
try {
_cleanup();
} catch (const DBException& ex) {
- warning() << "Failed to clean up migration: " << redact(_args.toString())
- << "due to: " << redact(ex);
+ LOGV2_WARNING(22022,
+ "Failed to clean up migration: {args}due to: {ex}",
+ "args"_attr = redact(_args.toString()),
+ "ex"_attr = redact(ex));
}
}
diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp
index 58f9198057c..a5938c94b79 100644
--- a/src/mongo/db/s/migration_util.cpp
+++ b/src/mongo/db/s/migration_util.cpp
@@ -52,6 +52,7 @@
#include "mongo/db/write_concern.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/client/shard.h"
@@ -83,7 +84,7 @@ void sendToRecipient(OperationContext* opCtx, const ShardId& recipientId, const
auto recipientShard =
uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, recipientId));
- LOG(1) << "Sending request " << cmd.toBSON({}) << " to recipient.";
+ LOGV2_DEBUG(22023, 1, "Sending request {cmd} to recipient.", "cmd"_attr = cmd.toBSON({}));
auto response = recipientShard->runCommandWithFixedRetryAttempts(
opCtx,
@@ -150,14 +151,20 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx,
// does not match the UUID of the deletion task, force a filtering metadata refresh
// once, because this node may have just stepped up and therefore may have a stale
// cache.
- LOG(0) << "Filtering metadata for namespace in deletion task "
- << deletionTask.toBSON()
- << (css->getCurrentMetadataIfKnown()
- ? (css->getCurrentMetadata()->isSharded()
- ? " has UUID that does not match UUID of the deletion task"
- : " is unsharded")
- : " is not known")
- << ", forcing a refresh of " << deletionTask.getNss();
+ LOGV2(
+ 22024,
+ "Filtering metadata for namespace in deletion task "
+ "{deletionTask}{css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_"
+ "has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_"
+ "known}, forcing a refresh of {deletionTask_getNss}",
+ "deletionTask"_attr = deletionTask.toBSON(),
+ "css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_known"_attr =
+ (css->getCurrentMetadataIfKnown()
+ ? (css->getCurrentMetadata()->isSharded()
+ ? " has UUID that does not match UUID of the deletion task"
+ : " is unsharded")
+ : " is not known"),
+ "deletionTask_getNss"_attr = deletionTask.getNss());
// TODO (SERVER-46075): Add an asynchronous version of
// forceShardFilteringMetadataRefresh to avoid blocking on the network in the
@@ -178,15 +185,20 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx,
autoColl.emplace(opCtx, deletionTask.getNss(), MODE_IS);
if (!css->getCurrentMetadataIfKnown() || !css->getCurrentMetadata()->isSharded() ||
!css->getCurrentMetadata()->uuidMatches(deletionTask.getCollectionUuid())) {
- LOG(0) << "Even after forced refresh, filtering metadata for namespace in deletion "
- "task "
- << deletionTask.toBSON()
- << (css->getCurrentMetadataIfKnown()
- ? (css->getCurrentMetadata()->isSharded()
- ? " has UUID that does not match UUID of the deletion task"
- : " is unsharded")
- : " is not known")
- << ", deleting the task.";
+ LOGV2(
+ 22025,
+ "Even after forced refresh, filtering metadata for namespace in deletion "
+ "task "
+ "{deletionTask}{css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_"
+ "has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_"
+ "known}, deleting the task.",
+ "deletionTask"_attr = deletionTask.toBSON(),
+ "css_getCurrentMetadataIfKnown_css_getCurrentMetadata_isSharded_has_UUID_that_does_not_match_UUID_of_the_deletion_task_is_unsharded_is_not_known"_attr =
+ (css->getCurrentMetadataIfKnown()
+ ? (css->getCurrentMetadata()->isSharded()
+ ? " has UUID that does not match UUID of the deletion task"
+ : " is unsharded")
+ : " is not known"));
autoColl.reset();
deleteRangeDeletionTaskLocally(
@@ -194,7 +206,9 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx,
return false;
}
- LOG(0) << "Submitting range deletion task " << deletionTask.toBSON();
+ LOGV2(22026,
+ "Submitting range deletion task {deletionTask}",
+ "deletionTask"_attr = deletionTask.toBSON());
const auto whenToClean = deletionTask.getWhenToClean() == CleanWhenEnum::kNow
? CollectionShardingRuntime::kNow
@@ -204,8 +218,12 @@ ExecutorFuture<bool> submitRangeDeletionTask(OperationContext* opCtx,
if (cleanupCompleteFuture.isReady() &&
!cleanupCompleteFuture.getNoThrow(opCtx).isOK()) {
- LOG(0) << "Failed to submit range deletion task " << deletionTask.toBSON()
- << causedBy(cleanupCompleteFuture.getNoThrow(opCtx));
+ LOGV2(22027,
+ "Failed to submit range deletion task "
+ "{deletionTask}{causedBy_cleanupCompleteFuture_getNoThrow_opCtx}",
+ "deletionTask"_attr = deletionTask.toBSON(),
+ "causedBy_cleanupCompleteFuture_getNoThrow_opCtx"_attr =
+ causedBy(cleanupCompleteFuture.getNoThrow(opCtx)));
return false;
}
return true;
@@ -225,7 +243,7 @@ void submitPendingDeletions(OperationContext* opCtx) {
}
void resubmitRangeDeletionsOnStepUp(ServiceContext* serviceContext) {
- LOG(0) << "Starting pending deletion submission thread.";
+ LOGV2(22028, "Starting pending deletion submission thread.");
auto executor = Grid::get(serviceContext)->getExecutorPool()->getFixedExecutor();
@@ -258,8 +276,9 @@ void forEachOrphanRange(OperationContext* opCtx, const NamespaceString& nss, Cal
RangeMap{SimpleBSONObjComparator::kInstance.makeBSONObjIndexedMap<BSONObj>()};
if (!metadata->isSharded()) {
- LOG(0) << "Upgrade: skipping orphaned range enumeration for " << nss
- << ", collection is not sharded";
+ LOGV2(22029,
+ "Upgrade: skipping orphaned range enumeration for {nss}, collection is not sharded",
+ "nss"_attr = nss);
return;
}
@@ -268,8 +287,12 @@ void forEachOrphanRange(OperationContext* opCtx, const NamespaceString& nss, Cal
while (true) {
auto range = metadata->getNextOrphanRange(emptyChunkMap, startingKey);
if (!range) {
- LOG(2) << "Upgrade: Completed orphaned range enumeration for " << nss.toString()
- << " starting from " << redact(startingKey) << ", no orphan ranges remain";
+ LOGV2_DEBUG(22030,
+ 2,
+ "Upgrade: Completed orphaned range enumeration for {nss} starting from "
+ "{startingKey}, no orphan ranges remain",
+ "nss"_attr = nss.toString(),
+ "startingKey"_attr = redact(startingKey));
return;
}
@@ -287,7 +310,11 @@ void submitOrphanRanges(OperationContext* opCtx, const NamespaceString& nss, con
if (version == ChunkVersion::UNSHARDED())
return;
- LOG(2) << "Upgrade: Cleaning up existing orphans for " << nss << " : " << uuid;
+ LOGV2_DEBUG(22031,
+ 2,
+ "Upgrade: Cleaning up existing orphans for {nss} : {uuid}",
+ "nss"_attr = nss,
+ "uuid"_attr = uuid);
std::vector<RangeDeletionTask> deletions;
forEachOrphanRange(opCtx, nss, [&deletions, &opCtx, &nss, &uuid](const auto& range) {
@@ -305,14 +332,19 @@ void submitOrphanRanges(OperationContext* opCtx, const NamespaceString& nss, con
NamespaceString::kRangeDeletionNamespace);
for (const auto& task : deletions) {
- LOG(2) << "Upgrade: Submitting range for cleanup: " << task.getRange() << " from "
- << nss;
+ LOGV2_DEBUG(22032,
+ 2,
+ "Upgrade: Submitting range for cleanup: {task_getRange} from {nss}",
+ "task_getRange"_attr = task.getRange(),
+ "nss"_attr = nss);
store.add(opCtx, task);
}
} catch (ExceptionFor<ErrorCodes::NamespaceNotFound>& e) {
- LOG(0) << "Upgrade: Failed to cleanup orphans for " << nss
- << " because the namespace was not found: " << e.what()
- << ", the collection must have been dropped";
+ LOGV2(22033,
+ "Upgrade: Failed to cleanup orphans for {nss} because the namespace was not found: "
+ "{e_what}, the collection must have been dropped",
+ "nss"_attr = nss,
+ "e_what"_attr = e.what());
}
}
@@ -327,7 +359,7 @@ void submitOrphanRangesForCleanup(OperationContext* opCtx) {
for (auto collIt = catalog.begin(dbName); collIt != catalog.end(); ++collIt) {
auto uuid = collIt.uuid().get();
auto nss = catalog.lookupNSSByUUID(opCtx, uuid).get();
- LOG(2) << "Upgrade: processing collection: " << nss;
+ LOGV2_DEBUG(22034, 2, "Upgrade: processing collection: {nss}", "nss"_attr = nss);
submitOrphanRanges(opCtx, nss, uuid);
}
@@ -504,8 +536,11 @@ void ensureChunkVersionIsGreaterThan(OperationContext* opCtx,
repl::MemberState::RS_PRIMARY &&
term == repl::ReplicationCoordinator::get(opCtx)->getTerm());
- LOG(0) << "_configsvrEnsureChunkVersionIsGreaterThan failed after " << attempts
- << " attempts " << causedBy(redact(ex.toStatus())) << " . Will try again.";
+ LOGV2(22035,
+ "_configsvrEnsureChunkVersionIsGreaterThan failed after {attempts} attempts "
+ "{causedBy_ex_toStatus} . Will try again.",
+ "attempts"_attr = attempts,
+ "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus())));
}
}
}
@@ -551,15 +586,18 @@ void refreshFilteringMetadataUntilSuccess(OperationContext* opCtx, const Namespa
repl::MemberState::RS_PRIMARY &&
term == repl::ReplicationCoordinator::get(opCtx)->getTerm());
- LOG(0) << "Failed to refresh metadata for " << nss.ns() << " after " << attempts
- << " attempts " << causedBy(redact(ex.toStatus()))
- << ". Will try to refresh again.";
+ LOGV2(22036,
+ "Failed to refresh metadata for {nss_ns} after {attempts} attempts "
+ "{causedBy_ex_toStatus}. Will try to refresh again.",
+ "nss_ns"_attr = nss.ns(),
+ "attempts"_attr = attempts,
+ "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus())));
}
}
}
void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) {
- LOG(0) << "Starting migration coordinator stepup recovery thread.";
+ LOGV2(22037, "Starting migration coordinator stepup recovery thread.");
auto executor = Grid::get(serviceContext)->getExecutorPool()->getFixedExecutor();
ExecutorFuture<void>(executor).getAsync([serviceContext](const Status& status) {
@@ -590,7 +628,9 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) {
auto& replClientInfo = repl::ReplClientInfo::forClient(opCtx->getClient());
replClientInfo.setLastOpToSystemLastOpTime(opCtx);
const auto lastOpTime = replClientInfo.getLastOp();
- LOG(0) << "Waiting for OpTime " << lastOpTime << " to become majority committed";
+ LOGV2(22038,
+ "Waiting for OpTime {lastOpTime} to become majority committed",
+ "lastOpTime"_attr = lastOpTime);
WriteConcernResult unusedWCResult;
uassertStatusOK(
waitForWriteConcern(opCtx,
@@ -604,7 +644,7 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) {
opCtx, NamespaceString::kMigrationCoordinatorsNamespace);
Query query;
store.forEach(opCtx, query, [&opCtx](const MigrationCoordinatorDocument& doc) {
- LOG(0) << "Recovering migration " << doc.toBSON();
+ LOGV2(22039, "Recovering migration {doc}", "doc"_attr = doc.toBSON());
// Create a MigrationCoordinator to complete the coordination.
MigrationCoordinator coordinator(doc.getId(),
@@ -643,15 +683,20 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) {
if (!refreshedMetadata || !(*refreshedMetadata)->isSharded() ||
!(*refreshedMetadata)->uuidMatches(doc.getCollectionUuid())) {
- LOG(0) << "Even after forced refresh, filtering metadata for namespace in "
- "migration coordinator doc "
- << doc.toBSON()
- << (!refreshedMetadata || !(*refreshedMetadata)->isSharded()
- ? "is not known"
- : "has UUID that does not match the collection UUID in the "
- "coordinator doc")
- << ". Deleting the range deletion tasks on the donor and recipient as "
- "well as the migration coordinator document on this node.";
+ LOGV2(
+ 22040,
+ "Even after forced refresh, filtering metadata for namespace in "
+ "migration coordinator doc "
+ "{doc}{refreshedMetadata_refreshedMetadata_isSharded_is_not_known_has_UUID_"
+ "that_does_not_match_the_collection_UUID_in_the_coordinator_doc}. Deleting "
+ "the range deletion tasks on the donor and recipient as "
+ "well as the migration coordinator document on this node.",
+ "doc"_attr = doc.toBSON(),
+ "refreshedMetadata_refreshedMetadata_isSharded_is_not_known_has_UUID_that_does_not_match_the_collection_UUID_in_the_coordinator_doc"_attr =
+ (!refreshedMetadata || !(*refreshedMetadata)->isSharded()
+ ? "is not known"
+ : "has UUID that does not match the collection UUID in the "
+ "coordinator doc"));
// TODO (SERVER-45707): Test that range deletion tasks are eventually
// deleted even if the collection is dropped before migration coordination
@@ -672,8 +717,9 @@ void resumeMigrationCoordinationsOnStepUp(ServiceContext* serviceContext) {
return true;
});
} catch (const DBException& ex) {
- LOG(0) << "Failed to resume coordinating migrations on stepup "
- << causedBy(ex.toStatus());
+ LOGV2(22041,
+ "Failed to resume coordinating migrations on stepup {causedBy_ex_toStatus}",
+ "causedBy_ex_toStatus"_attr = causedBy(ex.toStatus()));
}
});
}
diff --git a/src/mongo/db/s/move_primary_source_manager.cpp b/src/mongo/db/s/move_primary_source_manager.cpp
index ec87bce1bfa..c6b97b5b1be 100644
--- a/src/mongo/db/s/move_primary_source_manager.cpp
+++ b/src/mongo/db/s/move_primary_source_manager.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/s/sharding_logging.h"
#include "mongo/db/s/sharding_state_recovery.h"
#include "mongo/db/s/sharding_statistics.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/type_shard_database.h"
#include "mongo/s/catalog_cache.h"
@@ -74,7 +75,11 @@ Status MovePrimarySourceManager::clone(OperationContext* opCtx) {
invariant(_state == kCreated);
auto scopedGuard = makeGuard([&] { cleanupOnError(opCtx); });
- log() << "Moving " << _dbname << " primary from: " << _fromShard << " to: " << _toShard;
+ LOGV2(22042,
+ "Moving {dbname} primary from: {fromShard} to: {toShard}",
+ "dbname"_attr = _dbname,
+ "fromShard"_attr = _fromShard,
+ "toShard"_attr = _toShard);
// Record start in changelog
uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked(
@@ -195,7 +200,7 @@ Status MovePrimarySourceManager::enterCriticalSection(OperationContext* opCtx) {
<< signalStatus.toString()};
}
- log() << "movePrimary successfully entered critical section";
+ LOGV2(22043, "movePrimary successfully entered critical section");
scopedGuard.dismiss();
return Status::OK();
@@ -244,9 +249,10 @@ Status MovePrimarySourceManager::commitOnConfig(OperationContext* opCtx) {
// Need to get the latest optime in case the refresh request goes to a secondary --
// otherwise the read won't wait for the write that _configsvrCommitMovePrimary may have
// done
- log() << "Error occurred while committing the movePrimary. Performing a majority write "
- "against the config server to obtain its latest optime"
- << causedBy(redact(commitStatus));
+ LOGV2(22044,
+ "Error occurred while committing the movePrimary. Performing a majority write "
+ "against the config server to obtain its latest optime{causedBy_commitStatus}",
+ "causedBy_commitStatus"_attr = causedBy(redact(commitStatus)));
Status validateStatus = ShardingLogging::get(opCtx)->logChangeChecked(
opCtx,
@@ -337,7 +343,10 @@ Status MovePrimarySourceManager::cleanStaleData(OperationContext* opCtx) {
client.runCommand(_dbname.toString(), BSON("drop" << coll.coll()), dropCollResult);
Status dropStatus = getStatusFromCommandResult(dropCollResult);
if (!dropStatus.isOK()) {
- log() << "failed to drop cloned collection " << coll << causedBy(redact(dropStatus));
+ LOGV2(22045,
+ "failed to drop cloned collection {coll}{causedBy_dropStatus}",
+ "coll"_attr = coll,
+ "causedBy_dropStatus"_attr = causedBy(redact(dropStatus)));
}
}
@@ -363,8 +372,10 @@ void MovePrimarySourceManager::cleanupOnError(OperationContext* opCtx) {
} catch (const ExceptionForCat<ErrorCategory::NotMasterError>& ex) {
BSONObjBuilder requestArgsBSON;
_requestArgs.serialize(&requestArgsBSON);
- warning() << "Failed to clean up movePrimary: " << redact(requestArgsBSON.obj())
- << "due to: " << redact(ex);
+ LOGV2_WARNING(22046,
+ "Failed to clean up movePrimary: {requestArgsBSON_obj}due to: {ex}",
+ "requestArgsBSON_obj"_attr = redact(requestArgsBSON.obj()),
+ "ex"_attr = redact(ex));
}
}
diff --git a/src/mongo/db/s/periodic_balancer_config_refresher.cpp b/src/mongo/db/s/periodic_balancer_config_refresher.cpp
index f9cab569d89..96c33e0ceb3 100644
--- a/src/mongo/db/s/periodic_balancer_config_refresher.cpp
+++ b/src/mongo/db/s/periodic_balancer_config_refresher.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -60,7 +61,9 @@ PeriodicJobAnchor launchBalancerConfigRefresher(ServiceContext* serviceContext)
Status status = balancerConfig->refreshAndCheck(opCtx.get());
if (!status.isOK()) {
- log() << "Failed to refresh balancer configuration" << causedBy(status);
+ LOGV2(22048,
+ "Failed to refresh balancer configuration{causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
}
},
Seconds(30));
diff --git a/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp b/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp
index 387d2c72652..b30403d42ff 100644
--- a/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp
+++ b/src/mongo/db/s/periodic_sharded_index_consistency_checker.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/s/sharding_runtime_d_params_gen.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_aggregate.h"
#include "mongo/util/log.h"
@@ -77,7 +78,7 @@ void PeriodicShardedIndexConsistencyChecker::_launchShardedIndexConsistencyCheck
return;
}
- log() << "Checking consistency of sharded collection indexes across the cluster";
+ LOGV2(22049, "Checking consistency of sharded collection indexes across the cluster");
const auto aggRequestBSON = fromjson(
"{pipeline: [{$indexStats: {}},"
@@ -141,8 +142,12 @@ void PeriodicShardedIndexConsistencyChecker::_launchShardedIndexConsistencyCheck
}
break;
} catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) {
- log() << "Attempt " << tries << " to check index consistency for "
- << nss << " received StaleShardVersion error" << causedBy(ex);
+ LOGV2(22050,
+ "Attempt {tries} to check index consistency for {nss} received "
+ "StaleShardVersion error{causedBy_ex}",
+ "tries"_attr = tries,
+ "nss"_attr = nss,
+ "causedBy_ex"_attr = causedBy(ex));
if (canRetry) {
continue;
}
@@ -151,14 +156,19 @@ void PeriodicShardedIndexConsistencyChecker::_launchShardedIndexConsistencyCheck
}
}
- log() << "Found " << numShardedCollsWithInconsistentIndexes
- << " collections with inconsistent indexes";
+ LOGV2(22051,
+ "Found {numShardedCollsWithInconsistentIndexes} collections with "
+ "inconsistent indexes",
+ "numShardedCollsWithInconsistentIndexes"_attr =
+ numShardedCollsWithInconsistentIndexes);
// Update the count.
_numShardedCollsWithInconsistentIndexes.store(
numShardedCollsWithInconsistentIndexes);
} catch (DBException& ex) {
- log() << "Failed to check index consistency " << causedBy(ex.toStatus());
+ LOGV2(22052,
+ "Failed to check index consistency {causedBy_ex_toStatus}",
+ "causedBy_ex_toStatus"_attr = causedBy(ex.toStatus()));
}
},
Milliseconds(shardedIndexConsistencyCheckIntervalMS));
diff --git a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp
index 5a8d900a810..2328a973aef 100644
--- a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp
+++ b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/s/shard_filtering_metadata_refresh.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/cannot_implicitly_create_collection_info.h"
#include "mongo/s/stale_exception.h"
#include "mongo/util/log.h"
@@ -89,16 +90,18 @@ ScopedOperationCompletionShardingActions::~ScopedOperationCompletionShardingActi
auto handleMismatchStatus = onShardVersionMismatchNoExcept(
_opCtx, staleInfo->getNss(), staleInfo->getVersionReceived());
if (!handleMismatchStatus.isOK())
- log() << "Failed to handle stale version exception"
- << causedBy(redact(handleMismatchStatus));
+ LOGV2(22053,
+ "Failed to handle stale version exception{causedBy_handleMismatchStatus}",
+ "causedBy_handleMismatchStatus"_attr = causedBy(redact(handleMismatchStatus)));
} else if (auto staleInfo = status->extraInfo<StaleDbRoutingVersion>()) {
auto handleMismatchStatus = onDbVersionMismatchNoExcept(_opCtx,
staleInfo->getDb(),
staleInfo->getVersionReceived(),
staleInfo->getVersionWanted());
if (!handleMismatchStatus.isOK())
- log() << "Failed to handle database version exception"
- << causedBy(redact(handleMismatchStatus));
+ LOGV2(22054,
+ "Failed to handle database version exception{causedBy_handleMismatchStatus}",
+ "causedBy_handleMismatchStatus"_attr = causedBy(redact(handleMismatchStatus)));
} else if (auto cannotImplicitCreateCollInfo =
status->extraInfo<CannotImplicitlyCreateCollectionInfo>()) {
if (ShardingState::get(_opCtx)->enabled() &&
@@ -107,8 +110,11 @@ ScopedOperationCompletionShardingActions::~ScopedOperationCompletionShardingActi
auto handleCannotImplicitCreateStatus =
onCannotImplicitlyCreateCollection(_opCtx, cannotImplicitCreateCollInfo->getNss());
if (!handleCannotImplicitCreateStatus.isOK())
- log() << "Failed to handle CannotImplicitlyCreateCollection exception"
- << causedBy(redact(handleCannotImplicitCreateStatus));
+ LOGV2(22055,
+ "Failed to handle CannotImplicitlyCreateCollection "
+ "exception{causedBy_handleCannotImplicitCreateStatus}",
+ "causedBy_handleCannotImplicitCreateStatus"_attr =
+ causedBy(redact(handleCannotImplicitCreateStatus)));
}
}
}
diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp
index 839c87ea602..a28ba943bb4 100644
--- a/src/mongo/db/s/set_shard_version_command.cpp
+++ b/src/mongo/db/s/set_shard_version_command.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/s/sharded_connection_info.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/set_shard_version_request.h"
@@ -305,7 +306,7 @@ public:
if (critSecSignal) {
collLock.reset();
autoDb.reset();
- log() << "waiting till out of critical section";
+ LOGV2(22056, "waiting till out of critical section");
critSecSignal->waitFor(opCtx, Seconds(10));
}
@@ -326,7 +327,7 @@ public:
if (critSecSignal) {
collLock.reset();
autoDb.reset();
- log() << "waiting till out of critical section";
+ LOGV2(22057, "waiting till out of critical section");
critSecSignal->waitFor(opCtx, Seconds(10));
}
@@ -371,7 +372,7 @@ public:
<< ", stored shard version is " << currVersion.toString()
<< causedBy(redact(status));
- warning() << errmsg;
+ LOGV2_WARNING(22058, "{errmsg}", "errmsg"_attr = errmsg);
result.append("ns", nss.ns());
result.append("code", status.code());
@@ -390,7 +391,7 @@ public:
static Occasionally sampler;
if (sampler.tick()) {
- warning() << errmsg;
+ LOGV2_WARNING(22059, "{errmsg}", "errmsg"_attr = errmsg);
}
// WARNING: the exact fields below are important for compatibility with mongos
diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp
index 5926ddcb456..ed66137c3d4 100644
--- a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp
+++ b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/sharding_statistics.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/grid.h"
#include "mongo/util/fail_point.h"
@@ -63,8 +64,11 @@ void onShardVersionMismatch(OperationContext* opCtx,
invariant(ShardingState::get(opCtx)->canAcceptShardedCommands());
- LOG(2) << "Metadata refresh requested for " << nss.ns() << " at shard version "
- << shardVersionReceived;
+ LOGV2_DEBUG(22061,
+ 2,
+ "Metadata refresh requested for {nss_ns} at shard version {shardVersionReceived}",
+ "nss_ns"_attr = nss.ns(),
+ "shardVersionReceived"_attr = shardVersionReceived);
ShardingStatistics::get(opCtx).countStaleConfigErrors.addAndFetch(1);
@@ -134,7 +138,10 @@ Status onShardVersionMismatchNoExcept(OperationContext* opCtx,
onShardVersionMismatch(opCtx, nss, shardVersionReceived, forceRefreshFromThisThread);
return Status::OK();
} catch (const DBException& ex) {
- log() << "Failed to refresh metadata for collection " << nss << causedBy(redact(ex));
+ LOGV2(22062,
+ "Failed to refresh metadata for collection {nss}{causedBy_ex}",
+ "nss"_attr = nss,
+ "causedBy_ex"_attr = causedBy(redact(ex)));
return ex.toStatus();
}
}
@@ -179,8 +186,13 @@ ChunkVersion forceShardFilteringMetadataRefresh(OperationContext* opCtx,
if (metadata->isSharded() &&
metadata->getCollVersion().epoch() == cm->getVersion().epoch() &&
metadata->getCollVersion() >= cm->getVersion()) {
- LOG(1) << "Skipping refresh of metadata for " << nss << " "
- << metadata->getCollVersion() << " with an older " << cm->getVersion();
+ LOGV2_DEBUG(22063,
+ 1,
+ "Skipping refresh of metadata for {nss} {metadata_getCollVersion} with "
+ "an older {cm_getVersion}",
+ "nss"_attr = nss,
+ "metadata_getCollVersion"_attr = metadata->getCollVersion(),
+ "cm_getVersion"_attr = cm->getVersion());
return metadata->getShardVersion();
}
}
@@ -202,8 +214,13 @@ ChunkVersion forceShardFilteringMetadataRefresh(OperationContext* opCtx,
if (metadata->isSharded() &&
metadata->getCollVersion().epoch() == cm->getVersion().epoch() &&
metadata->getCollVersion() >= cm->getVersion()) {
- LOG(1) << "Skipping refresh of metadata for " << nss << " "
- << metadata->getCollVersion() << " with an older " << cm->getVersion();
+ LOGV2_DEBUG(22064,
+ 1,
+ "Skipping refresh of metadata for {nss} {metadata_getCollVersion} with "
+ "an older {cm_getVersion}",
+ "nss"_attr = nss,
+ "metadata_getCollVersion"_attr = metadata->getCollVersion(),
+ "cm_getVersion"_attr = cm->getVersion());
return metadata->getShardVersion();
}
}
@@ -225,8 +242,10 @@ Status onDbVersionMismatchNoExcept(
onDbVersionMismatch(opCtx, dbName, clientDbVersion, serverDbVersion);
return Status::OK();
} catch (const DBException& ex) {
- log() << "Failed to refresh databaseVersion for database " << dbName
- << causedBy(redact(ex));
+ LOGV2(22065,
+ "Failed to refresh databaseVersion for database {dbName}{causedBy_ex}",
+ "dbName"_attr = dbName,
+ "causedBy_ex"_attr = causedBy(redact(ex)));
return ex.toStatus();
}
}
@@ -266,10 +285,14 @@ void forceDatabaseRefresh(OperationContext* opCtx, const StringData dbName) {
const auto cachedDbVersion = dss->getDbVersion(opCtx, dssLock);
if (cachedDbVersion && cachedDbVersion->getUuid() == refreshedDbVersion.getUuid() &&
cachedDbVersion->getLastMod() >= refreshedDbVersion.getLastMod()) {
- LOG(2) << "Skipping setting cached databaseVersion for " << dbName
- << " to refreshed version " << refreshedDbVersion.toBSON()
- << " because current cached databaseVersion is already "
- << cachedDbVersion->toBSON();
+ LOGV2_DEBUG(22066,
+ 2,
+ "Skipping setting cached databaseVersion for {dbName} to refreshed version "
+ "{refreshedDbVersion} because current cached databaseVersion is already "
+ "{cachedDbVersion}",
+ "dbName"_attr = dbName,
+ "refreshedDbVersion"_attr = refreshedDbVersion.toBSON(),
+ "cachedDbVersion"_attr = cachedDbVersion->toBSON());
return;
}
}
diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp
index d08c5f4cd79..37500a2ee15 100644
--- a/src/mongo/db/s/shard_metadata_util.cpp
+++ b/src/mongo/db/s/shard_metadata_util.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/ops/write_ops.h"
#include "mongo/db/write_concern_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/unique_message.h"
#include "mongo/s/catalog/type_chunk.h"
@@ -425,7 +426,10 @@ Status dropChunksAndDeleteCollectionsEntry(OperationContext* opCtx, const Namesp
}
}
- LOG(1) << "Successfully cleared persisted chunk metadata for collection '" << nss << "'.";
+ LOGV2_DEBUG(22090,
+ 1,
+ "Successfully cleared persisted chunk metadata for collection '{nss}'.",
+ "nss"_attr = nss);
return Status::OK();
} catch (const DBException& ex) {
return ex.toStatus();
@@ -444,7 +448,10 @@ void dropChunks(OperationContext* opCtx, const NamespaceString& nss) {
}
}
- LOG(1) << "Successfully cleared persisted chunk metadata for collection '" << nss << "'.";
+ LOGV2_DEBUG(22091,
+ 1,
+ "Successfully cleared persisted chunk metadata for collection '{nss}'.",
+ "nss"_attr = nss);
}
Status deleteDatabasesEntry(OperationContext* opCtx, StringData dbName) {
@@ -464,7 +471,10 @@ Status deleteDatabasesEntry(OperationContext* opCtx, StringData dbName) {
uassertStatusOK(
getStatusFromWriteCommandResponse(deleteCommandResponse->getCommandReply()));
- LOG(1) << "Successfully cleared persisted metadata for db '" << dbName.toString() << "'.";
+ LOGV2_DEBUG(22092,
+ 1,
+ "Successfully cleared persisted metadata for db '{dbName}'.",
+ "dbName"_attr = dbName.toString());
return Status::OK();
} catch (const DBException& ex) {
return ex.toStatus();
diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
index 682954e7b43..449e812bc2c 100644
--- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
+++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/s/shard_metadata_util.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_shard_collection.h"
#include "mongo/s/catalog/type_shard_database.h"
#include "mongo/s/client/shard_registry.h"
@@ -90,7 +91,7 @@ void dropChunksIfEpochChanged(OperationContext* opCtx,
dropChunks(opCtx, nss);
if (MONGO_unlikely(hangPersistCollectionAndChangedChunksAfterDropChunks.shouldFail())) {
- log() << "Hit hangPersistCollectionAndChangedChunksAfterDropChunks failpoint";
+ LOGV2(22093, "Hit hangPersistCollectionAndChangedChunksAfterDropChunks failpoint");
hangPersistCollectionAndChangedChunksAfterDropChunks.pauseWhileSet(opCtx);
}
}
@@ -954,12 +955,15 @@ void ShardServerCatalogCacheLoader::_runCollAndChunksTasks(const NamespaceString
_updatePersistedCollAndChunksMetadata(context.opCtx(), nss);
taskFinished = true;
} catch (const ExceptionForCat<ErrorCategory::ShutdownError>&) {
- LOG(0) << "Failed to persist chunk metadata update for collection '" << nss
- << "' due to shutdown.";
+ LOGV2(22094,
+ "Failed to persist chunk metadata update for collection '{nss}' due to shutdown.",
+ "nss"_attr = nss);
inShutdown = true;
} catch (const DBException& ex) {
- LOG(0) << "Failed to persist chunk metadata update for collection '" << nss
- << causedBy(redact(ex));
+ LOGV2(22095,
+ "Failed to persist chunk metadata update for collection '{nss}{causedBy_ex}",
+ "nss"_attr = nss,
+ "causedBy_ex"_attr = causedBy(redact(ex)));
}
{
@@ -988,10 +992,12 @@ void ShardServerCatalogCacheLoader::_runCollAndChunksTasks(const NamespaceString
_threadPool.schedule([this, nss](auto status) {
if (ErrorCodes::isCancelationError(status.code())) {
- LOG(0) << "Cache loader failed to schedule a persisted metadata update"
- << " task for namespace '" << nss << "' due to '" << redact(status)
- << "'. Clearing task list so that scheduling will be attempted by the next"
- << " caller to refresh this namespace.";
+ LOGV2(22096,
+ "Cache loader failed to schedule a persisted metadata update task for namespace "
+ "'{nss}' due to '{status}'. Clearing task list so that scheduling will be "
+ "attempted by the next caller to refresh this namespace.",
+ "nss"_attr = nss,
+ "status"_attr = redact(status));
{
stdx::lock_guard<Latch> lock(_mutex);
@@ -1014,11 +1020,15 @@ void ShardServerCatalogCacheLoader::_runDbTasks(StringData dbName) {
_updatePersistedDbMetadata(context.opCtx(), dbName);
taskFinished = true;
} catch (const ExceptionForCat<ErrorCategory::ShutdownError>&) {
- LOG(0) << "Failed to persist metadata update for db '" << dbName << "' due to shutdown.";
+ LOGV2(22097,
+ "Failed to persist metadata update for db '{dbName}' due to shutdown.",
+ "dbName"_attr = dbName);
inShutdown = true;
} catch (const DBException& ex) {
- LOG(0) << "Failed to persist chunk metadata update for database " << dbName
- << causedBy(redact(ex));
+ LOGV2(22098,
+ "Failed to persist chunk metadata update for database {dbName}{causedBy_ex}",
+ "dbName"_attr = dbName,
+ "causedBy_ex"_attr = causedBy(redact(ex)));
}
{
@@ -1047,10 +1057,12 @@ void ShardServerCatalogCacheLoader::_runDbTasks(StringData dbName) {
_threadPool.schedule([this, name = dbName.toString()](auto status) {
if (ErrorCodes::isCancelationError(status.code())) {
- LOG(0) << "Cache loader failed to schedule a persisted metadata update"
- << " task for namespace '" << name << "' due to '" << redact(status)
- << "'. Clearing task list so that scheduling will be attempted by the next"
- << " caller to refresh this namespace.";
+ LOGV2(22099,
+ "Cache loader failed to schedule a persisted metadata update task for namespace "
+ "'{name}' due to '{status}'. Clearing task list so that scheduling will be "
+ "attempted by the next caller to refresh this namespace.",
+ "name"_attr = name,
+ "status"_attr = redact(status));
{
stdx::lock_guard<Latch> lock(_mutex);
diff --git a/src/mongo/db/s/sharded_connection_info.cpp b/src/mongo/db/s/sharded_connection_info.cpp
index 228572e1354..7348c90c486 100644
--- a/src/mongo/db/s/sharded_connection_info.cpp
+++ b/src/mongo/db/s/sharded_connection_info.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/s/sharded_connection_info.h"
#include "mongo/db/client.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -51,7 +52,7 @@ ShardedConnectionInfo* ShardedConnectionInfo::get(Client* client, bool create) {
auto& current = clientSCI(client);
if (!current && create) {
- LOG(1) << "entering shard mode for connection";
+ LOGV2_DEBUG(22060, 1, "entering shard mode for connection");
current.emplace();
}
diff --git a/src/mongo/db/s/sharding_initialization_mongod.cpp b/src/mongo/db/s/sharding_initialization_mongod.cpp
index 7c81c06766c..ec320b06c07 100644
--- a/src/mongo/db/s/sharding_initialization_mongod.cpp
+++ b/src/mongo/db/s/sharding_initialization_mongod.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/s/transaction_coordinator_service.h"
#include "mongo/db/server_options.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_connection.h"
@@ -102,13 +103,18 @@ public:
->getFixedExecutor()
->schedule([serviceContext = _serviceContext, connStr = state.connStr](Status status) {
if (ErrorCodes::isCancelationError(status.code())) {
- LOG(2) << "Unable to schedule confirmed set update due to " << status;
+ LOGV2_DEBUG(22067,
+ 2,
+ "Unable to schedule confirmed set update due to {status}",
+ "status"_attr = status);
return;
}
invariant(status);
try {
- LOG(0) << "Updating config server with confirmed set " << connStr;
+ LOGV2(22068,
+ "Updating config server with confirmed set {connStr}",
+ "connStr"_attr = connStr);
Grid::get(serviceContext)->shardRegistry()->updateReplSetHosts(connStr);
if (MONGO_unlikely(failUpdateShardIdentityConfigString.shouldFail())) {
@@ -130,7 +136,7 @@ public:
ShardingInitializationMongoD::updateShardIdentityConfigString(opCtx.get(),
connStr);
} catch (const ExceptionForCat<ErrorCategory::ShutdownError>& e) {
- LOG(0) << "Unable to update config server due to " << e;
+ LOGV2(22069, "Unable to update config server due to {e}", "e"_attr = e);
}
});
}
@@ -138,7 +144,10 @@ public:
try {
Grid::get(_serviceContext)->shardRegistry()->updateReplSetHosts(state.connStr);
} catch (const DBException& ex) {
- LOG(2) << "Unable to update config server with possible set due to " << ex;
+ LOGV2_DEBUG(22070,
+ 2,
+ "Unable to update config server with possible set due to {ex}",
+ "ex"_attr = ex);
}
}
void onDroppedSet(const Key&) noexcept final {}
@@ -176,8 +185,11 @@ void ShardingInitializationMongoD::initializeShardingEnvironmentOnShardServer(
Grid::get(opCtx)->setShardingInitialized();
- LOG(0) << "Finished initializing sharding components for "
- << (isStandaloneOrPrimary ? "primary" : "secondary") << " node.";
+ LOGV2(22071,
+ "Finished initializing sharding components for {isStandaloneOrPrimary_primary_secondary} "
+ "node.",
+ "isStandaloneOrPrimary_primary_secondary"_attr =
+ (isStandaloneOrPrimary ? "primary" : "secondary"));
}
ShardingInitializationMongoD::ShardingInitializationMongoD()
@@ -269,11 +281,13 @@ bool ShardingInitializationMongoD::initializeShardingAwarenessIfNeeded(Operation
if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
if (!foundShardIdentity) {
- warning() << "Started with --shardsvr, but no shardIdentity document was found on "
- "disk in "
- << NamespaceString::kServerConfigurationNamespace
- << ". This most likely means this server has not yet been added to a "
- "sharded cluster.";
+ LOGV2_WARNING(22074,
+ "Started with --shardsvr, but no shardIdentity document was found on "
+ "disk in {NamespaceString_kServerConfigurationNamespace}. This most "
+ "likely means this server has not yet been added to a "
+ "sharded cluster.",
+ "NamespaceString_kServerConfigurationNamespace"_attr =
+ NamespaceString::kServerConfigurationNamespace);
return false;
}
@@ -292,10 +306,13 @@ bool ShardingInitializationMongoD::initializeShardingAwarenessIfNeeded(Operation
} else {
// Warn if a shardIdentity document is found on disk but *not* started with --shardsvr.
if (!shardIdentityBSON.isEmpty()) {
- warning() << "Not started with --shardsvr, but a shardIdentity document was found "
- "on disk in "
- << NamespaceString::kServerConfigurationNamespace << ": "
- << shardIdentityBSON;
+ LOGV2_WARNING(
+ 22075,
+ "Not started with --shardsvr, but a shardIdentity document was found "
+ "on disk in {NamespaceString_kServerConfigurationNamespace}: {shardIdentityBSON}",
+ "NamespaceString_kServerConfigurationNamespace"_attr =
+ NamespaceString::kServerConfigurationNamespace,
+ "shardIdentityBSON"_attr = shardIdentityBSON);
}
return false;
}
@@ -310,7 +327,9 @@ void ShardingInitializationMongoD::initializeFromShardIdentity(
shardIdentity.validate(),
"Invalid shard identity document found when initializing sharding state");
- log() << "initializing sharding state with: " << shardIdentity;
+ LOGV2(22072,
+ "initializing sharding state with: {shardIdentity}",
+ "shardIdentity"_attr = shardIdentity);
const auto& configSvrConnStr = shardIdentity.getConfigsvrConnectionString();
@@ -361,17 +380,24 @@ void ShardingInitializationMongoD::updateShardIdentityConfigString(
auto result = update(opCtx, autoDb.getDb(), updateReq);
if (result.numMatched == 0) {
- warning() << "failed to update config string of shard identity document because "
- << "it does not exist. This shard could have been removed from the cluster";
+ LOGV2_WARNING(22076,
+ "failed to update config string of shard identity document because it "
+ "does not exist. This shard could have been removed from the cluster");
} else {
- LOG(2) << "Updated config server connection string in shardIdentity document to"
- << newConnectionString;
+ LOGV2_DEBUG(22073,
+ 2,
+ "Updated config server connection string in shardIdentity document "
+ "to{newConnectionString}",
+ "newConnectionString"_attr = newConnectionString);
}
} catch (const DBException& exception) {
auto status = exception.toStatus();
if (!ErrorCodes::isNotMasterError(status.code())) {
- warning() << "Error encountered while trying to update config connection string to "
- << newConnectionString.toString() << causedBy(redact(status));
+ LOGV2_WARNING(22077,
+ "Error encountered while trying to update config connection string to "
+ "{newConnectionString}{causedBy_status}",
+ "newConnectionString"_attr = newConnectionString.toString(),
+ "causedBy_status"_attr = causedBy(redact(status)));
}
}
}
diff --git a/src/mongo/db/s/sharding_logging.cpp b/src/mongo/db/s/sharding_logging.cpp
index c3d07903ceb..e714e59e73d 100644
--- a/src/mongo/db/s/sharding_logging.cpp
+++ b/src/mongo/db/s/sharding_logging.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/server_options.h"
#include "mongo/executor/network_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_changelog.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -80,7 +81,9 @@ Status ShardingLogging::logAction(OperationContext* opCtx,
if (result.isOK()) {
_actionLogCollectionCreated.store(1);
} else {
- log() << "couldn't create config.actionlog collection:" << causedBy(result);
+ LOGV2(22078,
+ "couldn't create config.actionlog collection:{causedBy_result}",
+ "causedBy_result"_attr = causedBy(result));
return result;
}
}
@@ -106,7 +109,9 @@ Status ShardingLogging::logChangeChecked(OperationContext* opCtx,
if (result.isOK()) {
_changeLogCollectionCreated.store(1);
} else {
- log() << "couldn't create config.changelog collection:" << causedBy(result);
+ LOGV2(22079,
+ "couldn't create config.changelog collection:{causedBy_result}",
+ "causedBy_result"_attr = causedBy(result));
return result;
}
}
@@ -144,15 +149,22 @@ Status ShardingLogging::_log(OperationContext* opCtx,
changeLog.setDetails(detail);
BSONObj changeLogBSON = changeLog.toBSON();
- log() << "about to log metadata event into " << logCollName << ": " << redact(changeLogBSON);
+ LOGV2(22080,
+ "about to log metadata event into {logCollName}: {changeLogBSON}",
+ "logCollName"_attr = logCollName,
+ "changeLogBSON"_attr = redact(changeLogBSON));
const NamespaceString nss("config", logCollName);
Status result = Grid::get(opCtx)->catalogClient()->insertConfigDocument(
opCtx, nss, changeLogBSON, writeConcern);
if (!result.isOK()) {
- warning() << "Error encountered while logging config change with ID [" << changeId
- << "] into collection " << logCollName << ": " << redact(result);
+ LOGV2_WARNING(22081,
+ "Error encountered while logging config change with ID [{changeId}] into "
+ "collection {logCollName}: {result}",
+ "changeId"_attr = changeId,
+ "logCollName"_attr = logCollName,
+ "result"_attr = redact(result));
}
return result;
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index 441d303a038..50c127f4de0 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -69,7 +70,9 @@ void ShardingState::setInitialized(ShardId shardId, OID clusterId) {
void ShardingState::setInitialized(Status failedStatus) {
invariant(!failedStatus.isOK());
- log() << "Failed to initialize sharding components" << causedBy(failedStatus);
+ LOGV2(22082,
+ "Failed to initialize sharding components{causedBy_failedStatus}",
+ "causedBy_failedStatus"_attr = causedBy(failedStatus));
stdx::unique_lock<Latch> ul(_mutex);
invariant(_getInitializationState() == InitializationState::kNew);
diff --git a/src/mongo/db/s/sharding_state_recovery.cpp b/src/mongo/db/s/sharding_state_recovery.cpp
index f8a869564ca..98d7a915e49 100644
--- a/src/mongo/db/s/sharding_state_recovery.cpp
+++ b/src/mongo/db/s/sharding_state_recovery.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/write_concern.h"
#include "mongo/db/write_concern_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -151,7 +152,10 @@ Status modifyRecoveryDocument(OperationContext* opCtx,
auto const grid = Grid::get(opCtx);
BSONObj updateObj = RecoveryDocument::createChangeObj(grid->configOpTime(), change);
- LOG(1) << "Changing sharding recovery document " << redact(updateObj);
+ LOGV2_DEBUG(22083,
+ 1,
+ "Changing sharding recovery document {updateObj}",
+ "updateObj"_attr = redact(updateObj));
UpdateRequest updateReq(NamespaceString::kServerConfigurationNamespace);
updateReq.setQuery(RecoveryDocument::getQuery());
@@ -196,7 +200,9 @@ void ShardingStateRecovery::endMetadataOp(OperationContext* opCtx) {
Status status =
modifyRecoveryDocument(opCtx, RecoveryDocument::Decrement, WriteConcernOptions());
if (!status.isOK()) {
- warning() << "Failed to decrement minOpTimeUpdaters due to " << redact(status);
+ LOGV2_WARNING(22088,
+ "Failed to decrement minOpTimeUpdaters due to {status}",
+ "status"_attr = redact(status));
}
}
@@ -223,24 +229,30 @@ Status ShardingStateRecovery::recover(OperationContext* opCtx) {
const auto recoveryDoc = std::move(recoveryDocStatus.getValue());
- log() << "Sharding state recovery process found document " << redact(recoveryDoc.toBSON());
+ LOGV2(22084,
+ "Sharding state recovery process found document {recoveryDoc}",
+ "recoveryDoc"_attr = redact(recoveryDoc.toBSON()));
if (!recoveryDoc.getMinOpTimeUpdaters()) {
// Treat the minOpTime as up-to-date
const auto prevOpTime = grid->advanceConfigOpTime(
opCtx, recoveryDoc.getMinOpTime(), "sharding state recovery document");
if (prevOpTime) {
- log()
- << "No in flight metadata change operations, so config server optime updated from "
- << *prevOpTime << " to " << recoveryDoc.getMinOpTime();
+ LOGV2(22085,
+ "No in flight metadata change operations, so config server optime updated from "
+ "{prevOpTime} to {recoveryDoc_getMinOpTime}",
+ "prevOpTime"_attr = *prevOpTime,
+ "recoveryDoc_getMinOpTime"_attr = recoveryDoc.getMinOpTime());
}
return Status::OK();
}
- log() << "Sharding state recovery document indicates there were "
- << recoveryDoc.getMinOpTimeUpdaters()
- << " metadata change operations in flight. Contacting the config server primary in order "
- "to retrieve the most recent opTime.";
+ LOGV2(
+ 22086,
+ "Sharding state recovery document indicates there were {recoveryDoc_getMinOpTimeUpdaters} "
+ "metadata change operations in flight. Contacting the config server primary in order "
+ "to retrieve the most recent opTime.",
+ "recoveryDoc_getMinOpTimeUpdaters"_attr = recoveryDoc.getMinOpTimeUpdaters());
// Need to fetch the latest uptime from the config server, so do a logging write
Status status = ShardingLogging::get(opCtx)->logChangeChecked(
@@ -252,12 +264,16 @@ Status ShardingStateRecovery::recover(OperationContext* opCtx) {
if (!status.isOK())
return status;
- log() << "Sharding state recovered. New config server opTime is " << grid->configOpTime();
+ LOGV2(22087,
+ "Sharding state recovered. New config server opTime is {grid_configOpTime}",
+ "grid_configOpTime"_attr = grid->configOpTime());
// Finally, clear the recovery document so next time we don't need to recover
status = modifyRecoveryDocument(opCtx, RecoveryDocument::Clear, kLocalWriteConcern);
if (!status.isOK()) {
- warning() << "Failed to reset sharding state recovery document due to " << redact(status);
+ LOGV2_WARNING(22089,
+ "Failed to reset sharding state recovery document due to {status}",
+ "status"_attr = redact(status));
}
return Status::OK();
diff --git a/src/mongo/db/s/shardsvr_shard_collection.cpp b/src/mongo/db/s/shardsvr_shard_collection.cpp
index c56eaeb0470..61d844b6fe8 100644
--- a/src/mongo/db/s/shardsvr_shard_collection.cpp
+++ b/src/mongo/db/s/shardsvr_shard_collection.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/s/shard_filtering_metadata_refresh.h"
#include "mongo/db/s/sharding_logging.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog/sharding_catalog_client_impl.h"
@@ -92,7 +93,9 @@ const ReadPreferenceSetting kConfigReadSelector(ReadPreference::Nearest, TagSet{
*/
void uassertStatusOKWithWarning(const Status& status) {
if (!status.isOK()) {
- warning() << "shardsvrShardCollection failed" << causedBy(redact(status));
+ LOGV2_WARNING(22103,
+ "shardsvrShardCollection failed{causedBy_status}",
+ "causedBy_status"_attr = causedBy(redact(status)));
uassertStatusOK(status);
}
}
@@ -467,7 +470,7 @@ void logStartShardCollection(OperationContext* opCtx,
const ShardsvrShardCollection& request,
const ShardCollectionTargetState& prerequisites,
const ShardId& dbPrimaryShardId) {
- LOG(0) << "CMD: shardcollection: " << cmdObj;
+ LOGV2(22100, "CMD: shardcollection: {cmdObj}", "cmdObj"_attr = cmdObj);
audit::logShardCollection(
opCtx->getClient(), nss.ns(), prerequisites.shardKeyPattern.toBSON(), request.getUnique());
@@ -722,8 +725,12 @@ UUID shardCollection(OperationContext* opCtx,
writeChunkDocumentsAndRefreshShards(*targetState, initialChunks);
}
- LOG(0) << "Created " << initialChunks.chunks.size() << " chunk(s) for: " << nss
- << ", producing collection version " << initialChunks.collVersion();
+ LOGV2(22101,
+ "Created {initialChunks_chunks_size} chunk(s) for: {nss}, producing collection version "
+ "{initialChunks_collVersion}",
+ "initialChunks_chunks_size"_attr = initialChunks.chunks.size(),
+ "nss"_attr = nss,
+ "initialChunks_collVersion"_attr = initialChunks.collVersion());
ShardingLogging::get(opCtx)->logChange(
@@ -813,7 +820,7 @@ public:
uuid);
if (MONGO_unlikely(pauseShardCollectionBeforeReturning.shouldFail())) {
- log() << "Hit pauseShardCollectionBeforeReturning";
+ LOGV2(22102, "Hit pauseShardCollectionBeforeReturning");
pauseShardCollectionBeforeReturning.pauseWhileSet(opCtx);
}
diff --git a/src/mongo/db/s/split_chunk_command.cpp b/src/mongo/db/s/split_chunk_command.cpp
index 4ddc478c405..2bc27bb5fb8 100644
--- a/src/mongo/db/s/split_chunk_command.cpp
+++ b/src/mongo/db/s/split_chunk_command.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/s/split_chunk.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -120,7 +121,7 @@ public:
auto parseShardNameStatus = bsonExtractStringField(cmdObj, "from", &shardName);
uassertStatusOK(parseShardNameStatus);
- log() << "received splitChunk request: " << redact(cmdObj);
+ LOGV2(22104, "received splitChunk request: {cmdObj}", "cmdObj"_attr = redact(cmdObj));
vector<BSONObj> splitKeys;
{
diff --git a/src/mongo/db/s/split_chunk_test.cpp b/src/mongo/db/s/split_chunk_test.cpp
index 5adb6c0b359..563692cac50 100644
--- a/src/mongo/db/s/split_chunk_test.cpp
+++ b/src/mongo/db/s/split_chunk_test.cpp
@@ -42,6 +42,7 @@
#include "mongo/executor/remote_command_request.h"
#include "mongo/executor/remote_command_response.h"
#include "mongo/executor/task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/dist_lock_manager_mock.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_collection.h"
@@ -169,8 +170,8 @@ void SplitChunkTest::expectLock() {
dynamic_cast<DistLockManagerMock*>(distLock())
->expectLock(
[this](StringData name, StringData whyMessage, Milliseconds) {
- LOG(0) << name;
- LOG(0) << whyMessage;
+ LOGV2(22105, "{name}", "name"_attr = name);
+ LOGV2(22106, "{whyMessage}", "whyMessage"_attr = whyMessage);
},
Status::OK());
}
diff --git a/src/mongo/db/s/split_vector.cpp b/src/mongo/db/s/split_vector.cpp
index 6b257208da1..725a60f95b1 100644
--- a/src/mongo/db/s/split_vector.cpp
+++ b/src/mongo/db/s/split_vector.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/query/plan_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -130,8 +131,11 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
return emptyVector;
}
- log() << "request split points lookup for chunk " << nss.toString() << " " << redact(minKey)
- << " -->> " << redact(maxKey);
+ LOGV2(22107,
+ "request split points lookup for chunk {nss} {minKey} -->> {maxKey}",
+ "nss"_attr = nss.toString(),
+ "minKey"_attr = redact(minKey),
+ "maxKey"_attr = redact(maxKey));
// We'll use the average object size and number of object to find approximately how many
// keys each chunk should have. We'll split at half the maxChunkSizeBytes or
@@ -141,8 +145,10 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
long long keyCount = maxChunkSizeBytes.get() / (2 * avgRecSize);
if (maxChunkObjects.get() && (maxChunkObjects.get() < keyCount)) {
- log() << "limiting split vector to " << maxChunkObjects.get() << " (from " << keyCount
- << ") objects ";
+ LOGV2(22108,
+ "limiting split vector to {maxChunkObjects_get} (from {keyCount}) objects ",
+ "maxChunkObjects_get"_attr = maxChunkObjects.get(),
+ "keyCount"_attr = keyCount);
keyCount = maxChunkObjects.get();
}
@@ -195,9 +201,14 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
if (currKey.woCompare(maxKeyInChunk) == 0) {
// Range contains only documents with a single key value. So we cannot possibly find a
// split point, and there is no need to scan any further.
- warning() << "possible low cardinality key detected in " << nss.toString()
- << " - range " << redact(minKey) << " -->> " << redact(maxKey)
- << " contains only the key " << redact(prettyKey(idx->keyPattern(), currKey));
+ LOGV2_WARNING(22113,
+ "possible low cardinality key detected in {nss} - range {minKey} -->> "
+ "{maxKey} contains only the key {prettyKey_idx_keyPattern_currKey}",
+ "nss"_attr = nss.toString(),
+ "minKey"_attr = redact(minKey),
+ "maxKey"_attr = redact(maxKey),
+ "prettyKey_idx_keyPattern_currKey"_attr =
+ redact(prettyKey(idx->keyPattern(), currKey)));
std::vector<BSONObj> emptyVector;
return emptyVector;
}
@@ -232,9 +243,12 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
continue;
}
- log() << "Max BSON response size reached for split vector before the"
- << " end of chunk " << nss.toString() << " " << redact(minKey)
- << " -->> " << redact(maxKey);
+ LOGV2(22109,
+ "Max BSON response size reached for split vector before the end "
+ "of chunk {nss} {minKey} -->> {maxKey}",
+ "nss"_attr = nss.toString(),
+ "minKey"_attr = redact(minKey),
+ "maxKey"_attr = redact(maxKey));
break;
}
@@ -242,15 +256,22 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
splitKeys.push_back(currKey.getOwned());
currCount = 0;
numChunks++;
- LOG(4) << "picked a split key: " << redact(currKey);
+ LOGV2_DEBUG(22110,
+ 4,
+ "picked a split key: {currKey}",
+ "currKey"_attr = redact(currKey));
}
}
// Stop if we have enough split points.
if (maxSplitPoints && maxSplitPoints.get() && (numChunks >= maxSplitPoints.get())) {
- log() << "max number of requested split points reached (" << numChunks
- << ") before the end of chunk " << nss.toString() << " " << redact(minKey)
- << " -->> " << redact(maxKey);
+ LOGV2(22111,
+ "max number of requested split points reached ({numChunks}) before the "
+ "end of chunk {nss} {minKey} -->> {maxKey}",
+ "numChunks"_attr = numChunks,
+ "nss"_attr = nss.toString(),
+ "minKey"_attr = redact(minKey),
+ "maxKey"_attr = redact(maxKey));
break;
}
@@ -273,7 +294,9 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
force = false;
keyCount = currCount / 2;
currCount = 0;
- log() << "splitVector doing another cycle because of force, keyCount now: " << keyCount;
+ LOGV2(22112,
+ "splitVector doing another cycle because of force, keyCount now: {keyCount}",
+ "keyCount"_attr = keyCount);
exec = InternalPlanner::indexScan(opCtx,
collection,
@@ -294,18 +317,28 @@ StatusWith<std::vector<BSONObj>> splitVector(OperationContext* opCtx,
// Warn for keys that are more numerous than maxChunkSizeBytes allows.
for (auto it = tooFrequentKeys.cbegin(); it != tooFrequentKeys.cend(); ++it) {
- warning() << "possible low cardinality key detected in " << nss.toString()
- << " - key is " << redact(prettyKey(idx->keyPattern(), *it));
+ LOGV2_WARNING(22114,
+ "possible low cardinality key detected in {nss} - key is "
+ "{prettyKey_idx_keyPattern_it}",
+ "nss"_attr = nss.toString(),
+ "prettyKey_idx_keyPattern_it"_attr =
+ redact(prettyKey(idx->keyPattern(), *it)));
}
// Remove the sentinel at the beginning before returning
splitKeys.erase(splitKeys.begin());
if (timer.millis() > serverGlobalParams.slowMS) {
- warning() << "Finding the split vector for " << nss.toString() << " over "
- << redact(keyPattern) << " keyCount: " << keyCount
- << " numSplits: " << splitKeys.size() << " lookedAt: " << currCount
- << " took " << timer.millis() << "ms";
+ LOGV2_WARNING(
+ 22115,
+ "Finding the split vector for {nss} over {keyPattern} keyCount: {keyCount} "
+ "numSplits: {splitKeys_size} lookedAt: {currCount} took {timer_millis}ms",
+ "nss"_attr = nss.toString(),
+ "keyPattern"_attr = redact(keyPattern),
+ "keyCount"_attr = keyCount,
+ "splitKeys_size"_attr = splitKeys.size(),
+ "currCount"_attr = currCount,
+ "timer_millis"_attr = timer.millis());
}
}
diff --git a/src/mongo/db/s/transaction_coordinator.cpp b/src/mongo/db/s/transaction_coordinator.cpp
index 9393168a86b..f890ee3ef5a 100644
--- a/src/mongo/db/s/transaction_coordinator.cpp
+++ b/src/mongo/db/s/transaction_coordinator.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/s/transaction_coordinator_metrics_observer.h"
#include "mongo/db/s/wait_for_majority_service.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -63,7 +64,7 @@ ExecutorFuture<void> waitForMajorityWithHangFailpoint(ServiceContext* service,
if (auto sfp = failpoint.scoped(); MONGO_unlikely(sfp.isActive())) {
const BSONObj& data = sfp.getData();
- LOG(0) << "Hit " << failPointName << " failpoint";
+ LOGV2(22445, "Hit {failPointName} failpoint", "failPointName"_attr = failPointName);
// Run the hang failpoint asynchronously on a different thread to avoid self deadlocks.
return ExecutorFuture<void>(executor).then(
@@ -200,9 +201,14 @@ TransactionCoordinator::TransactionCoordinator(OperationContext* operationContex
}
if (_decision->getDecision() == CommitDecision::kCommit) {
- LOG(3) << txn::txnIdToString(_lsid, _txnNumber)
- << " Advancing cluster time to the commit timestamp "
- << *_decision->getCommitTimestamp();
+ LOGV2_DEBUG(22446,
+ 3,
+ "{txn_txnIdToString_lsid_txnNumber} Advancing cluster time to "
+ "the commit timestamp {decision_getCommitTimestamp}",
+ "txn_txnIdToString_lsid_txnNumber"_attr =
+ txn::txnIdToString(_lsid, _txnNumber),
+ "decision_getCommitTimestamp"_attr =
+ *_decision->getCommitTimestamp());
uassertStatusOK(LogicalClock::get(_serviceContext)
->advanceClusterTime(
@@ -382,8 +388,11 @@ void TransactionCoordinator::_done(Status status) {
str::stream() << "Coordinator " << _lsid.getId() << ':' << _txnNumber
<< " stopped due to: " << status.reason());
- LOG(3) << txn::txnIdToString(_lsid, _txnNumber) << " Two-phase commit completed with "
- << redact(status);
+ LOGV2_DEBUG(22447,
+ 3,
+ "{txn_txnIdToString_lsid_txnNumber} Two-phase commit completed with {status}",
+ "txn_txnIdToString_lsid_txnNumber"_attr = txn::txnIdToString(_lsid, _txnNumber),
+ "status"_attr = redact(status));
stdx::unique_lock<Latch> ul(_mutex);
@@ -413,7 +422,9 @@ void TransactionCoordinator::_done(Status status) {
void TransactionCoordinator::_logSlowTwoPhaseCommit(
const txn::CoordinatorCommitDecision& decision) {
- log() << _twoPhaseCommitInfoForLog(decision);
+ LOGV2(22448,
+ "{twoPhaseCommitInfoForLog_decision}",
+ "twoPhaseCommitInfoForLog_decision"_attr = _twoPhaseCommitInfoForLog(decision));
}
std::string TransactionCoordinator::_twoPhaseCommitInfoForLog(
diff --git a/src/mongo/db/s/transaction_coordinator_catalog.cpp b/src/mongo/db/s/transaction_coordinator_catalog.cpp
index fc0612515b2..0b90a8694f3 100644
--- a/src/mongo/db/s/transaction_coordinator_catalog.cpp
+++ b/src/mongo/db/s/transaction_coordinator_catalog.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/s/transaction_coordinator_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -46,10 +47,12 @@ TransactionCoordinatorCatalog::~TransactionCoordinatorCatalog() {
void TransactionCoordinatorCatalog::exitStepUp(Status status) {
if (status.isOK()) {
- LOG(0) << "Incoming coordinateCommit requests are now enabled";
+ LOGV2(22438, "Incoming coordinateCommit requests are now enabled");
} else {
- warning() << "Coordinator recovery failed and coordinateCommit requests will not be allowed"
- << causedBy(status);
+ LOGV2_WARNING(22444,
+ "Coordinator recovery failed and coordinateCommit requests will not be "
+ "allowed{causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
}
stdx::lock_guard<Latch> lk(_mutex);
@@ -80,8 +83,11 @@ void TransactionCoordinatorCatalog::insert(OperationContext* opCtx,
TxnNumber txnNumber,
std::shared_ptr<TransactionCoordinator> coordinator,
bool forStepUp) {
- LOG(3) << "Inserting coordinator " << lsid.getId() << ':' << txnNumber
- << " into in-memory catalog";
+ LOGV2_DEBUG(22439,
+ 3,
+ "Inserting coordinator {lsid_getId}:{txnNumber} into in-memory catalog",
+ "lsid_getId"_attr = lsid.getId(),
+ "txnNumber"_attr = txnNumber);
stdx::unique_lock<Latch> ul(_mutex);
if (!forStepUp) {
@@ -153,8 +159,11 @@ TransactionCoordinatorCatalog::getLatestOnSession(OperationContext* opCtx,
}
void TransactionCoordinatorCatalog::_remove(const LogicalSessionId& lsid, TxnNumber txnNumber) {
- LOG(3) << "Removing coordinator " << lsid.getId() << ':' << txnNumber
- << " from in-memory catalog";
+ LOGV2_DEBUG(22440,
+ 3,
+ "Removing coordinator {lsid_getId}:{txnNumber} from in-memory catalog",
+ "lsid_getId"_attr = lsid.getId(),
+ "txnNumber"_attr = txnNumber);
stdx::lock_guard<Latch> lk(_mutex);
@@ -175,7 +184,7 @@ void TransactionCoordinatorCatalog::_remove(const LogicalSessionId& lsid, TxnNum
}
if (_coordinatorsBySession.empty()) {
- LOG(3) << "Signaling last active coordinator removed";
+ LOGV2_DEBUG(22441, 3, "Signaling last active coordinator removed");
_noActiveCoordinatorsCV.notify_all();
}
}
@@ -185,9 +194,11 @@ void TransactionCoordinatorCatalog::join() {
while (!_noActiveCoordinatorsCV.wait_for(
ul, stdx::chrono::seconds{5}, [this] { return _coordinatorsBySession.empty(); })) {
- LOG(0) << "After 5 seconds of wait there are still " << _coordinatorsBySession.size()
- << " sessions left with active coordinators which have not yet completed";
- LOG(0) << _toString(ul);
+ LOGV2(22442,
+ "After 5 seconds of wait there are still {coordinatorsBySession_size} sessions left "
+ "with active coordinators which have not yet completed",
+ "coordinatorsBySession_size"_attr = _coordinatorsBySession.size());
+ LOGV2(22443, "{ul}", "ul"_attr = _toString(ul));
}
}
diff --git a/src/mongo/db/s/transaction_coordinator_futures_util.cpp b/src/mongo/db/s/transaction_coordinator_futures_util.cpp
index 5f19b0eeb46..f243396228e 100644
--- a/src/mongo/db/s/transaction_coordinator_futures_util.cpp
+++ b/src/mongo/db/s/transaction_coordinator_futures_util.cpp
@@ -36,6 +36,7 @@
#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/s/sharding_state.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/grid.h"
#include "mongo/transport/service_entry_point.h"
@@ -96,7 +97,7 @@ Future<executor::TaskExecutor::ResponseStatus> AsyncWorkScheduler::scheduleRemot
->grantInternalAuthorization(opCtx->getClient());
if (MONGO_unlikely(hangWhileTargetingLocalHost.shouldFail())) {
- LOG(0) << "Hit hangWhileTargetingLocalHost failpoint";
+ LOGV2(22449, "Hit hangWhileTargetingLocalHost failpoint");
hangWhileTargetingLocalHost.pauseWhileSet(opCtx);
}
@@ -232,7 +233,9 @@ Future<AsyncWorkScheduler::HostAndShard> AsyncWorkScheduler::_targetHostAsync(
const auto shard = uassertStatusOK(shardRegistry->getShard(opCtx, shardId));
if (MONGO_unlikely(hangWhileTargetingRemoteHost.shouldFail())) {
- LOG(0) << "Hit hangWhileTargetingRemoteHost failpoint for shard " << shardId;
+ LOGV2(22450,
+ "Hit hangWhileTargetingRemoteHost failpoint for shard {shardId}",
+ "shardId"_attr = shardId);
hangWhileTargetingRemoteHost.pauseWhileSet(opCtx);
}
diff --git a/src/mongo/db/s/transaction_coordinator_service.cpp b/src/mongo/db/s/transaction_coordinator_service.cpp
index 3ac1212a468..131a79eef8a 100644
--- a/src/mongo/db/s/transaction_coordinator_service.cpp
+++ b/src/mongo/db/s/transaction_coordinator_service.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/s/transaction_coordinator_document_gen.h"
#include "mongo/db/transaction_participant_gen.h"
#include "mongo/db/write_concern.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -184,8 +185,10 @@ void TransactionCoordinatorService::onStepUp(OperationContext* opCtx,
replClientInfo.setLastOpToSystemLastOpTime(opCtx);
const auto lastOpTime = replClientInfo.getLastOp();
- LOG(3) << "Waiting for OpTime " << lastOpTime
- << " to become majority committed";
+ LOGV2_DEBUG(22451,
+ 3,
+ "Waiting for OpTime {lastOpTime} to become majority committed",
+ "lastOpTime"_attr = lastOpTime);
WriteConcernResult unusedWCResult;
uassertStatusOK(waitForWriteConcern(
@@ -198,8 +201,10 @@ void TransactionCoordinatorService::onStepUp(OperationContext* opCtx,
auto coordinatorDocs = txn::readAllCoordinatorDocs(opCtx);
- LOG(0) << "Need to resume coordinating commit for " << coordinatorDocs.size()
- << " transactions";
+ LOGV2(22452,
+ "Need to resume coordinating commit for {coordinatorDocs_size} "
+ "transactions",
+ "coordinatorDocs_size"_attr = coordinatorDocs.size());
const auto service = opCtx->getServiceContext();
const auto clockSource = service->getFastClockSource();
@@ -208,7 +213,10 @@ void TransactionCoordinatorService::onStepUp(OperationContext* opCtx,
auto& scheduler = catalogAndScheduler->scheduler;
for (const auto& doc : coordinatorDocs) {
- LOG(3) << "Going to resume coordinating commit for " << doc.toBSON();
+ LOGV2_DEBUG(22453,
+ 3,
+ "Going to resume coordinating commit for {doc}",
+ "doc"_attr = doc.toBSON());
const auto lsid = *doc.getId().getSessionId();
const auto txnNumber = *doc.getId().getTxnNumber();
@@ -274,7 +282,7 @@ void TransactionCoordinatorService::joinPreviousRound() {
if (!_catalogAndSchedulerToCleanup)
return;
- LOG(0) << "Waiting for coordinator tasks from previous term to complete";
+ LOGV2(22454, "Waiting for coordinator tasks from previous term to complete");
// Block until all coordinators scheduled the previous time the service was primary to have
// drained. Because the scheduler was interrupted, it should be extremely rare for there to be
diff --git a/src/mongo/db/s/transaction_coordinator_test.cpp b/src/mongo/db/s/transaction_coordinator_test.cpp
index 93083cb9739..3d6be9ff152 100644
--- a/src/mongo/db/s/transaction_coordinator_test.cpp
+++ b/src/mongo/db/s/transaction_coordinator_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/s/transaction_coordinator_document_gen.h"
#include "mongo/db/s/transaction_coordinator_metrics_observer.h"
#include "mongo/db/s/transaction_coordinator_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/log.h"
@@ -87,7 +88,9 @@ void killClientOpCtx(ServiceContext* service, const std::string& clientName) {
sleepmillis(50);
}
- error() << "Timed out trying to find and kill client opCtx with name: " << clientName;
+ LOGV2_ERROR(22462,
+ "Timed out trying to find and kill client opCtx with name: {clientName}",
+ "clientName"_attr = clientName);
ASSERT_FALSE(true);
}
@@ -1513,7 +1516,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) {
checkMetrics(expectedMetrics);
- log() << "Create the coordinator.";
+ LOGV2(22455, "Create the coordinator.");
expectedStats.createTime = advanceClockSourceAndReturnNewNow();
expectedStats.totalDuration = Microseconds(0);
@@ -1531,8 +1534,9 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) {
checkStats(stats, expectedStats);
checkMetrics(expectedMetrics);
- log() << "Start two-phase commit (allow the coordinator to progress to writing the participant "
- "list).";
+ LOGV2(22456,
+ "Start two-phase commit (allow the coordinator to progress to writing the participant "
+ "list).");
expectedStats.writingParticipantListStartTime = advanceClockSourceAndReturnNewNow();
tickSource()->advance(Microseconds(100));
@@ -1552,7 +1556,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) {
checkStats(stats, expectedStats);
checkMetrics(expectedMetrics);
- log() << "Allow the coordinator to progress to waiting for votes.";
+ LOGV2(22457, "Allow the coordinator to progress to waiting for votes.");
expectedStats.waitingForVotesStartTime = advanceClockSourceAndReturnNewNow();
tickSource()->advance(Microseconds(100));
@@ -1573,7 +1577,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) {
checkStats(stats, expectedStats);
checkMetrics(expectedMetrics);
- log() << "Allow the coordinator to progress to writing the decision.";
+ LOGV2(22458, "Allow the coordinator to progress to writing the decision.");
expectedStats.writingDecisionStartTime = advanceClockSourceAndReturnNewNow();
tickSource()->advance(Microseconds(100));
@@ -1599,7 +1603,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) {
checkStats(stats, expectedStats);
checkMetrics(expectedMetrics);
- log() << "Allow the coordinator to progress to waiting for acks.";
+ LOGV2(22459, "Allow the coordinator to progress to waiting for acks.");
expectedStats.waitingForDecisionAcksStartTime = advanceClockSourceAndReturnNewNow();
tickSource()->advance(Microseconds(100));
@@ -1623,7 +1627,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) {
checkStats(stats, expectedStats);
checkMetrics(expectedMetrics);
- log() << "Allow the coordinator to progress to deleting the coordinator doc.";
+ LOGV2(22460, "Allow the coordinator to progress to deleting the coordinator doc.");
expectedStats.deletingCoordinatorDocStartTime = advanceClockSourceAndReturnNewNow();
tickSource()->advance(Microseconds(100));
@@ -1649,7 +1653,7 @@ TEST_F(TransactionCoordinatorMetricsTest, SimpleTwoPhaseCommitRealCoordinator) {
checkStats(stats, expectedStats);
checkMetrics(expectedMetrics);
- log() << "Allow the coordinator to complete.";
+ LOGV2(22461, "Allow the coordinator to complete.");
expectedStats.endTime = advanceClockSourceAndReturnNewNow();
tickSource()->advance(Microseconds(100));
diff --git a/src/mongo/db/s/transaction_coordinator_util.cpp b/src/mongo/db/s/transaction_coordinator_util.cpp
index 7d98befd9d2..f0968bc0644 100644
--- a/src/mongo/db/s/transaction_coordinator_util.cpp
+++ b/src/mongo/db/s/transaction_coordinator_util.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/s/transaction_coordinator_futures_util.h"
#include "mongo/db/s/transaction_coordinator_worker_curop_repository.h"
#include "mongo/db/write_concern.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -105,10 +106,13 @@ repl::OpTime persistParticipantListBlocking(OperationContext* opCtx,
const LogicalSessionId& lsid,
TxnNumber txnNumber,
const std::vector<ShardId>& participantList) {
- LOG(3) << txnIdToString(lsid, txnNumber) << " Going to write participant list";
+ LOGV2_DEBUG(22463,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Going to write participant list",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber));
if (MONGO_unlikely(hangBeforeWritingParticipantList.shouldFail())) {
- LOG(0) << "Hit hangBeforeWritingParticipantList failpoint";
+ LOGV2(22464, "Hit hangBeforeWritingParticipantList failpoint");
hangBeforeWritingParticipantList.pauseWhileSet(opCtx);
}
@@ -167,7 +171,10 @@ repl::OpTime persistParticipantListBlocking(OperationContext* opCtx,
// Throw any other error.
uassertStatusOK(upsertStatus);
- LOG(3) << txnIdToString(lsid, txnNumber) << " Wrote participant list";
+ LOGV2_DEBUG(22465,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Wrote participant list",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber));
return repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp();
}
@@ -240,7 +247,7 @@ Future<PrepareVoteConsensus> sendPrepare(ServiceContext* service,
opCtx, lsid, txnNumber, CoordinatorAction::kSendingPrepare);
if (MONGO_unlikely(hangBeforeSendingPrepare.shouldFail())) {
- LOG(0) << "Hit hangBeforeSendingPrepare failpoint";
+ LOGV2(22466, "Hit hangBeforeSendingPrepare failpoint");
hangBeforeSendingPrepare.pauseWhileSet(opCtx);
}
};
@@ -289,11 +296,14 @@ repl::OpTime persistDecisionBlocking(OperationContext* opCtx,
const std::vector<ShardId>& participantList,
const txn::CoordinatorCommitDecision& decision) {
const bool isCommit = decision.getDecision() == txn::CommitDecision::kCommit;
- LOG(3) << txnIdToString(lsid, txnNumber) << " Going to write decision "
- << (isCommit ? "commit" : "abort");
+ LOGV2_DEBUG(22467,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Going to write decision {isCommit_commit_abort}",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber),
+ "isCommit_commit_abort"_attr = (isCommit ? "commit" : "abort"));
if (MONGO_unlikely(hangBeforeWritingDecision.shouldFail())) {
- LOG(0) << "Hit hangBeforeWritingDecision failpoint";
+ LOGV2(22468, "Hit hangBeforeWritingDecision failpoint");
hangBeforeWritingDecision.pauseWhileSet(opCtx);
}
@@ -357,8 +367,11 @@ repl::OpTime persistDecisionBlocking(OperationContext* opCtx,
<< doc);
}
- LOG(3) << txnIdToString(lsid, txnNumber) << " Wrote decision "
- << (isCommit ? "commit" : "abort");
+ LOGV2_DEBUG(22469,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Wrote decision {isCommit_commit_abort}",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber),
+ "isCommit_commit_abort"_attr = (isCommit ? "commit" : "abort"));
return repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp();
}
@@ -402,7 +415,7 @@ Future<void> sendCommit(ServiceContext* service,
opCtx, lsid, txnNumber, CoordinatorAction::kSendingCommit);
if (MONGO_unlikely(hangBeforeSendingCommit.shouldFail())) {
- LOG(0) << "Hit hangBeforeSendingCommit failpoint";
+ LOGV2(22470, "Hit hangBeforeSendingCommit failpoint");
hangBeforeSendingCommit.pauseWhileSet(opCtx);
}
};
@@ -432,7 +445,7 @@ Future<void> sendAbort(ServiceContext* service,
opCtx, lsid, txnNumber, CoordinatorAction::kSendingAbort);
if (MONGO_unlikely(hangBeforeSendingAbort.shouldFail())) {
- LOG(0) << "Hit hangBeforeSendingAbort failpoint";
+ LOGV2(22471, "Hit hangBeforeSendingAbort failpoint");
hangBeforeSendingAbort.pauseWhileSet(opCtx);
}
};
@@ -449,10 +462,13 @@ namespace {
void deleteCoordinatorDocBlocking(OperationContext* opCtx,
const LogicalSessionId& lsid,
TxnNumber txnNumber) {
- LOG(3) << txnIdToString(lsid, txnNumber) << " Going to delete coordinator doc";
+ LOGV2_DEBUG(22472,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Going to delete coordinator doc",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber));
if (MONGO_unlikely(hangBeforeDeletingCoordinatorDoc.shouldFail())) {
- LOG(0) << "Hit hangBeforeDeletingCoordinatorDoc failpoint";
+ LOGV2(22473, "Hit hangBeforeDeletingCoordinatorDoc failpoint");
hangBeforeDeletingCoordinatorDoc.pauseWhileSet(opCtx);
}
@@ -504,10 +520,13 @@ void deleteCoordinatorDocBlocking(OperationContext* opCtx,
<< doc);
}
- LOG(3) << txnIdToString(lsid, txnNumber) << " Deleted coordinator doc";
+ LOGV2_DEBUG(22474,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Deleted coordinator doc",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber));
hangAfterDeletingCoordinatorDoc.execute([&](const BSONObj& data) {
- LOG(0) << "Hit hangAfterDeletingCoordinatorDoc failpoint";
+ LOGV2(22475, "Hit hangAfterDeletingCoordinatorDoc failpoint");
if (!data["useUninterruptibleSleep"].eoo()) {
hangAfterDeletingCoordinatorDoc.pauseWhileSet();
} else {
@@ -576,8 +595,14 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service,
isLocalShard,
commandObj = commandObj.getOwned(),
operationContextFn] {
- LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator going to send command "
- << commandObj << " to " << (isLocalShard ? "local " : "") << "shard " << shardId;
+ LOGV2_DEBUG(22476,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Coordinator going to send command "
+ "{commandObj} to {isLocalShard_local}shard {shardId}",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber),
+ "commandObj"_attr = commandObj,
+ "isLocalShard_local"_attr = (isLocalShard ? "local " : ""),
+ "shardId"_attr = shardId);
return scheduler
.scheduleRemoteCommand(
@@ -605,16 +630,26 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service,
<< shardId
<< ", which is not an expected behavior. "
"Interpreting the response as vote to abort");
- LOG(0) << txnIdToString(lsid, txnNumber) << " " << redact(abortStatus);
+ LOGV2(22477,
+ "{txnIdToString_lsid_txnNumber} {abortStatus}",
+ "txnIdToString_lsid_txnNumber"_attr =
+ txnIdToString(lsid, txnNumber),
+ "abortStatus"_attr = redact(abortStatus));
return PrepareResponse{
shardId, PrepareVote::kAbort, boost::none, abortStatus};
}
- LOG(3) << txnIdToString(lsid, txnNumber)
- << " Coordinator shard received a vote to commit from shard "
- << shardId
- << " with prepareTimestamp: " << prepareTimestampField.timestamp();
+ LOGV2_DEBUG(22478,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Coordinator shard received a "
+ "vote to commit from shard {shardId} with prepareTimestamp: "
+ "{prepareTimestampField_timestamp}",
+ "txnIdToString_lsid_txnNumber"_attr =
+ txnIdToString(lsid, txnNumber),
+ "shardId"_attr = shardId,
+ "prepareTimestampField_timestamp"_attr =
+ prepareTimestampField.timestamp());
return PrepareResponse{shardId,
PrepareVote::kCommit,
@@ -622,8 +657,15 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service,
boost::none};
}
- LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator shard received "
- << status << " from shard " << shardId << " for " << commandObj;
+ LOGV2_DEBUG(22479,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Coordinator shard received "
+ "{status} from shard {shardId} for {commandObj}",
+ "txnIdToString_lsid_txnNumber"_attr =
+ txnIdToString(lsid, txnNumber),
+ "status"_attr = status,
+ "shardId"_attr = shardId,
+ "commandObj"_attr = commandObj);
if (ErrorCodes::isVoteAbortError(status.code())) {
return PrepareResponse{
@@ -652,8 +694,11 @@ Future<PrepareResponse> sendPrepareToShard(ServiceContext* service,
return std::move(f).onError<ErrorCodes::TransactionCoordinatorReachedAbortDecision>(
[lsid, txnNumber, shardId](const Status& status) {
- LOG(3) << txnIdToString(lsid, txnNumber)
- << " Prepare stopped retrying due to retrying being cancelled";
+ LOGV2_DEBUG(22480,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Prepare stopped retrying due to retrying "
+ "being cancelled",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber));
return PrepareResponse{shardId, boost::none, boost::none, status};
});
}
@@ -682,8 +727,14 @@ Future<void> sendDecisionToShard(ServiceContext* service,
isLocalShard,
operationContextFn,
commandObj = commandObj.getOwned()] {
- LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator going to send command "
- << commandObj << " to " << (isLocalShard ? "local " : "") << "shard " << shardId;
+ LOGV2_DEBUG(22481,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Coordinator going to send command "
+ "{commandObj} to {isLocalShard_local}shard {shardId}",
+ "txnIdToString_lsid_txnNumber"_attr = txnIdToString(lsid, txnNumber),
+ "commandObj"_attr = commandObj,
+ "isLocalShard_local"_attr = (isLocalShard ? "local " : ""),
+ "shardId"_attr = shardId);
return scheduler
.scheduleRemoteCommand(
@@ -699,9 +750,15 @@ Future<void> sendDecisionToShard(ServiceContext* service,
status = wcStatus;
}
- LOG(3) << txnIdToString(lsid, txnNumber) << " Coordinator shard received "
- << status << " in response to " << commandObj << " from shard "
- << shardId;
+ LOGV2_DEBUG(22482,
+ 3,
+ "{txnIdToString_lsid_txnNumber} Coordinator shard received "
+ "{status} in response to {commandObj} from shard {shardId}",
+ "txnIdToString_lsid_txnNumber"_attr =
+ txnIdToString(lsid, txnNumber),
+ "status"_attr = status,
+ "commandObj"_attr = commandObj,
+ "shardId"_attr = shardId);
if (ErrorCodes::isVoteAbortError(status.code())) {
// Interpret voteAbort errors as an ack.
diff --git a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
index 01bd1fed90a..6246e02d1ae 100644
--- a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
+++ b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/s/transaction_coordinator_service.h"
#include "mongo/db/session_catalog_mongod.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/log.h"
@@ -99,10 +100,12 @@ public:
"prepareTransaction must be run within a transaction",
txnParticipant);
- LOG(3)
- << "Participant shard received prepareTransaction for transaction with txnNumber "
- << opCtx->getTxnNumber() << " on session "
- << opCtx->getLogicalSessionId()->toBSON();
+ LOGV2_DEBUG(22483,
+ 3,
+ "Participant shard received prepareTransaction for transaction with "
+ "txnNumber {opCtx_getTxnNumber} on session {opCtx_getLogicalSessionId}",
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(),
+ "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON());
uassert(ErrorCodes::NoSuchTransaction,
"Transaction isn't in progress",
@@ -199,10 +202,14 @@ std::set<ShardId> validateParticipants(OperationContext* opCtx,
}
ss << ']';
- LOG(3) << "Coordinator shard received request to coordinate commit with "
- "participant list "
- << ss.str() << " for " << opCtx->getLogicalSessionId()->getId() << ':'
- << opCtx->getTxnNumber();
+ LOGV2_DEBUG(
+ 22484,
+ 3,
+ "Coordinator shard received request to coordinate commit with "
+ "participant list {ss_str} for {opCtx_getLogicalSessionId_getId}:{opCtx_getTxnNumber}",
+ "ss_str"_attr = ss.str(),
+ "opCtx_getLogicalSessionId_getId"_attr = opCtx->getLogicalSessionId()->getId(),
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber());
return participantsSet;
}
@@ -234,7 +241,7 @@ public:
validateParticipants(opCtx, cmd.getParticipants()));
if (MONGO_unlikely(hangAfterStartingCoordinateCommit.shouldFail())) {
- LOG(0) << "Hit hangAfterStartingCoordinateCommit failpoint";
+ LOGV2(22485, "Hit hangAfterStartingCoordinateCommit failpoint");
hangAfterStartingCoordinateCommit.pauseWhileSet(opCtx);
}
@@ -274,8 +281,13 @@ public:
// No coordinator was found in memory. Recover the decision from the local participant.
- LOG(3) << "Going to recover decision from local participant for "
- << opCtx->getLogicalSessionId()->getId() << ':' << opCtx->getTxnNumber();
+ LOGV2_DEBUG(22486,
+ 3,
+ "Going to recover decision from local participant for "
+ "{opCtx_getLogicalSessionId_getId}:{opCtx_getTxnNumber}",
+ "opCtx_getLogicalSessionId_getId"_attr =
+ opCtx->getLogicalSessionId()->getId(),
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber());
boost::optional<SharedSemiFuture<void>> participantExitPrepareFuture;
{
diff --git a/src/mongo/db/s/wait_for_majority_service.cpp b/src/mongo/db/s/wait_for_majority_service.cpp
index 1864335150a..d2895908c49 100644
--- a/src/mongo/db/s/wait_for_majority_service.cpp
+++ b/src/mongo/db/s/wait_for_majority_service.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/write_concern.h"
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/concurrency/thread_pool.h"
#include "mongo/util/log.h"
@@ -184,7 +185,7 @@ void WaitForMajorityService::_periodicallyWaitForMajority(ServiceContext* servic
_opCtx->waitForConditionOrInterrupt(
_hasNewOpTimeCV, lk, [&] { return !_queuedOpTimes.empty() || _inShutDown; });
} catch (const DBException& e) {
- LOG(1) << "Unable to wait for new op time due to: " << e;
+ LOGV2_DEBUG(22487, 1, "Unable to wait for new op time due to: {e}", "e"_attr = e);
}
_opCtx = nullptr;
diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp
index 4cf1a4164da..b1d4409f724 100644
--- a/src/mongo/db/server_options_server_helpers.cpp
+++ b/src/mongo/db/server_options_server_helpers.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/server_options_helpers.h"
#include "mongo/logger/log_component.h"
#include "mongo/logger/message_event_utf8_encoder.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/message_compressor_registry.h"
#include "mongo/util/cmdline_utils/censor_cmdline.h"
#include "mongo/util/fail_point.h"
@@ -114,7 +115,9 @@ Status setParsedOpts(const moe::Environment& params) {
} // namespace
void printCommandLineOpts() {
- log() << "options: " << serverGlobalParams.parsedOpts << endl;
+ LOGV2(21951,
+ "options: {serverGlobalParams_parsedOpts}",
+ "serverGlobalParams_parsedOpts"_attr = serverGlobalParams.parsedOpts);
}
Status validateServerOptions(const moe::Environment& params) {
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index 413a113e782..bd4165f2fe2 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -144,8 +144,11 @@ void generateLegacyQueryErrorResponse(const AssertionException& exception,
"ns"_attr = queryMessage.ns);
if (queryMessage.ntoskip || queryMessage.ntoreturn) {
- log(LogComponent::kQuery) << " ntoskip:" << queryMessage.ntoskip
- << " ntoreturn:" << queryMessage.ntoreturn;
+ LOGV2_OPTIONS(21952,
+ {logComponentV1toV2(LogComponent::kQuery)},
+ " ntoskip:{queryMessage_ntoskip} ntoreturn:{queryMessage_ntoreturn}",
+ "queryMessage_ntoskip"_attr = queryMessage.ntoskip,
+ "queryMessage_ntoreturn"_attr = queryMessage.ntoreturn);
}
BSONObjBuilder err;
@@ -160,8 +163,11 @@ void generateLegacyQueryErrorResponse(const AssertionException& exception,
const bool isStaleConfig = exception.code() == ErrorCodes::StaleConfig;
if (isStaleConfig) {
- log(LogComponent::kQuery) << "stale version detected during query over " << queryMessage.ns
- << " : " << errObj;
+ LOGV2_OPTIONS(21953,
+ {logComponentV1toV2(LogComponent::kQuery)},
+ "stale version detected during query over {queryMessage_ns} : {errObj}",
+ "queryMessage_ns"_attr = queryMessage.ns,
+ "errObj"_attr = errObj);
}
BufBuilder bb;
@@ -265,7 +271,8 @@ StatusWith<repl::ReadConcernArgs> _extractReadConcern(OperationContext* opCtx,
// shard/config server.
if (!readConcernArgs.isSpecified()) {
// TODO: Disabled until after SERVER-44539, to avoid log spam.
- // log() << "Missing readConcern on " << invocation->definition()->getName();
+ // LOGV2(21954, "Missing readConcern on {invocation_definition_getName}",
+ // "invocation_definition_getName"_attr = invocation->definition()->getName());
}
} else {
// A member in a regular replica set. Since these servers receive client queries, in
@@ -277,8 +284,13 @@ StatusWith<repl::ReadConcernArgs> _extractReadConcern(OperationContext* opCtx,
.getDefaultReadConcern(opCtx);
if (rcDefault) {
readConcernArgs = std::move(*rcDefault);
- LOG(2) << "Applying default readConcern on "
- << invocation->definition()->getName() << " of " << *rcDefault;
+ LOGV2_DEBUG(21955,
+ 2,
+ "Applying default readConcern on {invocation_definition_getName} "
+ "of {rcDefault}",
+ "invocation_definition_getName"_attr =
+ invocation->definition()->getName(),
+ "rcDefault"_attr = *rcDefault);
// Update the readConcernSupport, since the default RC was applied.
readConcernSupport =
invocation->supportsReadConcern(readConcernArgs.getLevel());
@@ -364,7 +376,7 @@ LogicalTime computeOperationTime(OperationContext* opCtx, LogicalTime startOpera
invariant(isReplSet);
if (startOperationTime == LogicalTime::kUninitialized) {
- LOG(5) << "startOperationTime is uninitialized";
+ LOGV2_DEBUG(21956, 5, "startOperationTime is uninitialized");
return LogicalTime(replCoord->getMyLastAppliedOpTime().getTimestamp());
}
@@ -413,8 +425,11 @@ void appendClusterAndOperationTime(OperationContext* opCtx,
dassert(signedTime.getTime() >= operationTime);
rpc::LogicalTimeMetadata(signedTime).writeToMetadata(metadataBob);
- LOG(5) << "Appending operationTime to cmd response for authorized client: "
- << operationTime;
+ LOGV2_DEBUG(
+ 21957,
+ 5,
+ "Appending operationTime to cmd response for authorized client: {operationTime}",
+ "operationTime"_attr = operationTime);
operationTime.appendAsOperationTime(commandBodyFieldsBob);
return;
@@ -438,7 +453,10 @@ void appendClusterAndOperationTime(OperationContext* opCtx,
dassert(signedTime.getTime() >= operationTime);
rpc::LogicalTimeMetadata(signedTime).writeToMetadata(metadataBob);
- LOG(5) << "Appending operationTime to cmd response: " << operationTime;
+ LOGV2_DEBUG(21958,
+ 5,
+ "Appending operationTime to cmd response: {operationTime}",
+ "operationTime"_attr = operationTime);
operationTime.appendAsOperationTime(commandBodyFieldsBob);
}
@@ -483,9 +501,14 @@ void _abortUnpreparedOrStashPreparedTransaction(
txnParticipant->abortTransaction(opCtx);
} catch (...) {
// It is illegal for this to throw so we catch and log this here for diagnosability.
- severe() << "Caught exception during transaction " << opCtx->getTxnNumber()
- << (isPrepared ? " stash " : " abort ") << opCtx->getLogicalSessionId()->toBSON()
- << ": " << exceptionToStatus();
+ LOGV2_FATAL(21974,
+ "Caught exception during transaction "
+ "{opCtx_getTxnNumber}{isPrepared_stash_abort}{opCtx_getLogicalSessionId}: "
+ "{exceptionToStatus}",
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(),
+ "isPrepared_stash_abort"_attr = (isPrepared ? " stash " : " abort "),
+ "opCtx_getLogicalSessionId"_attr = opCtx->getLogicalSessionId()->toBSON(),
+ "exceptionToStatus"_attr = exceptionToStatus());
std::terminate();
}
}
@@ -668,7 +691,8 @@ bool runCommandImpl(OperationContext* opCtx,
serverGlobalParams.clusterRole == ClusterRole::ConfigServer) &&
!request.body.hasField(WriteConcernOptions::kWriteConcernField)) {
// TODO: Disabled until after SERVER-44539, to avoid log spam.
- // log() << "Missing writeConcern on " << command->getName();
+ // LOGV2(21959, "Missing writeConcern on {command_getName}", "command_getName"_attr
+ // = command->getName());
}
extractedWriteConcern.emplace(
uassertStatusOK(extractWriteConcern(opCtx, request.body)));
@@ -709,9 +733,10 @@ bool runCommandImpl(OperationContext* opCtx,
if (MONGO_unlikely(failWithErrorCodeInRunCommand.shouldFail())) {
auto scoped = failWithErrorCodeInRunCommand.scoped();
const auto errorCode = scoped.getData()["errorCode"].numberInt();
- log() << "failWithErrorCodeInRunCommand enabled - failing command with error "
- "code: "
- << errorCode;
+ LOGV2(21960,
+ "failWithErrorCodeInRunCommand enabled - failing command with error "
+ "code: {errorCode}",
+ "errorCode"_attr = errorCode);
BSONObjBuilder errorBuilder;
errorBuilder.append("ok", 0.0);
errorBuilder.append("code", errorCode);
@@ -951,7 +976,10 @@ void execCommandDatabase(OperationContext* opCtx,
}
if (command->adminOnly()) {
- LOG(2) << "command: " << request.getCommandName();
+ LOGV2_DEBUG(21961,
+ 2,
+ "command: {request_getCommandName}",
+ "request_getCommandName"_attr = request.getCommandName());
}
if (command->maintenanceMode()) {
@@ -1124,11 +1152,17 @@ void execCommandDatabase(OperationContext* opCtx,
}
appendClusterAndOperationTime(opCtx, &extraFieldsBuilder, &metadataBob, startOperationTime);
- LOG(1) << "assertion while executing command '" << request.getCommandName() << "' "
- << "on database '" << request.getDatabase() << "' "
- << "with arguments '"
- << redact(ServiceEntryPointCommon::getRedactedCopyForLogging(command, request.body))
- << "': " << redact(e.toString());
+ LOGV2_DEBUG(
+ 21962,
+ 1,
+ "assertion while executing command '{request_getCommandName}' on database "
+ "'{request_getDatabase}' with arguments "
+ "'{ServiceEntryPointCommon_getRedactedCopyForLogging_command_request_body}': {e}",
+ "request_getCommandName"_attr = request.getCommandName(),
+ "request_getDatabase"_attr = request.getDatabase(),
+ "ServiceEntryPointCommon_getRedactedCopyForLogging_command_request_body"_attr =
+ redact(ServiceEntryPointCommon::getRedactedCopyForLogging(command, request.body)),
+ "e"_attr = redact(e.toString()));
generateErrorResponse(opCtx, replyBuilder, e, metadataBob.obj(), extraFieldsBuilder.obj());
}
@@ -1174,7 +1208,8 @@ DbResponse receivedCommands(OperationContext* opCtx,
// Otherwise, reply with the parse error. This is useful for cases where parsing fails
// due to user-supplied input, such as the document too deep error. Since we failed
// during parsing, we can't log anything about the command.
- LOG(1) << "assertion while parsing command: " << ex.toString();
+ LOGV2_DEBUG(
+ 21963, 1, "assertion while parsing command: {ex}", "ex"_attr = ex.toString());
generateErrorResponse(
opCtx, replyBuilder.get(), ex, metadataBob.obj(), extraFieldsBuilder.obj());
@@ -1194,12 +1229,18 @@ DbResponse receivedCommands(OperationContext* opCtx,
globalCommandRegistry()->incrementUnknownCommands();
std::string msg = str::stream()
<< "no such command: '" << request.getCommandName() << "'";
- LOG(2) << msg;
+ LOGV2_DEBUG(21964, 2, "{msg}", "msg"_attr = msg);
uasserted(ErrorCodes::CommandNotFound, str::stream() << msg);
}
- LOG(2) << "run command " << request.getDatabase() << ".$cmd" << ' '
- << redact(ServiceEntryPointCommon::getRedactedCopyForLogging(c, request.body));
+ LOGV2_DEBUG(
+ 21965,
+ 2,
+ "run command {request_getDatabase}.$cmd "
+ "{ServiceEntryPointCommon_getRedactedCopyForLogging_c_request_body}",
+ "request_getDatabase"_attr = request.getDatabase(),
+ "ServiceEntryPointCommon_getRedactedCopyForLogging_c_request_body"_attr =
+ redact(ServiceEntryPointCommon::getRedactedCopyForLogging(c, request.body)));
{
// Try to set this as early as possible, as soon as we have figured out the command.
@@ -1218,8 +1259,13 @@ DbResponse receivedCommands(OperationContext* opCtx,
appendClusterAndOperationTime(
opCtx, &extraFieldsBuilder, &metadataBob, LogicalTime::kUninitialized);
- LOG(1) << "assertion while executing command '" << request.getCommandName() << "' "
- << "on database '" << request.getDatabase() << "': " << ex.toString();
+ LOGV2_DEBUG(21966,
+ 1,
+ "assertion while executing command '{request_getCommandName}' on database "
+ "'{request_getDatabase}': {ex}",
+ "request_getCommandName"_attr = request.getCommandName(),
+ "request_getDatabase"_attr = request.getDatabase(),
+ "ex"_attr = ex.toString());
generateErrorResponse(
opCtx, replyBuilder.get(), ex, metadataBob.obj(), extraFieldsBuilder.obj());
@@ -1308,7 +1354,11 @@ void receivedKillCursors(OperationContext* opCtx, const Message& m) {
int found = runOpKillCursors(opCtx, static_cast<size_t>(n), cursorArray);
if (shouldLog(logger::LogSeverity::Debug(1)) || found != n) {
- LOG(found == n ? 1 : 0) << "killcursors: found " << found << " of " << n;
+ LOGV2_DEBUG(21967,
+ logSeverityV1toV2(found == n ? 1 : 0).toInt(),
+ "killcursors: found {found} of {n}",
+ "found"_attr = found,
+ "n"_attr = n);
}
}
@@ -1523,7 +1573,9 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx,
slowMsOverride = 10;
receivedKillCursors(opCtx, m);
} else if (op != dbInsert && op != dbUpdate && op != dbDelete) {
- log() << " operation isn't supported: " << static_cast<int>(op);
+ LOGV2(21968,
+ " operation isn't supported: {static_cast_int_op}",
+ "static_cast_int_op"_attr = static_cast<int>(op));
currentOp.done();
forceLog = true;
} else {
@@ -1549,8 +1601,11 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx,
}
} catch (const AssertionException& ue) {
LastError::get(c).setLastError(ue.code(), ue.reason());
- LOG(3) << " Caught Assertion in " << networkOpToString(op) << ", continuing "
- << redact(ue);
+ LOGV2_DEBUG(21969,
+ 3,
+ " Caught Assertion in {networkOpToString_op}, continuing {ue}",
+ "networkOpToString_op"_attr = networkOpToString(op),
+ "ue"_attr = redact(ue));
debug.errInfo = ue.toStatus();
}
// A NotMaster error can be set either within receivedInsert/receivedUpdate/receivedDelete
@@ -1580,15 +1635,15 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx,
if (currentOp.shouldDBProfile(shouldSample)) {
// Performance profiling is on
if (opCtx->lockState()->isReadLocked()) {
- LOG(1) << "note: not profiling because recursive read lock";
+ LOGV2_DEBUG(21970, 1, "note: not profiling because recursive read lock");
} else if (c.isInDirectClient()) {
- LOG(1) << "note: not profiling because we are in DBDirectClient";
+ LOGV2_DEBUG(21971, 1, "note: not profiling because we are in DBDirectClient");
} else if (behaviors.lockedForWriting()) {
// TODO SERVER-26825: Fix race condition where fsyncLock is acquired post
// lockedForWriting() call but prior to profile collection lock acquisition.
- LOG(1) << "note: not profiling because doing fsync+lock";
+ LOGV2_DEBUG(21972, 1, "note: not profiling because doing fsync+lock");
} else if (storageGlobalParams.readOnly) {
- LOG(1) << "note: not profiling because server is read-only";
+ LOGV2_DEBUG(21973, 1, "note: not profiling because server is read-only");
} else {
invariant(!opCtx->lockState()->inAWriteUnitOfWork());
profile(opCtx, op);
diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp
index f365c4d4987..f2ad493211e 100644
--- a/src/mongo/db/service_entry_point_mongod.cpp
+++ b/src/mongo/db/service_entry_point_mongod.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_entry_point_common.h"
#include "mongo/logger/redaction.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/config_server_metadata.h"
#include "mongo/rpc/metadata/sharding_metadata.h"
@@ -84,11 +85,18 @@ public:
if (ErrorCodes::isExceededTimeLimitError(rcStatus.code())) {
const int debugLevel =
serverGlobalParams.clusterRole == ClusterRole::ConfigServer ? 0 : 2;
- LOG(debugLevel) << "Command on database " << request.getDatabase()
- << " timed out waiting for read concern to be satisfied. Command: "
- << redact(ServiceEntryPointCommon::getRedactedCopyForLogging(
- invocation->definition(), request.body))
- << ". Info: " << redact(rcStatus);
+ LOGV2_DEBUG(
+ 21975,
+ logSeverityV1toV2(debugLevel).toInt(),
+ "Command on database {request_getDatabase} timed out waiting for read concern "
+ "to be satisfied. Command: "
+ "{ServiceEntryPointCommon_getRedactedCopyForLogging_invocation_definition_"
+ "request_body}. Info: {rcStatus}",
+ "request_getDatabase"_attr = request.getDatabase(),
+ "ServiceEntryPointCommon_getRedactedCopyForLogging_invocation_definition_request_body"_attr =
+ redact(ServiceEntryPointCommon::getRedactedCopyForLogging(
+ invocation->definition(), request.body)),
+ "rcStatus"_attr = redact(rcStatus));
}
uassertStatusOK(rcStatus);
diff --git a/src/mongo/db/session_catalog.cpp b/src/mongo/db/session_catalog.cpp
index 97fbff47f89..9f21653674b 100644
--- a/src/mongo/db/session_catalog.cpp
+++ b/src/mongo/db/session_catalog.cpp
@@ -36,6 +36,7 @@
#include <memory>
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -153,7 +154,10 @@ void SessionCatalog::scanSessions(const SessionKiller::Matcher& matcher,
{
stdx::lock_guard<Latch> lg(_mutex);
- LOG(2) << "Beginning scanSessions. Scanning " << _sessions.size() << " sessions.";
+ LOGV2_DEBUG(21976,
+ 2,
+ "Beginning scanSessions. Scanning {sessions_size} sessions.",
+ "sessions_size"_attr = _sessions.size());
for (auto it = _sessions.begin(); it != _sessions.end(); ++it) {
if (matcher.match(it->first)) {
diff --git a/src/mongo/db/session_catalog_mongod.cpp b/src/mongo/db/session_catalog_mongod.cpp
index 9094e585b35..ca8f411c165 100644
--- a/src/mongo/db/session_catalog_mongod.cpp
+++ b/src/mongo/db/session_catalog_mongod.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/session_txn_record_gen.h"
#include "mongo/db/sessions_collection.h"
#include "mongo/db/transaction_participant.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/util/concurrency/thread_pool.h"
@@ -195,7 +196,7 @@ void abortInProgressTransactions(OperationContext* opCtx) {
<< DurableTxnState_serializer(DurableTxnStateEnum::kInProgress)));
auto cursor = client.query(NamespaceString::kSessionTransactionsTableNamespace, query);
if (cursor->more()) {
- LOG(3) << "Aborting in-progress transactions on stepup.";
+ LOGV2_DEBUG(21977, 3, "Aborting in-progress transactions on stepup.");
}
while (cursor->more()) {
auto txnRecord = SessionTxnRecord::parse(
@@ -205,8 +206,12 @@ void abortInProgressTransactions(OperationContext* opCtx) {
opCtx->setInMultiDocumentTransaction();
MongoDOperationContextSessionWithoutRefresh ocs(opCtx);
auto txnParticipant = TransactionParticipant::get(opCtx);
- LOG(3) << "Aborting transaction sessionId: " << txnRecord.getSessionId().toBSON()
- << " txnNumber " << txnRecord.getTxnNum();
+ LOGV2_DEBUG(21978,
+ 3,
+ "Aborting transaction sessionId: {txnRecord_getSessionId} txnNumber "
+ "{txnRecord_getTxnNum}",
+ "txnRecord_getSessionId"_attr = txnRecord.getSessionId().toBSON(),
+ "txnRecord_getTxnNum"_attr = txnRecord.getTxnNum());
txnParticipant.abortTransaction(opCtx);
}
}
@@ -248,8 +253,13 @@ void MongoDSessionCatalog::onStepUp(OperationContext* opCtx) {
newOpCtx->setLogicalSessionId(sessionId);
MongoDOperationContextSession ocs(newOpCtx.get());
auto txnParticipant = TransactionParticipant::get(newOpCtx.get());
- LOG(3) << "Restoring locks of prepared transaction. SessionId: " << sessionId.getId()
- << " TxnNumber: " << txnParticipant.getActiveTxnNumber();
+ LOGV2_DEBUG(21979,
+ 3,
+ "Restoring locks of prepared transaction. SessionId: {sessionId_getId} "
+ "TxnNumber: {txnParticipant_getActiveTxnNumber}",
+ "sessionId_getId"_attr = sessionId.getId(),
+ "txnParticipant_getActiveTxnNumber"_attr =
+ txnParticipant.getActiveTxnNumber());
txnParticipant.refreshLocksForPreparedTransaction(newOpCtx.get(), false);
}
}
diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp
index 892686fb26b..4faa2afdcef 100644
--- a/src/mongo/db/sessions_collection_config_server.cpp
+++ b/src/mongo/db/sessions_collection_config_server.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/logical_session_id.h"
#include "mongo/db/operation_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_commands_helpers.h"
@@ -98,8 +99,12 @@ void SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext*
BSONObj() /* collation */);
return;
} catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) {
- log() << "Attempt " << tries << " to generate TTL index for " << nss
- << " received StaleShardVersion error" << causedBy(ex);
+ LOGV2(21980,
+ "Attempt {tries} to generate TTL index for {nss} received StaleShardVersion "
+ "error{causedBy_ex}",
+ "tries"_attr = tries,
+ "nss"_attr = nss,
+ "causedBy_ex"_attr = causedBy(ex));
if (canRetry) {
continue;
}
diff --git a/src/mongo/db/sorter/sorter_test.cpp b/src/mongo/db/sorter/sorter_test.cpp
index e8c534db10e..ebfd7cf605e 100644
--- a/src/mongo/db/sorter/sorter_test.cpp
+++ b/src/mongo/db/sorter/sorter_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/db/sorter/sorter.h"
@@ -44,6 +46,8 @@
#include "mongo/unittest/unittest.h"
#include "mongo/util/str.h"
+#include "mongo/logv2/log.h"
+#include "mongo/util/log.h"
#include <memory>
namespace mongo {
@@ -204,8 +208,10 @@ void _assertIteratorsEquivalent(It1 it1, It2 it2, int line) {
it1->closeSource();
it2->closeSource();
} catch (...) {
- mongo::unittest::log() << "Failure from line " << line << " on iteration " << iteration
- << std::endl;
+ LOGV2(22047,
+ "Failure from line {line} on iteration {iteration}",
+ "line"_attr = line,
+ "iteration"_attr = iteration);
it1->closeSource();
it2->closeSource();
throw;
diff --git a/src/mongo/db/startup_warnings_common.cpp b/src/mongo/db/startup_warnings_common.cpp
index 099df94ceac..e04df02e5b2 100644
--- a/src/mongo/db/startup_warnings_common.cpp
+++ b/src/mongo/db/startup_warnings_common.cpp
@@ -39,6 +39,7 @@
#include "mongo/client/authenticate.h"
#include "mongo/config.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/util/processinfo.h"
@@ -56,46 +57,61 @@ void logCommonStartupWarnings(const ServerGlobalParams& serverParams) {
{
auto&& vii = VersionInfoInterface::instance();
if ((vii.minorVersion() % 2) != 0) {
- log() << startupWarningsLog;
- log() << "** NOTE: This is a development version (" << vii.version() << ") of MongoDB."
- << startupWarningsLog;
- log() << "** Not recommended for production." << startupWarningsLog;
+ LOGV2_OPTIONS(22116, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22117,
+ {logv2::LogTag::kStartupWarnings},
+ "** NOTE: This is a development version ({vii_version}) of MongoDB.",
+ "vii_version"_attr = vii.version());
+ LOGV2_OPTIONS(22118,
+ {logv2::LogTag::kStartupWarnings},
+ "** Not recommended for production.");
warned = true;
}
}
if (serverParams.authState == ServerGlobalParams::AuthState::kUndefined) {
- log() << startupWarningsLog;
- log() << "** WARNING: Access control is not enabled for the database."
- << startupWarningsLog;
- log() << "** Read and write access to data and configuration is "
- "unrestricted."
- << startupWarningsLog;
+ LOGV2_OPTIONS(22119, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22120,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: Access control is not enabled for the database.");
+ LOGV2_OPTIONS(22121,
+ {logv2::LogTag::kStartupWarnings},
+ "** Read and write access to data and configuration is "
+ "unrestricted.");
warned = true;
}
const bool is32bit = sizeof(int*) == 4;
if (is32bit) {
- log() << startupWarningsLog;
- log() << "** WARNING: This 32-bit MongoDB binary is deprecated" << startupWarningsLog;
+ LOGV2_OPTIONS(22122, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22123,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: This 32-bit MongoDB binary is deprecated");
warned = true;
}
#ifdef MONGO_CONFIG_SSL
if (sslGlobalParams.sslAllowInvalidCertificates) {
- log() << "** WARNING: While invalid X509 certificates may be used to" << startupWarningsLog;
- log() << "** connect to this server, they will not be considered"
- << startupWarningsLog;
- log() << "** permissible for authentication." << startupWarningsLog;
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(22124,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: While invalid X509 certificates may be used to");
+ LOGV2_OPTIONS(22125,
+ {logv2::LogTag::kStartupWarnings},
+ "** connect to this server, they will not be considered");
+ LOGV2_OPTIONS(22126,
+ {logv2::LogTag::kStartupWarnings},
+ "** permissible for authentication.");
+ LOGV2_OPTIONS(22127, {logv2::LogTag::kStartupWarnings}, "");
}
if (sslGlobalParams.sslAllowInvalidHostnames) {
- log() << "** WARNING: This server will not perform X.509 hostname validation"
- << startupWarningsLog;
- log() << "** This may allow your server to make or accept connections to"
- << startupWarningsLog;
- log() << "** untrusted parties" << startupWarningsLog;
+ LOGV2_OPTIONS(22128,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: This server will not perform X.509 hostname validation");
+ LOGV2_OPTIONS(22129,
+ {logv2::LogTag::kStartupWarnings},
+ "** This may allow your server to make or accept connections to");
+ LOGV2_OPTIONS(22130, {logv2::LogTag::kStartupWarnings}, "** untrusted parties");
}
#endif
@@ -108,13 +124,14 @@ void logCommonStartupWarnings(const ServerGlobalParams& serverParams) {
sslGlobalParams.sslCertificateSelector.empty() &&
#endif
sslGlobalParams.sslCAFile.empty()) {
- log() << "";
- log() << "** WARNING: No client certificate validation can be performed since"
- " no CA file has been provided";
+ LOGV2(22131, "");
+ LOGV2(22132,
+ "** WARNING: No client certificate validation can be performed since"
+ " no CA file has been provided");
#ifdef MONGO_CONFIG_SSL_CERTIFICATE_SELECTORS
- log() << "** and no sslCertificateSelector has been specified.";
+ LOGV2(22133, "** and no sslCertificateSelector has been specified.");
#endif
- log() << "** Please specify an sslCAFile parameter.";
+ LOGV2(22134, "** Please specify an sslCAFile parameter.");
}
#if defined(_WIN32) && !defined(_WIN64)
@@ -122,50 +139,68 @@ void logCommonStartupWarnings(const ServerGlobalParams& serverParams) {
BOOL wow64Process;
BOOL retWow64 = IsWow64Process(GetCurrentProcess(), &wow64Process);
if (retWow64 && wow64Process) {
- log() << "** NOTE: This is a 32-bit MongoDB binary running on a 64-bit operating"
- << startupWarningsLog;
- log() << "** system. Switch to a 64-bit build of MongoDB to" << startupWarningsLog;
- log() << "** support larger databases." << startupWarningsLog;
+ LOGV2_OPTIONS(22135,
+ {logv2::LogTag::kStartupWarnings},
+ "** NOTE: This is a 32-bit MongoDB binary running on a 64-bit operating");
+ LOGV2_OPTIONS(22136,
+ {logv2::LogTag::kStartupWarnings},
+ "** system. Switch to a 64-bit build of MongoDB to");
+ LOGV2_OPTIONS(
+ 22137, {logv2::LogTag::kStartupWarnings}, "** support larger databases.");
warned = true;
}
#endif
#if !defined(_WIN32)
if (getuid() == 0) {
- log() << "** WARNING: You are running this process as the root user, "
- << "which is not recommended." << startupWarningsLog;
+ LOGV2_OPTIONS(
+ 22138,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: You are running this process as the root user, which is not recommended.");
warned = true;
}
#endif
if (serverParams.bind_ips.empty()) {
- log() << startupWarningsLog;
- log() << "** WARNING: This server is bound to localhost." << startupWarningsLog;
- log() << "** Remote systems will be unable to connect to this server. "
- << startupWarningsLog;
- log() << "** Start the server with --bind_ip <address> to specify which IP "
- << startupWarningsLog;
- log() << "** addresses it should serve responses from, or with --bind_ip_all to"
- << startupWarningsLog;
- log() << "** bind to all interfaces. If this behavior is desired, start the"
- << startupWarningsLog;
- log() << "** server with --bind_ip 127.0.0.1 to disable this warning."
- << startupWarningsLog;
+ LOGV2_OPTIONS(22139, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22140,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: This server is bound to localhost.");
+ LOGV2_OPTIONS(22141,
+ {logv2::LogTag::kStartupWarnings},
+ "** Remote systems will be unable to connect to this server. ");
+ LOGV2_OPTIONS(22142,
+ {logv2::LogTag::kStartupWarnings},
+ "** Start the server with --bind_ip <address> to specify which IP ");
+ LOGV2_OPTIONS(
+ 22143,
+ {logv2::LogTag::kStartupWarnings},
+ "** addresses it should serve responses from, or with --bind_ip_all to");
+ LOGV2_OPTIONS(22144,
+ {logv2::LogTag::kStartupWarnings},
+ "** bind to all interfaces. If this behavior is desired, start the");
+ LOGV2_OPTIONS(22145,
+ {logv2::LogTag::kStartupWarnings},
+ "** server with --bind_ip 127.0.0.1 to disable this warning.");
warned = true;
}
if (auth::hasMultipleInternalAuthKeys()) {
- log() << startupWarningsLog;
- log() << "** WARNING: Multiple keys specified in security key file. If cluster key file"
- << startupWarningsLog;
- log() << " rollover is not in progress, only one key should be specified in"
- << startupWarningsLog;
- log() << " the key file" << startupWarningsLog;
+ LOGV2_OPTIONS(22146, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 22147,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: Multiple keys specified in security key file. If cluster key file");
+ LOGV2_OPTIONS(
+ 22148,
+ {logv2::LogTag::kStartupWarnings},
+ " rollover is not in progress, only one key should be specified in");
+ LOGV2_OPTIONS(22149, {logv2::LogTag::kStartupWarnings}, " the key file");
warned = true;
}
if (warned) {
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(22150, {logv2::LogTag::kStartupWarnings}, "");
}
}
} // namespace mongo
diff --git a/src/mongo/db/startup_warnings_mongod.cpp b/src/mongo/db/startup_warnings_mongod.cpp
index 29a452f687e..b7b8e5fc067 100644
--- a/src/mongo/db/startup_warnings_mongod.cpp
+++ b/src/mongo/db/startup_warnings_mongod.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/startup_warnings_common.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/processinfo.h"
#include "mongo/util/str.h"
@@ -141,32 +142,46 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
bool warned = false;
if (sizeof(int*) == 4) {
- log() << startupWarningsLog;
- log() << "** NOTE: This is a 32 bit MongoDB binary." << startupWarningsLog;
- log() << "** 32 bit builds are limited to less than 2GB of data "
- << "(or less with --journal)." << startupWarningsLog;
+ LOGV2_OPTIONS(22151, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 22152, {logv2::LogTag::kStartupWarnings}, "** NOTE: This is a 32 bit MongoDB binary.");
+ LOGV2_OPTIONS(22153,
+ {logv2::LogTag::kStartupWarnings},
+ "** 32 bit builds are limited to less than 2GB of data (or less with "
+ "--journal).");
if (!storageParams.dur) {
- log() << "** Note that journaling defaults to off for 32 bit "
- << "and is currently off." << startupWarningsLog;
+ LOGV2_OPTIONS(
+ 22154,
+ {logv2::LogTag::kStartupWarnings},
+ "** Note that journaling defaults to off for 32 bit and is currently off.");
}
- log() << "** See http://dochub.mongodb.org/core/32bit" << startupWarningsLog;
+ LOGV2_OPTIONS(22155,
+ {logv2::LogTag::kStartupWarnings},
+ "** See http://dochub.mongodb.org/core/32bit");
warned = true;
}
if (!ProcessInfo::blockCheckSupported()) {
- log() << startupWarningsLog;
- log() << "** NOTE: your operating system version does not support the method that "
- << "MongoDB" << startupWarningsLog;
- log() << "** uses to detect impending page faults." << startupWarningsLog;
- log() << "** This may result in slower performance for certain use "
- << "cases" << startupWarningsLog;
+ LOGV2_OPTIONS(22156, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 22157,
+ {logv2::LogTag::kStartupWarnings},
+ "** NOTE: your operating system version does not support the method that MongoDB");
+ LOGV2_OPTIONS(22158,
+ {logv2::LogTag::kStartupWarnings},
+ "** uses to detect impending page faults.");
+ LOGV2_OPTIONS(22159,
+ {logv2::LogTag::kStartupWarnings},
+ "** This may result in slower performance for certain use cases");
warned = true;
}
#ifdef __linux__
if (boost::filesystem::exists("/proc/vz") && !boost::filesystem::exists("/proc/bc")) {
- log() << startupWarningsLog;
- log() << "** WARNING: You are running in OpenVZ which can cause issues on versions "
- << "of RHEL older than RHEL6." << startupWarningsLog;
+ LOGV2_OPTIONS(22160, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22161,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: You are running in OpenVZ which can cause issues on versions of "
+ "RHEL older than RHEL6.");
warned = true;
}
@@ -174,10 +189,13 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
try {
hasMultipleNumaNodes = boost::filesystem::exists("/sys/devices/system/node/node1");
} catch (boost::filesystem::filesystem_error& e) {
- log() << startupWarningsLog;
- log() << "** WARNING: Cannot detect if NUMA interleaving is enabled. "
- << "Failed to probe \"" << e.path1().string() << "\": " << e.code().message()
- << startupWarningsLog;
+ LOGV2_OPTIONS(22162, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22163,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: Cannot detect if NUMA interleaving is enabled. Failed to probe "
+ "\"{e_path1_string}\": {e_code_message}",
+ "e_path1_string"_attr = e.path1().string(),
+ "e_code_message"_attr = e.code().message());
}
if (hasMultipleNumaNodes) {
// We are on a box with a NUMA enabled kernel and more than 1 numa node (they start at
@@ -197,27 +215,38 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
std::string line; // we only need the first line
std::getline(f, line);
if (f.fail()) {
- warning() << "failed to read from /proc/self/numa_maps: " << errnoWithDescription()
- << startupWarningsLog;
+ LOGV2_WARNING_OPTIONS(
+ 22200,
+ {logv2::LogTag::kStartupWarnings},
+ "failed to read from /proc/self/numa_maps: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
warned = true;
} else {
// skip over pointer
std::string::size_type where = line.find(' ');
if ((where == std::string::npos) || (++where == line.size())) {
- log() << startupWarningsLog;
- log() << "** WARNING: cannot parse numa_maps line: '" << line << "'"
- << startupWarningsLog;
+ LOGV2_OPTIONS(22164, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22165,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: cannot parse numa_maps line: '{line}'",
+ "line"_attr = line);
warned = true;
}
// if the text following the space doesn't begin with 'interleave', then
// issue the warning.
else if (line.find("interleave", where) != where) {
- log() << startupWarningsLog;
- log() << "** WARNING: You are running on a NUMA machine." << startupWarningsLog;
- log() << "** We suggest launching mongod like this to avoid "
- << "performance problems:" << startupWarningsLog;
- log() << "** numactl --interleave=all mongod [other options]"
- << startupWarningsLog;
+ LOGV2_OPTIONS(22166, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22167,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: You are running on a NUMA machine.");
+ LOGV2_OPTIONS(22168,
+ {logv2::LogTag::kStartupWarnings},
+ "** We suggest launching mongod like this to avoid "
+ "performance problems:");
+ LOGV2_OPTIONS(
+ 22169,
+ {logv2::LogTag::kStartupWarnings},
+ "** numactl --interleave=all mongod [other options]");
warned = true;
}
}
@@ -230,10 +259,14 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
f >> val;
if (val == 2) {
- log() << startupWarningsLog;
- log() << "** WARNING: /proc/sys/vm/overcommit_memory is " << val << startupWarningsLog;
- log() << "** Journaling works best with it set to 0 or 1"
- << startupWarningsLog;
+ LOGV2_OPTIONS(22170, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22171,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: /proc/sys/vm/overcommit_memory is {val}",
+ "val"_attr = val);
+ LOGV2_OPTIONS(22172,
+ {logv2::LogTag::kStartupWarnings},
+ "** Journaling works best with it set to 0 or 1");
}
}
@@ -243,11 +276,16 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
f >> val;
if (val != 0) {
- log() << startupWarningsLog;
- log() << "** WARNING: /proc/sys/vm/zone_reclaim_mode is " << val << startupWarningsLog;
- log() << "** We suggest setting it to 0" << startupWarningsLog;
- log() << "** http://www.kernel.org/doc/Documentation/sysctl/vm.txt"
- << startupWarningsLog;
+ LOGV2_OPTIONS(22173, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22174,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: /proc/sys/vm/zone_reclaim_mode is {val}",
+ "val"_attr = val);
+ LOGV2_OPTIONS(
+ 22175, {logv2::LogTag::kStartupWarnings}, "** We suggest setting it to 0");
+ LOGV2_OPTIONS(22176,
+ {logv2::LogTag::kStartupWarnings},
+ "** http://www.kernel.org/doc/Documentation/sysctl/vm.txt");
}
}
@@ -260,16 +298,24 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
// If we do not have hugepages enabled, we don't need to warn about its features
shouldWarnAboutDefragAlways = true;
- log() << startupWarningsLog;
- log() << "** WARNING: " << kTransparentHugePagesDirectory << "/enabled is 'always'."
- << startupWarningsLog;
- log() << "** We suggest setting it to 'never'" << startupWarningsLog;
+ LOGV2_OPTIONS(22177, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22178,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: {kTransparentHugePagesDirectory}/enabled is 'always'.",
+ "kTransparentHugePagesDirectory"_attr = kTransparentHugePagesDirectory);
+ LOGV2_OPTIONS(22179,
+ {logv2::LogTag::kStartupWarnings},
+ "** We suggest setting it to 'never'");
warned = true;
}
} else if (transparentHugePagesEnabledResult.getStatus().code() !=
ErrorCodes::NonExistentPath) {
- warning() << startupWarningsLog;
- warning() << transparentHugePagesEnabledResult.getStatus().reason() << startupWarningsLog;
+ LOGV2_WARNING_OPTIONS(22201, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_WARNING_OPTIONS(22202,
+ {logv2::LogTag::kStartupWarnings},
+ "{transparentHugePagesEnabledResult_getStatus_reason}",
+ "transparentHugePagesEnabledResult_getStatus_reason"_attr =
+ transparentHugePagesEnabledResult.getStatus().reason());
warned = true;
}
@@ -278,15 +324,23 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
if (transparentHugePagesDefragResult.isOK()) {
if (shouldWarnAboutDefragAlways &&
transparentHugePagesDefragResult.getValue() == "always") {
- log() << startupWarningsLog;
- log() << "** WARNING: " << kTransparentHugePagesDirectory << "/defrag is 'always'."
- << startupWarningsLog;
- log() << "** We suggest setting it to 'never'" << startupWarningsLog;
+ LOGV2_OPTIONS(22180, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22181,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: {kTransparentHugePagesDirectory}/defrag is 'always'.",
+ "kTransparentHugePagesDirectory"_attr = kTransparentHugePagesDirectory);
+ LOGV2_OPTIONS(22182,
+ {logv2::LogTag::kStartupWarnings},
+ "** We suggest setting it to 'never'");
warned = true;
}
} else if (transparentHugePagesDefragResult.getStatus().code() != ErrorCodes::NonExistentPath) {
- warning() << startupWarningsLog;
- warning() << transparentHugePagesDefragResult.getStatus().reason() << startupWarningsLog;
+ LOGV2_WARNING_OPTIONS(22203, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_WARNING_OPTIONS(22204,
+ {logv2::LogTag::kStartupWarnings},
+ "{transparentHugePagesDefragResult_getStatus_reason}",
+ "transparentHugePagesDefragResult_getStatus_reason"_attr =
+ transparentHugePagesDefragResult.getStatus().reason());
warned = true;
}
#endif // __linux__
@@ -298,14 +352,21 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
if (!getrlimit(RLIMIT_NOFILE, &rlnofile)) {
if (rlnofile.rlim_cur < minNumFiles) {
- log() << startupWarningsLog;
- log() << "** WARNING: soft rlimits too low. Number of files is " << rlnofile.rlim_cur
- << ", should be at least " << minNumFiles << startupWarningsLog;
+ LOGV2_OPTIONS(22183, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22184,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: soft rlimits too low. Number of files is "
+ "{rlnofile_rlim_cur}, should be at least {minNumFiles}",
+ "rlnofile_rlim_cur"_attr = rlnofile.rlim_cur,
+ "minNumFiles"_attr = minNumFiles);
}
} else {
const auto errmsg = errnoWithDescription();
- log() << startupWarningsLog;
- log() << "** WARNING: getrlimit failed. " << errmsg << startupWarningsLog;
+ LOGV2_OPTIONS(22185, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22186,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: getrlimit failed. {errmsg}",
+ "errmsg"_attr = errmsg);
}
// Solaris does not have RLIMIT_MEMLOCK, these are exposed via getrctl(2) instead
@@ -317,15 +378,23 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
if (!getrlimit(RLIMIT_MEMLOCK, &rlmemlock)) {
if ((rlmemlock.rlim_cur / ProcessInfo::getPageSize()) < minLockedPages) {
- log() << startupWarningsLog;
- log() << "** WARNING: soft rlimits too low. The locked memory size is "
- << rlmemlock.rlim_cur << " bytes, it should be at least "
- << minLockedPages * ProcessInfo::getPageSize() << " bytes" << startupWarningsLog;
+ LOGV2_OPTIONS(22187, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 22188,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: soft rlimits too low. The locked memory size is {rlmemlock_rlim_cur} "
+ "bytes, it should be at least {minLockedPages_ProcessInfo_getPageSize} bytes",
+ "rlmemlock_rlim_cur"_attr = rlmemlock.rlim_cur,
+ "minLockedPages_ProcessInfo_getPageSize"_attr =
+ minLockedPages * ProcessInfo::getPageSize());
}
} else {
const auto errmsg = errnoWithDescription();
- log() << startupWarningsLog;
- log() << "** WARNING: getrlimit failed. " << errmsg << startupWarningsLog;
+ LOGV2_OPTIONS(22189, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22190,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: getrlimit failed. {errmsg}",
+ "errmsg"_attr = errmsg);
}
#endif
#endif
@@ -334,28 +403,36 @@ void logMongodStartupWarnings(const StorageGlobalParams& storageParams,
ProcessInfo p;
if (p.hasNumaEnabled()) {
- log() << startupWarningsLog;
- log() << "** WARNING: You are running on a NUMA machine." << startupWarningsLog;
- log() << "** We suggest disabling NUMA in the machine BIOS " << startupWarningsLog;
- log() << "** by enabling interleaving to avoid performance problems. "
- << startupWarningsLog;
- log() << "** See your BIOS documentation for more information."
- << startupWarningsLog;
+ LOGV2_OPTIONS(22191, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22192,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: You are running on a NUMA machine.");
+ LOGV2_OPTIONS(22193,
+ {logv2::LogTag::kStartupWarnings},
+ "** We suggest disabling NUMA in the machine BIOS ");
+ LOGV2_OPTIONS(22194,
+ {logv2::LogTag::kStartupWarnings},
+ "** by enabling interleaving to avoid performance problems. ");
+ LOGV2_OPTIONS(22195,
+ {logv2::LogTag::kStartupWarnings},
+ "** See your BIOS documentation for more information.");
warned = true;
}
#endif // #ifdef _WIN32
if (storageParams.engine == "ephemeralForTest") {
- log() << startupWarningsLog;
- log() << "** NOTE: The ephemeralForTest storage engine is for testing only. "
- << startupWarningsLog;
- log() << "** Do not use in production." << startupWarningsLog;
+ LOGV2_OPTIONS(22196, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22197,
+ {logv2::LogTag::kStartupWarnings},
+ "** NOTE: The ephemeralForTest storage engine is for testing only. ");
+ LOGV2_OPTIONS(
+ 22198, {logv2::LogTag::kStartupWarnings}, "** Do not use in production.");
warned = true;
}
if (warned) {
- log() << startupWarningsLog;
+ LOGV2_OPTIONS(22199, {logv2::LogTag::kStartupWarnings}, "");
}
}
} // namespace mongo
diff --git a/src/mongo/db/stats/counters.cpp b/src/mongo/db/stats/counters.cpp
index 8e4458db7a7..0e5d0595dcd 100644
--- a/src/mongo/db/stats/counters.cpp
+++ b/src/mongo/db/stats/counters.cpp
@@ -35,6 +35,7 @@
#include "mongo/client/authenticate.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -63,7 +64,7 @@ void OpCounters::gotOp(int op, bool isCommand) {
case opReply:
break;
default:
- log() << "OpCounters::gotOp unknown op: " << op << std::endl;
+ LOGV2(22205, "OpCounters::gotOp unknown op: {op}", "op"_attr = op);
}
}
diff --git a/src/mongo/db/storage/durable_catalog_impl.cpp b/src/mongo/db/storage/durable_catalog_impl.cpp
index c6ed7ee93a5..a4f8c2f4681 100644
--- a/src/mongo/db/storage/durable_catalog_impl.cpp
+++ b/src/mongo/db/storage/durable_catalog_impl.cpp
@@ -49,6 +49,7 @@
#include "mongo/db/storage/record_store.h"
#include "mongo/db/storage/recovery_unit.h"
#include "mongo/db/storage/storage_engine_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/bits.h"
#include "mongo/platform/random.h"
#include "mongo/util/log.h"
@@ -219,9 +220,14 @@ public:
// Intentionally ignoring failure here. Since we've removed the metadata pointing to the
// index, we should never see it again anyway.
if (_engine->getStorageEngine()->supportsPendingDrops() && commitTimestamp) {
- log() << "Deferring table drop for index '" << _indexName << "' on collection '"
- << _indexNss << (_uuid ? " (" + _uuid->toString() + ")'" : "") << ". Ident: '"
- << _ident << "', commit timestamp: '" << commitTimestamp << "'";
+ LOGV2(22206,
+ "Deferring table drop for index '{indexName}' on collection "
+ "'{indexNss}{uuid_uuid}. Ident: '{ident}', commit timestamp: '{commitTimestamp}'",
+ "indexName"_attr = _indexName,
+ "indexNss"_attr = _indexNss,
+ "uuid_uuid"_attr = (_uuid ? " (" + _uuid->toString() + ")'" : ""),
+ "ident"_attr = _ident,
+ "commitTimestamp"_attr = commitTimestamp);
_engine->addDropPendingIdent(*commitTimestamp, _indexNss, _ident);
} else {
auto kvEngine = _engine->getEngine();
@@ -345,7 +351,9 @@ DurableCatalogImpl::FeatureTracker::FeatureBits DurableCatalogImpl::FeatureTrack
auto nonRepairableFeaturesStatus = bsonExtractTypedField(
obj, kNonRepairableFeaturesFieldName, BSONType::NumberLong, &nonRepairableFeaturesElem);
if (!nonRepairableFeaturesStatus.isOK()) {
- error() << "error: exception extracting typed field with obj:" << redact(obj);
+ LOGV2_ERROR(22215,
+ "error: exception extracting typed field with obj:{obj}",
+ "obj"_attr = redact(obj));
fassert(40111, nonRepairableFeaturesStatus);
}
@@ -353,7 +361,9 @@ DurableCatalogImpl::FeatureTracker::FeatureBits DurableCatalogImpl::FeatureTrack
auto repairableFeaturesStatus = bsonExtractTypedField(
obj, kRepairableFeaturesFieldName, BSONType::NumberLong, &repairableFeaturesElem);
if (!repairableFeaturesStatus.isOK()) {
- error() << "error: exception extracting typed field with obj:" << redact(obj);
+ LOGV2_ERROR(22216,
+ "error: exception extracting typed field with obj:{obj}",
+ "obj"_attr = redact(obj));
fassert(40112, repairableFeaturesStatus);
}
@@ -539,7 +549,11 @@ StatusWith<DurableCatalog::Entry> DurableCatalogImpl::_addEntry(OperationContext
_catalogIdToEntryMap[res.getValue()] = {res.getValue(), ident, nss};
opCtx->recoveryUnit()->registerChange(std::make_unique<AddIdentChange>(this, res.getValue()));
- LOG(1) << "stored meta data for " << nss.ns() << " @ " << res.getValue();
+ LOGV2_DEBUG(22207,
+ 1,
+ "stored meta data for {nss_ns} @ {res_getValue}",
+ "nss_ns"_attr = nss.ns(),
+ "res_getValue"_attr = res.getValue());
return {{res.getValue(), ident, nss}};
}
@@ -552,7 +566,7 @@ std::string DurableCatalogImpl::getIndexIdent(OperationContext* opCtx,
}
BSONObj DurableCatalogImpl::_findEntry(OperationContext* opCtx, RecordId catalogId) const {
- LOG(3) << "looking up metadata for: " << catalogId;
+ LOGV2_DEBUG(22208, 3, "looking up metadata for: {catalogId}", "catalogId"_attr = catalogId);
RecordData data;
if (!_rs->findRecord(opCtx, catalogId, &data)) {
// since the in memory meta data isn't managed with mvcc
@@ -567,11 +581,11 @@ BSONObj DurableCatalogImpl::_findEntry(OperationContext* opCtx, RecordId catalog
BSONCollectionCatalogEntry::MetaData DurableCatalogImpl::getMetaData(OperationContext* opCtx,
RecordId catalogId) const {
BSONObj obj = _findEntry(opCtx, catalogId);
- LOG(3) << " fetched CCE metadata: " << obj;
+ LOGV2_DEBUG(22209, 3, " fetched CCE metadata: {obj}", "obj"_attr = obj);
BSONCollectionCatalogEntry::MetaData md;
const BSONElement mdElement = obj["md"];
if (mdElement.isABSONObj()) {
- LOG(3) << "returning metadata: " << mdElement;
+ LOGV2_DEBUG(22210, 3, "returning metadata: {mdElement}", "mdElement"_attr = mdElement);
md.parse(mdElement.Obj());
}
return md;
@@ -632,7 +646,7 @@ void DurableCatalogImpl::putMetaData(OperationContext* opCtx,
opCtx->recoveryUnit()->setMustBeTimestamped();
}
- LOG(3) << "recording new metadata: " << obj;
+ LOGV2_DEBUG(22211, 3, "recording new metadata: {obj}", "obj"_attr = obj);
Status status = _rs->updateRecord(opCtx, catalogId, obj.objdata(), obj.objsize());
fassert(28521, status);
}
@@ -693,7 +707,11 @@ Status DurableCatalogImpl::_removeEntry(OperationContext* opCtx, RecordId catalo
opCtx->recoveryUnit()->registerChange(
std::make_unique<RemoveIdentChange>(this, catalogId, it->second));
- LOG(1) << "deleting metadata for " << it->second.nss << " @ " << catalogId;
+ LOGV2_DEBUG(22212,
+ 1,
+ "deleting metadata for {it_second_nss} @ {catalogId}",
+ "it_second_nss"_attr = it->second.nss,
+ "catalogId"_attr = catalogId);
_rs->deleteRecord(opCtx, catalogId);
_catalogIdToEntryMap.erase(it);
@@ -781,7 +799,11 @@ StatusWith<std::string> DurableCatalogImpl::newOrphanedIdent(OperationContext* o
_catalogIdToEntryMap[res.getValue()] = Entry(res.getValue(), ident, ns);
opCtx->recoveryUnit()->registerChange(std::make_unique<AddIdentChange>(this, res.getValue()));
- LOG(1) << "stored meta data for orphaned collection " << ns << " @ " << res.getValue();
+ LOGV2_DEBUG(22213,
+ 1,
+ "stored meta data for orphaned collection {ns} @ {res_getValue}",
+ "ns"_attr = ns,
+ "res_getValue"_attr = res.getValue());
return {ns.ns()};
}
@@ -871,8 +893,12 @@ Status DurableCatalogImpl::dropCollection(OperationContext* opCtx, RecordId cata
StorageEngineInterface* engine = catalog->_engine;
auto storageEngine = engine->getStorageEngine();
if (storageEngine->supportsPendingDrops() && commitTimestamp) {
- log() << "Deferring table drop for collection '" << entry.nss
- << "'. Ident: " << entry.ident << ", commit timestamp: " << commitTimestamp;
+ LOGV2(22214,
+ "Deferring table drop for collection '{entry_nss}'. Ident: {entry_ident}, "
+ "commit timestamp: {commitTimestamp}",
+ "entry_nss"_attr = entry.nss,
+ "entry_ident"_attr = entry.ident,
+ "commitTimestamp"_attr = commitTimestamp);
engine->addDropPendingIdent(*commitTimestamp, entry.nss, entry.ident);
} else {
// Intentionally ignoring failure here. Since we've removed the metadata pointing to
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp
index a390b43664e..05f665e90de 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h"
#include "mongo/db/storage/sorted_data_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -78,7 +79,10 @@ void EphemeralForTestRecoveryUnit::doAbortUnitOfWork() {
for (Changes::reverse_iterator it = _changes.rbegin(), end = _changes.rend(); it != end;
++it) {
auto change = *it;
- LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*change));
+ LOGV2_DEBUG(22217,
+ 2,
+ "CUSTOM ROLLBACK {demangleName_typeid_change}",
+ "demangleName_typeid_change"_attr = demangleName(typeid(*change)));
change->rollback();
}
_changes.clear();
diff --git a/src/mongo/db/storage/flow_control.cpp b/src/mongo/db/storage/flow_control.cpp
index 0552357f45c..4e0c957fda6 100644
--- a/src/mongo/db/storage/flow_control.cpp
+++ b/src/mongo/db/storage/flow_control.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/server_options.h"
#include "mongo/db/storage/flow_control_parameters_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/background.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -103,8 +104,11 @@ Timestamp getMedianAppliedTimestamp(const std::vector<repl::MemberData>& sortedM
bool sustainerAdvanced(const std::vector<repl::MemberData>& prevMemberData,
const std::vector<repl::MemberData>& currMemberData) {
if (currMemberData.size() == 0 || currMemberData.size() != prevMemberData.size()) {
- warning() << "Flow control detected a change in topology. PrevMemberSize: "
- << prevMemberData.size() << " CurrMemberSize: " << currMemberData.size();
+ LOGV2_WARNING(22223,
+ "Flow control detected a change in topology. PrevMemberSize: "
+ "{prevMemberData_size} CurrMemberSize: {currMemberData_size}",
+ "prevMemberData_size"_attr = prevMemberData.size(),
+ "currMemberData_size"_attr = currMemberData.size());
return false;
}
@@ -112,8 +116,11 @@ bool sustainerAdvanced(const std::vector<repl::MemberData>& prevMemberData,
auto prevSustainerAppliedTs = getMedianAppliedTimestamp(prevMemberData);
if (currSustainerAppliedTs < prevSustainerAppliedTs) {
- warning() << "Flow control's sustainer time decreased. PrevSustainer: "
- << prevSustainerAppliedTs << " CurrSustainer: " << currSustainerAppliedTs;
+ LOGV2_WARNING(22224,
+ "Flow control's sustainer time decreased. PrevSustainer: "
+ "{prevSustainerAppliedTs} CurrSustainer: {currSustainerAppliedTs}",
+ "prevSustainerAppliedTs"_attr = prevSustainerAppliedTs,
+ "currSustainerAppliedTs"_attr = currSustainerAppliedTs);
return false;
}
@@ -240,9 +247,13 @@ int FlowControl::_calculateNewTicketsForLag(const std::vector<repl::MemberData>&
const std::int64_t sustainerAppliedCount =
_approximateOpsBetween(prevSustainerAppliedTs, currSustainerAppliedTs);
- LOG(DEBUG_LOG_LEVEL) << " PrevApplied: " << prevSustainerAppliedTs
- << " CurrApplied: " << currSustainerAppliedTs
- << " NumSustainerApplied: " << sustainerAppliedCount;
+ LOGV2_DEBUG(22218,
+ logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(),
+ " PrevApplied: {prevSustainerAppliedTs} CurrApplied: {currSustainerAppliedTs} "
+ "NumSustainerApplied: {sustainerAppliedCount}",
+ "prevSustainerAppliedTs"_attr = prevSustainerAppliedTs,
+ "currSustainerAppliedTs"_attr = currSustainerAppliedTs,
+ "sustainerAppliedCount"_attr = sustainerAppliedCount);
if (sustainerAppliedCount > 0) {
_lastTimeSustainerAdvanced = Date_t::now();
} else {
@@ -250,8 +261,9 @@ int FlowControl::_calculateNewTicketsForLag(const std::vector<repl::MemberData>&
const auto now = Date_t::now();
if (warnThresholdSeconds > 0 &&
now - _lastTimeSustainerAdvanced >= Seconds(warnThresholdSeconds)) {
- warning() << "Flow control is engaged and the sustainer point is not moving. Please "
- "check the health of all secondaries.";
+ LOGV2_WARNING(22225,
+ "Flow control is engaged and the sustainer point is not moving. Please "
+ "check the health of all secondaries.");
// Log once every `warnThresholdSeconds` seconds.
_lastTimeSustainerAdvanced = now;
@@ -285,9 +297,17 @@ int FlowControl::_calculateNewTicketsForLag(const std::vector<repl::MemberData>&
// an environment where secondaries consistently process operations slower than the primary.
double sustainerAppliedPenalty =
sustainerAppliedCount * reduce * gFlowControlFudgeFactor.load();
- LOG(DEBUG_LOG_LEVEL) << "Sustainer: " << sustainerAppliedCount << " LagMillis: " << lagMillis
- << " Threshold lag: " << thresholdLagMillis << " Exponent: " << exponent
- << " Reduce: " << reduce << " Penalty: " << sustainerAppliedPenalty;
+ LOGV2_DEBUG(22219,
+ logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(),
+ "Sustainer: {sustainerAppliedCount} LagMillis: {lagMillis} Threshold lag: "
+ "{thresholdLagMillis} Exponent: {exponent} Reduce: {reduce} Penalty: "
+ "{sustainerAppliedPenalty}",
+ "sustainerAppliedCount"_attr = sustainerAppliedCount,
+ "lagMillis"_attr = lagMillis,
+ "thresholdLagMillis"_attr = thresholdLagMillis,
+ "exponent"_attr = exponent,
+ "reduce"_attr = reduce,
+ "sustainerAppliedPenalty"_attr = sustainerAppliedPenalty);
return multiplyWithOverflowCheck(locksPerOp, sustainerAppliedPenalty, _kMaxTickets);
}
@@ -375,19 +395,29 @@ int FlowControl::getNumTickets() {
ret = std::max(ret, gFlowControlMinTicketsPerSecond.load());
- LOG(DEBUG_LOG_LEVEL) << "Are lagged? " << (_isLagged.load() ? "true" : "false")
- << " Curr lag millis: "
- << getLagMillis(myLastApplied.wallTime, lastCommitted.wallTime)
- << " OpsLagged: "
- << _approximateOpsBetween(lastCommitted.opTime.getTimestamp(),
- myLastApplied.opTime.getTimestamp())
- << " Granting: " << ret
- << " Last granted: " << _lastTargetTicketsPermitted.load()
- << " Last sustainer applied: " << _lastSustainerAppliedCount.load()
- << " Acquisitions since last check: " << locksUsedLastPeriod
- << " Locks per op: " << _lastLocksPerOp.load()
- << " Count of lagged periods: " << _isLaggedCount.load()
- << " Total duration of lagged periods: " << _isLaggedTimeMicros.load();
+ LOGV2_DEBUG(
+ 22220,
+ logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(),
+ "Are lagged? {isLagged_load_true_false} Curr lag millis: "
+ "{getLagMillis_myLastApplied_wallTime_lastCommitted_wallTime} OpsLagged: "
+ "{approximateOpsBetween_lastCommitted_opTime_getTimestamp_myLastApplied_opTime_"
+ "getTimestamp} Granting: {ret} Last granted: {lastTargetTicketsPermitted_load} Last "
+ "sustainer applied: {lastSustainerAppliedCount_load} Acquisitions since last check: "
+ "{locksUsedLastPeriod} Locks per op: {lastLocksPerOp_load} Count of lagged periods: "
+ "{isLaggedCount_load} Total duration of lagged periods: {isLaggedTimeMicros_load}",
+ "isLagged_load_true_false"_attr = (_isLagged.load() ? "true" : "false"),
+ "getLagMillis_myLastApplied_wallTime_lastCommitted_wallTime"_attr =
+ getLagMillis(myLastApplied.wallTime, lastCommitted.wallTime),
+ "approximateOpsBetween_lastCommitted_opTime_getTimestamp_myLastApplied_opTime_getTimestamp"_attr =
+ _approximateOpsBetween(lastCommitted.opTime.getTimestamp(),
+ myLastApplied.opTime.getTimestamp()),
+ "ret"_attr = ret,
+ "lastTargetTicketsPermitted_load"_attr = _lastTargetTicketsPermitted.load(),
+ "lastSustainerAppliedCount_load"_attr = _lastSustainerAppliedCount.load(),
+ "locksUsedLastPeriod"_attr = locksUsedLastPeriod,
+ "lastLocksPerOp_load"_attr = _lastLocksPerOp.load(),
+ "isLaggedCount_load"_attr = _isLaggedCount.load(),
+ "isLaggedTimeMicros_load"_attr = _isLaggedTimeMicros.load());
_lastTargetTicketsPermitted.store(ret);
@@ -449,8 +479,13 @@ void FlowControl::sample(Timestamp timestamp, std::uint64_t opsApplied) {
_lastSample = _numOpsSinceStartup;
const auto lockAcquisitions = stats.get(resourceIdGlobal, LockMode::MODE_IX).numAcquisitions;
- LOG(DEBUG_LOG_LEVEL) << "Sampling. Time: " << timestamp << " Applied: " << _numOpsSinceStartup
- << " LockAcquisitions: " << lockAcquisitions;
+ LOGV2_DEBUG(22221,
+ logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(),
+ "Sampling. Time: {timestamp} Applied: {numOpsSinceStartup} LockAcquisitions: "
+ "{lockAcquisitions}",
+ "timestamp"_attr = timestamp,
+ "numOpsSinceStartup"_attr = _numOpsSinceStartup,
+ "lockAcquisitions"_attr = lockAcquisitions);
if (_sampledOpsApplied.size() <
static_cast<std::deque<Sample>::size_type>(gFlowControlMaxSamples)) {
@@ -479,7 +514,10 @@ void FlowControl::_trimSamples(const Timestamp trimTo) {
++numTrimmed;
}
- LOG(DEBUG_LOG_LEVEL) << "Trimmed samples. Num: " << numTrimmed;
+ LOGV2_DEBUG(22222,
+ logSeverityV1toV2(DEBUG_LOG_LEVEL).toInt(),
+ "Trimmed samples. Num: {numTrimmed}",
+ "numTrimmed"_attr = numTrimmed);
}
int64_t FlowControl::_getLocksUsedLastPeriod() {
diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp
index db6ceb39e29..f9489633c6b 100644
--- a/src/mongo/db/storage/key_string_test.cpp
+++ b/src/mongo/db/storage/key_string_test.cpp
@@ -48,6 +48,7 @@
#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/config.h"
#include "mongo/db/storage/key_string.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/decimal128.h"
#include "mongo/stdx/future.h"
#include "mongo/unittest/death_test.h"
@@ -97,8 +98,11 @@ public:
version = KeyString::Version::V1;
base->run();
} catch (...) {
- log() << "exception while testing KeyStringBuilder version "
- << mongo::KeyString::keyStringVersionToString(version);
+ LOGV2(22226,
+ "exception while testing KeyStringBuilder version "
+ "{mongo_KeyString_keyStringVersionToString_version}",
+ "mongo_KeyString_keyStringVersionToString_version"_attr =
+ mongo::KeyString::keyStringVersionToString(version));
throw;
}
}
@@ -351,8 +355,12 @@ TEST_F(KeyStringBuilderTest, ActualBytesDouble) {
BSONObj a = BSON("" << 5.5);
KeyString::Builder ks(version, a, ALL_ASCENDING);
- log() << keyStringVersionToString(version) << " size: " << ks.getSize() << " hex ["
- << toHex(ks.getBuffer(), ks.getSize()) << "]";
+ LOGV2(22227,
+ "{keyStringVersionToString_version} size: {ks_getSize} hex "
+ "[{toHex_ks_getBuffer_ks_getSize}]",
+ "keyStringVersionToString_version"_attr = keyStringVersionToString(version),
+ "ks_getSize"_attr = ks.getSize(),
+ "toHex_ks_getBuffer_ks_getSize"_attr = toHex(ks.getBuffer(), ks.getSize()));
ASSERT_EQUALS(10U, ks.getSize());
@@ -484,7 +492,7 @@ TEST_F(KeyStringBuilderTest, NumbersNearInt32Max) {
TEST_F(KeyStringBuilderTest, DecimalNumbers) {
if (version == KeyString::Version::V0) {
- log() << "not testing DecimalNumbers for KeyStringBuilder V0";
+ LOGV2(22228, "not testing DecimalNumbers for KeyStringBuilder V0");
return;
}
@@ -1172,7 +1180,7 @@ void testPermutation(KeyString::Version version,
BSONObj orderObj = orderings[k];
Ordering ordering = Ordering::make(orderObj);
if (debug)
- log() << "ordering: " << orderObj;
+ LOGV2(22229, "ordering: {orderObj}", "orderObj"_attr = orderObj);
std::vector<BSONObj> elements = elementsOrig;
BSONObjComparator bsonCmp(orderObj,
@@ -1183,7 +1191,7 @@ void testPermutation(KeyString::Version version,
for (size_t i = 0; i < elements.size(); i++) {
const BSONObj& o1 = elements[i];
if (debug)
- log() << "\to1: " << o1;
+ LOGV2(22230, "\to1: {o1}", "o1"_attr = o1);
ROUNDTRIP_ORDER(version, o1, ordering);
KeyString::Builder k1(version, o1, ordering);
@@ -1191,7 +1199,7 @@ void testPermutation(KeyString::Version version,
if (i + 1 < elements.size()) {
const BSONObj& o2 = elements[i + 1];
if (debug)
- log() << "\t\t o2: " << o2;
+ LOGV2(22231, "\t\t o2: {o2}", "o2"_attr = o2);
KeyString::Builder k2(version, o2, ordering);
int bsonCmp = o1.woCompare(o2, ordering);
@@ -1225,7 +1233,7 @@ std::mt19937_64 seedGen(rd());
// To be used by perf test for seeding, so that the entire test is repeatable in case of error.
unsigned newSeed() {
unsigned int seed = seedGen(); // Replace by the reported number to repeat test execution.
- log() << "Initializing random number generator using seed " << seed;
+ LOGV2(22232, "Initializing random number generator using seed {seed}", "seed"_attr = seed);
return seed;
};
@@ -1237,8 +1245,10 @@ std::vector<BSONObj> thinElements(std::vector<BSONObj> elements,
if (elements.size() <= maxElements)
return elements;
- log() << "only keeping " << maxElements << " of " << elements.size()
- << " elements using random selection";
+ LOGV2(22233,
+ "only keeping {maxElements} of {elements_size} elements using random selection",
+ "maxElements"_attr = maxElements,
+ "elements_size"_attr = elements.size());
std::shuffle(elements.begin(), elements.end(), gen);
elements.resize(maxElements);
return elements;
@@ -1284,7 +1294,10 @@ TEST_F(KeyStringBuilderTest, AllPerm2Compare) {
}
}
- log() << "AllPerm2Compare " << keyStringVersionToString(version) << " size:" << elements.size();
+ LOGV2(22234,
+ "AllPerm2Compare {keyStringVersionToString_version} size:{elements_size}",
+ "keyStringVersionToString_version"_attr = keyStringVersionToString(version),
+ "elements_size"_attr = elements.size());
for (size_t i = 0; i < elements.size(); i++) {
const BSONObj& o = elements[i];
@@ -1443,7 +1456,10 @@ TEST_F(KeyStringBuilderTest, NumberOrderLots) {
if (a.compare(b) !=
compareNumbers(numbers[i].firstElement(), numbers[j].firstElement())) {
- log() << numbers[i] << " " << numbers[j];
+ LOGV2(22235,
+ "{numbers_i} {numbers_j}",
+ "numbers_i"_attr = numbers[i],
+ "numbers_j"_attr = numbers[j]);
}
ASSERT_EQUALS(a.compare(b),
@@ -1755,10 +1771,17 @@ void perfTest(KeyString::Version version, const Numbers& numbers) {
auto minmax = std::minmax_element(
numbers.begin(), numbers.end(), SimpleBSONObjComparator::kInstance.makeLessThan());
- log() << 1E3 * micros / static_cast<double>(iters * numbers.size()) << " ns per "
- << mongo::KeyString::keyStringVersionToString(version) << " roundtrip"
- << (kDebugBuild ? " (DEBUG BUILD!)" : "") << " min " << (*minmax.first)[""] << ", max"
- << (*minmax.second)[""];
+ LOGV2(22236,
+ "{_1E3_micros_static_cast_double_iters_numbers_size} ns per "
+ "{mongo_KeyString_keyStringVersionToString_version} roundtrip{kDebugBuild_DEBUG_BUILD} "
+ "min {minmax_first}, max{minmax_second}",
+ "_1E3_micros_static_cast_double_iters_numbers_size"_attr =
+ 1E3 * micros / static_cast<double>(iters * numbers.size()),
+ "mongo_KeyString_keyStringVersionToString_version"_attr =
+ mongo::KeyString::keyStringVersionToString(version),
+ "kDebugBuild_DEBUG_BUILD"_attr = (kDebugBuild ? " (DEBUG BUILD!)" : ""),
+ "minmax_first"_attr = (*minmax.first)[""],
+ "minmax_second"_attr = (*minmax.second)[""]);
}
} // namespace
diff --git a/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp b/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp
index a68cbfe58f1..4e8927b2017 100644
--- a/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp
+++ b/src/mongo/db/storage/kv/kv_drop_pending_ident_reaper.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/storage/write_unit_of_work.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -57,9 +58,12 @@ void KVDropPendingIdentReaper::addDropPendingIdent(const Timestamp& dropTimestam
info.ident = ident.toString();
_dropPendingIdents.insert(std::make_pair(dropTimestamp, info));
} else {
- severe() << "Failed to add drop-pending ident " << ident << " (" << nss << ")"
- << " with drop timestamp " << dropTimestamp
- << ": duplicate timestamp and ident pair.";
+ LOGV2_FATAL(22238,
+ "Failed to add drop-pending ident {ident} ({nss}) with drop timestamp "
+ "{dropTimestamp}: duplicate timestamp and ident pair.",
+ "ident"_attr = ident,
+ "nss"_attr = nss,
+ "dropTimestamp"_attr = dropTimestamp);
fassertFailedNoTrace(51023);
}
}
@@ -109,13 +113,22 @@ void KVDropPendingIdentReaper::dropIdentsOlderThan(OperationContext* opCtx, cons
const auto& identInfo = timestampAndIdentInfo.second;
const auto& nss = identInfo.nss;
const auto& ident = identInfo.ident;
- log() << "Completing drop for ident " << ident << " (ns: " << nss
- << ") with drop timestamp " << dropTimestamp;
+ LOGV2(
+ 22237,
+ "Completing drop for ident {ident} (ns: {nss}) with drop timestamp {dropTimestamp}",
+ "ident"_attr = ident,
+ "nss"_attr = nss,
+ "dropTimestamp"_attr = dropTimestamp);
WriteUnitOfWork wuow(opCtx);
auto status = _engine->dropIdent(opCtx, opCtx->recoveryUnit(), ident);
if (!status.isOK()) {
- severe() << "Failed to remove drop-pending ident " << ident << "(ns: " << nss
- << ") with drop timestamp " << dropTimestamp << ": " << status;
+ LOGV2_FATAL(22239,
+ "Failed to remove drop-pending ident {ident}(ns: {nss}) with drop "
+ "timestamp {dropTimestamp}: {status}",
+ "ident"_attr = ident,
+ "nss"_attr = nss,
+ "dropTimestamp"_attr = dropTimestamp,
+ "status"_attr = status);
fassertFailedNoTrace(51022);
}
wuow.commit();
diff --git a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp
index a418badd579..88792e3709b 100644
--- a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp
+++ b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/service_context.h"
#include "mongo/db/storage/record_store.h"
#include "mongo/logger/logstream_builder.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
@@ -56,7 +57,7 @@ namespace mongo {
bool OplogCapMaintainerThread::_deleteExcessDocuments() {
if (!getGlobalServiceContext()->getStorageEngine()) {
- LOG(2) << "OplogCapMaintainerThread: no global storage engine yet";
+ LOGV2_DEBUG(22240, 2, "OplogCapMaintainerThread: no global storage engine yet");
return false;
}
@@ -81,7 +82,7 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() {
auto databaseHolder = DatabaseHolder::get(opCtx.get());
auto db = databaseHolder->getDb(opCtx.get(), oplogNss.db());
if (!db) {
- LOG(2) << "no local database yet";
+ LOGV2_DEBUG(22241, 2, "no local database yet");
return false;
}
// We need to hold the database lock while getting the collection. Otherwise a
@@ -90,7 +91,7 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() {
Collection* collection = CollectionCatalog::get(opCtx.get())
.lookupCollectionByNamespace(opCtx.get(), oplogNss);
if (!collection) {
- LOG(2) << "no collection " << oplogNss;
+ LOGV2_DEBUG(22242, 2, "no collection {oplogNss}", "oplogNss"_attr = oplogNss);
return false;
}
rs = collection->getRecordStore();
@@ -102,7 +103,7 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() {
} catch (const ExceptionForCat<ErrorCategory::Interruption>&) {
return false;
} catch (const std::exception& e) {
- severe() << "error in OplogCapMaintainerThread: " << e.what();
+ LOGV2_FATAL(22243, "error in OplogCapMaintainerThread: {e_what}", "e_what"_attr = e.what());
fassertFailedNoTrace(!"error in OplogCapMaintainerThread");
} catch (...) {
fassertFailedNoTrace(!"unknown error in OplogCapMaintainerThread");
diff --git a/src/mongo/db/storage/recovery_unit.cpp b/src/mongo/db/storage/recovery_unit.cpp
index 3d167d7a9c3..35d605a5cdc 100644
--- a/src/mongo/db/storage/recovery_unit.cpp
+++ b/src/mongo/db/storage/recovery_unit.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/storage/recovery_unit.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -74,7 +75,10 @@ void RecoveryUnit::commitRegisteredChanges(boost::optional<Timestamp> commitTime
for (auto& change : _changes) {
try {
// Log at higher level because commits occur far more frequently than rollbacks.
- LOG(3) << "CUSTOM COMMIT " << redact(demangleName(typeid(*change)));
+ LOGV2_DEBUG(22244,
+ 3,
+ "CUSTOM COMMIT {demangleName_typeid_change}",
+ "demangleName_typeid_change"_attr = redact(demangleName(typeid(*change))));
change->commit(commitTimestamp);
} catch (...) {
std::terminate();
@@ -90,7 +94,10 @@ void RecoveryUnit::abortRegisteredChanges() {
it != end;
++it) {
Change* change = it->get();
- LOG(2) << "CUSTOM ROLLBACK " << redact(demangleName(typeid(*change)));
+ LOGV2_DEBUG(22245,
+ 2,
+ "CUSTOM ROLLBACK {demangleName_typeid_change}",
+ "demangleName_typeid_change"_attr = redact(demangleName(typeid(*change))));
change->rollback();
}
_changes.clear();
diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp
index 2a4091b1f4e..1cbe9cc86ec 100644
--- a/src/mongo/db/storage/storage_engine_impl.cpp
+++ b/src/mongo/db/storage/storage_engine_impl.cpp
@@ -50,6 +50,7 @@
#include "mongo/db/storage/storage_repair_observer.h"
#include "mongo/db/storage/two_phase_index_build_knobs_gen.h"
#include "mongo/db/unclean_shutdown.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/unordered_map.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -90,11 +91,13 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) {
auto repairObserver = StorageRepairObserver::get(getGlobalServiceContext());
invariant(repairObserver->isIncomplete());
- log() << "Repairing catalog metadata";
+ LOGV2(22246, "Repairing catalog metadata");
Status status = _engine->repairIdent(opCtx, catalogInfo);
if (status.code() == ErrorCodes::DataModifiedByRepair) {
- warning() << "Catalog data modified by repair: " << status.reason();
+ LOGV2_WARNING(22264,
+ "Catalog data modified by repair: {status_reason}",
+ "status_reason"_attr = status.reason());
repairObserver->invalidatingModification(str::stream() << "DurableCatalog repaired: "
<< status.reason());
} else {
@@ -159,12 +162,14 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) {
if (statusWithNs.isOK()) {
wuow.commit();
auto orphanCollNs = statusWithNs.getValue();
- log() << "Successfully created an entry in the catalog for the orphaned "
- "collection: "
- << orphanCollNs;
- warning() << orphanCollNs
- << " does not have the _id index. Please manually "
- "build the index.";
+ LOGV2(22247,
+ "Successfully created an entry in the catalog for the orphaned "
+ "collection: {orphanCollNs}",
+ "orphanCollNs"_attr = orphanCollNs);
+ LOGV2_WARNING(22265,
+ "{orphanCollNs} does not have the _id index. Please manually "
+ "build the index.",
+ "orphanCollNs"_attr = orphanCollNs);
StorageRepairObserver::get(getGlobalServiceContext())
->benignModification(str::stream() << "Orphan collection created: "
@@ -173,10 +178,14 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) {
} else {
// Log an error message if we cannot create the entry.
// reconcileCatalogAndIdents() will later drop this ident.
- error() << "Cannot create an entry in the catalog for the orphaned "
- "collection ident: "
- << ident << " due to " << statusWithNs.getStatus().reason();
- error() << "Restarting the server will remove this ident.";
+ LOGV2_ERROR(
+ 22268,
+ "Cannot create an entry in the catalog for the orphaned "
+ "collection ident: {ident} due to {statusWithNs_getStatus_reason}",
+ "ident"_attr = ident,
+ "statusWithNs_getStatus_reason"_attr =
+ statusWithNs.getStatus().reason());
+ LOGV2_ERROR(22269, "Restarting the server will remove this ident.");
}
}
}
@@ -201,8 +210,11 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) {
auto status =
_recoverOrphanedCollection(opCtx, entry.catalogId, entry.nss, collectionIdent);
if (!status.isOK()) {
- warning() << "Failed to recover orphaned data file for collection '"
- << entry.nss << "': " << status;
+ LOGV2_WARNING(22266,
+ "Failed to recover orphaned data file for collection "
+ "'{entry_nss}': {status}",
+ "entry_nss"_attr = entry.nss,
+ "status"_attr = status);
WriteUnitOfWork wuow(opCtx);
fassert(50716, _catalog->_removeEntry(opCtx, entry.catalogId));
@@ -223,7 +235,7 @@ void StorageEngineImpl::loadCatalog(OperationContext* opCtx) {
maxSeenPrefix = std::max(maxSeenPrefix, maxPrefixForCollection);
if (entry.nss.isOrphanCollection()) {
- log() << "Orphaned collection found: " << entry.nss;
+ LOGV2(22248, "Orphaned collection found: {entry_nss}", "entry_nss"_attr = entry.nss);
}
}
@@ -284,9 +296,11 @@ Status StorageEngineImpl::_recoverOrphanedCollection(OperationContext* opCtx,
if (!_options.forRepair) {
return {ErrorCodes::IllegalOperation, "Orphan recovery only supported in repair"};
}
- log() << "Storage engine is missing collection '" << collectionName
- << "' from its metadata. Attempting to locate and recover the data for "
- << collectionIdent;
+ LOGV2(22249,
+ "Storage engine is missing collection '{collectionName}' from its metadata. Attempting "
+ "to locate and recover the data for {collectionIdent}",
+ "collectionName"_attr = collectionName,
+ "collectionIdent"_attr = collectionIdent);
WriteUnitOfWork wuow(opCtx);
const auto metadata = _catalog->getMetaData(opCtx, catalogId);
@@ -376,12 +390,14 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
// These idents have to be retained as long as the corresponding drops are not part of a
// checkpoint.
if (dropPendingIdents.find(it) != dropPendingIdents.cend()) {
- log() << "Not removing ident for uncheckpointed collection or index drop: " << it;
+ LOGV2(22250,
+ "Not removing ident for uncheckpointed collection or index drop: {it}",
+ "it"_attr = it);
continue;
}
const auto& toRemove = it;
- log() << "Dropping unknown ident: " << toRemove;
+ LOGV2(22251, "Dropping unknown ident: {toRemove}", "toRemove"_attr = toRemove);
WriteUnitOfWork wuow(opCtx);
fassert(40591, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), toRemove));
wuow.commit();
@@ -427,11 +443,14 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
indexMetaData.multikeyPaths.end(),
[](auto& pathSet) { return pathSet.size() > 0; });
if (!indexMetaData.multikey && hasMultiKeyPaths) {
- warning() << "The 'multikey' field for index " << indexName << " on collection "
- << coll << " was false with non-empty 'multikeyPaths'. This indicates "
- << "corruption of the catalog. Consider either dropping and recreating "
- << "the index, or rerunning with the --repair option. See "
- << "http://dochub.mongodb.org/core/repair for more information.";
+ LOGV2_WARNING(22267,
+ "The 'multikey' field for index {indexName} on collection {coll} was "
+ "false with non-empty 'multikeyPaths'. This indicates corruption of "
+ "the catalog. Consider either dropping and recreating the index, or "
+ "rerunning with the --repair option. See "
+ "http://dochub.mongodb.org/core/repair for more information.",
+ "indexName"_attr = indexName,
+ "coll"_attr = coll);
}
const bool foundIdent = engineIdents.find(indexIdent) != engineIdents.end();
@@ -440,8 +459,11 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
// majority of nodes. The code will rebuild the index, despite potentially
// encountering another `dropIndex` command.
if (indexMetaData.ready && !foundIdent) {
- log() << "Expected index data is missing, rebuilding. Collection: " << coll
- << " Index: " << indexName;
+ LOGV2(22252,
+ "Expected index data is missing, rebuilding. Collection: {coll} Index: "
+ "{indexName}",
+ "coll"_attr = coll,
+ "indexName"_attr = indexName);
ret.indexesToRebuild.push_back({entry.catalogId, coll, indexName});
continue;
}
@@ -456,8 +478,13 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
invariant(collUUID);
auto buildUUID = *indexMetaData.buildUUID;
- log() << "Found index from unfinished build. Collection: " << coll << " ("
- << *collUUID << "), index: " << indexName << ", build UUID: " << buildUUID;
+ LOGV2(22253,
+ "Found index from unfinished build. Collection: {coll} ({collUUID}), index: "
+ "{indexName}, build UUID: {buildUUID}",
+ "coll"_attr = coll,
+ "collUUID"_attr = *collUUID,
+ "indexName"_attr = indexName,
+ "buildUUID"_attr = buildUUID);
// Insert in the map if a build has not already been registered.
auto existingIt = ret.indexBuildsToRestart.find(buildUUID);
@@ -476,17 +503,21 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
// will return the index to be rebuilt.
if (indexMetaData.isBackgroundSecondaryBuild && (!foundIdent || !indexMetaData.ready)) {
if (!serverGlobalParams.indexBuildRetry) {
- log() << "Dropping an unfinished index because --noIndexBuildRetry is set. "
- "Collection: "
- << coll << " Index: " << indexName;
+ LOGV2(22254,
+ "Dropping an unfinished index because --noIndexBuildRetry is set. "
+ "Collection: {coll} Index: {indexName}",
+ "coll"_attr = coll,
+ "indexName"_attr = indexName);
fassert(51197, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), indexIdent));
indexesToDrop.push_back(indexName);
continue;
}
- log() << "Expected background index build did not complete, rebuilding. "
- "Collection: "
- << coll << " Index: " << indexName;
+ LOGV2(22255,
+ "Expected background index build did not complete, rebuilding. "
+ "Collection: {coll} Index: {indexName}",
+ "coll"_attr = coll,
+ "indexName"_attr = indexName);
ret.indexesToRebuild.push_back({entry.catalogId, coll, indexName});
continue;
}
@@ -498,8 +529,10 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
// index when it replays the oplog. In these cases the index entry in the catalog
// should be dropped.
if (!indexMetaData.ready && !indexMetaData.isBackgroundSecondaryBuild) {
- log() << "Dropping unfinished index. Collection: " << coll
- << " Index: " << indexName;
+ LOGV2(22256,
+ "Dropping unfinished index. Collection: {coll} Index: {indexName}",
+ "coll"_attr = coll,
+ "indexName"_attr = indexName);
// Ensure the `ident` is dropped while we have the `indexIdent` value.
fassert(50713, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), indexIdent));
indexesToDrop.push_back(indexName);
@@ -520,7 +553,7 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn
}
for (auto&& temp : internalIdentsToDrop) {
- log() << "Dropping internal ident: " << temp;
+ LOGV2(22257, "Dropping internal ident: {temp}", "temp"_attr = temp);
WriteUnitOfWork wuow(opCtx);
fassert(51067, _engine->dropIdent(opCtx, opCtx->recoveryUnit(), temp));
wuow.commit();
@@ -730,7 +763,10 @@ std::unique_ptr<TemporaryRecordStore> StorageEngineImpl::makeTemporaryRecordStor
OperationContext* opCtx) {
std::unique_ptr<RecordStore> rs =
_engine->makeTemporaryRecordStore(opCtx, _catalog->newInternalIdent());
- LOG(1) << "created temporary record store: " << rs->getIdent();
+ LOGV2_DEBUG(22258,
+ 1,
+ "created temporary record store: {rs_getIdent}",
+ "rs_getIdent"_attr = rs->getIdent());
return std::make_unique<TemporaryKVRecordStore>(getEngine(), std::move(rs));
}
@@ -799,7 +835,9 @@ StatusWith<Timestamp> StorageEngineImpl::recoverToStableTimestamp(OperationConte
catalog::openCatalog(opCtx, state);
- log() << "recoverToStableTimestamp successful. Stable Timestamp: " << swTimestamp.getValue();
+ LOGV2(22259,
+ "recoverToStableTimestamp successful. Stable Timestamp: {swTimestamp_getValue}",
+ "swTimestamp_getValue"_attr = swTimestamp.getValue());
return {swTimestamp.getValue()};
}
@@ -907,8 +945,9 @@ void StorageEngineImpl::_onMinOfCheckpointAndOldestTimestampChanged(const Timest
// No drop-pending idents present if getEarliestDropTimestamp() returns boost::none.
if (auto earliestDropTimestamp = _dropPendingIdentReaper.getEarliestDropTimestamp()) {
if (timestamp > *earliestDropTimestamp) {
- log() << "Removing drop-pending idents with drop timestamps before timestamp "
- << timestamp;
+ LOGV2(22260,
+ "Removing drop-pending idents with drop timestamps before timestamp {timestamp}",
+ "timestamp"_attr = timestamp);
auto opCtx = cc().getOperationContext();
invariant(opCtx);
@@ -930,7 +969,7 @@ StorageEngineImpl::TimestampMonitor::TimestampMonitor(KVEngine* engine, Periodic
}
StorageEngineImpl::TimestampMonitor::~TimestampMonitor() {
- log() << "Timestamp monitor shutting down";
+ LOGV2(22261, "Timestamp monitor shutting down");
stdx::lock_guard<Latch> lock(_monitorMutex);
invariant(_listeners.empty());
}
@@ -938,7 +977,7 @@ StorageEngineImpl::TimestampMonitor::~TimestampMonitor() {
void StorageEngineImpl::TimestampMonitor::startup() {
invariant(!_running);
- log() << "Timestamp monitor starting";
+ LOGV2(22262, "Timestamp monitor starting");
PeriodicRunner::PeriodicJob job(
"TimestampMonitor",
[&](Client* client) {
@@ -998,7 +1037,10 @@ void StorageEngineImpl::TimestampMonitor::startup() {
}
} catch (const ExceptionFor<ErrorCodes::InterruptedAtShutdown>& ex) {
// If we're interrupted at shutdown, it's fine to give up on future notifications
- log() << "Timestamp monitor is stopping due to: " + ex.reason();
+ LOGV2(22263,
+ "{Timestamp_monitor_is_stopping_due_to_ex_reason}",
+ "Timestamp_monitor_is_stopping_due_to_ex_reason"_attr =
+ "Timestamp monitor is stopping due to: " + ex.reason());
return;
}
},
diff --git a/src/mongo/db/storage/storage_engine_init.cpp b/src/mongo/db/storage/storage_engine_init.cpp
index c2fe7559438..ab3e8e9b032 100644
--- a/src/mongo/db/storage/storage_engine_init.cpp
+++ b/src/mongo/db/storage/storage_engine_init.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/storage/storage_repair_observer.h"
#include "mongo/db/unclean_shutdown.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -78,10 +79,11 @@ void initializeStorageEngine(ServiceContext* service, const StorageEngineInitFla
if (storageGlobalParams.repair) {
repairObserver->onRepairStarted();
} else if (repairObserver->isIncomplete()) {
- severe()
- << "An incomplete repair has been detected! This is likely because a repair "
- "operation unexpectedly failed before completing. MongoDB will not start up "
- "again without --repair.";
+ LOGV2_FATAL(
+ 22272,
+ "An incomplete repair has been detected! This is likely because a repair "
+ "operation unexpectedly failed before completing. MongoDB will not start up "
+ "again without --repair.");
fassertFailedNoTrace(50922);
}
}
@@ -104,9 +106,13 @@ void initializeStorageEngine(ServiceContext* service, const StorageEngineInitFla
}
} else {
// Otherwise set the active storage engine as the contents of the metadata file.
- log() << "Detected data files in " << dbpath << " created by the '"
- << *existingStorageEngine << "' storage engine, so setting the active"
- << " storage engine to '" << *existingStorageEngine << "'.";
+ LOGV2(
+ 22270,
+ "Detected data files in {dbpath} created by the '{existingStorageEngine}' storage "
+ "engine, so setting the active storage engine to '{existingStorageEngine2}'.",
+ "dbpath"_attr = dbpath,
+ "existingStorageEngine"_attr = *existingStorageEngine,
+ "existingStorageEngine2"_attr = *existingStorageEngine);
storageGlobalParams.engine = *existingStorageEngine;
}
}
@@ -205,11 +211,14 @@ void createLockFile(ServiceContext* service) {
if (wasUnclean) {
if (storageGlobalParams.readOnly) {
- severe() << "Attempted to open dbpath in readOnly mode, but the server was "
- "previously not shut down cleanly.";
+ LOGV2_FATAL(22273,
+ "Attempted to open dbpath in readOnly mode, but the server was "
+ "previously not shut down cleanly.");
fassertFailedNoTrace(34416);
}
- warning() << "Detected unclean shutdown - " << lockFile->getFilespec() << " is not empty.";
+ LOGV2_WARNING(22271,
+ "Detected unclean shutdown - {lockFile_getFilespec} is not empty.",
+ "lockFile_getFilespec"_attr = lockFile->getFilespec());
startingAfterUncleanShutdown(service) = true;
}
}
diff --git a/src/mongo/db/storage/storage_engine_lock_file_posix.cpp b/src/mongo/db/storage/storage_engine_lock_file_posix.cpp
index c0398eddec3..aba21904fa5 100644
--- a/src/mongo/db/storage/storage_engine_lock_file_posix.cpp
+++ b/src/mongo/db/storage/storage_engine_lock_file_posix.cpp
@@ -42,6 +42,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -56,14 +57,16 @@ void flushMyDirectory(const boost::filesystem::path& file) {
// so make a warning. need a better solution longer term.
// massert(40389, str::stream() << "Couldn't find parent dir for file: " << file.string(),);
if (!file.has_branch_path()) {
- log() << "warning flushMyDirectory couldn't find parent dir for file: " << file.string();
+ LOGV2(22274,
+ "warning flushMyDirectory couldn't find parent dir for file: {file_string}",
+ "file_string"_attr = file.string());
return;
}
boost::filesystem::path dir = file.branch_path(); // parent_path in new boosts
- LOG(1) << "flushing directory " << dir.string();
+ LOGV2_DEBUG(22275, 1, "flushing directory {dir_string}", "dir_string"_attr = dir.string());
int fd = ::open(dir.string().c_str(), O_RDONLY); // DO NOT THROW OR ASSERT BEFORE CLOSING
massert(40387,
@@ -74,12 +77,17 @@ void flushMyDirectory(const boost::filesystem::path& file) {
int e = errno;
if (e == EINVAL) { // indicates filesystem does not support synchronization
if (!_warnedAboutFilesystem) {
- log() << "\tWARNING: This file system is not supported. For further information"
- << " see:" << startupWarningsLog;
- log() << "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems"
- << startupWarningsLog;
- log() << "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated "
- << "this warning." << startupWarningsLog;
+ LOGV2_OPTIONS(
+ 22276,
+ {logv2::LogTag::kStartupWarnings},
+ "\tWARNING: This file system is not supported. For further information see:");
+ LOGV2_OPTIONS(22277,
+ {logv2::LogTag::kStartupWarnings},
+ "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems");
+ LOGV2_OPTIONS(22278,
+ {logv2::LogTag::kStartupWarnings},
+ "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated "
+ "this warning.");
_warnedAboutFilesystem = true;
}
} else {
@@ -225,13 +233,15 @@ void StorageEngineLockFile::clearPidAndUnlock() {
if (!_lockFileHandle->isValid()) {
return;
}
- log() << "shutdown: removing fs lock...";
+ LOGV2(22279, "shutdown: removing fs lock...");
// This ought to be an unlink(), but Eliot says the last
// time that was attempted, there was a race condition
// with StorageEngineLockFile::open().
if (::ftruncate(_lockFileHandle->_fd, 0)) {
int errorcode = errno;
- log() << "couldn't remove fs lock " << errnoWithDescription(errorcode);
+ LOGV2(22280,
+ "couldn't remove fs lock {errnoWithDescription_errorcode}",
+ "errnoWithDescription_errorcode"_attr = errnoWithDescription(errorcode));
}
close();
}
diff --git a/src/mongo/db/storage/storage_engine_lock_file_windows.cpp b/src/mongo/db/storage/storage_engine_lock_file_windows.cpp
index 4055318d1d8..e6a152b4262 100644
--- a/src/mongo/db/storage/storage_engine_lock_file_windows.cpp
+++ b/src/mongo/db/storage/storage_engine_lock_file_windows.cpp
@@ -38,6 +38,7 @@
#include <ostream>
#include <sstream>
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
#include "mongo/util/text.h"
@@ -184,13 +185,13 @@ void StorageEngineLockFile::clearPidAndUnlock() {
if (!_lockFileHandle->isValid()) {
return;
}
- log() << "shutdown: removing fs lock...";
+ LOGV2(22281, "shutdown: removing fs lock...");
// This ought to be an unlink(), but Eliot says the last
// time that was attempted, there was a race condition
// with StorageEngineLockFile::open().
Status status = _truncateFile(_lockFileHandle->_handle);
if (!status.isOK()) {
- log() << "couldn't remove fs lock " << status.toString();
+ LOGV2(22282, "couldn't remove fs lock {status}", "status"_attr = status.toString());
}
CloseHandle(_lockFileHandle->_handle);
_lockFileHandle->clear();
diff --git a/src/mongo/db/storage/storage_engine_metadata.cpp b/src/mongo/db/storage/storage_engine_metadata.cpp
index ecf401f3ee9..f02288a1edd 100644
--- a/src/mongo/db/storage/storage_engine_metadata.cpp
+++ b/src/mongo/db/storage/storage_engine_metadata.cpp
@@ -51,6 +51,7 @@
#include "mongo/base/data_type_validated.h"
#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/object_check.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/file.h"
@@ -85,7 +86,9 @@ std::unique_ptr<StorageEngineMetadata> StorageEngineMetadata::forPath(const std:
metadata.reset(new StorageEngineMetadata(dbpath));
Status status = metadata->read();
if (!status.isOK()) {
- error() << "Unable to read the storage engine metadata file: " << status;
+ LOGV2_ERROR(22288,
+ "Unable to read the storage engine metadata file: {status}",
+ "status"_attr = status);
fassertFailedNoTrace(28661);
}
}
@@ -219,14 +222,16 @@ void flushMyDirectory(const boost::filesystem::path& file) {
// so make a warning. need a better solution longer term.
// massert(13652, str::stream() << "Couldn't find parent dir for file: " << file.string(),);
if (!file.has_branch_path()) {
- log() << "warning flushMyDirectory couldn't find parent dir for file: " << file.string();
+ LOGV2(22283,
+ "warning flushMyDirectory couldn't find parent dir for file: {file_string}",
+ "file_string"_attr = file.string());
return;
}
boost::filesystem::path dir = file.branch_path(); // parent_path in new boosts
- LOG(1) << "flushing directory " << dir.string();
+ LOGV2_DEBUG(22284, 1, "flushing directory {dir_string}", "dir_string"_attr = dir.string());
int fd = ::open(dir.string().c_str(), O_RDONLY); // DO NOT THROW OR ASSERT BEFORE CLOSING
massert(13650,
@@ -237,12 +242,17 @@ void flushMyDirectory(const boost::filesystem::path& file) {
int e = errno;
if (e == EINVAL) { // indicates filesystem does not support synchronization
if (!_warnedAboutFilesystem) {
- log() << "\tWARNING: This file system is not supported. For further information"
- << " see:" << startupWarningsLog;
- log() << "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems"
- << startupWarningsLog;
- log() << "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated "
- << "this warning." << startupWarningsLog;
+ LOGV2_OPTIONS(
+ 22285,
+ {logv2::LogTag::kStartupWarnings},
+ "\tWARNING: This file system is not supported. For further information see:");
+ LOGV2_OPTIONS(22286,
+ {logv2::LogTag::kStartupWarnings},
+ "\t\t\thttp://dochub.mongodb.org/core/unsupported-filesystems");
+ LOGV2_OPTIONS(22287,
+ {logv2::LogTag::kStartupWarnings},
+ "\t\tPlease notify MongoDB, Inc. if an unlisted filesystem generated "
+ "this warning.");
_warnedAboutFilesystem = true;
}
} else {
diff --git a/src/mongo/db/storage/storage_file_util.cpp b/src/mongo/db/storage/storage_file_util.cpp
index dd47a85642d..2a457ccf3a5 100644
--- a/src/mongo/db/storage/storage_file_util.cpp
+++ b/src/mongo/db/storage/storage_file_util.cpp
@@ -42,6 +42,7 @@
#include <boost/filesystem/path.hpp>
+#include "mongo/logv2/log.h"
#include "mongo/util/file.h"
#include "mongo/util/log.h"
@@ -67,7 +68,7 @@ Status fsyncParentDirectory(const boost::filesystem::path& file) {
boost::filesystem::path dir = file.parent_path();
- LOG(1) << "flushing directory " << dir.string();
+ LOGV2_DEBUG(22289, 1, "flushing directory {dir_string}", "dir_string"_attr = dir.string());
int fd = ::open(dir.string().c_str(), O_RDONLY);
if (fd < 0) {
@@ -78,7 +79,8 @@ Status fsyncParentDirectory(const boost::filesystem::path& file) {
if (fsync(fd) != 0) {
int e = errno;
if (e == EINVAL) {
- warning() << "Could not fsync directory because this file system is not supported.";
+ LOGV2_WARNING(22290,
+ "Could not fsync directory because this file system is not supported.");
} else {
close(fd);
return {ErrorCodes::OperationFailed,
diff --git a/src/mongo/db/storage/storage_repair_observer_test.cpp b/src/mongo/db/storage/storage_repair_observer_test.cpp
index b9bb17e818f..fa653febf9b 100644
--- a/src/mongo/db/storage/storage_repair_observer_test.cpp
+++ b/src/mongo/db/storage/storage_repair_observer_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <boost/filesystem.hpp>
@@ -37,8 +39,10 @@
#include "mongo/db/repl/replication_coordinator_mock.h"
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/db/storage/storage_repair_observer.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace {
@@ -107,9 +111,11 @@ public:
}
if (repairObserver->isDone() && repairObserver->isDataInvalidated()) {
- unittest::log() << "Modifications: ";
+ LOGV2(22291, "Modifications: ");
for (const auto& mod : repairObserver->getModifications()) {
- unittest::log() << " " << mod.getDescription();
+ LOGV2(22292,
+ " {mod_getDescription}",
+ "mod_getDescription"_attr = mod.getDescription());
}
}
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp
index 7e708bfded2..d4b4a497bb9 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_global_options.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_global_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace moe = mongo::optionenvironment;
@@ -49,15 +50,22 @@ Status WiredTigerGlobalOptions::store(const moe::Environment& params) {
}
if (!wiredTigerGlobalOptions.engineConfig.empty()) {
- log() << "Engine custom option: " << wiredTigerGlobalOptions.engineConfig;
+ LOGV2(22293,
+ "Engine custom option: {wiredTigerGlobalOptions_engineConfig}",
+ "wiredTigerGlobalOptions_engineConfig"_attr = wiredTigerGlobalOptions.engineConfig);
}
if (!wiredTigerGlobalOptions.collectionConfig.empty()) {
- log() << "Collection custom option: " << wiredTigerGlobalOptions.collectionConfig;
+ LOGV2(22294,
+ "Collection custom option: {wiredTigerGlobalOptions_collectionConfig}",
+ "wiredTigerGlobalOptions_collectionConfig"_attr =
+ wiredTigerGlobalOptions.collectionConfig);
}
if (!wiredTigerGlobalOptions.indexConfig.empty()) {
- log() << "Index custom option: " << wiredTigerGlobalOptions.indexConfig;
+ LOGV2(22295,
+ "Index custom option: {wiredTigerGlobalOptions_indexConfig}",
+ "wiredTigerGlobalOptions_indexConfig"_attr = wiredTigerGlobalOptions.indexConfig);
}
return Status::OK();
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp
index ec034eccc34..da0e63a957a 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_server_status.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/processinfo.h"
@@ -67,7 +68,7 @@ public:
virtual StorageEngine* create(const StorageGlobalParams& params,
const StorageEngineLockFile* lockFile) const {
if (lockFile && lockFile->createdByUncleanShutdown()) {
- warning() << "Recovering data from the last clean checkpoint.";
+ LOGV2_WARNING(22302, "Recovering data from the last clean checkpoint.");
}
#if defined(__linux__)
@@ -79,13 +80,16 @@ public:
int ret = statfs(params.dbpath.c_str(), &fs_stats);
if (ret == 0 && fs_stats.f_type == EXT4_SUPER_MAGIC) {
- log() << startupWarningsLog;
- log() << "** WARNING: Using the XFS filesystem is strongly recommended with the "
- "WiredTiger storage engine"
- << startupWarningsLog;
- log() << "** See "
- "http://dochub.mongodb.org/core/prodnotes-filesystem"
- << startupWarningsLog;
+ LOGV2_OPTIONS(22296, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(
+ 22297,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: Using the XFS filesystem is strongly recommended with the "
+ "WiredTiger storage engine");
+ LOGV2_OPTIONS(22298,
+ {logv2::LogTag::kStartupWarnings},
+ "** See "
+ "http://dochub.mongodb.org/core/prodnotes-filesystem");
}
}
#endif
@@ -95,13 +99,17 @@ public:
ProcessInfo p;
if (p.supported()) {
if (cacheMB > memoryThresholdPercentage * p.getMemSizeMB()) {
- log() << startupWarningsLog;
- log() << "** WARNING: The configured WiredTiger cache size is more than "
- << memoryThresholdPercentage * 100 << "% of available RAM."
- << startupWarningsLog;
- log() << "** See "
- "http://dochub.mongodb.org/core/faq-memory-diagnostics-wt"
- << startupWarningsLog;
+ LOGV2_OPTIONS(22299, {logv2::LogTag::kStartupWarnings}, "");
+ LOGV2_OPTIONS(22300,
+ {logv2::LogTag::kStartupWarnings},
+ "** WARNING: The configured WiredTiger cache size is more than "
+ "{memoryThresholdPercentage_100}% of available RAM.",
+ "memoryThresholdPercentage_100"_attr =
+ memoryThresholdPercentage * 100);
+ LOGV2_OPTIONS(22301,
+ {logv2::LogTag::kStartupWarnings},
+ "** See "
+ "http://dochub.mongodb.org/core/faq-memory-diagnostics-wt");
}
}
const bool ephemeral = false;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index 5e220754e7e..2d39e7336a3 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -83,6 +83,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/util/background.h"
#include "mongo/util/concurrency/idle_thread_block.h"
@@ -197,7 +198,7 @@ public:
virtual void run() {
ThreadClient tc(name(), getGlobalServiceContext());
- LOG(1) << "starting " << name() << " thread";
+ LOGV2_DEBUG(22303, 1, "starting {name} thread", "name"_attr = name());
while (!_shuttingDown.load()) {
{
@@ -210,7 +211,7 @@ public:
_sessionCache->closeExpiredIdleSessions(gWiredTigerSessionCloseIdleTimeSecs.load() *
1000);
}
- LOG(1) << "stopping " << name() << " thread";
+ LOGV2_DEBUG(22304, 1, "stopping {name} thread", "name"_attr = name());
}
void shutdown() {
@@ -245,7 +246,7 @@ public:
virtual void run() {
ThreadClient tc(name(), getGlobalServiceContext());
- LOG(1) << "starting " << name() << " thread";
+ LOGV2_DEBUG(22305, 1, "starting {name} thread", "name"_attr = name());
// Initialize the thread's opCtx.
_uniqueCtx.emplace(tc->makeOperationContext());
@@ -296,7 +297,7 @@ public:
_flushJournalNow = false;
if (_shuttingDown) {
- LOG(1) << "stopping " << name() << " thread";
+ LOGV2_DEBUG(22306, 1, "stopping {name} thread", "name"_attr = name());
_nextSharedPromise->setError(
Status(ErrorCodes::ShutdownInProgress, "The storage catalog is being closed."));
stdx::lock_guard<Latch> lk(_opCtxMutex);
@@ -447,7 +448,7 @@ public:
virtual void run() {
ThreadClient tc(name(), getGlobalServiceContext());
- LOG(1) << "starting " << name() << " thread";
+ LOGV2_DEBUG(22307, 1, "starting {name} thread", "name"_attr = name());
while (!_shuttingDown.load()) {
auto opCtx = tc->makeOperationContext();
@@ -540,16 +541,19 @@ public:
const auto secondsElapsed = durationCount<Seconds>(Date_t::now() - startTime);
if (secondsElapsed >= 30) {
- LOG(1) << "Checkpoint took " << secondsElapsed << " seconds to complete.";
+ LOGV2_DEBUG(22308,
+ 1,
+ "Checkpoint took {secondsElapsed} seconds to complete.",
+ "secondsElapsed"_attr = secondsElapsed);
}
} catch (const WriteConflictException&) {
// Temporary: remove this after WT-3483
- warning() << "Checkpoint encountered a write conflict exception.";
+ LOGV2_WARNING(22346, "Checkpoint encountered a write conflict exception.");
} catch (const AssertionException& exc) {
invariant(ErrorCodes::isShutdownError(exc.code()), exc.what());
}
}
- LOG(1) << "stopping " << name() << " thread";
+ LOGV2_DEBUG(22309, 1, "stopping {name} thread", "name"_attr = name());
}
/**
@@ -575,8 +579,12 @@ public:
invariant(!_hasTriggeredFirstStableCheckpoint);
if (prevStable < initialData && currStable >= initialData) {
_hasTriggeredFirstStableCheckpoint = true;
- log() << "Triggering the first stable checkpoint. Initial Data: " << initialData
- << " PrevStable: " << prevStable << " CurrStable: " << currStable;
+ LOGV2(22310,
+ "Triggering the first stable checkpoint. Initial Data: {initialData} PrevStable: "
+ "{prevStable} CurrStable: {currStable}",
+ "initialData"_attr = initialData,
+ "prevStable"_attr = prevStable,
+ "currStable"_attr = currStable);
stdx::unique_lock<Latch> lock(_mutex);
_condvar.notify_one();
}
@@ -727,8 +735,14 @@ StatusWith<StorageEngine::BackupInformation> getBackupInformationFromBackupCurso
while ((wtRet = dupCursor->next(dupCursor)) == 0) {
uint64_t offset, size, type;
invariantWTOK(dupCursor->get_key(dupCursor, &offset, &size, &type));
- LOG(2) << "Block to copy for incremental backup: filename: " << filePath.string()
- << ", offset: " << offset << ", size: " << size << ", type: " << type;
+ LOGV2_DEBUG(22311,
+ 2,
+ "Block to copy for incremental backup: filename: {filePath_string}, "
+ "offset: {offset}, size: {size}, type: {type}",
+ "filePath_string"_attr = filePath.string(),
+ "offset"_attr = offset,
+ "size"_attr = size,
+ "type"_attr = type);
backupInformation.at(filePath.string()).blocksToCopy.push_back({offset, size});
}
@@ -779,7 +793,10 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName,
try {
boost::filesystem::create_directory(journalPath);
} catch (std::exception& e) {
- log() << "error creating journal dir " << journalPath.string() << ' ' << e.what();
+ LOGV2(22312,
+ "error creating journal dir {journalPath_string} {e_what}",
+ "journalPath_string"_attr = journalPath.string(),
+ "e_what"_attr = e.what());
throw;
}
}
@@ -841,8 +858,9 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName,
// the normal path without the journal.
if (boost::filesystem::exists(journalPath)) {
string config = ss.str();
- log() << "Detected WT journal files. Running recovery from last checkpoint.";
- log() << "journal to nojournal transition config: " << config;
+ LOGV2(22313, "Detected WT journal files. Running recovery from last checkpoint.");
+ LOGV2(
+ 22314, "journal to nojournal transition config: {config}", "config"_attr = config);
int ret = wiredtiger_open(
path.c_str(), _eventHandler.getWtEventHandler(), config.c_str(), &_conn);
if (ret == EINVAL) {
@@ -856,7 +874,10 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName,
try {
boost::filesystem::remove_all(journalPath);
} catch (std::exception& e) {
- error() << "error removing journal dir " << journalPath.string() << ' ' << e.what();
+ LOGV2_ERROR(22355,
+ "error removing journal dir {journalPath_string} {e_what}",
+ "journalPath_string"_attr = journalPath.string(),
+ "e_what"_attr = e.what());
throw;
}
}
@@ -865,7 +886,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName,
}
string config = ss.str();
- log() << "wiredtiger_open config: " << config;
+ LOGV2(22315, "wiredtiger_open config: {config}", "config"_attr = config);
_openWiredTiger(path, config);
_eventHandler.setStartupSuccessful();
_wtOpenConfig = config;
@@ -907,7 +928,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName,
_sizeStorerUri = _uri("sizeStorer");
WiredTigerSession session(_conn);
if (!_readOnly && repair && _hasUri(session.getSession(), _sizeStorerUri)) {
- log() << "Repairing size cache";
+ LOGV2(22316, "Repairing size cache");
auto status = _salvageIfNeeded(_sizeStorerUri.c_str());
if (status.code() != ErrorCodes::DataModifiedByRepair)
@@ -998,28 +1019,30 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str
return;
}
- warning() << "Failed to start up WiredTiger under any compatibility version.";
+ LOGV2_WARNING(22347, "Failed to start up WiredTiger under any compatibility version.");
if (ret == EINVAL) {
fassertFailedNoTrace(28561);
}
if (ret == WT_TRY_SALVAGE) {
- warning() << "WiredTiger metadata corruption detected";
+ LOGV2_WARNING(22348, "WiredTiger metadata corruption detected");
if (!_inRepairMode) {
- severe() << kWTRepairMsg;
+ LOGV2_FATAL(22362, "{kWTRepairMsg}", "kWTRepairMsg"_attr = kWTRepairMsg);
fassertFailedNoTrace(50944);
}
}
- severe() << "Reason: " << wtRCToStatus(ret).reason();
+ LOGV2_FATAL(22363,
+ "Reason: {wtRCToStatus_ret_reason}",
+ "wtRCToStatus_ret_reason"_attr = wtRCToStatus(ret).reason());
if (!_inRepairMode) {
fassertFailedNoTrace(28595);
}
// Always attempt to salvage metadata regardless of error code when in repair mode.
- warning() << "Attempting to salvage WiredTiger metadata";
+ LOGV2_WARNING(22349, "Attempting to salvage WiredTiger metadata");
configStr = wtOpenConfig + ",salvage=true";
ret = wiredtiger_open(path.c_str(), wtEventHandler, configStr.c_str(), &_conn);
if (!ret) {
@@ -1028,12 +1051,15 @@ void WiredTigerKVEngine::_openWiredTiger(const std::string& path, const std::str
return;
}
- severe() << "Failed to salvage WiredTiger metadata: " + wtRCToStatus(ret).reason();
+ LOGV2_FATAL(22364,
+ "{Failed_to_salvage_WiredTiger_metadata_wtRCToStatus_ret_reason}",
+ "Failed_to_salvage_WiredTiger_metadata_wtRCToStatus_ret_reason"_attr =
+ "Failed to salvage WiredTiger metadata: " + wtRCToStatus(ret).reason());
fassertFailedNoTrace(50947);
}
void WiredTigerKVEngine::cleanShutdown() {
- log() << "WiredTigerKVEngine shutting down";
+ LOGV2(22317, "WiredTigerKVEngine shutting down");
if (!_readOnly)
syncSizeInfo(true);
if (!_conn) {
@@ -1042,19 +1068,19 @@ void WiredTigerKVEngine::cleanShutdown() {
// these must be the last things we do before _conn->close();
if (_sessionSweeper) {
- log() << "Shutting down session sweeper thread";
+ LOGV2(22318, "Shutting down session sweeper thread");
_sessionSweeper->shutdown();
- log() << "Finished shutting down session sweeper thread";
+ LOGV2(22319, "Finished shutting down session sweeper thread");
}
if (_journalFlusher) {
- log() << "Shutting down journal flusher thread";
+ LOGV2(22320, "Shutting down journal flusher thread");
_journalFlusher->shutdown();
- log() << "Finished shutting down journal flusher thread";
+ LOGV2(22321, "Finished shutting down journal flusher thread");
}
if (_checkpointThread) {
- log() << "Shutting down checkpoint thread";
+ LOGV2(22322, "Shutting down checkpoint thread");
_checkpointThread->shutdown();
- log() << "Finished shutting down checkpoint thread";
+ LOGV2(22323, "Finished shutting down checkpoint thread");
}
LOG_FOR_RECOVERY(2) << "Shutdown timestamps. StableTimestamp: " << _stableTimestamp.load()
<< " Initial data timestamp: " << _initialDataTimestamp.load();
@@ -1080,12 +1106,15 @@ void WiredTigerKVEngine::cleanShutdown() {
}
if (_fileVersion.shouldDowngrade(_readOnly, _inRepairMode, !_recoveryTimestamp.isNull())) {
- log() << "Downgrading WiredTiger datafiles.";
+ LOGV2(22324, "Downgrading WiredTiger datafiles.");
invariantWTOK(_conn->close(_conn, closeConfig.c_str()));
invariantWTOK(wiredtiger_open(
_path.c_str(), _eventHandler.getWtEventHandler(), _wtOpenConfig.c_str(), &_conn));
- LOG(1) << "Downgrade compatibility configuration: " << _fileVersion.getDowngradeString();
+ LOGV2_DEBUG(22325,
+ 1,
+ "Downgrade compatibility configuration: {fileVersion_getDowngradeString}",
+ "fileVersion_getDowngradeString"_attr = _fileVersion.getDowngradeString());
invariantWTOK(_conn->reconfigure(_conn, _fileVersion.getDowngradeString().c_str()));
}
@@ -1098,9 +1127,11 @@ void WiredTigerKVEngine::cleanShutdown() {
if (stableTimestamp >= initialDataTimestamp) {
invariantWTOK(_conn->close(_conn, closeConfig.c_str()));
} else {
- log() << "Skipping checkpoint during clean shutdown because stableTimestamp ("
- << stableTimestamp << ") is less than the initialDataTimestamp ("
- << initialDataTimestamp << ")";
+ LOGV2(22326,
+ "Skipping checkpoint during clean shutdown because stableTimestamp "
+ "({stableTimestamp}) is less than the initialDataTimestamp ({initialDataTimestamp})",
+ "stableTimestamp"_attr = stableTimestamp,
+ "initialDataTimestamp"_attr = initialDataTimestamp);
quickExit(EXIT_SUCCESS);
}
_conn = nullptr;
@@ -1140,7 +1171,7 @@ Status WiredTigerKVEngine::_salvageIfNeeded(const char* uri) {
int rc = (session->verify)(session, uri, nullptr);
if (rc == 0) {
- log() << "Verify succeeded on uri " << uri << ". Not salvaging.";
+ LOGV2(22327, "Verify succeeded on uri {uri}. Not salvaging.", "uri"_attr = uri);
return Status::OK();
}
@@ -1148,28 +1179,34 @@ Status WiredTigerKVEngine::_salvageIfNeeded(const char* uri) {
// SERVER-16457: verify and salvage are occasionally failing with EBUSY. For now we
// lie and return OK to avoid breaking tests. This block should go away when that ticket
// is resolved.
- error()
- << "Verify on " << uri << " failed with EBUSY. "
- << "This means the collection was being accessed. No repair is necessary unless other "
- "errors are reported.";
+ LOGV2_ERROR(22356,
+ "Verify on {uri} failed with EBUSY. This means the collection was being "
+ "accessed. No repair is necessary unless other "
+ "errors are reported.",
+ "uri"_attr = uri);
return Status::OK();
}
if (rc == ENOENT) {
- warning() << "Data file is missing for " << uri
- << ". Attempting to drop and re-create the collection.";
+ LOGV2_WARNING(
+ 22350,
+ "Data file is missing for {uri}. Attempting to drop and re-create the collection.",
+ "uri"_attr = uri);
return _rebuildIdent(session, uri);
}
- log() << "Verify failed on uri " << uri << ". Running a salvage operation.";
+ LOGV2(22328, "Verify failed on uri {uri}. Running a salvage operation.", "uri"_attr = uri);
auto status = wtRCToStatus(session->salvage(session, uri, nullptr), "Salvage failed:");
if (status.isOK()) {
return {ErrorCodes::DataModifiedByRepair, str::stream() << "Salvaged data for " << uri};
}
- warning() << "Salvage failed for uri " << uri << ": " << status.reason()
- << ". The file will be moved out of the way and a new ident will be created.";
+ LOGV2_WARNING(22351,
+ "Salvage failed for uri {uri}: {status_reason}. The file will be moved out of "
+ "the way and a new ident will be created.",
+ "uri"_attr = uri,
+ "status_reason"_attr = status.reason());
// If the data is unsalvageable, we should completely rebuild the ident.
return _rebuildIdent(session, uri);
@@ -1184,8 +1221,10 @@ Status WiredTigerKVEngine::_rebuildIdent(WT_SESSION* session, const char* uri) {
auto filePath = getDataFilePathForIdent(identName);
if (filePath) {
const boost::filesystem::path corruptFile(filePath->string() + ".corrupt");
- warning() << "Moving data file " << filePath->string() << " to backup as "
- << corruptFile.string();
+ LOGV2_WARNING(22352,
+ "Moving data file {filePath_string} to backup as {corruptFile_string}",
+ "filePath_string"_attr = filePath->string(),
+ "corruptFile_string"_attr = corruptFile.string());
auto status = fsyncRename(filePath.get(), corruptFile);
if (!status.isOK()) {
@@ -1193,34 +1232,37 @@ Status WiredTigerKVEngine::_rebuildIdent(WT_SESSION* session, const char* uri) {
}
}
- warning() << "Rebuilding ident " << identName;
+ LOGV2_WARNING(22353, "Rebuilding ident {identName}", "identName"_attr = identName);
// This is safe to call after moving the file because it only reads from the metadata, and not
// the data file itself.
auto swMetadata = WiredTigerUtil::getMetadataCreate(session, uri);
if (!swMetadata.isOK()) {
- error() << "Failed to get metadata for " << uri;
+ LOGV2_ERROR(22357, "Failed to get metadata for {uri}", "uri"_attr = uri);
return swMetadata.getStatus();
}
int rc = session->drop(session, uri, nullptr);
if (rc != 0) {
- error() << "Failed to drop " << uri;
+ LOGV2_ERROR(22358, "Failed to drop {uri}", "uri"_attr = uri);
return wtRCToStatus(rc);
}
rc = session->create(session, uri, swMetadata.getValue().c_str());
if (rc != 0) {
- error() << "Failed to create " << uri << " with config: " << swMetadata.getValue();
+ LOGV2_ERROR(22359,
+ "Failed to create {uri} with config: {swMetadata_getValue}",
+ "uri"_attr = uri,
+ "swMetadata_getValue"_attr = swMetadata.getValue());
return wtRCToStatus(rc);
}
- log() << "Successfully re-created " << uri << ".";
+ LOGV2(22329, "Successfully re-created {uri}.", "uri"_attr = uri);
return {ErrorCodes::DataModifiedByRepair,
str::stream() << "Re-created empty data file for " << uri};
}
void WiredTigerKVEngine::flushAllFiles(OperationContext* opCtx, bool callerHoldsReadLock) {
- LOG(1) << "WiredTigerKVEngine::flushAllFiles";
+ LOGV2_DEBUG(22330, 1, "WiredTigerKVEngine::flushAllFiles");
if (_ephemeral) {
return;
}
@@ -1285,7 +1327,7 @@ Status WiredTigerKVEngine::disableIncrementalBackup(OperationContext* opCtx) {
int wtRet =
session->open_cursor(session, "backup:", nullptr, "incremental=(force_stop=true)", &cursor);
if (wtRet != 0) {
- error() << "Could not open a backup cursor to disable incremental backups";
+ LOGV2_ERROR(22360, "Could not open a backup cursor to disable incremental backups");
return wtRCToStatus(wtRet);
}
@@ -1448,8 +1490,12 @@ Status WiredTigerKVEngine::createGroupedRecordStore(OperationContext* opCtx,
string uri = _uri(ident);
WT_SESSION* s = session.getSession();
- LOG(2) << "WiredTigerKVEngine::createRecordStore ns: " << ns << " uri: " << uri
- << " config: " << config;
+ LOGV2_DEBUG(22331,
+ 2,
+ "WiredTigerKVEngine::createRecordStore ns: {ns} uri: {uri} config: {config}",
+ "ns"_attr = ns,
+ "uri"_attr = uri,
+ "config"_attr = config);
return wtRCToStatus(s->create(s, uri.c_str(), config.c_str()));
}
@@ -1477,21 +1523,30 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx,
boost::filesystem::path tmpFile{*identFilePath};
tmpFile += ".tmp";
- log() << "Renaming data file " + identFilePath->string() + " to temporary file " +
- tmpFile.string();
+ LOGV2(22332,
+ "{Renaming_data_file_identFilePath_string_to_temporary_file_tmpFile_string}",
+ "Renaming_data_file_identFilePath_string_to_temporary_file_tmpFile_string"_attr =
+ "Renaming data file " + identFilePath->string() + " to temporary file " +
+ tmpFile.string());
auto status = fsyncRename(identFilePath.get(), tmpFile);
if (!status.isOK()) {
return status;
}
- log() << "Creating new RecordStore for collection " << nss << " with UUID: " << options.uuid;
+ LOGV2(22333,
+ "Creating new RecordStore for collection {nss} with UUID: {options_uuid}",
+ "nss"_attr = nss,
+ "options_uuid"_attr = options.uuid);
status = createGroupedRecordStore(opCtx, nss.ns(), ident, options, KVPrefix::kNotPrefixed);
if (!status.isOK()) {
return status;
}
- log() << "Moving orphaned data file back as " + identFilePath->string();
+ LOGV2(22334,
+ "{Moving_orphaned_data_file_back_as_identFilePath_string}",
+ "Moving_orphaned_data_file_back_as_identFilePath_string"_attr =
+ "Moving orphaned data file back as " + identFilePath->string());
boost::filesystem::remove(*identFilePath, ec);
if (ec) {
@@ -1507,7 +1562,9 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx,
return status;
}
- log() << "Salvaging ident " + ident;
+ LOGV2(22335,
+ "{Salvaging_ident_ident}",
+ "Salvaging_ident_ident"_attr = "Salvaging ident " + ident);
WiredTigerSession sessionWrapper(_conn);
WT_SESSION* session = sessionWrapper.getSession();
@@ -1517,7 +1574,9 @@ Status WiredTigerKVEngine::recoverOrphanedIdent(OperationContext* opCtx,
return {ErrorCodes::DataModifiedByRepair,
str::stream() << "Salvaged data for ident " << ident};
}
- warning() << "Could not salvage data. Rebuilding ident: " << status.reason();
+ LOGV2_WARNING(22354,
+ "Could not salvage data. Rebuilding ident: {status_reason}",
+ "status_reason"_attr = status.reason());
// If the data is unsalvageable, we should completely rebuild the ident.
return _rebuildIdent(session, _uri(ident).c_str());
@@ -1609,8 +1668,13 @@ Status WiredTigerKVEngine::createGroupedSortedDataInterface(OperationContext* op
std::string config = result.getValue();
- LOG(2) << "WiredTigerKVEngine::createSortedDataInterface ns: " << collection->ns()
- << " ident: " << ident << " config: " << config;
+ LOGV2_DEBUG(22336,
+ 2,
+ "WiredTigerKVEngine::createSortedDataInterface ns: {collection_ns} ident: {ident} "
+ "config: {config}",
+ "collection_ns"_attr = collection->ns(),
+ "ident"_attr = ident,
+ "config"_attr = config);
return wtRCToStatus(WiredTigerIndex::Create(opCtx, _uri(ident), config));
}
@@ -1639,8 +1703,11 @@ std::unique_ptr<RecordStore> WiredTigerKVEngine::makeTemporaryRecordStore(Operat
std::string uri = _uri(ident);
WT_SESSION* session = wtSession.getSession();
- LOG(2) << "WiredTigerKVEngine::createTemporaryRecordStore uri: " << uri
- << " config: " << config;
+ LOGV2_DEBUG(22337,
+ 2,
+ "WiredTigerKVEngine::createTemporaryRecordStore uri: {uri} config: {config}",
+ "uri"_attr = uri,
+ "config"_attr = config);
uassertStatusOK(wtRCToStatus(session->create(session, uri.c_str(), config.c_str())));
WiredTigerRecordStore::Params params;
@@ -1677,7 +1744,7 @@ Status WiredTigerKVEngine::dropIdent(OperationContext* opCtx, RecoveryUnit* ru,
int ret = session.getSession()->drop(
session.getSession(), uri.c_str(), "force,checkpoint_wait=false");
- LOG(1) << "WT drop of " << uri << " res " << ret;
+ LOGV2_DEBUG(22338, 1, "WT drop of {uri} res {ret}", "uri"_attr = uri, "ret"_attr = ret);
if (ret == 0) {
// yay, it worked
@@ -1759,7 +1826,11 @@ void WiredTigerKVEngine::dropSomeQueuedIdents() {
if (tenPercentQueue > 10)
numToDelete = tenPercentQueue;
- LOG(1) << "WT Queue is: " << numInQueue << " attempting to drop: " << numToDelete << " tables";
+ LOGV2_DEBUG(22339,
+ 1,
+ "WT Queue is: {numInQueue} attempting to drop: {numToDelete} tables",
+ "numInQueue"_attr = numInQueue,
+ "numToDelete"_attr = numToDelete);
for (int i = 0; i < numToDelete; i++) {
string uri;
{
@@ -1771,7 +1842,8 @@ void WiredTigerKVEngine::dropSomeQueuedIdents() {
}
int ret = session.getSession()->drop(
session.getSession(), uri.c_str(), "force,checkpoint_wait=false");
- LOG(1) << "WT queued drop of " << uri << " res " << ret;
+ LOGV2_DEBUG(
+ 22340, 1, "WT queued drop of {uri} res {ret}", "uri"_attr = uri, "ret"_attr = ret);
if (ret == EBUSY) {
stdx::lock_guard<Latch> lk(_identToDropMutex);
@@ -1865,11 +1937,14 @@ void WiredTigerKVEngine::_ensureIdentPath(StringData ident) {
boost::filesystem::path subdir = _path;
subdir /= dir.toString();
if (!boost::filesystem::exists(subdir)) {
- LOG(1) << "creating subdirectory: " << dir;
+ LOGV2_DEBUG(22341, 1, "creating subdirectory: {dir}", "dir"_attr = dir);
try {
boost::filesystem::create_directory(subdir);
} catch (const std::exception& e) {
- error() << "error creating path " << subdir.string() << ' ' << e.what();
+ LOGV2_ERROR(22361,
+ "error creating path {subdir_string} {e_what}",
+ "subdir_string"_attr = subdir.string(),
+ "e_what"_attr = e.what());
throw;
}
}
@@ -1970,14 +2045,20 @@ void WiredTigerKVEngine::setOldestTimestamp(Timestamp newOldestTimestamp, bool f
newOldestTimestamp.asULL());
invariantWTOK(_conn->set_timestamp(_conn, oldestTSConfigString.c_str()));
_oldestTimestamp.store(newOldestTimestamp.asULL());
- LOG(2) << "oldest_timestamp and commit_timestamp force set to " << newOldestTimestamp;
+ LOGV2_DEBUG(22342,
+ 2,
+ "oldest_timestamp and commit_timestamp force set to {newOldestTimestamp}",
+ "newOldestTimestamp"_attr = newOldestTimestamp);
} else {
auto oldestTSConfigString = "oldest_timestamp={:x}"_format(newOldestTimestamp.asULL());
invariantWTOK(_conn->set_timestamp(_conn, oldestTSConfigString.c_str()));
// set_timestamp above ignores backwards in time if 'force' is not set.
if (_oldestTimestamp.load() < newOldestTimestamp.asULL())
_oldestTimestamp.store(newOldestTimestamp.asULL());
- LOG(2) << "oldest_timestamp set to " << newOldestTimestamp;
+ LOGV2_DEBUG(22343,
+ 2,
+ "oldest_timestamp set to {newOldestTimestamp}",
+ "newOldestTimestamp"_attr = newOldestTimestamp);
}
}
@@ -2012,7 +2093,10 @@ Timestamp WiredTigerKVEngine::_calculateHistoryLagFromStableTimestamp(Timestamp
}
void WiredTigerKVEngine::setInitialDataTimestamp(Timestamp initialDataTimestamp) {
- LOG(2) << "Setting initial data timestamp. Value: " << initialDataTimestamp;
+ LOGV2_DEBUG(22344,
+ 2,
+ "Setting initial data timestamp. Value: {initialDataTimestamp}",
+ "initialDataTimestamp"_attr = initialDataTimestamp);
_initialDataTimestamp.store(initialDataTimestamp.asULL());
}
@@ -2038,7 +2122,7 @@ bool WiredTigerKVEngine::_canRecoverToStableTimestamp() const {
StatusWith<Timestamp> WiredTigerKVEngine::recoverToStableTimestamp(OperationContext* opCtx) {
if (!supportsRecoverToStableTimestamp()) {
- severe() << "WiredTiger is configured to not support recover to a stable timestamp";
+ LOGV2_FATAL(22365, "WiredTiger is configured to not support recover to a stable timestamp");
fassertFailed(50665);
}
@@ -2111,7 +2195,8 @@ Timestamp WiredTigerKVEngine::getOldestOpenReadTimestamp() const {
boost::optional<Timestamp> WiredTigerKVEngine::getRecoveryTimestamp() const {
if (!supportsRecoveryTimestamp()) {
- severe() << "WiredTiger is configured to not support providing a recovery timestamp";
+ LOGV2_FATAL(22366,
+ "WiredTiger is configured to not support providing a recovery timestamp");
fassertFailed(50745);
}
@@ -2157,7 +2242,10 @@ StatusWith<Timestamp> WiredTigerKVEngine::getOplogNeededForRollback() const {
if (status.isOK()) {
oldestActiveTransactionTimestamp.swap(status.getValue());
} else {
- LOG(1) << "getting oldest active transaction timestamp: " << status.getStatus();
+ LOGV2_DEBUG(22345,
+ 1,
+ "getting oldest active transaction timestamp: {status_getStatus}",
+ "status_getStatus"_attr = status.getStatus());
return status.getStatus();
}
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
index 2f818dce98a..0879d6e8a1e 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/db/storage/kv/kv_engine_test_harness.h"
@@ -45,9 +47,11 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h"
#include "mongo/logger/logger.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
+#include "mongo/util/log.h"
#include "mongo/util/log_global_settings.h"
namespace mongo {
@@ -294,8 +298,12 @@ TEST_F(WiredTigerKVEngineTest, TestOplogTruncation) {
sleepmillis(100);
}
- unittest::log() << "Expected the pinned oplog to advance. Expected value: " << newPinned
- << " Published value: " << _engine->getOplogNeededForCrashRecovery();
+ LOGV2(22367,
+ "Expected the pinned oplog to advance. Expected value: {newPinned} Published value: "
+ "{engine_getOplogNeededForCrashRecovery}",
+ "newPinned"_attr = newPinned,
+ "engine_getOplogNeededForCrashRecovery"_attr =
+ _engine->getOplogNeededForCrashRecovery());
FAIL("");
};
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
index faae62bad5e..dd4369428fc 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/log.h"
@@ -66,7 +67,10 @@ void WiredTigerOplogManager::start(OperationContext* opCtx,
// rollback before servicing oplog reads.
auto oplogVisibility = Timestamp(lastRecord->id.repr());
setOplogReadTimestamp(oplogVisibility);
- LOG(1) << "Setting oplog visibility at startup. Val: " << oplogVisibility;
+ LOGV2_DEBUG(22368,
+ 1,
+ "Setting oplog visibility at startup. Val: {oplogVisibility}",
+ "oplogVisibility"_attr = oplogVisibility);
} else {
// Avoid setting oplog visibility to 0. That means "everything is visible".
setOplogReadTimestamp(Timestamp(kMinimumTimestamp));
@@ -112,7 +116,7 @@ void WiredTigerOplogManager::waitForAllEarlierOplogWritesToBeVisible(
oplogRecordStore->getCursor(opCtx, false /* false = reverse cursor */);
auto lastRecord = cursor->next();
if (!lastRecord) {
- LOG(2) << "Trying to query an empty oplog";
+ LOGV2_DEBUG(22369, 2, "Trying to query an empty oplog");
opCtx->recoveryUnit()->abandonSnapshot();
return;
}
@@ -130,9 +134,15 @@ void WiredTigerOplogManager::waitForAllEarlierOplogWritesToBeVisible(
opCtx->waitForConditionOrInterrupt(_opsBecameVisibleCV, lk, [&] {
auto newLatestVisibleTimestamp = getOplogReadTimestamp();
if (newLatestVisibleTimestamp < currentLatestVisibleTimestamp) {
- LOG(1) << "Oplog latest visible timestamp went backwards. newLatestVisibleTimestamp: "
- << Timestamp(newLatestVisibleTimestamp) << " currentLatestVisibleTimestamp: "
- << Timestamp(currentLatestVisibleTimestamp);
+ LOGV2_DEBUG(22370,
+ 1,
+ "Oplog latest visible timestamp went backwards. newLatestVisibleTimestamp: "
+ "{Timestamp_newLatestVisibleTimestamp} currentLatestVisibleTimestamp: "
+ "{Timestamp_currentLatestVisibleTimestamp}",
+ "Timestamp_newLatestVisibleTimestamp"_attr =
+ Timestamp(newLatestVisibleTimestamp),
+ "Timestamp_currentLatestVisibleTimestamp"_attr =
+ Timestamp(currentLatestVisibleTimestamp));
// If the visibility went backwards, this means a rollback occurred.
// Thus, we are finished waiting.
return true;
@@ -140,8 +150,13 @@ void WiredTigerOplogManager::waitForAllEarlierOplogWritesToBeVisible(
currentLatestVisibleTimestamp = newLatestVisibleTimestamp;
RecordId latestVisible = RecordId(currentLatestVisibleTimestamp);
if (latestVisible < waitingFor) {
- LOG(2) << "Operation is waiting for " << Timestamp(waitingFor.repr())
- << "; latestVisible is " << Timestamp(currentLatestVisibleTimestamp);
+ LOGV2_DEBUG(22371,
+ 2,
+ "Operation is waiting for {Timestamp_waitingFor_repr}; latestVisible is "
+ "{Timestamp_currentLatestVisibleTimestamp}",
+ "Timestamp_waitingFor_repr"_attr = Timestamp(waitingFor.repr()),
+ "Timestamp_currentLatestVisibleTimestamp"_attr =
+ Timestamp(currentLatestVisibleTimestamp));
}
return latestVisible >= waitingFor;
});
@@ -212,7 +227,7 @@ void WiredTigerOplogManager::_oplogJournalThreadLoop(WiredTigerSessionCache* ses
}
if (_shuttingDown) {
- log() << "Oplog journal thread loop shutting down";
+ LOGV2(22372, "Oplog journal thread loop shutting down");
return;
}
invariant(_opsWaitingForJournal);
@@ -225,7 +240,10 @@ void WiredTigerOplogManager::_oplogJournalThreadLoop(WiredTigerSessionCache* ses
// where we commit data file changes separately from oplog changes, so ignore
// a non-incrementing timestamp.
if (newTimestamp <= _oplogReadTimestamp.load()) {
- LOG(2) << "No new oplog entries were made visible: " << Timestamp(newTimestamp);
+ LOGV2_DEBUG(22373,
+ 2,
+ "No new oplog entries were made visible: {Timestamp_newTimestamp}",
+ "Timestamp_newTimestamp"_attr = Timestamp(newTimestamp));
continue;
}
@@ -260,7 +278,10 @@ void WiredTigerOplogManager::setOplogReadTimestamp(Timestamp ts) {
void WiredTigerOplogManager::_setOplogReadTimestamp(WithLock, uint64_t newTimestamp) {
_oplogReadTimestamp.store(newTimestamp);
_opsBecameVisibleCV.notify_all();
- LOG(2) << "Setting new oplogReadTimestamp: " << Timestamp(newTimestamp);
+ LOGV2_DEBUG(22374,
+ 2,
+ "Setting new oplogReadTimestamp: {Timestamp_newTimestamp}",
+ "Timestamp_newTimestamp"_attr = Timestamp(newTimestamp));
}
uint64_t WiredTigerOplogManager::fetchAllDurableValue(WT_CONNECTION* conn) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp
index d2a25c55a4f..44a90b320da 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h"
#include "mongo/logger/parse_log_component_settings.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -50,7 +51,9 @@ Status applyMaxCacheOverflowSizeGBParameter(WiredTigerMaxCacheOverflowSizeGBPara
const auto valueMB = static_cast<size_t>(1024 * value);
- log() << "Reconfiguring WiredTiger max cache overflow size with value: \"" << valueMB << "MB\'";
+ LOGV2(22375,
+ "Reconfiguring WiredTiger max cache overflow size with value: \"{valueMB}MB\'",
+ "valueMB"_attr = valueMB);
invariant(param._data.second);
int ret = param._data.second->reconfigure(
@@ -58,7 +61,7 @@ Status applyMaxCacheOverflowSizeGBParameter(WiredTigerMaxCacheOverflowSizeGBPara
if (ret != 0) {
string result = (str::stream() << "WiredTiger reconfiguration failed with error code ("
<< ret << "): " << wiredtiger_strerror(ret));
- error() << result;
+ LOGV2_ERROR(22377, "{result}", "result"_attr = result);
return Status(ErrorCodes::BadValue, result);
}
@@ -85,14 +88,16 @@ Status WiredTigerEngineRuntimeConfigParameter::setFromString(const std::string&
<< pos));
}
- log() << "Reconfiguring WiredTiger storage engine with config string: \"" << str << "\"";
+ LOGV2(22376,
+ "Reconfiguring WiredTiger storage engine with config string: \"{str}\"",
+ "str"_attr = str);
invariant(_data.second);
int ret = _data.second->reconfigure(str.c_str());
if (ret != 0) {
string result = (str::stream() << "WiredTiger reconfiguration failed with error code ("
<< ret << "): " << wiredtiger_strerror(ret));
- error() << result;
+ LOGV2_ERROR(22378, "{result}", "result"_attr = result);
return Status(ErrorCodes::BadValue, result);
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp
index c5533e62edd..ddd979a5510 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -46,12 +47,15 @@ MONGO_FAIL_POINT_DEFINE(WTSkipPrepareConflictRetries);
MONGO_FAIL_POINT_DEFINE(WTPrintPrepareConflictLog);
void wiredTigerPrepareConflictLog(int attempts) {
- LOG(1) << "Caught WT_PREPARE_CONFLICT, attempt " << attempts
- << ". Waiting for unit of work to commit or abort.";
+ LOGV2_DEBUG(22379,
+ 1,
+ "Caught WT_PREPARE_CONFLICT, attempt {attempts}. Waiting for unit of work to "
+ "commit or abort.",
+ "attempts"_attr = attempts);
}
void wiredTigerPrepareConflictFailPointLog() {
- log() << "WTPrintPrepareConflictLog fail point enabled.";
+ LOGV2(22380, "WTPrintPrepareConflictLog fail point enabled.");
}
} // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index a409680879a..235cb8f057e 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -61,6 +61,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/fail_point.h"
@@ -261,7 +262,10 @@ void WiredTigerRecordStore::OplogStones::createNewStoneIfNeeded(RecordId lastRec
return;
}
- LOG(2) << "create new oplogStone, current stones:" << _stones.size();
+ LOGV2_DEBUG(22381,
+ 2,
+ "create new oplogStone, current stones:{stones_size}",
+ "stones_size"_attr = _stones.size());
OplogStones::Stone stone = {_currentRecords.swap(0), _currentBytes.swap(0), lastRecord};
_stones.push_back(stone);
@@ -325,14 +329,19 @@ void WiredTigerRecordStore::OplogStones::_calculateStones(OperationContext* opCt
const std::uint64_t startWaitTime = curTimeMicros64();
ON_BLOCK_EXIT([&] {
auto waitTime = curTimeMicros64() - startWaitTime;
- log() << "WiredTiger record store oplog processing took " << waitTime / 1000 << "ms";
+ LOGV2(22382,
+ "WiredTiger record store oplog processing took {waitTime_1000}ms",
+ "waitTime_1000"_attr = waitTime / 1000);
_totalTimeProcessing.fetchAndAdd(waitTime);
});
long long numRecords = _rs->numRecords(opCtx);
long long dataSize = _rs->dataSize(opCtx);
- log() << "The size storer reports that the oplog contains " << numRecords
- << " records totaling to " << dataSize << " bytes";
+ LOGV2(22383,
+ "The size storer reports that the oplog contains {numRecords} records totaling to "
+ "{dataSize} bytes",
+ "numRecords"_attr = numRecords,
+ "dataSize"_attr = dataSize);
// Don't calculate stones if this is a new collection. This is to prevent standalones from
// attempting to get a forward scanning oplog cursor on an explicit create of the oplog
@@ -366,7 +375,7 @@ void WiredTigerRecordStore::OplogStones::_calculateStones(OperationContext* opCt
void WiredTigerRecordStore::OplogStones::_calculateStonesByScanning(OperationContext* opCtx) {
_processBySampling.store(false); // process by scanning
- log() << "Scanning the oplog to determine where to place markers for truncation";
+ LOGV2(22384, "Scanning the oplog to determine where to place markers for truncation");
long long numRecords = 0;
long long dataSize = 0;
@@ -376,8 +385,11 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesByScanning(OperationCon
_currentRecords.addAndFetch(1);
int64_t newCurrentBytes = _currentBytes.addAndFetch(record->data.size());
if (newCurrentBytes >= _minBytesPerStone) {
- LOG(1) << "Placing a marker at optime "
- << Timestamp(record->id.repr()).toStringPretty();
+ LOGV2_DEBUG(22385,
+ 1,
+ "Placing a marker at optime {Timestamp_record_id_repr_Pretty}",
+ "Timestamp_record_id_repr_Pretty"_attr =
+ Timestamp(record->id.repr()).toStringPretty());
OplogStones::Stone stone = {_currentRecords.swap(0), _currentBytes.swap(0), record->id};
_stones.push_back(stone);
@@ -393,7 +405,7 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesByScanning(OperationCon
void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationContext* opCtx,
int64_t estRecordsPerStone,
int64_t estBytesPerStone) {
- log() << "Sampling the oplog to determine where to place markers for truncation";
+ LOGV2(22386, "Sampling the oplog to determine where to place markers for truncation");
_processBySampling.store(true); // process by sampling
Timestamp earliestOpTime;
Timestamp latestOpTime;
@@ -405,7 +417,8 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon
if (!record) {
// This shouldn't really happen unless the size storer values are far off from reality.
// The collection is probably empty, but fall back to scanning the oplog just in case.
- log() << "Failed to determine the earliest optime, falling back to scanning the oplog";
+ LOGV2(22387,
+ "Failed to determine the earliest optime, falling back to scanning the oplog");
_calculateStonesByScanning(opCtx);
return;
}
@@ -419,22 +432,29 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon
if (!record) {
// This shouldn't really happen unless the size storer values are far off from reality.
// The collection is probably empty, but fall back to scanning the oplog just in case.
- log() << "Failed to determine the latest optime, falling back to scanning the oplog";
+ LOGV2(22388,
+ "Failed to determine the latest optime, falling back to scanning the oplog");
_calculateStonesByScanning(opCtx);
return;
}
latestOpTime = Timestamp(record->id.repr());
}
- log() << "Sampling from the oplog between " << earliestOpTime.toStringPretty() << " and "
- << latestOpTime.toStringPretty() << " to determine where to place markers for truncation";
+ LOGV2(22389,
+ "Sampling from the oplog between {earliestOpTime_Pretty} and {latestOpTime_Pretty} to "
+ "determine where to place markers for truncation",
+ "earliestOpTime_Pretty"_attr = earliestOpTime.toStringPretty(),
+ "latestOpTime_Pretty"_attr = latestOpTime.toStringPretty());
int64_t wholeStones = _rs->numRecords(opCtx) / estRecordsPerStone;
int64_t numSamples = kRandomSamplesPerStone * _rs->numRecords(opCtx) / estRecordsPerStone;
- log() << "Taking " << numSamples << " samples and assuming that each section of oplog contains"
- << " approximately " << estRecordsPerStone << " records totaling to " << estBytesPerStone
- << " bytes";
+ LOGV2(22390,
+ "Taking {numSamples} samples and assuming that each section of oplog contains "
+ "approximately {estRecordsPerStone} records totaling to {estBytesPerStone} bytes",
+ "numSamples"_attr = numSamples,
+ "estRecordsPerStone"_attr = estRecordsPerStone,
+ "estBytesPerStone"_attr = estBytesPerStone);
// Inform the random cursor of the number of samples we intend to take. This allows it to
// account for skew in the tree shape.
@@ -455,7 +475,7 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon
if (!record) {
// This shouldn't really happen unless the size storer values are far off from reality.
// The collection is probably empty, but fall back to scanning the oplog just in case.
- log() << "Failed to get enough random samples, falling back to scanning the oplog";
+ LOGV2(22391, "Failed to get enough random samples, falling back to scanning the oplog");
_calculateStonesByScanning(opCtx);
return;
}
@@ -464,13 +484,15 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon
const auto now = Date_t::now();
if (samplingLogIntervalSeconds > 0 &&
now - lastProgressLog >= Seconds(samplingLogIntervalSeconds)) {
- log() << "Oplog sampling progress: " << (i + 1) << " of " << numSamples
- << " samples taken";
+ LOGV2(22392,
+ "Oplog sampling progress: {i_1} of {numSamples} samples taken",
+ "i_1"_attr = (i + 1),
+ "numSamples"_attr = numSamples);
lastProgressLog = now;
}
}
std::sort(oplogEstimates.begin(), oplogEstimates.end());
- log() << "Oplog sampling complete";
+ LOGV2(22393, "Oplog sampling complete");
for (int i = 1; i <= wholeStones; ++i) {
// Use every (kRandomSamplesPerStone)th sample, starting with the
@@ -478,7 +500,10 @@ void WiredTigerRecordStore::OplogStones::_calculateStonesBySampling(OperationCon
int sampleIndex = kRandomSamplesPerStone * i - 1;
RecordId lastRecord = oplogEstimates[sampleIndex];
- log() << "Placing a marker at optime " << Timestamp(lastRecord.repr()).toStringPretty();
+ LOGV2(22394,
+ "Placing a marker at optime {Timestamp_lastRecord_repr_Pretty}",
+ "Timestamp_lastRecord_repr_Pretty"_attr =
+ Timestamp(lastRecord.repr()).toStringPretty());
OplogStones::Stone stone = {estRecordsPerStone, estBytesPerStone, lastRecord};
_stones.push_back(stone);
}
@@ -755,9 +780,12 @@ WiredTigerRecordStore::~WiredTigerRecordStore() {
}
if (!isTemp()) {
- LOG(1) << "~WiredTigerRecordStore for: " << ns();
+ LOGV2_DEBUG(22395, 1, "~WiredTigerRecordStore for: {ns}", "ns"_attr = ns());
} else {
- LOG(1) << "~WiredTigerRecordStore for temporary ident: " << getIdent();
+ LOGV2_DEBUG(22396,
+ 1,
+ "~WiredTigerRecordStore for temporary ident: {getIdent}",
+ "getIdent"_attr = getIdent());
}
if (_oplogStones) {
@@ -1174,7 +1202,7 @@ int64_t WiredTigerRecordStore::_cappedDeleteAsNeeded_inlock(OperationContext* op
if (ret == ENOENT || ret == WT_NOTFOUND) {
// TODO we should remove this case once SERVER-17141 is resolved
- log() << "Soft failure truncating capped collection. Will try again later.";
+ LOGV2(22397, "Soft failure truncating capped collection. Will try again later.");
docsRemoved = 0;
} else {
invariantWTOK(ret);
@@ -1188,7 +1216,7 @@ int64_t WiredTigerRecordStore::_cappedDeleteAsNeeded_inlock(OperationContext* op
} catch (const WriteConflictException&) {
opCtx->releaseRecoveryUnit();
opCtx->setRecoveryUnit(std::unique_ptr<RecoveryUnit>(realRecoveryUnit), realRUstate);
- log() << "got conflict truncating capped, ignoring";
+ LOGV2(22398, "got conflict truncating capped, ignoring");
return 0;
} catch (...) {
opCtx->releaseRecoveryUnit();
@@ -1243,9 +1271,15 @@ void WiredTigerRecordStore::reclaimOplog(OperationContext* opCtx, Timestamp mayT
return;
}
- LOG(1) << "Truncating the oplog between " << _oplogStones->firstRecord << " and "
- << stone->lastRecord << " to remove approximately " << stone->records
- << " records totaling to " << stone->bytes << " bytes";
+ LOGV2_DEBUG(
+ 22399,
+ 1,
+ "Truncating the oplog between {oplogStones_firstRecord} and {stone_lastRecord} to "
+ "remove approximately {stone_records} records totaling to {stone_bytes} bytes",
+ "oplogStones_firstRecord"_attr = _oplogStones->firstRecord,
+ "stone_lastRecord"_attr = stone->lastRecord,
+ "stone_records"_attr = stone->records,
+ "stone_bytes"_attr = stone->bytes);
WiredTigerRecoveryUnit* ru = WiredTigerRecoveryUnit::get(opCtx);
WT_SESSION* session = ru->getSession()->getSession();
@@ -1261,8 +1295,12 @@ void WiredTigerRecordStore::reclaimOplog(OperationContext* opCtx, Timestamp mayT
invariantWTOK(ret);
RecordId firstRecord = getKey(cursor);
if (firstRecord < _oplogStones->firstRecord || firstRecord > stone->lastRecord) {
- warning() << "First oplog record " << firstRecord << " is not in truncation range ("
- << _oplogStones->firstRecord << ", " << stone->lastRecord << ")";
+ LOGV2_WARNING(22407,
+ "First oplog record {firstRecord} is not in truncation range "
+ "({oplogStones_firstRecord}, {stone_lastRecord})",
+ "firstRecord"_attr = firstRecord,
+ "oplogStones_firstRecord"_attr = _oplogStones->firstRecord,
+ "stone_lastRecord"_attr = stone->lastRecord);
}
setKey(cursor, stone->lastRecord);
@@ -1279,18 +1317,24 @@ void WiredTigerRecordStore::reclaimOplog(OperationContext* opCtx, Timestamp mayT
_oplogStones->firstRecord = stone->lastRecord;
_cappedFirstRecord = stone->lastRecord;
} catch (const WriteConflictException&) {
- LOG(1) << "Caught WriteConflictException while truncating oplog entries, retrying";
+ LOGV2_DEBUG(
+ 22400, 1, "Caught WriteConflictException while truncating oplog entries, retrying");
}
}
- LOG(1) << "Finished truncating the oplog, it now contains approximately "
- << _sizeInfo->numRecords.load() << " records totaling to " << _sizeInfo->dataSize.load()
- << " bytes";
+ LOGV2_DEBUG(22401,
+ 1,
+ "Finished truncating the oplog, it now contains approximately "
+ "{sizeInfo_numRecords_load} records totaling to {sizeInfo_dataSize_load} bytes",
+ "sizeInfo_numRecords_load"_attr = _sizeInfo->numRecords.load(),
+ "sizeInfo_dataSize_load"_attr = _sizeInfo->dataSize.load());
auto elapsedMicros = timer.micros();
auto elapsedMillis = elapsedMicros / 1000;
_totalTimeTruncating.fetchAndAdd(elapsedMicros);
_truncateCount.fetchAndAdd(1);
- log() << "WiredTiger record store oplog truncation finished in: " << elapsedMillis << "ms";
+ LOGV2(22402,
+ "WiredTiger record store oplog truncation finished in: {elapsedMillis}ms",
+ "elapsedMillis"_attr = elapsedMillis);
}
Status WiredTigerRecordStore::insertRecords(OperationContext* opCtx,
@@ -1353,7 +1397,7 @@ Status WiredTigerRecordStore::_insertRecords(OperationContext* opCtx,
ts = timestamps[i];
}
if (!ts.isNull()) {
- LOG(4) << "inserting record with timestamp " << ts;
+ LOGV2_DEBUG(22403, 4, "inserting record with timestamp {ts}", "ts"_attr = ts);
fassert(39001, opCtx->recoveryUnit()->setTimestamp(ts));
}
setKey(c, record.id);
@@ -1617,7 +1661,7 @@ void WiredTigerRecordStore::validate(OperationContext* opCtx,
<< "This is a transient issue as the collection was actively "
"in use by other operations.";
- warning() << msg;
+ LOGV2_WARNING(22408, "{msg}", "msg"_attr = msg);
results->warnings.push_back(msg);
return;
}
@@ -1625,7 +1669,7 @@ void WiredTigerRecordStore::validate(OperationContext* opCtx,
std::string msg = str::stream() << "verify() returned " << wiredtiger_strerror(err) << ". "
<< "This indicates structural damage. "
<< "Not examining individual documents.";
- error() << msg;
+ LOGV2_ERROR(22409, "{msg}", "msg"_attr = msg);
results->errors.push_back(msg);
results->valid = false;
}
@@ -1778,7 +1822,10 @@ public:
NumRecordsChange(WiredTigerRecordStore* rs, int64_t diff) : _rs(rs), _diff(diff) {}
virtual void commit(boost::optional<Timestamp>) {}
virtual void rollback() {
- LOG(3) << "WiredTigerRecordStore: rolling back NumRecordsChange " << -_diff;
+ LOGV2_DEBUG(22404,
+ 3,
+ "WiredTigerRecordStore: rolling back NumRecordsChange {diff}",
+ "diff"_attr = -_diff);
_rs->_sizeInfo->numRecords.fetchAndAdd(-_diff);
}
@@ -1912,7 +1959,7 @@ void WiredTigerRecordStore::cappedTruncateAfter(OperationContext* opCtx,
}
_kvEngine->getOplogManager()->setOplogReadTimestamp(truncTs);
- LOG(1) << "truncation new read timestamp: " << truncTs;
+ LOGV2_DEBUG(22405, 1, "truncation new read timestamp: {truncTs}", "truncTs"_attr = truncTs);
}
if (_oplogStones) {
@@ -1992,9 +2039,11 @@ boost::optional<Record> WiredTigerRecordStoreCursorBase::next() {
}
if (_forward && _lastReturnedId >= id) {
- log() << "WTCursor::next -- c->next_key ( " << id
- << ") was not greater than _lastReturnedId (" << _lastReturnedId
- << ") which is a bug.";
+ LOGV2(22406,
+ "WTCursor::next -- c->next_key ( {id}) was not greater than _lastReturnedId "
+ "({lastReturnedId}) which is a bug.",
+ "id"_attr = id,
+ "lastReturnedId"_attr = _lastReturnedId);
// Crash when test commands are enabled.
invariant(!getTestCommandsEnabled());
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index 8d1fe8821ff..604297cdf48 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_prepare_conflict.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
@@ -221,7 +222,10 @@ void WiredTigerRecoveryUnit::prepareUnitOfWork() {
auto session = getSession();
WT_SESSION* s = session->getSession();
- LOG(1) << "preparing transaction at time: " << _prepareTimestamp;
+ LOGV2_DEBUG(22410,
+ 1,
+ "preparing transaction at time: {prepareTimestamp}",
+ "prepareTimestamp"_attr = _prepareTimestamp);
const std::string conf = "prepare_timestamp=" + integerToHex(_prepareTimestamp.asULL());
// Prepare the transaction.
@@ -280,7 +284,9 @@ void WiredTigerRecoveryUnit::assertInActiveTxn() const {
if (_isActive()) {
return;
}
- severe() << "Recovery unit is not active. Current state: " << toString(_getState());
+ LOGV2_FATAL(22417,
+ "Recovery unit is not active. Current state: {getState}",
+ "getState"_attr = toString(_getState()));
fassertFailed(28575);
}
@@ -333,9 +339,12 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) {
// `serverGlobalParams.slowMs` can be set to values <= 0. In those cases, give logging a
// break.
if (transactionTime >= std::max(1, serverGlobalParams.slowMS)) {
- LOG(kSlowTransactionSeverity)
- << "Slow WT transaction. Lifetime of SnapshotId " << getSnapshotId().toNumber()
- << " was " << transactionTime << "ms";
+ LOGV2_DEBUG(22411,
+ logSeverityV1toV2(kSlowTransactionSeverity).toInt(),
+ "Slow WT transaction. Lifetime of SnapshotId {getSnapshotId_toNumber} was "
+ "{transactionTime}ms",
+ "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber(),
+ "transactionTime"_attr = transactionTime);
}
}
@@ -360,11 +369,17 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) {
}
wtRet = s->commit_transaction(s, conf.str().c_str());
- LOG(3) << "WT commit_transaction for snapshot id " << getSnapshotId().toNumber();
+ LOGV2_DEBUG(22412,
+ 3,
+ "WT commit_transaction for snapshot id {getSnapshotId_toNumber}",
+ "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber());
} else {
wtRet = s->rollback_transaction(s, nullptr);
invariant(!wtRet);
- LOG(3) << "WT rollback_transaction for snapshot id " << getSnapshotId().toNumber();
+ LOGV2_DEBUG(22413,
+ 3,
+ "WT rollback_transaction for snapshot id {getSnapshotId_toNumber}",
+ "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber());
}
if (_isTimestamped) {
@@ -543,7 +558,10 @@ void WiredTigerRecoveryUnit::_txnOpen() {
}
}
- LOG(3) << "WT begin_transaction for snapshot id " << getSnapshotId().toNumber();
+ LOGV2_DEBUG(22414,
+ 3,
+ "WT begin_transaction for snapshot id {getSnapshotId_toNumber}",
+ "getSnapshotId_toNumber"_attr = getSnapshotId().toNumber());
}
Timestamp WiredTigerRecoveryUnit::_beginTransactionAtAllDurableTimestamp(WT_SESSION* session) {
@@ -619,7 +637,10 @@ Timestamp WiredTigerRecoveryUnit::_getTransactionReadTimestamp(WT_SESSION* sessi
Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) {
_ensureSession();
- LOG(3) << "WT set timestamp of future write operations to " << timestamp;
+ LOGV2_DEBUG(22415,
+ 3,
+ "WT set timestamp of future write operations to {timestamp}",
+ "timestamp"_attr = timestamp);
WT_SESSION* session = _session->getSession();
invariant(_inUnitOfWork(), toString(_getState()));
invariant(_prepareTimestamp.isNull());
@@ -746,8 +767,12 @@ void WiredTigerRecoveryUnit::setRoundUpPreparedTimestamps(bool value) {
void WiredTigerRecoveryUnit::setTimestampReadSource(ReadSource readSource,
boost::optional<Timestamp> provided) {
- LOG(3) << "setting timestamp read source: " << static_cast<int>(readSource)
- << ", provided timestamp: " << ((provided) ? provided->toString() : "none");
+ LOGV2_DEBUG(22416,
+ 3,
+ "setting timestamp read source: {static_cast_int_readSource}, provided timestamp: "
+ "{provided_provided_none}",
+ "static_cast_int_readSource"_attr = static_cast<int>(readSource),
+ "provided_provided_none"_attr = ((provided) ? provided->toString() : "none"));
invariant(!_isActive() || _timestampReadSource == readSource,
str::stream() << "Current state: " << toString(_getState())
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp
index d02e5aeb59f..208b426853c 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -104,8 +105,10 @@ void _openCursor(WT_SESSION* session,
uasserted(ErrorCodes::CursorNotFound, cursorErrMsg);
}
- error() << cursorErrMsg;
- error() << "This may be due to data corruption. " << kWTRepairMsg;
+ LOGV2_ERROR(22421, "{cursorErrMsg}", "cursorErrMsg"_attr = cursorErrMsg);
+ LOGV2_ERROR(22422,
+ "This may be due to data corruption. {kWTRepairMsg}",
+ "kWTRepairMsg"_attr = kWTRepairMsg);
fassertFailedNoTrace(50882);
}
@@ -294,7 +297,7 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx,
_journalListener->onDurable(token.get());
}
}
- LOG(4) << "created checkpoint (forced)";
+ LOGV2_DEBUG(22418, 4, "created checkpoint (forced)");
return;
}
@@ -330,12 +333,12 @@ void WiredTigerSessionCache::waitUntilDurable(OperationContext* opCtx,
// Use the journal when available, or a checkpoint otherwise.
if (_engine && _engine->isDurable()) {
invariantWTOK(_waitUntilDurableSession->log_flush(_waitUntilDurableSession, "sync=on"));
- LOG(4) << "flushed journal";
+ LOGV2_DEBUG(22419, 4, "flushed journal");
} else {
auto checkpointLock = _engine->getCheckpointLock(opCtx);
_engine->clearIndividuallyCheckpointedIndexesList();
invariantWTOK(_waitUntilDurableSession->checkpoint(_waitUntilDurableSession, nullptr));
- LOG(4) << "created checkpoint";
+ LOGV2_DEBUG(22420, 4, "created checkpoint");
}
if (token) {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp
index e0847eb0444..64a79fbc05c 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_size_storer.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -82,9 +83,15 @@ void WiredTigerSizeStorer::store(StringData uri, std::shared_ptr<SizeInfo> sizeI
entry->_dirty.store(false);
entry = sizeInfo;
entry->_dirty.store(true);
- LOG(2) << "WiredTigerSizeStorer::store Marking " << uri
- << " dirty, numRecords: " << sizeInfo->numRecords.load()
- << ", dataSize: " << sizeInfo->dataSize.load() << ", use_count: " << entry.use_count();
+ LOGV2_DEBUG(
+ 22423,
+ 2,
+ "WiredTigerSizeStorer::store Marking {uri} dirty, numRecords: {sizeInfo_numRecords_load}, "
+ "dataSize: {sizeInfo_dataSize_load}, use_count: {entry_use_count}",
+ "uri"_attr = uri,
+ "sizeInfo_numRecords_load"_attr = sizeInfo->numRecords.load(),
+ "sizeInfo_dataSize_load"_attr = sizeInfo->dataSize.load(),
+ "entry_use_count"_attr = entry.use_count());
}
std::shared_ptr<WiredTigerSizeStorer::SizeInfo> WiredTigerSizeStorer::load(StringData uri) const {
@@ -115,7 +122,11 @@ std::shared_ptr<WiredTigerSizeStorer::SizeInfo> WiredTigerSizeStorer::load(Strin
invariantWTOK(_cursor->get_value(_cursor, &value));
BSONObj data(reinterpret_cast<const char*>(value.data));
- LOG(2) << "WiredTigerSizeStorer::load " << uri << " -> " << redact(data);
+ LOGV2_DEBUG(22424,
+ 2,
+ "WiredTigerSizeStorer::load {uri} -> {data}",
+ "uri"_attr = uri,
+ "data"_attr = redact(data));
return std::make_shared<SizeInfo>(data["numRecords"].safeNumberLong(),
data["dataSize"].safeNumberLong());
}
@@ -157,7 +168,11 @@ void WiredTigerSizeStorer::flush(bool syncToDisk) {
<< sizeInfo.dataSize.load());
auto& uri = it->first;
- LOG(2) << "WiredTigerSizeStorer::flush " << uri << " -> " << redact(data);
+ LOGV2_DEBUG(22425,
+ 2,
+ "WiredTigerSizeStorer::flush {uri} -> {data}",
+ "uri"_attr = uri,
+ "data"_attr = redact(data));
WiredTigerItem key(uri.c_str(), uri.size());
WiredTigerItem value(data.objdata(), data.objsize());
_cursor->set_key(_cursor, key.Get());
@@ -170,6 +185,6 @@ void WiredTigerSizeStorer::flush(bool syncToDisk) {
}
auto micros = t.micros();
- LOG(2) << "WiredTigerSizeStorer flush took " << micros << " µs";
+ LOGV2_DEBUG(22426, 2, "WiredTigerSizeStorer flush took {micros} µs", "micros"_attr = micros);
}
} // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp
index dd7c6ce52b5..d7598300171 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_snapshot_manager.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_begin_transaction_block.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_util.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -101,7 +102,10 @@ Timestamp WiredTigerSnapshotManager::beginTransactionOnLocalSnapshot(
stdx::lock_guard<Latch> lock(_localSnapshotMutex);
invariant(_localSnapshot);
- LOG(3) << "begin_transaction on local snapshot " << _localSnapshot.get().toString();
+ LOGV2_DEBUG(22427,
+ 3,
+ "begin_transaction on local snapshot {localSnapshot_get}",
+ "localSnapshot_get"_attr = _localSnapshot.get().toString());
auto status = txnOpen.setReadSnapshot(_localSnapshot.get());
fassert(50775, status);
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
index cdb40992c26..8b72cbf94a0 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/processinfo.h"
@@ -144,7 +145,7 @@ StatusWith<std::string> WiredTigerUtil::getMetadataCreate(OperationContext* opCt
cursor = session->getCachedCursor(
"metadata:create", WiredTigerSession::kMetadataCreateTableId, NULL);
} catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) {
- error() << ex;
+ LOGV2_ERROR(22433, "{ex}", "ex"_attr = ex);
fassertFailedNoTrace(51257);
}
invariant(cursor);
@@ -171,7 +172,7 @@ StatusWith<std::string> WiredTigerUtil::getMetadata(OperationContext* opCtx, Str
try {
cursor = session->getCachedCursor("metadata:", WiredTigerSession::kMetadataTableId, NULL);
} catch (const ExceptionFor<ErrorCodes::CursorNotFound>& ex) {
- error() << ex;
+ LOGV2_ERROR(22434, "{ex}", "ex"_attr = ex);
fassertFailedNoTrace(31293);
}
invariant(cursor);
@@ -291,9 +292,14 @@ StatusWith<int64_t> WiredTigerUtil::checkApplicationMetadataFormatVersion(Operat
<< " has unsupported format version: " << version << ".");
}
- LOG(2) << "WiredTigerUtil::checkApplicationMetadataFormatVersion "
- << " uri: " << uri << " ok range " << minimumVersion << " -> " << maximumVersion
- << " current: " << version;
+ LOGV2_DEBUG(22428,
+ 2,
+ "WiredTigerUtil::checkApplicationMetadataFormatVersion uri: {uri} ok range "
+ "{minimumVersion} -> {maximumVersion} current: {version}",
+ "uri"_attr = uri,
+ "minimumVersion"_attr = minimumVersion,
+ "maximumVersion"_attr = maximumVersion,
+ "version"_attr = version);
return version;
}
@@ -394,8 +400,10 @@ size_t WiredTigerUtil::getCacheSizeMB(double requestedCacheSizeGB) {
cacheSizeMB = 1024 * requestedCacheSizeGB;
}
if (cacheSizeMB > kMaxSizeCacheMB) {
- log() << "Requested cache size: " << cacheSizeMB << "MB exceeds max; setting to "
- << kMaxSizeCacheMB << "MB";
+ LOGV2(22429,
+ "Requested cache size: {cacheSizeMB}MB exceeds max; setting to {kMaxSizeCacheMB}MB",
+ "cacheSizeMB"_attr = cacheSizeMB,
+ "kMaxSizeCacheMB"_attr = kMaxSizeCacheMB);
cacheSizeMB = kMaxSizeCacheMB;
}
return static_cast<size_t>(cacheSizeMB);
@@ -418,8 +426,11 @@ int mdb_handle_error_with_startup_suppression(WT_EVENT_HANDLER* handler,
return 0;
}
}
- error() << "WiredTiger error (" << errorCode << ") " << redact(message)
- << " Raw: " << message;
+ LOGV2_ERROR(22435,
+ "WiredTiger error ({errorCode}) {message} Raw: {message2}",
+ "errorCode"_attr = errorCode,
+ "message"_attr = redact(message),
+ "message2"_attr = message);
// Don't abort on WT_PANIC when repairing, as the error will be handled at a higher layer.
if (storageGlobalParams.repair) {
@@ -437,7 +448,10 @@ int mdb_handle_error(WT_EVENT_HANDLER* handler,
int errorCode,
const char* message) {
try {
- error() << "WiredTiger error (" << errorCode << ") " << redact(message);
+ LOGV2_ERROR(22436,
+ "WiredTiger error ({errorCode}) {message}",
+ "errorCode"_attr = errorCode,
+ "message"_attr = redact(message));
// Don't abort on WT_PANIC when repairing, as the error will be handled at a higher layer.
if (storageGlobalParams.repair) {
@@ -452,7 +466,7 @@ int mdb_handle_error(WT_EVENT_HANDLER* handler,
int mdb_handle_message(WT_EVENT_HANDLER* handler, WT_SESSION* session, const char* message) {
try {
- log() << "WiredTiger message " << redact(message);
+ LOGV2(22430, "WiredTiger message {message}", "message"_attr = redact(message));
} catch (...) {
std::terminate();
}
@@ -464,7 +478,10 @@ int mdb_handle_progress(WT_EVENT_HANDLER* handler,
const char* operation,
uint64_t progress) {
try {
- log() << "WiredTiger progress " << redact(operation) << " " << progress;
+ LOGV2(22431,
+ "WiredTiger progress {operation} {progress}",
+ "operation"_attr = redact(operation),
+ "progress"_attr = progress);
} catch (...) {
std::terminate();
}
@@ -603,12 +620,21 @@ Status WiredTigerUtil::setTableLogging(WT_SESSION* session, const std::string& u
return Status::OK();
}
- LOG(1) << "Changing table logging settings. Uri: " << uri << " Enable? " << on;
+ LOGV2_DEBUG(22432,
+ 1,
+ "Changing table logging settings. Uri: {uri} Enable? {on}",
+ "uri"_attr = uri,
+ "on"_attr = on);
int ret = session->alter(session, uri.c_str(), setting.c_str());
if (ret) {
- severe() << "Failed to update log setting. Uri: " << uri << " Enable? " << on
- << " Ret: " << ret << " MD: " << redact(existingMetadata)
- << " Msg: " << session->strerror(session, ret);
+ LOGV2_FATAL(22437,
+ "Failed to update log setting. Uri: {uri} Enable? {on} Ret: {ret} MD: "
+ "{existingMetadata} Msg: {session_strerror_session_ret}",
+ "uri"_attr = uri,
+ "on"_attr = on,
+ "ret"_attr = ret,
+ "existingMetadata"_attr = redact(existingMetadata),
+ "session_strerror_session_ret"_attr = session->strerror(session, ret));
fassertFailed(50756);
}
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp
index dfafa0e46a1..45fa2c2c457 100644
--- a/src/mongo/db/system_index.cpp
+++ b/src/mongo/db/system_index.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/index_builds_coordinator.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/storage/storage_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -106,15 +107,21 @@ void generateSystemIndexForExistingCollection(OperationContext* opCtx,
opCtx, spec.toBSON(), serverGlobalParams.featureCompatibility);
BSONObj indexSpec = fassert(40452, indexSpecStatus);
- log() << "No authorization index detected on " << ns
- << " collection. Attempting to recover by creating an index with spec: " << indexSpec;
+ LOGV2(22488,
+ "No authorization index detected on {ns} collection. Attempting to recover by "
+ "creating an index with spec: {indexSpec}",
+ "ns"_attr = ns,
+ "indexSpec"_attr = indexSpec);
auto indexConstraints = IndexBuildsManager::IndexConstraints::kEnforce;
auto fromMigrate = false;
IndexBuildsCoordinator::get(opCtx)->createIndexes(
opCtx, collectionUUID, {indexSpec}, indexConstraints, fromMigrate);
} catch (const DBException& e) {
- severe() << "Failed to regenerate index for " << ns << ". Exception: " << e.what();
+ LOGV2_FATAL(22490,
+ "Failed to regenerate index for {ns}. Exception: {e_what}",
+ "ns"_attr = ns,
+ "e_what"_attr = e.what());
throw;
}
}
@@ -124,7 +131,8 @@ void generateSystemIndexForExistingCollection(OperationContext* opCtx,
Status verifySystemIndexes(OperationContext* opCtx) {
// Do not try and generate any system indexes in read only mode.
if (storageGlobalParams.readOnly) {
- warning() << "Running in queryable backup mode. Unable to create authorization indexes";
+ LOGV2_WARNING(22489,
+ "Running in queryable backup mode. Unable to create authorization indexes");
return Status::OK();
}
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 3c9dfa78395..3cea8461baa 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -63,6 +63,7 @@
#include "mongo/db/stats/fill_locker_info.h"
#include "mongo/db/transaction_history_iterator.h"
#include "mongo/db/transaction_participant_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
#include "mongo/util/log_with_sampling.h"
@@ -97,11 +98,16 @@ void fassertOnRepeatedExecution(const LogicalSessionId& lsid,
StmtId stmtId,
const repl::OpTime& firstOpTime,
const repl::OpTime& secondOpTime) {
- severe() << "Statement id " << stmtId << " from transaction [ " << lsid.toBSON() << ":"
- << txnNumber << " ] was committed once with opTime " << firstOpTime
- << " and a second time with opTime " << secondOpTime
- << ". This indicates possible data corruption or server bug and the process will be "
- "terminated.";
+ LOGV2_FATAL(22524,
+ "Statement id {stmtId} from transaction [ {lsid}:{txnNumber} ] was committed once "
+ "with opTime {firstOpTime} and a second time with opTime {secondOpTime}. This "
+ "indicates possible data corruption or server bug and the process will be "
+ "terminated.",
+ "stmtId"_attr = stmtId,
+ "lsid"_attr = lsid.toBSON(),
+ "txnNumber"_attr = txnNumber,
+ "firstOpTime"_attr = firstOpTime,
+ "secondOpTime"_attr = secondOpTime);
fassertFailed(40526);
}
@@ -654,9 +660,9 @@ TransactionParticipant::OplogSlotReserver::OplogSlotReserver(OperationContext* o
TransactionParticipant::OplogSlotReserver::~OplogSlotReserver() {
if (MONGO_unlikely(hangBeforeReleasingTransactionOplogHole.shouldFail())) {
- log()
- << "transaction - hangBeforeReleasingTransactionOplogHole fail point enabled. Blocking "
- "until fail point is disabled.";
+ LOGV2(22520,
+ "transaction - hangBeforeReleasingTransactionOplogHole fail point enabled. Blocking "
+ "until fail point is disabled.");
hangBeforeReleasingTransactionOplogHole.pauseWhileSet();
}
@@ -1071,9 +1077,12 @@ Timestamp TransactionParticipant::Participant::prepareTransaction(
} catch (...) {
// It is illegal for aborting a prepared transaction to fail for any reason, so we crash
// instead.
- severe() << "Caught exception during abort of prepared transaction "
- << opCtx->getTxnNumber() << " on " << _sessionId().toBSON() << ": "
- << exceptionToStatus();
+ LOGV2_FATAL(22525,
+ "Caught exception during abort of prepared transaction "
+ "{opCtx_getTxnNumber} on {sessionId}: {exceptionToStatus}",
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(),
+ "sessionId"_attr = _sessionId().toBSON(),
+ "exceptionToStatus"_attr = exceptionToStatus());
std::terminate();
}
});
@@ -1135,9 +1144,11 @@ Timestamp TransactionParticipant::Participant::prepareTransaction(
if (MONGO_unlikely(hangAfterReservingPrepareTimestamp.shouldFail())) {
// This log output is used in js tests so please leave it.
- log() << "transaction - hangAfterReservingPrepareTimestamp fail point "
- "enabled. Blocking until fail point is disabled. Prepare OpTime: "
- << prepareOplogSlot;
+ LOGV2(22521,
+ "transaction - hangAfterReservingPrepareTimestamp fail point "
+ "enabled. Blocking until fail point is disabled. Prepare OpTime: "
+ "{prepareOplogSlot}",
+ "prepareOplogSlot"_attr = prepareOplogSlot);
hangAfterReservingPrepareTimestamp.pauseWhileSet();
}
}
@@ -1163,8 +1174,9 @@ Timestamp TransactionParticipant::Participant::prepareTransaction(
}
if (MONGO_unlikely(hangAfterSettingPrepareStartTime.shouldFail())) {
- log() << "transaction - hangAfterSettingPrepareStartTime fail point enabled. Blocking "
- "until fail point is disabled.";
+ LOGV2(22522,
+ "transaction - hangAfterSettingPrepareStartTime fail point enabled. Blocking "
+ "until fail point is disabled.");
hangAfterSettingPrepareStartTime.pauseWhileSet();
}
@@ -1390,9 +1402,12 @@ void TransactionParticipant::Participant::commitPreparedTransaction(
} catch (...) {
// It is illegal for committing a prepared transaction to fail for any reason, other than an
// invalid command, so we crash instead.
- severe() << "Caught exception during commit of prepared transaction "
- << opCtx->getTxnNumber() << " on " << _sessionId().toBSON() << ": "
- << exceptionToStatus();
+ LOGV2_FATAL(22526,
+ "Caught exception during commit of prepared transaction {opCtx_getTxnNumber} "
+ "on {sessionId}: {exceptionToStatus}",
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(),
+ "sessionId"_attr = _sessionId().toBSON(),
+ "exceptionToStatus"_attr = exceptionToStatus());
std::terminate();
}
}
@@ -1518,10 +1533,12 @@ void TransactionParticipant::Participant::_abortActiveTransaction(
} catch (...) {
// It is illegal for aborting a transaction that must write an abort oplog entry to fail
// after aborting the storage transaction, so we crash instead.
- severe()
- << "Caught exception during abort of transaction that must write abort oplog entry "
- << opCtx->getTxnNumber() << " on " << _sessionId().toBSON() << ": "
- << exceptionToStatus();
+ LOGV2_FATAL(22527,
+ "Caught exception during abort of transaction that must write abort oplog "
+ "entry {opCtx_getTxnNumber} on {sessionId}: {exceptionToStatus}",
+ "opCtx_getTxnNumber"_attr = opCtx->getTxnNumber(),
+ "sessionId"_attr = _sessionId().toBSON(),
+ "exceptionToStatus"_attr = exceptionToStatus());
std::terminate();
}
} else {
@@ -1901,9 +1918,13 @@ void TransactionParticipant::Participant::_logSlowTransaction(
opDuration,
Milliseconds(serverGlobalParams.slowMS))
.first) {
- log(logger::LogComponent::kTransaction)
- << "transaction "
- << _transactionInfoForLog(opCtx, lockStats, terminationCause, readConcernArgs);
+ LOGV2_OPTIONS(
+ 22523,
+ {logComponentV1toV2(logger::LogComponent::kTransaction)},
+ "transaction "
+ "{transactionInfoForLog_opCtx_lockStats_terminationCause_readConcernArgs}",
+ "transactionInfoForLog_opCtx_lockStats_terminationCause_readConcernArgs"_attr =
+ _transactionInfoForLog(opCtx, lockStats, terminationCause, readConcernArgs));
}
}
}
diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp
index be0ca3fd9c2..d3668ab3dd6 100644
--- a/src/mongo/db/ttl.cpp
+++ b/src/mongo/db/ttl.cpp
@@ -54,6 +54,7 @@
#include "mongo/db/storage/durable_catalog.h"
#include "mongo/db/ttl_collection_cache.h"
#include "mongo/db/ttl_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/background.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
@@ -96,26 +97,29 @@ public:
sleepsecs(ttlMonitorSleepSecs.load());
}
- LOG(3) << "thread awake";
+ LOGV2_DEBUG(22528, 3, "thread awake");
if (!ttlMonitorEnabled.load()) {
- LOG(1) << "disabled";
+ LOGV2_DEBUG(22529, 1, "disabled");
continue;
}
if (lockedForWriting()) {
// Note: this is not perfect as you can go into fsync+lock between this and actually
// doing the delete later.
- LOG(3) << "locked for writing";
+ LOGV2_DEBUG(22530, 3, "locked for writing");
continue;
}
try {
doTTLPass();
} catch (const WriteConflictException&) {
- LOG(1) << "got WriteConflictException";
+ LOGV2_DEBUG(22531, 1, "got WriteConflictException");
} catch (const ExceptionForCat<ErrorCategory::Interruption>& interruption) {
- LOG(1) << "TTLMonitor was interrupted: " << interruption;
+ LOGV2_DEBUG(22532,
+ 1,
+ "TTLMonitor was interrupted: {interruption}",
+ "interruption"_attr = interruption);
}
}
}
@@ -181,11 +185,16 @@ private:
try {
doTTLForIndex(&opCtx, it.first, it.second);
} catch (const ExceptionForCat<ErrorCategory::Interruption>&) {
- warning() << "TTLMonitor was interrupted, waiting " << ttlMonitorSleepSecs.load()
- << " seconds before doing another pass";
+ LOGV2_WARNING(22537,
+ "TTLMonitor was interrupted, waiting {ttlMonitorSleepSecs_load} "
+ "seconds before doing another pass",
+ "ttlMonitorSleepSecs_load"_attr = ttlMonitorSleepSecs.load());
return;
} catch (const DBException& dbex) {
- error() << "Error processing ttl index: " << it.second << " -- " << dbex.toString();
+ LOGV2_ERROR(22538,
+ "Error processing ttl index: {it_second} -- {dbex}",
+ "it_second"_attr = it.second,
+ "dbex"_attr = dbex.toString());
// Continue on to the next index.
continue;
}
@@ -201,23 +210,33 @@ private:
return;
}
if (!userAllowedWriteNS(collectionNSS).isOK()) {
- error() << "namespace '" << collectionNSS
- << "' doesn't allow deletes, skipping ttl job for: " << idx;
+ LOGV2_ERROR(
+ 22539,
+ "namespace '{collectionNSS}' doesn't allow deletes, skipping ttl job for: {idx}",
+ "collectionNSS"_attr = collectionNSS,
+ "idx"_attr = idx);
return;
}
const BSONObj key = idx["key"].Obj();
const StringData name = idx["name"].valueStringData();
if (key.nFields() != 1) {
- error() << "key for ttl index can only have 1 field, skipping ttl job for: " << idx;
+ LOGV2_ERROR(22540,
+ "key for ttl index can only have 1 field, skipping ttl job for: {idx}",
+ "idx"_attr = idx);
return;
}
- LOG(1) << "ns: " << collectionNSS << " key: " << key << " name: " << name;
+ LOGV2_DEBUG(22533,
+ 1,
+ "ns: {collectionNSS} key: {key} name: {name}",
+ "collectionNSS"_attr = collectionNSS,
+ "key"_attr = key,
+ "name"_attr = name);
AutoGetCollection autoGetCollection(opCtx, collectionNSS, MODE_IX);
if (MONGO_unlikely(hangTTLMonitorWithLock.shouldFail())) {
- log() << "Hanging due to hangTTLMonitorWithLock fail point";
+ LOGV2(22534, "Hanging due to hangTTLMonitorWithLock fail point");
hangTTLMonitorWithLock.pauseWhileSet(opCtx);
}
@@ -234,8 +253,11 @@ private:
const IndexDescriptor* desc = collection->getIndexCatalog()->findIndexByName(opCtx, name);
if (!desc) {
- LOG(1) << "index not found (index build in progress? index dropped?), skipping "
- << "ttl job for: " << idx;
+ LOGV2_DEBUG(22535,
+ 1,
+ "index not found (index build in progress? index dropped?), skipping ttl "
+ "job for: {idx}",
+ "idx"_attr = idx);
return;
}
@@ -244,15 +266,21 @@ private:
idx = desc->infoObj();
if (IndexType::INDEX_BTREE != IndexNames::nameToType(desc->getAccessMethodName())) {
- error() << "special index can't be used as a ttl index, skipping ttl job for: " << idx;
+ LOGV2_ERROR(22541,
+ "special index can't be used as a ttl index, skipping ttl job for: {idx}",
+ "idx"_attr = idx);
return;
}
BSONElement secondsExpireElt = idx[secondsExpireField];
if (!secondsExpireElt.isNumber()) {
- error() << "ttl indexes require the " << secondsExpireField << " field to be "
- << "numeric but received a type of " << typeName(secondsExpireElt.type())
- << ", skipping ttl job for: " << idx;
+ LOGV2_ERROR(
+ 22542,
+ "ttl indexes require the {secondsExpireField} field to be numeric but received a "
+ "type of {typeName_secondsExpireElt_type}, skipping ttl job for: {idx}",
+ "secondsExpireField"_attr = secondsExpireField,
+ "typeName_secondsExpireElt_type"_attr = typeName(secondsExpireElt.type()),
+ "idx"_attr = idx);
return;
}
@@ -295,14 +323,16 @@ private:
Status result = exec->executePlan();
if (!result.isOK()) {
- error() << "ttl query execution for index " << idx
- << " failed with status: " << redact(result);
+ LOGV2_ERROR(22543,
+ "ttl query execution for index {idx} failed with status: {result}",
+ "idx"_attr = idx,
+ "result"_attr = redact(result));
return;
}
const long long numDeleted = DeleteStage::getNumDeleted(*exec);
ttlDeletedDocuments.increment(numDeleted);
- LOG(1) << "deleted: " << numDeleted;
+ LOGV2_DEBUG(22536, 1, "deleted: {numDeleted}", "numDeleted"_attr = numDeleted);
}
ServiceContext* _serviceContext;
diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp
index 5d3e410cd41..174cbc37568 100644
--- a/src/mongo/db/views/durable_view_catalog.cpp
+++ b/src/mongo/db/views/durable_view_catalog.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/storage/record_data.h"
#include "mongo/db/views/view_catalog.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/unordered_set.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -195,7 +196,11 @@ void DurableViewCatalogImpl::upsert(OperationContext* opCtx,
Snapshotted<BSONObj> oldView;
if (!id.isValid() || !systemViews->findDoc(opCtx, id, &oldView)) {
- LOG(2) << "insert view " << view << " into " << _db->getSystemViewsName();
+ LOGV2_DEBUG(22544,
+ 2,
+ "insert view {view} into {db_getSystemViewsName}",
+ "view"_attr = view,
+ "db_getSystemViewsName"_attr = _db->getSystemViewsName());
uassertStatusOK(
systemViews->insertDocument(opCtx, InsertStatement(view), &CurOp::get(opCtx)->debug()));
} else {
@@ -225,7 +230,11 @@ void DurableViewCatalogImpl::remove(OperationContext* opCtx, const NamespaceStri
if (!id.isValid())
return;
- LOG(2) << "remove view " << name << " from " << _db->getSystemViewsName();
+ LOGV2_DEBUG(22545,
+ 2,
+ "remove view {name} from {db_getSystemViewsName}",
+ "name"_attr = name,
+ "db_getSystemViewsName"_attr = _db->getSystemViewsName());
systemViews->deleteDocument(opCtx, kUninitializedStmtId, id, &CurOp::get(opCtx)->debug());
}
} // namespace mongo
diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp
index 11003651962..01a104b14d3 100644
--- a/src/mongo/db/views/view_catalog.cpp
+++ b/src/mongo/db/views/view_catalog.cpp
@@ -55,6 +55,7 @@
#include "mongo/db/views/resolved_view.h"
#include "mongo/db/views/view.h"
#include "mongo/db/views/view_graph.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -94,7 +95,10 @@ Status ViewCatalog::reload(OperationContext* opCtx, ViewCatalogLookupBehavior lo
Status ViewCatalog::_reload(WithLock,
OperationContext* opCtx,
ViewCatalogLookupBehavior lookupBehavior) {
- LOG(1) << "reloading view catalog for database " << _durable->getName();
+ LOGV2_DEBUG(22546,
+ 1,
+ "reloading view catalog for database {durable_getName}",
+ "durable_getName"_attr = _durable->getName());
_viewMap.clear();
_valid = false;
@@ -137,8 +141,10 @@ Status ViewCatalog::_reload(WithLock,
}
} catch (const DBException& ex) {
auto status = ex.toStatus();
- LOG(0) << "could not load view catalog for database " << _durable->getName() << ": "
- << status;
+ LOGV2(22547,
+ "could not load view catalog for database {durable_getName}: {status}",
+ "durable_getName"_attr = _durable->getName(),
+ "status"_attr = status);
return status;
}
diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp
index 546a590c9b5..3f55e87de40 100644
--- a/src/mongo/db/write_concern.cpp
+++ b/src/mongo/db/write_concern.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/storage/storage_engine.h"
#include "mongo/db/transaction_validation.h"
#include "mongo/db/write_concern_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/protocol.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/log.h"
@@ -97,8 +98,13 @@ StatusWith<WriteConcernOptions> extractWriteConcern(OperationContext* opCtx,
auto wcDefault = ReadWriteConcernDefaults::get(opCtx->getServiceContext())
.getDefaultWriteConcern(opCtx);
if (wcDefault) {
- LOG(2) << "Applying default writeConcern on " << cmdObj.firstElementFieldName()
- << " of " << wcDefault->toBSON();
+ LOGV2_DEBUG(22548,
+ 2,
+ "Applying default writeConcern on {cmdObj_firstElementFieldName} "
+ "of {wcDefault}",
+ "cmdObj_firstElementFieldName"_attr =
+ cmdObj.firstElementFieldName(),
+ "wcDefault"_attr = wcDefault->toBSON());
return *wcDefault;
}
}
@@ -210,8 +216,11 @@ Status waitForWriteConcern(OperationContext* opCtx,
const OpTime& replOpTime,
const WriteConcernOptions& writeConcern,
WriteConcernResult* result) {
- LOG(2) << "Waiting for write concern. OpTime: " << replOpTime
- << ", write concern: " << writeConcern.toBSON();
+ LOGV2_DEBUG(22549,
+ 2,
+ "Waiting for write concern. OpTime: {replOpTime}, write concern: {writeConcern}",
+ "replOpTime"_attr = replOpTime,
+ "writeConcern"_attr = writeConcern.toBSON());
auto const replCoord = repl::ReplicationCoordinator::get(opCtx);
@@ -227,7 +236,7 @@ Status waitForWriteConcern(OperationContext* opCtx,
switch (writeConcernWithPopulatedSyncMode.syncMode) {
case WriteConcernOptions::SyncMode::UNSET:
- severe() << "Attempting to wait on a WriteConcern with an unset sync option";
+ LOGV2_FATAL(22550, "Attempting to wait on a WriteConcern with an unset sync option");
fassertFailed(34410);
case WriteConcernOptions::SyncMode::NONE:
break;
diff --git a/src/mongo/dbtests/framework_options.cpp b/src/mongo/dbtests/framework_options.cpp
index d9743cb17b4..3429cebc564 100644
--- a/src/mongo/dbtests/framework_options.cpp
+++ b/src/mongo/dbtests/framework_options.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/storage/flow_control_parameters_gen.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
#include "mongo/util/options_parser/startup_options.h"
@@ -119,7 +120,7 @@ Status storeTestFrameworkOptions(const moe::Environment& params,
}
if (kDebugBuild)
- log() << "DEBUG build" << endl;
+ LOGV2(22491, "DEBUG build");
string dbpathString = p.string();
storageGlobalParams.dbpath = dbpathString.c_str();
@@ -128,7 +129,7 @@ Status storeTestFrameworkOptions(const moe::Environment& params,
gFlowControlEnabled.store(params["enableFlowControl"].as<bool>());
if (gFlowControlEnabled.load()) {
- log() << "Flow Control enabled" << endl;
+ LOGV2(22492, "Flow Control enabled");
}
if (storageGlobalParams.engine == "wiredTiger" &&
diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp
index 08ae278aa12..5124e1dee45 100644
--- a/src/mongo/dbtests/jsobjtests.cpp
+++ b/src/mongo/dbtests/jsobjtests.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/decimal128.h"
#include "mongo/util/allocator.h"
#include "mongo/util/embedded_builder.h"
@@ -163,7 +164,10 @@ FieldCompareResult compareDottedFieldNames(const string& l,
return LEFT_SUBFIELD;
}
- log() << "compareDottedFieldNames ERROR l: " << l << " r: " << r << " TOO MANY LOOPS" << endl;
+ LOGV2(22493,
+ "compareDottedFieldNames ERROR l: {l} r: {r} TOO MANY LOOPS",
+ "l"_attr = l,
+ "r"_attr = r);
verify(0);
return SAME; // will never get here
}
diff --git a/src/mongo/dbtests/jsontests.cpp b/src/mongo/dbtests/jsontests.cpp
index ec602c246f9..926e65db9c8 100644
--- a/src/mongo/dbtests/jsontests.cpp
+++ b/src/mongo/dbtests/jsontests.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/decimal128.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -544,14 +545,18 @@ void assertEquals(const std::string& json,
const char* msg) {
const bool bad = expected.woCompare(actual);
if (bad) {
- ::mongo::log() << "want:" << expected.jsonString() << " size: " << expected.objsize()
- << std::endl;
- ::mongo::log() << "got :" << actual.jsonString() << " size: " << actual.objsize()
- << std::endl;
- ::mongo::log() << expected.hexDump() << std::endl;
- ::mongo::log() << actual.hexDump() << std::endl;
- ::mongo::log() << msg << std::endl;
- ::mongo::log() << "orig json:" << json;
+ LOGV2(22494,
+ "want:{expected_jsonString} size: {expected_objsize}",
+ "expected_jsonString"_attr = expected.jsonString(),
+ "expected_objsize"_attr = expected.objsize());
+ LOGV2(22495,
+ "got :{actual_jsonString} size: {actual_objsize}",
+ "actual_jsonString"_attr = actual.jsonString(),
+ "actual_objsize"_attr = actual.objsize());
+ LOGV2(22496, "{expected_hexDump}", "expected_hexDump"_attr = expected.hexDump());
+ LOGV2(22497, "{actual_hexDump}", "actual_hexDump"_attr = actual.hexDump());
+ LOGV2(22498, "{msg}", "msg"_attr = msg);
+ LOGV2(22499, "orig json:{json}", "json"_attr = json);
}
ASSERT(!bad);
}
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index f6c1a6e2445..c3503d2721f 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/s/op_observer_sharding_impl.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/logger/logger.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/transport_layer_asio.h"
#include "mongo/util/log.h"
@@ -193,8 +194,10 @@ protected:
}
void check(const BSONObj& expected, const BSONObj& got) const {
if (expected.woCompare(got)) {
- ::mongo::log() << "expected: " << expected.toString() << ", got: " << got.toString()
- << endl;
+ LOGV2(22500,
+ "expected: {expected}, got: {got}",
+ "expected"_attr = expected.toString(),
+ "got"_attr = got.toString());
}
ASSERT_BSONOBJ_EQ(expected, got);
}
@@ -243,7 +246,7 @@ protected:
OldClientContext ctx(&_opCtx, ns());
for (vector<BSONObj>::iterator i = ops.begin(); i != ops.end(); ++i) {
if (0) {
- mongo::unittest::log() << "op: " << *i << endl;
+ LOGV2(22501, "op: {i}", "i"_attr = *i);
}
repl::UnreplicatedWritesBlock uwb(&_opCtx);
auto entry = uassertStatusOK(OplogEntry::parse(*i));
diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp
index c4c0d4cc33d..50061a85861 100644
--- a/src/mongo/dbtests/storage_timestamp_tests.cpp
+++ b/src/mongo/dbtests/storage_timestamp_tests.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <cstdint>
@@ -81,8 +83,10 @@
#include "mongo/db/transaction_participant.h"
#include "mongo/db/transaction_participant_gen.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/future.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
#include "mongo/util/stacktrace.h"
namespace mongo {
@@ -1525,9 +1529,9 @@ public:
auto beforeTxnTs = beforeTxnTime.asTimestamp();
auto commitEntryTs = beforeTxnTime.addTicks(1).asTimestamp();
- unittest::log() << "Present TS: " << presentTs;
- unittest::log() << "Before transaction TS: " << beforeTxnTs;
- unittest::log() << "Commit entry TS: " << commitEntryTs;
+ LOGV2(22502, "Present TS: {presentTs}", "presentTs"_attr = presentTs);
+ LOGV2(22503, "Before transaction TS: {beforeTxnTs}", "beforeTxnTs"_attr = beforeTxnTs);
+ LOGV2(22504, "Commit entry TS: {commitEntryTs}", "commitEntryTs"_attr = commitEntryTs);
const auto sessionId = makeLogicalSessionIdForTest();
_opCtx->setLogicalSessionId(sessionId);
@@ -2612,7 +2616,7 @@ public:
// NOTE: This test does not test any timestamp reads.
const LogicalTime insert1 = _clock->reserveTicks(1);
{
- log() << "inserting " << badDoc1;
+ LOGV2(22505, "inserting {badDoc1}", "badDoc1"_attr = badDoc1);
WriteUnitOfWork wuow(_opCtx);
insertDocument(autoColl.getCollection(),
InsertStatement(badDoc1, insert1.asTimestamp(), presentTerm));
@@ -2621,7 +2625,7 @@ public:
const LogicalTime insert2 = _clock->reserveTicks(1);
{
- log() << "inserting " << badDoc2;
+ LOGV2(22506, "inserting {badDoc2}", "badDoc2"_attr = badDoc2);
WriteUnitOfWork wuow(_opCtx);
insertDocument(autoColl.getCollection(),
InsertStatement(badDoc2, insert2.asTimestamp(), presentTerm));
@@ -2681,7 +2685,7 @@ public:
{
// This write will not succeed because the node is a primary and the document is not
// indexable.
- log() << "attempting to insert " << badDoc3;
+ LOGV2(22507, "attempting to insert {badDoc3}", "badDoc3"_attr = badDoc3);
WriteUnitOfWork wuow(_opCtx);
ASSERT_THROWS_CODE(
collection->insertDocument(
@@ -3101,9 +3105,9 @@ public:
}
void logTimestamps() const {
- unittest::log() << "Present TS: " << presentTs;
- unittest::log() << "Before transaction TS: " << beforeTxnTs;
- unittest::log() << "Commit entry TS: " << commitEntryTs;
+ LOGV2(22508, "Present TS: {presentTs}", "presentTs"_attr = presentTs);
+ LOGV2(22509, "Before transaction TS: {beforeTxnTs}", "beforeTxnTs"_attr = beforeTxnTs);
+ LOGV2(22510, "Commit entry TS: {commitEntryTs}", "commitEntryTs"_attr = commitEntryTs);
}
BSONObj getSessionTxnInfoAtTimestamp(const Timestamp& ts, bool expected) {
@@ -3300,7 +3304,7 @@ public:
void run() {
auto txnParticipant = TransactionParticipant::get(_opCtx);
ASSERT(txnParticipant);
- unittest::log() << "PrepareTS: " << prepareEntryTs;
+ LOGV2(22511, "PrepareTS: {prepareEntryTs}", "prepareEntryTs"_attr = prepareEntryTs);
logTimestamps();
const auto prepareFilter = BSON("ts" << prepareEntryTs);
@@ -3494,8 +3498,8 @@ public:
void run() {
auto txnParticipant = TransactionParticipant::get(_opCtx);
ASSERT(txnParticipant);
- unittest::log() << "PrepareTS: " << prepareEntryTs;
- unittest::log() << "AbortTS: " << abortEntryTs;
+ LOGV2(22512, "PrepareTS: {prepareEntryTs}", "prepareEntryTs"_attr = prepareEntryTs);
+ LOGV2(22513, "AbortTS: {abortEntryTs}", "abortEntryTs"_attr = abortEntryTs);
const auto prepareFilter = BSON("ts" << prepareEntryTs);
const auto abortFilter = BSON("ts" << abortEntryTs);
@@ -3598,7 +3602,7 @@ public:
const auto currentTime = _clock->getClusterTime();
const auto prepareTs = currentTime.addTicks(1).asTimestamp();
commitEntryTs = currentTime.addTicks(2).asTimestamp();
- unittest::log() << "Prepare TS: " << prepareTs;
+ LOGV2(22514, "Prepare TS: {prepareTs}", "prepareTs"_attr = prepareTs);
logTimestamps();
{
@@ -3699,7 +3703,7 @@ public:
const auto currentTime = _clock->getClusterTime();
const auto prepareTs = currentTime.addTicks(1).asTimestamp();
const auto abortEntryTs = currentTime.addTicks(2).asTimestamp();
- unittest::log() << "Prepare TS: " << prepareTs;
+ LOGV2(22515, "Prepare TS: {prepareTs}", "prepareTs"_attr = prepareTs);
logTimestamps();
{
@@ -3794,8 +3798,10 @@ public:
auto storageEngine = cc().getServiceContext()->getStorageEngine();
if (!storageEngine->supportsReadConcernSnapshot() ||
!mongo::serverGlobalParams.enableMajorityReadConcern) {
- unittest::log() << "Skipping this test suite because storage engine "
- << storageGlobalParams.engine << " does not support timestamp writes.";
+ LOGV2(22516,
+ "Skipping this test suite because storage engine {storageGlobalParams_engine} "
+ "does not support timestamp writes.",
+ "storageGlobalParams_engine"_attr = storageGlobalParams.engine);
return true;
}
return false;
diff --git a/src/mongo/dbtests/threadedtests.cpp b/src/mongo/dbtests/threadedtests.cpp
index 7395c8d5066..f06ba1a00ea 100644
--- a/src/mongo/dbtests/threadedtests.cpp
+++ b/src/mongo/dbtests/threadedtests.cpp
@@ -38,6 +38,7 @@
#include "mongo/config.h"
#include "mongo/db/client.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/platform/bits.h"
#include "mongo/stdx/thread.h"
@@ -278,7 +279,7 @@ private:
_hotel.checkOut();
if ((i % (checkIns / 10)) == 0)
- mongo::unittest::log() << "checked in " << i << " times..." << endl;
+ LOGV2(22517, "checked in {i} times...", "i"_attr = i);
}
}
diff --git a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
index 25774af37ad..dce7de25165 100644
--- a/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
+++ b/src/mongo/dbtests/wildcard_multikey_persistence_test.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/index/wildcard_access_method.h"
#include "mongo/db/repl/storage_interface_impl.h"
#include "mongo/db/storage/sorted_data_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -116,9 +117,12 @@ protected:
// Confirm that there are no further keys in the index.
ASSERT(!indexKey);
} catch (const TestAssertionFailureException& ex) {
- log() << "Writing remaining index keys to debug log:";
+ LOGV2(22518, "Writing remaining index keys to debug log:");
while (indexKey) {
- log() << "{ key: " << indexKey->key << ", loc: " << indexKey->loc << " }";
+ LOGV2(22519,
+ "{{ key: {indexKey_key}, loc: {indexKey_loc} }}",
+ "indexKey_key"_attr = indexKey->key,
+ "indexKey_loc"_attr = indexKey->loc);
indexKey = indexCursor->next();
}
throw ex;
diff --git a/src/mongo/embedded/embedded.cpp b/src/mongo/embedded/embedded.cpp
index 69911b0fa21..95ff681e5cb 100644
--- a/src/mongo/embedded/embedded.cpp
+++ b/src/mongo/embedded/embedded.cpp
@@ -66,6 +66,7 @@
#include "mongo/embedded/replication_coordinator_embedded.h"
#include "mongo/embedded/service_entry_point_embedded.h"
#include "mongo/logger/log_component.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/dbdirectclient_factory.h"
#include "mongo/util/background.h"
#include "mongo/util/exit.h"
@@ -182,7 +183,7 @@ void shutdown(ServiceContext* srvContext) {
}
setGlobalServiceContext(nullptr);
- log(LogComponent::kControl) << "now exiting";
+ LOGV2_OPTIONS(22551, {logComponentV1toV2(LogComponent::kControl)}, "now exiting");
}
@@ -226,7 +227,8 @@ ServiceContext* initialize(const char* yaml_config) {
}
if (kDebugBuild)
- log(LogComponent::kControl) << "DEBUG build (which is slower)" << endl;
+ LOGV2_OPTIONS(
+ 22552, {logComponentV1toV2(LogComponent::kControl)}, "DEBUG build (which is slower)");
// The periodic runner is required by the storage engine to be running beforehand.
auto periodicRunner = std::make_unique<PeriodicRunnerEmbedded>(
@@ -249,9 +251,11 @@ ServiceContext* initialize(const char* yaml_config) {
// Warn if field name matches non-active registered storage engine.
if (isRegisteredStorageEngine(serviceContext, e.fieldName())) {
- warning() << "Detected configuration for non-active storage engine "
- << e.fieldName() << " when current storage engine is "
- << storageGlobalParams.engine;
+ LOGV2_WARNING(22554,
+ "Detected configuration for non-active storage engine {e_fieldName} "
+ "when current storage engine is {storageGlobalParams_engine}",
+ "e_fieldName"_attr = e.fieldName(),
+ "storageGlobalParams_engine"_attr = storageGlobalParams.engine);
}
}
}
@@ -286,7 +290,10 @@ ServiceContext* initialize(const char* yaml_config) {
try {
repairDatabasesAndCheckVersion(startupOpCtx.get());
} catch (const ExceptionFor<ErrorCodes::MustDowngrade>& error) {
- severe(LogComponent::kControl) << "** IMPORTANT: " << error.toStatus().reason();
+ LOGV2_FATAL_OPTIONS(22555,
+ {logComponentV1toV2(LogComponent::kControl)},
+ "** IMPORTANT: {error_toStatus_reason}",
+ "error_toStatus_reason"_attr = error.toStatus().reason());
quickExit(EXIT_NEED_DOWNGRADE);
}
@@ -300,7 +307,7 @@ ServiceContext* initialize(const char* yaml_config) {
}
if (storageGlobalParams.upgrade) {
- log() << "finished checking dbs";
+ LOGV2(22553, "finished checking dbs");
exitCleanly(EXIT_CLEAN);
}
diff --git a/src/mongo/embedded/mongoc_embedded/mongoc_embedded_test.cpp b/src/mongo/embedded/mongoc_embedded/mongoc_embedded_test.cpp
index a684bf1bec8..21679980bca 100644
--- a/src/mongo/embedded/mongoc_embedded/mongoc_embedded_test.cpp
+++ b/src/mongo/embedded/mongoc_embedded/mongoc_embedded_test.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/server_options.h"
#include "mongo/embedded/mongo_embedded/mongo_embedded.h"
#include "mongo/embedded/mongoc_embedded/mongoc_embedded_test_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -87,7 +88,7 @@ bool insert_data(mongoc_collection_t* collection) {
bool ret = mongoc_bulk_operation_execute(bulk, NULL, &error);
if (!ret) {
- ::mongo::log() << "Error inserting data: " << error.message;
+ LOGV2(22556, "Error inserting data: {error_message}", "error_message"_attr = error.message);
}
mongoc_bulk_operation_destroy(bulk);
@@ -118,7 +119,7 @@ bool explain(mongoc_collection_t* collection) {
"}");
res = mongoc_collection_command_simple(collection, command, NULL, &reply, &error);
if (!res) {
- ::mongo::log() << "Error with explain: " << error.message;
+ LOGV2(22557, "Error with explain: {error_message}", "error_message"_attr = error.message);
goto explain_cleanup;
}
diff --git a/src/mongo/executor/connection_pool.cpp b/src/mongo/executor/connection_pool.cpp
index 42ff763018f..613fa914ab8 100644
--- a/src/mongo/executor/connection_pool.cpp
+++ b/src/mongo/executor/connection_pool.cpp
@@ -41,6 +41,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/executor/connection_pool_stats.h"
#include "mongo/executor/remote_command_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/destructor_guard.h"
#include "mongo/util/hierarchical_acquisition.h"
@@ -112,7 +113,11 @@ size_t ConnectionPool::ConnectionInterface::getGeneration() const {
void ConnectionPool::ControllerInterface::init(ConnectionPool* pool) {
invariant(pool);
- LOG(2) << "Controller for " << pool->_name << " is " << name();
+ LOGV2_DEBUG(22558,
+ 2,
+ "Controller for {pool_name} is {name}",
+ "pool_name"_attr = pool->_name,
+ "name"_attr = name());
_pool = pool;
}
@@ -325,7 +330,7 @@ public:
void fassertSSLModeIs(transport::ConnectSSLMode desired) const {
if (desired != _sslMode) {
- severe() << "Mixing ssl modes for a single host is not supported";
+ LOGV2_FATAL(22580, "Mixing ssl modes for a single host is not supported");
fassertFailedNoTrace(51043);
}
}
@@ -629,8 +634,11 @@ Future<ConnectionPool::ConnectionHandle> ConnectionPool::SpecificPool::getConnec
auto conn = tryGetConnection();
if (conn) {
- LOG(kDiagnosticLogLevel) << "Requesting new connection to " << _hostAndPort
- << "--using existing idle connection";
+ LOGV2_DEBUG(
+ 22559,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Requesting new connection to {hostAndPort}--using existing idle connection",
+ "hostAndPort"_attr = _hostAndPort);
return Future<ConnectionPool::ConnectionHandle>::makeReady(std::move(conn));
}
}
@@ -639,8 +647,11 @@ Future<ConnectionPool::ConnectionHandle> ConnectionPool::SpecificPool::getConnec
if (timeout < Milliseconds(0) || timeout > pendingTimeout) {
timeout = pendingTimeout;
}
- LOG(kDiagnosticLogLevel) << "Requesting new connection to " << _hostAndPort << " with timeout "
- << timeout;
+ LOGV2_DEBUG(22560,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Requesting new connection to {hostAndPort} with timeout {timeout}",
+ "hostAndPort"_attr = _hostAndPort,
+ "timeout"_attr = timeout);
const auto expiration = now + timeout;
auto pf = makePromiseFuture<ConnectionHandle>();
@@ -672,7 +683,9 @@ ConnectionPool::ConnectionHandle ConnectionPool::SpecificPool::tryGetConnection(
conn->cancelTimeout();
if (!conn->isHealthy()) {
- log() << "dropping unhealthy pooled connection to " << conn->getHostAndPort();
+ LOGV2(22561,
+ "dropping unhealthy pooled connection to {conn_getHostAndPort}",
+ "conn_getHostAndPort"_attr = conn->getHostAndPort());
// Drop the bad connection via scoped destruction and retry
continue;
@@ -705,28 +718,40 @@ void ConnectionPool::SpecificPool::finishRefresh(ConnectionInterface* connPtr, S
// various callers have their own time limit which is unrelated
// to our internal one.
if (status.code() == ErrorCodes::NetworkInterfaceExceededTimeLimit) {
- LOG(kDiagnosticLogLevel) << "Pending connection to host " << _hostAndPort
- << " did not complete within the connection timeout,"
- << " retrying with a new connection;" << openConnections()
- << " connections to that host remain open";
+ LOGV2_DEBUG(22562,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Pending connection to host {hostAndPort} did not complete within the "
+ "connection timeout, retrying with a new connection;{openConnections} "
+ "connections to that host remain open",
+ "hostAndPort"_attr = _hostAndPort,
+ "openConnections"_attr = openConnections());
return;
}
// Pass a failure on through
if (!status.isOK()) {
- LOG(kDiagnosticLogLevel) << "Connection failed to " << _hostAndPort << " due to "
- << redact(status);
+ LOGV2_DEBUG(22563,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Connection failed to {hostAndPort} due to {status}",
+ "hostAndPort"_attr = _hostAndPort,
+ "status"_attr = redact(status));
processFailure(status);
return;
}
// If the host and port were dropped, let this lapse and spawn new connections
if (!conn || conn->getGeneration() != _generation) {
- LOG(kDiagnosticLogLevel) << "Dropping late refreshed connection to " << _hostAndPort;
+ LOGV2_DEBUG(22564,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Dropping late refreshed connection to {hostAndPort}",
+ "hostAndPort"_attr = _hostAndPort);
return;
}
- LOG(kDiagnosticLogLevel) << "Finishing connection refresh for " << _hostAndPort;
+ LOGV2_DEBUG(22565,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Finishing connection refresh for {hostAndPort}",
+ "hostAndPort"_attr = _hostAndPort);
// If the connection refreshed successfully, throw it back in the ready pool
addToReady(std::move(conn));
@@ -752,9 +777,12 @@ void ConnectionPool::SpecificPool::returnConnection(ConnectionInterface* connPtr
if (auto status = conn->getStatus(); !status.isOK()) {
// TODO: alert via some callback if the host is bad
- log() << "Ending connection to host " << _hostAndPort
- << " due to bad connection status: " << redact(status) << "; " << openConnections()
- << " connections to that host remain open";
+ LOGV2(22566,
+ "Ending connection to host {hostAndPort} due to bad connection status: {status}; "
+ "{openConnections} connections to that host remain open",
+ "hostAndPort"_attr = _hostAndPort,
+ "status"_attr = redact(status),
+ "openConnections"_attr = openConnections());
return;
}
@@ -766,15 +794,20 @@ void ConnectionPool::SpecificPool::returnConnection(ConnectionInterface* connPtr
if (_readyPool.size() + _processingPool.size() + _checkedOutPool.size() >=
controls.targetConnections) {
// If we already have minConnections, just let the connection lapse
- log() << "Ending idle connection to host " << _hostAndPort
- << " because the pool meets constraints; " << openConnections()
- << " connections to that host remain open";
+ LOGV2(22567,
+ "Ending idle connection to host {hostAndPort} because the pool meets "
+ "constraints; {openConnections} connections to that host remain open",
+ "hostAndPort"_attr = _hostAndPort,
+ "openConnections"_attr = openConnections());
return;
}
_processingPool[connPtr] = std::move(conn);
- LOG(kDiagnosticLogLevel) << "Refreshing connection to " << _hostAndPort;
+ LOGV2_DEBUG(22568,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Refreshing connection to {hostAndPort}",
+ "hostAndPort"_attr = _hostAndPort);
connPtr->refresh(_parent->_controller->pendingTimeout(),
guardCallback([this](auto conn, auto status) {
finishRefresh(std::move(conn), std::move(status));
@@ -784,7 +817,10 @@ void ConnectionPool::SpecificPool::returnConnection(ConnectionInterface* connPtr
}
// If it's fine as it is, just put it in the ready queue
- LOG(kDiagnosticLogLevel) << "Returning ready connection to " << _hostAndPort;
+ LOGV2_DEBUG(22569,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Returning ready connection to {hostAndPort}",
+ "hostAndPort"_attr = _hostAndPort);
addToReady(std::move(conn));
fulfillRequests();
@@ -801,7 +837,10 @@ void ConnectionPool::SpecificPool::addToReady(OwnedConnection conn) {
// immediately check them back in (which kicks off the refresh logic in
// returnConnection
auto returnConnectionFunc = guardCallback([this, connPtr]() {
- LOG(kDiagnosticLogLevel) << "Triggered refresh timeout for " << _hostAndPort;
+ LOGV2_DEBUG(22570,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Triggered refresh timeout for {hostAndPort}",
+ "hostAndPort"_attr = _hostAndPort);
auto conn = takeFromPool(_readyPool, connPtr);
// We've already been checked out. We don't need to refresh ourselves.
@@ -828,7 +867,8 @@ void ConnectionPool::SpecificPool::triggerShutdown(const Status& status) {
return;
}
- LOG(2) << "Delisting connection pool for " << _hostAndPort;
+ LOGV2_DEBUG(
+ 22571, 2, "Delisting connection pool for {hostAndPort}", "hostAndPort"_attr = _hostAndPort);
// Make sure the pool lifetime lasts until the end of this function,
// it could be only in the map of pools
@@ -849,8 +889,11 @@ void ConnectionPool::SpecificPool::processFailure(const Status& status) {
if (!_readyPool.empty() || !_processingPool.empty()) {
auto severity = MONGO_GET_LIMITED_SEVERITY(_hostAndPort, Seconds{1}, 0, 2);
- LOG(severity) << "Dropping all pooled connections to " << _hostAndPort << " due to "
- << redact(status);
+ LOGV2_DEBUG(22572,
+ logSeverityV1toV2(severity).toInt(),
+ "Dropping all pooled connections to {hostAndPort} due to {status}",
+ "hostAndPort"_attr = _hostAndPort,
+ "status"_attr = redact(status));
}
// When a connection enters the ready pool, its timer is set to eventually refresh the
@@ -878,7 +921,10 @@ void ConnectionPool::SpecificPool::processFailure(const Status& status) {
request.second.setError(status);
}
- LOG(kDiagnosticLogLevel) << "Failing requests to " << _hostAndPort;
+ LOGV2_DEBUG(22573,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Failing requests to {hostAndPort}",
+ "hostAndPort"_attr = _hostAndPort);
_requests.clear();
}
@@ -916,15 +962,20 @@ void ConnectionPool::SpecificPool::spawnConnections() {
}
if (_health.isFailed) {
- LOG(kDiagnosticLogLevel)
- << "Pool for " << _hostAndPort
- << " has failed recently. Postponing any attempts to spawn connections";
+ LOGV2_DEBUG(22574,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Pool for {hostAndPort} has failed recently. Postponing any attempts to spawn "
+ "connections",
+ "hostAndPort"_attr = _hostAndPort);
return;
}
auto controls = _parent->_controller->getControls(_id);
- LOG(kDiagnosticLogLevel) << "Comparing connection state for " << _hostAndPort
- << " to Controls: " << controls;
+ LOGV2_DEBUG(22575,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Comparing connection state for {hostAndPort} to Controls: {controls}",
+ "hostAndPort"_attr = _hostAndPort,
+ "controls"_attr = controls);
auto pendingConnections = refreshingConnections();
if (pendingConnections >= controls.maxPendingConnections) {
@@ -937,18 +988,27 @@ void ConnectionPool::SpecificPool::spawnConnections() {
}
auto severity = MONGO_GET_LIMITED_SEVERITY(_hostAndPort, Seconds{1}, 0, 2);
- LOG(severity) << "Connecting to " << _hostAndPort;
+ LOGV2_DEBUG(22576,
+ logSeverityV1toV2(severity).toInt(),
+ "Connecting to {hostAndPort}",
+ "hostAndPort"_attr = _hostAndPort);
auto allowance = std::min(controls.targetConnections - totalConnections,
controls.maxPendingConnections - pendingConnections);
- LOG(kDiagnosticLogLevel) << "Spawning " << allowance << " connections to " << _hostAndPort;
+ LOGV2_DEBUG(22577,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Spawning {allowance} connections to {hostAndPort}",
+ "allowance"_attr = allowance,
+ "hostAndPort"_attr = _hostAndPort);
for (decltype(allowance) i = 0; i < allowance; ++i) {
OwnedConnection handle;
try {
// make a new connection and put it in processing
handle = _parent->_factory->makeConnection(_hostAndPort, _sslMode, _generation);
} catch (std::system_error& e) {
- severe() << "Failed to construct a new connection object: " << e.what();
+ LOGV2_FATAL(22581,
+ "Failed to construct a new connection object: {e_what}",
+ "e_what"_attr = e.what());
fassertFailed(40336);
}
@@ -1067,8 +1127,11 @@ void ConnectionPool::SpecificPool::updateController() {
availableConnections(),
inUseConnections(),
};
- LOG(kDiagnosticLogLevel) << "Updating controller for " << _hostAndPort
- << " with State: " << state;
+ LOGV2_DEBUG(22578,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "Updating controller for {hostAndPort} with State: {state}",
+ "hostAndPort"_attr = _hostAndPort,
+ "state"_attr = state);
auto hostGroup = controller.updateHost(_id, std::move(state));
// If we can shutdown, then do so
@@ -1110,7 +1173,10 @@ void ConnectionPool::SpecificPool::updateController() {
void ConnectionPool::SpecificPool::updateState() {
if (_health.isShutdown) {
// If we're in shutdown, there is nothing to update. Our clients are all gone.
- LOG(kDiagnosticLogLevel) << _hostAndPort << " is dead";
+ LOGV2_DEBUG(22579,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "{hostAndPort} is dead",
+ "hostAndPort"_attr = _hostAndPort);
return;
}
diff --git a/src/mongo/executor/connection_pool_tl.cpp b/src/mongo/executor/connection_pool_tl.cpp
index 6d3150d1218..f1e48ee38a9 100644
--- a/src/mongo/executor/connection_pool_tl.cpp
+++ b/src/mongo/executor/connection_pool_tl.cpp
@@ -35,6 +35,7 @@
#include "mongo/client/authenticate.h"
#include "mongo/db/auth/authorization_manager.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -58,7 +59,7 @@ void TLTypeFactory::shutdown() {
stdx::lock_guard<Latch> lk(_mutex);
- log() << "Killing all outstanding egress activity.";
+ LOGV2(22582, "Killing all outstanding egress activity.");
for (auto collar : _collars) {
collar->kill();
}
@@ -94,7 +95,7 @@ void TLTimer::setTimeout(Milliseconds timeoutVal, TimeoutCallback cb) {
// We will not wait on a timeout if we are in shutdown.
// The clients will be canceled as an inevitable consequence of pools shutting down.
if (inShutdown()) {
- LOG(2) << "Skipping timeout due to impending shutdown.";
+ LOGV2_DEBUG(22583, 2, "Skipping timeout due to impending shutdown.");
return;
}
@@ -306,11 +307,15 @@ void TLConnection::setup(Milliseconds timeout, SetupCallback cb) {
if (status.isOK()) {
handler->promise.emplaceValue();
} else {
- LOG(2) << "Failed to connect to " << _peer << " - " << redact(status);
+ LOGV2_DEBUG(22584,
+ 2,
+ "Failed to connect to {peer} - {status}",
+ "peer"_attr = _peer,
+ "status"_attr = redact(status));
handler->promise.setError(status);
}
});
- LOG(2) << "Finished connection setup.";
+ LOGV2_DEBUG(22585, 2, "Finished connection setup.");
}
void TLConnection::refresh(Milliseconds timeout, RefreshCallback cb) {
diff --git a/src/mongo/executor/network_interface_integration_fixture.cpp b/src/mongo/executor/network_interface_integration_fixture.cpp
index 51e3092a17c..847fcf4b5b8 100644
--- a/src/mongo/executor/network_interface_integration_fixture.cpp
+++ b/src/mongo/executor/network_interface_integration_fixture.cpp
@@ -38,6 +38,7 @@
#include "mongo/executor/network_interface_integration_fixture.h"
#include "mongo/executor/remote_command_response.h"
#include "mongo/executor/task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/stdx/future.h"
#include "mongo/unittest/integration_test.h"
@@ -117,9 +118,9 @@ RemoteCommandResponse NetworkInterfaceIntegrationFixture::runCommandSync(
auto deferred = runCommand(makeCallbackHandle(), request);
auto& res = deferred.get();
if (res.isOK()) {
- log() << "got command result: " << res.toString();
+ LOGV2(22586, "got command result: {res}", "res"_attr = res.toString());
} else {
- log() << "command failed: " << res.status;
+ LOGV2(22587, "command failed: {res_status}", "res_status"_attr = res.status);
}
return res;
}
diff --git a/src/mongo/executor/network_interface_mock.cpp b/src/mongo/executor/network_interface_mock.cpp
index 9f3ccfc25dd..080fe35738e 100644
--- a/src/mongo/executor/network_interface_mock.cpp
+++ b/src/mongo/executor/network_interface_mock.cpp
@@ -39,6 +39,7 @@
#include "mongo/executor/connection_pool_stats.h"
#include "mongo/executor/network_connection_hook.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
#include "mongo/util/time_support.h"
@@ -77,9 +78,11 @@ void NetworkInterfaceMock::logQueues() {
continue;
}
- log() << "**** queue: " << queue.first << " ****";
+ LOGV2(22588, "**** queue: {queue_first} ****", "queue_first"_attr = queue.first);
for (auto&& item : *queue.second) {
- log() << "\t\t " << item.getDiagnosticString();
+ LOGV2(22589,
+ "\t\t {item_getDiagnosticString}",
+ "item_getDiagnosticString"_attr = item.getDiagnosticString());
}
}
}
@@ -240,8 +243,10 @@ void NetworkInterfaceMock::shutdown() {
_waitingToRunMask |= kExecutorThread; // Prevents network thread from scheduling.
lk.unlock();
for (NetworkOperationIterator iter = todo.begin(); iter != todo.end(); ++iter) {
- warning() << "Mock network interface shutting down with outstanding request: "
- << iter->getRequest();
+ LOGV2_WARNING(
+ 22590,
+ "Mock network interface shutting down with outstanding request: {iter_getRequest}",
+ "iter_getRequest"_attr = iter->getRequest());
iter->setResponse(
now, {ErrorCodes::ShutdownInProgress, "Shutting down mock network", Milliseconds(0)});
iter->finishResponse();
diff --git a/src/mongo/executor/network_interface_perf_test.cpp b/src/mongo/executor/network_interface_perf_test.cpp
index 2f625301dfe..3fc2eaf95e1 100644
--- a/src/mongo/executor/network_interface_perf_test.cpp
+++ b/src/mongo/executor/network_interface_perf_test.cpp
@@ -43,6 +43,7 @@
#include "mongo/executor/network_interface_asio.h"
#include "mongo/executor/network_interface_asio_test_utils.h"
#include "mongo/executor/task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/integration_test.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/assert_util.h"
@@ -107,7 +108,7 @@ TEST(NetworkInterfaceASIO, SerialPerf) {
int duration = timeNetworkTestMillis(numOperations, &netAsio);
int result = numOperations * 1000 / duration;
- log() << "THROUGHPUT asio ping ops/s: " << result;
+ LOGV2(22591, "THROUGHPUT asio ping ops/s: {result}", "result"_attr = result);
}
} // namespace
diff --git a/src/mongo/executor/network_interface_tl.cpp b/src/mongo/executor/network_interface_tl.cpp
index 6bb4e8f88d1..0ad76215257 100644
--- a/src/mongo/executor/network_interface_tl.cpp
+++ b/src/mongo/executor/network_interface_tl.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/server_options.h"
#include "mongo/executor/connection_pool_tl.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/transport/transport_layer_manager.h"
#include "mongo/util/concurrency/idle_thread_block.h"
@@ -107,7 +108,7 @@ NetworkInterfaceTL::NetworkInterfaceTL(std::string instanceName,
// Even if you have a service context, it may not have a transport layer (mostly for unittests).
if (!_tl) {
- warning() << "No TransportLayer configured during NetworkInterface startup";
+ LOGV2_WARNING(22601, "No TransportLayer configured during NetworkInterface startup");
_ownedTransportLayer =
transport::TransportLayerManager::makeAndStartDefaultEgressTransportLayer();
_tl = _ownedTransportLayer.get();
@@ -158,7 +159,7 @@ void NetworkInterfaceTL::startup() {
}
void NetworkInterfaceTL::_run() {
- LOG(2) << "The NetworkInterfaceTL reactor thread is spinning up";
+ LOGV2_DEBUG(22592, 2, "The NetworkInterfaceTL reactor thread is spinning up");
// This returns when the reactor is stopped in shutdown()
_reactor->run();
@@ -171,14 +172,14 @@ void NetworkInterfaceTL::_run() {
// Close out all remaining tasks in the reactor now that they've all been canceled.
_reactor->drain();
- LOG(2) << "NetworkInterfaceTL shutdown successfully";
+ LOGV2_DEBUG(22593, 2, "NetworkInterfaceTL shutdown successfully");
}
void NetworkInterfaceTL::shutdown() {
if (_state.swap(kStopped) != kStarted)
return;
- LOG(2) << "Shutting down network interface.";
+ LOGV2_DEBUG(22594, 2, "Shutting down network interface.");
// Stop the reactor/thread first so that nothing runs on a partially dtor'd pool.
_reactor->stop();
@@ -298,7 +299,7 @@ void NetworkInterfaceTL::CommandState::setTimer() {
<< ", deadline was " << deadline.toString()
<< ", op was " << redact(requestOnAny.toString());
- LOG(2) << message;
+ LOGV2_DEBUG(22595, 2, "{message}", "message"_attr = message);
promise.setError(Status(ErrorCodes::NetworkInterfaceExceededTimeLimit, message));
});
}
@@ -383,7 +384,10 @@ Status NetworkInterfaceTL::startCommand(const TaskExecutor::CallbackHandle& cbHa
return {ErrorCodes::ShutdownInProgress, "NetworkInterface shutdown in progress"};
}
- LOG(kDiagnosticLogLevel) << "startCommand: " << redact(request.toString());
+ LOGV2_DEBUG(22596,
+ logSeverityV1toV2(kDiagnosticLogLevel).toInt(),
+ "startCommand: {request}",
+ "request"_attr = redact(request.toString()));
if (_metadataHook) {
BSONObjBuilder newMetadata(std::move(request.metadata));
@@ -429,13 +433,18 @@ Status NetworkInterfaceTL::startCommand(const TaskExecutor::CallbackHandle& cbHa
StatusWith<RemoteCommandOnAnyResponse> swr) {
invariant(swr.isOK());
auto rs = std::move(swr.getValue());
- LOG(2) << "Request " << cmdState->requestOnAny.id << " finished with response: "
- << redact(rs.isOK() ? rs.data.toString() : rs.status.toString());
+ LOGV2_DEBUG(22597,
+ 2,
+ "Request {cmdState_requestOnAny_id} finished with response: "
+ "{rs_isOK_rs_data_rs_status_toString}",
+ "cmdState_requestOnAny_id"_attr = cmdState->requestOnAny.id,
+ "rs_isOK_rs_data_rs_status_toString"_attr =
+ redact(rs.isOK() ? rs.data.toString() : rs.status.toString()));
onFinish(std::move(rs));
});
if (MONGO_unlikely(networkInterfaceDiscardCommandsBeforeAcquireConn.shouldFail())) {
- log() << "Discarding command due to failpoint before acquireConn";
+ LOGV2(22598, "Discarding command due to failpoint before acquireConn");
return Status::OK();
}
@@ -607,8 +616,10 @@ void NetworkInterfaceTL::cancelCommand(const TaskExecutor::CallbackHandle& cbHan
}
// Satisfy the promise locally
- LOG(2) << "Canceling operation; original request was: "
- << redact(state->requestOnAny.toString());
+ LOGV2_DEBUG(22599,
+ 2,
+ "Canceling operation; original request was: {state_requestOnAny}",
+ "state_requestOnAny"_attr = redact(state->requestOnAny.toString()));
state->promise.setError({ErrorCodes::CallbackCanceled,
str::stream() << "Command canceled; original request was: "
<< redact(state->requestOnAny.toString())});
@@ -702,8 +713,11 @@ void NetworkInterfaceTL::_answerAlarm(Status status, std::shared_ptr<AlarmState>
// free and allows us to be resilient to a world where timers impls do have spurious wake ups.
auto currentTime = now();
if (status.isOK() && currentTime < state->when) {
- LOG(2) << "Alarm returned early. Expected at: " << state->when
- << ", fired at: " << currentTime;
+ LOGV2_DEBUG(22600,
+ 2,
+ "Alarm returned early. Expected at: {state_when}, fired at: {currentTime}",
+ "state_when"_attr = state->when,
+ "currentTime"_attr = currentTime);
state->timer->waitUntil(state->when, nullptr)
.getAsync([this, state = std::move(state)](Status status) mutable {
_answerAlarm(status, state);
diff --git a/src/mongo/executor/thread_pool_mock.cpp b/src/mongo/executor/thread_pool_mock.cpp
index fb809990e49..5f2255af995 100644
--- a/src/mongo/executor/thread_pool_mock.cpp
+++ b/src/mongo/executor/thread_pool_mock.cpp
@@ -34,6 +34,7 @@
#include "mongo/executor/thread_pool_mock.h"
#include "mongo/executor/network_interface_mock.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -52,7 +53,7 @@ ThreadPoolMock::~ThreadPoolMock() {
}
void ThreadPoolMock::startup() {
- LOG(1) << "Starting pool";
+ LOGV2_DEBUG(22602, 1, "Starting pool");
stdx::lock_guard<Latch> lk(_mutex);
invariant(!_started);
invariant(!_worker.joinable());
@@ -61,7 +62,7 @@ void ThreadPoolMock::startup() {
_options.onCreateThread();
stdx::unique_lock<Latch> lk(_mutex);
- LOG(1) << "Starting to consume tasks";
+ LOGV2_DEBUG(22603, 1, "Starting to consume tasks");
while (!_joining) {
if (_tasks.empty()) {
lk.unlock();
@@ -72,7 +73,7 @@ void ThreadPoolMock::startup() {
_consumeOneTask(lk);
}
- LOG(1) << "Done consuming tasks";
+ LOGV2_DEBUG(22604, 1, "Done consuming tasks");
});
}
@@ -115,14 +116,14 @@ void ThreadPoolMock::_consumeOneTask(stdx::unique_lock<Latch>& lk) {
}
void ThreadPoolMock::_shutdown(stdx::unique_lock<Latch>& lk) {
- LOG(1) << "Shutting down pool";
+ LOGV2_DEBUG(22605, 1, "Shutting down pool");
_inShutdown = true;
_net->signalWorkAvailable();
}
void ThreadPoolMock::_join(stdx::unique_lock<Latch>& lk) {
- LOG(1) << "Joining pool";
+ LOGV2_DEBUG(22606, 1, "Joining pool");
_joining = true;
_net->signalWorkAvailable();
diff --git a/src/mongo/executor/thread_pool_task_executor.cpp b/src/mongo/executor/thread_pool_task_executor.cpp
index 0ad34b4e6a9..9646de7e480 100644
--- a/src/mongo/executor/thread_pool_task_executor.cpp
+++ b/src/mongo/executor/thread_pool_task_executor.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/operation_context.h"
#include "mongo/executor/connection_pool_stats.h"
#include "mongo/executor/network_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/transport/baton.h"
#include "mongo/util/concurrency/thread_pool_interface.h"
@@ -432,7 +433,10 @@ StatusWith<TaskExecutor::CallbackHandle> ThreadPoolTaskExecutor::scheduleRemoteC
if (!swCbHandle.isOK())
return swCbHandle;
const auto cbState = _networkInProgressQueue.back();
- LOG(3) << "Scheduling remote command request: " << redact(scheduledRequest.toString());
+ LOGV2_DEBUG(22607,
+ 3,
+ "Scheduling remote command request: {scheduledRequest}",
+ "scheduledRequest"_attr = redact(scheduledRequest.toString()));
lk.unlock();
auto commandStatus = _net->startCommand(
@@ -447,8 +451,12 @@ StatusWith<TaskExecutor::CallbackHandle> ThreadPoolTaskExecutor::scheduleRemoteC
if (_inShutdown_inlock()) {
return;
}
- LOG(3) << "Received remote response: "
- << redact(response.isOK() ? response.toString() : response.status.toString());
+ LOGV2_DEBUG(
+ 22608,
+ 3,
+ "Received remote response: {response_isOK_response_response_status_toString}",
+ "response_isOK_response_response_status_toString"_attr =
+ redact(response.isOK() ? response.toString() : response.status.toString()));
swap(cbState->callback, newCb);
scheduleIntoPool_inlock(&_networkInProgressQueue, cbState->iter, std::move(lk));
},
diff --git a/src/mongo/platform/decimal128_bson_test.cpp b/src/mongo/platform/decimal128_bson_test.cpp
index dd6c2dd2018..6f0313f1d12 100644
--- a/src/mongo/platform/decimal128_bson_test.cpp
+++ b/src/mongo/platform/decimal128_bson_test.cpp
@@ -42,6 +42,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/config.h"
#include "mongo/db/json.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/decimal128.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/hex.h"
@@ -94,7 +95,7 @@ TEST(Decimal128BSONTest, TestsConstructingDecimalWithBsonDump) {
BSONElement extjson = b.getField("extjson");
BSONElement canonical_extjson = b.getField("canonical_extjson");
- log() << "Test - " << desc.str();
+ LOGV2(22609, "Test - {desc_str}", "desc_str"_attr = desc.str());
StringData hexString = bson.valueStringData();
BSONObj d = convertHexStringToBsonObj(hexString);
@@ -108,7 +109,7 @@ TEST(Decimal128BSONTest, TestsConstructingDecimalWithBsonDump) {
}
ASSERT_EQ(trimWhiteSpace(outputJson), trimWhiteSpace(expectedJson));
- log() << "PASSED";
+ LOGV2(22610, "PASSED");
}
}
}
diff --git a/src/mongo/platform/random_test.cpp b/src/mongo/platform/random_test.cpp
index c3271f8b926..f4bf565d700 100644
--- a/src/mongo/platform/random_test.cpp
+++ b/src/mongo/platform/random_test.cpp
@@ -27,12 +27,16 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include <set>
#include <vector>
#include "mongo/platform/random.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
namespace mongo {
@@ -233,11 +237,14 @@ TEST(RandomTest, NextInt32Uniformity) {
if (kDebugBuild) {
for (size_t i = 0; i < hist.size(); ++i) {
double dev = std::pow(std::pow((hist[i] - mu) / mu, 2), .5);
- unittest::log() << format(FMT_STRING(" [{:4}] count:{:4}, dev:{:6f}, {}"),
- i,
- hist[i],
- dev,
- std::string(hist[i] / 256, '*'));
+ LOGV2(22611,
+ "{format_FMT_STRING_4_count_4_dev_6f_i_hist_i_dev_std_string_hist_i_256}",
+ "format_FMT_STRING_4_count_4_dev_6f_i_hist_i_dev_std_string_hist_i_256"_attr =
+ format(FMT_STRING(" [{:4}] count:{:4}, dev:{:6f}, {}"),
+ i,
+ hist[i],
+ dev,
+ std::string(hist[i] / 256, '*')));
}
}
for (size_t i = 0; i < hist.size(); ++i) {
diff --git a/src/mongo/platform/shared_library_posix.cpp b/src/mongo/platform/shared_library_posix.cpp
index 871bd697012..ee7e1eca829 100644
--- a/src/mongo/platform/shared_library_posix.cpp
+++ b/src/mongo/platform/shared_library_posix.cpp
@@ -36,6 +36,7 @@
#include <dlfcn.h>
#include <memory>
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -45,14 +46,16 @@ namespace mongo {
SharedLibrary::~SharedLibrary() {
if (_handle) {
if (dlclose(_handle) != 0) {
- LOG(2) << "Load Library close failed " << dlerror();
+ LOGV2_DEBUG(
+ 22612, 2, "Load Library close failed {dlerror}", "dlerror"_attr = dlerror());
}
}
}
StatusWith<std::unique_ptr<SharedLibrary>> SharedLibrary::create(
const boost::filesystem::path& full_path) {
- LOG(1) << "Loading library: " << full_path.c_str();
+ LOGV2_DEBUG(
+ 22613, 1, "Loading library: {full_path_c_str}", "full_path_c_str"_attr = full_path.c_str());
void* handle = dlopen(full_path.c_str(), RTLD_NOW | RTLD_GLOBAL);
if (handle == nullptr) {
diff --git a/src/mongo/platform/shared_library_windows.cpp b/src/mongo/platform/shared_library_windows.cpp
index 504b366ab2e..9d9a261de59 100644
--- a/src/mongo/platform/shared_library_windows.cpp
+++ b/src/mongo/platform/shared_library_windows.cpp
@@ -34,6 +34,7 @@
#include <boost/filesystem.hpp>
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -45,14 +46,20 @@ SharedLibrary::~SharedLibrary() {
if (_handle) {
if (FreeLibrary(static_cast<HMODULE>(_handle)) == 0) {
DWORD lasterror = GetLastError();
- LOG(2) << "Load library close failed: " << errnoWithDescription(lasterror);
+ LOGV2_DEBUG(22614,
+ 2,
+ "Load library close failed: {errnoWithDescription_lasterror}",
+ "errnoWithDescription_lasterror"_attr = errnoWithDescription(lasterror));
}
}
}
StatusWith<std::unique_ptr<SharedLibrary>> SharedLibrary::create(
const boost::filesystem::path& full_path) {
- LOG(1) << "Loading library: " << toUtf8String(full_path.c_str());
+ LOGV2_DEBUG(22615,
+ 1,
+ "Loading library: {toUtf8String_full_path_c_str}",
+ "toUtf8String_full_path_c_str"_attr = toUtf8String(full_path.c_str()));
HMODULE handle = LoadLibraryW(full_path.c_str());
if (handle == nullptr) {
diff --git a/src/mongo/platform/source_location_test.cpp b/src/mongo/platform/source_location_test.cpp
index a702eda827e..5ba247fa807 100644
--- a/src/mongo/platform/source_location_test.cpp
+++ b/src/mongo/platform/source_location_test.cpp
@@ -27,9 +27,13 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/source_location_test.h"
+#include "mongo/util/log.h"
namespace mongo {
namespace {
@@ -64,9 +68,9 @@ TEST(SourceLocation, InlineVariable) {
ASSERT_LT(inlineLocation1.line(), inlineLocation2.line());
ASSERT_LT(inlineLocation2.line(), inlineLocation3.line());
- unittest::log() << inlineLocation1;
- unittest::log() << inlineLocation2;
- unittest::log() << inlineLocation3;
+ LOGV2(22616, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22617, "{inlineLocation2}", "inlineLocation2"_attr = inlineLocation2);
+ LOGV2(22618, "{inlineLocation3}", "inlineLocation3"_attr = inlineLocation3);
}
TEST(SourceLocation, LocalFunction) {
@@ -81,9 +85,11 @@ TEST(SourceLocation, LocalFunction) {
// The two local function locations should be identical
ASSERT_EQ(localFunctionLocation1, localFunctionLocation2);
- unittest::log() << inlineLocation1;
- unittest::log() << localFunctionLocation1;
- unittest::log() << localFunctionLocation2;
+ LOGV2(22619, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(
+ 22620, "{localFunctionLocation1}", "localFunctionLocation1"_attr = localFunctionLocation1);
+ LOGV2(
+ 22621, "{localFunctionLocation2}", "localFunctionLocation2"_attr = localFunctionLocation2);
}
TEST(SourceLocation, HeaderFunction) {
@@ -97,9 +103,9 @@ TEST(SourceLocation, HeaderFunction) {
// The two header locations should be identical
ASSERT_EQ(headerLocation1, headerLocation2);
- unittest::log() << inlineLocation1;
- unittest::log() << headerLocation1;
- unittest::log() << headerLocation2;
+ LOGV2(22622, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22623, "{headerLocation1}", "headerLocation1"_attr = headerLocation1);
+ LOGV2(22624, "{headerLocation2}", "headerLocation2"_attr = headerLocation2);
}
TEST(SourceLocation, GlobalVariable) {
@@ -109,8 +115,8 @@ TEST(SourceLocation, GlobalVariable) {
ASSERT_EQ(inlineLocation1.file_name(), kLocation.file_name());
ASSERT_GT(inlineLocation1.line(), kLocation.line());
- unittest::log() << inlineLocation1;
- unittest::log() << kLocation;
+ LOGV2(22625, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22626, "{kLocation}", "kLocation"_attr = kLocation);
}
TEST(SourceLocation, DefaultStructMember) {
@@ -125,9 +131,9 @@ TEST(SourceLocation, DefaultStructMember) {
// The two default ctor'd struct member locations should be identical
ASSERT_EQ(obj1.location, obj2.location);
- unittest::log() << inlineLocation1;
- unittest::log() << obj1.location;
- unittest::log() << obj2.location;
+ LOGV2(22627, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22628, "{obj1_location}", "obj1_location"_attr = obj1.location);
+ LOGV2(22629, "{obj2_location}", "obj2_location"_attr = obj2.location);
}
TEST(SourceLocation, Macro) {
@@ -140,8 +146,8 @@ TEST(SourceLocation, Macro) {
// The line numbers for each location should increase monotonically when inline
ASSERT_LT(inlineLocation1.line(), inlineLocation2.line());
- unittest::log() << inlineLocation1;
- unittest::log() << inlineLocation2;
+ LOGV2(22630, "{inlineLocation1}", "inlineLocation1"_attr = inlineLocation1);
+ LOGV2(22631, "{inlineLocation2}", "inlineLocation2"_attr = inlineLocation2);
}
TEST(SourceLocation, Constexpr) {
diff --git a/src/mongo/rpc/op_msg.cpp b/src/mongo/rpc/op_msg.cpp
index e0a8d60881c..b20e269283b 100644
--- a/src/mongo/rpc/op_msg.cpp
+++ b/src/mongo/rpc/op_msg.cpp
@@ -39,6 +39,7 @@
#include "mongo/base/data_type_endian.h"
#include "mongo/config.h"
#include "mongo/db/bson/dotted_path_support.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/object_check.h"
#include "mongo/util/bufreader.h"
#include "mongo/util/hex.h"
@@ -218,8 +219,14 @@ OpMsg OpMsg::parse(const Message& message) try {
return msg;
} catch (const DBException& ex) {
- LOG(1) << "invalid message: " << ex.code() << " " << redact(ex) << " -- "
- << redact(hexdump(message.singleData().view2ptr(), message.size()));
+ LOGV2_DEBUG(
+ 22632,
+ 1,
+ "invalid message: {ex_code} {ex} -- {hexdump_message_singleData_view2ptr_message_size}",
+ "ex_code"_attr = ex.code(),
+ "ex"_attr = redact(ex),
+ "hexdump_message_singleData_view2ptr_message_size"_attr =
+ redact(hexdump(message.singleData().view2ptr(), message.size())));
throw;
}
@@ -291,8 +298,11 @@ Message OpMsgBuilder::finish() {
std::set<StringData> seenFields;
for (auto elem : resumeBody().asTempObj()) {
if (!(seenFields.insert(elem.fieldNameStringData()).second)) {
- severe() << "OP_MSG with duplicate field '" << elem.fieldNameStringData()
- << "' : " << redact(resumeBody().asTempObj());
+ LOGV2_FATAL(22633,
+ "OP_MSG with duplicate field '{elem_fieldNameStringData}' : "
+ "{resumeBody_asTempObj}",
+ "elem_fieldNameStringData"_attr = elem.fieldNameStringData(),
+ "resumeBody_asTempObj"_attr = redact(resumeBody().asTempObj()));
fassert(40474, false);
}
}
diff --git a/src/mongo/rpc/op_msg_integration_test.cpp b/src/mongo/rpc/op_msg_integration_test.cpp
index 3e9125c00a6..68dc5fa259b 100644
--- a/src/mongo/rpc/op_msg_integration_test.cpp
+++ b/src/mongo/rpc/op_msg_integration_test.cpp
@@ -27,16 +27,20 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include "mongo/client/dbclient_connection.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/db/ops/write_ops.h"
#include "mongo/db/query/getmore_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/unittest/integration_test.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -694,14 +698,14 @@ TEST(OpMsg, ExhaustWithDBClientCursorBehavesCorrectly) {
conn->dropCollection(nss.toString());
const int nDocs = 5;
- unittest::log() << "Inserting " << nDocs << " documents.";
+ LOGV2(22634, "Inserting {nDocs} documents.", "nDocs"_attr = nDocs);
for (int i = 0; i < nDocs; i++) {
auto doc = BSON("_id" << i);
conn->insert(nss.toString(), doc);
}
ASSERT_EQ(conn->count(nss), size_t(nDocs));
- unittest::log() << "Finished document insertion.";
+ LOGV2(22635, "Finished document insertion.");
// Open an exhaust cursor.
int batchSize = 2;
diff --git a/src/mongo/rpc/op_msg_test.cpp b/src/mongo/rpc/op_msg_test.cpp
index c534dbdb702..8ad5723e6ce 100644
--- a/src/mongo/rpc/op_msg_test.cpp
+++ b/src/mongo/rpc/op_msg_test.cpp
@@ -37,6 +37,7 @@
#include "mongo/bson/json.h"
#include "mongo/bson/util/builder.h"
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/hex.h"
@@ -661,12 +662,18 @@ void testSerializer(const Message& fromSerializer, OpMsgBytes&& expected) {
std::mismatch(gotSD.begin(), gotSD.end(), expectedSD.begin(), expectedSD.end()).first -
gotSD.begin();
- log() << "Mismatch after " << commonLength << " bytes.";
- log() << "Common prefix: " << hexdump(gotSD.rawData(), commonLength);
- log() << "Got suffix : "
- << hexdump(gotSD.rawData() + commonLength, gotSD.size() - commonLength);
- log() << "Expected suffix: "
- << hexdump(expectedSD.rawData() + commonLength, expectedSD.size() - commonLength);
+ LOGV2(22636, "Mismatch after {commonLength} bytes.", "commonLength"_attr = commonLength);
+ LOGV2(22637,
+ "Common prefix: {hexdump_gotSD_rawData_commonLength}",
+ "hexdump_gotSD_rawData_commonLength"_attr = hexdump(gotSD.rawData(), commonLength));
+ LOGV2(22638,
+ "Got suffix : {hexdump_gotSD_rawData_commonLength_gotSD_size_commonLength}",
+ "hexdump_gotSD_rawData_commonLength_gotSD_size_commonLength"_attr =
+ hexdump(gotSD.rawData() + commonLength, gotSD.size() - commonLength));
+ LOGV2(22639,
+ "Expected suffix: {hexdump_expectedSD_rawData_commonLength_expectedSD_size_commonLength}",
+ "hexdump_expectedSD_rawData_commonLength_expectedSD_size_commonLength"_attr =
+ hexdump(expectedSD.rawData() + commonLength, expectedSD.size() - commonLength));
FAIL("Serialization didn't match expected data. See above for details.");
}
diff --git a/src/mongo/s/balancer_configuration.cpp b/src/mongo/s/balancer_configuration.cpp
index 8197c03e19c..ffce7776003 100644
--- a/src/mongo/s/balancer_configuration.cpp
+++ b/src/mongo/s/balancer_configuration.cpp
@@ -43,6 +43,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -242,8 +243,12 @@ Status BalancerConfiguration::_refreshChunkSizeSettings(OperationContext* opCtx)
}
if (settings.getMaxChunkSizeBytes() != getMaxChunkSizeBytes()) {
- log() << "MaxChunkSize changing from " << getMaxChunkSizeBytes() / (1024 * 1024) << "MB"
- << " to " << settings.getMaxChunkSizeBytes() / (1024 * 1024) << "MB";
+ LOGV2(22640,
+ "MaxChunkSize changing from {getMaxChunkSizeBytes_1024_1024}MB to "
+ "{settings_getMaxChunkSizeBytes_1024_1024}MB",
+ "getMaxChunkSizeBytes_1024_1024"_attr = getMaxChunkSizeBytes() / (1024 * 1024),
+ "settings_getMaxChunkSizeBytes_1024_1024"_attr =
+ settings.getMaxChunkSizeBytes() / (1024 * 1024));
_maxChunkSizeBytes.store(settings.getMaxChunkSizeBytes());
}
@@ -268,8 +273,10 @@ Status BalancerConfiguration::_refreshAutoSplitSettings(OperationContext* opCtx)
}
if (settings.getShouldAutoSplit() != getShouldAutoSplit()) {
- log() << "ShouldAutoSplit changing from " << getShouldAutoSplit() << " to "
- << settings.getShouldAutoSplit();
+ LOGV2(22641,
+ "ShouldAutoSplit changing from {getShouldAutoSplit} to {settings_getShouldAutoSplit}",
+ "getShouldAutoSplit"_attr = getShouldAutoSplit(),
+ "settings_getShouldAutoSplit"_attr = settings.getShouldAutoSplit());
_shouldAutoSplit.store(settings.getShouldAutoSplit());
}
diff --git a/src/mongo/s/catalog/replset_dist_lock_manager.cpp b/src/mongo/s/catalog/replset_dist_lock_manager.cpp
index a7c5d6221b8..b3d4e678e28 100644
--- a/src/mongo/s/catalog/replset_dist_lock_manager.cpp
+++ b/src/mongo/s/catalog/replset_dist_lock_manager.cpp
@@ -39,6 +39,7 @@
#include "mongo/base/status_with.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/dist_lock_catalog.h"
#include "mongo/s/catalog/type_lockpings.h"
#include "mongo/s/catalog/type_locks.h"
@@ -108,8 +109,11 @@ void ReplSetDistLockManager::shutDown(OperationContext* opCtx) {
auto status = _catalog->stopPing(opCtx, _processID);
if (!status.isOK()) {
- warning() << "error encountered while cleaning up distributed ping entry for " << _processID
- << causedBy(redact(status));
+ LOGV2_WARNING(22667,
+ "error encountered while cleaning up distributed ping entry for "
+ "{processID}{causedBy_status}",
+ "processID"_attr = _processID,
+ "causedBy_status"_attr = causedBy(redact(status)));
}
}
@@ -123,8 +127,11 @@ bool ReplSetDistLockManager::isShutDown() {
}
void ReplSetDistLockManager::doTask() {
- LOG(0) << "creating distributed lock ping thread for process " << _processID
- << " (sleeping for " << _pingInterval << ")";
+ LOGV2(22649,
+ "creating distributed lock ping thread for process {processID} (sleeping for "
+ "{pingInterval})",
+ "processID"_attr = _processID,
+ "pingInterval"_attr = _pingInterval);
Timer elapsedSincelastPing(_serviceContext->getTickSource());
Client::initThread("replSetDistLockPinger");
@@ -135,13 +142,17 @@ void ReplSetDistLockManager::doTask() {
auto pingStatus = _catalog->ping(opCtx.get(), _processID, Date_t::now());
if (!pingStatus.isOK() && pingStatus != ErrorCodes::NotMaster) {
- warning() << "pinging failed for distributed lock pinger" << causedBy(pingStatus);
+ LOGV2_WARNING(22668,
+ "pinging failed for distributed lock pinger{causedBy_pingStatus}",
+ "causedBy_pingStatus"_attr = causedBy(pingStatus));
}
const Milliseconds elapsed(elapsedSincelastPing.millis());
if (elapsed > 10 * _pingInterval) {
- warning() << "Lock pinger for proc: " << _processID << " was inactive for "
- << elapsed << " ms";
+ LOGV2_WARNING(22669,
+ "Lock pinger for proc: {processID} was inactive for {elapsed} ms",
+ "processID"_attr = _processID,
+ "elapsed"_attr = elapsed);
}
elapsedSincelastPing.reset();
@@ -164,15 +175,24 @@ void ReplSetDistLockManager::doTask() {
}
if (!unlockStatus.isOK()) {
- warning() << "Failed to unlock lock with " << LocksType::lockID() << ": "
- << toUnlock.first << nameMessage << causedBy(unlockStatus);
+ LOGV2_WARNING(22670,
+ "Failed to unlock lock with {LocksType_lockID}: "
+ "{toUnlock_first}{nameMessage}{causedBy_unlockStatus}",
+ "LocksType_lockID"_attr = LocksType::lockID(),
+ "toUnlock_first"_attr = toUnlock.first,
+ "nameMessage"_attr = nameMessage,
+ "causedBy_unlockStatus"_attr = causedBy(unlockStatus));
// Queue another attempt, unless the problem was no longer being primary.
if (unlockStatus != ErrorCodes::NotMaster) {
queueUnlock(toUnlock.first, toUnlock.second);
}
} else {
- LOG(0) << "distributed lock with " << LocksType::lockID() << ": "
- << toUnlock.first << nameMessage << " unlocked.";
+ LOGV2(22650,
+ "distributed lock with {LocksType_lockID}: {toUnlock_first}{nameMessage} "
+ "unlocked.",
+ "LocksType_lockID"_attr = LocksType::lockID(),
+ "toUnlock_first"_attr = toUnlock.first,
+ "nameMessage"_attr = nameMessage);
}
if (isShutDown()) {
@@ -246,8 +266,13 @@ StatusWith<bool> ReplSetDistLockManager::isLockExpired(OperationContext* opCtx,
auto* pingInfo = &pingIter->second;
- LOG(1) << "checking last ping for lock '" << lockDoc.getName() << "' against last seen process "
- << pingInfo->processId << " and ping " << pingInfo->lastPing;
+ LOGV2_DEBUG(22651,
+ 1,
+ "checking last ping for lock '{lockDoc_getName}' against last seen process "
+ "{pingInfo_processId} and ping {pingInfo_lastPing}",
+ "lockDoc_getName"_attr = lockDoc.getName(),
+ "pingInfo_processId"_attr = pingInfo->processId,
+ "pingInfo_lastPing"_attr = pingInfo->lastPing);
if (pingInfo->lastPing != pingValue || // ping is active
@@ -266,21 +291,35 @@ StatusWith<bool> ReplSetDistLockManager::isLockExpired(OperationContext* opCtx,
}
if (configServerLocalTime < pingInfo->configLocalTime) {
- warning() << "config server local time went backwards, from last seen: "
- << pingInfo->configLocalTime << " to " << configServerLocalTime;
+ LOGV2_WARNING(22671,
+ "config server local time went backwards, from last seen: "
+ "{pingInfo_configLocalTime} to {configServerLocalTime}",
+ "pingInfo_configLocalTime"_attr = pingInfo->configLocalTime,
+ "configServerLocalTime"_attr = configServerLocalTime);
return false;
}
Milliseconds elapsedSinceLastPing(configServerLocalTime - pingInfo->configLocalTime);
if (elapsedSinceLastPing >= lockExpiration) {
- LOG(0) << "forcing lock '" << lockDoc.getName() << "' because elapsed time "
- << elapsedSinceLastPing << " >= takeover time " << lockExpiration;
+ LOGV2(22652,
+ "forcing lock '{lockDoc_getName}' because elapsed time {elapsedSinceLastPing} >= "
+ "takeover time {lockExpiration}",
+ "lockDoc_getName"_attr = lockDoc.getName(),
+ "elapsedSinceLastPing"_attr = elapsedSinceLastPing,
+ "lockExpiration"_attr = lockExpiration);
return true;
}
- LOG(1) << "could not force lock '" << lockDoc.getName() << "' because elapsed time "
- << durationCount<Milliseconds>(elapsedSinceLastPing) << " < takeover time "
- << durationCount<Milliseconds>(lockExpiration) << " ms";
+ LOGV2_DEBUG(22653,
+ 1,
+ "could not force lock '{lockDoc_getName}' because elapsed time "
+ "{durationCount_Milliseconds_elapsedSinceLastPing} < takeover time "
+ "{durationCount_Milliseconds_lockExpiration} ms",
+ "lockDoc_getName"_attr = lockDoc.getName(),
+ "durationCount_Milliseconds_elapsedSinceLastPing"_attr =
+ durationCount<Milliseconds>(elapsedSinceLastPing),
+ "durationCount_Milliseconds_lockExpiration"_attr =
+ durationCount<Milliseconds>(lockExpiration));
return false;
}
@@ -311,11 +350,20 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::lockWithSessionID(OperationCo
lockExpiration = Milliseconds(data["timeoutMs"].numberInt());
});
- LOG(1) << "trying to acquire new distributed lock for " << name
- << " ( lock timeout : " << durationCount<Milliseconds>(lockExpiration)
- << " ms, ping interval : " << durationCount<Milliseconds>(_pingInterval)
- << " ms, process : " << _processID << " )"
- << " with lockSessionID: " << lockSessionID << ", why: " << whyMessage.toString();
+ LOGV2_DEBUG(22654,
+ 1,
+ "trying to acquire new distributed lock for {name} ( lock timeout : "
+ "{durationCount_Milliseconds_lockExpiration} ms, ping interval : "
+ "{durationCount_Milliseconds_pingInterval} ms, process : {processID} ) with "
+ "lockSessionID: {lockSessionID}, why: {whyMessage}",
+ "name"_attr = name,
+ "durationCount_Milliseconds_lockExpiration"_attr =
+ durationCount<Milliseconds>(lockExpiration),
+ "durationCount_Milliseconds_pingInterval"_attr =
+ durationCount<Milliseconds>(_pingInterval),
+ "processID"_attr = _processID,
+ "lockSessionID"_attr = lockSessionID,
+ "whyMessage"_attr = whyMessage.toString());
auto lockResult = _catalog->grabLock(
opCtx, name, lockSessionID, who, _processID, Date_t::now(), whyMessage.toString());
@@ -325,17 +373,23 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::lockWithSessionID(OperationCo
if (status.isOK()) {
// Lock is acquired since findAndModify was able to successfully modify
// the lock document.
- log() << "distributed lock '" << name << "' acquired for '" << whyMessage.toString()
- << "', ts : " << lockSessionID;
+ LOGV2(22655,
+ "distributed lock '{name}' acquired for '{whyMessage}', ts : {lockSessionID}",
+ "name"_attr = name,
+ "whyMessage"_attr = whyMessage.toString(),
+ "lockSessionID"_attr = lockSessionID);
return lockSessionID;
}
// If a network error occurred, unlock the lock synchronously and try again
if (configShard->isRetriableError(status.code(), Shard::RetryPolicy::kIdempotent) &&
networkErrorRetries < kMaxNumLockAcquireRetries) {
- LOG(1) << "Failed to acquire distributed lock because of retriable error. Retrying "
- "acquisition by first unlocking the stale entry, which possibly exists now"
- << causedBy(redact(status));
+ LOGV2_DEBUG(22656,
+ 1,
+ "Failed to acquire distributed lock because of retriable error. Retrying "
+ "acquisition by first unlocking the stale entry, which possibly exists "
+ "now{causedBy_status}",
+ "causedBy_status"_attr = causedBy(redact(status)));
networkErrorRetries++;
@@ -348,9 +402,11 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::lockWithSessionID(OperationCo
// Fall-through to the error checking logic below
invariant(status != ErrorCodes::LockStateChangeFailed);
- LOG(1)
- << "Failed to retry acquisition of distributed lock. No more attempts will be made"
- << causedBy(redact(status));
+ LOGV2_DEBUG(22657,
+ 1,
+ "Failed to retry acquisition of distributed lock. No more attempts will be "
+ "made{causedBy_status}",
+ "causedBy_status"_attr = causedBy(redact(status)));
}
if (status != ErrorCodes::LockStateChangeFailed) {
@@ -394,8 +450,11 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::lockWithSessionID(OperationCo
// Lock is acquired since findAndModify was able to successfully modify
// the lock document.
- LOG(0) << "lock '" << name << "' successfully forced";
- LOG(0) << "distributed lock '" << name << "' acquired, ts : " << lockSessionID;
+ LOGV2(22658, "lock '{name}' successfully forced", "name"_attr = name);
+ LOGV2(22659,
+ "distributed lock '{name}' acquired, ts : {lockSessionID}",
+ "name"_attr = name,
+ "lockSessionID"_attr = lockSessionID);
return lockSessionID;
}
@@ -408,7 +467,7 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::lockWithSessionID(OperationCo
}
}
- LOG(1) << "distributed lock '" << name << "' was not acquired.";
+ LOGV2_DEBUG(22660, 1, "distributed lock '{name}' was not acquired.", "name"_attr = name);
if (waitFor == Milliseconds::zero()) {
break;
@@ -416,8 +475,11 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::lockWithSessionID(OperationCo
// Periodically message for debugging reasons
if (msgTimer.seconds() > 10) {
- LOG(0) << "waited " << timer.seconds() << "s for distributed lock " << name << " for "
- << whyMessage.toString();
+ LOGV2(22661,
+ "waited {timer_seconds}s for distributed lock {name} for {whyMessage}",
+ "timer_seconds"_attr = timer.seconds(),
+ "name"_attr = name,
+ "whyMessage"_attr = whyMessage.toString());
msgTimer.reset();
}
@@ -438,11 +500,20 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::tryLockWithLocalWriteConcern(
OperationContext* opCtx, StringData name, StringData whyMessage, const OID& lockSessionID) {
const string who = str::stream() << _processID << ":" << getThreadName();
- LOG(1) << "trying to acquire new distributed lock for " << name
- << " ( lock timeout : " << durationCount<Milliseconds>(_lockExpiration)
- << " ms, ping interval : " << durationCount<Milliseconds>(_pingInterval)
- << " ms, process : " << _processID << " )"
- << " with lockSessionID: " << lockSessionID << ", why: " << whyMessage.toString();
+ LOGV2_DEBUG(22662,
+ 1,
+ "trying to acquire new distributed lock for {name} ( lock timeout : "
+ "{durationCount_Milliseconds_lockExpiration} ms, ping interval : "
+ "{durationCount_Milliseconds_pingInterval} ms, process : {processID} ) with "
+ "lockSessionID: {lockSessionID}, why: {whyMessage}",
+ "name"_attr = name,
+ "durationCount_Milliseconds_lockExpiration"_attr =
+ durationCount<Milliseconds>(_lockExpiration),
+ "durationCount_Milliseconds_pingInterval"_attr =
+ durationCount<Milliseconds>(_pingInterval),
+ "processID"_attr = _processID,
+ "lockSessionID"_attr = lockSessionID,
+ "whyMessage"_attr = whyMessage.toString());
auto lockStatus = _catalog->grabLock(opCtx,
name,
@@ -454,12 +525,15 @@ StatusWith<DistLockHandle> ReplSetDistLockManager::tryLockWithLocalWriteConcern(
DistLockCatalog::kLocalWriteConcern);
if (lockStatus.isOK()) {
- log() << "distributed lock '" << name << "' acquired for '" << whyMessage.toString()
- << "', ts : " << lockSessionID;
+ LOGV2(22663,
+ "distributed lock '{name}' acquired for '{whyMessage}', ts : {lockSessionID}",
+ "name"_attr = name,
+ "whyMessage"_attr = whyMessage.toString(),
+ "lockSessionID"_attr = lockSessionID);
return lockSessionID;
}
- LOG(1) << "distributed lock '" << name << "' was not acquired.";
+ LOGV2_DEBUG(22664, 1, "distributed lock '{name}' was not acquired.", "name"_attr = name);
if (lockStatus == ErrorCodes::LockStateChangeFailed) {
return {ErrorCodes::LockBusy, str::stream() << "Unable to acquire " << name};
@@ -474,8 +548,10 @@ void ReplSetDistLockManager::unlock(OperationContext* opCtx, const DistLockHandl
if (!unlockStatus.isOK()) {
queueUnlock(lockSessionID, boost::none);
} else {
- LOG(0) << "distributed lock with " << LocksType::lockID() << ": " << lockSessionID
- << "' unlocked.";
+ LOGV2(22665,
+ "distributed lock with {LocksType_lockID}: {lockSessionID}' unlocked.",
+ "LocksType_lockID"_attr = LocksType::lockID(),
+ "lockSessionID"_attr = lockSessionID);
}
}
@@ -487,16 +563,22 @@ void ReplSetDistLockManager::unlock(OperationContext* opCtx,
if (!unlockStatus.isOK()) {
queueUnlock(lockSessionID, name.toString());
} else {
- LOG(0) << "distributed lock with " << LocksType::lockID() << ": '" << lockSessionID
- << "' and " << LocksType::name() << ": '" << name.toString() << "' unlocked.";
+ LOGV2(22666,
+ "distributed lock with {LocksType_lockID}: '{lockSessionID}' and {LocksType_name}: "
+ "'{name}' unlocked.",
+ "LocksType_lockID"_attr = LocksType::lockID(),
+ "lockSessionID"_attr = lockSessionID,
+ "LocksType_name"_attr = LocksType::name(),
+ "name"_attr = name.toString());
}
}
void ReplSetDistLockManager::unlockAll(OperationContext* opCtx, const std::string& processID) {
Status status = _catalog->unlockAll(opCtx, processID);
if (!status.isOK()) {
- warning() << "Error while trying to unlock existing distributed locks"
- << causedBy(redact(status));
+ LOGV2_WARNING(22672,
+ "Error while trying to unlock existing distributed locks{causedBy_status}",
+ "causedBy_status"_attr = causedBy(redact(status)));
}
}
diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
index 04d88a11834..171fdbbf1e1 100644
--- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
+++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp
@@ -48,6 +48,7 @@
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/executor/network_interface.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/s/catalog/config_server_version.h"
@@ -154,7 +155,7 @@ void ShardingCatalogClientImpl::startup() {
}
void ShardingCatalogClientImpl::shutDown(OperationContext* opCtx) {
- LOG(1) << "ShardingCatalogClientImpl::shutDown() called.";
+ LOGV2_DEBUG(22673, 1, "ShardingCatalogClientImpl::shutDown() called.");
{
stdx::lock_guard<Latch> lk(_mutex);
_inShutdown = true;
@@ -722,8 +723,10 @@ Status ShardingCatalogClientImpl::applyChunkOpsDeprecated(OperationContext* opCt
// document in the list of updates should be returned from a query to the chunks
// collection. The last chunk can be identified by namespace and version number.
- warning() << "chunk operation commit failed and metadata will be revalidated"
- << causedBy(redact(status));
+ LOGV2_WARNING(
+ 22675,
+ "chunk operation commit failed and metadata will be revalidated{causedBy_status}",
+ "causedBy_status"_attr = causedBy(redact(status)));
// Look for the chunk in this shard whose version got bumped. We assume that if that
// mod made it to the config server, then transaction was successful.
@@ -810,7 +813,8 @@ Status ShardingCatalogClientImpl::insertConfigDocument(OperationContext* opCtx,
// or it is because we failed to wait for write concern on the first attempt. In order to
// differentiate, fetch the entry and check.
if (retry > 1 && status == ErrorCodes::DuplicateKey) {
- LOG(1) << "Insert retry failed because of duplicate key error, rechecking.";
+ LOGV2_DEBUG(
+ 22674, 1, "Insert retry failed because of duplicate key error, rechecking.");
auto fetchDuplicate =
_exhaustiveFindOnConfig(opCtx,
diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp
index 5b677d2671d..c7f2bb37315 100644
--- a/src/mongo/s/catalog_cache.cpp
+++ b/src/mongo/s/catalog_cache.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/logical_clock.h"
#include "mongo/db/query/collation/collator_factory_interface.h"
#include "mongo/db/repl/optime_with.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_database.h"
#include "mongo/s/client/shard_registry.h"
@@ -345,7 +346,8 @@ void CatalogCache::onStaleDatabaseVersion(const StringData dbName,
} else if (!itDbEntry->second->dbt ||
databaseVersion::equal(itDbEntry->second->dbt->getVersion(), databaseVersion)) {
// If the versions match, the cached database info is stale, so mark it as needs refresh.
- log() << "Marking cached database entry for '" << dbName << "' as stale";
+ LOGV2(
+ 22642, "Marking cached database entry for '{dbName}' as stale", "dbName"_attr = dbName);
itDbEntry->second->needsRefresh = true;
}
}
@@ -456,14 +458,23 @@ void CatalogCache::invalidateShardForShardedCollection(const NamespaceString& ns
void CatalogCache::invalidateEntriesThatReferenceShard(const ShardId& shardId) {
stdx::lock_guard<Latch> lg(_mutex);
- log() << "Starting to invalidate databases and collections with data on shard: " << shardId;
+ LOGV2(22643,
+ "Starting to invalidate databases and collections with data on shard: {shardId}",
+ "shardId"_attr = shardId);
// Invalidate databases with this shard as their primary.
for (const auto& [dbNs, dbInfoEntry] : _databases) {
- LOG(3) << "Checking if database " << dbNs << "has primary shard: " << shardId;
+ LOGV2_DEBUG(22644,
+ 3,
+ "Checking if database {dbNs}has primary shard: {shardId}",
+ "dbNs"_attr = dbNs,
+ "shardId"_attr = shardId);
if (!dbInfoEntry->needsRefresh && dbInfoEntry->dbt->getPrimary() == shardId) {
- LOG(3) << "Database " << dbNs << "has primary shard " << shardId
- << ", invalidating cache entry";
+ LOGV2_DEBUG(22645,
+ 3,
+ "Database {dbNs}has primary shard {shardId}, invalidating cache entry",
+ "dbNs"_attr = dbNs,
+ "shardId"_attr = shardId);
dbInfoEntry->needsRefresh = true;
}
}
@@ -472,7 +483,11 @@ void CatalogCache::invalidateEntriesThatReferenceShard(const ShardId& shardId) {
for (const auto& [db, collInfoMap] : _collectionsByDb) {
for (const auto& [collNs, collRoutingInfoEntry] : collInfoMap) {
- LOG(3) << "Checking if " << collNs << "has data on shard: " << shardId;
+ LOGV2_DEBUG(22646,
+ 3,
+ "Checking if {collNs}has data on shard: {shardId}",
+ "collNs"_attr = collNs,
+ "shardId"_attr = shardId);
// The set of shards on which this collection contains chunks.
std::set<ShardId> shardsOwningDataForCollection;
if (collRoutingInfoEntry->routingInfo) {
@@ -480,8 +495,11 @@ void CatalogCache::invalidateEntriesThatReferenceShard(const ShardId& shardId) {
if (shardsOwningDataForCollection.find(shardId) !=
shardsOwningDataForCollection.end()) {
- LOG(3) << collNs << "has data on shard " << shardId
- << ", invalidating cache entry";
+ LOGV2_DEBUG(22647,
+ 3,
+ "{collNs}has data on shard {shardId}, invalidating cache entry",
+ "collNs"_attr = collNs,
+ "shardId"_attr = shardId);
collRoutingInfoEntry->routingInfo->setShardStale(shardId);
}
@@ -489,7 +507,9 @@ void CatalogCache::invalidateEntriesThatReferenceShard(const ShardId& shardId) {
}
}
- log() << "Finished invalidating databases and collections with data on shard: " << shardId;
+ LOGV2(22648,
+ "Finished invalidating databases and collections with data on shard: {shardId}",
+ "shardId"_attr = shardId);
}
void CatalogCache::purgeCollection(const NamespaceString& nss) {
diff --git a/src/mongo/s/chunk_manager_index_bounds_test.cpp b/src/mongo/s/chunk_manager_index_bounds_test.cpp
index 3ff2dd03cb0..822ad25aa9c 100644
--- a/src/mongo/s/chunk_manager_index_bounds_test.cpp
+++ b/src/mongo/s/chunk_manager_index_bounds_test.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/db/pipeline/expression_context_for_test.h"
#include "mongo/db/query/canonical_query.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/shard_key_pattern.h"
#include "mongo/s/sharding_router_test_fixture.h"
@@ -88,7 +89,10 @@ protected:
for (size_t i = 0; i < oil.intervals.size(); i++) {
if (Interval::INTERVAL_EQUALS !=
oil.intervals[i].compare(expectedOil.intervals[i])) {
- log() << oil.intervals[i] << " != " << expectedOil.intervals[i];
+ LOGV2(22676,
+ "{oil_intervals_i} != {expectedOil_intervals_i}",
+ "oil_intervals_i"_attr = oil.intervals[i],
+ "expectedOil_intervals_i"_attr = expectedOil.intervals[i]);
}
ASSERT_EQUALS(Interval::INTERVAL_EQUALS,
oil.intervals[i].compare(expectedOil.intervals[i]));
@@ -109,7 +113,7 @@ protected:
if (oil.intervals.size() != expectedOil.intervals.size()) {
for (size_t i = 0; i < oil.intervals.size(); i++) {
- log() << oil.intervals[i];
+ LOGV2(22677, "{oil_intervals_i}", "oil_intervals_i"_attr = oil.intervals[i]);
}
}
diff --git a/src/mongo/s/client/parallel.cpp b/src/mongo/s/client/parallel.cpp
index fae0d1c7c47..83360c2f958 100644
--- a/src/mongo/s/client/parallel.cpp
+++ b/src/mongo/s/client/parallel.cpp
@@ -39,6 +39,7 @@
#include "mongo/client/replica_set_monitor.h"
#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/query/query_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_connection.h"
@@ -376,9 +377,11 @@ void ParallelSortClusteredCursor::setupVersionAndHandleSlaveOk(
if (sampler.tick()) {
const DBClientReplicaSet* repl = dynamic_cast<const DBClientReplicaSet*>(rawConn);
dassert(repl);
- warning() << "Primary for " << repl->getServerAddress()
- << " was down before, bypassing setShardVersion."
- << " The local replica set view and targeting may be stale.";
+ LOGV2_WARNING(
+ 22695,
+ "Primary for {repl_getServerAddress} was down before, bypassing "
+ "setShardVersion. The local replica set view and targeting may be stale.",
+ "repl_getServerAddress"_attr = repl->getServerAddress());
}
return;
@@ -387,8 +390,11 @@ void ParallelSortClusteredCursor::setupVersionAndHandleSlaveOk(
try {
if (state->conn->setVersion()) {
- LOG(2) << "pcursor: needed to set remote version on connection to value "
- << "compatible with " << vinfo;
+ LOGV2_DEBUG(22678,
+ 2,
+ "pcursor: needed to set remote version on connection to value compatible "
+ "with {vinfo}",
+ "vinfo"_attr = vinfo);
}
} catch (const DBException& dbExcep) {
auto errCode = dbExcep.code();
@@ -403,9 +409,10 @@ void ParallelSortClusteredCursor::setupVersionAndHandleSlaveOk(
const DBClientReplicaSet* repl =
dynamic_cast<const DBClientReplicaSet*>(state->conn->getRawConn());
dassert(repl);
- warning() << "Cannot contact primary for " << repl->getServerAddress()
- << " to check shard version."
- << " The local replica set view and targeting may be stale.";
+ LOGV2_WARNING(22696,
+ "Cannot contact primary for {repl_getServerAddress} to check shard "
+ "version. The local replica set view and targeting may be stale.",
+ "repl_getServerAddress"_attr = repl->getServerAddress());
}
} else {
throw;
@@ -425,7 +432,12 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
prefix = "creating";
}
}
- LOG(2) << "pcursor: " << prefix << " pcursor over " << _qSpec << " and " << _cInfo;
+ LOGV2_DEBUG(22679,
+ 2,
+ "pcursor: {prefix} pcursor over {qSpec} and {cInfo}",
+ "prefix"_attr = prefix,
+ "qSpec"_attr = _qSpec,
+ "cInfo"_attr = _cInfo);
shared_ptr<ChunkManager> manager;
shared_ptr<Shard> primary;
@@ -470,14 +482,22 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
const auto& shardId = cmEntry.first;
if (shardIds.find(shardId) == shardIds.end()) {
- LOG(2) << "pcursor: closing cursor on shard " << shardId
- << " as the connection is no longer required by " << vinfo;
+ LOGV2_DEBUG(22680,
+ 2,
+ "pcursor: closing cursor on shard {shardId} as the connection is no longer "
+ "required by {vinfo}",
+ "shardId"_attr = shardId,
+ "vinfo"_attr = vinfo);
cmEntry.second.cleanup(true);
}
}
- LOG(2) << "pcursor: initializing over " << shardIds.size() << " shards required by " << vinfo;
+ LOGV2_DEBUG(22681,
+ 2,
+ "pcursor: initializing over {shardIds_size} shards required by {vinfo}",
+ "shardIds_size"_attr = shardIds.size(),
+ "vinfo"_attr = vinfo);
// Don't retry indefinitely for whatever reason
_totalTries++;
@@ -486,8 +506,11 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
for (const ShardId& shardId : shardIds) {
auto& mdata = _cursorMap[shardId];
- LOG(2) << "pcursor: initializing on shard " << shardId << ", current connection state is "
- << mdata.toBSON();
+ LOGV2_DEBUG(22682,
+ 2,
+ "pcursor: initializing on shard {shardId}, current connection state is {mdata}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON());
// This may be the first time connecting to this shard, if so we can get an error here
try {
@@ -500,11 +523,11 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
bool compatibleManager = true;
if (primary && !state->primary)
- warning() << "Collection becoming unsharded detected";
+ LOGV2_WARNING(22697, "Collection becoming unsharded detected");
if (manager && !state->manager)
- warning() << "Collection becoming sharded detected";
+ LOGV2_WARNING(22698, "Collection becoming sharded detected");
if (primary && state->primary && primary != state->primary)
- warning() << "Weird shift of primary detected";
+ LOGV2_WARNING(22699, "Weird shift of primary detected");
compatiblePrimary = primary && state->primary && primary == state->primary;
compatibleManager =
@@ -609,9 +632,14 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
mdata.finished = true;
}
- LOG(2) << "pcursor: initialized " << (isCommand() ? "command " : "query ")
- << (lazyInit ? "(lazily) " : "(full) ") << "on shard " << shardId
- << ", current connection state is " << mdata.toBSON();
+ LOGV2_DEBUG(22683,
+ 2,
+ "pcursor: initialized {isCommand_command_query}{lazyInit_lazily_full}on "
+ "shard {shardId}, current connection state is {mdata}",
+ "isCommand_command_query"_attr = (isCommand() ? "command " : "query "),
+ "lazyInit_lazily_full"_attr = (lazyInit ? "(lazily) " : "(full) "),
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON());
} catch (StaleConfigException& e) {
// Our version isn't compatible with the current version anymore on at least one shard,
// need to retry immediately
@@ -623,21 +651,32 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
->invalidateShardOrEntireCollectionEntryForShardedCollection(
opCtx, nss, e->getVersionWanted(), e->getVersionReceived(), e->getShardId());
- LOG(1) << "stale config of ns " << staleNS << " during initialization, will retry"
- << causedBy(redact(e));
+ LOGV2_DEBUG(
+ 22684,
+ 1,
+ "stale config of ns {staleNS} during initialization, will retry{causedBy_e}",
+ "staleNS"_attr = staleNS,
+ "causedBy_e"_attr = causedBy(redact(e)));
// This is somewhat strange
if (staleNS != nss) {
- warning() << "versioned ns " << nss.ns() << " doesn't match stale config namespace "
- << staleNS;
+ LOGV2_WARNING(
+ 22700,
+ "versioned ns {nss_ns} doesn't match stale config namespace {staleNS}",
+ "nss_ns"_attr = nss.ns(),
+ "staleNS"_attr = staleNS);
}
// Restart with new chunk manager
startInit(opCtx);
return;
} catch (NetworkException& e) {
- warning() << "socket exception when initializing on " << shardId
- << ", current connection state is " << mdata.toBSON() << causedBy(redact(e));
+ LOGV2_WARNING(22701,
+ "socket exception when initializing on {shardId}, current connection "
+ "state is {mdata}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON(),
+ "causedBy_e"_attr = causedBy(redact(e)));
mdata.errored = true;
if (returnPartial) {
mdata.cleanup(true);
@@ -645,8 +684,12 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
}
throw;
} catch (DBException& e) {
- warning() << "db exception when initializing on " << shardId
- << ", current connection state is " << mdata.toBSON() << causedBy(redact(e));
+ LOGV2_WARNING(22702,
+ "db exception when initializing on {shardId}, current connection state "
+ "is {mdata}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON(),
+ "causedBy_e"_attr = causedBy(redact(e)));
mdata.errored = true;
if (returnPartial && e.code() == 15925 /* From above! */) {
mdata.cleanup(true);
@@ -654,13 +697,20 @@ void ParallelSortClusteredCursor::startInit(OperationContext* opCtx) {
}
throw;
} catch (std::exception& e) {
- warning() << "exception when initializing on " << shardId
- << ", current connection state is " << mdata.toBSON() << causedBy(e);
+ LOGV2_WARNING(22703,
+ "exception when initializing on {shardId}, current connection state is "
+ "{mdata}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON(),
+ "causedBy_e"_attr = causedBy(e));
mdata.errored = true;
throw;
} catch (...) {
- warning() << "unknown exception when initializing on " << shardId
- << ", current connection state is " << mdata.toBSON();
+ LOGV2_WARNING(22704,
+ "unknown exception when initializing on {shardId}, current connection "
+ "state is {mdata}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON());
mdata.errored = true;
throw;
}
@@ -709,14 +759,20 @@ void ParallelSortClusteredCursor::finishInit(OperationContext* opCtx) {
bool retry = false;
map<string, StaleConfigException> staleNSExceptions;
- LOG(2) << "pcursor: finishing over " << _cursorMap.size() << " shards";
+ LOGV2_DEBUG(22685,
+ 2,
+ "pcursor: finishing over {cursorMap_size} shards",
+ "cursorMap_size"_attr = _cursorMap.size());
for (auto& cmEntry : _cursorMap) {
const auto& shardId = cmEntry.first;
auto& mdata = cmEntry.second;
- LOG(2) << "pcursor: finishing on shard " << shardId << ", current connection state is "
- << mdata.toBSON();
+ LOGV2_DEBUG(22686,
+ 2,
+ "pcursor: finishing on shard {shardId}, current connection state is {mdata}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON());
// Ignore empty conns for now
if (!mdata.pcState)
@@ -763,8 +819,12 @@ void ParallelSortClusteredCursor::finishInit(OperationContext* opCtx) {
// Finalize state
state->cursor->attach(state->conn.get()); // Closes connection for us
- LOG(2) << "pcursor: finished on shard " << shardId
- << ", current connection state is " << mdata.toBSON();
+ LOGV2_DEBUG(
+ 22687,
+ 2,
+ "pcursor: finished on shard {shardId}, current connection state is {mdata}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON());
}
} catch (StaleConfigException& e) {
retry = true;
@@ -778,8 +838,12 @@ void ParallelSortClusteredCursor::finishInit(OperationContext* opCtx) {
mdata.cleanup(true);
continue;
} catch (NetworkException& e) {
- warning() << "socket exception when finishing on " << shardId
- << ", current connection state is " << mdata.toBSON() << causedBy(redact(e));
+ LOGV2_WARNING(22705,
+ "socket exception when finishing on {shardId}, current connection state "
+ "is {mdata}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON(),
+ "causedBy_e"_attr = causedBy(redact(e)));
mdata.errored = true;
if (returnPartial) {
mdata.cleanup(true);
@@ -790,9 +854,12 @@ void ParallelSortClusteredCursor::finishInit(OperationContext* opCtx) {
// NOTE: RECV() WILL NOT THROW A SOCKET EXCEPTION - WE GET THIS AS ERROR 15988 FROM
// ABOVE
if (e.code() == 15988) {
- warning() << "exception when receiving data from " << shardId
- << ", current connection state is " << mdata.toBSON()
- << causedBy(redact(e));
+ LOGV2_WARNING(22706,
+ "exception when receiving data from {shardId}, current connection "
+ "state is {mdata}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON(),
+ "causedBy_e"_attr = causedBy(redact(e)));
mdata.errored = true;
if (returnPartial) {
@@ -804,23 +871,36 @@ void ParallelSortClusteredCursor::finishInit(OperationContext* opCtx) {
// the InvalidBSON exception indicates that the BSON is malformed ->
// don't print/call "mdata.toBSON()" to avoid unexpected errors e.g. a segfault
if (e.code() == ErrorCodes::InvalidBSON)
- warning() << "bson is malformed :: db exception when finishing on " << shardId
- << causedBy(redact(e));
+ LOGV2_WARNING(
+ 22707,
+ "bson is malformed :: db exception when finishing on {shardId}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "causedBy_e"_attr = causedBy(redact(e)));
else
- warning() << "db exception when finishing on " << shardId
- << ", current connection state is " << mdata.toBSON()
- << causedBy(redact(e));
+ LOGV2_WARNING(22708,
+ "db exception when finishing on {shardId}, current connection "
+ "state is {mdata}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON(),
+ "causedBy_e"_attr = causedBy(redact(e)));
mdata.errored = true;
throw;
}
} catch (std::exception& e) {
- warning() << "exception when finishing on " << shardId
- << ", current connection state is " << mdata.toBSON() << causedBy(e);
+ LOGV2_WARNING(22709,
+ "exception when finishing on {shardId}, current connection state is "
+ "{mdata}{causedBy_e}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON(),
+ "causedBy_e"_attr = causedBy(e));
mdata.errored = true;
throw;
} catch (...) {
- warning() << "unknown exception when finishing on " << shardId
- << ", current connection state is " << mdata.toBSON();
+ LOGV2_WARNING(22710,
+ "unknown exception when finishing on {shardId}, current connection state "
+ "is {mdata}",
+ "shardId"_attr = shardId,
+ "mdata"_attr = mdata.toBSON());
mdata.errored = true;
throw;
}
@@ -844,13 +924,20 @@ void ParallelSortClusteredCursor::finishInit(OperationContext* opCtx) {
staleNS, *ex->getShardId());
}
- LOG(1) << "stale config of ns " << staleNS << " on finishing query, will retry"
- << causedBy(redact(ex));
+ LOGV2_DEBUG(
+ 22688,
+ 1,
+ "stale config of ns {staleNS} on finishing query, will retry{causedBy_ex}",
+ "staleNS"_attr = staleNS,
+ "causedBy_ex"_attr = causedBy(redact(ex)));
// This is somewhat strange
if (staleNS.ns() != ns) {
- warning() << "versioned ns " << ns << " doesn't match stale config namespace "
- << staleNS;
+ LOGV2_WARNING(
+ 22711,
+ "versioned ns {ns} doesn't match stale config namespace {staleNS}",
+ "ns"_attr = ns,
+ "staleNS"_attr = staleNS);
}
}
}
@@ -867,7 +954,7 @@ void ParallelSortClusteredCursor::finishInit(OperationContext* opCtx) {
// Erase empty stuff
if (!mdata.pcState) {
- log() << "PCursor erasing empty state " << mdata.toBSON();
+ LOGV2(22689, "PCursor erasing empty state {mdata}", "mdata"_attr = mdata.toBSON());
_cursorMap.erase(i++);
continue;
} else {
@@ -957,13 +1044,16 @@ void ParallelSortClusteredCursor::_oldInit(OperationContext* opCtx) {
bool firstPass = retryQueries.size() == 0;
if (!firstPass) {
- log() << "retrying " << (returnPartial ? "(partial) " : "")
- << "parallel connection to ";
+ LOGV2(22690,
+ "retrying {returnPartial_partial}parallel connection to ",
+ "returnPartial_partial"_attr = (returnPartial ? "(partial) " : ""));
for (set<int>::const_iterator it = retryQueries.begin(); it != retryQueries.end();
++it) {
- log() << serverHosts[*it] << ", ";
+ LOGV2(22691, "{serverHosts_it}, ", "serverHosts_it"_attr = serverHosts[*it]);
}
- log() << finishedQueries << " finished queries.";
+ LOGV2(22692,
+ "{finishedQueries} finished queries.",
+ "finishedQueries"_attr = finishedQueries);
}
size_t num = 0;
@@ -1008,9 +1098,15 @@ void ParallelSortClusteredCursor::_oldInit(OperationContext* opCtx) {
break;
}
- LOG(5) << "ParallelSortClusteredCursor::init server:" << serverHost << " ns:" << _ns
- << " query:" << redact(_query) << " fields:" << redact(_fields)
- << " options: " << _options;
+ LOGV2_DEBUG(22693,
+ 5,
+ "ParallelSortClusteredCursor::init server:{serverHost} ns:{ns} "
+ "query:{query} fields:{fields} options: {options}",
+ "serverHost"_attr = serverHost,
+ "ns"_attr = _ns,
+ "query"_attr = redact(_query),
+ "fields"_attr = redact(_fields),
+ "options"_attr = _options);
if (!_cursors[i].get())
_cursors[i].reset(
@@ -1061,8 +1157,10 @@ void ParallelSortClusteredCursor::_oldInit(OperationContext* opCtx) {
try {
if (!_cursors[i].get()->initLazyFinish(retry)) {
- warning() << "invalid result from " << conns[i]->getHost()
- << (retry ? ", retrying" : "");
+ LOGV2_WARNING(22712,
+ "invalid result from {conns_i_getHost}{retry_retrying}",
+ "conns_i_getHost"_attr = conns[i]->getHost(),
+ "retry_retrying"_attr = (retry ? ", retrying" : ""));
_cursors[i].reset(nullptr, nullptr);
if (!retry) {
@@ -1166,12 +1264,14 @@ void ParallelSortClusteredCursor::_oldInit(OperationContext* opCtx) {
} else if (throwException) {
uasserted(14827, errMsg.str());
} else {
- warning() << redact(errMsg.str());
+ LOGV2_WARNING(22713, "{errMsg_str}", "errMsg_str"_attr = redact(errMsg.str()));
}
}
if (retries > 0)
- log() << "successfully finished parallel query after " << retries << " retries";
+ LOGV2(22694,
+ "successfully finished parallel query after {retries} retries",
+ "retries"_attr = retries);
}
bool ParallelSortClusteredCursor::more() {
@@ -1264,9 +1364,9 @@ void ParallelConnectionMetadata::cleanup(bool full) {
bool retry = false;
pcState->cursor->initLazyFinish(retry);
} catch (std::exception&) {
- warning() << "exception closing cursor";
+ LOGV2_WARNING(22714, "exception closing cursor");
} catch (...) {
- warning() << "unknown exception closing cursor";
+ LOGV2_WARNING(22715, "unknown exception closing cursor");
}
}
}
diff --git a/src/mongo/s/client/shard.cpp b/src/mongo/s/client/shard.cpp
index 0ee5444dc5a..f76216b1c4a 100644
--- a/src/mongo/s/client/shard.cpp
+++ b/src/mongo/s/client/shard.cpp
@@ -38,6 +38,7 @@
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -125,9 +126,12 @@ StatusWith<Shard::CommandResponse> Shard::runCommand(OperationContext* opCtx,
auto swResponse = _runCommand(opCtx, readPref, dbName, maxTimeMSOverride, cmdObj);
auto status = CommandResponse::getEffectiveStatus(swResponse);
if (isRetriableError(status.code(), retryPolicy)) {
- LOG(2) << "Command " << redact(cmdObj)
- << " failed with retriable error and will be retried"
- << causedBy(redact(status));
+ LOGV2_DEBUG(
+ 22719,
+ 2,
+ "Command {cmdObj} failed with retriable error and will be retried{causedBy_status}",
+ "cmdObj"_attr = redact(cmdObj),
+ "causedBy_status"_attr = causedBy(redact(status)));
continue;
}
@@ -162,9 +166,12 @@ StatusWith<Shard::CommandResponse> Shard::runCommandWithFixedRetryAttempts(
auto swResponse = _runCommand(opCtx, readPref, dbName, maxTimeMSOverride, cmdObj);
auto status = CommandResponse::getEffectiveStatus(swResponse);
if (retry < kOnErrorNumRetries && isRetriableError(status.code(), retryPolicy)) {
- LOG(2) << "Command " << redact(cmdObj)
- << " failed with retriable error and will be retried"
- << causedBy(redact(status));
+ LOGV2_DEBUG(
+ 22720,
+ 2,
+ "Command {cmdObj} failed with retriable error and will be retried{causedBy_status}",
+ "cmdObj"_attr = redact(cmdObj),
+ "causedBy_status"_attr = causedBy(redact(status)));
continue;
}
@@ -207,9 +214,12 @@ BatchedCommandResponse Shard::runBatchWriteCommand(OperationContext* opCtx,
BatchedCommandResponse batchResponse;
auto writeStatus = CommandResponse::processBatchWriteResponse(swResponse, &batchResponse);
if (retry < kOnErrorNumRetries && isRetriableError(writeStatus.code(), retryPolicy)) {
- LOG(2) << "Batch write command to " << getId()
- << " failed with retriable error and will be retried"
- << causedBy(redact(writeStatus));
+ LOGV2_DEBUG(22721,
+ 2,
+ "Batch write command to {getId} failed with retriable error and will be "
+ "retried{causedBy_writeStatus}",
+ "getId"_attr = getId(),
+ "causedBy_writeStatus"_attr = causedBy(redact(writeStatus)));
continue;
}
diff --git a/src/mongo/s/client/shard_connection.cpp b/src/mongo/s/client/shard_connection.cpp
index b78e4aefeeb..55bc10c5f5f 100644
--- a/src/mongo/s/client/shard_connection.cpp
+++ b/src/mongo/s/client/shard_connection.cpp
@@ -37,6 +37,7 @@
#include "mongo/base/init.h"
#include "mongo/db/lasterror.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_connection_gen.h"
@@ -184,8 +185,10 @@ public:
const bool isConnGood = shardConnectionPool.isConnectionGood(addr, conn);
if (s->avail != nullptr) {
- warning() << "Detected additional sharded connection in the "
- << "thread local pool for " << addr;
+ LOGV2_WARNING(
+ 22717,
+ "Detected additional sharded connection in the thread local pool for {addr}",
+ "addr"_attr = addr);
if (DBException::traceExceptions.load()) {
// There shouldn't be more than one connection checked out to the same
@@ -247,8 +250,11 @@ public:
versionManager.checkShardVersionCB(opCtx, s->avail, ns, false, 1);
} catch (const DBException& ex) {
- warning() << "Problem while initially checking shard versions on"
- << " " << shardId << causedBy(redact(ex));
+ LOGV2_WARNING(
+ 22718,
+ "Problem while initially checking shard versions on {shardId}{causedBy_ex}",
+ "shardId"_attr = shardId,
+ "causedBy_ex"_attr = causedBy(redact(ex)));
// NOTE: This is only a heuristic, to avoid multiple stale version retries across
// multiple shards, and does not affect correctness.
@@ -399,8 +405,9 @@ ShardConnection::~ShardConnection() {
}
} else {
// see done() comments above for why we log this line
- log() << "sharded connection to " << _conn->getServerAddress()
- << " not being returned to the pool";
+ LOGV2(22716,
+ "sharded connection to {conn_getServerAddress} not being returned to the pool",
+ "conn_getServerAddress"_attr = _conn->getServerAddress());
kill();
}
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index 16b1f8bf5f4..66659121c5f 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -50,6 +50,7 @@
#include "mongo/executor/task_executor.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
@@ -99,7 +100,7 @@ ShardRegistry::~ShardRegistry() {
void ShardRegistry::shutdown() {
if (_executor && !_isShutdown) {
- LOG(1) << "Shutting down task executor for reloading shard registry";
+ LOGV2_DEBUG(22723, 1, "Shutting down task executor for reloading shard registry");
_executor->shutdown();
_executor->join();
_isShutdown = true;
@@ -228,28 +229,31 @@ void ShardRegistry::startup(OperationContext* opCtx) {
auto netPtr = net.get();
_executor = std::make_unique<ThreadPoolTaskExecutor>(
std::make_unique<NetworkInterfaceThreadPool>(netPtr), std::move(net));
- LOG(1) << "Starting up task executor for periodic reloading of ShardRegistry";
+ LOGV2_DEBUG(22724, 1, "Starting up task executor for periodic reloading of ShardRegistry");
_executor->startup();
auto status =
_executor->scheduleWork([this](const CallbackArgs& cbArgs) { _internalReload(cbArgs); });
if (status.getStatus() == ErrorCodes::ShutdownInProgress) {
- LOG(1) << "Cant schedule Shard Registry reload. "
- << "Executor shutdown in progress";
+ LOGV2_DEBUG(22725, 1, "Cant schedule Shard Registry reload. Executor shutdown in progress");
return;
}
if (!status.isOK()) {
- severe() << "Can't schedule ShardRegistry reload due to " << causedBy(status.getStatus());
+ LOGV2_FATAL(22737,
+ "Can't schedule ShardRegistry reload due to {causedBy_status_getStatus}",
+ "causedBy_status_getStatus"_attr = causedBy(status.getStatus()));
fassertFailed(40252);
}
}
void ShardRegistry::_internalReload(const CallbackArgs& cbArgs) {
- LOG(1) << "Reloading shardRegistry";
+ LOGV2_DEBUG(22726, 1, "Reloading shardRegistry");
if (!cbArgs.status.isOK()) {
- warning() << "cant reload ShardRegistry " << causedBy(cbArgs.status);
+ LOGV2_WARNING(22734,
+ "cant reload ShardRegistry {causedBy_cbArgs_status}",
+ "causedBy_cbArgs_status"_attr = causedBy(cbArgs.status));
return;
}
@@ -260,8 +264,11 @@ void ShardRegistry::_internalReload(const CallbackArgs& cbArgs) {
try {
reload(opCtx.get());
} catch (const DBException& e) {
- log() << "Periodic reload of shard registry failed " << causedBy(e) << "; will retry after "
- << kRefreshPeriod;
+ LOGV2(22727,
+ "Periodic reload of shard registry failed {causedBy_e}; will retry after "
+ "{kRefreshPeriod}",
+ "causedBy_e"_attr = causedBy(e),
+ "kRefreshPeriod"_attr = kRefreshPeriod);
}
// reschedule itself
@@ -270,13 +277,14 @@ void ShardRegistry::_internalReload(const CallbackArgs& cbArgs) {
[this](const CallbackArgs& cbArgs) { _internalReload(cbArgs); });
if (status.getStatus() == ErrorCodes::ShutdownInProgress) {
- LOG(1) << "Cant schedule ShardRegistry reload. "
- << "Executor shutdown in progress";
+ LOGV2_DEBUG(22728, 1, "Cant schedule ShardRegistry reload. Executor shutdown in progress");
return;
}
if (!status.isOK()) {
- severe() << "Can't schedule ShardRegistry reload due to " << causedBy(status.getStatus());
+ LOGV2_FATAL(22738,
+ "Can't schedule ShardRegistry reload due to {causedBy_status_getStatus}",
+ "causedBy_status_getStatus"_attr = causedBy(status.getStatus()));
fassertFailed(40253);
}
}
@@ -298,7 +306,10 @@ bool ShardRegistry::reload(OperationContext* opCtx) {
opCtx->waitForConditionOrInterrupt(
_inReloadCV, reloadLock, [&] { return _reloadState != ReloadState::Reloading; });
} catch (const DBException& e) {
- LOG(1) << "ShardRegistry reload is interrupted due to: " << redact(e.toStatus());
+ LOGV2_DEBUG(22729,
+ 1,
+ "ShardRegistry reload is interrupted due to: {e_toStatus}",
+ "e_toStatus"_attr = redact(e.toStatus()));
return false;
}
@@ -365,8 +376,11 @@ void ShardRegistry::updateReplicaSetOnConfigServer(ServiceContext* serviceContex
std::shared_ptr<Shard> s = grid->shardRegistry()->lookupRSName(connStr.getSetName());
if (!s) {
- LOG(1) << "shard not found for set: " << connStr
- << " when attempting to inform config servers of updated set membership";
+ LOGV2_DEBUG(22730,
+ 1,
+ "shard not found for set: {connStr} when attempting to inform config servers "
+ "of updated set membership",
+ "connStr"_attr = connStr);
return;
}
@@ -384,8 +398,11 @@ void ShardRegistry::updateReplicaSetOnConfigServer(ServiceContext* serviceContex
ShardingCatalogClient::kMajorityWriteConcern);
auto status = swWasUpdated.getStatus();
if (!status.isOK()) {
- error() << "RSChangeWatcher: could not update config db with connection string " << connStr
- << causedBy(redact(status));
+ LOGV2_ERROR(22736,
+ "RSChangeWatcher: could not update config db with connection string "
+ "{connStr}{causedBy_status}",
+ "connStr"_attr = connStr,
+ "causedBy_status"_attr = causedBy(redact(status)));
}
}
@@ -410,9 +427,12 @@ ShardRegistryData::ShardRegistryData(OperationContext* opCtx, ShardFactory* shar
auto shards = std::move(shardsAndOpTime.value);
auto reloadOpTime = std::move(shardsAndOpTime.opTime);
- LOG(1) << "found " << shards.size()
- << " shards listed on config server(s) with lastVisibleOpTime: "
- << reloadOpTime.toBSON();
+ LOGV2_DEBUG(22731,
+ 1,
+ "found {shards_size} shards listed on config server(s) with lastVisibleOpTime: "
+ "{reloadOpTime}",
+ "shards_size"_attr = shards.size(),
+ "reloadOpTime"_attr = reloadOpTime.toBSON());
// Ensure targeter exists for all shards and take shard connection string from the targeter.
// Do this before re-taking the mutex to avoid deadlock with the ReplicaSetMonitor updating
@@ -424,7 +444,10 @@ ShardRegistryData::ShardRegistryData(OperationContext* opCtx, ShardFactory* shar
// been stored (i.e., the entire getAllShards call would fail).
auto shardHostStatus = ConnectionString::parse(shardType.getHost());
if (!shardHostStatus.isOK()) {
- warning() << "Unable to parse shard host " << shardHostStatus.getStatus().toString();
+ LOGV2_WARNING(22735,
+ "Unable to parse shard host {shardHostStatus_getStatus}",
+ "shardHostStatus_getStatus"_attr =
+ shardHostStatus.getStatus().toString());
continue;
}
@@ -561,8 +584,12 @@ void ShardRegistryData::_addShard(WithLock lk,
auto oldConnString = currentShard->originalConnString();
if (oldConnString.toString() != connString.toString()) {
- log() << "Updating ShardRegistry connection string for shard " << currentShard->getId()
- << " from: " << oldConnString.toString() << " to: " << connString.toString();
+ LOGV2(22732,
+ "Updating ShardRegistry connection string for shard {currentShard_getId} from: "
+ "{oldConnString} to: {connString}",
+ "currentShard_getId"_attr = currentShard->getId(),
+ "oldConnString"_attr = oldConnString.toString(),
+ "connString"_attr = connString.toString());
}
for (const auto& host : oldConnString.getServers()) {
@@ -574,7 +601,11 @@ void ShardRegistryData::_addShard(WithLock lk,
_lookup[shard->getId()] = shard;
- LOG(3) << "Adding shard " << shard->getId() << ", with CS " << connString.toString();
+ LOGV2_DEBUG(22733,
+ 3,
+ "Adding shard {shard_getId}, with CS {connString}",
+ "shard_getId"_attr = shard->getId(),
+ "connString"_attr = connString.toString());
if (connString.type() == ConnectionString::SET) {
_rsLookup[connString.getSetName()] = shard;
} else if (connString.type() == ConnectionString::CUSTOM) {
diff --git a/src/mongo/s/client/shard_remote.cpp b/src/mongo/s/client/shard_remote.cpp
index c28a962636b..544f7e19c7e 100644
--- a/src/mongo/s/client/shard_remote.cpp
+++ b/src/mongo/s/client/shard_remote.cpp
@@ -47,6 +47,7 @@
#include "mongo/db/query/query_request.h"
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
#include "mongo/rpc/metadata/tracking_metadata.h"
@@ -229,7 +230,9 @@ StatusWith<Shard::CommandResponse> ShardRemote::_runCommand(OperationContext* op
if (!response.status.isOK()) {
if (ErrorCodes::isExceededTimeLimitError(response.status.code())) {
- LOG(0) << "Operation timed out with status " << redact(response.status);
+ LOGV2(22739,
+ "Operation timed out with status {response_status}",
+ "response_status"_attr = redact(response.status));
}
return response.status;
}
@@ -327,7 +330,9 @@ StatusWith<Shard::QueryResponse> ShardRemote::_runExhaustiveCursorCommand(
if (!status.isOK()) {
if (ErrorCodes::isExceededTimeLimitError(status.code())) {
- LOG(0) << "Operation timed out " << causedBy(status);
+ LOGV2(22740,
+ "Operation timed out {causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
}
return status;
}
diff --git a/src/mongo/s/client/sharding_connection_hook.cpp b/src/mongo/s/client/sharding_connection_hook.cpp
index cbdad3a1257..e55396f6347 100644
--- a/src/mongo/s/client/sharding_connection_hook.cpp
+++ b/src/mongo/s/client/sharding_connection_hook.cpp
@@ -38,6 +38,7 @@
#include "mongo/bson/util/bson_extract.h"
#include "mongo/client/authenticate.h"
#include "mongo/db/client.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/client/version_manager.h"
#include "mongo/util/log.h"
@@ -58,7 +59,7 @@ void ShardingConnectionHook::onCreate(DBClientBase* conn) {
// Authenticate as the first thing we do
// NOTE: Replica set authentication allows authentication against *any* online host
if (auth::isInternalAuthSet()) {
- LOG(2) << "calling onCreate auth for " << conn->toString();
+ LOGV2_DEBUG(22722, 2, "calling onCreate auth for {conn}", "conn"_attr = conn->toString());
uassertStatusOKWithContext(conn->authenticateInternalUser(),
str::stream() << "can't authenticate to server "
diff --git a/src/mongo/s/client/version_manager.cpp b/src/mongo/s/client/version_manager.cpp
index 69a4ab67b5a..a24ef43df52 100644
--- a/src/mongo/s/client/version_manager.cpp
+++ b/src/mongo/s/client/version_manager.cpp
@@ -36,6 +36,7 @@
#include "mongo/client/dbclient_cursor.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_connection.h"
#include "mongo/s/client/shard_registry.h"
@@ -202,7 +203,7 @@ bool initShardVersionEmptyNS(OperationContext* opCtx, DBClientBase* conn_in) {
true,
result);
- LOG(3) << "initial sharding result : " << result;
+ LOGV2_DEBUG(22741, 3, "initial sharding result : {result}", "result"_attr = result);
connectionShardStatus.setSequence(conn, "", 0);
return ok;
@@ -221,8 +222,9 @@ bool initShardVersionEmptyNS(OperationContext* opCtx, DBClientBase* conn_in) {
static Occasionally sampler;
if (sampler.tick()) {
- warning() << "failed to initialize new replica set connection version, "
- << "will initialize on first use";
+ LOGV2_WARNING(22747,
+ "failed to initialize new replica set connection version, will "
+ "initialize on first use");
}
return false;
@@ -343,11 +345,19 @@ bool checkShardVersion(OperationContext* opCtx,
version = manager->getVersion(shard->getId());
}
- LOG(1) << "setting shard version of " << version << " for " << ns << " on shard "
- << shard->toString();
+ LOGV2_DEBUG(22742,
+ 1,
+ "setting shard version of {version} for {ns} on shard {shard}",
+ "version"_attr = version,
+ "ns"_attr = ns,
+ "shard"_attr = shard->toString());
- LOG(3) << "last version sent with chunk manager iteration " << sequenceNumber
- << ", current chunk manager iteration is " << officialSequenceNumber;
+ LOGV2_DEBUG(22743,
+ 3,
+ "last version sent with chunk manager iteration {sequenceNumber}, current chunk "
+ "manager iteration is {officialSequenceNumber}",
+ "sequenceNumber"_attr = sequenceNumber,
+ "officialSequenceNumber"_attr = officialSequenceNumber);
BSONObj result;
if (setShardVersion(opCtx,
@@ -358,7 +368,7 @@ bool checkShardVersion(OperationContext* opCtx,
manager.get(),
authoritative,
result)) {
- LOG(1) << " setShardVersion success: " << result;
+ LOGV2_DEBUG(22744, 1, " setShardVersion success: {result}", "result"_attr = result);
connectionShardStatus.setSequence(conn, ns, officialSequenceNumber);
return true;
}
@@ -367,7 +377,7 @@ bool checkShardVersion(OperationContext* opCtx,
int errCode = result["code"].numberInt();
uassert(errCode, result["errmsg"].String(), errCode != ErrorCodes::NoShardingEnabled);
- LOG(1) << " setShardVersion failed!\n" << result;
+ LOGV2_DEBUG(22745, 1, " setShardVersion failed!\n{result}", "result"_attr = result);
if (result["need_authoritative"].trueValue())
massert(10428, "need_authoritative set but in authoritative mode already", !authoritative);
@@ -394,7 +404,7 @@ bool checkShardVersion(OperationContext* opCtx,
string errmsg = str::stream() << "setShardVersion failed shard: " << shard->toString() << " "
<< result;
- log() << " " << errmsg;
+ LOGV2(22746, " {errmsg}", "errmsg"_attr = errmsg);
massert(10429, errmsg, 0);
return true;
}
diff --git a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp
index 3d4667879f3..c1c9a24d5f8 100644
--- a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp
+++ b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
@@ -173,7 +174,9 @@ public:
}
}
} else {
- log() << "mongos collstats doesn't know about: " << e.fieldName();
+ LOGV2(22749,
+ "mongos collstats doesn't know about: {e_fieldName}",
+ "e_fieldName"_attr = e.fieldName());
}
}
diff --git a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
index 21c8dc7a141..6bcfeac3521 100644
--- a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
+++ b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -69,7 +70,11 @@ public:
std::string& errmsg,
BSONObjBuilder& output) override {
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj));
- LOG(1) << "collMod: " << nss << " cmd:" << redact(cmdObj);
+ LOGV2_DEBUG(22748,
+ 1,
+ "collMod: {nss} cmd:{cmdObj}",
+ "nss"_attr = nss,
+ "cmdObj"_attr = redact(cmdObj));
auto routingInfo =
uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss));
diff --git a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp
index affdf4e583f..242e8699766 100644
--- a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp
+++ b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
@@ -70,7 +71,11 @@ public:
std::string& errmsg,
BSONObjBuilder& output) override {
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj));
- LOG(1) << "createIndexes: " << nss << " cmd:" << redact(cmdObj);
+ LOGV2_DEBUG(22750,
+ 1,
+ "createIndexes: {nss} cmd:{cmdObj}",
+ "nss"_attr = nss,
+ "cmdObj"_attr = redact(cmdObj));
createShardDatabase(opCtx, dbName);
diff --git a/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp b/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp
index 2b45943c3b8..55519ddda48 100644
--- a/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp
+++ b/src/mongo/s/commands/cluster_drop_indexes_cmd.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/grid.h"
#include "mongo/util/log.h"
@@ -69,7 +70,11 @@ public:
std::string& errmsg,
BSONObjBuilder& output) override {
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj));
- LOG(1) << "dropIndexes: " << nss << " cmd:" << redact(cmdObj);
+ LOGV2_DEBUG(22751,
+ 1,
+ "dropIndexes: {nss} cmd:{cmdObj}",
+ "nss"_attr = nss,
+ "cmdObj"_attr = redact(cmdObj));
// If the collection is sharded, we target only the primary shard and the shards that own
// chunks for the collection. We ignore IndexNotFound errors, because the index may have
diff --git a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
index 3d941e1ad3b..cfc28fd3682 100644
--- a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
+++ b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/commands.h"
#include "mongo/db/lasterror.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/cluster_last_error_info.h"
@@ -105,9 +106,14 @@ Status enforceLegacyWriteConcern(OperationContext* opCtx,
return swShard.getStatus();
}
- LOG(3) << "enforcing write concern " << options << " on " << shardConnStr.toString()
- << " at opTime " << opTime.getTimestamp().toStringPretty() << " with electionID "
- << electionId;
+ LOGV2_DEBUG(22752,
+ 3,
+ "enforcing write concern {options} on {shardConnStr} at opTime "
+ "{opTime_getTimestamp_Pretty} with electionID {electionId}",
+ "options"_attr = options,
+ "shardConnStr"_attr = shardConnStr.toString(),
+ "opTime_getTimestamp_Pretty"_attr = opTime.getTimestamp().toStringPretty(),
+ "electionId"_attr = electionId);
BSONObj gleCmd = buildGLECmdWithOpTime(options, opTime, electionId);
requests.emplace_back(swShard.getValue()->getId(), gleCmd);
diff --git a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp
index 78b3021a698..c4c5acaec63 100644
--- a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp
+++ b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/auth/action_type.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/database_version_gen.h"
@@ -114,7 +115,7 @@ public:
bool exceedsSizeLimit = false;
for (const auto& chunk : cm->chunks()) {
- log() << redact(chunk.toString());
+ LOGV2(22753, "{chunk}", "chunk"_attr = redact(chunk.toString()));
if (!exceedsSizeLimit) {
BSONArrayBuilder chunkBB(chunksArrBuilder.subarrayStart());
chunkBB.append(chunk.getMin());
diff --git a/src/mongo/s/commands/cluster_kill_op.cpp b/src/mongo/s/commands/cluster_kill_op.cpp
index 89e00b7d497..353b200dbf2 100644
--- a/src/mongo/s/commands/cluster_kill_op.cpp
+++ b/src/mongo/s/commands/cluster_kill_op.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/kill_op_cmd_base.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/metadata.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_registry.h"
@@ -93,7 +94,7 @@ private:
(opSepPos != (opToKill.size() - 1))); // can't be NN:
auto shardIdent = opToKill.substr(0, opSepPos);
- log() << "want to kill op: " << redact(opToKill);
+ LOGV2(22754, "want to kill op: {opToKill}", "opToKill"_attr = redact(opToKill));
// Will throw if shard id is not found
auto shardStatus = Grid::get(opCtx)->shardRegistry()->getShard(opCtx, shardIdent);
diff --git a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
index 89732fa2407..f237fe1760d 100644
--- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
+++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/write_concern_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_registry.h"
@@ -119,7 +120,7 @@ public:
std::string msg(str::stream()
<< "Could not move chunk in '" << nss.ns() << "' to shard '" << toString
<< "' because that shard does not exist");
- log() << msg;
+ LOGV2(22755, "{msg}", "msg"_attr = msg);
uasserted(ErrorCodes::ShardNotFound, msg);
}
diff --git a/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp
index def3fc00af0..15560de3866 100644
--- a/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp
+++ b/src/mongo/s/commands/cluster_refine_collection_shard_key_cmd.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/s/request_types/refine_collection_shard_key_gen.h"
#include "mongo/util/fail_point.h"
@@ -59,7 +60,7 @@ public:
nss));
if (MONGO_unlikely(hangRefineCollectionShardKeyAfterRefresh.shouldFail())) {
- log() << "Hit hangRefineCollectionShardKeyAfterRefresh failpoint";
+ LOGV2(22756, "Hit hangRefineCollectionShardKeyAfterRefresh failpoint");
hangRefineCollectionShardKeyAfterRefresh.pauseWhileSet(opCtx);
}
diff --git a/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp b/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp
index 5074b7da454..6848eee5371 100644
--- a/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp
+++ b/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/set_index_commit_quorum_gen.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/util/log.h"
@@ -85,8 +86,11 @@ public:
void typedRun(OperationContext* opCtx) {
BSONObj cmdObj = request().toBSON(BSONObj());
- LOG(1) << "setIndexCommitQuorum: " << request().getNamespace()
- << " cmd:" << redact(cmdObj);
+ LOGV2_DEBUG(22757,
+ 1,
+ "setIndexCommitQuorum: {request_getNamespace} cmd:{cmdObj}",
+ "request_getNamespace"_attr = request().getNamespace(),
+ "cmdObj"_attr = redact(cmdObj));
scatterGatherOnlyVersionIfUnsharded(
opCtx,
diff --git a/src/mongo/s/commands/cluster_split_cmd.cpp b/src/mongo/s/commands/cluster_split_cmd.cpp
index 0ea00d0138d..4a89095ea0f 100644
--- a/src/mongo/s/commands/cluster_split_cmd.cpp
+++ b/src/mongo/s/commands/cluster_split_cmd.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
#include "mongo/db/field_parser.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_commands_helpers.h"
@@ -254,10 +255,14 @@ public:
cm->getShardKeyPattern(),
ChunkRange(chunk->getMin(), chunk->getMax()));
- log() << "Splitting chunk "
- << redact(ChunkRange(chunk->getMin(), chunk->getMax()).toString())
- << " in collection " << nss.ns() << " on shard " << chunk->getShardId() << " at key "
- << redact(splitPoint);
+ LOGV2(22758,
+ "Splitting chunk {ChunkRange_chunk_getMin_chunk_getMax} in collection {nss_ns} on "
+ "shard {chunk_getShardId} at key {splitPoint}",
+ "ChunkRange_chunk_getMin_chunk_getMax"_attr =
+ redact(ChunkRange(chunk->getMin(), chunk->getMax()).toString()),
+ "nss_ns"_attr = nss.ns(),
+ "chunk_getShardId"_attr = chunk->getShardId(),
+ "splitPoint"_attr = redact(splitPoint));
uassertStatusOK(
shardutil::splitChunkAtMultiplePoints(opCtx,
diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp
index c0370d168b0..29ed31f4393 100644
--- a/src/mongo/s/commands/cluster_write_cmd.cpp
+++ b/src/mongo/s/commands/cluster_write_cmd.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/stats/counters.h"
#include "mongo/db/storage/duplicate_key_error_info.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/client/num_hosts_targeted_metrics.h"
#include "mongo/s/client/shard_registry.h"
@@ -206,7 +207,7 @@ bool handleWouldChangeOwningShardError(OperationContext* opCtx,
boost::optional<BSONObj> upsertedId;
if (isRetryableWrite) {
if (MONGO_unlikely(hangAfterThrowWouldChangeOwningShardRetryableWrite.shouldFail())) {
- log() << "Hit hangAfterThrowWouldChangeOwningShardRetryableWrite failpoint";
+ LOGV2(22759, "Hit hangAfterThrowWouldChangeOwningShardRetryableWrite failpoint");
hangAfterThrowWouldChangeOwningShardRetryableWrite.pauseWhileSet(opCtx);
}
RouterOperationContextSession routerSession(opCtx);
diff --git a/src/mongo/s/commands/document_shard_key_update_util.cpp b/src/mongo/s/commands/document_shard_key_update_util.cpp
index d576e496ea6..f7c2c33bba0 100644
--- a/src/mongo/s/commands/document_shard_key_update_util.cpp
+++ b/src/mongo/s/commands/document_shard_key_update_util.cpp
@@ -33,6 +33,7 @@
#include "mongo/base/status_with.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/would_change_owning_shard_exception.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
@@ -78,7 +79,7 @@ bool executeOperationsAsPartOfShardKeyUpdate(OperationContext* opCtx,
}
if (MONGO_unlikely(hangBeforeInsertOnUpdateShardKey.shouldFail())) {
- log() << "Hit hangBeforeInsertOnUpdateShardKey failpoint";
+ LOGV2(22760, "Hit hangBeforeInsertOnUpdateShardKey failpoint");
hangBeforeInsertOnUpdateShardKey.pauseWhileSet(opCtx);
}
diff --git a/src/mongo/s/commands/flush_router_config_cmd.cpp b/src/mongo/s/commands/flush_router_config_cmd.cpp
index 3c180ea36b0..e84e66cdfd7 100644
--- a/src/mongo/s/commands/flush_router_config_cmd.cpp
+++ b/src/mongo/s/commands/flush_router_config_cmd.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/commands.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/grid.h"
#include "mongo/s/is_mongos.h"
#include "mongo/util/log.h"
@@ -86,16 +87,16 @@ public:
const auto argumentElem = cmdObj.firstElement();
if (argumentElem.isNumber() || argumentElem.isBoolean()) {
- LOG(0) << "Routing metadata flushed for all databases";
+ LOGV2(22761, "Routing metadata flushed for all databases");
catalogCache->purgeAllDatabases();
} else {
const auto ns = argumentElem.checkAndGetStringData();
if (nsIsDbOnly(ns)) {
- LOG(0) << "Routing metadata flushed for database " << ns;
+ LOGV2(22762, "Routing metadata flushed for database {ns}", "ns"_attr = ns);
catalogCache->purgeDatabase(ns);
} else {
const NamespaceString nss(ns);
- LOG(0) << "Routing metadata flushed for collection " << nss;
+ LOGV2(22763, "Routing metadata flushed for collection {nss}", "nss"_attr = nss);
catalogCache->purgeCollection(nss);
}
}
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index 17b6aa0bc14..e130e65b707 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -61,6 +61,7 @@
#include "mongo/db/stats/counters.h"
#include "mongo/db/transaction_validation.h"
#include "mongo/db/views/resolved_view.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/factory.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/logical_time_metadata.h"
@@ -136,12 +137,18 @@ void appendRequiredFieldsToResponse(OperationContext* opCtx, BSONObjBuilder* res
// Add operationTime.
auto operationTime = OperationTimeTracker::get(opCtx)->getMaxOperationTime();
if (operationTime != LogicalTime::kUninitialized) {
- LOG(5) << "Appending operationTime: " << operationTime.asTimestamp();
+ LOGV2_DEBUG(22764,
+ 5,
+ "Appending operationTime: {operationTime_asTimestamp}",
+ "operationTime_asTimestamp"_attr = operationTime.asTimestamp());
responseBuilder->append(kOperationTime, operationTime.asTimestamp());
} else if (now != LogicalTime::kUninitialized) {
// If we don't know the actual operation time, use the cluster time instead. This is
// safe but not optimal because we can always return a later operation time than actual.
- LOG(5) << "Appending clusterTime as operationTime " << now.asTimestamp();
+ LOGV2_DEBUG(22765,
+ 5,
+ "Appending clusterTime as operationTime {now_asTimestamp}",
+ "now_asTimestamp"_attr = now.asTimestamp());
responseBuilder->append(kOperationTime, now.asTimestamp());
}
@@ -446,8 +453,12 @@ void runCommand(OperationContext* opCtx,
if (const auto wcDefault = ReadWriteConcernDefaults::get(opCtx->getServiceContext())
.getDefaultWriteConcern(opCtx)) {
wc = *wcDefault;
- LOG(2) << "Applying default writeConcern on " << request.getCommandName() << " of "
- << wcDefault->toBSON();
+ LOGV2_DEBUG(
+ 22766,
+ 2,
+ "Applying default writeConcern on {request_getCommandName} of {wcDefault}",
+ "request_getCommandName"_attr = request.getCommandName(),
+ "wcDefault"_attr = wcDefault->toBSON());
}
}
@@ -473,8 +484,13 @@ void runCommand(OperationContext* opCtx,
stdx::lock_guard<Client> lk(*opCtx->getClient());
readConcernArgs = std::move(*rcDefault);
}
- LOG(2) << "Applying default readConcern on "
- << invocation->definition()->getName() << " of " << *rcDefault;
+ LOGV2_DEBUG(22767,
+ 2,
+ "Applying default readConcern on {invocation_definition_getName} "
+ "of {rcDefault}",
+ "invocation_definition_getName"_attr =
+ invocation->definition()->getName(),
+ "rcDefault"_attr = *rcDefault);
// Update the readConcernSupport, since the default RC was applied.
readConcernSupport =
invocation->supportsReadConcern(readConcernArgs.getLevel());
@@ -795,8 +811,13 @@ DbResponse Strategy::queryOp(OperationContext* opCtx, const NamespaceString& nss
audit::logQueryAuthzCheck(client, nss, q.query, status.code());
uassertStatusOK(status);
- LOG(3) << "query: " << q.ns << " " << redact(q.query) << " ntoreturn: " << q.ntoreturn
- << " options: " << q.queryOptions;
+ LOGV2_DEBUG(22768,
+ 3,
+ "query: {q_ns} {q_query} ntoreturn: {q_ntoreturn} options: {q_queryOptions}",
+ "q_ns"_attr = q.ns,
+ "q_query"_attr = redact(q.query),
+ "q_ntoreturn"_attr = q.ntoreturn,
+ "q_queryOptions"_attr = q.queryOptions);
if (q.queryOptions & QueryOption_Exhaust) {
uasserted(18526,
@@ -894,7 +915,10 @@ DbResponse Strategy::clientCommand(OperationContext* opCtx, const Message& m) {
if (ErrorCodes::isConnectionFatalMessageParseError(ex.code()))
propagateException = true;
- LOG(1) << "Exception thrown while parsing command " << causedBy(redact(ex));
+ LOGV2_DEBUG(22769,
+ 1,
+ "Exception thrown while parsing command {causedBy_ex}",
+ "causedBy_ex"_attr = causedBy(redact(ex)));
throw;
}
}();
@@ -904,12 +928,25 @@ DbResponse Strategy::clientCommand(OperationContext* opCtx, const Message& m) {
// Execute.
std::string db = request.getDatabase().toString();
try {
- LOG(3) << "Command begin db: " << db << " msg id: " << m.header().getId();
+ LOGV2_DEBUG(22770,
+ 3,
+ "Command begin db: {db} msg id: {m_header_getId}",
+ "db"_attr = db,
+ "m_header_getId"_attr = m.header().getId());
runCommand(opCtx, request, m.operation(), reply.get(), &errorBuilder);
- LOG(3) << "Command end db: " << db << " msg id: " << m.header().getId();
+ LOGV2_DEBUG(22771,
+ 3,
+ "Command end db: {db} msg id: {m_header_getId}",
+ "db"_attr = db,
+ "m_header_getId"_attr = m.header().getId());
} catch (const DBException& ex) {
- LOG(1) << "Exception thrown while processing command on " << db
- << " msg id: " << m.header().getId() << causedBy(redact(ex));
+ LOGV2_DEBUG(22772,
+ 1,
+ "Exception thrown while processing command on {db} msg id: "
+ "{m_header_getId}{causedBy_ex}",
+ "db"_attr = db,
+ "m_header_getId"_attr = m.header().getId(),
+ "causedBy_ex"_attr = causedBy(redact(ex)));
// Record the exception in CurOp.
CurOp::get(opCtx)->debug().errInfo = ex.toStatus();
@@ -1046,7 +1083,10 @@ void Strategy::killCursors(OperationContext* opCtx, DbMessage* dbm) {
boost::optional<NamespaceString> nss = manager->getNamespaceForCursorId(cursorId);
if (!nss) {
- LOG(3) << "Can't find cursor to kill. Cursor id: " << cursorId << ".";
+ LOGV2_DEBUG(22773,
+ 3,
+ "Can't find cursor to kill. Cursor id: {cursorId}.",
+ "cursorId"_attr = cursorId);
continue;
}
@@ -1057,19 +1097,30 @@ void Strategy::killCursors(OperationContext* opCtx, DbMessage* dbm) {
auto authzStatus = manager->checkAuthForKillCursors(opCtx, *nss, cursorId, authChecker);
audit::logKillCursorsAuthzCheck(client, *nss, cursorId, authzStatus.code());
if (!authzStatus.isOK()) {
- LOG(3) << "Not authorized to kill cursor. Namespace: '" << *nss
- << "', cursor id: " << cursorId << ".";
+ LOGV2_DEBUG(
+ 22774,
+ 3,
+ "Not authorized to kill cursor. Namespace: '{nss}', cursor id: {cursorId}.",
+ "nss"_attr = *nss,
+ "cursorId"_attr = cursorId);
continue;
}
Status killCursorStatus = manager->killCursor(opCtx, *nss, cursorId);
if (!killCursorStatus.isOK()) {
- LOG(3) << "Can't find cursor to kill. Namespace: '" << *nss
- << "', cursor id: " << cursorId << ".";
+ LOGV2_DEBUG(22775,
+ 3,
+ "Can't find cursor to kill. Namespace: '{nss}', cursor id: {cursorId}.",
+ "nss"_attr = *nss,
+ "cursorId"_attr = cursorId);
continue;
}
- LOG(3) << "Killed cursor. Namespace: '" << *nss << "', cursor id: " << cursorId << ".";
+ LOGV2_DEBUG(22776,
+ 3,
+ "Killed cursor. Namespace: '{nss}', cursor id: {cursorId}.",
+ "nss"_attr = *nss,
+ "cursorId"_attr = cursorId);
}
}
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp
index bda2bc6e929..86f6907931c 100644
--- a/src/mongo/s/grid.cpp
+++ b/src/mongo/s/grid.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/server_options.h"
#include "mongo/executor/task_executor.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/shard_factory.h"
@@ -130,10 +131,13 @@ boost::optional<repl::OpTime> Grid::advanceConfigOpTime(OperationContext* opCtx,
if (opCtx && opCtx->getClient()) {
clientAddr = opCtx->getClient()->clientAddress(true);
}
- log() << "Received " << what << " " << clientAddr
- << " indicating config server optime "
- "term has increased, previous optime "
- << prevOpTime << ", now " << opTime;
+ LOGV2(22792,
+ "Received {what} {clientAddr} indicating config server optime "
+ "term has increased, previous optime {prevOpTime}, now {opTime}",
+ "what"_attr = what,
+ "clientAddr"_attr = clientAddr,
+ "prevOpTime"_attr = prevOpTime,
+ "opTime"_attr = opTime);
}
return prevOpTime;
}
diff --git a/src/mongo/s/query/cluster_aggregation_planner.cpp b/src/mongo/s/query/cluster_aggregation_planner.cpp
index d778c8cb774..0a0eb8f109c 100644
--- a/src/mongo/s/query/cluster_aggregation_planner.cpp
+++ b/src/mongo/s/query/cluster_aggregation_planner.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/pipeline/document_source_skip.h"
#include "mongo/db/pipeline/sharded_agg_helpers.h"
#include "mongo/db/query/find_common.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/op_msg_rpc_impls.h"
#include "mongo/s/catalog_cache.h"
@@ -87,7 +88,7 @@ AsyncRequestsSender::Response establishMergingShardCursor(OperationContext* opCt
const BSONObj mergeCmdObj,
const ShardId& mergingShardId) {
if (MONGO_unlikely(shardedAggregateFailToEstablishMergingShardCursor.shouldFail())) {
- log() << "shardedAggregateFailToEstablishMergingShardCursor fail point enabled.";
+ LOGV2(22834, "shardedAggregateFailToEstablishMergingShardCursor fail point enabled.");
uasserted(ErrorCodes::FailPointEnabled,
"Asserting on establishing merging shard cursor due to failpoint.");
}
@@ -205,7 +206,10 @@ Status dispatchMergingPipeline(const boost::intrusive_ptr<ExpressionContext>& ex
auto mergeCmdObj = createCommandForMergingShard(
serializedCommand, expCtx, mergingShardId, mergingShardContributesData, mergePipeline);
- LOG(1) << "Dispatching merge pipeline " << redact(mergeCmdObj) << " to designated shard";
+ LOGV2_DEBUG(22835,
+ 1,
+ "Dispatching merge pipeline {mergeCmdObj} to designated shard",
+ "mergeCmdObj"_attr = redact(mergeCmdObj));
// Dispatch $mergeCursors to the chosen shard, store the resulting cursor, and return.
auto mergeResponse =
@@ -352,7 +356,7 @@ DispatchShardPipelineResults dispatchExchangeConsumerPipeline(
auto opCtx = expCtx->opCtx;
if (MONGO_unlikely(shardedAggregateFailToDispatchExchangeConsumerPipeline.shouldFail())) {
- log() << "shardedAggregateFailToDispatchExchangeConsumerPipeline fail point enabled.";
+ LOGV2(22836, "shardedAggregateFailToDispatchExchangeConsumerPipeline fail point enabled.");
uasserted(ErrorCodes::FailPointEnabled,
"Asserting on exhange consumer pipeline dispatch due to failpoint.");
}
diff --git a/src/mongo/s/query/cluster_cursor_manager.cpp b/src/mongo/s/query/cluster_cursor_manager.cpp
index ef0c3b02964..358bbfc4d18 100644
--- a/src/mongo/s/query/cluster_cursor_manager.cpp
+++ b/src/mongo/s/query/cluster_cursor_manager.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/kill_sessions_common.h"
#include "mongo/db/logical_session_cache.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/clock_source.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -396,8 +397,10 @@ std::size_t ClusterCursorManager::killMortalCursorsInactiveSince(OperationContex
!entry.getOperationUsingCursor() && entry.getLastActive() <= cutoff;
if (res) {
- log() << "Cursor id " << cursorId << " timed out, idle since "
- << entry.getLastActive().toString();
+ LOGV2(22837,
+ "Cursor id {cursorId} timed out, idle since {entry_getLastActive}",
+ "cursorId"_attr = cursorId,
+ "entry_getLastActive"_attr = entry.getLastActive().toString());
}
return res;
@@ -582,7 +585,7 @@ std::pair<Status, int> ClusterCursorManager::killCursorsWithMatchingSessions(
return;
}
uassertStatusOK(mgr.killCursor(opCtx, *cursorNss, id));
- log() << "killing cursor: " << id << " as part of killing session(s)";
+ LOGV2(22838, "killing cursor: {id} as part of killing session(s)", "id"_attr = id);
};
auto bySessionCursorKiller = makeKillCursorsBySessionAdaptor(opCtx, matcher, std::move(eraser));
diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp
index 74e1840ccac..9695682bd7c 100644
--- a/src/mongo/s/query/cluster_find.cpp
+++ b/src/mongo/s/query/cluster_find.cpp
@@ -51,6 +51,7 @@
#include "mongo/db/query/getmore_request.h"
#include "mongo/db/query/query_planner_common.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/overflow_arithmetic.h"
#include "mongo/s/catalog_cache.h"
#include "mongo/s/client/num_hosts_targeted_metrics.h"
@@ -538,8 +539,14 @@ CursorId ClusterFind::runQuery(OperationContext* opCtx,
throw;
}
- LOG(1) << "Received error status for query " << redact(query.toStringShort())
- << " on attempt " << retries << " of " << kMaxRetries << ": " << redact(ex);
+ LOGV2_DEBUG(22839,
+ 1,
+ "Received error status for query {query_Short} on attempt {retries} of "
+ "{kMaxRetries}: {ex}",
+ "query_Short"_attr = redact(query.toStringShort()),
+ "retries"_attr = retries,
+ "kMaxRetries"_attr = kMaxRetries,
+ "ex"_attr = redact(ex));
Grid::get(opCtx)->catalogCache()->onStaleDatabaseVersion(ex->getDb(),
ex->getVersionReceived());
@@ -573,8 +580,14 @@ CursorId ClusterFind::runQuery(OperationContext* opCtx,
throw;
}
- LOG(1) << "Received error status for query " << redact(query.toStringShort())
- << " on attempt " << retries << " of " << kMaxRetries << ": " << redact(ex);
+ LOGV2_DEBUG(22840,
+ 1,
+ "Received error status for query {query_Short} on attempt {retries} of "
+ "{kMaxRetries}: {ex}",
+ "query_Short"_attr = redact(query.toStringShort()),
+ "retries"_attr = retries,
+ "kMaxRetries"_attr = kMaxRetries,
+ "ex"_attr = redact(ex));
if (ex.code() != ErrorCodes::ShardInvalidatedForTargeting) {
if (auto staleInfo = ex.extraInfo<StaleConfigInfo>()) {
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index bf6a06cb11d..cf8ae66f85d 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -70,6 +70,7 @@
#include "mongo/db/startup_warnings_common.h"
#include "mongo/db/wire_version.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/process_id.h"
#include "mongo/rpc/metadata/egress_metadata_hook_list.h"
#include "mongo/s/balancer_configuration.h"
@@ -157,8 +158,10 @@ Status waitForSigningKeys(OperationContext* opCtx) {
// mongod will set minWireVersion == maxWireVersion for isMaster requests from
// internalClient.
if (rsm && (rsm->getMaxWireVersion() < WireVersion::SUPPORTS_OP_MSG)) {
- log() << "Not waiting for signing keys, not supported by the config shard "
- << configCS.getSetName();
+ LOGV2(22841,
+ "Not waiting for signing keys, not supported by the config shard "
+ "{configCS_getSetName}",
+ "configCS_getSetName"_attr = configCS.getSetName());
return Status::OK();
}
auto stopStatus = opCtx->checkForInterruptNoAssert();
@@ -170,14 +173,19 @@ Status waitForSigningKeys(OperationContext* opCtx) {
if (LogicalTimeValidator::get(opCtx)->shouldGossipLogicalTime()) {
return Status::OK();
}
- log() << "Waiting for signing keys, sleeping for " << kSignKeysRetryInterval
- << " and trying again.";
+ LOGV2(
+ 22842,
+ "Waiting for signing keys, sleeping for {kSignKeysRetryInterval} and trying again.",
+ "kSignKeysRetryInterval"_attr = kSignKeysRetryInterval);
sleepFor(kSignKeysRetryInterval);
continue;
} catch (const DBException& ex) {
Status status = ex.toStatus();
- warning() << "Error waiting for signing keys, sleeping for " << kSignKeysRetryInterval
- << " and trying again " << causedBy(status);
+ LOGV2_WARNING(22853,
+ "Error waiting for signing keys, sleeping for {kSignKeysRetryInterval} "
+ "and trying again {causedBy_status}",
+ "kSignKeysRetryInterval"_attr = kSignKeysRetryInterval,
+ "causedBy_status"_attr = causedBy(status));
sleepFor(kSignKeysRetryInterval);
continue;
}
@@ -265,7 +273,9 @@ void cleanupTask(ServiceContext* serviceContext) {
// Shutdown the TransportLayer so that new connections aren't accepted
if (auto tl = serviceContext->getTransportLayer()) {
- log(LogComponent::kNetwork) << "shutdown: going to close all sockets...";
+ LOGV2_OPTIONS(22843,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "shutdown: going to close all sockets...");
tl->shutdown();
}
@@ -274,8 +284,9 @@ void cleanupTask(ServiceContext* serviceContext) {
// Abort transactions while we can still send remote commands.
implicitlyAbortAllTransactions(opCtx);
} catch (const DBException& excep) {
- warning() << "encountered " << excep
- << " while trying to abort all active transactions";
+ LOGV2_WARNING(22854,
+ "encountered {excep} while trying to abort all active transactions",
+ "excep"_attr = excep);
}
if (auto lsc = LogicalSessionCache::get(serviceContext)) {
@@ -328,8 +339,9 @@ void cleanupTask(ServiceContext* serviceContext) {
// Shutdown the Service Entry Point and its sessions and give it a grace period to complete.
if (auto sep = serviceContext->getServiceEntryPoint()) {
if (!sep->shutdown(Seconds(10))) {
- log(LogComponent::kNetwork)
- << "Service entry point failed to shutdown within timelimit.";
+ LOGV2_OPTIONS(22844,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "Service entry point failed to shutdown within timelimit.");
}
}
@@ -337,8 +349,11 @@ void cleanupTask(ServiceContext* serviceContext) {
if (auto svcExec = serviceContext->getServiceExecutor()) {
Status status = svcExec->shutdown(Seconds(5));
if (!status.isOK()) {
- log(LogComponent::kNetwork)
- << "Service executor failed to shutdown within timelimit: " << status.reason();
+ LOGV2_OPTIONS(
+ 22845,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "Service executor failed to shutdown within timelimit: {status_reason}",
+ "status_reason"_attr = status.reason());
}
}
#endif
@@ -473,7 +488,9 @@ public:
invariant(args.status);
try {
- LOG(0) << "Updating sharding state with confirmed set " << connStr;
+ LOGV2(22846,
+ "Updating sharding state with confirmed set {connStr}",
+ "connStr"_attr = connStr);
Grid::get(serviceContext)->shardRegistry()->updateReplSetHosts(connStr);
@@ -482,14 +499,17 @@ public:
}
ShardRegistry::updateReplicaSetOnConfigServer(serviceContext, connStr);
} catch (const ExceptionForCat<ErrorCategory::ShutdownError>& e) {
- LOG(0) << "Unable to update sharding state due to " << e;
+ LOGV2(22847, "Unable to update sharding state due to {e}", "e"_attr = e);
}
};
auto executor = Grid::get(_serviceContext)->getExecutorPool()->getFixedExecutor();
auto schedStatus = executor->scheduleWork(std::move(fun)).getStatus();
if (ErrorCodes::isCancelationError(schedStatus.code())) {
- LOG(2) << "Unable to schedule confirmed set update due to " << schedStatus;
+ LOGV2_DEBUG(22848,
+ 2,
+ "Unable to schedule confirmed set update due to {schedStatus}",
+ "schedStatus"_attr = schedStatus);
return;
}
uassertStatusOK(schedStatus);
@@ -499,7 +519,10 @@ public:
try {
Grid::get(_serviceContext)->shardRegistry()->updateReplSetHosts(state.connStr);
} catch (const DBException& ex) {
- LOG(2) << "Unable to update sharding state with possible set due to " << ex;
+ LOGV2_DEBUG(22849,
+ 2,
+ "Unable to update sharding state with possible set due to {ex}",
+ "ex"_attr = ex);
}
}
@@ -523,7 +546,7 @@ ExitCode runMongosServer(ServiceContext* serviceContext) {
transport::TransportLayerManager::createWithConfig(&serverGlobalParams, serviceContext);
auto res = tl->setup();
if (!res.isOK()) {
- error() << "Failed to set up listener: " << res;
+ LOGV2_ERROR(22856, "Failed to set up listener: {res}", "res"_attr = res);
return EXIT_NET_ERROR;
}
serviceContext->setTransportLayer(std::move(tl));
@@ -574,10 +597,11 @@ ExitCode runMongosServer(ServiceContext* serviceContext) {
if (!status.isOK()) {
if (status == ErrorCodes::CallbackCanceled) {
invariant(globalInShutdownDeprecated());
- log() << "Shutdown called before mongos finished starting up";
+ LOGV2(22850, "Shutdown called before mongos finished starting up");
return EXIT_CLEAN;
}
- error() << "Error initializing sharding system: " << status;
+ LOGV2_ERROR(
+ 22857, "Error initializing sharding system: {status}", "status"_attr = status);
return EXIT_SHARDING_ERROR;
}
@@ -589,8 +613,10 @@ ExitCode runMongosServer(ServiceContext* serviceContext) {
try {
ReadWriteConcernDefaults::get(serviceContext).refreshIfNecessary(opCtx);
} catch (const DBException& ex) {
- warning() << "Failed to load read and write concern defaults at startup"
- << causedBy(redact(ex.toStatus()));
+ LOGV2_WARNING(
+ 22855,
+ "Failed to load read and write concern defaults at startup{causedBy_ex_toStatus}",
+ "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus())));
}
}
@@ -602,7 +628,8 @@ ExitCode runMongosServer(ServiceContext* serviceContext) {
Status status = AuthorizationManager::get(serviceContext)->initialize(opCtx);
if (!status.isOK()) {
- error() << "Initializing authorization data failed: " << status;
+ LOGV2_ERROR(
+ 22858, "Initializing authorization data failed: {status}", "status"_attr = status);
return EXIT_SHARDING_ERROR;
}
@@ -636,19 +663,24 @@ ExitCode runMongosServer(ServiceContext* serviceContext) {
status = serviceContext->getServiceExecutor()->start();
if (!status.isOK()) {
- error() << "Failed to start the service executor: " << redact(status);
+ LOGV2_ERROR(22859,
+ "Failed to start the service executor: {status}",
+ "status"_attr = redact(status));
return EXIT_NET_ERROR;
}
status = serviceContext->getServiceEntryPoint()->start();
if (!status.isOK()) {
- error() << "Failed to start the service entry point: " << redact(status);
+ LOGV2_ERROR(22860,
+ "Failed to start the service entry point: {status}",
+ "status"_attr = redact(status));
return EXIT_NET_ERROR;
}
status = serviceContext->getTransportLayer()->start();
if (!status.isOK()) {
- error() << "Failed to start the transport layer: " << redact(status);
+ LOGV2_ERROR(
+ 22861, "Failed to start the transport layer: {status}", "status"_attr = redact(status));
return EXIT_NET_ERROR;
}
@@ -659,7 +691,7 @@ ExitCode runMongosServer(ServiceContext* serviceContext) {
#else
if (ntservice::shouldStartService()) {
ntservice::reportStatus(SERVICE_RUNNING);
- log() << "Service running";
+ LOGV2(22851, "Service running");
}
#endif
@@ -708,7 +740,9 @@ ExitCode main(ServiceContext* serviceContext) {
}
if (configAddr.isLocalHost() != shardingContext->allowLocalHost()) {
- log(LogComponent::kDefault) << "cannot mix localhost and ip addresses in configdbs";
+ LOGV2_OPTIONS(22852,
+ {logComponentV1toV2(LogComponent::kDefault)},
+ "cannot mix localhost and ip addresses in configdbs");
return EXIT_BADOPTIONS;
}
}
@@ -765,7 +799,10 @@ ExitCode mongoSMain(int argc, char* argv[], char** envp) {
Status status = runGlobalInitializers(argc, argv, envp);
if (!status.isOK()) {
- severe(LogComponent::kDefault) << "Failed global initialization: " << status;
+ LOGV2_FATAL_OPTIONS(22865,
+ {logComponentV1toV2(LogComponent::kDefault)},
+ "Failed global initialization: {status}",
+ "status"_attr = status);
return EXIT_ABRUPT;
}
@@ -773,7 +810,10 @@ ExitCode mongoSMain(int argc, char* argv[], char** envp) {
setGlobalServiceContext(ServiceContext::make());
} catch (...) {
auto cause = exceptionToStatus();
- severe(LogComponent::kDefault) << "Failed to create service context: " << redact(cause);
+ LOGV2_FATAL_OPTIONS(22866,
+ {logComponentV1toV2(LogComponent::kDefault)},
+ "Failed to create service context: {cause}",
+ "cause"_attr = redact(cause));
return EXIT_ABRUPT;
}
@@ -799,13 +839,15 @@ ExitCode mongoSMain(int argc, char* argv[], char** envp) {
return main(service);
} catch (const DBException& e) {
- error() << "uncaught DBException in mongos main: " << redact(e);
+ LOGV2_ERROR(22862, "uncaught DBException in mongos main: {e}", "e"_attr = redact(e));
return EXIT_UNCAUGHT;
} catch (const std::exception& e) {
- error() << "uncaught std::exception in mongos main:" << redact(e.what());
+ LOGV2_ERROR(22863,
+ "uncaught std::exception in mongos main:{e_what}",
+ "e_what"_attr = redact(e.what()));
return EXIT_UNCAUGHT;
} catch (...) {
- error() << "uncaught unknown exception in mongos main";
+ LOGV2_ERROR(22864, "uncaught unknown exception in mongos main");
return EXIT_UNCAUGHT;
}
}
diff --git a/src/mongo/s/service_entry_point_mongos.cpp b/src/mongo/s/service_entry_point_mongos.cpp
index 598d9a052fb..f15dabf9bec 100644
--- a/src/mongo/s/service_entry_point_mongos.cpp
+++ b/src/mongo/s/service_entry_point_mongos.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/lasterror.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/message.h"
#include "mongo/s/client/shard_connection.h"
#include "mongo/s/cluster_last_error_info.h"
@@ -117,8 +118,12 @@ DbResponse ServiceEntryPointMongos::handleRequest(OperationContext* opCtx, const
}
- LOG(3) << "Request::process begin ns: " << nss << " msg id: " << msgId
- << " op: " << networkOpToString(op);
+ LOGV2_DEBUG(22867,
+ 3,
+ "Request::process begin ns: {nss} msg id: {msgId} op: {networkOpToString_op}",
+ "nss"_attr = nss,
+ "msgId"_attr = msgId,
+ "networkOpToString_op"_attr = networkOpToString(op));
switch (op) {
case dbQuery:
@@ -146,12 +151,21 @@ DbResponse ServiceEntryPointMongos::handleRequest(OperationContext* opCtx, const
MONGO_UNREACHABLE;
}
- LOG(3) << "Request::process end ns: " << nss << " msg id: " << msgId
- << " op: " << networkOpToString(op);
+ LOGV2_DEBUG(22868,
+ 3,
+ "Request::process end ns: {nss} msg id: {msgId} op: {networkOpToString_op}",
+ "nss"_attr = nss,
+ "msgId"_attr = msgId,
+ "networkOpToString_op"_attr = networkOpToString(op));
} catch (const DBException& ex) {
- LOG(1) << "Exception thrown while processing " << networkOpToString(op) << " op for "
- << nss.ns() << causedBy(ex);
+ LOGV2_DEBUG(
+ 22869,
+ 1,
+ "Exception thrown while processing {networkOpToString_op} op for {nss_ns}{causedBy_ex}",
+ "networkOpToString_op"_attr = networkOpToString(op),
+ "nss_ns"_attr = nss.ns(),
+ "causedBy_ex"_attr = causedBy(ex));
if (op == dbQuery || op == dbGetMore) {
dbResponse = replyToQuery(buildErrReply(ex), ResultFlag_ErrSet);
diff --git a/src/mongo/s/shard_util.cpp b/src/mongo/s/shard_util.cpp
index 1f430a0d7be..68e9b9ad02d 100644
--- a/src/mongo/s/shard_util.cpp
+++ b/src/mongo/s/shard_util.cpp
@@ -38,6 +38,7 @@
#include "mongo/client/read_preference.h"
#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard_key_pattern.h"
@@ -203,7 +204,10 @@ StatusWith<boost::optional<ChunkRange>> splitChunkAtMultiplePoints(
}
if (!status.isOK()) {
- log() << "Split chunk " << redact(cmdObj) << " failed" << causedBy(redact(status));
+ LOGV2(22878,
+ "Split chunk {cmdObj} failed{causedBy_status}",
+ "cmdObj"_attr = redact(cmdObj),
+ "causedBy_status"_attr = causedBy(redact(status)));
return status.withContext("split failed");
}
@@ -217,10 +221,13 @@ StatusWith<boost::optional<ChunkRange>> splitChunkAtMultiplePoints(
return boost::optional<ChunkRange>(std::move(chunkRangeStatus.getValue()));
} else if (status != ErrorCodes::NoSuchKey) {
- warning()
- << "Chunk migration will be skipped because splitChunk returned invalid response: "
- << redact(cmdResponse) << ". Extracting " << kShouldMigrate << " field failed"
- << causedBy(redact(status));
+ LOGV2_WARNING(
+ 22879,
+ "Chunk migration will be skipped because splitChunk returned invalid response: "
+ "{cmdResponse}. Extracting {kShouldMigrate} field failed{causedBy_status}",
+ "cmdResponse"_attr = redact(cmdResponse),
+ "kShouldMigrate"_attr = kShouldMigrate,
+ "causedBy_status"_attr = causedBy(redact(status)));
}
return boost::optional<ChunkRange>();
diff --git a/src/mongo/s/sharding_task_executor.cpp b/src/mongo/s/sharding_task_executor.cpp
index c8db2851af7..5d3eb5243e9 100644
--- a/src/mongo/s/sharding_task_executor.cpp
+++ b/src/mongo/s/sharding_task_executor.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/logical_time.h"
#include "mongo/db/operation_time_tracker.h"
#include "mongo/executor/thread_pool_task_executor.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata/sharding_metadata.h"
#include "mongo/s/client/shard_registry.h"
@@ -180,16 +181,21 @@ StatusWith<TaskExecutor::CallbackHandle> ShardingTaskExecutor::scheduleRemoteCom
auto shard = grid->shardRegistry()->getShardForHostNoReload(target);
if (!shard) {
- LOG(1) << "Could not find shard containing host: " << target;
+ LOGV2_DEBUG(22870,
+ 1,
+ "Could not find shard containing host: {target}",
+ "target"_attr = target);
}
if (isMongos() && args.response.status == ErrorCodes::IncompatibleWithUpgradedServer) {
- severe() << "This mongos server must be upgraded. It is attempting to communicate "
+ LOGV2_FATAL(22873,
+ "This mongos server must be upgraded. It is attempting to communicate "
"with "
- "an upgraded cluster with which it is incompatible. Error: '"
- << args.response.status.toString()
- << "' Crashing in order to bring attention to the incompatibility, rather "
- "than erroring endlessly.";
+ "an upgraded cluster with which it is incompatible. Error: "
+ "'{args_response_status}' Crashing in order to bring attention to the "
+ "incompatibility, rather "
+ "than erroring endlessly.",
+ "args_response_status"_attr = args.response.status.toString());
fassertNoTrace(50710, false);
}
@@ -197,7 +203,8 @@ StatusWith<TaskExecutor::CallbackHandle> ShardingTaskExecutor::scheduleRemoteCom
shard->updateReplSetMonitor(target, args.response.status);
}
- LOG(1) << "Error processing the remote request, not updating operationTime or gLE";
+ LOGV2_DEBUG(
+ 22871, 1, "Error processing the remote request, not updating operationTime or gLE");
return;
}
@@ -228,16 +235,21 @@ StatusWith<TaskExecutor::CallbackHandle> ShardingTaskExecutor::scheduleRemoteCom
auto shardConn = ConnectionString::parse(target.toString());
if (!shardConn.isOK()) {
- severe() << "got bad host string in saveGLEStats: " << target;
+ LOGV2_FATAL(22874,
+ "got bad host string in saveGLEStats: {target}",
+ "target"_attr = target);
}
clusterGLE->addHostOpTime(shardConn.getValue(),
HostOpTime(shardingMetadata.getLastOpTime(),
shardingMetadata.getLastElectionId()));
} else if (swShardingMetadata.getStatus() != ErrorCodes::NoSuchKey) {
- warning() << "Got invalid sharding metadata "
- << redact(swShardingMetadata.getStatus()) << " metadata object was '"
- << redact(args.response.data) << "'";
+ LOGV2_WARNING(22872,
+ "Got invalid sharding metadata {swShardingMetadata_getStatus} "
+ "metadata object was '{args_response_data}'",
+ "swShardingMetadata_getStatus"_attr =
+ redact(swShardingMetadata.getStatus()),
+ "args_response_data"_attr = redact(args.response.data));
}
}
};
diff --git a/src/mongo/s/sharding_uptime_reporter.cpp b/src/mongo/s/sharding_uptime_reporter.cpp
index e1b7e57f7b5..72cb497c90d 100644
--- a/src/mongo/s/sharding_uptime_reporter.cpp
+++ b/src/mongo/s/sharding_uptime_reporter.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/client.h"
#include "mongo/db/read_write_concern_defaults.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/balancer_configuration.h"
#include "mongo/s/catalog/type_mongos.h"
#include "mongo/s/grid.h"
@@ -85,7 +86,7 @@ void reportStatus(OperationContext* opCtx,
ShardingCatalogClient::kMajorityWriteConcern)
.status_with_transitional_ignore();
} catch (const std::exception& e) {
- log() << "Caught exception while reporting uptime: " << e.what();
+ LOGV2(22875, "Caught exception while reporting uptime: {e_what}", "e_what"_attr = e.what());
}
}
@@ -117,15 +118,18 @@ void ShardingUptimeReporter::startPeriodicThread() {
->getBalancerConfiguration()
->refreshAndCheck(opCtx.get());
if (!status.isOK()) {
- warning() << "failed to refresh mongos settings" << causedBy(status);
+ LOGV2_WARNING(22876,
+ "failed to refresh mongos settings{causedBy_status}",
+ "causedBy_status"_attr = causedBy(status));
}
try {
ReadWriteConcernDefaults::get(opCtx.get()->getServiceContext())
.refreshIfNecessary(opCtx.get());
} catch (const DBException& ex) {
- warning() << "failed to refresh RWC defaults"
- << causedBy(redact(ex.toStatus()));
+ LOGV2_WARNING(22877,
+ "failed to refresh RWC defaults{causedBy_ex_toStatus}",
+ "causedBy_ex_toStatus"_attr = causedBy(redact(ex.toStatus())));
}
}
diff --git a/src/mongo/s/transaction_router.cpp b/src/mongo/s/transaction_router.cpp
index 44796119e1a..a7e4325e833 100644
--- a/src/mongo/s/transaction_router.cpp
+++ b/src/mongo/s/transaction_router.cpp
@@ -44,6 +44,7 @@
#include "mongo/db/repl/read_concern_args.h"
#include "mongo/db/transaction_validation.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/async_requests_sender.h"
#include "mongo/s/cluster_commands_helpers.h"
@@ -483,7 +484,11 @@ void TransactionRouter::Router::processParticipantResponse(OperationContext* opC
if (txnResponseMetadata.getReadOnly()) {
if (participant->readOnly == Participant::ReadOnly::kUnset) {
- LOG(3) << txnIdToString() << " Marking " << shardId << " as read-only";
+ LOGV2_DEBUG(22880,
+ 3,
+ "{txnIdToString} Marking {shardId} as read-only",
+ "txnIdToString"_attr = txnIdToString(),
+ "shardId"_attr = shardId);
_setReadOnlyForParticipant(opCtx, shardId, Participant::ReadOnly::kReadOnly);
return;
}
@@ -499,12 +504,20 @@ void TransactionRouter::Router::processParticipantResponse(OperationContext* opC
// The shard reported readOnly:false on this statement.
if (participant->readOnly != Participant::ReadOnly::kNotReadOnly) {
- LOG(3) << txnIdToString() << " Marking " << shardId << " as having done a write";
+ LOGV2_DEBUG(22881,
+ 3,
+ "{txnIdToString} Marking {shardId} as having done a write",
+ "txnIdToString"_attr = txnIdToString(),
+ "shardId"_attr = shardId);
_setReadOnlyForParticipant(opCtx, shardId, Participant::ReadOnly::kNotReadOnly);
if (!p().recoveryShardId) {
- LOG(3) << txnIdToString() << " Choosing " << shardId << " as recovery shard";
+ LOGV2_DEBUG(22882,
+ 3,
+ "{txnIdToString} Choosing {shardId} as recovery shard",
+ "txnIdToString"_attr = txnIdToString(),
+ "shardId"_attr = shardId);
p().recoveryShardId = shardId;
}
}
@@ -552,13 +565,20 @@ BSONObj TransactionRouter::Router::attachTxnFieldsIfNeeded(OperationContext* opC
const BSONObj& cmdObj) {
RouterTransactionsMetrics::get(opCtx)->incrementTotalRequestsTargeted();
if (auto txnPart = getParticipant(shardId)) {
- LOG(4) << txnIdToString()
- << " Sending transaction fields to existing participant: " << shardId;
+ LOGV2_DEBUG(22883,
+ 4,
+ "{txnIdToString} Sending transaction fields to existing participant: {shardId}",
+ "txnIdToString"_attr = txnIdToString(),
+ "shardId"_attr = shardId);
return txnPart->attachTxnFieldsIfNeeded(cmdObj, false);
}
auto txnPart = _createParticipant(opCtx, shardId);
- LOG(4) << txnIdToString() << " Sending transaction fields to new participant: " << shardId;
+ LOGV2_DEBUG(22884,
+ 4,
+ "{txnIdToString} Sending transaction fields to new participant: {shardId}",
+ "txnIdToString"_attr = txnIdToString(),
+ "shardId"_attr = shardId);
if (!p().isRecoveringCommit) {
// Don't update participant stats during recovery since the participant list isn't known.
RouterTransactionsMetrics::get(opCtx)->incrementTotalContactedParticipants();
@@ -740,8 +760,12 @@ void TransactionRouter::Router::onStaleShardOrDbError(OperationContext* opCtx,
const Status& errorStatus) {
invariant(canContinueOnStaleShardOrDbError(cmdName));
- LOG(3) << txnIdToString()
- << " Clearing pending participants after stale version error: " << errorStatus;
+ LOGV2_DEBUG(
+ 22885,
+ 3,
+ "{txnIdToString} Clearing pending participants after stale version error: {errorStatus}",
+ "txnIdToString"_attr = txnIdToString(),
+ "errorStatus"_attr = errorStatus);
// Remove participants created during the current statement so they are sent the correct options
// if they are targeted again by the retry.
@@ -752,8 +776,12 @@ void TransactionRouter::Router::onViewResolutionError(OperationContext* opCtx,
const NamespaceString& nss) {
// The router can always retry on a view resolution error.
- LOG(3) << txnIdToString()
- << " Clearing pending participants after view resolution error on namespace: " << nss;
+ LOGV2_DEBUG(22886,
+ 3,
+ "{txnIdToString} Clearing pending participants after view resolution error on "
+ "namespace: {nss}",
+ "txnIdToString"_attr = txnIdToString(),
+ "nss"_attr = nss);
// Requests against views are always routed to the primary shard for its database, but the retry
// on the resolved namespace does not have to re-target the primary, so pending participants
@@ -773,10 +801,14 @@ void TransactionRouter::Router::onSnapshotError(OperationContext* opCtx,
const Status& errorStatus) {
invariant(canContinueOnSnapshotError());
- LOG(3) << txnIdToString()
- << " Clearing pending participants and resetting global snapshot "
- "timestamp after snapshot error: "
- << errorStatus << ", previous timestamp: " << o().atClusterTime->getTime();
+ LOGV2_DEBUG(22887,
+ 3,
+ "{txnIdToString} Clearing pending participants and resetting global snapshot "
+ "timestamp after snapshot error: {errorStatus}, previous timestamp: "
+ "{o_atClusterTime_getTime}",
+ "txnIdToString"_attr = txnIdToString(),
+ "errorStatus"_attr = errorStatus,
+ "o_atClusterTime_getTime"_attr = o().atClusterTime->getTime());
// The transaction must be restarted on all participants because a new read timestamp will be
// selected, so clear all pending participants. Snapshot errors are only retryable on the first
@@ -814,8 +846,13 @@ void TransactionRouter::Router::_setAtClusterTime(
return;
}
- LOG(2) << txnIdToString() << " Setting global snapshot timestamp to " << candidateTime
- << " on statement " << p().latestStmtId;
+ LOGV2_DEBUG(22888,
+ 2,
+ "{txnIdToString} Setting global snapshot timestamp to {candidateTime} on statement "
+ "{p_latestStmtId}",
+ "txnIdToString"_attr = txnIdToString(),
+ "candidateTime"_attr = candidateTime,
+ "p_latestStmtId"_attr = p().latestStmtId);
o(lk).atClusterTime->setTime(candidateTime, p().latestStmtId);
}
@@ -877,7 +914,10 @@ void TransactionRouter::Router::beginOrContinueTxn(OperationContext* opCtx,
o(lk).atClusterTime.emplace();
}
- LOG(3) << txnIdToString() << " New transaction started";
+ LOGV2_DEBUG(22889,
+ 3,
+ "{txnIdToString} New transaction started",
+ "txnIdToString"_attr = txnIdToString());
break;
}
case TransactionActions::kContinue: {
@@ -892,7 +932,10 @@ void TransactionRouter::Router::beginOrContinueTxn(OperationContext* opCtx,
// means that the client is attempting to recover a commit decision.
p().isRecoveringCommit = true;
- LOG(3) << txnIdToString() << " Commit recovery started";
+ LOGV2_DEBUG(22890,
+ 3,
+ "{txnIdToString} Commit recovery started",
+ "txnIdToString"_attr = txnIdToString());
break;
}
};
@@ -929,8 +972,11 @@ BSONObj TransactionRouter::Router::_handOffCommitToCoordinator(OperationContext*
const auto coordinateCommitCmdObj = coordinateCommitCmd.toBSON(
BSON(WriteConcernOptions::kWriteConcernField << opCtx->getWriteConcern().toBSON()));
- LOG(3) << txnIdToString()
- << " Committing using two-phase commit, coordinator: " << *o().coordinatorId;
+ LOGV2_DEBUG(22891,
+ 3,
+ "{txnIdToString} Committing using two-phase commit, coordinator: {o_coordinatorId}",
+ "txnIdToString"_attr = txnIdToString(),
+ "o_coordinatorId"_attr = *o().coordinatorId);
MultiStatementTransactionRequestsSender ars(
opCtx,
@@ -1031,8 +1077,12 @@ BSONObj TransactionRouter::Router::_commitTransaction(
if (o().participants.size() == 1) {
ShardId shardId = o().participants.cbegin()->first;
- LOG(3) << txnIdToString()
- << " Committing single-shard transaction, single participant: " << shardId;
+ LOGV2_DEBUG(
+ 22892,
+ 3,
+ "{txnIdToString} Committing single-shard transaction, single participant: {shardId}",
+ "txnIdToString"_attr = txnIdToString(),
+ "shardId"_attr = shardId);
{
stdx::lock_guard<Client> lk(*opCtx->getClient());
@@ -1045,8 +1095,12 @@ BSONObj TransactionRouter::Router::_commitTransaction(
}
if (writeShards.size() == 0) {
- LOG(3) << txnIdToString() << " Committing read-only transaction on "
- << readOnlyShards.size() << " shards";
+ LOGV2_DEBUG(
+ 22893,
+ 3,
+ "{txnIdToString} Committing read-only transaction on {readOnlyShards_size} shards",
+ "txnIdToString"_attr = txnIdToString(),
+ "readOnlyShards_size"_attr = readOnlyShards.size());
{
stdx::lock_guard<Client> lk(*opCtx->getClient());
o(lk).commitType = CommitType::kReadOnly;
@@ -1057,9 +1111,13 @@ BSONObj TransactionRouter::Router::_commitTransaction(
}
if (writeShards.size() == 1) {
- LOG(3) << txnIdToString() << " Committing single-write-shard transaction with "
- << readOnlyShards.size()
- << " read-only shards, write shard: " << writeShards.front();
+ LOGV2_DEBUG(22894,
+ 3,
+ "{txnIdToString} Committing single-write-shard transaction with "
+ "{readOnlyShards_size} read-only shards, write shard: {writeShards_front}",
+ "txnIdToString"_attr = txnIdToString(),
+ "readOnlyShards_size"_attr = readOnlyShards.size(),
+ "writeShards_front"_attr = writeShards.front());
{
stdx::lock_guard<Client> lk(*opCtx->getClient());
o(lk).commitType = CommitType::kSingleWriteShard;
@@ -1106,8 +1164,11 @@ BSONObj TransactionRouter::Router::abortTransaction(OperationContext* opCtx) {
abortRequests.emplace_back(ShardId(participantEntry.first), abortCmd);
}
- LOG(3) << txnIdToString() << " Aborting transaction on " << o().participants.size()
- << " shard(s)";
+ LOGV2_DEBUG(22895,
+ 3,
+ "{txnIdToString} Aborting transaction on {o_participants_size} shard(s)",
+ "txnIdToString"_attr = txnIdToString(),
+ "o_participants_size"_attr = o().participants.size());
const auto responses = gatherResponses(opCtx,
NamespaceString::kAdminDb,
@@ -1145,9 +1206,11 @@ void TransactionRouter::Router::implicitlyAbortTransaction(OperationContext* opC
if (o().commitType == CommitType::kTwoPhaseCommit ||
o().commitType == CommitType::kRecoverWithToken) {
- LOG(3) << txnIdToString()
- << " Router not sending implicit abortTransaction because commit "
- "may have been handed off to the coordinator";
+ LOGV2_DEBUG(22896,
+ 3,
+ "{txnIdToString} Router not sending implicit abortTransaction because commit "
+ "may have been handed off to the coordinator",
+ "txnIdToString"_attr = txnIdToString());
return;
}
@@ -1167,8 +1230,13 @@ void TransactionRouter::Router::implicitlyAbortTransaction(OperationContext* opC
abortRequests.emplace_back(ShardId(participantEntry.first), abortCmd);
}
- LOG(3) << txnIdToString() << " Implicitly aborting transaction on " << o().participants.size()
- << " shard(s) due to error: " << errorStatus;
+ LOGV2_DEBUG(22897,
+ 3,
+ "{txnIdToString} Implicitly aborting transaction on {o_participants_size} shard(s) "
+ "due to error: {errorStatus}",
+ "txnIdToString"_attr = txnIdToString(),
+ "o_participants_size"_attr = o().participants.size(),
+ "errorStatus"_attr = errorStatus);
try {
// Ignore the responses.
@@ -1178,8 +1246,11 @@ void TransactionRouter::Router::implicitlyAbortTransaction(OperationContext* opC
Shard::RetryPolicy::kIdempotent,
abortRequests);
} catch (const DBException& ex) {
- LOG(3) << txnIdToString() << " Implicitly aborting transaction failed "
- << causedBy(ex.toStatus());
+ LOGV2_DEBUG(22898,
+ 3,
+ "{txnIdToString} Implicitly aborting transaction failed {causedBy_ex_toStatus}",
+ "txnIdToString"_attr = txnIdToString(),
+ "causedBy_ex_toStatus"_attr = causedBy(ex.toStatus()));
// Ignore any exceptions.
}
}
@@ -1262,7 +1333,10 @@ BSONObj TransactionRouter::Router::_commitWithRecoveryToken(OperationContext* op
void TransactionRouter::Router::_logSlowTransaction(OperationContext* opCtx,
TerminationCause terminationCause) const {
- log() << "transaction " << _transactionInfoForLog(opCtx, terminationCause);
+ LOGV2(22899,
+ "transaction {transactionInfoForLog_opCtx_terminationCause}",
+ "transactionInfoForLog_opCtx_terminationCause"_attr =
+ _transactionInfoForLog(opCtx, terminationCause));
}
std::string TransactionRouter::Router::_transactionInfoForLog(
diff --git a/src/mongo/s/version_mongos.cpp b/src/mongo/s/version_mongos.cpp
index 4e80a8e36f3..df35212494b 100644
--- a/src/mongo/s/version_mongos.cpp
+++ b/src/mongo/s/version_mongos.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/log_process_details.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/process_id.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/log.h"
@@ -47,10 +48,10 @@ void printShardingVersionInfo(bool isForVersionReportingOnly) {
if (isForVersionReportingOnly) {
setPlainConsoleLogger();
- log() << mongosVersion(vii);
+ LOGV2(22900, "{mongosVersion_vii}", "mongosVersion_vii"_attr = mongosVersion(vii));
vii.logBuildInfo();
} else {
- log() << mongosVersion(vii);
+ LOGV2(22901, "{mongosVersion_vii}", "mongosVersion_vii"_attr = mongosVersion(vii));
logProcessDetails();
}
}
diff --git a/src/mongo/s/write_ops/batch_write_exec.cpp b/src/mongo/s/write_ops/batch_write_exec.cpp
index c480589e65a..c81638ef82b 100644
--- a/src/mongo/s/write_ops/batch_write_exec.cpp
+++ b/src/mongo/s/write_ops/batch_write_exec.cpp
@@ -41,6 +41,7 @@
#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/error_labels.h"
#include "mongo/executor/task_executor_pool.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/multi_statement_transaction_requests_sender.h"
@@ -71,8 +72,12 @@ WriteErrorDetail errorFromStatus(const Status& status) {
// Helper to note several stale shard errors from a response
void noteStaleShardResponses(const std::vector<ShardError>& staleErrors, NSTargeter* targeter) {
for (const auto& error : staleErrors) {
- LOG(4) << "Noting stale config response " << error.error.getErrInfo() << " from shard "
- << error.endpoint.shardName;
+ LOGV2_DEBUG(22902,
+ 4,
+ "Noting stale config response {error_error_getErrInfo} from shard "
+ "{error_endpoint_shardName}",
+ "error_error_getErrInfo"_attr = error.error.getErrInfo(),
+ "error_endpoint_shardName"_attr = error.endpoint.shardName);
targeter->noteStaleShardResponse(
error.endpoint,
StaleConfigInfo::parseFromCommandError(
@@ -83,8 +88,12 @@ void noteStaleShardResponses(const std::vector<ShardError>& staleErrors, NSTarge
// Helper to note several stale db errors from a response
void noteStaleDbResponses(const std::vector<ShardError>& staleErrors, NSTargeter* targeter) {
for (const auto& error : staleErrors) {
- LOG(4) << "Noting stale database response " << error.error.toBSON() << " from shard "
- << error.endpoint.shardName;
+ LOGV2_DEBUG(
+ 22903,
+ 4,
+ "Noting stale database response {error_error} from shard {error_endpoint_shardName}",
+ "error_error"_attr = error.error.toBSON(),
+ "error_endpoint_shardName"_attr = error.endpoint.shardName);
targeter->noteStaleDbResponse(
error.endpoint, StaleDbRoutingVersion::parseFromCommandError(error.error.toBSON()));
}
@@ -115,8 +124,13 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
BatchWriteExecStats* stats) {
const auto& nss(clientRequest.getNS());
- LOG(4) << "Starting execution of write batch of size "
- << static_cast<int>(clientRequest.sizeWriteOps()) << " for " << nss.ns();
+ LOGV2_DEBUG(22904,
+ 4,
+ "Starting execution of write batch of size "
+ "{static_cast_int_clientRequest_sizeWriteOps} for {nss_ns}",
+ "static_cast_int_clientRequest_sizeWriteOps"_attr =
+ static_cast<int>(clientRequest.sizeWriteOps()),
+ "nss_ns"_attr = nss.ns());
BatchWriteOp batchOp(opCtx, clientRequest);
@@ -233,7 +247,11 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
return requestBuilder.obj();
}();
- LOG(4) << "Sending write batch to " << targetShardId << ": " << redact(request);
+ LOGV2_DEBUG(22905,
+ 4,
+ "Sending write batch to {targetShardId}: {request}",
+ "targetShardId"_attr = targetShardId,
+ "request"_attr = redact(request));
requests.emplace_back(targetShardId, request);
@@ -279,8 +297,14 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
// TODO: It may be necessary to refresh the cache if stale, or maybe just cancel
// and retarget the batch
- LOG(4) << "Unable to send write batch to " << batch->getEndpoint().shardName
- << causedBy(response.swResponse.getStatus());
+ LOGV2_DEBUG(
+ 22906,
+ 4,
+ "Unable to send write batch to "
+ "{batch_getEndpoint_shardName}{causedBy_response_swResponse_getStatus}",
+ "batch_getEndpoint_shardName"_attr = batch->getEndpoint().shardName,
+ "causedBy_response_swResponse_getStatus"_attr =
+ causedBy(response.swResponse.getStatus()));
// We're done with this batch. Clean up when we can't resolve a host.
auto it = childBatches.find(batch->getEndpoint().shardName);
@@ -309,8 +333,13 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
trackedErrors.startTracking(ErrorCodes::StaleShardVersion);
trackedErrors.startTracking(ErrorCodes::StaleDbVersion);
- LOG(4) << "Write results received from " << shardHost.toString() << ": "
- << redact(batchedCommandResponse.toStatus());
+ LOGV2_DEBUG(22907,
+ 4,
+ "Write results received from {shardHost}: "
+ "{batchedCommandResponse_toStatus}",
+ "shardHost"_attr = shardHost.toString(),
+ "batchedCommandResponse_toStatus"_attr =
+ redact(batchedCommandResponse.toStatus()));
// Dispatch was ok, note response
batchOp.noteBatchResponse(*batch, batchedCommandResponse, &trackedErrors);
@@ -372,8 +401,11 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
batchOp.noteBatchError(*batch, errorFromStatus(status));
- LOG(4) << "Unable to receive write results from " << shardHost
- << causedBy(redact(status));
+ LOGV2_DEBUG(22908,
+ 4,
+ "Unable to receive write results from {shardHost}{causedBy_status}",
+ "shardHost"_attr = shardHost,
+ "causedBy_status"_attr = causedBy(redact(status)));
// If we are in a transaction, we must stop immediately (even for unordered).
if (TransactionRouter::get(opCtx)) {
@@ -409,12 +441,17 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
bool targeterChanged = false;
Status refreshStatus = targeter.refreshIfNeeded(opCtx, &targeterChanged);
- LOG(4) << "executeBatch targeter changed: " << targeterChanged;
+ LOGV2_DEBUG(22909,
+ 4,
+ "executeBatch targeter changed: {targeterChanged}",
+ "targeterChanged"_attr = targeterChanged);
if (!refreshStatus.isOK()) {
// It's okay if we can't refresh, we'll just record errors for the ops if
// needed.
- warning() << "could not refresh targeter" << causedBy(refreshStatus.reason());
+ LOGV2_WARNING(22911,
+ "could not refresh targeter{causedBy_refreshStatus_reason}",
+ "causedBy_refreshStatus_reason"_attr = causedBy(refreshStatus.reason()));
}
//
@@ -446,13 +483,21 @@ void BatchWriteExec::executeBatch(OperationContext* opCtx,
batchOp.buildClientResponse(clientResponse);
- LOG(4) << "Finished execution of write batch"
- << (clientResponse->isErrDetailsSet() ? " with write errors" : "")
- << (clientResponse->isErrDetailsSet() && clientResponse->isWriteConcernErrorSet()
- ? " and"
- : "")
- << (clientResponse->isWriteConcernErrorSet() ? " with write concern error" : "")
- << " for " << clientRequest.getNS();
+ LOGV2_DEBUG(22910,
+ 4,
+ "Finished execution of write "
+ "batch{clientResponse_isErrDetailsSet_with_write_errors}{clientResponse_"
+ "isErrDetailsSet_clientResponse_isWriteConcernErrorSet_and}{clientResponse_"
+ "isWriteConcernErrorSet_with_write_concern_error} for {clientRequest_getNS}",
+ "clientResponse_isErrDetailsSet_with_write_errors"_attr =
+ (clientResponse->isErrDetailsSet() ? " with write errors" : ""),
+ "clientResponse_isErrDetailsSet_clientResponse_isWriteConcernErrorSet_and"_attr =
+ (clientResponse->isErrDetailsSet() && clientResponse->isWriteConcernErrorSet()
+ ? " and"
+ : ""),
+ "clientResponse_isWriteConcernErrorSet_with_write_concern_error"_attr =
+ (clientResponse->isWriteConcernErrorSet() ? " with write concern error" : ""),
+ "clientRequest_getNS"_attr = clientRequest.getNS());
}
void BatchWriteExecStats::noteTargetedShard(const ShardId& shardId) {
diff --git a/src/mongo/s/write_ops/chunk_manager_targeter.cpp b/src/mongo/s/write_ops/chunk_manager_targeter.cpp
index d5323ae09da..3d7012183dd 100644
--- a/src/mongo/s/write_ops/chunk_manager_targeter.cpp
+++ b/src/mongo/s/write_ops/chunk_manager_targeter.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/matcher/extensions_callback_noop.h"
#include "mongo/db/query/canonical_query.h"
#include "mongo/db/query/collation/collation_index_key.h"
+#include "mongo/logv2/log.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/cluster_commands_helpers.h"
#include "mongo/s/database_version_helpers.h"
@@ -271,9 +272,11 @@ CompareResult compareAllShardVersions(const CachedCollectionRoutingInfo& routing
// Throws b/c shard constructor throws
cachedShardVersion = getShardVersion(routingInfo, shardId);
} catch (const DBException& ex) {
- warning() << "could not lookup shard " << shardId
- << " in local cache, shard metadata may have changed"
- << " or be unavailable" << causedBy(ex);
+ LOGV2_WARNING(22915,
+ "could not lookup shard {shardId} in local cache, shard metadata may "
+ "have changed or be unavailable{causedBy_ex}",
+ "shardId"_attr = shardId,
+ "causedBy_ex"_attr = causedBy(ex));
return CompareResult_Unknown;
}
@@ -729,10 +732,14 @@ Status ChunkManagerTargeter::refreshIfNeeded(OperationContext* opCtx, bool* wasC
*wasChanged = false;
- LOG(4) << "ChunkManagerTargeter checking if refresh is needed, needsTargetingRefresh("
- << _needsTargetingRefresh << ") remoteShardVersions empty ("
- << _remoteShardVersions.empty() << ")"
- << ") remoteDbVersion empty (" << !_remoteDbVersion << ")";
+ LOGV2_DEBUG(22912,
+ 4,
+ "ChunkManagerTargeter checking if refresh is needed, "
+ "needsTargetingRefresh({needsTargetingRefresh}) remoteShardVersions empty "
+ "({remoteShardVersions_empty})) remoteDbVersion empty ({remoteDbVersion})",
+ "needsTargetingRefresh"_attr = _needsTargetingRefresh,
+ "remoteShardVersions_empty"_attr = _remoteShardVersions.empty(),
+ "remoteDbVersion"_attr = !_remoteDbVersion);
//
// Did we have any stale config or targeting errors at all?
@@ -786,7 +793,10 @@ Status ChunkManagerTargeter::refreshIfNeeded(OperationContext* opCtx, bool* wasC
CompareResult result = compareAllShardVersions(*_routingInfo, _remoteShardVersions);
- LOG(4) << "ChunkManagerTargeter shard versions comparison result: " << (int)result;
+ LOGV2_DEBUG(22913,
+ 4,
+ "ChunkManagerTargeter shard versions comparison result: {int_result}",
+ "int_result"_attr = (int)result);
// Reset the versions
_remoteShardVersions.clear();
@@ -805,7 +815,10 @@ Status ChunkManagerTargeter::refreshIfNeeded(OperationContext* opCtx, bool* wasC
CompareResult result = compareDbVersions(*_routingInfo, *_remoteDbVersion);
- LOG(4) << "ChunkManagerTargeter database versions comparison result: " << (int)result;
+ LOGV2_DEBUG(22914,
+ 4,
+ "ChunkManagerTargeter database versions comparison result: {int_result}",
+ "int_result"_attr = (int)result);
// Reset the version
_remoteDbVersion = boost::none;
diff --git a/src/mongo/scripting/engine.cpp b/src/mongo/scripting/engine.cpp
index 77017f455ae..fb18a034226 100644
--- a/src/mongo/scripting/engine.cpp
+++ b/src/mongo/scripting/engine.cpp
@@ -40,6 +40,7 @@
#include "mongo/client/dbclient_cursor.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/dbdirectclient_factory.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/file.h"
@@ -137,7 +138,7 @@ bool Scope::execFile(const string& filename, bool printResult, bool reportError,
boost::filesystem::path p(filename);
#endif
if (!exists(p)) {
- error() << "file [" << filename << "] doesn't exist";
+ LOGV2_ERROR(22779, "file [{filename}] doesn't exist", "filename"_attr = filename);
return false;
}
@@ -156,7 +157,9 @@ bool Scope::execFile(const string& filename, bool printResult, bool reportError,
}
if (empty) {
- error() << "directory [" << filename << "] doesn't have any *.js files";
+ LOGV2_ERROR(22780,
+ "directory [{filename}] doesn't have any *.js files",
+ "filename"_attr = filename);
return false;
}
@@ -171,7 +174,7 @@ bool Scope::execFile(const string& filename, bool printResult, bool reportError,
fileofs fo = f.len();
if (fo > kMaxJsFileLength) {
- warning() << "attempted to execute javascript file larger than 2GB";
+ LOGV2_WARNING(22778, "attempted to execute javascript file larger than 2GB");
return false;
}
unsigned len = static_cast<unsigned>(fo);
@@ -258,8 +261,10 @@ void Scope::loadStored(OperationContext* opCtx, bool ignoreNotConnected) {
throw;
}
- error() << "unable to load stored JavaScript function " << n.valuestr()
- << "(): " << redact(setElemEx);
+ LOGV2_ERROR(22781,
+ "unable to load stored JavaScript function {n_valuestr}(): {setElemEx}",
+ "n_valuestr"_attr = n.valuestr(),
+ "setElemEx"_attr = redact(setElemEx));
}
}
@@ -339,7 +344,7 @@ public:
if (scope->hasOutOfMemoryException()) {
// make some room
- log() << "Clearing all idle JS contexts due to out of memory";
+ LOGV2(22777, "Clearing all idle JS contexts due to out of memory");
_pools.clear();
return;
}
diff --git a/src/mongo/scripting/mozjs/cursor_handle.cpp b/src/mongo/scripting/mozjs/cursor_handle.cpp
index 101334a737b..80a1950d46d 100644
--- a/src/mongo/scripting/mozjs/cursor_handle.cpp
+++ b/src/mongo/scripting/mozjs/cursor_handle.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/client/dbclient_base.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/mozjs/cursor_handle.h"
#include "mongo/scripting/mozjs/implscope.h"
#include "mongo/scripting/mozjs/scripting_util_gen.h"
@@ -77,7 +78,10 @@ void CursorHandleInfo::finalize(js::FreeOp* fop, JSObject* obj) {
auto status = exceptionToStatus();
try {
- LOG(0) << "Failed to kill cursor " << cursorId << " due to " << status;
+ LOGV2(22782,
+ "Failed to kill cursor {cursorId} due to {status}",
+ "cursorId"_attr = cursorId,
+ "status"_attr = status);
} catch (...) {
// This is here in case logging fails.
}
diff --git a/src/mongo/scripting/mozjs/engine.cpp b/src/mongo/scripting/mozjs/engine.cpp
index 766c2fce637..2b921bf01f7 100644
--- a/src/mongo/scripting/mozjs/engine.cpp
+++ b/src/mongo/scripting/mozjs/engine.cpp
@@ -36,6 +36,7 @@
#include <js/Initialization.h>
#include "mongo/db/operation_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/mozjs/engine_gen.h"
#include "mongo/scripting/mozjs/implscope.h"
#include "mongo/scripting/mozjs/proxyscope.h"
@@ -86,11 +87,19 @@ void MozJSScriptEngine::interrupt(unsigned opId) {
OpIdToScopeMap::iterator iScope = _opToScopeMap.find(opId);
if (iScope == _opToScopeMap.end()) {
// got interrupt request for a scope that no longer exists
- LOG(1) << "received interrupt request for unknown op: " << opId << printKnownOps_inlock();
+ LOGV2_DEBUG(22783,
+ 1,
+ "received interrupt request for unknown op: {opId}{printKnownOps_inlock}",
+ "opId"_attr = opId,
+ "printKnownOps_inlock"_attr = printKnownOps_inlock());
return;
}
- LOG(1) << "interrupting op: " << opId << printKnownOps_inlock();
+ LOGV2_DEBUG(22784,
+ 1,
+ "interrupting op: {opId}{printKnownOps_inlock}",
+ "opId"_attr = opId,
+ "printKnownOps_inlock"_attr = printKnownOps_inlock());
iScope->second->kill();
}
@@ -147,7 +156,11 @@ void MozJSScriptEngine::registerOperation(OperationContext* opCtx, MozJSImplScop
_opToScopeMap[opId] = scope;
- LOG(2) << "SMScope " << reinterpret_cast<uint64_t>(scope) << " registered for op " << opId;
+ LOGV2_DEBUG(22785,
+ 2,
+ "SMScope {reinterpret_cast_uint64_t_scope} registered for op {opId}",
+ "reinterpret_cast_uint64_t_scope"_attr = reinterpret_cast<uint64_t>(scope),
+ "opId"_attr = opId);
Status status = opCtx->checkForInterruptNoAssert();
if (!status.isOK()) {
scope->kill();
@@ -157,7 +170,11 @@ void MozJSScriptEngine::registerOperation(OperationContext* opCtx, MozJSImplScop
void MozJSScriptEngine::unregisterOperation(unsigned int opId) {
stdx::lock_guard<Latch> giLock(_globalInterruptLock);
- LOG(2) << "ImplScope " << reinterpret_cast<uint64_t>(this) << " unregistered for op " << opId;
+ LOGV2_DEBUG(22786,
+ 2,
+ "ImplScope {reinterpret_cast_uint64_t_this} unregistered for op {opId}",
+ "reinterpret_cast_uint64_t_this"_attr = reinterpret_cast<uint64_t>(this),
+ "opId"_attr = opId);
if (opId != 0) {
// scope is currently associated with an operation id
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp
index 7c2f57a04ef..75f4a902a37 100644
--- a/src/mongo/scripting/mozjs/implscope.cpp
+++ b/src/mongo/scripting/mozjs/implscope.cpp
@@ -43,6 +43,7 @@
#include "mongo/base/error_codes.h"
#include "mongo/config.h"
#include "mongo/db/operation_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/decimal128.h"
#include "mongo/platform/mutex.h"
#include "mongo/platform/stack_locator.h"
@@ -224,8 +225,13 @@ void MozJSImplScope::_gcCallback(JSContext* rt, JSGCStatus status, void* data) {
return;
}
- log() << "MozJS GC " << (status == JSGC_BEGIN ? "prologue" : "epilogue") << " heap stats - "
- << " total: " << mongo::sm::get_total_bytes() << " limit: " << mongo::sm::get_max_bytes();
+ LOGV2(22787,
+ "MozJS GC {status_JSGC_BEGIN_prologue_epilogue} heap stats - total: "
+ "{mongo_sm_get_total_bytes} limit: {mongo_sm_get_max_bytes}",
+ "status_JSGC_BEGIN_prologue_epilogue"_attr =
+ (status == JSGC_BEGIN ? "prologue" : "epilogue"),
+ "mongo_sm_get_total_bytes"_attr = mongo::sm::get_total_bytes(),
+ "mongo_sm_get_max_bytes"_attr = mongo::sm::get_max_bytes());
}
#if __has_feature(address_sanitizer)
@@ -275,7 +281,8 @@ MozJSImplScope::MozRuntime::MozRuntime(const MozJSScriptEngine* engine,
jsHeapLimitMB ? std::min(*jsHeapLimitMB, engineJsHeapLimit) : engineJsHeapLimit;
if (jsHeapLimit != 0 && jsHeapLimit < 10) {
- warning() << "JavaScript may not be able to initialize with a heap limit less than 10MB.";
+ LOGV2_WARNING(22788,
+ "JavaScript may not be able to initialize with a heap limit less than 10MB.");
}
size_t mallocMemoryLimit = 1024ul * 1024 * jsHeapLimit;
mongo::sm::reset(mallocMemoryLimit);
@@ -699,7 +706,7 @@ int MozJSImplScope::invoke(ScriptingFunction func,
// must validate the handle because TerminateExecution may have
// been thrown after the above checks
if (out.isObject() && _nativeFunctionProto.instanceOf(out)) {
- warning() << "storing native function as return value";
+ LOGV2_WARNING(22789, "storing native function as return value");
_lastRetIsNativeCode = true;
} else {
_lastRetIsNativeCode = false;
diff --git a/src/mongo/scripting/mozjs/session.cpp b/src/mongo/scripting/mozjs/session.cpp
index f1353742344..cc7eaa204af 100644
--- a/src/mongo/scripting/mozjs/session.cpp
+++ b/src/mongo/scripting/mozjs/session.cpp
@@ -33,6 +33,7 @@
#include "mongo/scripting/mozjs/session.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/mozjs/bson.h"
#include "mongo/scripting/mozjs/implscope.h"
#include "mongo/scripting/mozjs/mongo.h"
@@ -152,7 +153,10 @@ void SessionInfo::finalize(js::FreeOp* fop, JSObject* obj) {
auto status = exceptionToStatus();
try {
- LOG(0) << "Failed to end session " << lsid << " due to " << status;
+ LOGV2(22791,
+ "Failed to end session {lsid} due to {status}",
+ "lsid"_attr = lsid,
+ "status"_attr = status);
} catch (...) {
// This is here in case logging fails.
}
diff --git a/src/mongo/shell/bench.cpp b/src/mongo/shell/bench.cpp
index 765120a8f94..ffa2af16563 100644
--- a/src/mongo/shell/bench.cpp
+++ b/src/mongo/shell/bench.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/getmore_request.h"
#include "mongo/db/query/query_request.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/bson_template_evaluator.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/log.h"
@@ -738,7 +739,7 @@ void BenchRunConfig::initializeFromBson(const BSONObj& args) {
ops.push_back(opFromBson(i.next().Obj()));
}
} else {
- log() << "benchRun passed an unsupported field: " << name;
+ LOGV2(22793, "benchRun passed an unsupported field: {name}", "name"_attr = name);
uassert(34376, "benchRun passed an unsupported configuration field", false);
}
}
@@ -763,9 +764,9 @@ BenchRunState::BenchRunState(unsigned numWorkers)
BenchRunState::~BenchRunState() {
if (_numActiveWorkers != 0)
- warning() << "Destroying BenchRunState with active workers";
+ LOGV2_WARNING(22802, "Destroying BenchRunState with active workers");
if (_numUnstartedWorkers != 0)
- warning() << "Destroying BenchRunState with unstarted workers";
+ LOGV2_WARNING(22803, "Destroying BenchRunState with unstarted workers");
}
void BenchRunState::waitForState(State awaitedState) {
@@ -841,7 +842,9 @@ BenchRunWorker::~BenchRunWorker() {
// before returning from BenchRunWorker's destructor.
_thread.join();
} catch (...) {
- severe() << "caught exception in destructor: " << exceptionToStatus();
+ LOGV2_FATAL(22807,
+ "caught exception in destructor: {exceptionToStatus}",
+ "exceptionToStatus"_attr = exceptionToStatus());
std::terminate();
}
}
@@ -915,8 +918,12 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) {
(!_config->noWatchPattern && _config->watchPattern &&
yesWatch) || // If we're just watching things
(_config->watchPattern && _config->noWatchPattern && yesWatch && !noWatch))
- log() << "Error in benchRun thread for op "
- << kOpTypeNames.find(op.op)->second << causedBy(ex);
+ LOGV2(22794,
+ "Error in benchRun thread for op "
+ "{kOpTypeNames_find_op_op_second}{causedBy_ex}",
+ "kOpTypeNames_find_op_op_second"_attr =
+ kOpTypeNames.find(op.op)->second,
+ "causedBy_ex"_attr = causedBy(ex));
}
bool yesTrap = (_config->trapPattern && _config->trapPattern->FullMatch(ex.what()));
@@ -942,8 +949,10 @@ void BenchRunWorker::generateLoadOnConnection(DBClientBase* conn) {
++opState.stats->errCount;
} catch (...) {
if (!_config->hideErrors || op.showError)
- log() << "Error in benchRun thread caused by unknown error for op "
- << kOpTypeNames.find(op.op)->second;
+ LOGV2(22795,
+ "Error in benchRun thread caused by unknown error for op "
+ "{kOpTypeNames_find_op_op_second}",
+ "kOpTypeNames_find_op_op_second"_attr = kOpTypeNames.find(op.op)->second);
if (!_config->handleErrors && !op.handleError)
return;
@@ -1013,7 +1022,9 @@ void BenchRunOp::executeOnce(DBClientBase* conn,
}
if (!config.hideResults || this->showResult)
- log() << "Result from benchRun thread [findOne] : " << result;
+ LOGV2(22796,
+ "Result from benchRun thread [findOne] : {result}",
+ "result"_attr = result);
} break;
case OpType::COMMAND: {
bool ok;
@@ -1142,13 +1153,16 @@ void BenchRunOp::executeOnce(DBClientBase* conn,
}
if (this->expected >= 0 && count != this->expected) {
- log() << "bench query on: " << this->ns << " expected: " << this->expected
- << " got: " << count;
+ LOGV2(22797,
+ "bench query on: {this_ns} expected: {this_expected} got: {count}",
+ "this_ns"_attr = this->ns,
+ "this_expected"_attr = this->expected,
+ "count"_attr = count);
verify(false);
}
if (!config.hideResults || this->showResult)
- log() << "Result from benchRun thread [query] : " << count;
+ LOGV2(22798, "Result from benchRun thread [query] : {count}", "count"_attr = count);
} break;
case OpType::UPDATE: {
BSONObj result;
@@ -1218,7 +1232,9 @@ void BenchRunOp::executeOnce(DBClientBase* conn,
if (this->safe) {
if (!config.hideResults || this->showResult)
- log() << "Result from benchRun thread [safe update] : " << result;
+ LOGV2(22799,
+ "Result from benchRun thread [safe update] : {result}",
+ "result"_attr = result);
if (!result["err"].eoo() && result["err"].type() == String &&
(config.throwGLE || this->throwGLE))
@@ -1282,7 +1298,9 @@ void BenchRunOp::executeOnce(DBClientBase* conn,
if (this->safe) {
if (!config.hideResults || this->showResult)
- log() << "Result from benchRun thread [safe insert] : " << result;
+ LOGV2(22800,
+ "Result from benchRun thread [safe insert] : {result}",
+ "result"_attr = result);
if (!result["err"].eoo() && result["err"].type() == String &&
(config.throwGLE || this->throwGLE))
@@ -1327,7 +1345,9 @@ void BenchRunOp::executeOnce(DBClientBase* conn,
if (this->safe) {
if (!config.hideResults || this->showResult)
- log() << "Result from benchRun thread [safe remove] : " << result;
+ LOGV2(22801,
+ "Result from benchRun thread [safe remove] : {result}",
+ "result"_attr = result);
if (!result["err"].eoo() && result["err"].type() == String &&
(config.throwGLE || this->throwGLE))
@@ -1370,11 +1390,15 @@ void BenchRunWorker::run() {
BenchRunWorkerStateGuard workerStateGuard(_brState);
generateLoadOnConnection(conn.get());
} catch (const DBException& e) {
- error() << "DBException not handled in benchRun thread" << causedBy(e);
+ LOGV2_ERROR(22804,
+ "DBException not handled in benchRun thread{causedBy_e}",
+ "causedBy_e"_attr = causedBy(e));
} catch (const std::exception& e) {
- error() << "std::exception not handled in benchRun thread" << causedBy(e);
+ LOGV2_ERROR(22805,
+ "std::exception not handled in benchRun thread{causedBy_e}",
+ "causedBy_e"_attr = causedBy(e));
} catch (...) {
- error() << "Unknown exception not handled in benchRun thread.";
+ LOGV2_ERROR(22806, "Unknown exception not handled in benchRun thread.");
}
}
diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp
index dbdc9371f9b..fed35a6d07b 100644
--- a/src/mongo/shell/shell_options.cpp
+++ b/src/mongo/shell/shell_options.cpp
@@ -43,6 +43,7 @@
#include "mongo/config.h"
#include "mongo/db/auth/sasl_command_constants.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/protocol.h"
#include "mongo/shell/shell_utils.h"
#include "mongo/transport/message_compressor_options_client_gen.h"
@@ -89,9 +90,14 @@ bool handlePreValidationMongoShellOptions(const moe::Environment& params,
auto&& vii = VersionInfoInterface::instance();
if (params.count("version") || params.count("help")) {
setPlainConsoleLogger();
- log() << mongoShellVersion(vii);
+ LOGV2(22808,
+ "{mongoShellVersion_vii}",
+ "mongoShellVersion_vii"_attr = mongoShellVersion(vii));
if (params.count("help")) {
- log() << getMongoShellHelp(args[0], moe::startupOptions);
+ LOGV2(22809,
+ "{getMongoShellHelp_args_0_moe_startupOptions}",
+ "getMongoShellHelp_args_0_moe_startupOptions"_attr =
+ getMongoShellHelp(args[0], moe::startupOptions));
} else {
vii.logBuildInfo();
}
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index 65a5207a6fd..592eda259d0 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -63,6 +63,7 @@
#include "mongo/base/environment_buffer.h"
#include "mongo/client/dbclient_connection.h"
#include "mongo/db/traffic_reader.h"
+#include "mongo/logv2/log.h"
#include "mongo/scripting/engine.h"
#include "mongo/shell/shell_options.h"
#include "mongo/shell/shell_utils.h"
@@ -129,7 +130,7 @@ void safeClose(int fd) {
#endif
if (close(fd) != 0) {
const auto ewd = errnoWithDescription();
- error() << "failed to close fd " << fd << ": " << ewd;
+ LOGV2_ERROR(22829, "failed to close fd {fd}: {ewd}", "fd"_attr = fd, "ewd"_attr = ewd);
fassertFailed(40318);
}
}
@@ -415,7 +416,7 @@ void ProgramRunner::start() {
int status = pipe(pipeEnds);
if (status != 0) {
const auto ewd = errnoWithDescription();
- error() << "failed to create pipe: " << ewd;
+ LOGV2_ERROR(22830, "failed to create pipe: {ewd}", "ewd"_attr = ewd);
fassertFailed(16701);
}
#ifndef _WIN32
@@ -426,13 +427,13 @@ void ProgramRunner::start() {
status = fcntl(pipeEnds[0], F_SETFD, FD_CLOEXEC);
if (status != 0) {
const auto ewd = errnoWithDescription();
- error() << "failed to set FD_CLOEXEC on pipe end 0: " << ewd;
+ LOGV2_ERROR(22831, "failed to set FD_CLOEXEC on pipe end 0: {ewd}", "ewd"_attr = ewd);
fassertFailed(40308);
}
status = fcntl(pipeEnds[1], F_SETFD, FD_CLOEXEC);
if (status != 0) {
const auto ewd = errnoWithDescription();
- error() << "failed to set FD_CLOEXEC on pipe end 1: " << ewd;
+ LOGV2_ERROR(22832, "failed to set FD_CLOEXEC on pipe end 1: {ewd}", "ewd"_attr = ewd);
fassertFailed(40317);
}
#endif
@@ -459,7 +460,7 @@ void ProgramRunner::start() {
for (unsigned i = 0; i < _argv.size(); i++) {
ss << " " << _argv[i];
}
- log() << ss.str();
+ LOGV2(22810, "{ss_str}", "ss_str"_attr = ss.str());
}
}
@@ -715,7 +716,7 @@ bool wait_for_pid(ProcessId pid, bool block = true, int* exit_code = nullptr) {
return false;
} else if (ret != WAIT_OBJECT_0) {
const auto ewd = errnoWithDescription();
- log() << "wait_for_pid: WaitForSingleObject failed: " << ewd;
+ LOGV2(22811, "wait_for_pid: WaitForSingleObject failed: {ewd}", "ewd"_attr = ewd);
}
DWORD tmp;
@@ -734,7 +735,7 @@ bool wait_for_pid(ProcessId pid, bool block = true, int* exit_code = nullptr) {
return true;
} else {
const auto ewd = errnoWithDescription();
- log() << "GetExitCodeProcess failed: " << ewd;
+ LOGV2(22812, "GetExitCodeProcess failed: {ewd}", "ewd"_attr = ewd);
return false;
}
#else
@@ -796,7 +797,7 @@ BSONObj WaitMongoProgram(const BSONObj& a, void* data) {
int exit_code = -123456; // sentinel value
invariant(port >= 0);
if (!registry.isPortRegistered(port)) {
- log() << "No db started on port: " << port;
+ LOGV2(22813, "No db started on port: {port}", "port"_attr = port);
return BSON(string("") << 0);
}
pid = registry.pidForPort(port);
@@ -862,7 +863,7 @@ BSONObj ResetDbpath(const BSONObj& a, void* data) {
verify(a.nFields() == 1);
string path = a.firstElement().valuestrsafe();
if (path.empty()) {
- warning() << "ResetDbpath(): nothing to do, path was empty";
+ LOGV2_WARNING(22824, "ResetDbpath(): nothing to do, path was empty");
return undefinedReturn;
}
if (boost::filesystem::exists(path))
@@ -875,7 +876,7 @@ BSONObj PathExists(const BSONObj& a, void* data) {
verify(a.nFields() == 1);
string path = a.firstElement().valuestrsafe();
if (path.empty()) {
- warning() << "PathExists(): path was empty";
+ LOGV2_WARNING(22825, "PathExists(): path was empty");
return BSON(string("") << false);
};
bool exists = boost::filesystem::exists(path);
@@ -892,8 +893,12 @@ void copyDir(const boost::filesystem::path& from, const boost::filesystem::path&
boost::system::error_code ec;
boost::filesystem::copy_file(p, to / p.leaf(), ec);
if (ec) {
- log() << "Skipping copying of file from '" << p.generic_string() << "' to '"
- << (to / p.leaf()).generic_string() << "' due to: " << ec.message();
+ LOGV2(22814,
+ "Skipping copying of file from '{p_generic_string}' to "
+ "'{to_p_leaf_generic_string}' due to: {ec_message}",
+ "p_generic_string"_attr = p.generic_string(),
+ "to_p_leaf_generic_string"_attr = (to / p.leaf()).generic_string(),
+ "ec_message"_attr = ec.message());
}
} else if (p.leaf() != "mongod.lock" && p.leaf() != "WiredTiger.lock") {
if (boost::filesystem::is_directory(p)) {
@@ -915,7 +920,8 @@ BSONObj CopyDbpath(const BSONObj& a, void* data) {
string from = i.next().str();
string to = i.next().str();
if (from.empty() || to.empty()) {
- warning() << "CopyDbpath(): nothing to do, source or destination path(s) were empty";
+ LOGV2_WARNING(22826,
+ "CopyDbpath(): nothing to do, source or destination path(s) were empty");
return undefinedReturn;
}
if (boost::filesystem::exists(to))
@@ -941,11 +947,13 @@ inline void kill_wrapper(ProcessId pid, int sig, int port, const BSONObj& opt) {
int gle = GetLastError();
if (gle != ERROR_FILE_NOT_FOUND) {
const auto ewd = errnoWithDescription();
- warning() << "kill_wrapper OpenEvent failed: " << ewd;
+ LOGV2_WARNING(22827, "kill_wrapper OpenEvent failed: {ewd}", "ewd"_attr = ewd);
} else {
- log() << "kill_wrapper OpenEvent failed to open event to the process " << pid.asUInt32()
- << ". It has likely died already or server is running an older version."
- << " Attempting to shutdown through admin command.";
+ LOGV2(22815,
+ "kill_wrapper OpenEvent failed to open event to the process {pid_asUInt32}. It "
+ "has likely died already or server is running an older version. Attempting to "
+ "shutdown through admin command.",
+ "pid_asUInt32"_attr = pid.asUInt32());
// Back-off to the old way of shutting down the server on Windows, in case we
// are managing a pre-2.6.0rc0 service, which did not have the event.
@@ -984,7 +992,7 @@ inline void kill_wrapper(ProcessId pid, int sig, int port, const BSONObj& opt) {
bool result = SetEvent(event);
if (!result) {
const auto ewd = errnoWithDescription();
- error() << "kill_wrapper SetEvent failed: " << ewd;
+ LOGV2_ERROR(22833, "kill_wrapper SetEvent failed: {ewd}", "ewd"_attr = ewd);
return;
}
#else
@@ -993,7 +1001,7 @@ inline void kill_wrapper(ProcessId pid, int sig, int port, const BSONObj& opt) {
if (errno == ESRCH) {
} else {
const auto ewd = errnoWithDescription();
- log() << "killFailed: " << ewd;
+ LOGV2(22816, "killFailed: {ewd}", "ewd"_attr = ewd);
verify(x == 0);
}
}
@@ -1005,7 +1013,7 @@ int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt, bool waitPi
ProcessId pid;
if (port > 0) {
if (!registry.isPortRegistered(port)) {
- log() << "No db started on port: " << port;
+ LOGV2(22817, "No db started on port: {port}", "port"_attr = port);
return 0;
}
pid = registry.pidForPort(port);
@@ -1017,16 +1025,16 @@ int killDb(int port, ProcessId _pid, int signal, const BSONObj& opt, bool waitPi
// If we are not waiting for the process to end, then return immediately.
if (!waitPid) {
- log() << "skip waiting for pid " << pid << " to terminate";
+ LOGV2(22818, "skip waiting for pid {pid} to terminate", "pid"_attr = pid);
return 0;
}
int exitCode = EXIT_FAILURE;
try {
- log() << "waiting for process " << pid << " to terminate.";
+ LOGV2(22819, "waiting for process {pid} to terminate.", "pid"_attr = pid);
wait_for_pid(pid, true, &exitCode);
} catch (...) {
- warning() << "process " << pid << " failed to terminate.";
+ LOGV2_WARNING(22828, "process {pid} failed to terminate.", "pid"_attr = pid);
return EXIT_FAILURE;
}
@@ -1090,10 +1098,12 @@ BSONObj StopMongoProgram(const BSONObj& a, void* data) {
uassert(ErrorCodes::FailedToParse, "wrong number of arguments", nFields >= 1 && nFields <= 4);
uassert(ErrorCodes::BadValue, "stopMongoProgram needs a number", a.firstElement().isNumber());
int port = int(a.firstElement().number());
- log() << "shell: stopping mongo program, waitpid=" << getWaitPid(a);
+ LOGV2(22820,
+ "shell: stopping mongo program, waitpid={getWaitPid_a}",
+ "getWaitPid_a"_attr = getWaitPid(a));
int code =
killDb(port, ProcessId::fromNative(0), getSignal(a), getStopMongodOpts(a), getWaitPid(a));
- log() << "shell: stopped mongo program on port " << port;
+ LOGV2(22821, "shell: stopped mongo program on port {port}", "port"_attr = port);
return BSON("" << (double)code);
}
@@ -1104,7 +1114,7 @@ BSONObj StopMongoProgramByPid(const BSONObj& a, void* data) {
ErrorCodes::BadValue, "stopMongoProgramByPid needs a number", a.firstElement().isNumber());
ProcessId pid = ProcessId::fromNative(int(a.firstElement().number()));
int code = killDb(0, pid, getSignal(a), getStopMongodOpts(a));
- log() << "shell: stopped mongo program with pid " << pid;
+ LOGV2(22822, "shell: stopped mongo program with pid {pid}", "pid"_attr = pid);
return BSON("" << (double)code);
}
@@ -1124,7 +1134,10 @@ int KillMongoProgramInstances() {
int port = registry.portForPid(pid);
int code = killDb(port != -1 ? port : 0, pid, SIGTERM);
if (code != EXIT_SUCCESS) {
- log() << "Process with pid " << pid << " exited with error code " << code;
+ LOGV2(22823,
+ "Process with pid {pid} exited with error code {code}",
+ "pid"_attr = pid,
+ "code"_attr = code);
returnCode = code;
}
}
diff --git a/src/mongo/tools/bridge.cpp b/src/mongo/tools/bridge.cpp
index 7a51f983fee..2405a343d5e 100644
--- a/src/mongo/tools/bridge.cpp
+++ b/src/mongo/tools/bridge.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/dbmessage.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/platform/mutex.h"
#include "mongo/platform/random.h"
@@ -93,7 +94,7 @@ public:
return status.getStatus();
}
- log() << "Processing bridge command: " << cmdName;
+ LOGV2(22916, "Processing bridge command: {cmdName}", "cmdName"_attr = cmdName);
BridgeCommand* command = status.getValue();
return command->run(cmdObj, &_settingsMutex, &_settings);
@@ -249,7 +250,10 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const
tl->connect(destAddr, transport::kGlobalSSLMode, connectExpiration - now);
auto status = sws.getStatus();
if (!status.isOK()) {
- warning() << "Unable to establish connection to " << destAddr << ": " << status;
+ LOGV2_WARNING(22924,
+ "Unable to establish connection to {destAddr}: {status}",
+ "destAddr"_attr = destAddr,
+ "status"_attr = status);
now = getGlobalServiceContext()->getFastClockSource()->now();
} else {
return std::move(sws.getValue());
@@ -277,8 +281,13 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const
dest.extractHostInfo(*cmdRequest);
- LOG(1) << "Received \"" << cmdRequest->getCommandName() << "\" command with arguments "
- << cmdRequest->body << " from " << dest;
+ LOGV2_DEBUG(22917,
+ 1,
+ "Received \"{cmdRequest_getCommandName}\" command with arguments "
+ "{cmdRequest_body} from {dest}",
+ "cmdRequest_getCommandName"_attr = cmdRequest->getCommandName(),
+ "cmdRequest_body"_attr = cmdRequest->body,
+ "dest"_attr = dest);
}
// Handle a message intended to configure the mongobridge and return a response.
@@ -304,8 +313,10 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const
switch (hostSettings.state) {
// Close the connection to 'dest'.
case HostSettings::State::kHangUp:
- log() << "Rejecting connection from " << dest << ", end connection "
- << source->remote().toString();
+ LOGV2(22918,
+ "Rejecting connection from {dest}, end connection {source_remote}",
+ "dest"_attr = dest,
+ "source_remote"_attr = source->remote().toString());
source->end();
return {Message()};
// Forward the message to 'dest' with probability '1 - hostSettings.loss'.
@@ -313,12 +324,18 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const
if (dest.nextCanonicalDouble() < hostSettings.loss) {
std::string hostName = dest.toString();
if (cmdRequest) {
- log() << "Discarding \"" << cmdRequest->getCommandName()
- << "\" command with arguments " << cmdRequest->body << " from "
- << hostName;
+ LOGV2(22919,
+ "Discarding \"{cmdRequest_getCommandName}\" command with arguments "
+ "{cmdRequest_body} from {hostName}",
+ "cmdRequest_getCommandName"_attr = cmdRequest->getCommandName(),
+ "cmdRequest_body"_attr = cmdRequest->body,
+ "hostName"_attr = hostName);
} else {
- log() << "Discarding " << networkOpToString(request.operation()) << " from "
- << hostName;
+ LOGV2(22920,
+ "Discarding {networkOpToString_request_operation} from {hostName}",
+ "networkOpToString_request_operation"_attr =
+ networkOpToString(request.operation()),
+ "hostName"_attr = hostName);
}
return {Message()};
}
@@ -351,7 +368,10 @@ DbResponse ServiceEntryPointBridge::handleRequest(OperationContext* opCtx, const
// reply with. If the message handling settings were since changed to close
// connections from 'host', then do so now.
if (hostSettings.state == HostSettings::State::kHangUp) {
- log() << "Closing connection from " << dest << ", end connection " << source->remote();
+ LOGV2(22921,
+ "Closing connection from {dest}, end connection {source_remote}",
+ "dest"_attr = dest,
+ "source_remote"_attr = source->remote());
source->end();
return {Message()};
}
@@ -403,12 +423,12 @@ int bridgeMain(int argc, char** argv, char** envp) {
opts, serviceContext->getServiceEntryPoint()));
auto tl = serviceContext->getTransportLayer();
if (!tl->setup().isOK()) {
- log() << "Error setting up transport layer";
+ LOGV2(22922, "Error setting up transport layer");
return EXIT_NET_ERROR;
}
if (!tl->start().isOK()) {
- log() << "Error starting transport layer";
+ LOGV2(22923, "Error starting transport layer");
return EXIT_NET_ERROR;
}
diff --git a/src/mongo/transport/message_compressor_manager.cpp b/src/mongo/transport/message_compressor_manager.cpp
index 5f0c5cb4d23..a0bbf922112 100644
--- a/src/mongo/transport/message_compressor_manager.cpp
+++ b/src/mongo/transport/message_compressor_manager.cpp
@@ -37,6 +37,7 @@
#include "mongo/base/data_type_endian.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/message.h"
#include "mongo/transport/message_compressor_registry.h"
#include "mongo/transport/session.h"
@@ -95,7 +96,10 @@ StatusWith<Message> MessageCompressorManager::compressMessage(
return {msg};
}
- LOG(3) << "Compressing message with " << compressor->getName();
+ LOGV2_DEBUG(22925,
+ 3,
+ "Compressing message with {compressor_getName}",
+ "compressor_getName"_attr = compressor->getName());
auto inputHeader = msg.header();
size_t bufferSize = compressor->getMaxCompressedSize(msg.dataSize()) +
@@ -105,8 +109,11 @@ StatusWith<Message> MessageCompressorManager::compressMessage(
inputHeader.getNetworkOp(), inputHeader.dataLen(), compressor->getId());
if (bufferSize > MaxMessageSizeBytes) {
- LOG(3) << "Compressed message would be larger than " << MaxMessageSizeBytes
- << ", returning original uncompressed message";
+ LOGV2_DEBUG(22926,
+ 3,
+ "Compressed message would be larger than {MaxMessageSizeBytes}, returning "
+ "original uncompressed message",
+ "MaxMessageSizeBytes"_attr = MaxMessageSizeBytes);
return {msg};
}
@@ -152,7 +159,10 @@ StatusWith<Message> MessageCompressorManager::decompressMessage(const Message& m
*compressorId = compressor->getId();
}
- LOG(3) << "Decompressing message with " << compressor->getName();
+ LOGV2_DEBUG(22927,
+ 3,
+ "Decompressing message with {compressor_getName}",
+ "compressor_getName"_attr = compressor->getName());
if (compressionHeader.uncompressedSize < 0) {
return {ErrorCodes::BadValue, "Decompressed message would be negative in size"};
@@ -191,7 +201,7 @@ StatusWith<Message> MessageCompressorManager::decompressMessage(const Message& m
}
void MessageCompressorManager::clientBegin(BSONObjBuilder* output) {
- LOG(3) << "Starting client-side compression negotiation";
+ LOGV2_DEBUG(22928, 3, "Starting client-side compression negotiation");
// We're about to update the compressor list with the negotiation result from the server.
_negotiated.clear();
@@ -202,7 +212,7 @@ void MessageCompressorManager::clientBegin(BSONObjBuilder* output) {
BSONArrayBuilder sub(output->subarrayStart("compression"));
for (const auto e : _registry->getCompressorNames()) {
- LOG(3) << "Offering " << e << " compressor to server";
+ LOGV2_DEBUG(22929, 3, "Offering {e} compressor to server", "e"_attr = e);
sub.append(e);
}
sub.doneFast();
@@ -210,7 +220,7 @@ void MessageCompressorManager::clientBegin(BSONObjBuilder* output) {
void MessageCompressorManager::clientFinish(const BSONObj& input) {
auto elem = input.getField("compression");
- LOG(3) << "Finishing client-side compression negotiation";
+ LOGV2_DEBUG(22930, 3, "Finishing client-side compression negotiation");
// We've just called clientBegin, so the list of compressors should be empty.
invariant(_negotiated.empty());
@@ -219,22 +229,25 @@ void MessageCompressorManager::clientFinish(const BSONObj& input) {
// supported by this server and just return. We've already disabled compression by clearing
// out the _negotiated array above.
if (elem.eoo()) {
- LOG(3) << "No compression algorithms were sent from the server. "
- << "This connection will be uncompressed";
+ LOGV2_DEBUG(22931,
+ 3,
+ "No compression algorithms were sent from the server. This connection will be "
+ "uncompressed");
return;
}
- LOG(3) << "Received message compressors from server";
+ LOGV2_DEBUG(22932, 3, "Received message compressors from server");
for (const auto& e : elem.Obj()) {
auto algoName = e.checkAndGetStringData();
auto ret = _registry->getCompressor(algoName);
- LOG(3) << "Adding compressor " << ret->getName();
+ LOGV2_DEBUG(
+ 22933, 3, "Adding compressor {ret_getName}", "ret_getName"_attr = ret->getName());
_negotiated.push_back(ret);
}
}
void MessageCompressorManager::serverNegotiate(const BSONObj& input, BSONObjBuilder* output) {
- LOG(3) << "Starting server-side compression negotiation";
+ LOGV2_DEBUG(22934, 3, "Starting server-side compression negotiation");
auto elem = input.getField("compression");
// If the "compression" field is missing, then this isMaster request is requesting information
@@ -250,7 +263,7 @@ void MessageCompressorManager::serverNegotiate(const BSONObj& input, BSONObjBuil
}
sub.doneFast();
} else {
- LOG(3) << "Compression negotiation not requested by client";
+ LOGV2_DEBUG(22935, 3, "Compression negotiation not requested by client");
}
return;
}
@@ -263,7 +276,7 @@ void MessageCompressorManager::serverNegotiate(const BSONObj& input, BSONObjBuil
BSONObj theirObj = elem.Obj();
if (!theirObj.nFields()) {
- LOG(3) << "No compressors provided";
+ LOGV2_DEBUG(22936, 3, "No compressors provided");
return;
}
@@ -273,10 +286,11 @@ void MessageCompressorManager::serverNegotiate(const BSONObj& input, BSONObjBuil
// If the MessageCompressorRegistry knows about a compressor with that name, then it is
// valid and we add it to our list of negotiated compressors.
if ((cur = _registry->getCompressor(curName))) {
- LOG(3) << cur->getName() << " is supported";
+ LOGV2_DEBUG(
+ 22937, 3, "{cur_getName} is supported", "cur_getName"_attr = cur->getName());
_negotiated.push_back(cur);
} else { // Otherwise the compressor is not supported and we skip over it.
- LOG(3) << curName << " is not supported";
+ LOGV2_DEBUG(22938, 3, "{curName} is not supported", "curName"_attr = curName);
}
}
@@ -289,7 +303,7 @@ void MessageCompressorManager::serverNegotiate(const BSONObj& input, BSONObjBuil
}
sub.doneFast();
} else {
- LOG(3) << "Could not agree on compressor to use";
+ LOGV2_DEBUG(22939, 3, "Could not agree on compressor to use");
}
}
diff --git a/src/mongo/transport/service_entry_point_impl.cpp b/src/mongo/transport/service_entry_point_impl.cpp
index 5076b21b9d7..9381e1e7b95 100644
--- a/src/mongo/transport/service_entry_point_impl.cpp
+++ b/src/mongo/transport/service_entry_point_impl.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/auth/restriction_environment.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/service_state_machine.h"
#include "mongo/transport/session.h"
#include "mongo/util/log.h"
@@ -91,8 +92,12 @@ ServiceEntryPointImpl::ServiceEntryPointImpl(ServiceContext* svcCtx) : _svcCtx(s
size_t max = (size_t)(limit.rlim_cur * .8);
- LOG(1) << "fd limit"
- << " hard:" << limit.rlim_max << " soft:" << limit.rlim_cur << " max conn: " << max;
+ LOGV2_DEBUG(22940,
+ 1,
+ "fd limit hard:{limit_rlim_max} soft:{limit_rlim_cur} max conn: {max}",
+ "limit_rlim_max"_attr = limit.rlim_max,
+ "limit_rlim_cur"_attr = limit.rlim_cur,
+ "max"_attr = max);
return std::min(max, serverGlobalParams.maxConns);
#endif
@@ -101,7 +106,9 @@ ServiceEntryPointImpl::ServiceEntryPointImpl(ServiceContext* svcCtx) : _svcCtx(s
// If we asked for more connections than supported, inform the user.
if (supportedMax < serverGlobalParams.maxConns &&
serverGlobalParams.maxConns != DEFAULT_MAX_CONN) {
- log() << " --maxConns too high, can only handle " << supportedMax;
+ LOGV2(22941,
+ " --maxConns too high, can only handle {supportedMax}",
+ "supportedMax"_attr = supportedMax);
}
_maxNumConnections = supportedMax;
@@ -154,7 +161,9 @@ void ServiceEntryPointImpl::startSession(transport::SessionHandle session) {
// while holding it.
if (connectionCount > _maxNumConnections && !usingMaxConnOverride) {
if (!quiet) {
- log() << "connection refused because too many open connections: " << connectionCount;
+ LOGV2(22942,
+ "connection refused because too many open connections: {connectionCount}",
+ "connectionCount"_attr = connectionCount);
}
return;
} else if (usingMaxConnOverride && _adminInternalPool) {
@@ -163,8 +172,13 @@ void ServiceEntryPointImpl::startSession(transport::SessionHandle session) {
if (!quiet) {
const auto word = (connectionCount == 1 ? " connection"_sd : " connections"_sd);
- log() << "connection accepted from " << session->remote() << " #" << session->id() << " ("
- << connectionCount << word << " now open)";
+ LOGV2(22943,
+ "connection accepted from {session_remote} #{session_id} ({connectionCount}{word} "
+ "now open)",
+ "session_remote"_attr = session->remote(),
+ "session_id"_attr = session->id(),
+ "connectionCount"_attr = connectionCount,
+ "word"_attr = word);
}
ssm->setCleanupHook([this, ssmIt, quiet, session = std::move(session)] {
@@ -180,7 +194,11 @@ void ServiceEntryPointImpl::startSession(transport::SessionHandle session) {
if (!quiet) {
const auto word = (connectionCount == 1 ? " connection"_sd : " connections"_sd);
- log() << "end connection " << remote << " (" << connectionCount << word << " now open)";
+ LOGV2(22944,
+ "end connection {remote} ({connectionCount}{word} now open)",
+ "remote"_attr = remote,
+ "connectionCount"_attr = connectionCount,
+ "word"_attr = word);
}
});
@@ -223,17 +241,24 @@ bool ServiceEntryPointImpl::shutdown(Milliseconds timeout) {
auto noWorkersLeft = [this] { return numOpenSessions() == 0; };
while (timeSpent < timeout &&
!_shutdownCondition.wait_for(lk, checkInterval.toSystemDuration(), noWorkersLeft)) {
- log(LogComponent::kNetwork)
- << "shutdown: still waiting on " << numOpenSessions() << " active workers to drain... ";
+ LOGV2_OPTIONS(22945,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "shutdown: still waiting on {numOpenSessions} active workers to drain... ",
+ "numOpenSessions"_attr = numOpenSessions());
timeSpent += checkInterval;
}
bool result = noWorkersLeft();
if (result) {
- log(LogComponent::kNetwork) << "shutdown: no running workers found...";
+ LOGV2_OPTIONS(22946,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "shutdown: no running workers found...");
} else {
- log(LogComponent::kNetwork) << "shutdown: exhausted grace period for" << numOpenSessions()
- << " active workers to drain; continuing with shutdown... ";
+ LOGV2_OPTIONS(22947,
+ {logComponentV1toV2(LogComponent::kNetwork)},
+ "shutdown: exhausted grace period for{numOpenSessions} active workers to "
+ "drain; continuing with shutdown... ",
+ "numOpenSessions"_attr = numOpenSessions());
}
return result;
}
diff --git a/src/mongo/transport/service_entry_point_utils.cpp b/src/mongo/transport/service_entry_point_utils.cpp
index 3db20b7da07..ea273c7564e 100644
--- a/src/mongo/transport/service_entry_point_utils.cpp
+++ b/src/mongo/transport/service_entry_point_utils.cpp
@@ -36,6 +36,7 @@
#include <functional>
#include <memory>
+#include "mongo/logv2/log.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/debug_util.h"
@@ -84,10 +85,12 @@ Status launchServiceWorkerThread(std::function<void()> task) {
int failed = pthread_attr_setstacksize(&attrs, stackSizeToSet);
if (failed) {
const auto ewd = errnoWithDescription(failed);
- warning() << "pthread_attr_setstacksize failed: " << ewd;
+ LOGV2_WARNING(22949, "pthread_attr_setstacksize failed: {ewd}", "ewd"_attr = ewd);
}
} else if (limits.rlim_cur < 1024 * 1024) {
- warning() << "Stack size set to " << (limits.rlim_cur / 1024) << "KB. We suggest 1MB";
+ LOGV2_WARNING(22950,
+ "Stack size set to {limits_rlim_cur_1024}KB. We suggest 1MB",
+ "limits_rlim_cur_1024"_attr = (limits.rlim_cur / 1024));
}
// Wrap the user-specified `task` so it runs with an installed `sigaltstack`.
@@ -104,7 +107,9 @@ Status launchServiceWorkerThread(std::function<void()> task) {
pthread_attr_destroy(&attrs);
if (failed) {
- log() << "pthread_create failed: " << errnoWithDescription(failed);
+ LOGV2(22948,
+ "pthread_create failed: {errnoWithDescription_failed}",
+ "errnoWithDescription_failed"_attr = errnoWithDescription(failed));
throw std::system_error(
std::make_error_code(std::errc::resource_unavailable_try_again));
}
diff --git a/src/mongo/transport/service_executor_adaptive.cpp b/src/mongo/transport/service_executor_adaptive.cpp
index 32e8ef9b8b0..b43635df36c 100644
--- a/src/mongo/transport/service_executor_adaptive.cpp
+++ b/src/mongo/transport/service_executor_adaptive.cpp
@@ -36,6 +36,7 @@
#include <array>
#include <random>
+#include "mongo/logv2/log.h"
#include "mongo/transport/service_entry_point_utils.h"
#include "mongo/transport/service_executor_gen.h"
#include "mongo/transport/service_executor_task_names.h"
@@ -79,8 +80,9 @@ struct ServerParameterOptions : public ServiceExecutorAdaptive::Options {
value = ProcessInfo::getNumAvailableCores() / 2;
value = std::max(value, 2);
adaptiveServiceExecutorReservedThreads.store(value);
- log() << "No thread count configured for executor. Using number of cores / 2: "
- << value;
+ LOGV2(22951,
+ "No thread count configured for executor. Using number of cores / 2: {value}",
+ "value"_attr = value);
}
return value;
}
@@ -101,9 +103,12 @@ struct ServerParameterOptions : public ServiceExecutorAdaptive::Options {
static Nanoseconds minTimerResolution = getMinimumTimerResolution();
Microseconds value{adaptiveServiceExecutorMaxQueueLatencyMicros.load()};
if (value < minTimerResolution) {
- log() << "Target MaxQueueLatencyMicros (" << value
- << ") is less than minimum timer resolution of OS (" << minTimerResolution
- << "). Using " << minTimerResolution;
+ LOGV2(22952,
+ "Target MaxQueueLatencyMicros ({value}) is less than minimum timer resolution of "
+ "OS ({minTimerResolution}). Using {minTimerResolution2}",
+ "value"_attr = value,
+ "minTimerResolution"_attr = minTimerResolution,
+ "minTimerResolution2"_attr = minTimerResolution);
value = duration_cast<Microseconds>(minTimerResolution) + Microseconds{1};
adaptiveServiceExecutorMaxQueueLatencyMicros.store(value.count());
}
@@ -350,9 +355,10 @@ void ServiceExecutorAdaptive::_controllerThreadRoutine() {
// thread to unblock the executor for now.
stuckThreadTimeout /= 2;
stuckThreadTimeout = std::max(Milliseconds{10}, stuckThreadTimeout);
- log() << "Detected blocked worker threads, "
- << "starting new thread to unblock service executor. "
- << "Stuck thread timeout now: " << stuckThreadTimeout;
+ LOGV2(22953,
+ "Detected blocked worker threads, starting new thread to unblock service "
+ "executor. Stuck thread timeout now: {stuckThreadTimeout}",
+ "stuckThreadTimeout"_attr = stuckThreadTimeout);
_startWorkerThread(ThreadCreationReason::kStuckDetection);
// Since we've just started a worker thread, then we know that the executor isn't
@@ -365,15 +371,21 @@ void ServiceExecutorAdaptive::_controllerThreadRoutine() {
auto newStuckThreadTimeout = stuckThreadTimeout + (stuckThreadTimeout / 2);
newStuckThreadTimeout = std::min(_config->stuckThreadTimeout(), newStuckThreadTimeout);
if (newStuckThreadTimeout != stuckThreadTimeout) {
- LOG(1) << "Increasing stuck thread timeout to " << newStuckThreadTimeout;
+ LOGV2_DEBUG(22954,
+ 1,
+ "Increasing stuck thread timeout to {newStuckThreadTimeout}",
+ "newStuckThreadTimeout"_attr = newStuckThreadTimeout);
stuckThreadTimeout = newStuckThreadTimeout;
}
}
auto threadsRunning = _threadsRunning.load();
if (threadsRunning < _config->reservedThreads()) {
- log() << "Starting " << _config->reservedThreads() - threadsRunning
- << " to replenish reserved worker threads";
+ LOGV2(22955,
+ "Starting {config_reservedThreads_threadsRunning} to replenish reserved worker "
+ "threads",
+ "config_reservedThreads_threadsRunning"_attr =
+ _config->reservedThreads() - threadsRunning);
while (_threadsRunning.load() < _config->reservedThreads()) {
_startWorkerThread(ThreadCreationReason::kReserveMinimum);
}
@@ -421,7 +433,7 @@ void ServiceExecutorAdaptive::_controllerThreadRoutine() {
// number of tasks executing (the number of free threads), then start a new worker to
// avoid starvation.
if (_isStarved()) {
- log() << "Starting worker thread to avoid starvation.";
+ LOGV2(22956, "Starting worker thread to avoid starvation.");
_startWorkerThread(ThreadCreationReason::kStarvation);
}
}
@@ -442,7 +454,9 @@ void ServiceExecutorAdaptive::_startWorkerThread(ThreadCreationReason reason) {
launchServiceWorkerThread([this, num, it] { _workerThreadRoutine(num, it); });
if (!launchResult.isOK()) {
- warning() << "Failed to launch new worker thread: " << launchResult;
+ LOGV2_WARNING(22959,
+ "Failed to launch new worker thread: {launchResult}",
+ "launchResult"_attr = launchResult);
lk.lock();
_threadsPending.subtractAndFetch(1);
_threadsRunning.subtractAndFetch(1);
@@ -528,7 +542,7 @@ void ServiceExecutorAdaptive::_workerThreadRoutine(
setThreadName(threadName);
}
- log() << "Started new database worker thread " << threadId;
+ LOGV2(22957, "Started new database worker thread {threadId}", "threadId"_attr = threadId);
bool guardThreadsRunning = true;
const auto guard = makeGuard([this, &guardThreadsRunning, state] {
@@ -605,8 +619,11 @@ void ServiceExecutorAdaptive::_workerThreadRoutine(
} while (terminateThread &&
!_threadsRunning.compareAndSwap(&runningThreads, runningThreads - 1));
if (terminateThread) {
- log() << "Thread was only executing tasks " << pctExecuting << "% over the last "
- << runTime << ". Exiting thread.";
+ LOGV2(22958,
+ "Thread was only executing tasks {pctExecuting}% over the last {runTime}. "
+ "Exiting thread.",
+ "pctExecuting"_attr = pctExecuting,
+ "runTime"_attr = runTime);
// Because we've already modified _threadsRunning, make sure the thread guard also
// doesn't do it.
diff --git a/src/mongo/transport/service_executor_adaptive_test.cpp b/src/mongo/transport/service_executor_adaptive_test.cpp
index f30679b408b..d2bce821868 100644
--- a/src/mongo/transport/service_executor_adaptive_test.cpp
+++ b/src/mongo/transport/service_executor_adaptive_test.cpp
@@ -34,6 +34,7 @@
#include "boost/optional.hpp"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/service_executor_adaptive.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -122,7 +123,7 @@ protected:
invariant(waitFor.load() != -1);
waitFor.fetchAndSubtract(1);
cond.notify_one();
- log() << "Ran callback";
+ LOGV2(22960, "Ran callback");
};
void waitForCallback(int expected, boost::optional<Milliseconds> timeout = boost::none) {
@@ -146,7 +147,7 @@ protected:
getGlobalServiceContext(), asioIoCtx, std::move(configOwned));
ASSERT_OK(exec->start());
- log() << "wait for executor to finish starting";
+ LOGV2(22961, "wait for executor to finish starting");
waitFor.store(1);
ASSERT_OK(exec->schedule(notifyCallback,
ServiceExecutor::kEmptyFlags,
@@ -173,7 +174,7 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestStuckTask) {
ASSERT_OK(exec->shutdown(config->workerThreadRunTime() * 2));
});
- log() << "Scheduling blocked task";
+ LOGV2(22962, "Scheduling blocked task");
waitFor.store(3);
ASSERT_OK(exec->schedule(
[this, &blockedMutex] {
@@ -184,20 +185,20 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestStuckTask) {
ServiceExecutor::kEmptyFlags,
ServiceExecutorTaskName::kSSMProcessMessage));
- log() << "Scheduling task stuck on blocked task";
+ LOGV2(22963, "Scheduling task stuck on blocked task");
ASSERT_OK(exec->schedule(
notifyCallback, ServiceExecutor::kEmptyFlags, ServiceExecutorTaskName::kSSMProcessMessage));
- log() << "Waiting for second thread to start";
+ LOGV2(22964, "Waiting for second thread to start");
waitForCallback(1);
ASSERT_EQ(exec->threadsRunning(), 2);
- log() << "Waiting for unstuck task to run";
+ LOGV2(22965, "Waiting for unstuck task to run");
blockedLock.unlock();
waitForCallback(0);
ASSERT_EQ(exec->threadsRunning(), 2);
- log() << "Waiting for second thread to idle out";
+ LOGV2(22966, "Waiting for second thread to idle out");
stdx::this_thread::sleep_for(config->workerThreadRunTime().toSystemDuration() * 1.5);
ASSERT_EQ(exec->threadsRunning(), config->reservedThreads());
}
@@ -219,7 +220,7 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestStuckThreads) {
});
auto blockedTask = [this, &blockedMutex] {
- log() << "waiting on blocked mutex";
+ LOGV2(22967, "waiting on blocked mutex");
notifyCallback();
stdx::unique_lock<Latch> lk(blockedMutex);
notifyCallback();
@@ -227,17 +228,17 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestStuckThreads) {
waitFor.store(6);
auto tasks = waitFor.load() / 2;
- log() << "Scheduling " << tasks << " blocked tasks";
+ LOGV2(22968, "Scheduling {tasks} blocked tasks", "tasks"_attr = tasks);
for (auto i = 0; i < tasks; i++) {
ASSERT_OK(exec->schedule(blockedTask,
ServiceExecutor::kEmptyFlags,
ServiceExecutorTaskName::kSSMProcessMessage));
}
- log() << "Waiting for executor to start new threads";
+ LOGV2(22969, "Waiting for executor to start new threads");
waitForCallback(3);
- log() << "All threads blocked, wait for executor to detect block and start a new thread.";
+ LOGV2(22970, "All threads blocked, wait for executor to detect block and start a new thread.");
// The controller thread in the adaptive executor runs on a stuckThreadTimeout in normal
// operation where no starvation is detected (shouldn't be in this test as all threads should be
@@ -247,7 +248,7 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestStuckThreads) {
ASSERT_EQ(exec->threadsRunning(), waitFor.load() + config->reservedThreads());
- log() << "Waiting for unstuck task to run";
+ LOGV2(22971, "Waiting for unstuck task to run");
blockedLock.unlock();
waitForCallback(0);
}
@@ -318,12 +319,12 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestRecursion) {
task = [this, &task, &exec, &mutex, &cv, &remainingTasks] {
if (remainingTasks.subtractAndFetch(1) == 0) {
- log() << "Signaling job done";
+ LOGV2(22972, "Signaling job done");
cv.notify_one();
return;
}
- log() << "Starting task recursively";
+ LOGV2(22973, "Starting task recursively");
ASSERT_OK(exec->schedule(
task, ServiceExecutor::kMayRecurse, ServiceExecutorTaskName::kSSMProcessMessage));
@@ -331,7 +332,7 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestRecursion) {
// Make sure we don't block too long because then the block detection logic would kick in.
stdx::this_thread::sleep_for(config->stuckThreadTimeout().toSystemDuration() /
(config->recursionLimit() * 2));
- log() << "Completing task recursively";
+ LOGV2(22974, "Completing task recursively");
};
stdx::unique_lock<Latch> lock(mutex);
@@ -363,7 +364,7 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestDeferredTasks) {
});
waitFor.store(3);
- log() << "Scheduling a blocking task";
+ LOGV2(22975, "Scheduling a blocking task");
ASSERT_OK(exec->schedule(
[this, &blockedMutex] {
stdx::unique_lock<Latch> lk(blockedMutex);
@@ -372,7 +373,7 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestDeferredTasks) {
ServiceExecutor::kEmptyFlags,
ServiceExecutorTaskName::kSSMProcessMessage));
- log() << "Scheduling deferred task";
+ LOGV2(22976, "Scheduling deferred task");
ASSERT_OK(exec->schedule(notifyCallback,
ServiceExecutor::kDeferredTask,
ServiceExecutorTaskName::kSSMProcessMessage));
@@ -380,7 +381,7 @@ TEST_F(ServiceExecutorAdaptiveFixture, TestDeferredTasks) {
ASSERT_THROWS(waitForCallback(1, config->stuckThreadTimeout()),
unittest::TestAssertionFailureException);
- log() << "Scheduling non-deferred task";
+ LOGV2(22977, "Scheduling non-deferred task");
ASSERT_OK(exec->schedule(
notifyCallback, ServiceExecutor::kEmptyFlags, ServiceExecutorTaskName::kSSMProcessMessage));
waitForCallback(1, config->stuckThreadTimeout());
diff --git a/src/mongo/transport/service_executor_reserved.cpp b/src/mongo/transport/service_executor_reserved.cpp
index 6dba2bafc39..af114738ce7 100644
--- a/src/mongo/transport/service_executor_reserved.cpp
+++ b/src/mongo/transport/service_executor_reserved.cpp
@@ -33,6 +33,7 @@
#include "mongo/transport/service_executor_reserved.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/thread.h"
#include "mongo/transport/service_entry_point_utils.h"
#include "mongo/transport/service_executor_gen.h"
@@ -78,7 +79,7 @@ Status ServiceExecutorReserved::start() {
}
Status ServiceExecutorReserved::_startWorker() {
- log() << "Starting new worker thread for " << _name << " service executor";
+ LOGV2(22978, "Starting new worker thread for {name} service executor", "name"_attr = _name);
return launchServiceWorkerThread([this] {
stdx::unique_lock<Latch> lk(_mutex);
_numRunningWorkerThreads.addAndFetch(1);
@@ -115,7 +116,9 @@ Status ServiceExecutorReserved::_startWorker() {
if (launchReplacement) {
auto threadStartStatus = _startWorker();
if (!threadStartStatus.isOK()) {
- warning() << "Could not start new reserve worker thread: " << threadStartStatus;
+ LOGV2_WARNING(22981,
+ "Could not start new reserve worker thread: {threadStartStatus}",
+ "threadStartStatus"_attr = threadStartStatus);
}
}
@@ -134,13 +137,14 @@ Status ServiceExecutorReserved::_startWorker() {
}
}
- LOG(3) << "Exiting worker thread in " << _name << " service executor";
+ LOGV2_DEBUG(
+ 22979, 3, "Exiting worker thread in {name} service executor", "name"_attr = _name);
});
}
Status ServiceExecutorReserved::shutdown(Milliseconds timeout) {
- LOG(3) << "Shutting down reserved executor";
+ LOGV2_DEBUG(22980, 3, "Shutting down reserved executor");
stdx::unique_lock<Latch> lock(_mutex);
_stillRunning.store(false);
diff --git a/src/mongo/transport/service_executor_synchronous.cpp b/src/mongo/transport/service_executor_synchronous.cpp
index 8fe383768e2..91cdf907b60 100644
--- a/src/mongo/transport/service_executor_synchronous.cpp
+++ b/src/mongo/transport/service_executor_synchronous.cpp
@@ -33,6 +33,7 @@
#include "mongo/transport/service_executor_synchronous.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/thread.h"
#include "mongo/transport/service_entry_point_utils.h"
#include "mongo/transport/service_executor_gen.h"
@@ -63,7 +64,7 @@ Status ServiceExecutorSynchronous::start() {
}
Status ServiceExecutorSynchronous::shutdown(Milliseconds timeout) {
- LOG(3) << "Shutting down passthrough executor";
+ LOGV2_DEBUG(22982, 3, "Shutting down passthrough executor");
_stillRunning.store(false);
@@ -113,7 +114,7 @@ Status ServiceExecutorSynchronous::schedule(Task task,
// First call to schedule() for this connection, spawn a worker thread that will push jobs
// into the thread local job queue.
- LOG(3) << "Starting new executor thread in passthrough mode";
+ LOGV2_DEBUG(22983, 3, "Starting new executor thread in passthrough mode");
Status status = launchServiceWorkerThread([this, task = std::move(task)] {
_numRunningWorkerThreads.addAndFetch(1);
diff --git a/src/mongo/transport/service_executor_test.cpp b/src/mongo/transport/service_executor_test.cpp
index 645752d90d0..af4e8ca7b49 100644
--- a/src/mongo/transport/service_executor_test.cpp
+++ b/src/mongo/transport/service_executor_test.cpp
@@ -34,6 +34,7 @@
#include "boost/optional.hpp"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/service_executor_adaptive.h"
#include "mongo/transport/service_executor_synchronous.h"
#include "mongo/transport/service_executor_task_names.h"
@@ -102,7 +103,9 @@ public:
try {
_ioContext.run_for(time.toSystemDuration());
} catch (...) {
- severe() << "Uncaught exception in reactor: " << exceptionToStatus();
+ LOGV2_FATAL(22985,
+ "Uncaught exception in reactor: {exceptionToStatus}",
+ "exceptionToStatus"_attr = exceptionToStatus());
fassertFailed(50476);
}
}
@@ -114,7 +117,7 @@ public:
void drain() override final {
_ioContext.restart();
while (_ioContext.poll()) {
- LOG(1) << "Draining remaining work in reactor.";
+ LOGV2_DEBUG(22984, 1, "Draining remaining work in reactor.");
}
_ioContext.stop();
}
diff --git a/src/mongo/transport/service_state_machine.cpp b/src/mongo/transport/service_state_machine.cpp
index 4ca997d96ed..041d2fdb715 100644
--- a/src/mongo/transport/service_state_machine.cpp
+++ b/src/mongo/transport/service_state_machine.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/dbmessage.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/traffic_recorder.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/message.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/transport/message_compressor_manager.h"
@@ -375,16 +376,27 @@ void ServiceStateMachine::_sourceCallback(Status status) {
transport::ServiceExecutorTaskName::kSSMProcessMessage);
} else if (ErrorCodes::isInterruption(status.code()) ||
ErrorCodes::isNetworkError(status.code())) {
- LOG(2) << "Session from " << remote
- << " encountered a network error during SourceMessage: " << status;
+ LOGV2_DEBUG(
+ 22986,
+ 2,
+ "Session from {remote} encountered a network error during SourceMessage: {status}",
+ "remote"_attr = remote,
+ "status"_attr = status);
_state.store(State::EndSession);
} else if (status == TransportLayer::TicketSessionClosedStatus) {
// Our session may have been closed internally.
- LOG(2) << "Session from " << remote << " was closed internally during SourceMessage";
+ LOGV2_DEBUG(22987,
+ 2,
+ "Session from {remote} was closed internally during SourceMessage",
+ "remote"_attr = remote);
_state.store(State::EndSession);
} else {
- log() << "Error receiving request from client: " << status << ". Ending connection from "
- << remote << " (connection id: " << _session()->id() << ")";
+ LOGV2(22988,
+ "Error receiving request from client: {status}. Ending connection from {remote} "
+ "(connection id: {session_id})",
+ "status"_attr = status,
+ "remote"_attr = remote,
+ "session_id"_attr = _session()->id());
_state.store(State::EndSession);
}
@@ -406,8 +418,12 @@ void ServiceStateMachine::_sinkCallback(Status status) {
// Otherwise, update the current state depending on whether we're in exhaust or not, and call
// scheduleNext() to unwind the stack and do the next step.
if (!status.isOK()) {
- log() << "Error sending response to client: " << status << ". Ending connection from "
- << _session()->remote() << " (connection id: " << _session()->id() << ")";
+ LOGV2(22989,
+ "Error sending response to client: {status}. Ending connection from {session_remote} "
+ "(connection id: {session_id})",
+ "status"_attr = status,
+ "session_remote"_attr = _session()->remote(),
+ "session_id"_attr = _session()->id());
_state.store(State::EndSession);
return _runNextInGuard(std::move(guard));
} else if (_inExhaust) {
@@ -540,7 +556,9 @@ void ServiceStateMachine::_runNextInGuard(ThreadGuard guard) {
return;
} catch (const DBException& e) {
- log() << "DBException handling request, closing client connection: " << redact(e);
+ LOGV2(22990,
+ "DBException handling request, closing client connection: {e}",
+ "e"_attr = redact(e));
}
// No need to catch std::exception, as std::terminate will be called when the exception bubbles
// to the top of the stack
@@ -604,7 +622,9 @@ void ServiceStateMachine::terminateIfTagsDontMatch(transport::Session::TagMask t
// If terminateIfTagsDontMatch gets called when we still are 'pending' where no tags have been
// set, then skip the termination check.
if ((sessionTags & tags) || (sessionTags & transport::Session::kPending)) {
- log() << "Skip closing connection for connection # " << _session()->id();
+ LOGV2(22991,
+ "Skip closing connection for connection # {session_id}",
+ "session_id"_attr = _session()->id());
return;
}
@@ -622,7 +642,10 @@ ServiceStateMachine::State ServiceStateMachine::state() {
void ServiceStateMachine::_terminateAndLogIfError(Status status) {
if (!status.isOK()) {
- warning(logger::LogComponent::kExecutor) << "Terminating session due to error: " << status;
+ LOGV2_WARNING_OPTIONS(22993,
+ {logComponentV1toV2(logger::LogComponent::kExecutor)},
+ "Terminating session due to error: {status}",
+ "status"_attr = status);
terminate();
}
}
@@ -642,7 +665,9 @@ void ServiceStateMachine::_cleanupExhaustResources() noexcept try {
_sep->handleRequest(opCtx.get(), makeKillCursorsMessage(cursorId));
}
} catch (const DBException& e) {
- log() << "Error cleaning up resources for exhaust requests: " << e.toStatus();
+ LOGV2(22992,
+ "Error cleaning up resources for exhaust requests: {e_toStatus}",
+ "e_toStatus"_attr = e.toStatus());
}
void ServiceStateMachine::_cleanupSession(ThreadGuard guard) {
diff --git a/src/mongo/transport/service_state_machine_test.cpp b/src/mongo/transport/service_state_machine_test.cpp
index caf064f91c6..3373f2ece2a 100644
--- a/src/mongo/transport/service_state_machine_test.cpp
+++ b/src/mongo/transport/service_state_machine_test.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/client.h"
#include "mongo/db/dbmessage.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/transport/mock_session.h"
#include "mongo/transport/service_entry_point.h"
@@ -73,7 +74,7 @@ public:
void startSession(transport::SessionHandle session) override {}
DbResponse handleRequest(OperationContext* opCtx, const Message& request) override {
- log() << "In handleRequest";
+ LOGV2(22994, "In handleRequest");
_ranHandler = true;
ASSERT_TRUE(haveClient());
@@ -152,7 +153,7 @@ public:
tl->_lastTicketSource = true;
tl->_ranSource = true;
- log() << "In sourceMessage";
+ LOGV2(22995, "In sourceMessage");
if (tl->_waitHook)
tl->_waitHook();
@@ -176,7 +177,7 @@ public:
ASSERT_EQ(tl->_ssm->state(), ServiceStateMachine::State::SinkWait);
tl->_lastTicketSource = false;
- log() << "In sinkMessage";
+ LOGV2(22996, "In sinkMessage");
tl->_ranSink = true;
if (tl->_waitHook)
@@ -365,7 +366,7 @@ protected:
void ServiceStateMachineFixture::runPingTest(State first, State second) {
ASSERT_FALSE(haveClient());
ASSERT_EQ(_ssm->state(), State::Created);
- log() << "run next";
+ LOGV2(22997, "run next");
_ssm->runNext();
ASSERT_EQ(_ssm->state(), first);
@@ -382,7 +383,7 @@ void ServiceStateMachineFixture::sourceAndSink(State afterSource, State afterSin
invariant(_ssm->state() == State::Source || _ssm->state() == State::Created);
// Source a new message from the network.
- log() << "(sourceAndSink) runNext to source a message";
+ LOGV2(22998, "(sourceAndSink) runNext to source a message");
_ssm->runNext();
ASSERT_TRUE(_tl->ranSource());
ASSERT_EQ(_ssm->state(), afterSource);
@@ -390,7 +391,7 @@ void ServiceStateMachineFixture::sourceAndSink(State afterSource, State afterSin
// Let the message be processed by sending it to the database, receiving the response, and then
// sinking it.
- log() << "(sourceAndSink) runNext to process and sink the response message";
+ LOGV2(22999, "(sourceAndSink) runNext to process and sink the response message");
_ssm->runNext();
ASSERT_FALSE(haveClient());
ASSERT_TRUE(_tl->ranSink());
@@ -474,7 +475,7 @@ TEST_F(ServiceStateMachineFixture, TestGetMoreWithExhaust) {
// terminal getMore, indicating that the exhaust stream should be ended.
_sep->setResponseMessage(getMoreTerminalRes);
- log() << "runNext to terminate the exhaust stream";
+ LOGV2(23000, "runNext to terminate the exhaust stream");
_ssm->runNext();
ASSERT_FALSE(haveClient());
ASSERT_EQ(_ssm->state(), State::Source);
@@ -560,7 +561,7 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStates) {
SimpleEvent hookRan, okayToContinue;
auto cleanupHook = [&hookRan] {
- log() << "Cleaning up session";
+ LOGV2(23001, "Cleaning up session");
hookRan.signal();
};
@@ -569,8 +570,10 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStates) {
State waitFor = State::Created;
SimpleEvent atDesiredState;
auto waitForHook = [this, &waitFor, &atDesiredState, &okayToContinue]() {
- log() << "Checking for wakeup at " << stateToString(_ssm->state()) << ". Expecting "
- << stateToString(waitFor);
+ LOGV2(23002,
+ "Checking for wakeup at {stateToString_ssm_state}. Expecting {stateToString_waitFor}",
+ "stateToString_ssm_state"_attr = stateToString(_ssm->state()),
+ "stateToString_waitFor"_attr = stateToString(waitFor));
if (_ssm->state() == waitFor) {
atDesiredState.signal();
okayToContinue.wait();
@@ -589,7 +592,9 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStates) {
// Run this same test for each state.
auto states = {State::Source, State::SourceWait, State::Process, State::SinkWait};
for (const auto testState : states) {
- log() << "Testing termination during " << stateToString(testState);
+ LOGV2(23003,
+ "Testing termination during {stateToString_testState}",
+ "stateToString_testState"_attr = stateToString(testState));
// Reset the _ssm to a fresh SSM and reset our tracking variables.
_ssm = ServiceStateMachine::create(
@@ -607,7 +612,9 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStates) {
// Wait for the SSM to advance to the expected state
atDesiredState.wait();
- log() << "Terminating session at " << stateToString(_ssm->state());
+ LOGV2(23004,
+ "Terminating session at {stateToString_ssm_state}",
+ "stateToString_ssm_state"_attr = stateToString(_ssm->state()));
// Terminate the SSM
_ssm->terminate();
@@ -634,7 +641,7 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStatesWithScheduleFailure
bool scheduleFailed = false;
auto cleanupHook = [&hookRan] {
- log() << "Cleaning up session";
+ LOGV2(23005, "Cleaning up session");
hookRan.signal();
};
@@ -643,8 +650,10 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStatesWithScheduleFailure
State waitFor = State::Created;
SimpleEvent atDesiredState;
auto waitForHook = [this, &waitFor, &scheduleFailed, &okayToContinue, &atDesiredState]() {
- log() << "Checking for wakeup at " << stateToString(_ssm->state()) << ". Expecting "
- << stateToString(waitFor);
+ LOGV2(23006,
+ "Checking for wakeup at {stateToString_ssm_state}. Expecting {stateToString_waitFor}",
+ "stateToString_ssm_state"_attr = stateToString(_ssm->state()),
+ "stateToString_waitFor"_attr = stateToString(waitFor));
if (_ssm->state() == waitFor) {
atDesiredState.signal();
okayToContinue.wait();
@@ -660,7 +669,9 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStatesWithScheduleFailure
auto states = {State::Source, State::SourceWait, State::Process, State::SinkWait};
for (const auto testState : states) {
- log() << "Testing termination during " << stateToString(testState);
+ LOGV2(23007,
+ "Testing termination during {stateToString_testState}",
+ "stateToString_testState"_attr = stateToString(testState));
_ssm = ServiceStateMachine::create(
getGlobalServiceContext(), _tl->createSession(), transport::Mode::kSynchronous);
_tl->setSSM(_ssm.get());
@@ -678,7 +689,9 @@ TEST_F(ServiceStateMachineFixture, TerminateWorksForAllStatesWithScheduleFailure
// Wait for the SSM to advance to the expected state
atDesiredState.wait();
ASSERT_EQ(_ssm->state(), testState);
- log() << "Terminating session at " << stateToString(_ssm->state());
+ LOGV2(23008,
+ "Terminating session at {stateToString_ssm_state}",
+ "stateToString_ssm_state"_attr = stateToString(_ssm->state()));
// Terminate the SSM
_ssm->terminate();
@@ -708,7 +721,9 @@ TEST_F(ServiceStateMachineFixture, SSMRunsRecursively) {
// The scheduleHook just runs the task, effectively making this a recursive executor.
int recursionDepth = 0;
_sexec->setScheduleHook([&recursionDepth](auto task) {
- log() << "running task in executor. depth: " << ++recursionDepth;
+ LOGV2(23009,
+ "running task in executor. depth: {recursionDepth}",
+ "recursionDepth"_attr = ++recursionDepth);
task();
return true;
});
diff --git a/src/mongo/transport/transport_layer_asio.cpp b/src/mongo/transport/transport_layer_asio.cpp
index 839d9e50d28..165079ad0af 100644
--- a/src/mongo/transport/transport_layer_asio.cpp
+++ b/src/mongo/transport/transport_layer_asio.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
#include "mongo/db/stats/counters.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/asio_utils.h"
#include "mongo/transport/service_entry_point.h"
#include "mongo/transport/transport_options_gen.h"
@@ -112,7 +113,7 @@ public:
void cancel(const BatonHandle& baton = nullptr) override {
// If we have a baton try to cancel that.
if (baton && baton->networking() && baton->networking()->cancelTimer(*this)) {
- LOG(2) << "Canceled via baton, skipping asio cancel.";
+ LOGV2_DEBUG(23010, 2, "Canceled via baton, skipping asio cancel.");
return;
}
@@ -139,7 +140,7 @@ private:
armTimer();
return _timer->async_wait(UseFuture{}).tapError([timer = _timer](const Status& status) {
if (status != ErrorCodes::CallbackCanceled) {
- LOG(2) << "Timer received error: " << status;
+ LOGV2_DEBUG(23011, 2, "Timer received error: {status}", "status"_attr = status);
}
});
@@ -191,7 +192,7 @@ public:
ThreadIdGuard threadIdGuard(this);
_ioContext.restart();
while (_ioContext.poll()) {
- LOG(2) << "Draining remaining work in reactor.";
+ LOGV2_DEBUG(23012, 2, "Draining remaining work in reactor.");
}
_ioContext.stop();
}
@@ -617,8 +618,11 @@ Future<SessionHandle> TransportLayerASIO::asyncConnect(HostAndPort peer,
try {
Date_t timeAfter = Date_t::now();
if (timeAfter - timeBefore > Seconds(1)) {
- warning() << "DNS resolution while connecting to " << connector->peer
- << " took " << timeAfter - timeBefore;
+ LOGV2_WARNING(23019,
+ "DNS resolution while connecting to {connector_peer} took "
+ "{timeAfter_timeBefore}",
+ "connector_peer"_attr = connector->peer,
+ "timeAfter_timeBefore"_attr = timeAfter - timeBefore);
}
stdx::lock_guard<Latch> lk(connector->mutex);
@@ -667,7 +671,7 @@ Future<SessionHandle> TransportLayerASIO::asyncConnect(HostAndPort peer,
})
.getAsync([connector](Status connectResult) {
if (MONGO_unlikely(transportLayerASIOasyncConnectTimesOut.shouldFail())) {
- log() << "asyncConnectTimesOut fail point is active. simulating timeout.";
+ LOGV2(23013, "asyncConnectTimesOut fail point is active. simulating timeout.");
return;
}
@@ -805,7 +809,7 @@ Status TransportLayerASIO::setup() {
if (tcpFastOpenIsConfigured) {
return foStatus;
} else {
- log() << foStatus.reason();
+ LOGV2(23014, "{foStatus_reason}", "foStatus_reason"_attr = foStatus.reason());
}
}
@@ -821,14 +825,16 @@ Status TransportLayerASIO::setup() {
std::set<WrappedEndpoint> endpoints;
for (auto& ip : listenAddrs) {
if (ip.empty()) {
- warning() << "Skipping empty bind address";
+ LOGV2_WARNING(23020, "Skipping empty bind address");
continue;
}
auto swAddrs =
resolver.resolve(HostAndPort(ip, _listenerPort), _listenerOptions.enableIPv6);
if (!swAddrs.isOK()) {
- warning() << "Found no addresses for " << swAddrs.getStatus();
+ LOGV2_WARNING(23021,
+ "Found no addresses for {swAddrs_getStatus}",
+ "swAddrs_getStatus"_attr = swAddrs.getStatus());
continue;
}
auto& addrs = swAddrs.getValue();
@@ -839,14 +845,17 @@ Status TransportLayerASIO::setup() {
#ifndef _WIN32
if (addr.family() == AF_UNIX) {
if (::unlink(addr.toString().c_str()) == -1 && errno != ENOENT) {
- error() << "Failed to unlink socket file " << addr.toString().c_str() << " "
- << errnoWithDescription(errno);
+ LOGV2_ERROR(
+ 23024,
+ "Failed to unlink socket file {addr_c_str} {errnoWithDescription_errno}",
+ "addr_c_str"_attr = addr.toString().c_str(),
+ "errnoWithDescription_errno"_attr = errnoWithDescription(errno));
fassertFailedNoTrace(40486);
}
}
#endif
if (addr.family() == AF_INET6 && !_listenerOptions.enableIPv6) {
- error() << "Specified ipv6 bind address, but ipv6 is disabled";
+ LOGV2_ERROR(23025, "Specified ipv6 bind address, but ipv6 is disabled");
fassertFailedNoTrace(40488);
}
@@ -881,8 +890,10 @@ Status TransportLayerASIO::setup() {
#ifndef _WIN32
if (addr.family() == AF_UNIX) {
if (::chmod(addr.toString().c_str(), serverGlobalParams.unixSocketPermissions) == -1) {
- error() << "Failed to chmod socket file " << addr.toString().c_str() << " "
- << errnoWithDescription(errno);
+ LOGV2_ERROR(23026,
+ "Failed to chmod socket file {addr_c_str} {errnoWithDescription_errno}",
+ "addr_c_str"_attr = addr.toString().c_str(),
+ "errnoWithDescription_errno"_attr = errnoWithDescription(errno));
fassertFailedNoTrace(40487);
}
}
@@ -950,13 +961,17 @@ void TransportLayerASIO::_runListener() noexcept {
asio::error_code ec;
acceptor.second.listen(serverGlobalParams.listenBacklog, ec);
if (ec) {
- severe() << "Error listening for new connections on " << acceptor.first << ": "
- << ec.message();
+ LOGV2_FATAL(23027,
+ "Error listening for new connections on {acceptor_first}: {ec_message}",
+ "acceptor_first"_attr = acceptor.first,
+ "ec_message"_attr = ec.message());
fassertFailed(31339);
}
_acceptConnection(acceptor.second);
- log() << "Listening on " << acceptor.first.getAddr();
+ LOGV2(23015,
+ "Listening on {acceptor_first_getAddr}",
+ "acceptor_first_getAddr"_attr = acceptor.first.getAddr());
}
const char* ssl = "";
@@ -965,7 +980,10 @@ void TransportLayerASIO::_runListener() noexcept {
ssl = " ssl";
}
#endif
- log() << "waiting for connections on port " << _listenerPort << ssl;
+ LOGV2(23016,
+ "waiting for connections on port {listenerPort}{ssl}",
+ "listenerPort"_attr = _listenerPort,
+ "ssl"_attr = ssl);
_listener.active = true;
_listener.cv.notify_all();
@@ -987,10 +1005,13 @@ void TransportLayerASIO::_runListener() noexcept {
auto& addr = acceptor.first;
if (addr.getType() == AF_UNIX && !addr.isAnonymousUNIXSocket()) {
auto path = addr.getAddr();
- log() << "removing socket file: " << path;
+ LOGV2(23017, "removing socket file: {path}", "path"_attr = path);
if (::unlink(path.c_str()) != 0) {
const auto ewd = errnoWithDescription();
- warning() << "Unable to remove UNIX socket " << path << ": " << ewd;
+ LOGV2_WARNING(23022,
+ "Unable to remove UNIX socket {path}: {ewd}",
+ "path"_attr = path,
+ "ewd"_attr = ewd);
}
}
}
@@ -1063,8 +1084,12 @@ void TransportLayerASIO::_acceptConnection(GenericAcceptor& acceptor) {
}
if (ec) {
- log() << "Error accepting new connection on "
- << endpointToHostAndPort(acceptor.local_endpoint()) << ": " << ec.message();
+ LOGV2(23018,
+ "Error accepting new connection on "
+ "{endpointToHostAndPort_acceptor_local_endpoint}: {ec_message}",
+ "endpointToHostAndPort_acceptor_local_endpoint"_attr =
+ endpointToHostAndPort(acceptor.local_endpoint()),
+ "ec_message"_attr = ec.message());
_acceptConnection(acceptor);
return;
}
@@ -1083,7 +1108,7 @@ void TransportLayerASIO::_acceptConnection(GenericAcceptor& acceptor) {
new ASIOSession(this, std::move(peerSocket), true));
_sep->startSession(std::move(session));
} catch (const DBException& e) {
- warning() << "Error accepting new connection " << e;
+ LOGV2_WARNING(23023, "Error accepting new connection {e}", "e"_attr = e);
}
_acceptConnection(acceptor);
diff --git a/src/mongo/transport/transport_layer_asio_integration_test.cpp b/src/mongo/transport/transport_layer_asio_integration_test.cpp
index d074f81599d..80aa571c2bd 100644
--- a/src/mongo/transport/transport_layer_asio_integration_test.cpp
+++ b/src/mongo/transport/transport_layer_asio_integration_test.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/client.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/topology_version_gen.h"
#include "mongo/stdx/thread.h"
#include "mongo/transport/session.h"
@@ -59,11 +60,11 @@ TEST(TransportLayerASIO, HTTPRequestGetsHTTPError) {
asio::ip::tcp::resolver resolver(ioContext);
asio::ip::tcp::socket socket(ioContext);
- log() << "Connecting to " << server;
+ LOGV2(23028, "Connecting to {server}", "server"_attr = server);
auto resolverIt = resolver.resolve(server.host(), std::to_string(server.port()));
asio::connect(socket, resolverIt);
- log() << "Sending HTTP request";
+ LOGV2(23029, "Sending HTTP request");
std::string httpReq = str::stream() << "GET /\r\n"
"Host: "
<< server
@@ -72,13 +73,13 @@ TEST(TransportLayerASIO, HTTPRequestGetsHTTPError) {
"Accept: */*";
asio::write(socket, asio::buffer(httpReq.data(), httpReq.size()));
- log() << "Waiting for response";
+ LOGV2(23030, "Waiting for response");
std::array<char, 256> httpRespBuf;
std::error_code ec;
auto size = asio::read(socket, asio::buffer(httpRespBuf.data(), httpRespBuf.size()), ec);
StringData httpResp(httpRespBuf.data(), size);
- log() << "Received response: \"" << httpResp << "\"";
+ LOGV2(23031, "Received response: \"{httpResp}\"", "httpResp"_attr = httpResp);
ASSERT_TRUE(httpResp.startsWith("HTTP/1.0 200 OK"));
// Why oh why can't ASIO unify their error codes
diff --git a/src/mongo/transport/transport_layer_asio_test.cpp b/src/mongo/transport/transport_layer_asio_test.cpp
index 53f979d9cd8..9e23beb33fd 100644
--- a/src/mongo/transport/transport_layer_asio_test.cpp
+++ b/src/mongo/transport/transport_layer_asio_test.cpp
@@ -33,6 +33,7 @@
#include "mongo/transport/transport_layer_asio.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/rpc/op_msg.h"
#include "mongo/transport/service_entry_point.h"
#include "mongo/unittest/unittest.h"
@@ -50,12 +51,12 @@ public:
void startSession(transport::SessionHandle session) override {
stdx::unique_lock<Latch> lk(_mutex);
_sessions.push_back(std::move(session));
- log() << "started session";
+ LOGV2(23032, "started session");
_cv.notify_one();
}
void endAllSessions(transport::Session::TagMask tags) override {
- log() << "end all sessions";
+ LOGV2(23033, "end all sessions");
std::vector<transport::SessionHandle> old_sessions;
{
stdx::unique_lock<Latch> lock(_mutex);
@@ -106,10 +107,10 @@ public:
Socket s;
SockAddr sa{"localhost", _port, AF_INET};
s.connect(sa);
- log() << "connection: port " << _port;
+ LOGV2(23034, "connection: port {port}", "port"_attr = _port);
stdx::unique_lock<Latch> lk(_mutex);
_cv.wait(lk, [&] { return _stop; });
- log() << "connection: Rx stop request";
+ LOGV2(23035, "connection: Rx stop request");
}};
}
@@ -118,10 +119,10 @@ public:
stdx::unique_lock<Latch> lk(_mutex);
_stop = true;
}
- log() << "connection: Tx stop request";
+ LOGV2(23036, "connection: Tx stop request");
_cv.notify_one();
_thr.join();
- log() << "connection: stopped";
+ LOGV2(23037, "connection: stopped");
}
private:
@@ -153,7 +154,7 @@ TEST(TransportLayerASIO, PortZeroConnect) {
ASSERT_OK(tla.start());
int port = tla.listenerPort();
ASSERT_GT(port, 0);
- log() << "TransportLayerASIO.listenerPort() is " << port;
+ LOGV2(23038, "TransportLayerASIO.listenerPort() is {port}", "port"_attr = port);
SimpleConnectionThread connect_thread(port);
sepu.waitForConnect();
@@ -174,7 +175,7 @@ public:
}
bool shutdown(Milliseconds timeout) override {
- log() << "Joining all worker threads";
+ LOGV2(23039, "Joining all worker threads");
for (auto& thread : _workerThreads) {
thread.join();
}
@@ -235,17 +236,19 @@ public:
TimeoutSyncSEP(Mode mode) : _mode(mode) {}
void startSession(transport::SessionHandle session) override {
- log() << "Accepted connection from " << session->remote();
+ LOGV2(23040,
+ "Accepted connection from {session_remote}",
+ "session_remote"_attr = session->remote());
startWorkerThread([this, session = std::move(session)]() mutable {
- log() << "waiting for message";
+ LOGV2(23041, "waiting for message");
session->setTimeout(Milliseconds{500});
auto status = session->sourceMessage().getStatus();
if (_mode == kShouldTimeout) {
ASSERT_EQ(status, ErrorCodes::NetworkTimeout);
- log() << "message timed out";
+ LOGV2(23042, "message timed out");
} else {
ASSERT_OK(status);
- log() << "message received okay";
+ LOGV2(23043, "message received okay");
}
session.reset();
@@ -331,9 +334,11 @@ TEST(TransportLayerASIO, SourceSyncTimeoutSucceeds) {
class TimeoutSwitchModesSEP : public TimeoutSEP {
public:
void startSession(transport::SessionHandle session) override {
- log() << "Accepted connection from " << session->remote();
+ LOGV2(23044,
+ "Accepted connection from {session_remote}",
+ "session_remote"_attr = session->remote());
startWorkerThread([this, session = std::move(session)]() mutable {
- log() << "waiting for message";
+ LOGV2(23045, "waiting for message");
auto sourceMessage = [&] { return session->sourceMessage().getStatus(); };
// the first message we source should time out.
@@ -341,13 +346,13 @@ public:
ASSERT_EQ(sourceMessage(), ErrorCodes::NetworkTimeout);
notifyComplete();
- log() << "timed out successfully";
+ LOGV2(23046, "timed out successfully");
// get the session back in a known state with the timeout still in place
ASSERT_OK(sourceMessage());
notifyComplete();
- log() << "waiting for message without a timeout";
+ LOGV2(23047, "waiting for message without a timeout");
// this should block and timeout the waitForComplete mutex, and the session should wait
// for a while to make sure this isn't timing out and then send a message to unblock
@@ -357,7 +362,7 @@ public:
session.reset();
notifyComplete();
- log() << "ending test";
+ LOGV2(23048, "ending test");
});
}
};
diff --git a/src/mongo/unittest/benchmark_main.cpp b/src/mongo/unittest/benchmark_main.cpp
index 957e2140332..a27d9db89f4 100644
--- a/src/mongo/unittest/benchmark_main.cpp
+++ b/src/mongo/unittest/benchmark_main.cpp
@@ -36,6 +36,7 @@
#include "mongo/base/initializer.h"
#include "mongo/config.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/signal_handlers_synchronous.h"
@@ -53,9 +54,10 @@ int main(int argc, char** argv, char** envp) {
return 1;
#ifndef MONGO_CONFIG_OPTIMIZED_BUILD
- ::mongo::log() << "***WARNING*** MongoDB was built with --opt=off. Function timings may be "
- "affected. Always verify any code change against the production environment "
- "(e.g. --opt=on).";
+ LOGV2(23049,
+ "***WARNING*** MongoDB was built with --opt=off. Function timings may be "
+ "affected. Always verify any code change against the production environment "
+ "(e.g. --opt=on).");
#endif
::benchmark::RunSpecifiedBenchmarks();
diff --git a/src/mongo/unittest/integration_test_main.cpp b/src/mongo/unittest/integration_test_main.cpp
index 123d421e79a..85b966fbb79 100644
--- a/src/mongo/unittest/integration_test_main.cpp
+++ b/src/mongo/unittest/integration_test_main.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/server_options_helpers.h"
#include "mongo/db/service_context.h"
#include "mongo/logger/logger.h"
+#include "mongo/logv2/log.h"
#include "mongo/transport/transport_layer_asio.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -133,7 +134,9 @@ MONGO_STARTUP_OPTIONS_STORE(IntegrationTestOptions)(InitializerContext*) {
}
fixtureConnectionString = std::move(swConnectionString.getValue());
- log() << "Using test fixture with connection string = " << connectionString;
+ LOGV2(23050,
+ "Using test fixture with connection string = {connectionString}",
+ "connectionString"_attr = connectionString);
return Status::OK();
diff --git a/src/mongo/unittest/temp_dir.cpp b/src/mongo/unittest/temp_dir.cpp
index 8b370dfd868..3ba1a70cee2 100644
--- a/src/mongo/unittest/temp_dir.cpp
+++ b/src/mongo/unittest/temp_dir.cpp
@@ -36,6 +36,7 @@
#include <boost/filesystem.hpp>
#include "mongo/base/init.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
#include "mongo/util/options_parser/startup_option_init.h"
@@ -86,19 +87,22 @@ TempDir::TempDir(const std::string& namePrefix) {
bool createdNewDirectory = boost::filesystem::create_directory(_path);
if (!createdNewDirectory) {
- error() << "unique path (" << _path << ") already existed";
+ LOGV2_ERROR(23053, "unique path ({path}) already existed", "path"_attr = _path);
fassertFailed(17147);
}
- ::mongo::unittest::log() << "Created temporary directory: " << _path;
+ LOGV2(23051, "Created temporary directory: {path}", "path"_attr = _path);
}
TempDir::~TempDir() {
try {
boost::filesystem::remove_all(_path);
} catch (const std::exception& e) {
- warning() << "error encountered recursively deleting directory '" << _path
- << "': " << e.what() << ". Ignoring and continuing.";
+ LOGV2_WARNING(23052,
+ "error encountered recursively deleting directory '{path}': {e_what}. "
+ "Ignoring and continuing.",
+ "path"_attr = _path,
+ "e_what"_attr = e.what());
}
}
diff --git a/src/mongo/unittest/unittest.cpp b/src/mongo/unittest/unittest.cpp
index 0fc1d57cf5e..816c97761f4 100644
--- a/src/mongo/unittest/unittest.cpp
+++ b/src/mongo/unittest/unittest.cpp
@@ -50,6 +50,7 @@
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logger/message_log_domain.h"
#include "mongo/logv2/component_settings_filter.h"
+#include "mongo/logv2/log.h"
#include "mongo/logv2/log_capture_backend.h"
#include "mongo/logv2/log_domain.h"
#include "mongo/logv2/log_domain_global.h"
@@ -312,11 +313,13 @@ const std::vector<std::string>& Test::CaptureLogs::getCapturedTextFormatLogMessa
}
void Test::CaptureLogs::printCapturedTextFormatLogLines() const {
- log() << "****************************** Captured Lines (start) *****************************";
+ LOGV2(23054,
+ "****************************** Captured Lines (start) *****************************");
for (const auto& line : getCapturedTextFormatLogMessages()) {
- log() << line;
+ LOGV2(23055, "{line}", "line"_attr = line);
}
- log() << "****************************** Captured Lines (end) ******************************";
+ LOGV2(23056,
+ "****************************** Captured Lines (end) ******************************");
}
int64_t Test::CaptureLogs::countTextFormatLogLinesContaining(const std::string& needle) {
@@ -355,13 +358,18 @@ std::unique_ptr<Result> Suite::run(const std::string& filter,
for (const auto& tc : _tests) {
if (filter.size() && tc.name.find(filter) == std::string::npos) {
- LOG(1) << "\t skipping test: " << tc.name << " because it doesn't match filter";
+ LOGV2_DEBUG(23057,
+ 1,
+ "\t skipping test: {tc_name} because it doesn't match filter",
+ "tc_name"_attr = tc.name);
continue;
}
if (fileNameFilter.size() && tc.fileName.find(fileNameFilter) == std::string::npos) {
- LOG(1) << "\t skipping test: " << tc.fileName
- << " because it doesn't match fileNameFilter";
+ LOGV2_DEBUG(23058,
+ 1,
+ "\t skipping test: {tc_fileName} because it doesn't match fileNameFilter",
+ "tc_fileName"_attr = tc.fileName);
continue;
}
@@ -379,7 +387,10 @@ std::unique_ptr<Result> Suite::run(const std::string& filter,
runTimes << " (" << x + 1 << "/" << runsPerTest << ")";
}
- log() << "\t going to run test: " << tc.name << runTimes.str();
+ LOGV2(23059,
+ "\t going to run test: {tc_name}{runTimes_str}",
+ "tc_name"_attr = tc.name,
+ "runTimes_str"_attr = runTimes.str());
TestSuiteEnvironment environment;
tc.fn();
}
@@ -408,7 +419,7 @@ std::unique_ptr<Result> Suite::run(const std::string& filter,
r->_millis = timer.millis();
- log() << "\t DONE running tests";
+ LOGV2(23060, "\t DONE running tests");
return r;
}
@@ -418,14 +429,15 @@ int Suite::run(const std::vector<std::string>& suites,
const std::string& fileNameFilter,
int runsPerTest) {
if (suitesMap().empty()) {
- log() << "error: no suites registered.";
+ LOGV2(23061, "error: no suites registered.");
return EXIT_FAILURE;
}
for (unsigned int i = 0; i < suites.size(); i++) {
if (suitesMap().count(suites[i]) == 0) {
- log() << "invalid test suite [" << suites[i] << "], use --list to see valid names"
- << std::endl;
+ LOGV2(23062,
+ "invalid test suite [{suites_i}], use --list to see valid names",
+ "suites_i"_attr = suites[i]);
return EXIT_FAILURE;
}
}
@@ -444,11 +456,11 @@ int Suite::run(const std::vector<std::string>& suites,
std::shared_ptr<Suite>& s = suitesMap()[name];
fassert(16145, s != nullptr);
- log() << "going to run suite: " << name << std::endl;
+ LOGV2(23063, "going to run suite: {name}", "name"_attr = name);
results.push_back(s->run(filter, fileNameFilter, runsPerTest));
}
- log() << "**************************************************" << std::endl;
+ LOGV2(23064, "**************************************************");
int rc = 0;
@@ -480,18 +492,20 @@ int Suite::run(const std::vector<std::string>& suites,
totals._asserts = asserts;
totals._millis = millis;
- log() << totals.toString(); // includes endl
+ LOGV2(23065, "{totals}", "totals"_attr = totals.toString());
// summary
if (!totals._fails.empty()) {
- log() << "Failing tests:" << std::endl;
+ LOGV2(23066, "Failing tests:");
for (const std::string& s : totals._fails) {
- log() << "\t " << s << " Failed";
+ LOGV2(23067, "\t {s} Failed", "s"_attr = s);
}
- log() << "FAILURE - " << totals._fails.size() << " tests in " << failedSuites.size()
- << " suites failed";
+ LOGV2(23068,
+ "FAILURE - {totals_fails_size} tests in {failedSuites_size} suites failed",
+ "totals_fails_size"_attr = totals._fails.size(),
+ "failedSuites_size"_attr = failedSuites.size());
} else {
- log() << "SUCCESS - All tests in all suites passed";
+ LOGV2(23069, "SUCCESS - All tests in all suites passed");
}
return rc;
@@ -547,7 +561,7 @@ TestAssertionFailure::~TestAssertionFailure() noexcept(false) {
if (!_stream.str().empty()) {
_exception.setMessage(_exception.getMessage() + " " + _stream.str());
}
- error() << "Throwing exception: " << _exception;
+ LOGV2_ERROR(23070, "Throwing exception: {exception}", "exception"_attr = _exception);
throw _exception;
}
diff --git a/src/mongo/util/alarm_test.cpp b/src/mongo/util/alarm_test.cpp
index f450284fc2a..9a712544d4b 100644
--- a/src/mongo/util/alarm_test.cpp
+++ b/src/mongo/util/alarm_test.cpp
@@ -30,6 +30,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/chrono.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/alarm.h"
@@ -49,21 +50,21 @@ TEST(AlarmScheduler, BasicSingleThread) {
auto alarm = scheduler->alarmAt(testStart + Milliseconds(10));
bool firstTimerExpired = false;
std::move(alarm.future).getAsync([&](Status status) {
- log() << "Timer expired: " << status;
+ LOGV2(23071, "Timer expired: {status}", "status"_attr = status);
firstTimerExpired = true;
});
alarm = scheduler->alarmAt(testStart + Milliseconds(500));
bool secondTimerExpired = false;
std::move(alarm.future).getAsync([&](Status status) {
- log() << "Second timer expired: " << status;
+ LOGV2(23072, "Second timer expired: {status}", "status"_attr = status);
secondTimerExpired = true;
});
alarm = scheduler->alarmAt(testStart + Milliseconds(515));
bool thirdTimerExpired = false;
std::move(alarm.future).getAsync([&](Status status) {
- log() << "third timer expired: " << status;
+ LOGV2(23073, "third timer expired: {status}", "status"_attr = status);
thirdTimerExpired = true;
});
auto missingEvent = alarm.handle;
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp
index c441e9b670c..c9f5d60fe6c 100644
--- a/src/mongo/util/assert_util.cpp
+++ b/src/mongo/util/assert_util.cpp
@@ -43,6 +43,7 @@
#include <exception>
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/debugger.h"
#include "mongo/util/exit.h"
@@ -75,14 +76,18 @@ AtomicWord<bool> DBException::traceExceptions(false);
void DBException::traceIfNeeded(const DBException& e) {
if (traceExceptions.load()) {
- warning() << "DBException thrown" << causedBy(e) << std::endl;
+ LOGV2_WARNING(23075, "DBException thrown{causedBy_e}", "causedBy_e"_attr = causedBy(e));
printStackTrace();
}
}
MONGO_COMPILER_NOINLINE void verifyFailed(const char* expr, const char* file, unsigned line) {
assertionCount.condrollover(assertionCount.regular.addAndFetch(1));
- error() << "Assertion failure " << expr << ' ' << file << ' ' << std::dec << line << std::endl;
+ LOGV2_ERROR(23076,
+ "Assertion failure {expr} {file} {line}",
+ "expr"_attr = expr,
+ "file"_attr = file,
+ "line"_attr = line);
logContext();
std::stringstream temp;
temp << "assertion " << file << ":" << line;
@@ -90,8 +95,7 @@ MONGO_COMPILER_NOINLINE void verifyFailed(const char* expr, const char* file, un
breakpoint();
#if defined(MONGO_CONFIG_DEBUG_BUILD)
// this is so we notice in buildbot
- severe() << "\n\n***aborting after verify() failure as this is a debug/test build\n\n"
- << std::endl;
+ LOGV2_FATAL(23078, "\n\n***aborting after verify() failure as this is a debug/test build\n\n");
std::abort();
#endif
error_details::throwExceptionForStatus(Status(ErrorCodes::UnknownError, temp.str()));
@@ -100,9 +104,13 @@ MONGO_COMPILER_NOINLINE void verifyFailed(const char* expr, const char* file, un
MONGO_COMPILER_NOINLINE void invariantFailed(const char* expr,
const char* file,
unsigned line) noexcept {
- severe() << "Invariant failure " << expr << ' ' << file << ' ' << std::dec << line << std::endl;
+ LOGV2_FATAL(23079,
+ "Invariant failure {expr} {file} {line}",
+ "expr"_attr = expr,
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after invariant() failure\n\n" << std::endl;
+ LOGV2_FATAL(23080, "\n\n***aborting after invariant() failure\n\n");
std::abort();
}
@@ -110,10 +118,14 @@ MONGO_COMPILER_NOINLINE void invariantFailedWithMsg(const char* expr,
const std::string& msg,
const char* file,
unsigned line) noexcept {
- severe() << "Invariant failure " << expr << " " << msg << " " << file << ' ' << std::dec << line
- << std::endl;
+ LOGV2_FATAL(23081,
+ "Invariant failure {expr} {msg} {file} {line}",
+ "expr"_attr = expr,
+ "msg"_attr = msg,
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after invariant() failure\n\n" << std::endl;
+ LOGV2_FATAL(23082, "\n\n***aborting after invariant() failure\n\n");
std::abort();
}
@@ -121,10 +133,14 @@ MONGO_COMPILER_NOINLINE void invariantOKFailed(const char* expr,
const Status& status,
const char* file,
unsigned line) noexcept {
- severe() << "Invariant failure: " << expr << " resulted in status " << redact(status) << " at "
- << file << ' ' << std::dec << line;
+ LOGV2_FATAL(23083,
+ "Invariant failure: {expr} resulted in status {status} at {file} {line}",
+ "expr"_attr = expr,
+ "status"_attr = redact(status),
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after invariant() failure\n\n" << std::endl;
+ LOGV2_FATAL(23084, "\n\n***aborting after invariant() failure\n\n");
std::abort();
}
@@ -133,38 +149,54 @@ MONGO_COMPILER_NOINLINE void invariantOKFailedWithMsg(const char* expr,
const std::string& msg,
const char* file,
unsigned line) noexcept {
- severe() << "Invariant failure: " << expr << " " << msg << " resulted in status "
- << redact(status) << " at " << file << ' ' << std::dec << line;
+ LOGV2_FATAL(23085,
+ "Invariant failure: {expr} {msg} resulted in status {status} at {file} {line}",
+ "expr"_attr = expr,
+ "msg"_attr = msg,
+ "status"_attr = redact(status),
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after invariant() failure\n\n" << std::endl;
+ LOGV2_FATAL(23086, "\n\n***aborting after invariant() failure\n\n");
std::abort();
}
MONGO_COMPILER_NOINLINE void invariantStatusOKFailed(const Status& status,
const char* file,
unsigned line) noexcept {
- severe() << "Invariant failure " << redact(status) << " at " << file << ' ' << std::dec << line
- << std::endl;
+ LOGV2_FATAL(23087,
+ "Invariant failure {status} at {file} {line}",
+ "status"_attr = redact(status),
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after invariant() failure\n\n" << std::endl;
+ LOGV2_FATAL(23088, "\n\n***aborting after invariant() failure\n\n");
std::abort();
}
MONGO_COMPILER_NOINLINE void fassertFailedWithLocation(int msgid,
const char* file,
unsigned line) noexcept {
- severe() << "Fatal Assertion " << msgid << " at " << file << " " << std::dec << line;
+ LOGV2_FATAL(23089,
+ "Fatal Assertion {msgid} at {file} {line}",
+ "msgid"_attr = msgid,
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after fassert() failure\n\n" << std::endl;
+ LOGV2_FATAL(23090, "\n\n***aborting after fassert() failure\n\n");
std::abort();
}
MONGO_COMPILER_NOINLINE void fassertFailedNoTraceWithLocation(int msgid,
const char* file,
unsigned line) noexcept {
- severe() << "Fatal Assertion " << msgid << " at " << file << " " << std::dec << line;
+ LOGV2_FATAL(23091,
+ "Fatal Assertion {msgid} at {file} {line}",
+ "msgid"_attr = msgid,
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after fassert() failure\n\n" << std::endl;
+ LOGV2_FATAL(23092, "\n\n***aborting after fassert() failure\n\n");
quickExit(EXIT_ABRUPT);
}
@@ -172,10 +204,14 @@ MONGO_COMPILER_NORETURN void fassertFailedWithStatusWithLocation(int msgid,
const Status& status,
const char* file,
unsigned line) noexcept {
- severe() << "Fatal assertion " << msgid << " " << redact(status) << " at " << file << " "
- << std::dec << line;
+ LOGV2_FATAL(23093,
+ "Fatal assertion {msgid} {status} at {file} {line}",
+ "msgid"_attr = msgid,
+ "status"_attr = redact(status),
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after fassert() failure\n\n" << std::endl;
+ LOGV2_FATAL(23094, "\n\n***aborting after fassert() failure\n\n");
std::abort();
}
@@ -183,10 +219,14 @@ MONGO_COMPILER_NORETURN void fassertFailedWithStatusNoTraceWithLocation(int msgi
const Status& status,
const char* file,
unsigned line) noexcept {
- severe() << "Fatal assertion " << msgid << " " << redact(status) << " at " << file << " "
- << std::dec << line;
+ LOGV2_FATAL(23095,
+ "Fatal assertion {msgid} {status} at {file} {line}",
+ "msgid"_attr = msgid,
+ "status"_attr = redact(status),
+ "file"_attr = file,
+ "line"_attr = line);
breakpoint();
- severe() << "\n\n***aborting after fassert() failure\n\n" << std::endl;
+ LOGV2_FATAL(23096, "\n\n***aborting after fassert() failure\n\n");
quickExit(EXIT_ABRUPT);
}
@@ -194,7 +234,12 @@ MONGO_COMPILER_NOINLINE void uassertedWithLocation(const Status& status,
const char* file,
unsigned line) {
assertionCount.condrollover(assertionCount.user.addAndFetch(1));
- LOG(1) << "User Assertion: " << redact(status) << ' ' << file << ' ' << std::dec << line;
+ LOGV2_DEBUG(23074,
+ 1,
+ "User Assertion: {status} {file} {line}",
+ "status"_attr = redact(status),
+ "file"_attr = file,
+ "line"_attr = line);
error_details::throwExceptionForStatus(status);
}
@@ -202,7 +247,11 @@ MONGO_COMPILER_NOINLINE void msgassertedWithLocation(const Status& status,
const char* file,
unsigned line) {
assertionCount.condrollover(assertionCount.msg.addAndFetch(1));
- error() << "Assertion: " << redact(status) << ' ' << file << ' ' << std::dec << line;
+ LOGV2_ERROR(23077,
+ "Assertion: {status} {file} {line}",
+ "status"_attr = redact(status),
+ "file"_attr = file,
+ "line"_attr = line);
error_details::throwExceptionForStatus(status);
}
@@ -267,7 +316,7 @@ Status exceptionToStatus() noexcept {
<< boost::diagnostic_information(ex));
} catch (...) {
- severe() << "Caught unknown exception in exceptionToStatus()";
+ LOGV2_FATAL(23097, "Caught unknown exception in exceptionToStatus()");
std::terminate();
}
}
diff --git a/src/mongo/util/background.cpp b/src/mongo/util/background.cpp
index 6951bf86681..995f3558017 100644
--- a/src/mongo/util/background.cpp
+++ b/src/mongo/util/background.cpp
@@ -36,6 +36,7 @@
#include <functional>
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/stdx/thread.h"
@@ -147,7 +148,7 @@ void BackgroundJob::jobBody() {
setThreadName(threadName);
}
- LOG(1) << "BackgroundJob starting: " << threadName;
+ LOGV2_DEBUG(23098, 1, "BackgroundJob starting: {threadName}", "threadName"_attr = threadName);
run();
@@ -333,14 +334,22 @@ void PeriodicTaskRunner::_runTask(PeriodicTask* const task) {
try {
task->taskDoWork();
} catch (const std::exception& e) {
- error() << "task: " << taskName << " failed: " << redact(e.what());
+ LOGV2_ERROR(23100,
+ "task: {taskName} failed: {e_what}",
+ "taskName"_attr = taskName,
+ "e_what"_attr = redact(e.what()));
} catch (...) {
- error() << "task: " << taskName << " failed with unknown error";
+ LOGV2_ERROR(
+ 23101, "task: {taskName} failed with unknown error", "taskName"_attr = taskName);
}
const int ms = timer.millis();
const int kMinLogMs = 100;
- LOG(ms <= kMinLogMs ? 3 : 0) << "task: " << taskName << " took: " << ms << "ms";
+ LOGV2_DEBUG(23099,
+ logSeverityV1toV2(ms <= kMinLogMs ? 3 : 0).toInt(),
+ "task: {taskName} took: {ms}ms",
+ "taskName"_attr = taskName,
+ "ms"_attr = ms);
}
} // namespace mongo
diff --git a/src/mongo/util/concurrency/thread_name.cpp b/src/mongo/util/concurrency/thread_name.cpp
index 03a6ab181c4..ecd727c4c79 100644
--- a/src/mongo/util/concurrency/thread_name.cpp
+++ b/src/mongo/util/concurrency/thread_name.cpp
@@ -51,6 +51,7 @@
#include "mongo/base/init.h"
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -132,7 +133,9 @@ void setThreadName(StringData name) {
}
int error = pthread_setname_np(threadNameCopy.c_str());
if (error) {
- log() << "Ignoring error from setting thread name: " << errnoWithDescription(error);
+ LOGV2(23102,
+ "Ignoring error from setting thread name: {errnoWithDescription_error}",
+ "errnoWithDescription_error"_attr = errnoWithDescription(error));
}
#elif defined(__linux__) && defined(MONGO_CONFIG_HAVE_PTHREAD_SETNAME_NP)
// Do not set thread name on the main() thread. Setting the name on main thread breaks
@@ -153,7 +156,9 @@ void setThreadName(StringData name) {
}
if (error) {
- log() << "Ignoring error from setting thread name: " << errnoWithDescription(error);
+ LOGV2(23103,
+ "Ignoring error from setting thread name: {errnoWithDescription_error}",
+ "errnoWithDescription_error"_attr = errnoWithDescription(error));
}
}
#endif
diff --git a/src/mongo/util/concurrency/thread_pool.cpp b/src/mongo/util/concurrency/thread_pool.cpp
index 0688293adfa..0f3f519867e 100644
--- a/src/mongo/util/concurrency/thread_pool.cpp
+++ b/src/mongo/util/concurrency/thread_pool.cpp
@@ -34,6 +34,7 @@
#include "mongo/util/concurrency/thread_pool.h"
#include "mongo/base/status.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/concurrency/idle_thread_block.h"
@@ -61,14 +62,21 @@ ThreadPool::Options cleanUpOptions(ThreadPool::Options&& options) {
options.threadNamePrefix = str::stream() << options.poolName << '-';
}
if (options.maxThreads < 1) {
- severe() << "Tried to create pool " << options.poolName << " with a maximum of "
- << options.maxThreads << " but the maximum must be at least 1";
+ LOGV2_FATAL(23114,
+ "Tried to create pool {options_poolName} with a maximum of "
+ "{options_maxThreads} but the maximum must be at least 1",
+ "options_poolName"_attr = options.poolName,
+ "options_maxThreads"_attr = options.maxThreads);
fassertFailed(28702);
}
if (options.minThreads > options.maxThreads) {
- severe() << "Tried to create pool " << options.poolName << " with a minimum of "
- << options.minThreads << " which is more than the configured maximum of "
- << options.maxThreads;
+ LOGV2_FATAL(
+ 23115,
+ "Tried to create pool {options_poolName} with a minimum of {options_minThreads} which "
+ "is more than the configured maximum of {options_maxThreads}",
+ "options_poolName"_attr = options.poolName,
+ "options_minThreads"_attr = options.minThreads,
+ "options_maxThreads"_attr = options.maxThreads);
fassertFailed(28686);
}
return {std::move(options)};
@@ -86,7 +94,7 @@ ThreadPool::~ThreadPool() {
}
if (shutdownComplete != _state) {
- severe() << "Failed to shutdown pool during destruction";
+ LOGV2_FATAL(23116, "Failed to shutdown pool during destruction");
fassertFailed(28704);
}
invariant(_threads.empty());
@@ -96,8 +104,9 @@ ThreadPool::~ThreadPool() {
void ThreadPool::startup() {
stdx::lock_guard<Latch> lk(_mutex);
if (_state != preStart) {
- severe() << "Attempting to start pool " << _options.poolName
- << ", but it has already started";
+ LOGV2_FATAL(23117,
+ "Attempting to start pool {options_poolName}, but it has already started",
+ "options_poolName"_attr = _options.poolName);
fassertFailed(28698);
}
_setState_inlock(running);
@@ -154,7 +163,9 @@ void ThreadPool::_join_inlock(stdx::unique_lock<Latch>* lk) {
return true;
case joining:
case shutdownComplete:
- severe() << "Attempted to join pool " << _options.poolName << " more than once";
+ LOGV2_FATAL(23118,
+ "Attempted to join pool {options_poolName} more than once",
+ "options_poolName"_attr = _options.poolName);
fassertFailed(28700);
}
MONGO_UNREACHABLE;
@@ -253,7 +264,7 @@ void ThreadPool::_workerThreadBody(ThreadPool* pool, const std::string& threadNa
setThreadName(threadName);
pool->_options.onCreateThread(threadName);
const auto poolName = pool->_options.poolName;
- LOG(1) << "starting thread in pool " << poolName;
+ LOGV2_DEBUG(23104, 1, "starting thread in pool {poolName}", "poolName"_attr = poolName);
pool->_consumeTasks();
// At this point, another thread may have destroyed "pool", if this thread chose to detach
@@ -263,7 +274,7 @@ void ThreadPool::_workerThreadBody(ThreadPool* pool, const std::string& threadNa
// This can happen if this thread decided to retire, got descheduled after removing itself
// from _threads and calling detach(), and then the pool was deleted. When this thread resumes,
// it is no longer safe to access "pool".
- LOG(1) << "shutting down thread in pool " << poolName;
+ LOGV2_DEBUG(23105, 1, "shutting down thread in pool {poolName}", "poolName"_attr = poolName);
}
void ThreadPool::_consumeTasks() {
@@ -286,13 +297,20 @@ void ThreadPool::_consumeTasks() {
_lastFullUtilizationDate + _options.maxIdleThreadAge;
if (now >= nextThreadRetirementDate) {
_lastFullUtilizationDate = now;
- LOG(1) << "Reaping this thread; next thread reaped no earlier than "
- << _lastFullUtilizationDate + _options.maxIdleThreadAge;
+ LOGV2_DEBUG(23106,
+ 1,
+ "Reaping this thread; next thread reaped no earlier than "
+ "{lastFullUtilizationDate_options_maxIdleThreadAge}",
+ "lastFullUtilizationDate_options_maxIdleThreadAge"_attr =
+ _lastFullUtilizationDate + _options.maxIdleThreadAge);
break;
}
- LOG(3) << "Not reaping because the earliest retirement date is "
- << nextThreadRetirementDate;
+ LOGV2_DEBUG(23107,
+ 3,
+ "Not reaping because the earliest retirement date is "
+ "{nextThreadRetirementDate}",
+ "nextThreadRetirementDate"_attr = nextThreadRetirementDate);
MONGO_IDLE_THREAD_BLOCK;
_workAvailable.wait_until(lk, nextThreadRetirementDate.toSystemTimePoint());
} else {
@@ -300,8 +318,12 @@ void ThreadPool::_consumeTasks() {
// eligible for retirement. It is OK to sleep until _workAvailable is signaled,
// because any new threads that put the number of total threads above minThreads
// would be eligible for retirement once they had no work left to do.
- LOG(3) << "waiting for work; I am one of " << _threads.size() << " thread(s);"
- << " the minimum number of threads is " << _options.minThreads;
+ LOGV2_DEBUG(23108,
+ 3,
+ "waiting for work; I am one of {threads_size} thread(s); the minimum "
+ "number of threads is {options_minThreads}",
+ "threads_size"_attr = _threads.size(),
+ "options_minThreads"_attr = _options.minThreads);
MONGO_IDLE_THREAD_BLOCK;
_workAvailable.wait(lk);
}
@@ -326,8 +348,12 @@ void ThreadPool::_consumeTasks() {
--_numIdleThreads;
if (_state != running) {
- severe() << "State of pool " << _options.poolName << " is " << static_cast<int32_t>(_state)
- << ", but expected " << static_cast<int32_t>(running);
+ LOGV2_FATAL(23119,
+ "State of pool {options_poolName} is {static_cast_int32_t_state}, but expected "
+ "{static_cast_int32_t_running}",
+ "options_poolName"_attr = _options.poolName,
+ "static_cast_int32_t_state"_attr = static_cast<int32_t>(_state),
+ "static_cast_int32_t_running"_attr = static_cast<int32_t>(running));
fassertFailedNoTrace(28701);
}
@@ -350,7 +376,10 @@ void ThreadPool::_consumeTasks() {
void ThreadPool::_doOneTask(stdx::unique_lock<Latch>* lk) noexcept {
invariant(!_pendingTasks.empty());
- LOG(3) << "Executing a task on behalf of pool " << _options.poolName;
+ LOGV2_DEBUG(23109,
+ 3,
+ "Executing a task on behalf of pool {options_poolName}",
+ "options_poolName"_attr = _options.poolName);
Task task = std::move(_pendingTasks.front());
_pendingTasks.pop_front();
--_numIdleThreads;
@@ -366,14 +395,19 @@ void ThreadPool::_doOneTask(stdx::unique_lock<Latch>* lk) noexcept {
void ThreadPool::_startWorkerThread_inlock() {
switch (_state) {
case preStart:
- LOG(1) << "Not starting new thread in pool " << _options.poolName
- << ", yet; waiting for startup() call";
+ LOGV2_DEBUG(23110,
+ 1,
+ "Not starting new thread in pool {options_poolName}, yet; waiting for "
+ "startup() call",
+ "options_poolName"_attr = _options.poolName);
return;
case joinRequired:
case joining:
case shutdownComplete:
- LOG(1) << "Not starting new thread in pool " << _options.poolName
- << " while shutting down";
+ LOGV2_DEBUG(23111,
+ 1,
+ "Not starting new thread in pool {options_poolName} while shutting down",
+ "options_poolName"_attr = _options.poolName);
return;
case running:
break;
@@ -381,8 +415,12 @@ void ThreadPool::_startWorkerThread_inlock() {
MONGO_UNREACHABLE;
}
if (_threads.size() == _options.maxThreads) {
- LOG(2) << "Not starting new thread in pool " << _options.poolName
- << " because it already has " << _options.maxThreads << ", its maximum";
+ LOGV2_DEBUG(23112,
+ 2,
+ "Not starting new thread in pool {options_poolName} because it already has "
+ "{options_maxThreads}, its maximum",
+ "options_poolName"_attr = _options.poolName,
+ "options_maxThreads"_attr = _options.maxThreads);
return;
}
invariant(_threads.size() < _options.maxThreads);
@@ -391,9 +429,13 @@ void ThreadPool::_startWorkerThread_inlock() {
_threads.emplace_back([this, threadName] { _workerThreadBody(this, threadName); });
++_numIdleThreads;
} catch (const std::exception& ex) {
- error() << "Failed to start " << threadName << "; " << _threads.size()
- << " other thread(s) still running in pool " << _options.poolName
- << "; caught exception: " << redact(ex.what());
+ LOGV2_ERROR(23113,
+ "Failed to start {threadName}; {threads_size} other thread(s) still running in "
+ "pool {options_poolName}; caught exception: {ex_what}",
+ "threadName"_attr = threadName,
+ "threads_size"_attr = _threads.size(),
+ "options_poolName"_attr = _options.poolName,
+ "ex_what"_attr = redact(ex.what()));
}
}
diff --git a/src/mongo/util/concurrency/ticketholder.cpp b/src/mongo/util/concurrency/ticketholder.cpp
index a6abd154b2e..13430c48640 100644
--- a/src/mongo/util/concurrency/ticketholder.cpp
+++ b/src/mongo/util/concurrency/ticketholder.cpp
@@ -35,6 +35,7 @@
#include <iostream>
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/str.h"
@@ -47,7 +48,9 @@ namespace {
* Accepts an errno code, prints its error message, and exits.
*/
void failWithErrno(int err) {
- severe() << "error in Ticketholder: " << errnoWithDescription(err);
+ LOGV2_FATAL(23121,
+ "error in Ticketholder: {errnoWithDescription_err}",
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
fassertFailed(28604);
}
@@ -218,7 +221,7 @@ Status TicketHolder::resize(int newSize) {
<< "more than newSize(" << newSize << ")";
std::string errmsg = ss.str();
- log() << errmsg;
+ LOGV2(23120, "{errmsg}", "errmsg"_attr = errmsg);
return Status(ErrorCodes::BadValue, errmsg);
}
diff --git a/src/mongo/util/concurrency/with_lock_test.cpp b/src/mongo/util/concurrency/with_lock_test.cpp
index 5724f899471..1c5f6acf375 100644
--- a/src/mongo/util/concurrency/with_lock_test.cpp
+++ b/src/mongo/util/concurrency/with_lock_test.cpp
@@ -31,6 +31,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/concurrency/with_lock.h"
@@ -63,7 +64,10 @@ private:
return _blerp(lk, i);
}
int _blerp(WithLock, int i) {
- log() << i << " bleep" << (i == 1 ? "\n" : "s\n");
+ LOGV2(23122,
+ "{i} bleep{i_1_n_s_n}",
+ "i"_attr = i,
+ "i_1_n_s_n"_attr = (i == 1 ? "\n" : "s\n"));
return i;
}
Mutex _m = MONGO_MAKE_LATCH("Beerp::_m");
diff --git a/src/mongo/util/diagnostic_info.cpp b/src/mongo/util/diagnostic_info.cpp
index f0b7bb8b1ce..b561c588ee3 100644
--- a/src/mongo/util/diagnostic_info.cpp
+++ b/src/mongo/util/diagnostic_info.cpp
@@ -40,6 +40,7 @@
#include "mongo/base/init.h"
#include "mongo/db/client.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/clock_source.h"
#include "mongo/util/hierarchical_acquisition.h"
@@ -100,29 +101,29 @@ void BlockedOp::start(ServiceContext* serviceContext) {
_latchState.thread = stdx::thread([this, serviceContext]() mutable {
ThreadClient tc("DiagnosticCaptureTestLatch", serviceContext);
- log() << "Entered currentOpSpawnsThreadWaitingForLatch thread";
+ LOGV2(23123, "Entered currentOpSpawnsThreadWaitingForLatch thread");
stdx::lock_guard testLock(_latchState.mutex);
- log() << "Joining currentOpSpawnsThreadWaitingForLatch thread";
+ LOGV2(23124, "Joining currentOpSpawnsThreadWaitingForLatch thread");
});
_interruptibleState.thread = stdx::thread([this, serviceContext]() mutable {
ThreadClient tc("DiagnosticCaptureTestInterruptible", serviceContext);
auto opCtx = tc->makeOperationContext();
- log() << "Entered currentOpSpawnsThreadWaitingForLatch thread for interruptibles";
+ LOGV2(23125, "Entered currentOpSpawnsThreadWaitingForLatch thread for interruptibles");
stdx::unique_lock lk(_interruptibleState.mutex);
opCtx->waitForConditionOrInterrupt(
_interruptibleState.cv, lk, [&] { return _interruptibleState.isDone; });
_interruptibleState.isDone = false;
- log() << "Joining currentOpSpawnsThreadWaitingForLatch thread for interruptibles";
+ LOGV2(23126, "Joining currentOpSpawnsThreadWaitingForLatch thread for interruptibles");
});
_cv.wait(lk, [this] { return _latchState.isContended && _interruptibleState.isWaiting; });
- log() << "Started threads for currentOpSpawnsThreadWaitingForLatch";
+ LOGV2(23127, "Started threads for currentOpSpawnsThreadWaitingForLatch");
}
// This function unlocks testMutex and joins if there are no more callers of BlockedOp::start()
@@ -155,14 +156,18 @@ void BlockedOp::join() {
}
void BlockedOp::setIsContended(bool value) {
- log() << "Setting isContended to " << (value ? "true" : "false");
+ LOGV2(23128,
+ "Setting isContended to {value_true_false}",
+ "value_true_false"_attr = (value ? "true" : "false"));
stdx::lock_guard lk(_m);
_latchState.isContended = value;
_cv.notify_one();
}
void BlockedOp::setIsWaiting(bool value) {
- log() << "Setting isWaiting to " << (value ? "true" : "false");
+ LOGV2(23129,
+ "Setting isWaiting to {value_true_false}",
+ "value_true_false"_attr = (value ? "true" : "false"));
stdx::lock_guard lk(_m);
_interruptibleState.isWaiting = value;
_cv.notify_one();
diff --git a/src/mongo/util/exception_filter_win32.cpp b/src/mongo/util/exception_filter_win32.cpp
index bda23d4e122..b9d84dcee1f 100644
--- a/src/mongo/util/exception_filter_win32.cpp
+++ b/src/mongo/util/exception_filter_win32.cpp
@@ -42,6 +42,7 @@
#include <ostream>
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/exit_code.h"
#include "mongo/util/log.h"
@@ -63,7 +64,9 @@ void doMinidumpWithException(struct _EXCEPTION_POINTERS* exceptionInfo) {
DWORD ret = GetModuleFileNameW(nullptr, &moduleFileName[0], ARRAYSIZE(moduleFileName));
if (ret == 0) {
int gle = GetLastError();
- log() << "GetModuleFileName failed " << errnoWithDescription(gle);
+ LOGV2(23130,
+ "GetModuleFileName failed {errnoWithDescription_gle}",
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
// Fallback name
wcscpy_s(moduleFileName, L"mongo");
@@ -88,8 +91,11 @@ void doMinidumpWithException(struct _EXCEPTION_POINTERS* exceptionInfo) {
dumpName.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (INVALID_HANDLE_VALUE == hFile) {
DWORD lasterr = GetLastError();
- log() << "failed to open minidump file " << toUtf8String(dumpName.c_str()) << " : "
- << errnoWithDescription(lasterr);
+ LOGV2(23131,
+ "failed to open minidump file {toUtf8String_dumpName_c_str} : "
+ "{errnoWithDescription_lasterr}",
+ "toUtf8String_dumpName_c_str"_attr = toUtf8String(dumpName.c_str()),
+ "errnoWithDescription_lasterr"_attr = errnoWithDescription(lasterr));
return;
}
@@ -105,7 +111,9 @@ void doMinidumpWithException(struct _EXCEPTION_POINTERS* exceptionInfo) {
static_cast<MINIDUMP_TYPE>(MiniDumpNormal | MiniDumpWithIndirectlyReferencedMemory |
MiniDumpWithProcessThreadData);
#endif
- log() << "writing minidump diagnostic file " << toUtf8String(dumpName.c_str());
+ LOGV2(23132,
+ "writing minidump diagnostic file {toUtf8String_dumpName_c_str}",
+ "toUtf8String_dumpName_c_str"_attr = toUtf8String(dumpName.c_str()));
BOOL bstatus = MiniDumpWriteDump(GetCurrentProcess(),
GetCurrentProcessId(),
@@ -116,7 +124,9 @@ void doMinidumpWithException(struct _EXCEPTION_POINTERS* exceptionInfo) {
nullptr);
if (FALSE == bstatus) {
DWORD lasterr = GetLastError();
- log() << "failed to create minidump : " << errnoWithDescription(lasterr);
+ LOGV2(23133,
+ "failed to create minidump : {errnoWithDescription_lasterr}",
+ "errnoWithDescription_lasterr"_attr = errnoWithDescription(lasterr));
}
CloseHandle(hFile);
@@ -135,8 +145,10 @@ LONG WINAPI exceptionFilter(struct _EXCEPTION_POINTERS* excPointers) {
sizeof(addressString),
"0x%p",
excPointers->ExceptionRecord->ExceptionAddress);
- severe() << "*** unhandled exception " << exceptionString << " at " << addressString
- << ", terminating";
+ LOGV2_FATAL(23134,
+ "*** unhandled exception {exceptionString} at {addressString}, terminating",
+ "exceptionString"_attr = exceptionString,
+ "addressString"_attr = addressString);
if (excPointers->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
ULONG acType = excPointers->ExceptionRecord->ExceptionInformation[0];
const char* acTypeString;
@@ -158,10 +170,13 @@ LONG WINAPI exceptionFilter(struct _EXCEPTION_POINTERS* excPointers) {
sizeof(addressString),
" 0x%llx",
excPointers->ExceptionRecord->ExceptionInformation[1]);
- severe() << "*** access violation was a " << acTypeString << addressString;
+ LOGV2_FATAL(23135,
+ "*** access violation was a {acTypeString}{addressString}",
+ "acTypeString"_attr = acTypeString,
+ "addressString"_attr = addressString);
}
- severe() << "*** stack trace for unhandled exception:";
+ LOGV2_FATAL(23136, "*** stack trace for unhandled exception:");
// Create a copy of context record because printWindowsStackTrace will mutate it.
CONTEXT contextCopy(*(excPointers->ContextRecord));
@@ -172,7 +187,7 @@ LONG WINAPI exceptionFilter(struct _EXCEPTION_POINTERS* excPointers) {
// Don't go through normal shutdown procedure. It may make things worse.
// Do not go through _exit or ExitProcess(), terminate immediately
- severe() << "*** immediate exit due to unhandled exception";
+ LOGV2_FATAL(23137, "*** immediate exit due to unhandled exception");
TerminateProcess(GetCurrentProcess(), EXIT_ABRUPT);
// We won't reach here
diff --git a/src/mongo/util/exit.cpp b/src/mongo/util/exit.cpp
index 66af99151ff..5057aaa1498 100644
--- a/src/mongo/util/exit.cpp
+++ b/src/mongo/util/exit.cpp
@@ -37,6 +37,7 @@
#include <functional>
#include <stack>
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/stdx/thread.h"
@@ -68,7 +69,7 @@ void runTasks(decltype(shutdownTasks) tasks, const ShutdownTaskArgs& shutdownArg
// has its own 'quickExitMutex' to prohibit multiple threads from attempting to call _exit().
MONGO_COMPILER_NORETURN void logAndQuickExit_inlock() {
ExitCode code = shutdownExitCode.get();
- log() << "shutting down with code:" << code;
+ LOGV2(23138, "shutting down with code:{code}", "code"_attr = code);
quickExit(code);
}
@@ -113,11 +114,13 @@ void shutdown(ExitCode code, const ShutdownTaskArgs& shutdownArgs) {
ExitCode originallyRequestedCode = shutdownExitCode.get();
if (code != originallyRequestedCode) {
- log() << "While running shutdown tasks with the intent to exit with code "
- << originallyRequestedCode
- << ", an additional shutdown request arrived with "
- "the intent to exit with a different exit code "
- << code << "; ignoring the conflicting exit code";
+ LOGV2(23139,
+ "While running shutdown tasks with the intent to exit with code "
+ "{originallyRequestedCode}, an additional shutdown request arrived with "
+ "the intent to exit with a different exit code {code}; ignoring the "
+ "conflicting exit code",
+ "originallyRequestedCode"_attr = originallyRequestedCode,
+ "code"_attr = code);
}
// Wait for the shutdown tasks to complete
diff --git a/src/mongo/util/file.cpp b/src/mongo/util/file.cpp
index b3c85b4c34e..226592485bd 100644
--- a/src/mongo/util/file.cpp
+++ b/src/mongo/util/file.cpp
@@ -43,6 +43,7 @@
#include <sys/types.h>
#endif
+#include "mongo/logv2/log.h"
#include "mongo/platform/basic.h"
#include "mongo/util/allocator.h"
#include "mongo/util/assert_util.h"
@@ -72,16 +73,22 @@ intmax_t File::freeSpace(const std::string& path) {
return avail.QuadPart;
}
DWORD dosError = GetLastError();
- log() << "In File::freeSpace(), GetDiskFreeSpaceEx for '" << path << "' failed with "
- << errnoWithDescription(dosError);
+ LOGV2(23140,
+ "In File::freeSpace(), GetDiskFreeSpaceEx for '{path}' failed with "
+ "{errnoWithDescription_dosError}",
+ "path"_attr = path,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
return -1;
}
void File::fsync() const {
if (FlushFileBuffers(_handle) == 0) {
DWORD dosError = GetLastError();
- log() << "In File::fsync(), FlushFileBuffers for '" << _name << "' failed with "
- << errnoWithDescription(dosError);
+ LOGV2(23141,
+ "In File::fsync(), FlushFileBuffers for '{name}' failed with "
+ "{errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
}
}
@@ -96,8 +103,10 @@ fileofs File::len() {
}
_bad = true;
DWORD dosError = GetLastError();
- log() << "In File::len(), GetFileSizeEx for '" << _name << "' failed with "
- << errnoWithDescription(dosError);
+ LOGV2(23142,
+ "In File::len(), GetFileSizeEx for '{name}' failed with {errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
return 0;
}
@@ -113,8 +122,11 @@ void File::open(const char* filename, bool readOnly, bool direct) {
_bad = !is_open();
if (_bad) {
DWORD dosError = GetLastError();
- log() << "In File::open(), CreateFileW for '" << _name << "' failed with "
- << errnoWithDescription(dosError);
+ LOGV2(
+ 23143,
+ "In File::open(), CreateFileW for '{name}' failed with {errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
}
}
@@ -124,17 +136,22 @@ void File::read(fileofs o, char* data, unsigned len) {
if (SetFilePointerEx(_handle, li, nullptr, FILE_BEGIN) == 0) {
_bad = true;
DWORD dosError = GetLastError();
- log() << "In File::read(), SetFilePointerEx for '" << _name
- << "' tried to set the file pointer to " << o << " but failed with "
- << errnoWithDescription(dosError);
+ LOGV2(23144,
+ "In File::read(), SetFilePointerEx for '{name}' tried to set the file pointer to {o} "
+ "but failed with {errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "o"_attr = o,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
return;
}
DWORD bytesRead;
if (!ReadFile(_handle, data, len, &bytesRead, 0)) {
_bad = true;
DWORD dosError = GetLastError();
- log() << "In File::read(), ReadFile for '" << _name << "' failed with "
- << errnoWithDescription(dosError);
+ LOGV2(23145,
+ "In File::read(), ReadFile for '{name}' failed with {errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
} else if (bytesRead != len) {
_bad = true;
msgasserted(10438,
@@ -153,16 +170,22 @@ void File::truncate(fileofs size) {
if (SetFilePointerEx(_handle, li, nullptr, FILE_BEGIN) == 0) {
_bad = true;
DWORD dosError = GetLastError();
- log() << "In File::truncate(), SetFilePointerEx for '" << _name
- << "' tried to set the file pointer to " << size << " but failed with "
- << errnoWithDescription(dosError);
+ LOGV2(23146,
+ "In File::truncate(), SetFilePointerEx for '{name}' tried to set the file pointer to "
+ "{size} but failed with {errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "size"_attr = size,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
return;
}
if (SetEndOfFile(_handle) == 0) {
_bad = true;
DWORD dosError = GetLastError();
- log() << "In File::truncate(), SetEndOfFile for '" << _name << "' failed with "
- << errnoWithDescription(dosError);
+ LOGV2(23147,
+ "In File::truncate(), SetEndOfFile for '{name}' failed with "
+ "{errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
}
}
@@ -172,18 +195,25 @@ void File::write(fileofs o, const char* data, unsigned len) {
if (SetFilePointerEx(_handle, li, nullptr, FILE_BEGIN) == 0) {
_bad = true;
DWORD dosError = GetLastError();
- log() << "In File::write(), SetFilePointerEx for '" << _name
- << "' tried to set the file pointer to " << o << " but failed with "
- << errnoWithDescription(dosError) << std::endl;
+ LOGV2(23148,
+ "In File::write(), SetFilePointerEx for '{name}' tried to set the file pointer to "
+ "{o} but failed with {errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "o"_attr = o,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
return;
}
DWORD bytesWritten;
if (WriteFile(_handle, data, len, &bytesWritten, nullptr) == 0) {
_bad = true;
DWORD dosError = GetLastError();
- log() << "In File::write(), WriteFile for '" << _name << "' tried to write " << len
- << " bytes but only wrote " << bytesWritten << " bytes, failing with "
- << errnoWithDescription(dosError);
+ LOGV2(23149,
+ "In File::write(), WriteFile for '{name}' tried to write {len} bytes but only wrote "
+ "{bytesWritten} bytes, failing with {errnoWithDescription_dosError}",
+ "name"_attr = _name,
+ "len"_attr = len,
+ "bytesWritten"_attr = bytesWritten,
+ "errnoWithDescription_dosError"_attr = errnoWithDescription(dosError));
}
}
@@ -203,15 +233,19 @@ intmax_t File::freeSpace(const std::string& path) {
if (statvfs(path.c_str(), &info) == 0) {
return static_cast<intmax_t>(info.f_bavail) * info.f_frsize;
}
- log() << "In File::freeSpace(), statvfs for '" << path << "' failed with "
- << errnoWithDescription();
+ LOGV2(23150,
+ "In File::freeSpace(), statvfs for '{path}' failed with {errnoWithDescription}",
+ "path"_attr = path,
+ "errnoWithDescription"_attr = errnoWithDescription());
return -1;
}
void File::fsync() const {
if (::fsync(_fd)) {
- log() << "In File::fsync(), ::fsync for '" << _name << "' failed with "
- << errnoWithDescription();
+ LOGV2(23151,
+ "In File::fsync(), ::fsync for '{name}' failed with {errnoWithDescription}",
+ "name"_attr = _name,
+ "errnoWithDescription"_attr = errnoWithDescription());
}
}
@@ -225,7 +259,10 @@ fileofs File::len() {
return o;
}
_bad = true;
- log() << "In File::len(), lseek for '" << _name << "' failed with " << errnoWithDescription();
+ LOGV2(23152,
+ "In File::len(), lseek for '{name}' failed with {errnoWithDescription}",
+ "name"_attr = _name,
+ "errnoWithDescription"_attr = errnoWithDescription());
return 0;
}
@@ -244,8 +281,10 @@ void File::open(const char* filename, bool readOnly, bool direct) {
S_IRUSR | S_IWUSR);
_bad = !is_open();
if (_bad) {
- log() << "In File::open(), ::open for '" << _name << "' failed with "
- << errnoWithDescription();
+ LOGV2(23153,
+ "In File::open(), ::open for '{name}' failed with {errnoWithDescription}",
+ "name"_attr = _name,
+ "errnoWithDescription"_attr = errnoWithDescription());
}
}
@@ -253,8 +292,10 @@ void File::read(fileofs o, char* data, unsigned len) {
ssize_t bytesRead = ::pread(_fd, data, len, o);
if (bytesRead == -1) {
_bad = true;
- log() << "In File::read(), ::pread for '" << _name << "' failed with "
- << errnoWithDescription();
+ LOGV2(23154,
+ "In File::read(), ::pread for '{name}' failed with {errnoWithDescription}",
+ "name"_attr = _name,
+ "errnoWithDescription"_attr = errnoWithDescription());
} else if (bytesRead != static_cast<ssize_t>(len)) {
_bad = true;
msgasserted(16569,
@@ -270,9 +311,12 @@ void File::truncate(fileofs size) {
}
if (ftruncate(_fd, size) != 0) {
_bad = true;
- log() << "In File::truncate(), ftruncate for '" << _name
- << "' tried to set the file pointer to " << size << " but failed with "
- << errnoWithDescription() << std::endl;
+ LOGV2(23155,
+ "In File::truncate(), ftruncate for '{name}' tried to set the file pointer to {size} "
+ "but failed with {errnoWithDescription}",
+ "name"_attr = _name,
+ "size"_attr = size,
+ "errnoWithDescription"_attr = errnoWithDescription());
return;
}
}
@@ -281,9 +325,13 @@ void File::write(fileofs o, const char* data, unsigned len) {
ssize_t bytesWritten = ::pwrite(_fd, data, len, o);
if (bytesWritten != static_cast<ssize_t>(len)) {
_bad = true;
- log() << "In File::write(), ::pwrite for '" << _name << "' tried to write " << len
- << " bytes but only wrote " << bytesWritten << " bytes, failing with "
- << errnoWithDescription();
+ LOGV2(23156,
+ "In File::write(), ::pwrite for '{name}' tried to write {len} bytes but only wrote "
+ "{bytesWritten} bytes, failing with {errnoWithDescription}",
+ "name"_attr = _name,
+ "len"_attr = len,
+ "bytesWritten"_attr = bytesWritten,
+ "errnoWithDescription"_attr = errnoWithDescription());
}
}
diff --git a/src/mongo/util/heap_profiler.cpp b/src/mongo/util/heap_profiler.cpp
index 5229fd55620..7d02ed21cc5 100644
--- a/src/mongo/util/heap_profiler.cpp
+++ b/src/mongo/util/heap_profiler.cpp
@@ -38,6 +38,7 @@
#include "mongo/base/static_assert.h"
#include "mongo/config.h"
#include "mongo/db/commands/server_status.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/stacktrace.h"
#include "mongo/util/tcmalloc_parameters_gen.h"
@@ -409,7 +410,7 @@ private:
// disable profiling and then log an error message.
void disable(const char* msg) {
sampleIntervalBytes = 0;
- log() << msg;
+ LOGV2(23157, "{msg}", "msg"_attr = msg);
}
//
@@ -537,7 +538,10 @@ private:
builder.append(frameString);
}
stackInfo.stackObj = builder.obj();
- log() << "heapProfile stack" << stackInfo.stackNum << ": " << stackInfo.stackObj;
+ LOGV2(23158,
+ "heapProfile stack{stackInfo_stackNum}: {stackInfo_stackObj}",
+ "stackInfo_stackNum"_attr = stackInfo.stackNum,
+ "stackInfo_stackObj"_attr = stackInfo.stackObj);
}
//
@@ -563,12 +567,16 @@ private:
const size_t objTableSize = objHashTable.memorySizeBytes();
const size_t stackTableSize = stackHashTable.memorySizeBytes();
const double MB = 1024 * 1024;
- log() << "sampleIntervalBytes " << HeapProfilingSampleIntervalBytes << "; "
- << "maxActiveMemory " << maxActiveMemory / MB << " MB; "
- << "objTableSize " << objTableSize / MB << " MB; "
- << "stackTableSize " << stackTableSize / MB << " MB";
+ LOGV2(23159,
+ "sampleIntervalBytes {HeapProfilingSampleIntervalBytes}; maxActiveMemory "
+ "{maxActiveMemory_MB} MB; objTableSize {objTableSize_MB} MB; stackTableSize "
+ "{stackTableSize_MB} MB",
+ "HeapProfilingSampleIntervalBytes"_attr = HeapProfilingSampleIntervalBytes,
+ "maxActiveMemory_MB"_attr = maxActiveMemory / MB,
+ "objTableSize_MB"_attr = objTableSize / MB,
+ "stackTableSize_MB"_attr = stackTableSize / MB);
// print a stack trace to log somap for post-facto symbolization
- log() << "following stack trace is for heap profiler informational purposes";
+ LOGV2(23160, "following stack trace is for heap profiler informational purposes");
printStackTrace();
logGeneralStats = false;
}
@@ -631,7 +639,7 @@ private:
// importantStacks grows monotonically, so it can accumulate unneeded stacks,
// so we clear it periodically.
if (++numImportantSamples >= kMaxImportantSamples) {
- log() << "clearing importantStacks";
+ LOGV2(23161, "clearing importantStacks");
importantStacks.clear();
numImportantSamples = 0;
}
diff --git a/src/mongo/util/latch_analyzer.cpp b/src/mongo/util/latch_analyzer.cpp
index b60254886d2..67c2821560f 100644
--- a/src/mongo/util/latch_analyzer.cpp
+++ b/src/mongo/util/latch_analyzer.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/client.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/latch_analyzer.h"
@@ -149,10 +150,10 @@ void dumpLevels(const LatchSetState& state) {
return;
}
- log() << "Dumping Latch Identities:";
+ LOGV2(23162, "Dumping Latch Identities:");
auto& identities = *state.identities;
for (auto& identity : identities) {
- log() << "- " << identity->name();
+ LOGV2(23163, "- {identity_name}", "identity_name"_attr = identity->name());
}
}
@@ -227,7 +228,7 @@ void LatchAnalyzer::onAcquire(const latch_detail::Identity& identity) {
fassert(31360, Status(ErrorCodes::HierarchicalAcquisitionLevelViolation, errorMessage));
} else {
- warning() << errorMessage;
+ LOGV2_WARNING(23164, "{errorMessage}", "errorMessage"_attr = errorMessage);
{
stdx::lock_guard lk(_mutex);
@@ -286,7 +287,7 @@ void LatchAnalyzer::onRelease(const latch_detail::Identity& identity) {
fassert(31361, Status(ErrorCodes::HierarchicalAcquisitionLevelViolation, errorMessage));
} else {
- warning() << errorMessage;
+ LOGV2_WARNING(23165, "{errorMessage}", "errorMessage"_attr = errorMessage);
{
stdx::lock_guard lk(_mutex);
diff --git a/src/mongo/util/log.cpp b/src/mongo/util/log.cpp
index 9a9d7099e4a..a60fd216972 100644
--- a/src/mongo/util/log.cpp
+++ b/src/mongo/util/log.cpp
@@ -33,6 +33,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/config.h"
@@ -84,12 +85,12 @@ Status logger::registerExtraLogContextFn(logger::ExtraLogContextFn contextFn) {
bool rotateLogs(bool renameFiles) {
// Rotate on both logv1 and logv2 so all files that need rotation gets rotated
- log() << "Log rotation initiated";
+ LOGV2(23166, "Log rotation initiated");
std::string suffix = "." + terseCurrentTime(false);
Status resultv2 =
logv2::LogManager::global().getGlobalDomainInternal().rotate(renameFiles, suffix);
if (!resultv2.isOK())
- warning() << "Log rotation failed: " << resultv2;
+ LOGV2_WARNING(23168, "Log rotation failed: {resultv2}", "resultv2"_attr = resultv2);
using logger::RotatableFileManager;
RotatableFileManager* manager = logger::globalRotatableFileManager();
@@ -97,14 +98,17 @@ bool rotateLogs(bool renameFiles) {
for (RotatableFileManager::FileNameStatusPairVector::iterator it = result.begin();
it != result.end();
it++) {
- warning() << "Rotating log file " << it->first << " failed: " << it->second.toString();
+ LOGV2_WARNING(23169,
+ "Rotating log file {it_first} failed: {it_second}",
+ "it_first"_attr = it->first,
+ "it_second"_attr = it->second.toString());
}
return resultv2.isOK() && result.empty();
}
void logContext(const char* errmsg) {
if (errmsg) {
- log() << errmsg << std::endl;
+ LOGV2(23167, "{errmsg}", "errmsg"_attr = errmsg);
}
// NOTE: We disable long-line truncation for the stack trace, because the JSON representation of
// the stack trace can sometimes exceed the long line limit.
diff --git a/src/mongo/util/net/hostname_canonicalization.cpp b/src/mongo/util/net/hostname_canonicalization.cpp
index e3710912892..0e9f06d7e3c 100644
--- a/src/mongo/util/net/hostname_canonicalization.cpp
+++ b/src/mongo/util/net/hostname_canonicalization.cpp
@@ -41,6 +41,7 @@
#include <sys/types.h>
#endif
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/net/sockaddr.h"
#include "mongo/util/scopeguard.h"
@@ -90,8 +91,12 @@ std::vector<std::string> getHostFQDNs(std::string hostName, HostnameCanonicaliza
int err;
auto nativeHostName = shim_toNativeString(hostName.c_str());
if ((err = shim_getaddrinfo(nativeHostName.c_str(), nullptr, &hints, &info)) != 0) {
- LOG(3) << "Failed to obtain address information for hostname " << hostName << ": "
- << getAddrInfoStrError(err);
+ LOGV2_DEBUG(23170,
+ 3,
+ "Failed to obtain address information for hostname {hostName}: "
+ "{getAddrInfoStrError_err}",
+ "hostName"_attr = hostName,
+ "getAddrInfoStrError_err"_attr = getAddrInfoStrError(err));
return results;
}
const auto guard = makeGuard(shim_freeaddrinfo);
@@ -141,7 +146,10 @@ std::vector<std::string> getHostFQDNs(std::string hostName, HostnameCanonicaliza
}
if (encounteredErrors) {
- LOG(3) << getNameInfoErrors.str() << " ]";
+ LOGV2_DEBUG(23171,
+ 3,
+ "{getNameInfoErrors_str} ]",
+ "getNameInfoErrors_str"_attr = getNameInfoErrors.str());
}
// Deduplicate the results list
diff --git a/src/mongo/util/net/openssl_init.cpp b/src/mongo/util/net/openssl_init.cpp
index 8f05d3c877a..60096c06756 100644
--- a/src/mongo/util/net/openssl_init.cpp
+++ b/src/mongo/util/net/openssl_init.cpp
@@ -33,6 +33,7 @@
#include "mongo/base/init.h"
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/net/ssl_manager.h"
#include "mongo/util/net/ssl_options.h"
@@ -148,13 +149,16 @@ void setupFIPS() {
#if defined(MONGO_CONFIG_HAVE_FIPS_MODE_SET)
int status = FIPS_mode_set(1);
if (!status) {
- severe() << "can't activate FIPS mode: "
- << SSLManagerInterface::getSSLErrorMessage(ERR_get_error());
+ LOGV2_FATAL(
+ 23173,
+ "can't activate FIPS mode: {SSLManagerInterface_getSSLErrorMessage_ERR_get_error}",
+ "SSLManagerInterface_getSSLErrorMessage_ERR_get_error"_attr =
+ SSLManagerInterface::getSSLErrorMessage(ERR_get_error()));
fassertFailedNoTrace(16703);
}
- log() << "FIPS 140-2 mode activated";
+ LOGV2(23172, "FIPS 140-2 mode activated");
#else
- severe() << "this version of mongodb was not compiled with FIPS support";
+ LOGV2_FATAL(23174, "this version of mongodb was not compiled with FIPS support");
fassertFailedNoTrace(17089);
#endif
}
diff --git a/src/mongo/util/net/sock.cpp b/src/mongo/util/net/sock.cpp
index 03b626f4da1..fffe41871a3 100644
--- a/src/mongo/util/net/sock.cpp
+++ b/src/mongo/util/net/sock.cpp
@@ -57,6 +57,7 @@
#include "mongo/config.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/background.h"
#include "mongo/util/concurrency/value.h"
#include "mongo/util/debug_util.h"
@@ -102,8 +103,13 @@ void networkWarnWithDescription(const Socket& socket, StringData call, int error
}
#endif
auto ewd = errnoWithDescription(errorCode);
- warning() << "Failed to connect to " << socket.remoteAddr().getAddr() << ":"
- << socket.remoteAddr().getPort() << ", in(" << call << "), reason: " << ewd;
+ LOGV2_WARNING(23190,
+ "Failed to connect to {socket_remoteAddr_getAddr}:{socket_remoteAddr_getPort}, "
+ "in({call}), reason: {ewd}",
+ "socket_remoteAddr_getAddr"_attr = socket.remoteAddr().getAddr(),
+ "socket_remoteAddr_getPort"_attr = socket.remoteAddr().getPort(),
+ "call"_attr = call,
+ "ewd"_attr = ewd);
}
const double kMaxConnectTimeoutMS = 5000;
@@ -115,21 +121,27 @@ void setSockTimeouts(int sock, double secs) {
int status =
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<char*>(&timeout), sizeof(DWORD));
if (report && (status == SOCKET_ERROR))
- log() << "unable to set SO_RCVTIMEO: " << errnoWithDescription(WSAGetLastError());
+ LOGV2(23177,
+ "unable to set SO_RCVTIMEO: {errnoWithDescription_WSAGetLastError}",
+ "errnoWithDescription_WSAGetLastError"_attr =
+ errnoWithDescription(WSAGetLastError()));
status =
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<char*>(&timeout), sizeof(DWORD));
if (kDebugBuild && report && (status == SOCKET_ERROR))
- log() << "unable to set SO_SNDTIMEO: " << errnoWithDescription(WSAGetLastError());
+ LOGV2(23178,
+ "unable to set SO_SNDTIMEO: {errnoWithDescription_WSAGetLastError}",
+ "errnoWithDescription_WSAGetLastError"_attr =
+ errnoWithDescription(WSAGetLastError()));
#else
struct timeval tv;
tv.tv_sec = (int)secs;
tv.tv_usec = (int)((long long)(secs * 1000 * 1000) % (1000 * 1000));
bool ok = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(tv)) == 0;
if (report && !ok)
- log() << "unable to set SO_RCVTIMEO";
+ LOGV2(23179, "unable to set SO_RCVTIMEO");
ok = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char*)&tv, sizeof(tv)) == 0;
if (kDebugBuild && report && !ok)
- log() << "unable to set SO_SNDTIMEO";
+ LOGV2(23180, "unable to set SO_SNDTIMEO");
#endif
}
@@ -144,11 +156,15 @@ void disableNagle(int sock) {
#endif
if (setsockopt(sock, level, TCP_NODELAY, (char*)&x, sizeof(x)))
- error() << "disableNagle failed: " << errnoWithDescription();
+ LOGV2_ERROR(23195,
+ "disableNagle failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
#ifdef SO_KEEPALIVE
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&x, sizeof(x)))
- error() << "SO_KEEPALIVE failed: " << errnoWithDescription();
+ LOGV2_ERROR(23196,
+ "SO_KEEPALIVE failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
#endif
setSocketKeepAliveParams(sock);
@@ -166,8 +182,12 @@ SockAddr getLocalAddrForBoundSocketFd(int fd) {
SockAddr result;
int rc = getsockname(fd, result.raw(), &result.addressSize);
if (rc != 0) {
- warning() << "Could not resolve local address for socket with fd " << fd << ": "
- << getAddrInfoStrError(socketGetLastError());
+ LOGV2_WARNING(23191,
+ "Could not resolve local address for socket with fd {fd}: "
+ "{getAddrInfoStrError_socketGetLastError}",
+ "fd"_attr = fd,
+ "getAddrInfoStrError_socketGetLastError"_attr =
+ getAddrInfoStrError(socketGetLastError()));
result = SockAddr();
}
return result;
@@ -337,9 +357,12 @@ bool Socket::connect(SockAddr& remote, Milliseconds connectTimeoutMillis) {
#endif
// No activity for the full duration of the timeout.
if (pollReturn == 0) {
- warning() << "Failed to connect to " << _remote.getAddr() << ":"
- << _remote.getPort() << " after " << connectTimeoutMillis
- << " milliseconds, giving up.";
+ LOGV2_WARNING(23192,
+ "Failed to connect to {remote_getAddr}:{remote_getPort} after "
+ "{connectTimeoutMillis} milliseconds, giving up.",
+ "remote_getAddr"_attr = _remote.getAddr(),
+ "remote_getPort"_attr = _remote.getPort(),
+ "connectTimeoutMillis"_attr = connectTimeoutMillis);
return false;
}
@@ -549,18 +572,29 @@ void Socket::handleSendError(int ret, const char* context) {
const int mongo_errno = errno;
if ((mongo_errno == EAGAIN || mongo_errno == EWOULDBLOCK) && _timeout != 0) {
#endif
- LOG(_logLevel) << "Socket " << context << " send() timed out " << remoteString();
+ LOGV2_DEBUG(23181,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "Socket {context} send() timed out {remoteString}",
+ "context"_attr = context,
+ "remoteString"_attr = remoteString());
throwSocketError(SocketErrorKind::SEND_TIMEOUT, remoteString());
} else if (mongo_errno != EINTR) {
- LOG(_logLevel) << "Socket " << context << " send() " << errnoWithDescription(mongo_errno)
- << ' ' << remoteString();
+ LOGV2_DEBUG(23182,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "Socket {context} send() {errnoWithDescription_mongo_errno} {remoteString}",
+ "context"_attr = context,
+ "errnoWithDescription_mongo_errno"_attr = errnoWithDescription(mongo_errno),
+ "remoteString"_attr = remoteString());
throwSocketError(SocketErrorKind::SEND_ERROR, remoteString());
}
} // namespace mongo
void Socket::handleRecvError(int ret, int len) {
if (ret == 0) {
- LOG(3) << "Socket recv() conn closed? " << remoteString();
+ LOGV2_DEBUG(23183,
+ 3,
+ "Socket recv() conn closed? {remoteString}",
+ "remoteString"_attr = remoteString());
throwSocketError(SocketErrorKind::CLOSED, remoteString());
}
@@ -583,11 +617,18 @@ void Socket::handleRecvError(int ret, int len) {
if (e == EAGAIN && _timeout > 0) {
#endif
// this is a timeout
- LOG(_logLevel) << "Socket recv() timeout " << remoteString();
+ LOGV2_DEBUG(23184,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "Socket recv() timeout {remoteString}",
+ "remoteString"_attr = remoteString());
throwSocketError(SocketErrorKind::RECV_TIMEOUT, remoteString());
}
- LOG(_logLevel) << "Socket recv() " << errnoWithDescription(e) << " " << remoteString();
+ LOGV2_DEBUG(23185,
+ logSeverityV1toV2(_logLevel).toInt(),
+ "Socket recv() {errnoWithDescription_e} {remoteString}",
+ "errnoWithDescription_e"_attr = errnoWithDescription(e),
+ "remoteString"_attr = remoteString());
throwSocketError(SocketErrorKind::RECV_ERROR, remoteString());
}
@@ -638,17 +679,26 @@ bool Socket::isStillConnected() {
// Poll( info[], size, timeout ) - timeout == 0 => nonblocking
int nEvents = socketPoll(&pollInfo, 1, 0);
- LOG(2) << "polling for status of connection to " << remoteString() << ", "
- << (nEvents == 0 ? "no events" : nEvents == -1 ? "error detected" : "event detected");
+ LOGV2_DEBUG(
+ 23186,
+ 2,
+ "polling for status of connection to {remoteString}, "
+ "{nEvents_0_no_events_nEvents_1_error_detected_event_detected}",
+ "remoteString"_attr = remoteString(),
+ "nEvents_0_no_events_nEvents_1_error_detected_event_detected"_attr =
+ (nEvents == 0 ? "no events" : nEvents == -1 ? "error detected" : "event detected"));
if (nEvents == 0) {
// No events incoming, return still connected AFAWK
return true;
} else if (nEvents < 0) {
// Poll itself failed, this is weird, warn and log errno
- warning() << "Socket poll() failed during connectivity check"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")" << causedBy(errnoWithDescription());
+ LOGV2_WARNING(23193,
+ "Socket poll() failed during connectivity check (idle {idleTimeSecs} secs, "
+ "remote host {remoteString}){causedBy_errnoWithDescription}",
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString(),
+ "causedBy_errnoWithDescription"_attr = causedBy(errnoWithDescription()));
// Return true since it's not clear that we're disconnected.
return true;
@@ -671,52 +721,67 @@ bool Socket::isStillConnected() {
if (recvd < 0) {
// An error occurred during recv, warn and log errno
- warning() << "Socket recv() failed during connectivity check"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")"
- << causedBy(errnoWithDescription());
+ LOGV2_WARNING(23194,
+ "Socket recv() failed during connectivity check (idle {idleTimeSecs} "
+ "secs, remote host {remoteString}){causedBy_errnoWithDescription}",
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString(),
+ "causedBy_errnoWithDescription"_attr = causedBy(errnoWithDescription()));
} else if (recvd > 0) {
// We got nonzero data from this socket, very weird?
// Log and warn at runtime, log and abort at devtime
// TODO: Dump the data to the log somehow?
- error() << "Socket found pending " << recvd
- << " bytes of data during connectivity check"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")";
+ LOGV2_ERROR(23197,
+ "Socket found pending {recvd} bytes of data during connectivity check "
+ "(idle {idleTimeSecs} secs, remote host {remoteString})",
+ "recvd"_attr = recvd,
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString());
if (kDebugBuild) {
std::string hex = hexdump(testBuf, recvd);
- error() << "Hex dump of stale log data: " << hex;
+ LOGV2_ERROR(23198, "Hex dump of stale log data: {hex}", "hex"_attr = hex);
}
dassert(false);
} else {
// recvd == 0, socket closed remotely, just return false
- LOG(0) << "Socket closed remotely, no longer connected"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")";
+ LOGV2(23187,
+ "Socket closed remotely, no longer connected (idle {idleTimeSecs} secs, remote "
+ "host {remoteString})",
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString());
}
} else if (pollInfo.revents & POLLHUP) {
// A hangup has occurred on this socket
- LOG(0) << "Socket hangup detected, no longer connected"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")";
+ LOGV2(23188,
+ "Socket hangup detected, no longer connected (idle {idleTimeSecs} secs, remote host "
+ "{remoteString})",
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString());
} else if (pollInfo.revents & POLLERR) {
// An error has occurred on this socket
- LOG(0) << "Socket error detected, no longer connected"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")";
+ LOGV2(23189,
+ "Socket error detected, no longer connected (idle {idleTimeSecs} secs, remote host "
+ "{remoteString})",
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString());
} else if (pollInfo.revents & POLLNVAL) {
// Socket descriptor itself is weird
// Log and warn at runtime, log and abort at devtime
- error() << "Socket descriptor detected as invalid"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")";
+ LOGV2_ERROR(23199,
+ "Socket descriptor detected as invalid (idle {idleTimeSecs} secs, remote host "
+ "{remoteString})",
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString());
dassert(false);
} else {
// Don't know what poll is saying here
// Log and warn at runtime, log and abort at devtime
- error() << "Socket had unknown event (" << static_cast<int>(pollInfo.revents) << ")"
- << " (idle " << idleTimeSecs << " secs,"
- << " remote host " << remoteString() << ")";
+ LOGV2_ERROR(23200,
+ "Socket had unknown event ({static_cast_int_pollInfo_revents}) (idle "
+ "{idleTimeSecs} secs, remote host {remoteString})",
+ "static_cast_int_pollInfo_revents"_attr = static_cast<int>(pollInfo.revents),
+ "idleTimeSecs"_attr = idleTimeSecs,
+ "remoteString"_attr = remoteString());
dassert(false);
}
diff --git a/src/mongo/util/net/sockaddr.cpp b/src/mongo/util/net/sockaddr.cpp
index ed4135d1eb7..9e2d81571f6 100644
--- a/src/mongo/util/net/sockaddr.cpp
+++ b/src/mongo/util/net/sockaddr.cpp
@@ -54,6 +54,7 @@
#endif
#include "mongo/bson/util/builder.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/itoa.h"
#include "mongo/util/log.h"
@@ -157,8 +158,10 @@ SockAddr::SockAddr(StringData target, int port, sa_family_t familyHint)
// we were unsuccessful
if (_hostOrIp != "0.0.0.0") { // don't log if this as it is a
// CRT construction and log() may not work yet.
- log() << "getaddrinfo(\"" << _hostOrIp
- << "\") failed: " << getAddrInfoStrError(addrErr.err);
+ LOGV2(23175,
+ "getaddrinfo(\"{hostOrIp}\") failed: {getAddrInfoStrError_addrErr_err}",
+ "hostOrIp"_attr = _hostOrIp,
+ "getAddrInfoStrError_addrErr_err"_attr = getAddrInfoStrError(addrErr.err));
_isValid = false;
return;
}
@@ -187,7 +190,10 @@ std::vector<SockAddr> SockAddr::createAll(StringData target, int port, sa_family
auto addrErr = resolveAddrInfo(hostOrIp, port, familyHint);
if (addrErr.err) {
- log() << "getaddrinfo(\"" << hostOrIp << "\") failed: " << getAddrInfoStrError(addrErr.err);
+ LOGV2(23176,
+ "getaddrinfo(\"{hostOrIp}\") failed: {getAddrInfoStrError_addrErr_err}",
+ "hostOrIp"_attr = hostOrIp,
+ "getAddrInfoStrError_addrErr_err"_attr = getAddrInfoStrError(addrErr.err));
return {};
}
diff --git a/src/mongo/util/net/socket_utils.cpp b/src/mongo/util/net/socket_utils.cpp
index f58ff484ec7..42c2e38eac8 100644
--- a/src/mongo/util/net/socket_utils.cpp
+++ b/src/mongo/util/net/socket_utils.cpp
@@ -54,6 +54,7 @@
#endif
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/concurrency/value.h"
#include "mongo/util/errno_util.h"
#include "mongo/util/log.h"
@@ -69,7 +70,9 @@ const struct WinsockInit {
WinsockInit() {
WSADATA d;
if (WSAStartup(MAKEWORD(2, 2), &d) != 0) {
- log() << "ERROR: wsastartup failed " << errnoWithDescription();
+ LOGV2(23201,
+ "ERROR: wsastartup failed {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
quickExit(EXIT_NTSERVICE_ERROR);
}
}
@@ -114,7 +117,9 @@ void setSocketKeepAliveParams(int sock,
// Return seconds
return val ? (val.get() / 1000) : default_value;
}
- error() << "can't get KeepAlive parameter: " << withval.getStatus();
+ LOGV2_ERROR(23203,
+ "can't get KeepAlive parameter: {withval_getStatus}",
+ "withval_getStatus"_attr = withval.getStatus());
return default_value;
};
@@ -136,7 +141,9 @@ void setSocketKeepAliveParams(int sock,
&sent,
nullptr,
nullptr)) {
- error() << "failed setting keepalive values: " << WSAGetLastError();
+ LOGV2_ERROR(23204,
+ "failed setting keepalive values: {WSAGetLastError}",
+ "WSAGetLastError"_attr = WSAGetLastError());
}
}
#elif defined(__APPLE__) || defined(__linux__)
@@ -146,13 +153,19 @@ void setSocketKeepAliveParams(int sock,
socklen_t len = sizeof(optval);
if (getsockopt(sock, level, optnum, (char*)&optval, &len)) {
- error() << "can't get " << optname << ": " << errnoWithDescription();
+ LOGV2_ERROR(23205,
+ "can't get {optname}: {errnoWithDescription}",
+ "optname"_attr = optname,
+ "errnoWithDescription"_attr = errnoWithDescription());
}
if (optval > maxval) {
optval = maxval;
if (setsockopt(sock, level, optnum, (char*)&optval, sizeof(optval))) {
- error() << "can't set " << optname << ": " << errnoWithDescription();
+ LOGV2_ERROR(23206,
+ "can't set {optname}: {errnoWithDescription}",
+ "optname"_attr = optname,
+ "errnoWithDescription"_attr = errnoWithDescription());
}
}
};
@@ -196,7 +209,9 @@ std::string getHostName() {
char buf[256];
int ec = gethostname(buf, 127);
if (ec || *buf == 0) {
- log() << "can't get this server's hostname " << errnoWithDescription();
+ LOGV2(23202,
+ "can't get this server's hostname {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return "";
}
return buf;
diff --git a/src/mongo/util/net/ssl_manager.cpp b/src/mongo/util/net/ssl_manager.cpp
index d0b6ae3988f..1fcc08f0205 100644
--- a/src/mongo/util/net/ssl_manager.cpp
+++ b/src/mongo/util/net/ssl_manager.cpp
@@ -42,6 +42,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/config.h"
#include "mongo/db/commands/server_status.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/overflow_arithmetic.h"
#include "mongo/transport/session.h"
#include "mongo/util/hex.h"
@@ -553,11 +554,21 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SSLManagerLogger, ("SSLManager", "GlobalLog
if (!isSSLServer || (sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled)) {
const auto& config = theSSLManager->getSSLConfiguration();
if (!config.clientSubjectName.empty()) {
- LOG(1) << "Client Certificate Name: " << config.clientSubjectName;
+ LOGV2_DEBUG(23214,
+ 1,
+ "Client Certificate Name: {config_clientSubjectName}",
+ "config_clientSubjectName"_attr = config.clientSubjectName);
}
if (!config.serverSubjectName().empty()) {
- LOG(1) << "Server Certificate Name: " << config.serverSubjectName();
- LOG(1) << "Server Certificate Expiration: " << config.serverCertificateExpirationDate;
+ LOGV2_DEBUG(23215,
+ 1,
+ "Server Certificate Name: {config_serverSubjectName}",
+ "config_serverSubjectName"_attr = config.serverSubjectName());
+ LOGV2_DEBUG(23216,
+ 1,
+ "Server Certificate Expiration: {config_serverCertificateExpirationDate}",
+ "config_serverCertificateExpirationDate"_attr =
+ config.serverCertificateExpirationDate);
}
}
@@ -594,8 +605,12 @@ Status SSLX509Name::normalizeStrings() {
break;
}
default:
- LOG(1) << "Certificate subject name contains unknown string type: "
- << entry.type << " (string value is \"" << entry.value << "\")";
+ LOGV2_DEBUG(23217,
+ 1,
+ "Certificate subject name contains unknown string type: "
+ "{entry_type} (string value is \"{entry_value}\")",
+ "entry_type"_attr = entry.type,
+ "entry_value"_attr = entry.value);
break;
}
}
@@ -677,13 +692,16 @@ bool SSLConfiguration::isClusterMember(SSLX509Name subject) const {
bool SSLConfiguration::isClusterMember(StringData subjectName) const {
auto swClient = parseDN(subjectName);
if (!swClient.isOK()) {
- warning() << "Unable to parse client subject name: " << swClient.getStatus();
+ LOGV2_WARNING(23219,
+ "Unable to parse client subject name: {swClient_getStatus}",
+ "swClient_getStatus"_attr = swClient.getStatus());
return false;
}
auto& client = swClient.getValue();
auto status = client.normalizeStrings();
if (!status.isOK()) {
- warning() << "Unable to normalize client subject name: " << status;
+ LOGV2_WARNING(
+ 23220, "Unable to normalize client subject name: {status}", "status"_attr = status);
return false;
}
@@ -1110,8 +1128,11 @@ void recordTLSVersion(TLSVersion version, const HostAndPort& hostForLogging) {
}
if (!versionString.empty()) {
- log() << "Accepted connection with TLS Version " << versionString << " from connection "
- << hostForLogging;
+ LOGV2(
+ 23218,
+ "Accepted connection with TLS Version {versionString} from connection {hostForLogging}",
+ "versionString"_attr = versionString,
+ "hostForLogging"_attr = hostForLogging);
}
}
@@ -1139,11 +1160,14 @@ bool hostNameMatchForX509Certificates(std::string nameToMatch, std::string certH
}
void tlsEmitWarningExpiringClientCertificate(const SSLX509Name& peer) {
- warning() << "Peer certificate '" << peer << "' expires soon";
+ LOGV2_WARNING(23221, "Peer certificate '{peer}' expires soon", "peer"_attr = peer);
}
void tlsEmitWarningExpiringClientCertificate(const SSLX509Name& peer, Days days) {
- warning() << "Peer certificate '" << peer << "' expires in " << days;
+ LOGV2_WARNING(23222,
+ "Peer certificate '{peer}' expires in {days}",
+ "peer"_attr = peer,
+ "days"_attr = days);
}
} // namespace mongo
diff --git a/src/mongo/util/net/ssl_manager_apple.cpp b/src/mongo/util/net/ssl_manager_apple.cpp
index 970db6c9d3b..3ae8a983904 100644
--- a/src/mongo/util/net/ssl_manager_apple.cpp
+++ b/src/mongo/util/net/ssl_manager_apple.cpp
@@ -43,6 +43,7 @@
#include "mongo/base/status_with.h"
#include "mongo/crypto/sha1_block.h"
#include "mongo/crypto/sha256_block.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/random.h"
#include "mongo/util/base64.h"
#include "mongo/util/concurrency/mutex.h"
@@ -527,8 +528,9 @@ StatusWith<std::vector<std::string>> extractSubjectAlternateNames(::CFDictionary
if (swCIDRValue.isOK()) {
swNameStr = swCIDRValue.getValue().toString();
if (san == kDNS) {
- warning() << "You have an IP Address in the DNS Name field on your "
- "certificate. This formulation is deprecated.";
+ LOGV2_WARNING(23208,
+ "You have an IP Address in the DNS Name field on your "
+ "certificate. This formulation is deprecated.");
}
}
ret.push_back(swNameStr.getValue());
@@ -1448,11 +1450,11 @@ Future<SSLPeerInfo> SSLManagerApple::parseAndValidatePeerCertificate(
const auto badCert = [&](StringData msg, bool warn = false) -> Future<SSLPeerInfo> {
constexpr StringData prefix = "SSL peer certificate validation failed: "_sd;
if (warn) {
- warning() << prefix << msg;
+ LOGV2_WARNING(23209, "{prefix}{msg}", "prefix"_attr = prefix, "msg"_attr = msg);
return Future<SSLPeerInfo>::makeReady(SSLPeerInfo(sniName));
} else {
std::string m = str::stream() << prefix << msg << "; connection rejected";
- error() << m;
+ LOGV2_ERROR(23212, "{m}", "m"_attr = m);
return Status(ErrorCodes::SSLHandshakeFailed, m);
}
};
@@ -1540,7 +1542,10 @@ Future<SSLPeerInfo> SSLManagerApple::parseAndValidatePeerCertificate(
return swPeerSubjectName.getStatus();
}
const auto peerSubjectName = std::move(swPeerSubjectName.getValue());
- LOG(2) << "Accepted TLS connection from peer: " << peerSubjectName;
+ LOGV2_DEBUG(23207,
+ 2,
+ "Accepted TLS connection from peer: {peerSubjectName}",
+ "peerSubjectName"_attr = peerSubjectName);
// Server side.
if (remoteHost.empty()) {
@@ -1563,7 +1568,7 @@ Future<SSLPeerInfo> SSLManagerApple::parseAndValidatePeerCertificate(
// If client and server certificate are the same, log a warning.
if (_sslConfiguration.serverSubjectName() == peerSubjectName) {
- warning() << "Client connecting with server's own TLS certificate";
+ LOGV2_WARNING(23210, "Client connecting with server's own TLS certificate");
}
// If this is an SSL server context (on a mongod/mongos)
@@ -1635,9 +1640,9 @@ Future<SSLPeerInfo> SSLManagerApple::parseAndValidatePeerCertificate(
if (!sanMatch && !cnMatch) {
const auto msg = certErr.str();
if (_allowInvalidCertificates || _allowInvalidHostnames || isUnixDomainSocket(remoteHost)) {
- warning() << msg;
+ LOGV2_WARNING(23211, "{msg}", "msg"_attr = msg);
} else {
- error() << msg;
+ LOGV2_ERROR(23213, "{msg}", "msg"_attr = msg);
return Status(ErrorCodes::SSLHandshakeFailed, msg);
}
}
diff --git a/src/mongo/util/net/ssl_manager_openssl.cpp b/src/mongo/util/net/ssl_manager_openssl.cpp
index 702ae32b4c3..bb709db0c79 100644
--- a/src/mongo/util/net/ssl_manager_openssl.cpp
+++ b/src/mongo/util/net/ssl_manager_openssl.cpp
@@ -48,6 +48,7 @@
#include "mongo/base/secure_allocator.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/transport/session.h"
#include "mongo/util/concurrency/mutex.h"
@@ -192,7 +193,8 @@ bool enableECDHE(SSL_CTX* const ctx) {
if (SSL_CTX_ctrl(ctx, 94, 1, nullptr) != 1) {
// If manually setting the configuration option failed, use a hard coded curve
if (!useDefaultECKey(ctx)) {
- warning() << "Failed to enable ECDHE due to a lack of support from system libraries.";
+ LOGV2_WARNING(23230,
+ "Failed to enable ECDHE due to a lack of support from system libraries.");
return false;
}
}
@@ -673,7 +675,7 @@ SSLConnectionOpenSSL::SSLConnectionOpenSSL(SSL_CTX* context,
if (len > 0) {
int toBIO = BIO_write(networkBIO, initialBytes, len);
if (toBIO != len) {
- LOG(3) << "Failed to write initial network data to the SSL BIO layer";
+ LOGV2_DEBUG(23223, 3, "Failed to write initial network data to the SSL BIO layer");
throwSocketError(SocketErrorKind::RECV_ERROR, socket->remoteString());
}
}
@@ -750,7 +752,9 @@ int SSLManagerOpenSSL::password_cb(char* buf, int num, int rwflag, void* userdat
auto pwFetcher = static_cast<PasswordFetcher*>(userdata);
auto swPassword = pwFetcher->fetchPassword();
if (!swPassword.isOK()) {
- error() << "Unable to fetch password: " << swPassword.getStatus();
+ LOGV2_ERROR(23239,
+ "Unable to fetch password: {swPassword_getStatus}",
+ "swPassword_getStatus"_attr = swPassword.getStatus());
return -1;
}
StringData password = std::move(swPassword.getValue());
@@ -1305,8 +1309,10 @@ int ocspClientCallback(SSL* ssl, void* arg) {
UniqueX509 peerCert(SSL_get_peer_certificate(ssl));
if (!peerCert) {
- LOG(1) << "Could not get peer certificate from SSL object in OCSP verification callback. "
- << "Will continue with the connection.";
+ LOGV2_DEBUG(23224,
+ 1,
+ "Could not get peer certificate from SSL object in OCSP verification callback. "
+ "Will continue with the connection.");
return OCSP_CLIENT_RESPONSE_ACCEPTABLE;
}
@@ -1328,14 +1334,19 @@ int ocspClientCallback(SSL* ssl, void* arg) {
// CRLs or check with the OCSP responder ourselves. If it is true, then we are done.
if (!swStapleOK.isOK()) {
if (swStapleOK.getStatus() == ErrorCodes::OCSPCertificateStatusRevoked) {
- LOG(1) << "Stapled Certificate validation failed: " << swStapleOK.getStatus().reason();
+ LOGV2_DEBUG(23225,
+ 1,
+ "Stapled Certificate validation failed: {swStapleOK_getStatus_reason}",
+ "swStapleOK_getStatus_reason"_attr = swStapleOK.getStatus().reason());
return OCSP_CLIENT_RESPONSE_NOT_ACCEPTABLE;
}
return OCSP_CLIENT_RESPONSE_ERROR;
} else if (!swStapleOK.getValue()) {
- LOG(1) << "Stapled Certificate validation failed: Stapled response does not "
- << "contain status information regarding the peer certificate.";
+ LOGV2_DEBUG(23226,
+ 1,
+ "Stapled Certificate validation failed: Stapled response does not contain "
+ "status information regarding the peer certificate.");
return OCSP_CLIENT_RESPONSE_NOT_ACCEPTABLE;
}
@@ -1378,7 +1389,8 @@ Status stapleOCSPResponse(SSL_CTX* context) {
if (!cert) {
// Because OpenSSL 1.0.1 doesn't allow accessing the internal cert object of a
// SSL context, so this shouldn't fail the program.
- warning() << "Could not staple because could not get certificate from SSL Context.";
+ LOGV2_WARNING(23231,
+ "Could not staple because could not get certificate from SSL Context.");
return Status::OK();
}
@@ -1398,7 +1410,7 @@ Status stapleOCSPResponse(SSL_CTX* context) {
auto swOCSPContext = extractOcspUris(context, cert, intermediateCerts.get());
if (!swOCSPContext.isOK()) {
- warning() << "Could not staple OCSP response to outgoing certificate.";
+ LOGV2_WARNING(23232, "Could not staple OCSP response to outgoing certificate.");
return swOCSPContext.getStatus();
}
@@ -1407,7 +1419,7 @@ Status stapleOCSPResponse(SSL_CTX* context) {
dispatchRequests(context, std::move(intermediateCerts), ocspContext)
.getAsync([context](StatusWith<std::pair<Status, UniqueOCSPResponse>> swResponse) {
if (!swResponse.isOK()) {
- warning() << "Could not staple OCSP response to outgoing certificate.";
+ LOGV2_WARNING(23233, "Could not staple OCSP response to outgoing certificate.");
return;
}
@@ -1569,8 +1581,10 @@ Status SSLManagerOpenSSL::initSSLContext(SSL_CTX* context,
UniqueDHParams dhparams = makeDefaultDHParameters();
if (!dhparams || SSL_CTX_set_tmp_dh(context, dhparams.get()) != 1) {
- error() << "Failed to set default DH parameters: "
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(
+ 23240,
+ "Failed to set default DH parameters: {getSSLErrorMessage_ERR_get_error}",
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
}
}
}
@@ -1598,14 +1612,14 @@ unsigned long long SSLManagerOpenSSL::_convertASN1ToMillis(ASN1_TIME* asn1time)
ON_BLOCK_EXIT([&] { BIO_free(outBIO); });
if (timeError <= 0) {
- error() << "ASN1_TIME_print failed or wrote no data.";
+ LOGV2_ERROR(23241, "ASN1_TIME_print failed or wrote no data.");
return 0;
}
char dateChar[DATE_LEN];
timeError = BIO_gets(outBIO, dateChar, DATE_LEN);
if (timeError <= 0) {
- error() << "BIO_gets call failed to transfer contents to buf";
+ LOGV2_ERROR(23242, "BIO_gets call failed to transfer contents to buf");
return 0;
}
@@ -1634,22 +1648,30 @@ bool SSLManagerOpenSSL::_parseAndValidateCertificate(const std::string& keyFile,
Date_t* serverCertificateExpirationDate) {
BIO* inBIO = BIO_new(BIO_s_file());
if (inBIO == nullptr) {
- error() << "failed to allocate BIO object: " << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23243,
+ "failed to allocate BIO object: {getSSLErrorMessage_ERR_get_error}",
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
ON_BLOCK_EXIT([&] { BIO_free(inBIO); });
if (BIO_read_filename(inBIO, keyFile.c_str()) <= 0) {
- error() << "cannot read key file when setting subject name: " << keyFile << ' '
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23244,
+ "cannot read key file when setting subject name: {keyFile} "
+ "{getSSLErrorMessage_ERR_get_error}",
+ "keyFile"_attr = keyFile,
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
X509* x509 = PEM_read_bio_X509(
inBIO, nullptr, &SSLManagerOpenSSL::password_cb, static_cast<void*>(&keyPassword));
if (x509 == nullptr) {
- error() << "cannot retrieve certificate from keyfile: " << keyFile << ' '
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23245,
+ "cannot retrieve certificate from keyfile: {keyFile} "
+ "{getSSLErrorMessage_ERR_get_error}",
+ "keyFile"_attr = keyFile,
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
ON_BLOCK_EXIT([&] { X509_free(x509); });
@@ -1658,18 +1680,18 @@ bool SSLManagerOpenSSL::_parseAndValidateCertificate(const std::string& keyFile,
if (serverCertificateExpirationDate != nullptr) {
unsigned long long notBeforeMillis = _convertASN1ToMillis(X509_get_notBefore(x509));
if (notBeforeMillis == 0) {
- error() << "date conversion failed";
+ LOGV2_ERROR(23246, "date conversion failed");
return false;
}
unsigned long long notAfterMillis = _convertASN1ToMillis(X509_get_notAfter(x509));
if (notAfterMillis == 0) {
- error() << "date conversion failed";
+ LOGV2_ERROR(23247, "date conversion failed");
return false;
}
if ((notBeforeMillis > curTimeMillis64()) || (curTimeMillis64() > notAfterMillis)) {
- severe() << "The provided SSL certificate is expired or not yet valid.";
+ LOGV2_FATAL(23265, "The provided SSL certificate is expired or not yet valid.");
fassertFailedNoTrace(28652);
}
@@ -1683,21 +1705,27 @@ bool SSLManagerOpenSSL::_setupPEM(SSL_CTX* context,
const std::string& keyFile,
PasswordFetcher* password) {
if (SSL_CTX_use_certificate_chain_file(context, keyFile.c_str()) != 1) {
- error() << "cannot read certificate file: " << keyFile << ' '
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23248,
+ "cannot read certificate file: {keyFile} {getSSLErrorMessage_ERR_get_error}",
+ "keyFile"_attr = keyFile,
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
BIO* inBio = BIO_new(BIO_s_file());
if (!inBio) {
- error() << "failed to allocate BIO object: " << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23249,
+ "failed to allocate BIO object: {getSSLErrorMessage_ERR_get_error}",
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
const auto bioGuard = makeGuard([&inBio]() { BIO_free(inBio); });
if (BIO_read_filename(inBio, keyFile.c_str()) <= 0) {
- error() << "cannot read PEM key file: " << keyFile << ' '
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23250,
+ "cannot read PEM key file: {keyFile} {getSSLErrorMessage_ERR_get_error}",
+ "keyFile"_attr = keyFile,
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
@@ -1706,21 +1734,27 @@ bool SSLManagerOpenSSL::_setupPEM(SSL_CTX* context,
void* userdata = static_cast<void*>(password);
EVP_PKEY* privateKey = PEM_read_bio_PrivateKey(inBio, nullptr, password_cb, userdata);
if (!privateKey) {
- error() << "cannot read PEM key file: " << keyFile << ' '
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23251,
+ "cannot read PEM key file: {keyFile} {getSSLErrorMessage_ERR_get_error}",
+ "keyFile"_attr = keyFile,
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
const auto privateKeyGuard = makeGuard([&privateKey]() { EVP_PKEY_free(privateKey); });
if (SSL_CTX_use_PrivateKey(context, privateKey) != 1) {
- error() << "cannot use PEM key file: " << keyFile << ' '
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23252,
+ "cannot use PEM key file: {keyFile} {getSSLErrorMessage_ERR_get_error}",
+ "keyFile"_attr = keyFile,
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
// Verify that the certificate and the key go together.
if (SSL_CTX_check_private_key(context) != 1) {
- error() << "SSL certificate validation: " << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23253,
+ "SSL certificate validation: {getSSLErrorMessage_ERR_get_error}",
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
@@ -1786,12 +1820,16 @@ bool SSLManagerOpenSSL::_setupCRL(SSL_CTX* context, const std::string& crlFile)
int status = X509_load_crl_file(lookup, crlFile.c_str(), X509_FILETYPE_PEM);
if (status == 0) {
- error() << "cannot read CRL file: " << crlFile << ' '
- << getSSLErrorMessage(ERR_get_error());
+ LOGV2_ERROR(23254,
+ "cannot read CRL file: {crlFile} {getSSLErrorMessage_ERR_get_error}",
+ "crlFile"_attr = crlFile,
+ "getSSLErrorMessage_ERR_get_error"_attr = getSSLErrorMessage(ERR_get_error()));
return false;
}
- log() << "ssl imported " << status << " revoked certificate" << ((status == 1) ? "" : "s")
- << " from the revocation list.";
+ LOGV2(23227,
+ "ssl imported {status} revoked certificate{status_1_s} from the revocation list.",
+ "status"_attr = status,
+ "status_1_s"_attr = ((status == 1) ? "" : "s"));
return true;
}
@@ -1838,7 +1876,7 @@ void SSLManagerOpenSSL::_flushNetworkBIO(SSLConnectionOpenSSL* conn) {
int toBIO = BIO_write(conn->networkBIO, buffer, numRead);
if (toBIO != numRead) {
- LOG(3) << "Failed to write network data to the SSL BIO layer";
+ LOGV2_DEBUG(23228, 3, "Failed to write network data to the SSL BIO layer");
throwSocketError(SocketErrorKind::RECV_ERROR, conn->socket->remoteString());
}
}
@@ -2008,12 +2046,12 @@ Future<SSLPeerInfo> SSLManagerOpenSSL::parseAndValidatePeerCertificate(
if (_weakValidation) {
// do not give warning if certificate warnings are suppressed
if (!_suppressNoCertificateWarning) {
- warning() << "no SSL certificate provided by peer";
+ LOGV2_WARNING(23234, "no SSL certificate provided by peer");
}
return SSLPeerInfo(sni);
} else {
auto msg = "no SSL certificate provided by peer; connection rejected";
- error() << msg;
+ LOGV2_ERROR(23255, "{msg}", "msg"_attr = msg);
return Status(ErrorCodes::SSLHandshakeFailed, msg);
}
}
@@ -2023,14 +2061,17 @@ Future<SSLPeerInfo> SSLManagerOpenSSL::parseAndValidatePeerCertificate(
if (result != X509_V_OK) {
if (_allowInvalidCertificates) {
- warning() << "SSL peer certificate validation failed: "
- << X509_verify_cert_error_string(result);
+ LOGV2_WARNING(
+ 23235,
+ "SSL peer certificate validation failed: {X509_verify_cert_error_string_result}",
+ "X509_verify_cert_error_string_result"_attr =
+ X509_verify_cert_error_string(result));
return SSLPeerInfo(sni);
} else {
str::stream msg;
msg << "SSL peer certificate validation failed: "
<< X509_verify_cert_error_string(result);
- error() << msg.ss.str();
+ LOGV2_ERROR(23256, "{msg_ss_str}", "msg_ss_str"_attr = msg.ss.str());
return Status(ErrorCodes::SSLHandshakeFailed, msg);
}
}
@@ -2042,7 +2083,10 @@ Future<SSLPeerInfo> SSLManagerOpenSSL::parseAndValidatePeerCertificate(
// TODO: check optional cipher restriction, using cert.
auto peerSubject = getCertificateSubjectX509Name(peerCert);
- LOG(2) << "Accepted TLS connection from peer: " << peerSubject;
+ LOGV2_DEBUG(23229,
+ 2,
+ "Accepted TLS connection from peer: {peerSubject}",
+ "peerSubject"_attr = peerSubject);
StatusWith<stdx::unordered_set<RoleName>> swPeerCertificateRoles = _parsePeerRoles(peerCert);
if (!swPeerCertificateRoles.isOK()) {
@@ -2072,7 +2116,7 @@ Future<SSLPeerInfo> SSLManagerOpenSSL::parseAndValidatePeerCertificate(
// If client and server certificate are the same, log a warning.
if (_sslConfiguration.serverSubjectName() == peerSubject) {
- warning() << "Client connecting with server's own TLS certificate";
+ LOGV2_WARNING(23236, "Client connecting with server's own TLS certificate");
}
// void futures are default constructed as ready futures.
@@ -2112,8 +2156,9 @@ Future<SSLPeerInfo> SSLManagerOpenSSL::parseAndValidatePeerCertificate(
reinterpret_cast<char*>(ASN1_STRING_data(currentName->d.dNSName)));
auto swCIDRDNSName = CIDR::parse(dnsName);
if (swCIDRDNSName.isOK()) {
- warning() << "You have an IP Address in the DNS Name field on your "
- "certificate. This formulation is deprecated.";
+ LOGV2_WARNING(23237,
+ "You have an IP Address in the DNS Name field on your "
+ "certificate. This formulation is deprecated.");
if (swCIDRRemoteHost.isOK() &&
swCIDRRemoteHost.getValue() == swCIDRDNSName.getValue()) {
sanMatch = true;
@@ -2178,9 +2223,9 @@ Future<SSLPeerInfo> SSLManagerOpenSSL::parseAndValidatePeerCertificate(
<< remoteHost << " does not match " << certificateNames.str();
std::string msg = msgBuilder.str();
if (_allowInvalidCertificates || _allowInvalidHostnames || isUnixDomainSocket(remoteHost)) {
- warning() << msg;
+ LOGV2_WARNING(23238, "{msg}", "msg"_attr = msg);
} else {
- error() << msg;
+ LOGV2_ERROR(23257, "{msg}", "msg"_attr = msg);
return Future<SSLPeerInfo>::makeReady(Status(ErrorCodes::SSLHandshakeFailed, msg));
}
}
@@ -2249,32 +2294,39 @@ void SSLManagerOpenSSL::_handleSSLError(SSLConnectionOpenSSL* conn, int ret) {
// manner.
errToThrow = (code == SSL_ERROR_WANT_READ) ? SocketErrorKind::RECV_ERROR
: SocketErrorKind::SEND_ERROR;
- error() << "SSL: " << code << ", possibly timed out during connect";
+ LOGV2_ERROR(
+ 23258, "SSL: {code}, possibly timed out during connect", "code"_attr = code);
break;
case SSL_ERROR_ZERO_RETURN:
// TODO: Check if we can avoid throwing an exception for this condition
// If so, change error() back to LOG(3)
- error() << "SSL network connection closed";
+ LOGV2_ERROR(23259, "SSL network connection closed");
break;
case SSL_ERROR_SYSCALL:
// If ERR_get_error returned 0, the error queue is empty
// check the return value of the actual SSL operation
if (err != 0) {
- error() << "SSL: " << getSSLErrorMessage(err);
+ LOGV2_ERROR(23260,
+ "SSL: {getSSLErrorMessage_err}",
+ "getSSLErrorMessage_err"_attr = getSSLErrorMessage(err));
} else if (ret == 0) {
- error() << "Unexpected EOF encountered during SSL communication";
+ LOGV2_ERROR(23261, "Unexpected EOF encountered during SSL communication");
} else {
- error() << "The SSL BIO reported an I/O error " << errnoWithDescription();
+ LOGV2_ERROR(23262,
+ "The SSL BIO reported an I/O error {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
}
break;
case SSL_ERROR_SSL: {
- error() << "SSL: " << getSSLErrorMessage(err);
+ LOGV2_ERROR(23263,
+ "SSL: {getSSLErrorMessage_err}",
+ "getSSLErrorMessage_err"_attr = getSSLErrorMessage(err));
break;
}
default:
- error() << "unrecognized SSL error";
+ LOGV2_ERROR(23264, "unrecognized SSL error");
break;
}
_flushNetworkBIO(conn);
diff --git a/src/mongo/util/net/ssl_manager_test.cpp b/src/mongo/util/net/ssl_manager_test.cpp
index a7335970125..c5c05ff5bf3 100644
--- a/src/mongo/util/net/ssl_manager_test.cpp
+++ b/src/mongo/util/net/ssl_manager_test.cpp
@@ -34,6 +34,7 @@
#include "mongo/util/net/ssl_manager.h"
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -78,10 +79,17 @@ TEST(SSLManager, matchHostname) {
for (const auto& test : tests) {
if (bool(test.expected) != hostNameMatchForX509Certificates(test.hostname, test.certName)) {
failure = true;
- LOG(1) << "Failure for Hostname: " << test.hostname
- << " Certificate: " << test.certName;
+ LOGV2_DEBUG(23266,
+ 1,
+ "Failure for Hostname: {test_hostname} Certificate: {test_certName}",
+ "test_hostname"_attr = test.hostname,
+ "test_certName"_attr = test.certName);
} else {
- LOG(1) << "Passed for Hostname: " << test.hostname << " Certificate: " << test.certName;
+ LOGV2_DEBUG(23267,
+ 1,
+ "Passed for Hostname: {test_hostname} Certificate: {test_certName}",
+ "test_hostname"_attr = test.hostname,
+ "test_certName"_attr = test.certName);
}
}
ASSERT_FALSE(failure);
@@ -358,7 +366,7 @@ TEST(SSLManager, DNParsingAndNormalization) {
{"2.5.4.7", "大田区, 東京都"}}}};
for (const auto& test : tests) {
- log() << "Testing DN \"" << test.first << "\"";
+ LOGV2(23268, "Testing DN \"{test_first}\"", "test_first"_attr = test.first);
auto swDN = parseDN(test.first);
ASSERT_OK(swDN.getStatus());
ASSERT_OK(swDN.getValue().normalizeStrings());
@@ -370,7 +378,7 @@ TEST(SSLManager, DNParsingAndNormalization) {
TEST(SSLManager, BadDNParsing) {
std::vector<std::string> tests = {"CN=#12345", R"(CN=\B)", R"(CN=<", "\)"};
for (const auto& test : tests) {
- log() << "Testing bad DN: \"" << test << "\"";
+ LOGV2(23269, "Testing bad DN: \"{test}\"", "test"_attr = test);
auto swDN = parseDN(test);
ASSERT_NOT_OK(swDN.getStatus());
}
diff --git a/src/mongo/util/net/ssl_manager_windows.cpp b/src/mongo/util/net/ssl_manager_windows.cpp
index 4c9bcb356c8..62c82e04261 100644
--- a/src/mongo/util/net/ssl_manager_windows.cpp
+++ b/src/mongo/util/net/ssl_manager_windows.cpp
@@ -47,6 +47,7 @@
#include "mongo/bson/util/builder.h"
#include "mongo/config.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/atomic_word.h"
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/debug_util.h"
@@ -396,7 +397,7 @@ SSLManagerWindows::SSLManagerWindows(const SSLParams& params, bool isServer)
BOOLEAN enabled = FALSE;
BCryptGetFipsAlgorithmMode(&enabled);
if (!enabled) {
- severe() << "FIPS modes is not enabled on the operating system.";
+ LOGV2_FATAL(23281, "FIPS modes is not enabled on the operating system.");
fassertFailedNoTrace(50744);
}
}
@@ -514,7 +515,9 @@ int SSLManagerWindows::SSL_read(SSLConnectionInterface* connInterface, void* buf
return bytes_transferred;
}
default:
- severe() << "Unexpected ASIO state: " << static_cast<int>(want);
+ LOGV2_FATAL(23282,
+ "Unexpected ASIO state: {static_cast_int_want}",
+ "static_cast_int_want"_attr = static_cast<int>(want));
MONGO_UNREACHABLE;
}
}
@@ -558,7 +561,9 @@ int SSLManagerWindows::SSL_write(SSLConnectionInterface* connInterface, const vo
return bytes_transferred;
}
default:
- severe() << "Unexpected ASIO state: " << static_cast<int>(want);
+ LOGV2_FATAL(23283,
+ "Unexpected ASIO state: {static_cast_int_want}",
+ "static_cast_int_want"_attr = static_cast<int>(want));
MONGO_UNREACHABLE;
}
}
@@ -1309,8 +1314,9 @@ Status SSLManagerWindows::_loadCertificates(const SSLParams& params) {
if (_sslCertificate || _sslClusterCertificate) {
if (!params.sslCAFile.empty()) {
- warning() << "Mixing certs from the system certificate store and PEM files. This may "
- "produced unexpected results.";
+ LOGV2_WARNING(23271,
+ "Mixing certs from the system certificate store and PEM files. This may "
+ "produced unexpected results.");
}
_sslConfiguration.hasCA = true;
@@ -1382,8 +1388,9 @@ Status SSLManagerWindows::initSSLContext(SCHANNEL_CRED* cred,
}
if (!params.sslCipherConfig.empty()) {
- warning()
- << "sslCipherConfig parameter is not supported with Windows SChannel and is ignored.";
+ LOGV2_WARNING(
+ 23272,
+ "sslCipherConfig parameter is not supported with Windows SChannel and is ignored.");
}
if (direction == ConnectionDirection::kOutgoing) {
@@ -1584,7 +1591,7 @@ Status SSLManagerWindows::_validateCertificate(PCCERT_CONTEXT cert,
if ((FiletimeToULL(cert->pCertInfo->NotBefore) > currentTimeLong) ||
(currentTimeLong > FiletimeToULL(cert->pCertInfo->NotAfter))) {
- severe() << "The provided SSL certificate is expired or not yet valid.";
+ LOGV2_FATAL(23284, "The provided SSL certificate is expired or not yet valid.");
fassertFailedNoTrace(50755);
}
@@ -1642,8 +1649,9 @@ StatusWith<std::vector<std::string>> getSubjectAlternativeNames(PCCERT_CONTEXT c
names.push_back(san);
auto swCIDRSan = CIDR::parse(san);
if (swCIDRSan.isOK()) {
- warning() << "You have an IP Address in the DNS Name field on your "
- "certificate. This formulation is depreceated.";
+ LOGV2_WARNING(23273,
+ "You have an IP Address in the DNS Name field on your "
+ "certificate. This formulation is depreceated.");
}
} else if (altNames->rgAltEntry[i].dwAltNameChoice == CERT_ALT_NAME_IP_ADDRESS) {
auto ipAddrStruct = altNames->rgAltEntry[i].IPAddress;
@@ -1809,14 +1817,19 @@ Status validatePeerCertificate(const std::string& remoteHost,
<< " does not match " << certificateNames.str();
if (allowInvalidCertificates) {
- warning() << "SSL peer certificate validation failed ("
- << integerToHex(certChainPolicyStatus.dwError)
- << "): " << errnoWithDescription(certChainPolicyStatus.dwError);
- warning() << msg.ss.str();
+ LOGV2_WARNING(23274,
+ "SSL peer certificate validation failed "
+ "({integerToHex_certChainPolicyStatus_dwError}): "
+ "{errnoWithDescription_certChainPolicyStatus_dwError}",
+ "integerToHex_certChainPolicyStatus_dwError"_attr =
+ integerToHex(certChainPolicyStatus.dwError),
+ "errnoWithDescription_certChainPolicyStatus_dwError"_attr =
+ errnoWithDescription(certChainPolicyStatus.dwError));
+ LOGV2_WARNING(23275, "{msg_ss_str}", "msg_ss_str"_attr = msg.ss.str());
*peerSubjectName = SSLX509Name();
return Status::OK();
} else if (allowInvalidHostnames) {
- warning() << msg.ss.str();
+ LOGV2_WARNING(23276, "{msg_ss_str}", "msg_ss_str"_attr = msg.ss.str());
return Status::OK();
} else {
return Status(ErrorCodes::SSLHandshakeFailed, msg);
@@ -1826,7 +1839,7 @@ Status validatePeerCertificate(const std::string& remoteHost,
msg << "SSL peer certificate validation failed: ("
<< integerToHex(certChainPolicyStatus.dwError) << ")"
<< errnoWithDescription(certChainPolicyStatus.dwError);
- error() << msg.ss.str();
+ LOGV2_ERROR(23279, "{msg_ss_str}", "msg_ss_str"_attr = msg.ss.str());
return Status(ErrorCodes::SSLHandshakeFailed, msg);
}
}
@@ -1885,12 +1898,12 @@ Future<SSLPeerInfo> SSLManagerWindows::parseAndValidatePeerCertificate(
if (_weakValidation) {
// do not give warning if "no certificate" warnings are suppressed
if (!_suppressNoCertificateWarning) {
- warning() << "no SSL certificate provided by peer";
+ LOGV2_WARNING(23277, "no SSL certificate provided by peer");
}
return SSLPeerInfo(sni);
} else {
auto msg = "no SSL certificate provided by peer; connection rejected";
- error() << msg;
+ LOGV2_ERROR(23280, "{msg}", "msg"_attr = msg);
return Status(ErrorCodes::SSLHandshakeFailed, msg);
}
}
@@ -1932,11 +1945,14 @@ Future<SSLPeerInfo> SSLManagerWindows::parseAndValidatePeerCertificate(
return Future<SSLPeerInfo>::makeReady(SSLPeerInfo(sni));
}
- LOG(2) << "Accepted TLS connection from peer: " << peerSubjectName;
+ LOGV2_DEBUG(23270,
+ 2,
+ "Accepted TLS connection from peer: {peerSubjectName}",
+ "peerSubjectName"_attr = peerSubjectName);
// If this is a server and client and server certificate are the same, log a warning.
if (remoteHost.empty() && _sslConfiguration.serverSubjectName() == peerSubjectName) {
- warning() << "Client connecting with server's own TLS certificate";
+ LOGV2_WARNING(23278, "Client connecting with server's own TLS certificate");
}
// On the server side, parse the certificate for roles
diff --git a/src/mongo/util/net/ssl_options_server.cpp b/src/mongo/util/net/ssl_options_server.cpp
index dba0e0f94f7..56b0be72190 100644
--- a/src/mongo/util/net/ssl_options_server.cpp
+++ b/src/mongo/util/net/ssl_options_server.cpp
@@ -38,6 +38,7 @@
#include "mongo/base/status.h"
#include "mongo/config.h"
#include "mongo/db/server_options.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/options_parser/startup_option_init.h"
#include "mongo/util/options_parser/startup_options.h"
@@ -138,8 +139,9 @@ MONGO_STARTUP_OPTIONS_POST(SSLServerOptions)(InitializerContext*) {
}
if (params.count("net.tls.tlsCipherConfig")) {
- warning()
- << "net.tls.tlsCipherConfig is deprecated. It will be removed in a future release.";
+ LOGV2_WARNING(
+ 23286,
+ "net.tls.tlsCipherConfig is deprecated. It will be removed in a future release.");
if (!sslGlobalParams.sslCipherConfig.empty()) {
return {ErrorCodes::BadValue,
"net.tls.tlsCipherConfig is incompatible with the openTLSCipherConfig "
@@ -337,8 +339,9 @@ MONGO_STARTUP_OPTIONS_VALIDATE(SSLServerOptions)(InitializerContext*) {
MONGO_INITIALIZER_WITH_PREREQUISITES(ImplicitDisableTLS10Warning, ("ServerLogRedirection"))
(InitializerContext*) {
if (gImplicitDisableTLS10) {
- log() << "Automatically disabling TLS 1.0, to force-enable TLS 1.0 "
- "specify --sslDisabledProtocols 'none'";
+ LOGV2(23285,
+ "Automatically disabling TLS 1.0, to force-enable TLS 1.0 "
+ "specify --sslDisabledProtocols 'none'");
}
return Status::OK();
}
diff --git a/src/mongo/util/ntservice.cpp b/src/mongo/util/ntservice.cpp
index 512200c2744..2a51081bb4a 100644
--- a/src/mongo/util/ntservice.cpp
+++ b/src/mongo/util/ntservice.cpp
@@ -37,6 +37,7 @@
#include "mongo/util/ntservice.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/chrono.h"
#include "mongo/stdx/future.h"
#include "mongo/stdx/thread.h"
@@ -108,38 +109,46 @@ void configureService(ServiceCallback serviceCallback,
if (params.count("install")) {
if (badOption != -1) {
- log() << "--install cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23287,
+ "--install cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
if (!params.count("systemLog.destination") ||
params["systemLog.destination"].as<std::string>() != "file") {
- log() << "--install has to be used with a log file for server output";
+ LOGV2(23288, "--install has to be used with a log file for server output");
quickExit(EXIT_BADOPTIONS);
}
installService = true;
}
if (params.count("reinstall")) {
if (badOption != -1) {
- log() << "--reinstall cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23289,
+ "--reinstall cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
if (!params.count("systemLog.destination") ||
params["systemLog.destination"].as<std::string>() != "file") {
- log() << "--reinstall has to be used with a log file for server output";
+ LOGV2(23290, "--reinstall has to be used with a log file for server output");
quickExit(EXIT_BADOPTIONS);
}
reinstallService = true;
}
if (params.count("remove")) {
if (badOption != -1) {
- log() << "--remove cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23291,
+ "--remove cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
removeService = true;
}
if (params.count("service")) {
if (badOption != -1) {
- log() << "--service cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23292,
+ "--service cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
_startService = true;
@@ -147,7 +156,9 @@ void configureService(ServiceCallback serviceCallback,
if (params.count("processManagement.windowsService.serviceName")) {
if (badOption != -1) {
- log() << "--serviceName cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23293,
+ "--serviceName cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
_serviceName = toWideString(
@@ -155,7 +166,9 @@ void configureService(ServiceCallback serviceCallback,
}
if (params.count("processManagement.windowsService.displayName")) {
if (badOption != -1) {
- log() << "--serviceDisplayName cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23294,
+ "--serviceDisplayName cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
windowsServiceDisplayName = toWideString(
@@ -163,7 +176,9 @@ void configureService(ServiceCallback serviceCallback,
}
if (params.count("processManagement.windowsService.description")) {
if (badOption != -1) {
- log() << "--serviceDescription cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23295,
+ "--serviceDescription cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
windowsServiceDescription = toWideString(
@@ -171,7 +186,9 @@ void configureService(ServiceCallback serviceCallback,
}
if (params.count("processManagement.windowsService.serviceUser")) {
if (badOption != -1) {
- log() << "--serviceUser cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23296,
+ "--serviceUser cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
windowsServiceUser = toWideString(
@@ -179,7 +196,9 @@ void configureService(ServiceCallback serviceCallback,
}
if (params.count("processManagement.windowsService.servicePassword")) {
if (badOption != -1) {
- log() << "--servicePassword cannot be used with --" << disallowedOptions[badOption];
+ LOGV2(23297,
+ "--servicePassword cannot be used with --{disallowedOptions_badOption}",
+ "disallowedOptions_badOption"_attr = disallowedOptions[badOption]);
quickExit(EXIT_BADOPTIONS);
}
windowsServicePassword = toWideString(
@@ -274,7 +293,9 @@ void installServiceOrDie(const wstring& serviceName,
const wstring& servicePassword,
const std::vector<std::string>& argv,
const bool reinstall) {
- log() << "Trying to install Windows service '" << toUtf8String(serviceName) << "'";
+ LOGV2(23298,
+ "Trying to install Windows service '{toUtf8String_serviceName}'",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName));
std::vector<std::string> serviceArgv = constructServiceArgv(argv);
@@ -287,7 +308,9 @@ void installServiceOrDie(const wstring& serviceName,
SC_HANDLE schSCManager = ::OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);
if (schSCManager == nullptr) {
DWORD err = ::GetLastError();
- log() << "Error connecting to the Service Control Manager: " << windows::GetErrMsg(err);
+ LOGV2(23299,
+ "Error connecting to the Service Control Manager: {windows_GetErrMsg_err}",
+ "windows_GetErrMsg_err"_attr = windows::GetErrMsg(err));
quickExit(EXIT_NTSERVICE_ERROR);
}
@@ -300,8 +323,12 @@ void installServiceOrDie(const wstring& serviceName,
// Services MMC snap-ins.
schService = ::OpenService(schSCManager, serviceName.c_str(), SERVICE_ALL_ACCESS);
if (schService != nullptr) {
- log() << "There is already a service named '" << toUtf8String(serviceName)
- << (retryCount > 0 ? "', sleeping and retrying" : "', aborting");
+ LOGV2(23300,
+ "There is already a service named "
+ "'{toUtf8String_serviceName}{retryCount_0_sleeping_and_retrying_aborting}",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName),
+ "retryCount_0_sleeping_and_retrying_aborting"_attr =
+ (retryCount > 0 ? "', sleeping and retrying" : "', aborting"));
::CloseServiceHandle(schService);
// If we are reinstalling the service, but SCM thinks it is installed, then wait
@@ -336,17 +363,25 @@ void installServiceOrDie(const wstring& serviceName,
nullptr); // user account password
if (schService == nullptr) {
DWORD err = ::GetLastError();
- log() << "Error creating service: " << windows::GetErrMsg(err);
+ LOGV2(23301,
+ "Error creating service: {windows_GetErrMsg_err}",
+ "windows_GetErrMsg_err"_attr = windows::GetErrMsg(err));
::CloseServiceHandle(schSCManager);
quickExit(EXIT_NTSERVICE_ERROR);
}
- log() << "Service '" << toUtf8String(serviceName) << "' (" << toUtf8String(displayName)
- << ") installed with command line '" << commandLine << "'";
+ LOGV2(23302,
+ "Service '{toUtf8String_serviceName}' ({toUtf8String_displayName}) installed with "
+ "command line '{commandLine}'",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName),
+ "toUtf8String_displayName"_attr = toUtf8String(displayName),
+ "commandLine"_attr = commandLine);
string typeableName((serviceName.find(L' ') != wstring::npos)
? "\"" + toUtf8String(serviceName) + "\""
: toUtf8String(serviceName));
- log() << "Service can be started from the command line with 'net start " << typeableName << "'";
+ LOGV2(23303,
+ "Service can be started from the command line with 'net start {typeableName}'",
+ "typeableName"_attr = typeableName);
bool serviceInstalled;
@@ -359,7 +394,9 @@ void installServiceOrDie(const wstring& serviceName,
actualServiceUser = serviceUser;
}
- log() << "Setting service login credentials for user: " << toUtf8String(actualServiceUser);
+ LOGV2(23304,
+ "Setting service login credentials for user: {toUtf8String_actualServiceUser}",
+ "toUtf8String_actualServiceUser"_attr = toUtf8String(actualServiceUser));
serviceInstalled = ::ChangeServiceConfig(schService, // service handle
SERVICE_NO_CHANGE, // service type
SERVICE_NO_CHANGE, // start type
@@ -372,7 +409,7 @@ void installServiceOrDie(const wstring& serviceName,
servicePassword.c_str(), // user account password
nullptr); // service display name
if (!serviceInstalled) {
- log() << "Setting service login failed, service has 'LocalService' permissions";
+ LOGV2(23305, "Setting service login failed, service has 'LocalService' permissions");
}
}
@@ -410,7 +447,8 @@ void installServiceOrDie(const wstring& serviceName,
} else {
#endif
- log() << "Could not set service description. Check the Windows Event Log for more details.";
+ LOGV2(23306,
+ "Could not set service description. Check the Windows Event Log for more details.");
}
// Set the pre-shutdown notification with a timeout of 10 minutes.
@@ -423,8 +461,10 @@ void installServiceOrDie(const wstring& serviceName,
schService, SERVICE_CONFIG_PRESHUTDOWN_INFO, &servicePreshutdownInfo);
if (!ret) {
DWORD gle = ::GetLastError();
- error() << "Failed to set timeout for pre-shutdown notification with error: "
- << errnoWithDescription(gle);
+ LOGV2_ERROR(23317,
+ "Failed to set timeout for pre-shutdown notification with error: "
+ "{errnoWithDescription_gle}",
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
serviceInstalled = false;
}
@@ -436,18 +476,24 @@ void installServiceOrDie(const wstring& serviceName,
}
void removeServiceOrDie(const wstring& serviceName) {
- log() << "Trying to remove Windows service '" << toUtf8String(serviceName) << "'";
+ LOGV2(23307,
+ "Trying to remove Windows service '{toUtf8String_serviceName}'",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName));
SC_HANDLE schSCManager = ::OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);
if (schSCManager == nullptr) {
DWORD err = ::GetLastError();
- log() << "Error connecting to the Service Control Manager: " << windows::GetErrMsg(err);
+ LOGV2(23308,
+ "Error connecting to the Service Control Manager: {windows_GetErrMsg_err}",
+ "windows_GetErrMsg_err"_attr = windows::GetErrMsg(err));
quickExit(EXIT_NTSERVICE_ERROR);
}
SC_HANDLE schService = ::OpenService(schSCManager, serviceName.c_str(), SERVICE_ALL_ACCESS);
if (schService == nullptr) {
- log() << "Could not find a service named '" << toUtf8String(serviceName) << "' to remove";
+ LOGV2(23309,
+ "Could not find a service named '{toUtf8String_serviceName}' to remove",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName));
::CloseServiceHandle(schSCManager);
quickExit(EXIT_NTSERVICE_ERROR);
}
@@ -456,8 +502,9 @@ void removeServiceOrDie(const wstring& serviceName) {
// stop service if its running
if (::ControlService(schService, SERVICE_CONTROL_STOP, &serviceStatus)) {
- log() << "Service " << toUtf8String(serviceName)
- << " is currently running, stopping service";
+ LOGV2(23310,
+ "Service {toUtf8String_serviceName} is currently running, stopping service",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName));
while (::QueryServiceStatus(schService, &serviceStatus)) {
if (serviceStatus.dwCurrentState == SERVICE_STOP_PENDING) {
Sleep(1000);
@@ -465,7 +512,9 @@ void removeServiceOrDie(const wstring& serviceName) {
break;
}
}
- log() << "Service '" << toUtf8String(serviceName) << "' stopped";
+ LOGV2(23311,
+ "Service '{toUtf8String_serviceName}' stopped",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName));
}
bool serviceRemoved = ::DeleteService(schService);
@@ -474,9 +523,13 @@ void removeServiceOrDie(const wstring& serviceName) {
::CloseServiceHandle(schSCManager);
if (serviceRemoved) {
- log() << "Service '" << toUtf8String(serviceName) << "' removed";
+ LOGV2(23312,
+ "Service '{toUtf8String_serviceName}' removed",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName));
} else {
- log() << "Failed to remove service '" << toUtf8String(serviceName) << "'";
+ LOGV2(23313,
+ "Failed to remove service '{toUtf8String_serviceName}'",
+ "toUtf8String_serviceName"_attr = toUtf8String(serviceName));
}
if (!serviceRemoved)
@@ -546,7 +599,7 @@ static void serviceStop() {
// We periodically check if we are done exiting by polling at half of each wait interval
while (exitedCleanly.wait_for(timeout.toSystemDuration()) != stdx::future_status::ready) {
reportStatus(SERVICE_STOP_PENDING, kStopWaitHintMillis);
- log() << "Service Stop is waiting for storage engine to finish shutdown";
+ LOGV2(23314, "Service Stop is waiting for storage engine to finish shutdown");
}
}
@@ -571,9 +624,14 @@ static void WINAPI initService(DWORD argc, LPTSTR* argv) {
static void serviceShutdown(const char* controlCodeName) {
setThreadName("serviceShutdown");
- log() << "got " << controlCodeName << " request from Windows Service Control Manager, "
- << (globalInShutdownDeprecated() ? "already in shutdown"
- : "will terminate after current cmd ends");
+ LOGV2(
+ 23315,
+ "got {controlCodeName} request from Windows Service Control Manager, "
+ "{globalInShutdownDeprecated_already_in_shutdown_will_terminate_after_current_cmd_ends}",
+ "controlCodeName"_attr = controlCodeName,
+ "globalInShutdownDeprecated_already_in_shutdown_will_terminate_after_current_cmd_ends"_attr =
+ (globalInShutdownDeprecated() ? "already in shutdown"
+ : "will terminate after current cmd ends"));
reportStatus(SERVICE_STOP_PENDING, kStopWaitHintMillis);
@@ -617,7 +675,9 @@ void startService() {
{const_cast<LPWSTR>(_serviceName.c_str()), (LPSERVICE_MAIN_FUNCTION)initService},
{nullptr, nullptr}};
- log() << "Trying to start Windows service '" << toUtf8String(_serviceName) << "'";
+ LOGV2(23316,
+ "Trying to start Windows service '{toUtf8String_serviceName}'",
+ "toUtf8String_serviceName"_attr = toUtf8String(_serviceName));
if (StartServiceCtrlDispatcherW(dispTable)) {
quickExit(EXIT_CLEAN);
} else {
diff --git a/src/mongo/util/options_parser/options_parser.cpp b/src/mongo/util/options_parser/options_parser.cpp
index 99231dd132c..5975d1e20c5 100644
--- a/src/mongo/util/options_parser/options_parser.cpp
+++ b/src/mongo/util/options_parser/options_parser.cpp
@@ -56,6 +56,7 @@
#include "mongo/crypto/sha256_block.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
@@ -594,9 +595,17 @@ StatusWith<YAML::Node> runYAMLExpansion(const YAML::Node& node,
prefix += '.';
}
- log() << "Processing " << expansion.getExpansionName() << " config expansion for: " << nodeName;
+ LOGV2(23318,
+ "Processing {expansion_getExpansionName} config expansion for: {nodeName}",
+ "expansion_getExpansionName"_attr = expansion.getExpansionName(),
+ "nodeName"_attr = nodeName);
const auto action = expansion.getAction();
- LOG(2) << prefix << expansion.getExpansionName() << ": " << action;
+ LOGV2_DEBUG(23319,
+ 2,
+ "{prefix}{expansion_getExpansionName}: {action}",
+ "prefix"_attr = prefix,
+ "expansion_getExpansionName"_attr = expansion.getExpansionName(),
+ "action"_attr = action);
if (expansion.isRestExpansion()) {
return expansion.process(runYAMLRestExpansion(action, configExpand.timeout));
@@ -658,8 +667,11 @@ Status YAMLNodeToValue(const YAML::Node& YAMLNode,
type = iterator->_type;
*option = &*iterator;
if (isDeprecated) {
- warning() << "Option: " << key << " is deprecated. Please use "
- << iterator->_dottedName << " instead.";
+ LOGV2_WARNING(
+ 23320,
+ "Option: {key} is deprecated. Please use {iterator_dottedName} instead.",
+ "key"_attr = key,
+ "iterator_dottedName"_attr = iterator->_dottedName);
}
}
}
@@ -796,10 +808,13 @@ Status checkLongName(const po::variables_map& vm,
if (vm.count(long_name)) {
if (!vm[long_name].defaulted() && singleName != option._singleName) {
- warning() << "Option: " << singleName << " is deprecated. Please use "
- << option._singleName << " instead.";
+ LOGV2_WARNING(
+ 23321,
+ "Option: {singleName} is deprecated. Please use {option_singleName} instead.",
+ "singleName"_attr = singleName,
+ "option_singleName"_attr = option._singleName);
} else if (long_name == "sslMode") {
- warning() << "Option: sslMode is deprecated. Please use tlsMode instead.";
+ LOGV2_WARNING(23322, "Option: sslMode is deprecated. Please use tlsMode instead.");
}
Value optionValue;
diff --git a/src/mongo/util/periodic_runner_impl.cpp b/src/mongo/util/periodic_runner_impl.cpp
index dc9f091505d..182e8ad7837 100644
--- a/src/mongo/util/periodic_runner_impl.cpp
+++ b/src/mongo/util/periodic_runner_impl.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/client.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/clock_source.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
@@ -114,7 +115,7 @@ void PeriodicRunnerImpl::PeriodicJobImpl::_run() {
}
void PeriodicRunnerImpl::PeriodicJobImpl::start() {
- LOG(2) << "Starting periodic job " << _job.name;
+ LOGV2_DEBUG(23323, 2, "Starting periodic job {job_name}", "job_name"_attr = _job.name);
_run();
}
@@ -148,7 +149,7 @@ void PeriodicRunnerImpl::PeriodicJobImpl::stop() {
// Only join once
if (lastExecStatus != ExecutionStatus::CANCELED) {
- LOG(2) << "Stopping periodic job " << _job.name;
+ LOGV2_DEBUG(23324, 2, "Stopping periodic job {job_name}", "job_name"_attr = _job.name);
_condvar.notify_one();
_thread.join();
diff --git a/src/mongo/util/platform_init.cpp b/src/mongo/util/platform_init.cpp
index 335cd5c7bf6..0299d467f33 100644
--- a/src/mongo/util/platform_init.cpp
+++ b/src/mongo/util/platform_init.cpp
@@ -39,6 +39,7 @@
#endif
#include "mongo/base/init.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/stacktrace.h"
@@ -71,8 +72,11 @@ extern "C" {
int __cdecl crtDebugCallback(int nRptType, char* originalMessage, int* returnValue) noexcept {
*returnValue = 0; // Returned by _CrtDbgReport. (1: starts the debugger).
bool die = (nRptType != _CRT_WARN);
- log() << "*** C runtime " << severity(nRptType) << ": " << firstLine(originalMessage)
- << (die ? ", terminating"_sd : ""_sd);
+ LOGV2(23325,
+ "*** C runtime {severity_nRptType}: {firstLine_originalMessage}{die_terminating_sd_sd}",
+ "severity_nRptType"_attr = severity(nRptType),
+ "firstLine_originalMessage"_attr = firstLine(originalMessage),
+ "die_terminating_sd_sd"_attr = (die ? ", terminating"_sd : ""_sd));
if (die) {
fassertFailed(17006);
}
@@ -89,7 +93,7 @@ MONGO_INITIALIZER(Behaviors_Win32)(InitializerContext*) {
_CrtSetReportHook(&crtDebugCallback);
if (_setmaxstdio(2048) == -1) {
- warning() << "Failed to increase max open files limit from default of 512 to 2048";
+ LOGV2_WARNING(23326, "Failed to increase max open files limit from default of 512 to 2048");
}
// Let's try to set minimum Windows Kernel quantum length to smallest viable timer resolution in
@@ -101,9 +105,9 @@ MONGO_INITIALIZER(Behaviors_Win32)(InitializerContext*) {
int timerResolution;
if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
- warning() << "Failed to read timer resolution range.";
+ LOGV2_WARNING(23327, "Failed to read timer resolution range.");
if (timeBeginPeriod(1) != TIMERR_NOERROR) {
- warning() << "Failed to set minimum timer resolution to 1 millisecond.";
+ LOGV2_WARNING(23328, "Failed to set minimum timer resolution to 1 millisecond.");
}
} else {
timerResolution =
diff --git a/src/mongo/util/processinfo.cpp b/src/mongo/util/processinfo.cpp
index 3428d0907d0..9501f0eefcf 100644
--- a/src/mongo/util/processinfo.cpp
+++ b/src/mongo/util/processinfo.cpp
@@ -39,6 +39,7 @@
#include <fstream>
#include <iostream>
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -61,11 +62,14 @@ public:
if (!out.good()) {
auto errAndStr = errnoAndDescription();
if (errAndStr.first == 0) {
- log() << "ERROR: Cannot write pid file to " << path.string()
- << ": Unable to determine OS error";
+ LOGV2(23329,
+ "ERROR: Cannot write pid file to {path_string}: Unable to determine OS error",
+ "path_string"_attr = path.string());
} else {
- log() << "ERROR: Cannot write pid file to " << path.string() << ": "
- << errAndStr.second;
+ LOGV2(23330,
+ "ERROR: Cannot write pid file to {path_string}: {errAndStr_second}",
+ "path_string"_attr = path.string(),
+ "errAndStr_second"_attr = errAndStr.second);
}
} else {
boost::system::error_code ec;
@@ -75,8 +79,10 @@ public:
boost::filesystem::group_read | boost::filesystem::others_read,
ec);
if (ec) {
- log() << "Could not set permissions on pid file " << path.string() << ": "
- << ec.message();
+ LOGV2(23331,
+ "Could not set permissions on pid file {path_string}: {ec_message}",
+ "path_string"_attr = path.string(),
+ "ec_message"_attr = ec.message());
return false;
}
}
diff --git a/src/mongo/util/processinfo_freebsd.cpp b/src/mongo/util/processinfo_freebsd.cpp
index f3b60f426ef..ec6c732497c 100644
--- a/src/mongo/util/processinfo_freebsd.cpp
+++ b/src/mongo/util/processinfo_freebsd.cpp
@@ -43,6 +43,7 @@
#include <unistd.h>
#include <vm/vm_param.h>
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
#include "processinfo.h"
@@ -130,13 +131,17 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
int status = getSysctlByNameWithDefault("kern.version", std::string("unknown"), &osVersion);
if (status != 0)
- log() << "Unable to collect OS Version. (errno: " << status << " msg: " << strerror(status)
- << ")";
+ LOGV2(23332,
+ "Unable to collect OS Version. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
status = getSysctlByNameWithDefault("hw.machine_arch", std::string("unknown"), &cpuArch);
if (status != 0)
- log() << "Unable to collect Machine Architecture. (errno: " << status
- << " msg: " << strerror(status) << ")";
+ LOGV2(23333,
+ "Unable to collect Machine Architecture. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
addrSize = cpuArch.find("64") != std::string::npos ? 64 : 32;
uintptr_t numBuffer;
@@ -145,14 +150,18 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
memSize = numBuffer;
memLimit = memSize;
if (status != 0)
- log() << "Unable to collect Physical Memory. (errno: " << status
- << " msg: " << strerror(status) << ")";
+ LOGV2(23334,
+ "Unable to collect Physical Memory. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
status = getSysctlByNameWithDefault("hw.ncpu", defaultNum, &numBuffer);
numCores = numBuffer;
if (status != 0)
- log() << "Unable to collect Number of CPUs. (errno: " << status
- << " msg: " << strerror(status) << ")";
+ LOGV2(23335,
+ "Unable to collect Number of CPUs. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
pageSize = static_cast<unsigned long long>(sysconf(_SC_PAGESIZE));
@@ -172,7 +181,9 @@ bool ProcessInfo::blockCheckSupported() {
bool ProcessInfo::blockInMemory(const void* start) {
char x = 0;
if (mincore(alignToStartOfPage(start), getPageSize(), &x)) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23336,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return 1;
}
return x & 0x1;
@@ -182,7 +193,9 @@ bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, std::vector<
out->resize(numPages);
// int mincore(const void *addr, size_t len, char *vec);
if (mincore(alignToStartOfPage(start), numPages * getPageSize(), &(out->front()))) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23337,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return false;
}
for (size_t i = 0; i < numPages; ++i) {
diff --git a/src/mongo/util/processinfo_linux.cpp b/src/mongo/util/processinfo_linux.cpp
index 9c2db3c4166..dde30376ce2 100644
--- a/src/mongo/util/processinfo_linux.cpp
+++ b/src/mongo/util/processinfo_linux.cpp
@@ -54,6 +54,7 @@
#include <boost/none.hpp>
#include <boost/optional.hpp>
+#include "mongo/logv2/log.h"
#include "mongo/util/file.h"
#include "mongo/util/log.h"
@@ -407,7 +408,7 @@ public:
if (mongo::NumberParser{}(meminfo, &systemMem).isOK()) {
return systemMem * 1024; // convert from kB to bytes
} else
- log() << "Unable to collect system memory information";
+ LOGV2(23338, "Unable to collect system memory information");
}
return 0;
}
@@ -521,7 +522,9 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
LinuxSysHelper::getLinuxDistro(distroName, distroVersion);
if (uname(&unameData) == -1) {
- log() << "Unable to collect detailed system information: " << strerror(errno);
+ LOGV2(23339,
+ "Unable to collect detailed system information: {strerror_errno}",
+ "strerror_errno"_attr = strerror(errno));
}
osType = "Linux";
@@ -573,8 +576,11 @@ bool ProcessInfo::checkNumaEnabled() {
hasMultipleNodes = boost::filesystem::exists("/sys/devices/system/node/node1");
hasNumaMaps = boost::filesystem::exists("/proc/self/numa_maps");
} catch (boost::filesystem::filesystem_error& e) {
- log() << "WARNING: Cannot detect if NUMA interleaving is enabled. "
- << "Failed to probe \"" << e.path1().string() << "\": " << e.code().message();
+ LOGV2(23340,
+ "WARNING: Cannot detect if NUMA interleaving is enabled. Failed to probe "
+ "\"{e_path1_string}\": {e_code_message}",
+ "e_path1_string"_attr = e.path1().string(),
+ "e_code_message"_attr = e.code().message());
return false;
}
@@ -600,7 +606,9 @@ bool ProcessInfo::blockCheckSupported() {
bool ProcessInfo::blockInMemory(const void* start) {
unsigned char x = 0;
if (mincore(const_cast<void*>(alignToStartOfPage(start)), getPageSize(), &x)) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23341,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return 1;
}
return x & 0x1;
@@ -611,7 +619,9 @@ bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, std::vector<
if (mincore(const_cast<void*>(alignToStartOfPage(start)),
numPages * getPageSize(),
reinterpret_cast<unsigned char*>(&out->front()))) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23342,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return false;
}
for (size_t i = 0; i < numPages; ++i) {
diff --git a/src/mongo/util/processinfo_openbsd.cpp b/src/mongo/util/processinfo_openbsd.cpp
index 34dade8a885..d358a7a797c 100644
--- a/src/mongo/util/processinfo_openbsd.cpp
+++ b/src/mongo/util/processinfo_openbsd.cpp
@@ -42,6 +42,7 @@
#include <sys/vmmeter.h>
#include <unistd.h>
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
#include "processinfo.h"
@@ -105,7 +106,7 @@ int ProcessInfo::getVirtualMemorySize() {
int cnt = 0;
char err[_POSIX2_LINE_MAX] = {0};
if ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, err)) == NULL) {
- log() << "Unable to get virt mem size: " << err;
+ LOGV2(23343, "Unable to get virt mem size: {err}", "err"_attr = err);
return -1;
}
@@ -121,7 +122,7 @@ int ProcessInfo::getResidentSize() {
int cnt = 0;
char err[_POSIX2_LINE_MAX] = {0};
if ((kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, err)) == NULL) {
- log() << "Unable to get res mem size: " << err;
+ LOGV2(23344, "Unable to get res mem size: {err}", "err"_attr = err);
return -1;
}
kinfo_proc* task = kvm_getprocs(kd, KERN_PROC_PID, _pid.toNative(), sizeof(kinfo_proc), &cnt);
@@ -143,15 +144,19 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
mib[1] = KERN_VERSION;
int status = getSysctlByIDWithDefault(mib, 2, std::string("unknown"), &osVersion);
if (status != 0)
- log() << "Unable to collect OS Version. (errno: " << status << " msg: " << strerror(status)
- << ")";
+ LOGV2(23345,
+ "Unable to collect OS Version. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
status = getSysctlByIDWithDefault(mib, 2, std::string("unknown"), &cpuArch);
if (status != 0)
- log() << "Unable to collect Machine Architecture. (errno: " << status
- << " msg: " << strerror(status) << ")";
+ LOGV2(23346,
+ "Unable to collect Machine Architecture. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
addrSize = cpuArch.find("64") != std::string::npos ? 64 : 32;
uintptr_t numBuffer;
@@ -162,16 +167,20 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
memSize = numBuffer;
memLimit = memSize;
if (status != 0)
- log() << "Unable to collect Physical Memory. (errno: " << status
- << " msg: " << strerror(status) << ")";
+ LOGV2(23347,
+ "Unable to collect Physical Memory. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
status = getSysctlByIDWithDefault(mib, 2, defaultNum, &numBuffer);
numCores = numBuffer;
if (status != 0)
- log() << "Unable to collect Number of CPUs. (errno: " << status
- << " msg: " << strerror(status) << ")";
+ LOGV2(23348,
+ "Unable to collect Number of CPUs. (errno: {status} msg: {strerror_status})",
+ "status"_attr = status,
+ "strerror_status"_attr = strerror(status));
pageSize = static_cast<unsigned long long>(sysconf(_SC_PAGESIZE));
@@ -191,7 +200,9 @@ bool ProcessInfo::blockCheckSupported() {
bool ProcessInfo::blockInMemory(const void* start) {
char x = 0;
if (mincore((void*)alignToStartOfPage(start), getPageSize(), &x)) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23349,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return 1;
}
return x & 0x1;
@@ -201,7 +212,9 @@ bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, std::vector<
out->resize(numPages);
// int mincore(const void *addr, size_t len, char *vec);
if (mincore((void*)alignToStartOfPage(start), numPages * getPageSize(), &(out->front()))) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23350,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return false;
}
for (size_t i = 0; i < numPages; ++i) {
diff --git a/src/mongo/util/processinfo_osx.cpp b/src/mongo/util/processinfo_osx.cpp
index 45fc77f68ff..3bc13439d16 100644
--- a/src/mongo/util/processinfo_osx.cpp
+++ b/src/mongo/util/processinfo_osx.cpp
@@ -48,6 +48,7 @@
#include <sys/types.h>
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
#include "mongo/util/processinfo.h"
@@ -153,7 +154,7 @@ Variant getSysctlByName(const char* sysctlName) {
} while (status == -1 && errno == ENOMEM);
if (status == -1) {
// unrecoverable error from sysctlbyname
- log() << sysctlName << " unavailable";
+ LOGV2(23351, "{sysctlName} unavailable", "sysctlName"_attr = sysctlName);
return "";
}
@@ -169,11 +170,15 @@ long long getSysctlByName<NumberVal>(const char* sysctlName) {
long long value = 0;
size_t len = sizeof(value);
if (sysctlbyname(sysctlName, &value, &len, nullptr, 0) < 0) {
- log() << "Unable to resolve sysctl " << sysctlName << " (number) ";
+ LOGV2(23352,
+ "Unable to resolve sysctl {sysctlName} (number) ",
+ "sysctlName"_attr = sysctlName);
}
if (len > 8) {
- log() << "Unable to resolve sysctl " << sysctlName << " as integer. System returned "
- << len << " bytes.";
+ LOGV2(23353,
+ "Unable to resolve sysctl {sysctlName} as integer. System returned {len} bytes.",
+ "sysctlName"_attr = sysctlName,
+ "len"_attr = len);
}
return value;
}
@@ -223,7 +228,9 @@ bool ProcessInfo::blockCheckSupported() {
bool ProcessInfo::blockInMemory(const void* start) {
char x = 0;
if (mincore(alignToStartOfPage(start), getPageSize(), &x)) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23354,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return 1;
}
return x & 0x1;
@@ -232,7 +239,9 @@ bool ProcessInfo::blockInMemory(const void* start) {
bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, std::vector<char>* out) {
out->resize(numPages);
if (mincore(alignToStartOfPage(start), numPages * getPageSize(), &out->front())) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23355,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return false;
}
for (size_t i = 0; i < numPages; ++i) {
diff --git a/src/mongo/util/processinfo_solaris.cpp b/src/mongo/util/processinfo_solaris.cpp
index c12ce0e6da9..d20328c9cae 100644
--- a/src/mongo/util/processinfo_solaris.cpp
+++ b/src/mongo/util/processinfo_solaris.cpp
@@ -45,6 +45,7 @@
#include <unistd.h>
#include <vector>
+#include "mongo/logv2/log.h"
#include "mongo/util/file.h"
#include "mongo/util/log.h"
#include "mongo/util/processinfo.h"
@@ -139,7 +140,9 @@ void ProcessInfo::getExtraInfo(BSONObjBuilder& info) {
void ProcessInfo::SystemInfo::collectSystemInfo() {
struct utsname unameData;
if (uname(&unameData) == -1) {
- log() << "Unable to collect detailed system information: " << strerror(errno);
+ LOGV2(23356,
+ "Unable to collect detailed system information: {strerror_errno}",
+ "strerror_errno"_attr = strerror(errno));
}
char buf_64[32];
@@ -148,7 +151,9 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
sysinfo(SI_ARCHITECTURE_NATIVE, buf_native, sizeof(buf_native)) != -1) {
addrSize = str::equals(buf_64, buf_native) ? 64 : 32;
} else {
- log() << "Unable to determine system architecture: " << strerror(errno);
+ LOGV2(23357,
+ "Unable to determine system architecture: {strerror_errno}",
+ "strerror_errno"_attr = strerror(errno));
}
osType = unameData.sysname;
@@ -177,12 +182,16 @@ void ProcessInfo::SystemInfo::collectSystemInfo() {
Status minorStatus = NumberParser{}(versionComponents[1], &minorInt);
if (!majorStatus.isOK() || !minorStatus.isOK()) {
- warning() << "Could not parse OS version numbers from uname: " << osVersion;
+ LOGV2_WARNING(23360,
+ "Could not parse OS version numbers from uname: {osVersion}",
+ "osVersion"_attr = osVersion);
} else if ((majorInt == 11 && minorInt >= 2) || majorInt > 11) {
preferMsyncOverFSync = true;
}
} else {
- warning() << "Could not parse OS version string from uname: " << osVersion;
+ LOGV2_WARNING(23361,
+ "Could not parse OS version string from uname: {osVersion}",
+ "osVersion"_attr = osVersion);
}
}
@@ -198,7 +207,9 @@ bool ProcessInfo::checkNumaEnabled() {
lgrp_cookie_t cookie = lgrp_init(LGRP_VIEW_OS);
if (cookie == LGRP_COOKIE_NONE) {
- warning() << "lgrp_init failed: " << errnoWithDescription();
+ LOGV2_WARNING(23362,
+ "lgrp_init failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return false;
}
@@ -207,7 +218,9 @@ bool ProcessInfo::checkNumaEnabled() {
int groups = lgrp_nlgrps(cookie);
if (groups == -1) {
- warning() << "lgrp_nlgrps failed: " << errnoWithDescription();
+ LOGV2_WARNING(23363,
+ "lgrp_nlgrps failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return false;
}
@@ -223,7 +236,9 @@ bool ProcessInfo::blockInMemory(const void* start) {
char x = 0;
if (mincore(
static_cast<char*>(const_cast<void*>(alignToStartOfPage(start))), getPageSize(), &x)) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23358,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return 1;
}
return x & 0x1;
@@ -234,7 +249,9 @@ bool ProcessInfo::pagesInMemory(const void* start, size_t numPages, std::vector<
if (mincore(static_cast<char*>(const_cast<void*>(alignToStartOfPage(start))),
numPages * getPageSize(),
&out->front())) {
- log() << "mincore failed: " << errnoWithDescription();
+ LOGV2(23359,
+ "mincore failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return false;
}
for (size_t i = 0; i < numPages; ++i) {
diff --git a/src/mongo/util/procparser_test.cpp b/src/mongo/util/procparser_test.cpp
index 1fba705f929..2429b119750 100644
--- a/src/mongo/util/procparser_test.cpp
+++ b/src/mongo/util/procparser_test.cpp
@@ -38,6 +38,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/log.h"
@@ -222,7 +223,7 @@ TEST(FTDCProcStat, TestLocalStat) {
BSONObj obj = builder.obj();
auto stringMap = toStringMap(obj);
- log() << "OBJ:" << obj;
+ LOGV2(23364, "OBJ:{obj}", "obj"_attr = obj);
ASSERT_KEY("user_ms");
ASSERT_KEY("nice_ms");
ASSERT_KEY("idle_ms");
@@ -335,7 +336,7 @@ TEST(FTDCProcMemInfo, TestLocalMemInfo) {
BSONObj obj = builder.obj();
auto stringMap = toStringMap(obj);
- log() << "OBJ:" << obj;
+ LOGV2(23365, "OBJ:{obj}", "obj"_attr = obj);
ASSERT_KEY("MemTotal_kb");
ASSERT_KEY("MemFree_kb");
// Needs in 3.15+ - ASSERT_KEY("MemAvailable_kb");
@@ -474,7 +475,7 @@ TEST(FTDCProcNetstat, TestLocalNetstat) {
BSONObj obj = builder.obj();
auto stringMap = toStringMap(obj);
- log() << "OBJ:" << obj;
+ LOGV2(23366, "OBJ:{obj}", "obj"_attr = obj);
ASSERT_KEY("TcpExt:TCPTimeouts");
ASSERT_KEY("TcpExt:TCPPureAcks");
ASSERT_KEY("TcpExt:TCPAbortOnTimeout");
@@ -498,7 +499,7 @@ TEST(FTDCProcNetstat, TestLocalNetSnmp) {
BSONObj obj = builder.obj();
auto stringMap = toStringMap(obj);
- log() << "OBJ:" << obj;
+ LOGV2(23367, "OBJ:{obj}", "obj"_attr = obj);
ASSERT_KEY("Ip:InReceives");
ASSERT_KEY("Ip:OutRequests");
ASSERT_KEY("Tcp:InSegs");
@@ -612,7 +613,7 @@ TEST(FTDCProcDiskStats, TestLocalDiskStats) {
std::vector<StringData> disks2;
for (const auto& disk : disks) {
- log() << "DISK:" << disk;
+ LOGV2(23368, "DISK:{disk}", "disk"_attr = disk);
disks2.emplace_back(disk);
}
@@ -624,7 +625,7 @@ TEST(FTDCProcDiskStats, TestLocalDiskStats) {
BSONObj obj = builder.obj();
auto stringMap = toNestedStringMap(obj);
- log() << "OBJ:" << obj;
+ LOGV2(23369, "OBJ:{obj}", "obj"_attr = obj);
bool foundDisk = false;
diff --git a/src/mongo/util/progress_meter.cpp b/src/mongo/util/progress_meter.cpp
index 1869eca8a95..49d6e06d62a 100644
--- a/src/mongo/util/progress_meter.cpp
+++ b/src/mongo/util/progress_meter.cpp
@@ -34,6 +34,7 @@
#include "mongo/util/progress_meter.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo {
@@ -53,7 +54,7 @@ void ProgressMeter::reset(unsigned long long total, int secondsBetween, int chec
bool ProgressMeter::hit(int n) {
if (!_active) {
- warning() << "hit an inactive ProgressMeter";
+ LOGV2_WARNING(23370, "hit an inactive ProgressMeter");
return false;
}
diff --git a/src/mongo/util/signal_handlers.cpp b/src/mongo/util/signal_handlers.cpp
index 20e82cbc0ea..8c8d04c6254 100644
--- a/src/mongo/util/signal_handlers.cpp
+++ b/src/mongo/util/signal_handlers.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/log_process_details.h"
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/process_id.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/assert_util.h"
@@ -78,24 +79,26 @@ namespace {
#ifdef _WIN32
void consoleTerminate(const char* controlCodeName) {
setThreadName("consoleTerminate");
- log() << "got " << controlCodeName << ", will terminate after current cmd ends";
+ LOGV2(23371,
+ "got {controlCodeName}, will terminate after current cmd ends",
+ "controlCodeName"_attr = controlCodeName);
exitCleanly(EXIT_KILL);
}
BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) {
switch (fdwCtrlType) {
case CTRL_C_EVENT:
- log() << "Ctrl-C signal";
+ LOGV2(23372, "Ctrl-C signal");
consoleTerminate("CTRL_C_EVENT");
return TRUE;
case CTRL_CLOSE_EVENT:
- log() << "CTRL_CLOSE_EVENT signal";
+ LOGV2(23373, "CTRL_CLOSE_EVENT signal");
consoleTerminate("CTRL_CLOSE_EVENT");
return TRUE;
case CTRL_BREAK_EVENT:
- log() << "CTRL_BREAK_EVENT signal";
+ LOGV2(23374, "CTRL_BREAK_EVENT signal");
consoleTerminate("CTRL_BREAK_EVENT");
return TRUE;
@@ -104,7 +107,7 @@ BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) {
return FALSE;
case CTRL_SHUTDOWN_EVENT:
- log() << "CTRL_SHUTDOWN_EVENT signal";
+ LOGV2(23375, "CTRL_SHUTDOWN_EVENT signal");
consoleTerminate("CTRL_SHUTDOWN_EVENT");
return TRUE;
@@ -118,7 +121,9 @@ void eventProcessingThread() {
HANDLE event = CreateEventA(nullptr, TRUE, FALSE, eventName.c_str());
if (event == nullptr) {
- warning() << "eventProcessingThread CreateEvent failed: " << errnoWithDescription();
+ LOGV2_WARNING(23382,
+ "eventProcessingThread CreateEvent failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return;
}
@@ -127,19 +132,24 @@ void eventProcessingThread() {
int returnCode = WaitForSingleObject(event, INFINITE);
if (returnCode != WAIT_OBJECT_0) {
if (returnCode == WAIT_FAILED) {
- warning() << "eventProcessingThread WaitForSingleObject failed: "
- << errnoWithDescription();
+ LOGV2_WARNING(
+ 23383,
+ "eventProcessingThread WaitForSingleObject failed: {errnoWithDescription}",
+ "errnoWithDescription"_attr = errnoWithDescription());
return;
} else {
- warning() << "eventProcessingThread WaitForSingleObject failed: "
- << errnoWithDescription(returnCode);
+ LOGV2_WARNING(23384,
+ "eventProcessingThread WaitForSingleObject failed: "
+ "{errnoWithDescription_returnCode}",
+ "errnoWithDescription_returnCode"_attr =
+ errnoWithDescription(returnCode));
return;
}
}
setThreadName("eventTerminate");
- log() << "shutdown event signaled, will terminate after current cmd ends";
+ LOGV2(23376, "shutdown event signaled, will terminate after current cmd ends");
exitCleanly(EXIT_CLEAN);
}
@@ -169,7 +179,9 @@ bool waitForSignal(const sigset_t& sigset, SignalWaitResult* result) {
if (result->sig == -1) {
if (errsv == EINTR)
continue;
- severe() << "sigwaitinfo failed with error:" << strerror(errsv);
+ LOGV2_FATAL(23385,
+ "sigwaitinfo failed with error:{strerror_errsv}",
+ "strerror_errsv"_attr = strerror(errsv));
return false;
}
return true;
@@ -189,19 +201,25 @@ struct LogRotationState {
void handleOneSignal(const SignalWaitResult& waited, LogRotationState* rotation) {
int sig = waited.sig;
- log() << "got signal " << sig << " (" << strsignal(sig) << ")";
+ LOGV2(23377,
+ "got signal {sig} ({strsignal_sig})",
+ "sig"_attr = sig,
+ "strsignal_sig"_attr = strsignal(sig));
#ifdef __linux__
const siginfo_t& si = waited.si;
switch (si.si_code) {
case SI_USER:
case SI_QUEUE:
- log() << "kill from pid:" << si.si_pid << " uid:" << si.si_uid;
+ LOGV2(23378,
+ "kill from pid:{si_si_pid} uid:{si_si_uid}",
+ "si_si_pid"_attr = si.si_pid,
+ "si_si_uid"_attr = si.si_uid);
break;
case SI_TKILL:
- log() << "tgkill";
+ LOGV2(23379, "tgkill");
break;
case SI_KERNEL:
- log() << "kernel";
+ LOGV2(23380, "kernel");
break;
}
#endif // __linux__
@@ -228,7 +246,7 @@ void handleOneSignal(const SignalWaitResult& waited, LogRotationState* rotation)
}
#endif
// interrupt/terminate signal
- log() << "will terminate after current cmd ends";
+ LOGV2(23381, "will terminate after current cmd ends");
exitCleanly(EXIT_CLEAN);
}
@@ -255,7 +273,9 @@ void signalProcessingThread(LogFileStatus rotate) {
errno = 0;
if (int r = pthread_sigmask(SIG_SETMASK, &waitSignals, nullptr); r != 0) {
int errsv = errno;
- severe() << "pthread_sigmask failed with error:" << strerror(errsv);
+ LOGV2_FATAL(23386,
+ "pthread_sigmask failed with error:{strerror_errsv}",
+ "strerror_errsv"_attr = strerror(errsv));
fassertFailed(31377);
}
diff --git a/src/mongo/util/stacktrace_test.cpp b/src/mongo/util/stacktrace_test.cpp
index 441c965de00..66d53a926d7 100644
--- a/src/mongo/util/stacktrace_test.cpp
+++ b/src/mongo/util/stacktrace_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <array>
@@ -47,10 +49,12 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/bson/json.h"
#include "mongo/config.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/mutex.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/stdx/thread.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/log.h"
#include "mongo/util/stacktrace.h"
#include "mongo/util/stacktrace_json.h"
@@ -501,10 +505,14 @@ public:
}
static void handlerPreamble(int sig) {
- unittest::log() << "tid:" << ostr(stdx::this_thread::get_id()) << ", caught signal " << sig
- << "!\n";
+ LOGV2(23387,
+ "tid:{ostr_stdx_this_thread_get_id}, caught signal {sig}!\n",
+ "ostr_stdx_this_thread_get_id"_attr = ostr(stdx::this_thread::get_id()),
+ "sig"_attr = sig);
char storage;
- unittest::log() << "local var:" << reinterpret_cast<uint64_t>(&storage) << "\n";
+ LOGV2(23388,
+ "local var:{reinterpret_cast_uint64_t_storage}",
+ "reinterpret_cast_uint64_t_storage"_attr = reinterpret_cast<uint64_t>(&storage));
}
static void tryHandler(void (*handler)(int, siginfo_t*, void*)) {
@@ -516,7 +524,9 @@ public:
unittest::log() << "sigaltstack buf: [" << std::hex << buf->size() << std::dec << "] @"
<< std::hex << uintptr_t(buf->data()) << std::dec << "\n";
stdx::thread thr([&] {
- unittest::log() << "tid:" << ostr(stdx::this_thread::get_id()) << " running\n";
+ LOGV2(23389,
+ "tid:{ostr_stdx_this_thread_get_id} running\n",
+ "ostr_stdx_this_thread_get_id"_attr = ostr(stdx::this_thread::get_id()));
{
stack_t ss;
ss.ss_sp = buf->data();
@@ -550,7 +560,7 @@ public:
size_t used = std::distance(
std::find_if(buf->begin(), buf->end(), [](unsigned char x) { return x != kSentinel; }),
buf->end());
- unittest::log() << "stack used: " << used << " bytes\n";
+ LOGV2(23390, "stack used: {used} bytes\n", "used"_attr = used);
}
};
@@ -872,9 +882,13 @@ TEST(StackTrace, BacktraceThroughLibc) {
capture.notify();
return static_cast<int>(static_cast<const int*>(a) < static_cast<const int*>(b));
});
- unittest::log() << "caught [" << capture.arrSize << "]:";
+ LOGV2(23391, "caught [{capture_arrSize}]:", "capture_arrSize"_attr = capture.arrSize);
for (size_t i = 0; i < capture.arrSize; ++i) {
- unittest::log() << " [" << i << "] " << reinterpret_cast<uint64_t>(capture.arr[i]);
+ LOGV2(23392,
+ " [{i}] {reinterpret_cast_uint64_t_capture_arr_i}",
+ "i"_attr = i,
+ "reinterpret_cast_uint64_t_capture_arr_i"_attr =
+ reinterpret_cast<uint64_t>(capture.arr[i]));
}
}
#endif // mongo stacktrace backend
diff --git a/src/mongo/util/stacktrace_threads.cpp b/src/mongo/util/stacktrace_threads.cpp
index dc827524c98..139c865acd5 100644
--- a/src/mongo/util/stacktrace_threads.cpp
+++ b/src/mongo/util/stacktrace_threads.cpp
@@ -144,7 +144,10 @@ public:
CachedMetaGenerator() = default;
~CachedMetaGenerator() {
- log() << "CachedMetaGenerator: " << _hits << "/" << (_hits + _misses);
+ LOGV2(23393,
+ "CachedMetaGenerator: {hits}/{hits_misses}",
+ "hits"_attr = _hits,
+ "hits_misses"_attr = (_hits + _misses));
}
const RedactedMeta& load(void* addr) {
@@ -406,7 +409,9 @@ void State::collectStacks(std::vector<ThreadBacktrace>& messageStorage,
std::vector<int>& missedTids) {
std::set<int> pendingTids;
iterateTids([&](int tid) { pendingTids.insert(tid); });
- log() << "Preparing to dump up to " << pendingTids.size() << " thread stacks";
+ LOGV2(23394,
+ "Preparing to dump up to {pendingTids_size} thread stacks",
+ "pendingTids_size"_attr = pendingTids.size());
messageStorage.resize(pendingTids.size());
received.reserve(pendingTids.size());
@@ -422,14 +427,19 @@ void State::collectStacks(std::vector<ThreadBacktrace>& messageStorage,
errno = 0;
if (int r = tgkill(getpid(), *iter, _signal); r < 0) {
int errsv = errno;
- log() << "failed to signal thread (" << *iter << "):" << strerror(errsv);
+ LOGV2(23395,
+ "failed to signal thread ({iter}):{strerror_errsv}",
+ "iter"_attr = *iter,
+ "strerror_errsv"_attr = strerror(errsv));
missedTids.push_back(*iter);
iter = pendingTids.erase(iter);
} else {
++iter;
}
}
- log() << "signalled " << pendingTids.size() << " threads";
+ LOGV2(23396,
+ "signalled {pendingTids_size} threads",
+ "pendingTids_size"_attr = pendingTids.size());
size_t napMicros = 0;
while (!pendingTids.empty()) {
@@ -634,9 +644,13 @@ void initialize(int signal) {
sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
if (sigaction(signal, &sa, nullptr) != 0) {
int savedErr = errno;
- severe() << format(FMT_STRING("Failed to install sigaction for signal {} ({})"),
- signal,
- strerror(savedErr));
+ LOGV2_FATAL(
+ 23397,
+ "{format_FMT_STRING_Failed_to_install_sigaction_for_signal_signal_strerror_savedErr}",
+ "format_FMT_STRING_Failed_to_install_sigaction_for_signal_signal_strerror_savedErr"_attr =
+ format(FMT_STRING("Failed to install sigaction for signal {} ({})"),
+ signal,
+ strerror(savedErr)));
fassertFailed(31376);
}
}
diff --git a/src/mongo/util/version.cpp b/src/mongo/util/version.cpp
index 494fbabf33d..eefe9fb4131 100644
--- a/src/mongo/util/version.cpp
+++ b/src/mongo/util/version.cpp
@@ -46,6 +46,7 @@
#include <sstream>
#include "mongo/db/jsobj.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/log.h"
@@ -118,7 +119,7 @@ const VersionInfoInterface& VersionInfoInterface::instance(NotEnabledAction acti
return fallbackVersionInfo;
}
- severe() << "Terminating because valid version info has not been configured";
+ LOGV2_FATAL(23405, "Terminating because valid version info has not been configured");
fassertFailed(40278);
}
@@ -195,17 +196,19 @@ std::string VersionInfoInterface::openSSLVersion(StringData prefix, StringData s
}
void VersionInfoInterface::logTargetMinOS() const {
- log() << "targetMinOS: " << targetMinOS();
+ LOGV2(23398, "targetMinOS: {targetMinOS}", "targetMinOS"_attr = targetMinOS());
}
void VersionInfoInterface::logBuildInfo() const {
- log() << "git version: " << gitVersion();
+ LOGV2(23399, "git version: {gitVersion}", "gitVersion"_attr = gitVersion());
#if defined(MONGO_CONFIG_SSL) && MONGO_CONFIG_SSL_PROVIDER == MONGO_CONFIG_SSL_PROVIDER_OPENSSL
- log() << openSSLVersion("OpenSSL version: ");
+ LOGV2(23400,
+ "{openSSLVersion_OpenSSL_version}",
+ "openSSLVersion_OpenSSL_version"_attr = openSSLVersion("OpenSSL version: "));
#endif
- log() << "allocator: " << allocator();
+ LOGV2(23401, "allocator: {allocator}", "allocator"_attr = allocator());
std::stringstream ss;
ss << "modules: ";
@@ -217,15 +220,18 @@ void VersionInfoInterface::logBuildInfo() const {
ss << m << " ";
}
}
- log() << ss.str();
+ LOGV2(23402, "{ss_str}", "ss_str"_attr = ss.str());
- log() << "build environment:";
+ LOGV2(23403, "build environment:");
for (auto&& envDataEntry : buildInfo()) {
if (std::get<3>(envDataEntry)) {
auto val = std::get<1>(envDataEntry);
if (val.size() == 0)
continue;
- log() << " " << std::get<0>(envDataEntry) << ": " << std::get<1>(envDataEntry);
+ LOGV2(23404,
+ " {std_get_0_envDataEntry}: {std_get_1_envDataEntry}",
+ "std_get_0_envDataEntry"_attr = std::get<0>(envDataEntry),
+ "std_get_1_envDataEntry"_attr = std::get<1>(envDataEntry));
}
}
}
diff --git a/src/mongo/watchdog/watchdog.cpp b/src/mongo/watchdog/watchdog.cpp
index accc1b3b06d..cbd6e2df39a 100644
--- a/src/mongo/watchdog/watchdog.cpp
+++ b/src/mongo/watchdog/watchdog.cpp
@@ -45,6 +45,7 @@
#include "mongo/base/static_assert.h"
#include "mongo/db/client.h"
#include "mongo/db/operation_context.h"
+#include "mongo/logv2/log.h"
#include "mongo/platform/process_id.h"
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
@@ -159,13 +160,15 @@ void WatchdogPeriodicThread::doLoop() {
} catch (const DBException& e) {
// The only bad status is when we are in shutdown
if (!opCtx->getServiceContext()->getKillAllOperations()) {
- severe() << "Watchdog was interrupted, shutting down, reason: " << e.toStatus();
+ LOGV2_FATAL(23415,
+ "Watchdog was interrupted, shutting down, reason: {e_toStatus}",
+ "e_toStatus"_attr = e.toStatus());
exitCleanly(ExitCode::EXIT_ABRUPT);
}
// This interruption ends the WatchdogPeriodicThread. This means it is possible to
// killOp this operation and stop it for the lifetime of the process.
- LOG(1) << "WatchdogPeriodicThread interrupted by: " << e;
+ LOGV2_DEBUG(23406, 1, "WatchdogPeriodicThread interrupted by: {e}", "e"_attr = e);
return;
}
@@ -202,8 +205,12 @@ void WatchdogCheckThread::run(OperationContext* opCtx) {
check->run(opCtx);
Microseconds micros = timer.elapsed();
- LOG(1) << "Watchdog test '" << check->getDescriptionForLogging() << "' took "
- << duration_cast<Milliseconds>(micros);
+ LOGV2_DEBUG(23407,
+ 1,
+ "Watchdog test '{check_getDescriptionForLogging}' took "
+ "{duration_cast_Milliseconds_micros}",
+ "check_getDescriptionForLogging"_attr = check->getDescriptionForLogging(),
+ "duration_cast_Milliseconds_micros"_attr = duration_cast<Milliseconds>(micros));
// We completed a check, bump the generation counter.
_checkGeneration.fetchAndAdd(1);
@@ -250,7 +257,7 @@ WatchdogMonitor::WatchdogMonitor(std::vector<std::unique_ptr<WatchdogCheck>> che
}
void WatchdogMonitor::start() {
- log() << "Starting Watchdog Monitor";
+ LOGV2(23408, "Starting Watchdog Monitor");
// Start the threads.
_watchdogCheckThread.start();
@@ -279,12 +286,14 @@ void WatchdogMonitor::setPeriod(Milliseconds duration) {
_watchdogCheckThread.setPeriod(_checkPeriod);
_watchdogMonitorThread.setPeriod(duration);
- log() << "WatchdogMonitor period changed to " << duration_cast<Seconds>(duration);
+ LOGV2(23409,
+ "WatchdogMonitor period changed to {duration_cast_Seconds_duration}",
+ "duration_cast_Seconds_duration"_attr = duration_cast<Seconds>(duration));
} else {
_watchdogMonitorThread.setPeriod(duration);
_watchdogCheckThread.setPeriod(duration);
- log() << "WatchdogMonitor disabled";
+ LOGV2(23410, "WatchdogMonitor disabled");
}
}
}
@@ -342,36 +351,52 @@ void checkFile(OperationContext* opCtx, const boost::filesystem::path& file) {
NULL);
if (hFile == INVALID_HANDLE_VALUE) {
std::uint32_t gle = ::GetLastError();
- severe() << "CreateFile failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(gle);
+ LOGV2_FATAL(
+ 23416,
+ "CreateFile failed for '{file_generic_string}' with error: {errnoWithDescription_gle}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
fassertNoTrace(4074, gle == 0);
}
DWORD bytesWrittenTotal;
if (!WriteFile(hFile, nowStr.c_str(), nowStr.size(), &bytesWrittenTotal, NULL)) {
std::uint32_t gle = ::GetLastError();
- severe() << "WriteFile failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(gle);
+ LOGV2_FATAL(
+ 23417,
+ "WriteFile failed for '{file_generic_string}' with error: {errnoWithDescription_gle}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
fassertNoTrace(4075, gle == 0);
}
if (bytesWrittenTotal != nowStr.size()) {
- warning() << "partial write for '" << file.generic_string() << "' expected "
- << nowStr.size() << " bytes but wrote " << bytesWrittenTotal << " bytes";
+ LOGV2_WARNING(23411,
+ "partial write for '{file_generic_string}' expected {nowStr_size} bytes but "
+ "wrote {bytesWrittenTotal} bytes",
+ "file_generic_string"_attr = file.generic_string(),
+ "nowStr_size"_attr = nowStr.size(),
+ "bytesWrittenTotal"_attr = bytesWrittenTotal);
} else {
if (!FlushFileBuffers(hFile)) {
std::uint32_t gle = ::GetLastError();
- severe() << "FlushFileBuffers failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(gle);
+ LOGV2_FATAL(23418,
+ "FlushFileBuffers failed for '{file_generic_string}' with error: "
+ "{errnoWithDescription_gle}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
fassertNoTrace(4076, gle == 0);
}
DWORD newOffset = SetFilePointer(hFile, 0, 0, FILE_BEGIN);
if (newOffset != 0) {
std::uint32_t gle = ::GetLastError();
- severe() << "SetFilePointer failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(gle);
+ LOGV2_FATAL(23419,
+ "SetFilePointer failed for '{file_generic_string}' with error: "
+ "{errnoWithDescription_gle}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
fassertNoTrace(4077, gle == 0);
}
@@ -379,29 +404,46 @@ void checkFile(OperationContext* opCtx, const boost::filesystem::path& file) {
auto readBuffer = std::make_unique<char[]>(nowStr.size());
if (!ReadFile(hFile, readBuffer.get(), nowStr.size(), &bytesRead, NULL)) {
std::uint32_t gle = ::GetLastError();
- severe() << "ReadFile failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(gle);
+ LOGV2_FATAL(23420,
+ "ReadFile failed for '{file_generic_string}' with error: "
+ "{errnoWithDescription_gle}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
fassertNoTrace(4078, gle == 0);
}
if (bytesRead != bytesWrittenTotal) {
- severe() << "Read wrong number of bytes for '" << file.generic_string() << "' expected "
- << bytesWrittenTotal << " bytes but read " << bytesRead << " bytes";
+ LOGV2_FATAL(23421,
+ "Read wrong number of bytes for '{file_generic_string}' expected "
+ "{bytesWrittenTotal} bytes but read {bytesRead} bytes",
+ "file_generic_string"_attr = file.generic_string(),
+ "bytesWrittenTotal"_attr = bytesWrittenTotal,
+ "bytesRead"_attr = bytesRead);
fassertNoTrace(50724, false);
}
if (memcmp(nowStr.c_str(), readBuffer.get(), nowStr.size()) != 0) {
- severe() << "Read wrong string from file '" << file.generic_string() << nowStr.size()
- << " bytes (in hex) '" << toHexLower(nowStr.c_str(), nowStr.size())
- << "' but read bytes '" << toHexLower(readBuffer.get(), bytesRead) << "'";
+ LOGV2_FATAL(23422,
+ "Read wrong string from file '{file_generic_string}{nowStr_size} bytes (in "
+ "hex) '{toHexLower_nowStr_c_str_nowStr_size}' but read bytes "
+ "'{toHexLower_readBuffer_get_bytesRead}'",
+ "file_generic_string"_attr = file.generic_string(),
+ "nowStr_size"_attr = nowStr.size(),
+ "toHexLower_nowStr_c_str_nowStr_size"_attr =
+ toHexLower(nowStr.c_str(), nowStr.size()),
+ "toHexLower_readBuffer_get_bytesRead"_attr =
+ toHexLower(readBuffer.get(), bytesRead));
fassertNoTrace(50717, false);
}
}
if (!CloseHandle(hFile)) {
std::uint32_t gle = ::GetLastError();
- severe() << "CloseHandle failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(gle);
+ LOGV2_FATAL(
+ 23423,
+ "CloseHandle failed for '{file_generic_string}' with error: {errnoWithDescription_gle}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_gle"_attr = errnoWithDescription(gle));
fassertNoTrace(4079, gle == 0);
}
}
@@ -426,8 +468,11 @@ void checkFile(OperationContext* opCtx, const boost::filesystem::path& file) {
int fd = open(file.generic_string().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd == -1) {
auto err = errno;
- severe() << "open failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(err);
+ LOGV2_FATAL(
+ 23424,
+ "open failed for '{file_generic_string}' with error: {errnoWithDescription_err}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
fassertNoTrace(4080, err == 0);
}
@@ -441,15 +486,22 @@ void checkFile(OperationContext* opCtx, const boost::filesystem::path& file) {
continue;
}
- severe() << "write failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(err);
+ LOGV2_FATAL(
+ 23425,
+ "write failed for '{file_generic_string}' with error: {errnoWithDescription_err}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
fassertNoTrace(4081, err == 0);
}
// Warn if the write was incomplete
if (bytesWrittenTotal == 0 && static_cast<size_t>(bytesWrittenInWrite) != nowStr.size()) {
- warning() << "parital write for '" << file.generic_string() << "' expected "
- << nowStr.size() << " bytes but wrote " << bytesWrittenInWrite << " bytes";
+ LOGV2_WARNING(23412,
+ "parital write for '{file_generic_string}' expected {nowStr_size} bytes "
+ "but wrote {bytesWrittenInWrite} bytes",
+ "file_generic_string"_attr = file.generic_string(),
+ "nowStr_size"_attr = nowStr.size(),
+ "bytesWrittenInWrite"_attr = bytesWrittenInWrite);
}
bytesWrittenTotal += bytesWrittenInWrite;
@@ -457,8 +509,11 @@ void checkFile(OperationContext* opCtx, const boost::filesystem::path& file) {
if (fsync(fd)) {
auto err = errno;
- severe() << "fsync failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(err);
+ LOGV2_FATAL(
+ 23426,
+ "fsync failed for '{file_generic_string}' with error: {errnoWithDescription_err}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
fassertNoTrace(4082, err == 0);
}
@@ -473,36 +528,53 @@ void checkFile(OperationContext* opCtx, const boost::filesystem::path& file) {
continue;
}
- severe() << "read failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(err);
+ LOGV2_FATAL(
+ 23427,
+ "read failed for '{file_generic_string}' with error: {errnoWithDescription_err}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
fassertNoTrace(4083, err == 0);
} else if (bytesReadInRead == 0) {
- severe() << "read failed for '" << file.generic_string()
- << "' with unexpected end of file";
+ LOGV2_FATAL(23428,
+ "read failed for '{file_generic_string}' with unexpected end of file",
+ "file_generic_string"_attr = file.generic_string());
fassertNoTrace(50719, false);
}
// Warn if the read was incomplete
if (bytesReadTotal == 0 && static_cast<size_t>(bytesReadInRead) != nowStr.size()) {
- warning() << "partial read for '" << file.generic_string() << "' expected "
- << nowStr.size() << " bytes but read " << bytesReadInRead << " bytes";
+ LOGV2_WARNING(23413,
+ "partial read for '{file_generic_string}' expected {nowStr_size} bytes "
+ "but read {bytesReadInRead} bytes",
+ "file_generic_string"_attr = file.generic_string(),
+ "nowStr_size"_attr = nowStr.size(),
+ "bytesReadInRead"_attr = bytesReadInRead);
}
bytesReadTotal += bytesReadInRead;
}
if (memcmp(nowStr.c_str(), readBuffer.get(), nowStr.size()) != 0) {
- severe() << "Read wrong string from file '" << file.generic_string() << "' expected "
- << nowStr.size() << " bytes (in hex) '"
- << toHexLower(nowStr.c_str(), nowStr.size()) << "' but read bytes '"
- << toHexLower(readBuffer.get(), bytesReadTotal) << "'";
+ LOGV2_FATAL(23429,
+ "Read wrong string from file '{file_generic_string}' expected {nowStr_size} "
+ "bytes (in hex) '{toHexLower_nowStr_c_str_nowStr_size}' but read bytes "
+ "'{toHexLower_readBuffer_get_bytesReadTotal}'",
+ "file_generic_string"_attr = file.generic_string(),
+ "nowStr_size"_attr = nowStr.size(),
+ "toHexLower_nowStr_c_str_nowStr_size"_attr =
+ toHexLower(nowStr.c_str(), nowStr.size()),
+ "toHexLower_readBuffer_get_bytesReadTotal"_attr =
+ toHexLower(readBuffer.get(), bytesReadTotal));
fassertNoTrace(50718, false);
}
if (close(fd)) {
auto err = errno;
- severe() << "close failed for '" << file.generic_string()
- << "' with error: " << errnoWithDescription(err);
+ LOGV2_FATAL(
+ 23430,
+ "close failed for '{file_generic_string}' with error: {errnoWithDescription_err}",
+ "file_generic_string"_attr = file.generic_string(),
+ "errnoWithDescription_err"_attr = errnoWithDescription(err));
fassertNoTrace(4084, err == 0);
}
}
@@ -529,8 +601,10 @@ void DirectoryCheck::run(OperationContext* opCtx) {
boost::system::error_code ec;
boost::filesystem::remove(file, ec);
if (ec) {
- warning() << "Failed to delete file '" << file.generic_string()
- << "', error: " << ec.message();
+ LOGV2_WARNING(23414,
+ "Failed to delete file '{file_generic_string}', error: {ec_message}",
+ "file_generic_string"_attr = file.generic_string(),
+ "ec_message"_attr = ec.message());
}
}
diff --git a/src/mongo/watchdog/watchdog_test.cpp b/src/mongo/watchdog/watchdog_test.cpp
index bc8bac2cc7b..02795b57481 100644
--- a/src/mongo/watchdog/watchdog_test.cpp
+++ b/src/mongo/watchdog/watchdog_test.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/client.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_test_fixture.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/temp_dir.h"
#include "mongo/unittest/unittest.h"
@@ -300,7 +301,7 @@ class WatchdogMonitorThreadTest : public ServiceContextTest {};
TEST_F(WatchdogMonitorThreadTest, Basic) {
ManualResetEvent deathEvent;
WatchdogDeathCallback deathCallback = [&deathEvent]() {
- log() << "Death signalled";
+ LOGV2(23431, "Death signalled");
deathEvent.set();
};
@@ -345,7 +346,7 @@ private:
TEST_F(WatchdogMonitorThreadTest, SleepyHungCheck) {
ManualResetEvent deathEvent;
WatchdogDeathCallback deathCallback = [&deathEvent]() {
- log() << "Death signalled";
+ LOGV2(23432, "Death signalled");
deathEvent.set();
};
@@ -375,7 +376,7 @@ class WatchdogMonitorTest : public ServiceContextTest {};
TEST_F(WatchdogMonitorTest, SleepyHungCheck) {
ManualResetEvent deathEvent;
WatchdogDeathCallback deathCallback = [&deathEvent]() {
- log() << "Death signalled";
+ LOGV2(23433, "Death signalled");
deathEvent.set();
};
@@ -412,7 +413,7 @@ DEATH_TEST(WatchdogMonitorTest, Death, "") {
TEST_F(WatchdogMonitorTest, PauseAndResume) {
WatchdogDeathCallback deathCallback = []() {
- log() << "Death signalled, it should not have been";
+ LOGV2(23434, "Death signalled, it should not have been");
invariant(false);
};