Skip to content

Commit

Permalink
Fix duplicate table create
Browse files Browse the repository at this point in the history
An exception could be raised, preventing the duplicate table logic from
running.
  • Loading branch information
caspiano committed Mar 21, 2022
1 parent 78dd906 commit 151b051
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/no_brainer/query_runner/table_on_demand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ def auto_create_table(env, db_name, table_name)
env[:last_auto_create_table] = [db_name, table_name]

create_options = model.table_create_options

NoBrainer.run(:db => db_name) do |r|
r.table_create(table_name, create_options.reject { |k,_| k.in? [:name, :write_acks] })
begin
NoBrainer.run(:db => db_name) do |r|
r.table_create(table_name, create_options.reject { |k,_| k.in? [:name, :write_acks] })
end
rescue RuntimeError => e
# We might have raced with another table create
raise unless e.message =~ /Table `#{db_name}\.#{table_name}` already exists/
end

# Prevent duplicate table errors on a cluster.
Expand All @@ -49,8 +53,5 @@ def auto_create_table(env, db_name, table_name)
r.table(table_name).config().update(:write_acks => create_options[:write_acks])
end
end
rescue RuntimeError => e
# We might have raced with another table create
raise unless e.message =~ /Table `#{db_name}\.#{table_name}` already exists/
end
end

0 comments on commit 151b051

Please sign in to comment.