summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/schema/schema_rename.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/schema/schema_rename.c')
-rw-r--r--src/third_party/wiredtiger/src/schema/schema_rename.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/src/third_party/wiredtiger/src/schema/schema_rename.c b/src/third_party/wiredtiger/src/schema/schema_rename.c
index 1868d907d00..06133814291 100644
--- a/src/third_party/wiredtiger/src/schema/schema_rename.c
+++ b/src/third_party/wiredtiger/src/schema/schema_rename.c
@@ -24,11 +24,9 @@ __rename_file(
newvalue = oldvalue = NULL;
filename = uri;
- if (!WT_PREFIX_SKIP(filename, "file:"))
- return (__wt_unexpected_object_type(session, uri, "file:"));
+ WT_PREFIX_SKIP_REQUIRED(session, filename, "file:");
newfile = newuri;
- if (!WT_PREFIX_SKIP(newfile, "file:"))
- return (__wt_unexpected_object_type(session, newuri, "file:"));
+ WT_PREFIX_SKIP_REQUIRED(session, newfile, "file:");
WT_RET(__wt_schema_backup_check(session, filename));
WT_RET(__wt_schema_backup_check(session, newfile));
@@ -94,11 +92,11 @@ __rename_tree(WT_SESSION_IMPL *session,
const char *newname, *olduri, *suffix;
char *value;
- olduri = table->name;
+ olduri = table->iface.name;
value = NULL;
newname = newuri;
- (void)WT_PREFIX_SKIP(newname, "table:");
+ WT_PREFIX_SKIP_REQUIRED(session, newname, "table:");
/*
* Create the new data source URI and update the schema value.
@@ -134,7 +132,7 @@ __rename_tree(WT_SESSION_IMPL *session,
* and substitute the new name temporarily.
*/
WT_ERR(__wt_scr_alloc(session, 0, &ns));
- table->name = newuri;
+ table->iface.name = newuri;
if (is_colgroup)
WT_ERR(__wt_schema_colgroup_source(
session, table, suffix, value, ns));
@@ -174,7 +172,7 @@ err: __wt_scr_free(session, &nn);
__wt_scr_free(session, &nv);
__wt_scr_free(session, &os);
__wt_free(session, value);
- table->name = olduri;
+ table->iface.name = olduri;
return (ret);
}
@@ -208,12 +206,23 @@ __rename_table(WT_SESSION_IMPL *session,
WT_TABLE *table;
u_int i;
const char *oldname;
+ bool tracked;
oldname = uri;
(void)WT_PREFIX_SKIP(oldname, "table:");
+ tracked = false;
+ /*
+ * Open the table so we can rename its column groups and indexes.
+ *
+ * Ideally we would keep the table locked exclusive across the rename,
+ * but for now we rely on the global table lock to prevent the table
+ * being reopened while it is being renamed. One issue is that the
+ * WT_WITHOUT_LOCKS macro can drop and reacquire the global table lock,
+ * avoiding deadlocks while waiting for LSM operation to quiesce.
+ */
WT_RET(__wt_schema_get_table(
- session, oldname, strlen(oldname), false, &table));
+ session, oldname, strlen(oldname), false, 0, &table));
/* Rename the column groups. */
for (i = 0; i < WT_COLGROUPS(table); i++)
@@ -226,14 +235,23 @@ __rename_table(WT_SESSION_IMPL *session,
WT_ERR(__rename_tree(session, table, newuri,
table->indices[i]->name, cfg));
- WT_ERR(__wt_schema_remove_table(session, table));
- table = NULL;
+ /* Make sure the table data handle is closed. */
+ WT_TRET(__wt_schema_release_table(session, table));
+ WT_ERR(__wt_schema_get_table_uri(
+ session, uri, true, WT_DHANDLE_EXCLUSIVE, &table));
+ F_SET(&table->iface, WT_DHANDLE_DISCARD);
+ if (WT_META_TRACKING(session)) {
+ WT_WITH_DHANDLE(session, &table->iface,
+ ret = __wt_meta_track_handle_lock(session, false));
+ WT_ERR(ret);
+ tracked = true;
+ }
/* Rename the table. */
- WT_ERR(__metadata_rename(session, uri, newuri));
+ ret = __metadata_rename(session, uri, newuri);
-err: if (table != NULL)
- __wt_schema_release_table(session, table);
+err: if (!tracked)
+ WT_TRET(__wt_schema_release_table(session, table));
return (ret);
}
@@ -276,9 +294,6 @@ __wt_schema_rename(WT_SESSION_IMPL *session,
else
ret = __wt_bad_object_type(session, uri);
- /* Bump the schema generation so that stale data is ignored. */
- (void)__wt_gen_next(session, WT_GEN_SCHEMA);
-
WT_TRET(__wt_meta_track_off(session, true, ret != 0));
/* If we didn't find a metadata entry, map that error to ENOENT. */