NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

NoBrainer::Error::MissingIndex error after running rake `nobrainer:sync_schema` and `nobrainer:sync_indexes` #240

Closed christiankakesa closed 7 years ago

christiankakesa commented 7 years ago

I created a document with an index. After running the tasks : rake nobrainer:sync_schema and rake nobrainer:sync_indexes (nobrainer_index_meta table is created) ; I have this error :

NoBrainer::Error::MissingIndex at /
Please run `NoBrainer.sync_indexes' or `rake nobrainer:sync_indexes' to create the index `sid` in the table `forgedtofightio_development.rack__session__no_brainer_session_stores`. Read http://nobrainer.io/docs/indexes for more information.

But calling ::NoBrainer.sync_indexes programmatically is OK.

nviennot commented 7 years ago

My guess is that the rake task is, for some reason, invoking some logic that hits the DB. What's the full stack trace?

christiankakesa commented 7 years ago

Full stack trace :

18:33:14 web.1  | E, [2017-07-21T18:33:14.366946 #25931] ERROR -- : [  38.7ms] r.table("rack__session__no_brainer_session_stores").get_all( "f38fcceb82204e170343d855e0d737b10d8954f4c48c4f9098b0ab8d97c4bbe1", {"index" => :sid}).order_by(r.asc(:id)).limit(1) -- RethinkDB::ReqlOpFailedError Index `sid` was not found on table `forgedtofightio_development.rack__session__no_brainer_session_stores`.
18:33:14 web.1  | NoBrainer::Error::MissingIndex: Please run `NoBrainer.sync_indexes' or `rake nobrainer:sync_indexes' to create the index `sid` in the table `forgedtofightio_development.rack__session__no_brainer_session_stores`. Read http://nobrainer.io/docs/indexes for more information.
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/query_runner/missing_index.rb:20:in `rescue in call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/query_runner/missing_index.rb:3:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/query_runner/run_options.rb:48:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/middleware-0.1.0/lib/middleware/runner.rb:31:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/middleware-0.1.0/lib/middleware/builder.rb:102:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/query_runner.rb:21:in `run'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/nobrainer.rb:26:in `run'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/criteria/run.rb:16:in `run'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/criteria/run.rb:12:in `run'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/criteria/first.rb:29:in `get_one'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/criteria/eager_load.rb:43:in `get_one'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/criteria/first.rb:5:in `first'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/nobrainer-0.33.0/lib/no_brainer/criteria/cache.rb:64:in `block (2 levels) in use_cache_for'
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/lib/rack/session/nobrainer.rb:96:in `_exists?'
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/lib/rack/session/nobrainer.rb:38:in `block in generate_sid'
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/lib/rack/session/nobrainer.rb:36:in `loop'
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/lib/rack/session/nobrainer.rb:36:in `generate_sid'
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/lib/rack/session/nobrainer.rb:44:in `block in get_session'
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/lib/rack/session/nobrainer.rb:70:in `with_lock'
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/lib/rack/session/nobrainer.rb:43:in `get_session'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:425:in `find_session'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:280:in `load_session'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:157:in `load!'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:153:in `load_for_write!'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:77:in `[]='
18:33:14 web.1  |       /home/christian/workspace/forgedtofight.io/app.rb:29:in `block in <top (required)>'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/syro-3.0.1/lib/syro.rb:271:in `instance_eval'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/syro-3.0.1/lib/syro.rb:271:in `block in call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/syro-3.0.1/lib/syro.rb:270:in `catch'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/syro-3.0.1/lib/syro.rb:270:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/syro-3.0.1/lib/syro.rb:371:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/shield-2.1.1/lib/shield.rb:14:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-timeout-0.4.2/lib/rack/timeout/core.rb:122:in `block in call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-timeout-0.4.2/lib/rack/timeout/support/timeout.rb:19:in `timeout'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-timeout-0.4.2/lib/rack/timeout/core.rb:121:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/show_exceptions.rb:23:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:232:in `context'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/deflater.rb:34:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/content_type.rb:19:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/content_length.rb:15:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/common_logger.rb:33:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/chunked.rb:54:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/builder.rb:153:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/urlmap.rb:68:in `block in call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `each'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/lint.rb:49:in `_call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/lint.rb:37:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/show_exceptions.rb:23:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/common_logger.rb:33:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/shotgun-0.9.2/lib/shotgun/loader.rb:86:in `proceed_as_child'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/shotgun-0.9.2/lib/shotgun/loader.rb:31:in `call!'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/shotgun-0.9.2/lib/shotgun/loader.rb:18:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/shotgun-0.9.2/lib/shotgun/favicon.rb:12:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/shotgun-0.9.2/lib/shotgun/static.rb:14:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/urlmap.rb:68:in `block in call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `each'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/urlmap.rb:53:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/rack-2.0.3/lib/rack/builder.rb:153:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/puma-3.9.1/lib/puma/configuration.rb:224:in `call'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/puma-3.9.1/lib/puma/server.rb:602:in `handle_request'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/puma-3.9.1/lib/puma/server.rb:435:in `process_client'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/puma-3.9.1/lib/puma/server.rb:299:in `block in run'
18:33:14 web.1  |       /home/christian/.rvm/gems/ruby-2.4.1@forgedtofight/gems/puma-3.9.1/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
nviennot commented 7 years ago

for some reason, puma is getting called for a client request (puma/server.rb:602:in `handle_request') which then invoke a controller, which then queries the session stored in the DB from a client cookie. Invoking a rake nobrainer:sync_index should not issue a request against the puma web server. Check what's in your app/config/initializers

christiankakesa commented 7 years ago

Ok, thanks for the advice. I'm not using RubyOnRails but a very light web framework called Syro ; when my task start, models are not created in database, that's was my mistake.

I fix my problem by load my boot step before running rake tasks. Everything is OK now.

christian@y510p:~/workspace/forgedtofight.io$ foreman run rake nobrainer:sync_schema
[NoBrainer] Create index Rack::Session::NoBrainerSessionStore.sid