How to fix: Mongo::Error::OperationFailure
How to fix: Mongo::Error::OperationFailure
我的 Ruby 在 Rails 应用程序上的生产日志有以下一些错误类型:
Mongo::Error::OperationFailure
[225:TransactionTooOld]: Retryable write with txnNumber 12 is prohibited on session b39c1b6b-54f5-4f5d-a010-7067c095bac7
数据库有一个主实例和两个副本。我想知道如何预防和解决这个问题。提前谢谢你
日志
mongo (2.15.0) lib/mongo/operation/result.rb:348:in `raise_operation_failure'
mongo (2.15.0) lib/mongo/operation/result.rb:314:in `validate!'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:36:in `block (3 levels) in validate_result'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:107:in `add_server_diagnostics'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:35:in `block (2 levels) in validate_result'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:54:in `add_error_labels'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:34:in `block in validate_result'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:93:in `unpin_maybe'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:33:in `validate_result'
mongo (2.15.0) lib/mongo/operation/shared/write.rb:49:in `block in execute'
mongo (2.15.0) lib/mongo/server/connection_pool.rb:593:in `with_connection'
mongo (2.15.0) lib/mongo/server.rb:437:in `with_connection'
mongo (2.15.0) lib/mongo/operation/shared/write.rb:38:in `execute'
mongo (2.15.0) lib/mongo/collection.rb:607:in `block (2 levels) in insert_one'
mongo (2.15.0) lib/mongo/retryable.rb:230:in `write_with_retry'
mongo (2.15.0) lib/mongo/collection.rb:596:in `block in insert_one'
mongo (2.15.0) lib/mongo/client.rb:1057:in `with_session'
mongo (2.15.0) lib/mongo/collection.rb:585:in `insert_one'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:83:in `insert_as_root'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:29:in `block in insert'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:122:in `block (2 levels) in prepare_insert'
activesupport (6.1.4) lib/active_support/callbacks.rb:106:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/interceptable.rb:135:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:121:in `block in prepare_insert'
activesupport (6.1.4) lib/active_support/callbacks.rb:98:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/interceptable.rb:135:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:120:in `prepare_insert'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:25:in `insert'
mongoid (7.3.2) lib/mongoid/persistable/savable.rb:25:in `save'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:153:in `block in create'
mongoid (7.3.2) lib/mongoid/threaded/lifecycle.rb:163:in `_creating'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:148:in `create'
app/models/email_message.rb:32:in `email_message'
app/controllers/application_controller.rb:17:in `render_error'
app/controllers/application_controller.rb:8:in `block in <class:ApplicationController>'
activesupport (6.1.4) lib/active_support/rescuable.rb:116:in `instance_exec'
activesupport (6.1.4) lib/active_support/rescuable.rb:116:in `block in handler_for_rescue'
activesupport (6.1.4) lib/active_support/rescuable.rb:92:in `rescue_with_handler'
activesupport (6.1.4) lib/active_support/rescuable.rb:165:in `rescue_with_handler'
actionpack (6.1.4) lib/action_controller/metal/rescue.rb:25:in `rescue in process_action'
actionpack (6.1.4) lib/action_controller/metal/rescue.rb:21:in `process_action'
actionpack (6.1.4) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (6.1.4) lib/active_support/notifications.rb:203:in `block in instrument'
activesupport (6.1.4) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.1.4) lib/active_support/notifications.rb:203:in `instrument'
actionpack (6.1.4) lib/action_controller/metal/instrumentation.rb:33:in `process_action'
actionpack (6.1.4) lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
mongoid (7.3.2) lib/mongoid/railties/controller_runtime.rb:22:in `process_action'
actionpack (6.1.4) lib/abstract_controller/base.rb:165:in `process'
actionpack (6.1.4) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (6.1.4) lib/action_controller/metal.rb:254:in `dispatch'
actionpack (6.1.4) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (6.1.4) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.1.4) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
actionpack (6.1.4) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (6.1.4) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (6.1.4) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.1.4) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.1.4) lib/action_dispatch/routing/route_set.rb:842:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack-pjax (1.1.0) lib/rack/pjax.rb:12:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
newrelic_rpm (7.2.0) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
newrelic_rpm (7.2.0) lib/new_relic/rack/browser_monitoring.rb:33:in `traced_call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/cookies.rb:689:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
remotipart (1.4.4) lib/remotipart/middleware.rb:32:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/cookies.rb:689:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.1.4) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (6.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
logster (2.9.7) lib/logster/middleware/reporter.rb:43:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
railties (6.1.4) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.1.4) lib/rails/rack/logger.rb:28:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/request_id.rb:26:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
act
database.yml
production:
clients:
default:
uri: "mongodb://user:password@[PRIMARY_IP_ADDRESS]:27017/[db_name is here]"
options:
auth_source: admin
read:
mode: :nearest
max_pool_size: 40
min_pool_size: 1
ssl: false
ssl_verify: false
我的 Ruby 在 Rails 应用程序上的生产日志有以下一些错误类型:
Mongo::Error::OperationFailure
[225:TransactionTooOld]: Retryable write with txnNumber 12 is prohibited on session b39c1b6b-54f5-4f5d-a010-7067c095bac7
数据库有一个主实例和两个副本。我想知道如何预防和解决这个问题。提前谢谢你
日志
mongo (2.15.0) lib/mongo/operation/result.rb:348:in `raise_operation_failure'
mongo (2.15.0) lib/mongo/operation/result.rb:314:in `validate!'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:36:in `block (3 levels) in validate_result'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:107:in `add_server_diagnostics'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:35:in `block (2 levels) in validate_result'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:54:in `add_error_labels'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:34:in `block in validate_result'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:93:in `unpin_maybe'
mongo (2.15.0) lib/mongo/operation/shared/response_handling.rb:33:in `validate_result'
mongo (2.15.0) lib/mongo/operation/shared/write.rb:49:in `block in execute'
mongo (2.15.0) lib/mongo/server/connection_pool.rb:593:in `with_connection'
mongo (2.15.0) lib/mongo/server.rb:437:in `with_connection'
mongo (2.15.0) lib/mongo/operation/shared/write.rb:38:in `execute'
mongo (2.15.0) lib/mongo/collection.rb:607:in `block (2 levels) in insert_one'
mongo (2.15.0) lib/mongo/retryable.rb:230:in `write_with_retry'
mongo (2.15.0) lib/mongo/collection.rb:596:in `block in insert_one'
mongo (2.15.0) lib/mongo/client.rb:1057:in `with_session'
mongo (2.15.0) lib/mongo/collection.rb:585:in `insert_one'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:83:in `insert_as_root'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:29:in `block in insert'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:122:in `block (2 levels) in prepare_insert'
activesupport (6.1.4) lib/active_support/callbacks.rb:106:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/interceptable.rb:135:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:121:in `block in prepare_insert'
activesupport (6.1.4) lib/active_support/callbacks.rb:98:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/interceptable.rb:135:in `run_callbacks'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:120:in `prepare_insert'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:25:in `insert'
mongoid (7.3.2) lib/mongoid/persistable/savable.rb:25:in `save'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:153:in `block in create'
mongoid (7.3.2) lib/mongoid/threaded/lifecycle.rb:163:in `_creating'
mongoid (7.3.2) lib/mongoid/persistable/creatable.rb:148:in `create'
app/models/email_message.rb:32:in `email_message'
app/controllers/application_controller.rb:17:in `render_error'
app/controllers/application_controller.rb:8:in `block in <class:ApplicationController>'
activesupport (6.1.4) lib/active_support/rescuable.rb:116:in `instance_exec'
activesupport (6.1.4) lib/active_support/rescuable.rb:116:in `block in handler_for_rescue'
activesupport (6.1.4) lib/active_support/rescuable.rb:92:in `rescue_with_handler'
activesupport (6.1.4) lib/active_support/rescuable.rb:165:in `rescue_with_handler'
actionpack (6.1.4) lib/action_controller/metal/rescue.rb:25:in `rescue in process_action'
actionpack (6.1.4) lib/action_controller/metal/rescue.rb:21:in `process_action'
actionpack (6.1.4) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (6.1.4) lib/active_support/notifications.rb:203:in `block in instrument'
activesupport (6.1.4) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.1.4) lib/active_support/notifications.rb:203:in `instrument'
actionpack (6.1.4) lib/action_controller/metal/instrumentation.rb:33:in `process_action'
actionpack (6.1.4) lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
mongoid (7.3.2) lib/mongoid/railties/controller_runtime.rb:22:in `process_action'
actionpack (6.1.4) lib/abstract_controller/base.rb:165:in `process'
actionpack (6.1.4) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (6.1.4) lib/action_controller/metal.rb:254:in `dispatch'
actionpack (6.1.4) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (6.1.4) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.1.4) lib/action_dispatch/routing/mapper.rb:19:in `block in <class:Constraints>'
actionpack (6.1.4) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (6.1.4) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (6.1.4) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.1.4) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.1.4) lib/action_dispatch/routing/route_set.rb:842:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack-pjax (1.1.0) lib/rack/pjax.rb:12:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
newrelic_rpm (7.2.0) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
newrelic_rpm (7.2.0) lib/new_relic/rack/browser_monitoring.rb:33:in `traced_call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/cookies.rb:689:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
remotipart (1.4.4) lib/remotipart/middleware.rb:32:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/cookies.rb:689:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.1.4) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (6.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
logster (2.9.7) lib/logster/middleware/reporter.rb:43:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
railties (6.1.4) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.1.4) lib/rails/rack/logger.rb:28:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/request_id.rb:26:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
actionpack (6.1.4) lib/action_dispatch/middleware/executor.rb:14:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
newrelic_rpm (7.2.0) lib/new_relic/agent/instrumentation/middleware_tracing.rb:101:in `call'
act
database.yml
production:
clients:
default:
uri: "mongodb://user:password@[PRIMARY_IP_ADDRESS]:27017/[db_name is here]"
options:
auth_source: admin
read:
mode: :nearest
max_pool_size: 40
min_pool_size: 1
ssl: false
ssl_verify: false