Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with HA console when ruby-debug is loaded #240

Closed
dwbutler opened this issue Feb 8, 2013 · 11 comments
Closed

Issue with HA console when ruby-debug is loaded #240

dwbutler opened this issue Feb 8, 2013 · 11 comments

Comments

@dwbutler
Copy link

dwbutler commented Feb 8, 2013

I tried out the console in HA mode following the instructions here:

https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3Aha-cluster

It didn't work for me at first - the console kept opening the same database as the rails server and going into readonly mode. Eventually I tracked the problem down to this line:

https://github.com/andreasronge/neo4j/blob/master/lib/neo4j/rails/ha_console/railtie.rb#L12

It turns out in my app, I load the 'ruby-debug' gem. This is loaded by Bundler This in turn loads IRB, which causes both the rails console and server to have IRB loaded.

I worked around the issue by doing the following:

Gemfile:

group :development do
  gem 'ruby-debug', :require => false
end

config/application.rb:

require 'neo4j/rails/ha_console/railtie' if Rails.env.development?
...
module MyRailsApp
  class Application < Rails::Application
    ...
    require 'ruby-debug' if Rails.env.development?

I'm not sure if there's a better way to do this. It's difficult to tell whether one is running in the Rails server or in the console.

@andreasronge
Copy link
Member

Aha, good to know. No I don't if there is a better way.

@ruprict
Copy link

ruprict commented May 13, 2013

I don't think this will work for Pry, as it is defined everywhere in development. As such, both server and console get 2 as a server_id.

Our fix was to put the contents of the railtie into config/environments/development.rb, check for Rails::Console:

 server_id = ((defined? Rails::Console)) ? 2 : 1
 config.neo4j['enable_ha'] = true
 config.neo4j['ha.server_id'] = server_id
 config.neo4j['ha.server'] = "localhost:600#{server_id}"
 config.neo4j['ha.pull_interval'] = '500ms'
 config.neo4j['ha.discovery.enabled'] = false
 config.neo4j['ha.initial_hosts'] = [1,2,3].map{|id| "localhost:500#{id}"}.join(',')
 config.neo4j['ha.cluster_server'] = "localhost:500#{server_id}"
 config.neo4j.storage_path = File.expand_path("db/ha_neo_#{server_id}", Object::Rails.root)
 puts "Config HA cluster, ha.server_id: #{config.neo4j['ha.server_id']}, db: #{config.neo4j.storage_path}"

Make sure you comment out the ha_console/railtie line in application.rb if you go this route. We are still testing, but it's working in our first glance.

@dwbutler
Copy link
Author

Cool! This fix works for me.

@ruprict
Copy link

ruprict commented May 15, 2013

BTW, if you want the neo-shell back, you can add

config.neo4j['enable_remote_shell'] = "port=133#{server_id}" 

To this config, then from a terminal prompt neo4j-shell -port 1331 (or whatever the port you want is) you have the shell back.

NOTE: The neo4j-shell command MUST be run from a prompt where JRUBY is not the current ruby. So, I am running RVM, I run it from a prompt where I am using ruby 2.0 and it works. If you try to run the neo4j-shell from a prompt where the ruby is JRuby, you'll get a Java error about JLine something or other (there is an issue on this)

Anyway, I was glad to have the shell back.

@dwbutler
Copy link
Author

@ruprict, do you plan to submit a pull request for this?

@ruprict
Copy link

ruprict commented May 21, 2013

I could, but have to figure out what will be in that PR. The fixes I have here are pretty much doc changes. From what I have found, the things we need to be defined (Rails::Console and Pry) are not when the railtie is called. As such, we have to take the code out of the railtie and put it in the development.rb config file.

I guess we could put this in an initializer (complete with a if Rails.env.development?), but that seems like a lateral move, at best.

I'd love to hear other opinions and/or corrections, as I am prepared to be wrong about this.

@dwbutler
Copy link
Author

I dug through the Rails source a bit and I think I found the solution. It appears that you can add block to a railtie that will be run when the console is loaded. Something like this should work

class Neo4j::Railtie < Rails::Railtie
  config.neo4j['ha.server_id'] = 1

  console do
    config.neo4j['ha.server_id'] = 2
  end

  after_initialize do
    config.neo4j['ha.server'] = "localhost:600#{config.neo4j['ha.server_id']}"
    # etc
  end
end

@ruprict
Copy link

ruprict commented May 22, 2013

Nice, that's great. Have you tried this? If so, you should definitely PR it.

Good work.

@dwbutler
Copy link
Author

I've not actually tried it, but I'll try it soon when I find some time.

@thekendalmiller
Copy link
Contributor

#261 to fix this

@dwbutler
Copy link
Author

Thanks @thekendalmiller!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants