moped icon indicating copy to clipboard operation
moped copied to clipboard

Updates cached or so?

Open solars opened this issue 12 years ago • 7 comments

Hi there,

We have encountered a weird problem: I've got a ruby app that polls messages from a queue (rabbitmq) and inserts into a mongodb (via mongoid).

I noticed that when the mongodb was not writeable (locked), the daemon still processed messages, and marked them as saved. However, they didn't arrive in the mongodb, even when the db was back online again they were not inserted. Only after restarting the app, the objects appeared in the database.

Does anyone know what could be the reason for this? Or how I can debug this in more detail?

Thanks a lot, Christoph

solars avatar Nov 18 '13 12:11 solars

  • which version of mongoid are you using?
  • Are you sure you are using safe writes, to insert in the DB?

arthurnn avatar Nov 18 '13 15:11 arthurnn

Mongoid mongoid (3.0.23) moped (1.5.1)

With the safe mode option it complains - is the version too old?

solars avatar Nov 18 '13 15:11 solars

(what do you mean, by it complains? it raises an error?, the error raises when you insert, or somewhere else?) I think what you should do is:

  • Upgrade to mongoid 3.1
  • insert to the collection using safe write, something like this:
Item.with(safe: true).create!(counter: 1, name: 'foo')

arthurnn avatar Nov 18 '13 16:11 arthurnn

sorry :) I meant:

/usr/local/rvm/gems/ruby-1.9.3-p448@history-daemon/gems/mongoid-3.0.23/lib/mongoid/config/validators/option.rb:19:in `validate': (Mongoid::Errors::InvalidConfigOption) Problem: Invalid configuration option: safe. Summary: A invalid configuration option was provided in your mongoid.yml, or a typo is potentially present. The valid configuration options are: :allow_dynamic_fields, :identity_map_enabled, :include_root_in_json, :include_type_for_serialization, :preload_models, :protect_sensitive_fields, :raise_not_found_error, :scope_overwrite_exception, :skip_version_check, :use_activesupport_time_zone, :use_utc. Resolution: Remove the invalid option or fix the typo. If you were expecting the option to be there, please consult the following page with repect to Mongoid's configuration:

solars avatar Nov 18 '13 16:11 solars

the option must be set under session/default, something like this:

production:
  sessions:
    default:
      hosts:
        - flame.mongohq.com:27017
      database: mongoid
      options:
        consistency: :strong
        safe: true

arthurnn avatar Nov 18 '13 16:11 arthurnn

ah, I had it in the wrong place!

now I get: 2013-11-18 17:18:59.854056 history-daemon(28679) [ERROR] history-daemon.rb:44: ERROR - Update not processed, Could not connect to a primary node for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">, <Moped::Node resolved_address="127.0.0.1:27019">, <Moped::Node resolved_address="127.0.0.1:27020">, <Moped::Node resolved_address="5.9.42.201:27017">]>

when I set to read only so I think this is the way to go, and if I don't use the flat then it doesn't realize that the db is not writeable and just pushes into it?

but what's the explanation for the updates floating around somewhere in between until the daemon is restarted?

solars avatar Nov 18 '13 16:11 solars

Did you strip the details out or are the addresses of the nodes actually in the wrong place as well?

durran avatar Dec 02 '13 16:12 durran