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

Fix duplicate table create #284

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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