Error upgrading from 4.12 to 5.2

Hi. I am trying to upgrade Opennebula from 4.12 to 5.2. Error during “onedb upgrade”

The scheduler (and oned) has been update to enforce access    
rights on system datastores. This new version also checks that
the user can access the System DS.
This *may require* to update system DS rights of your cloud

Do you want to proceed ? [y/N]y

Mysql::Error: Duplicate entry '0' for key 'PRIMARY'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:178:in `query'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:178:in `block in _execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/logging.rb:44:in `log_connection_yield'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:178:in `_execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/utils/mysql_mysql2.rb:36:in `block in execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/connecting.rb:251:in `block in synchronize'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/connection_pool/threaded.rb:103:in `hold'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/connecting.rb:251:in `synchronize'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/utils/mysql_mysql2.rb:36:in `execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:163:in `execute_insert'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/dataset/actions.rb:986:in `execute_insert'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/dataset/actions.rb:338:in `insert'
/usr/lib/one/ruby/onedb/local/4.11.80_to_4.13.80.rb:106:in `block (2 levels) in up'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/dataset/actions.rb:141:in `block in each'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:316:in `block (2 levels) in fetch_rows'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:373:in `yield_rows'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:316:in `block in fetch_rows'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:180:in `_execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/utils/mysql_mysql2.rb:36:in `block in execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/connecting.rb:251:in `block in synchronize'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/connection_pool/threaded.rb:103:in `hold'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/connecting.rb:251:in `synchronize'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/utils/mysql_mysql2.rb:36:in `execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/dataset/actions.rb:970:in `execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:357:in `execute'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/adapters/mysql.rb:300:in `fetch_rows'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/dataset/actions.rb:141:in `each'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/dataset.rb:48:in `fetch'
/usr/lib/one/ruby/onedb/local/4.11.80_to_4.13.80.rb:101:in `block in up'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/transactions.rb:163:in `_transaction'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/transactions.rb:138:in `block in transaction'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/connecting.rb:251:in `block in synchronize'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/connection_pool/threaded.rb:107:in `hold'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/connecting.rb:251:in `synchronize'
/usr/local/share/gems/gems/sequel-4.38.0/lib/sequel/database/transactions.rb:104:in `transaction'
/usr/lib/one/ruby/onedb/local/4.11.80_to_4.13.80.rb:99:in `up'
/usr/lib/one/ruby/onedb/onedb.rb:232:in `apply_migrators'
/usr/lib/one/ruby/onedb/onedb.rb:179:in `upgrade'
/usr/bin/onedb:313:in `block (2 levels) in <main>'
/usr/lib/one/ruby/cli/command_parser.rb:449:in `call'
/usr/lib/one/ruby/cli/command_parser.rb:449:in `run'
/usr/lib/one/ruby/cli/command_parser.rb:76:in `initialize'
/usr/bin/onedb:222:in `new'
/usr/bin/onedb:222:in `<main>'


The database will be restored

onedb fsck shows no errors on current installation

There is code in 4.11.80_to_4.13.80.rb


@db.run “ALTER TABLE vm_pool RENAME TO old_vm_pool;”
@db.run “CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);”

@db.run “INSERT INTO vm_pool SELECT * FROM old_vm_pool WHERE state=6;”

log_time()

@db.transaction do
# @db.fetch("SELECT * FROM old_vm_pool WHERE state<>6") do |row|
@db.fetch(“SELECT * FROM old_vm_pool”) do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}

“INSERT INTO vm_pool SELECT * FROM old_vm_pool WHERE state=6;” populate old_vm_pool table with data and subsequent inserts cause violation of primary key. I commented out this line and migration went without errors. Same thing with “INSERT INTO history SELECT * FROM old_history WHERE etime<>0;”"

Maybe I misconfigured something

Hello,

I just hit this bug when trying to upgrade from 4.8 to 5.4.

You’re solution seems to work great !

But i would like advise and/or bug fix on this procedure from The opennebula support team.

Thanks !