fix: Handle potential for data race in catalog table insertion by re-fetching if detected

pull/24376/head
Carol (Nichols || Goulding) 2023-05-22 17:16:57 -04:00
parent 90cb4b6ed9
commit 46f7e3e48a
No known key found for this signature in database
GPG Key ID: E907EE5A736F87D4
1 changed files with 19 additions and 2 deletions

View File

@ -215,16 +215,33 @@ where
{
Some(table) => table,
None => {
repos
// There is a possibility of a race condition here, if another request has also
// created this table after the `get_by_namespace_and_name` call but before
// this `create` call. In that (hopefully) rare case, do an additional fetch
// from the catalog for the record that should now exist.
let create_result = repos
.tables()
.create(
table_name,
TablePartitionTemplateOverride::from(namespace_partition_template),
namespace_id,
)
.await;
if let Err(Error::TableNameExists { .. }) = create_result {
repos
.tables()
.get_by_namespace_and_name(namespace_id, table_name)
.await?
.expect(
"Table creation failed because the table exists, \
so looking up the table should succeed",
)
} else {
create_result?
}
}
};
let mut table = TableSchema::new_empty_from(&table);
// Always add a time column to all new tables.