view · edit · sidebar · attach · print · history

20110126-check-migrate-ramaze_oddb

<< | Index | >>


  1. Read migrate script

Goal
  • Understand migrate / 70%
Milestones
  • Read migrate script
Summary
Commits
ToDo Tomorrow
  • Continue checking migrate script
  • Debug TypeError first
  • Focus on company object next
Keep in Mind
  1. Check rdbi instead of dbi for ODBA
  2. Encoding woes (from Davatz-san)
  3. Feedback: This option indicates that the regular expression is parsed as 'UTF8' (from Davatz-san)
  4. pg on Ubuntu - see http://dev.ywesee.com/wiki.php/Gem/Pg (from Davatz-san)
  5. On Ice
  6. emerge --sync

Read migrate script

Experiment

ch.oddb.org/bin/migrate

#!/usr/bin/env ruby19

$: << File.expand_path('../lib', File.dirname(__FILE__))

p "A"
require 'drb'
p "B"
require 'oddb/persistence/odba'
p "C"
require 'odba/18_19_loading_compatibility'
p "D"
$project_path, url, _ = ARGV
$project_path ||= '/var/www/oddb.org'
url ||= 'druby://localhost:10000'
p "E"
count = ODBA.cache.count(ODDB::Business::Company)
p count
exit

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate 
"A"
"B"
ERROR:  relation "object" already exists

ERROR:  relation "prefetchable_index" already exists

ERROR:  relation "extent_index" already exists

ERROR:  relation "object_connection" already exists

ERROR:  relation "target_id_index" already exists

ERROR:  relation "collection" already exists

/usr/lib64/ruby/site_ruby/1.9.1/odba/marshal.rb:15:in `load': undefined class/module ODDB::Business::GrantDownload (ArgumentError)
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/marshal.rb:15:in `load'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:588:in `restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:313:in `block in fetch_or_restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:308:in `call'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:308:in `fetch_or_do'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:312:in `fetch_or_restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:62:in `block in bulk_restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:59:in `each'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:59:in `bulk_restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:53:in `bulk_fetch'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:255:in `fetch_collection'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:592:in `restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:313:in `block in fetch_or_restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:308:in `call'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:308:in `fetch_or_do'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:312:in `fetch_or_restore'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:299:in `block in fetch_named'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:308:in `call'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:308:in `fetch_or_do'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:291:in `fetch_named'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:346:in `indices'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/cache.rb:434:in `setup'
        from /home/masa/ywesee/ch.oddb.org/lib/oddb/persistence/odba.rb:32:in `<module:ODDB>'
        from /home/masa/ywesee/ch.oddb.org/lib/oddb/persistence/odba.rb:25:in `<top (required)>'
        from bin/migrate:8:in `require'
        from bin/migrate:8:in `<main>'

Note

  • This is the similar error to the one we got yesterday
    • There is a Marshal data in the database but there is no definition of ODDB::Business::GrantDownload class
    • That is why this error comes
  • The error comes from 'require 'oddb/persistence/odba'

Next

  • Look for 'ODDB::Business::GrantDownload' definition

grep search

masa@masa ~/ywesee $ grep -r GrantDownload ch.oddb.org
masa@masa ~/ywesee $ grep -r GrantDownload oddb
masa@masa ~/ywesee $ grep -r GrantDownload oddb.org
masa@masa ~/ywesee $ grep -r GrantDownload ch.oddb
masa@masa ~/ywesee $ grep -r GrantDownload de.oddb.org/lib
de.oddb.org/lib/oddb/business/grant_download.rb:# ODDB::Business::GrantDownload -- de.oddb.org -- 18.11.2010 -- mhatakeyama@ywesee.com
de.oddb.org/lib/oddb/business/grant_download.rb:    class GrantDownload < Model
de.oddb.org/lib/oddb/html/state/global.rb:    if email && file && user = ODDB::Business::GrantDownload.find_by_email(email)
de.oddb.org/lib/oddb/persistence/odba/business/grant_download.rb:# ODDB::Business::GrantDownload -- de.oddb.org -- 18.11.2010 -- mhatakeyama@ywesee.com
de.oddb.org/lib/oddb/persistence/odba/business/grant_download.rb:    class GrantDownload < Model
de.oddb.org/lib/oddb/util/server.rb:          unless user = ODDB::Business::GrantDownload.find_by_email(email)
de.oddb.org/lib/oddb/util/server.rb:            user = ODDB::Business::GrantDownload.new(email)
de.oddb.org/lib/oddb/util/server.rb:          if user = ODDB::Business::GrantDownload.find_by_email(email)

Note

  • 'ODDB::Business::GrantDownload' is defined in 'de.oddb.org'

Experiment

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 -I ../de.oddb.org/lib bin/migrate 
/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:300:in `block in load_driver': Unable to load driver 'pg' (underlying error: wrong constant name pg) (DBI::InterfaceError)
        from /usr/lib64/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/connection_pool.rb:60:in `block in _connect'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/connection_pool.rb:59:in `times'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/connection_pool.rb:59:in `_connect'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/connection_pool.rb:56:in `block in connect'
        from <internal:prelude>:10:in `synchronize'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/connection_pool.rb:56:in `connect'
        from /usr/lib64/ruby/site_ruby/1.9.1/odba/connection_pool.rb:19:in `initialize'
        from /home/masa/ywesee/de.oddb.org/lib/oddb/persistence/odba.rb:29:in `new'
        from /home/masa/ywesee/de.oddb.org/lib/oddb/persistence/odba.rb:29:in `<module:ODDB>'
        from /home/masa/ywesee/de.oddb.org/lib/oddb/persistence/odba.rb:24:in `<top (required)>'
        from bin/migrate:6:in `require'
        from bin/migrate:6:in `<main>'

Note

  • This, linking to 'de.oddb.org' library, may be fundamentally wrong

Next

  • Read migrate

Question

  • Which database does this script try to load data from?
    • Probably it is 'oddb.org' (for 'oddb.org' project)

Experiment

ch.oddb.org/lib/oddb/persistence/odba.rb

module ODDB
  module Persistence
    module ODBA
    end
  end
print "config.db_name="
p config.db_name
  ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:Pg:#{@config.db_name}",
                                              @config.db_user, @config.db_auth)
p "A"
  ODBA.cache.setup
p "B"
end

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate 
config.db_name="oddb"
"A"

Note

  • The database from which 'migrate' script tries to load data is 'oddb'
    • 'oddb' is the table for 'de.oddb.org'
    • This configuration comes from 'ch.oddb.org/lib/oddb/config.rb' file
    • This means, at least as a default, 'migrate' is a script for 'de.oddb.org'
  • The error comes from 'ODBA.cache.setup'

Experiment (delete data in 'oddb' table)

masa@masa ~/ywesee/ch.oddb.org $ sudo -u postgres dropdb oddb
masa@masa ~/ywesee/ch.oddb.org $ sudo -u postgres createdb -E UTF8 -T template0 oddb

Run ch.oddb.org/bin/migrate

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "object_pkey" for table "object"
NOTICE:  CREATE TABLE / UNIQUE will create implicit index "object_name_key" for table "object"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "object_connection_pkey" for table "object_connection"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "collection_pkey" for table "collection"
bin/migrate tried to import data from ch.oddb.org at druby://localhost:10000 but could not connect.
Exiting.

Note

  • It runs but it stops because of some daemon is not running (probably oddb.org/bin/oddbd)
  • (probably) this script move (migrate) data from 'oddb.org' (ch.oddb.org) to 'oddb' (de.oddb.org)

Experiment

Run oddb.org/bin/oddbd (server_url: druby://localhost:10000 (default value))

Run ch.oddb.org/bin/migrate

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
ERROR:  relation "object" already exists

ERROR:  relation "prefetchable_index" already exists

ERROR:  relation "extent_index" already exists

ERROR:  relation "object_connection" already exists

ERROR:  relation "target_id_index" already exists

ERROR:  relation "collection" already exists

ERROR:  relation "target_id_oddb_business_company_name" already exists

ERROR:  relation "target_id_oddb_business_invoice_yus_name" already exists

ERROR:  relation "target_id_oddb_business_invoice_id" already exists

ERROR:  relation "target_id_oddb_drugs_atc_code" already exists

ERROR:  relation "target_id_oddb_drugs_atc_level_and_code" already exists

ERROR:  relation "target_id_oddb_drugs_atc_name" already exists

ERROR:  relation "target_id_oddb_drugs_galenicform_description" already exists

ERROR:  relation "target_id_oddb_drugs_galenicform_code" already exists

ERROR:  relation "target_id_oddb_drugs_galenicgroup_name" already exists

ERROR:  relation "target_id_oddb_drugs_substance_name" already exists

ERROR:  relation "target_id_oddb_drugs_substance_code" already exists

ERROR:  relation "target_id_oddb_drugs_package_code" already exists

ERROR:  relation "target_id_oddb_drugs_package_atc" already exists

ERROR:  relation "target_id_oddb_drugs_package_name" already exists

ERROR:  relation "target_id_oddb_drugs_package_substance" already exists

ERROR:  relation "target_id_oddb_drugs_package_company" already exists

ERROR:  relation "target_id_oddb_drugs_package_product" already exists

ERROR:  relation "target_id_oddb_drugs_product_name" already exists

ERROR:  relation "target_id_oddb_drugs_sequence_code" already exists

ERROR:  relation "target_id_oddb_drugs_sequence_fachinfo_indications_de" already exists

ERROR:  relation "target_id_oddb_drugs_sequence_product" already exists

ERROR:  relation "target_id_oddb_drugs_substancegroup_name" already exists

ERROR:  relation "target_id_oddb_drugs_unit_name" already exists

ERROR:  relation "target_id_oddb_regulatory_authority_name" already exists

ERROR:  relation "target_id_oddb_regulatory_registration_code" already exists

ERROR:  relation "target_id_oddb_text_document_source" already exists

(druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/marshal.rb:15:in `load': undefined class/module ODDB::RootUser (ArgumentError)
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/marshal.rb:15:in `load'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:246:in `fetch_collection'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:244:in `each'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:244:in `fetch_collection'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:620:in `restore'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:336:in `fetch_or_restore'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:330:in `call'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:330:in `fetch_or_do'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:335:in `fetch_or_restore'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:628:in `restore_object'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:589:in `load_object'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:232:in `fetch'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:330:in `call'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:330:in `fetch_or_do'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/cache.rb:231:in `fetch'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/stub.rb:51:in `odba_instance'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/stub.rb:141:in `method_missing'
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/stub.rb:160:in `[]'
        from (druby://localhost:10000) /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:151:in `admin'
        from bin/migrate:71:in `<main>'

Note

  • A similar load error again
  • This time, the error comes from druby://localhost:10000 (oddb.org)

Search RootUser definition

masa@masa ~/ywesee/ch.oddb.org $ grep -r RootUser ../oddb.org/src
../oddb.org/src/state/admin/login.rb:      ['org.oddb.RootUser', State::Admin::Root],
../oddb.org/src/util/validator.rb:        'login|org.oddb.RootUser', 
../oddb.org/src/view/drugs/atcchooser.rb:               if(@session.user.allowed?('login', 'org.oddb.RootUser'))
../oddb.org/src/view/drugs/resultlist.rb:class RootUser < View::Drugs::User; end

Note

  • There is a RootUser definition in 'oddb.org'
  • But this is not ODDB::RootUser but ODDB::View::Drugs::RootUser

Experiment

ch.oddb.org/bin/migrate

server = DRb::DRbObject.new(nil, url)
begin
p "A"
  server.admin "self.class"
p "B"
rescue DRb::DRbConnError
  puts <<-EOS
#$0 tried to import data from ch.oddb.org at #{url} but could not connect.
Exiting.
  EOS
  exit -1
end
p "C"
exit

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
"A"
(druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/marshal.rb:15:in `load': undefined class/module ODDB::RootUser (ArgumentError)
        from (druby://localhost:10000) /usr/lib64/ruby/site_ruby/1.8/odba/marshal.rb:15:in `load'
...

Note

  • The error comes from 'server.admin "self.class"'

Hypothesis

  • 'server.admin "self.class"' is just a confirmation of the connecting to the server

Experiment

ch.oddb.org/bin/migrate

begin
  #server.admin "self.class"
  server.company_count
rescue DRb::DRbConnError

Run oddb.org/bin/oddbd

Run ch.oddb.org/bin/migrate

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
...
(druby://localhost:10000) /usr/lib64/ruby/1.8/delegate.rb:158:in `method_missing': undefined method `remote_each_atc_class' for #<ODDB::App:0x7fd2de033938> (NoMethodError)

Note

  • I cannot find 'remote_each_atc_class' method definition

Experiment

ch.oddb.org/bin/migrate

#server.remote_each_atc_class do |atc|
server.each_atc_class do |atc|

Run oddb.org/bin/oddbd

Run ch.oddb.org/bin/migrate

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
...
(druby://localhost:39748) bin/migrate:448:in `block in <main>': undefined method `en' for #<DRb::DRbUnknown:0x00000001c9e3d8> (NoMethodError)
        from (druby://localhost:39748) /usr/lib64/ruby/1.9.1/drb/drb.rb:1558:in `call'
        from (druby://localhost:39748) /usr/lib64/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
        from (druby://localhost:39748) /usr/lib64/ruby/1.9.1/drb/drb.rb:1518:in `perform'
        from (druby://localhost:39748) /usr/lib64/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
        from (druby://localhost:39748) /usr/lib64/ruby/1.9.1/drb/drb.rb:1588:in `loop'
        from (druby://localhost:39748) /usr/lib64/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
        from (druby://localhost:10000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:10:in `block_yield'
        from (druby://localhost:10000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:17:in `perform_with_block'
        from (druby://localhost:10000) /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:588:in `each_value'
        from (druby://localhost:10000) /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:588:in `each_atc_class'
        from bin/migrate:447:in `<main>'

InterimSummary

  • There are many 'migrate_XXX' methods in ch.oddb.org/bin/migrate script
  • These 'migrate_XXX' methods are used to move and save each XXX data
  • 'server.remote_each_atc_class' and 'sever.remote_each_company' failed since there is no method definition for the remote server
    • 'remote_each_atc_class' and 'remote_each_company' methods are necessary for the remote server object
    • As a default, the remote server is 'oddb.org/src/util/oddbapp.rb' (ODDB::App)

Consideration

  • The source database may be the one of 'ch.oddb' (ODDB v3.0 for Ruby1.9)

Next

  • Focus on 'server.remote_each_atc_class'

Experiment

ch.oddb.org/bin/migrate

#server.remote_each_atc_class do |atc|
server.each_atc_class do |atc|
  unless atc.en.to_s.empty?
    migrate_atc ODDB::Remote::Drugs::Atc.new url, atc
  end
end

Run oddb.org/bin/oddbd

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 -I lib bin/migrate .
...
(druby://localhost:56200) bin/migrate:448:in `block in <main>': undefined method `en' for #<DRb::DRbUnknown:0x0000000268c930> (NoMethodError)
        from (druby://localhost:56200) /usr/lib64/ruby/1.9.1/drb/drb.rb:1558:in `call'
        from (druby://localhost:56200) /usr/lib64/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
        from (druby://localhost:56200) /usr/lib64/ruby/1.9.1/drb/drb.rb:1518:in `perform'
        from (druby://localhost:56200) /usr/lib64/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
        from (druby://localhost:56200) /usr/lib64/ruby/1.9.1/drb/drb.rb:1588:in `loop'
        from (druby://localhost:56200) /usr/lib64/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
        from (druby://localhost:10000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:10:in `block_yield'
        from (druby://localhost:10000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:17:in `perform_with_block'
        from (druby://localhost:10000) /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:588:in `each_value'
        from (druby://localhost:10000) /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:588:in `each_atc_class'
        from bin/migrate:447:in `<main>'

Note

  • Becase 'en' method (accessor) is not defined in Atc class in 'oddb.org'

Experiment

oddb.org/src/util/oddbapp.rb#each_atc_class

    def each_atc_class(&block)
@atc_classes.values.each do |x|
  p x.en.to_s
end

ch.oddb.org/bin/migrate

server.each_atc_class do |atc|
  p atc.en
=begin
  unless atc.en.to_s.empty?
    migrate_atc ODDB::Remote::Drugs::Atc.new url, atc
  end
=end
end

Run oddb.org/bin/oddbd

Run ch.oddb.org/bin/migrate

Result (on the console of ch.oddb.org/bin/migrate)

...
"Iproniazide"
"Irinotecan"
"Adrenalone"
"Iproclozide"
"Corticosteroide, Kombinationen mit anderen Mitteln"
"Thrombin"
"Methylthiouracil"
"Hamamelisrindenextrakt, Kombinationen"

Result (on the console of oddb.org/bin/oddbd)

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
...
(druby://localhost:34080) bin/migrate:449:in `block in <main>': undefined method `en' for #<DRb::DRbUnknown:0x00000001a25548> (NoMethodError)
        from (druby://localhost:34080) /usr/lib64/ruby/1.9.1/drb/drb.rb:1558:in `call'
        from (druby://localhost:34080) /usr/lib64/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
        from (druby://localhost:34080) /usr/lib64/ruby/1.9.1/drb/drb.rb:1518:in `perform'
        from (druby://localhost:34080) /usr/lib64/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
        from (druby://localhost:34080) /usr/lib64/ruby/1.9.1/drb/drb.rb:1588:in `loop'
        from (druby://localhost:34080) /usr/lib64/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
        from (druby://localhost:10000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:10:in `block_yield'
        from (druby://localhost:10000) /usr/lib64/ruby/1.8/drb/invokemethod.rb:17:in `perform_with_block'
        from (druby://localhost:10000) /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:592:in `each_value'
        from (druby://localhost:10000) /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:592:in `each_atc_class'
        from bin/migrate:448:in `<main>'

Note

  • The 'en' method works correctly on the server side

Question

  • Why does NOT the Atc object work on the client side?

Reference

Experiment

oddb.org/src/util/oddbapp.rb

    def atc_values
      @atc_classes.values[0]
    end

ch.oddb.org/bin/migrate

atc_values=server.atc_values
p atc_values.class

Run oddb.org/bin/oddbd

Run ch.oddb.org/bin/migrate

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
DRb::DRbUnknown

Note

  • The 'migrate' script side does not know the class of the object
  • That is why 'atc' object cannot call 'en' method on the 'migrate' side

Experiment (call by reference through drb)

oddb.org/src/util/oddbapp.rb

 def atc_values
   @atc_classes.values[0].extend(DRb::DRbUndumped)
 end

ch.oddb.org/bin/migrate

 atc_values=server.atc_values
 p atc_values.class
 p atc_values.en

Run oddb.org/bin/oddbd

Run ch.oddb.org/bin/migrate

Result

masa@masa ~/ywesee/ch.oddb.org $ ruby1.9 bin/migrate .
DRb::DRbObject
"Propylthiouracil"

Note

  • Good!
  • It is also fine, @atc_classes.extend(DRb::DRbUndumped)values[0]
  • But I have to be careful since it is 'call by reference' which means it has a possibility to delete some data in the client side

Experiment

oddb.org/src/util/oddbapp.rb#each_atc_class

    def each_atc_class(&block)
        #@atc_classes.each_value(&block)
        @atc_classes.extend(DRb::DRbUndumped).each_value(&block)
    end

ch.oddb.org/bin/migrate

#server.remote_each_atc_class do |atc|
server.each_atc_class do |atc|
  unless atc.en.to_s.empty?
    migrate_atc ODDB::Remote::Drugs::Atc.new url, atc
  end
end
exit

Result


TypeError: can't convert String into Integer when updating index 'oddb_drugs_atc_level_and_code' with a ODDB::Drugs::Atc
["/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:301:in `[]'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:301:in `block in current_ids'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:299:in `collect'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:299:in `current_ids'"]
[...]

TypeError: can't convert String into Integer when updating index 'oddb_drugs_atc_level_and_code' with a ODDB::Drugs::Atc
["/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:301:in `[]'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:301:in `block in current_ids'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:299:in `collect'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:299:in `current_ids'"]
[...]

TypeError: can't convert String into Integer when updating index 'oddb_drugs_atc_level_and_code' with a ODDB::Drugs::Atc
["/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:301:in `[]'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:301:in `block in current_ids'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:299:in `collect'", "/usr/lib64/ruby/site_ruby/1.9.1/odba/index.rb:299:in `current_ids'"]
[...]

...

Notes

  • The remote method problem is resolved
  • But I should check more
  • These error does not come in the second time 'migrate' runs
    • I guess it does not import because there is already data in the database

Memo

  • dRuby (drb) automatically switch 'call by reference' and 'call by value' depending on the object that can be converted into Marshal data
    • in other words, if it is possible to do Marshal.dump or not
  • If it is possible to Marshal.dump the object,the object is 'called by value'
  • If the object is called by value and also if there is no definition of the class at the client side, the object becomes DRb::DRbUnknown class,
  • then it cannot call the methods of the object (it is possible to pass the object through to another server)
  • In such a case, it is possible to call the methods at the client side by making the object forcibly Un-Marshaled (impossible to convert it into Marshal data), to include or extend DRb::DRbUndumped in the object or class
  • But be careful to change the object at the client side in the case of 'call by reference', because the change will be reflected to the server side object.
view · edit · sidebar · attach · print · history
Page last modified on January 26, 2011, at 05:06 PM