summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/schema/schema_drop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/wiredtiger/src/schema/schema_drop.c')
-rw-r--r--src/third_party/wiredtiger/src/schema/schema_drop.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/third_party/wiredtiger/src/schema/schema_drop.c b/src/third_party/wiredtiger/src/schema/schema_drop.c
index ec12ec3752f..d058dae69e1 100644
--- a/src/third_party/wiredtiger/src/schema/schema_drop.c
+++ b/src/third_party/wiredtiger/src/schema/schema_drop.c
@@ -25,8 +25,7 @@ __drop_file(
remove_files = cval.val != 0;
filename = uri;
- if (!WT_PREFIX_SKIP(filename, "file:"))
- return (__wt_unexpected_object_type(session, uri, "file:"));
+ WT_PREFIX_SKIP_REQUIRED(session, filename, "file:");
WT_RET(__wt_schema_backup_check(session, filename));
/* Close all btree handles associated with this file. */
@@ -60,13 +59,14 @@ __drop_colgroup(
WT_DECL_RET;
WT_TABLE *table;
- WT_ASSERT(session, F_ISSET(session, WT_SESSION_LOCKED_TABLE));
+ WT_ASSERT(session, F_ISSET(session, WT_SESSION_LOCKED_TABLE_WRITE));
/* If we can get the colgroup, detach it from the table. */
if ((ret = __wt_schema_get_colgroup(
session, uri, force, &table, &colgroup)) == 0) {
- table->cg_complete = false;
WT_TRET(__wt_schema_drop(session, colgroup->source, cfg));
+ if (ret == 0)
+ table->cg_complete = false;
}
WT_TRET(__wt_metadata_remove(session, uri));
@@ -83,14 +83,10 @@ __drop_index(
{
WT_INDEX *idx;
WT_DECL_RET;
- WT_TABLE *table;
/* If we can get the index, detach it from the table. */
- if ((ret = __wt_schema_get_index(
- session, uri, force, &table, &idx)) == 0) {
- table->idx_complete = false;
+ if ((ret = __wt_schema_get_index(session, uri, true, force, &idx)) == 0)
WT_TRET(__wt_schema_drop(session, idx->source, cfg));
- }
WT_TRET(__wt_metadata_remove(session, uri));
return (ret);
@@ -101,7 +97,8 @@ __drop_index(
* WT_SESSION::drop for a table.
*/
static int
-__drop_table(WT_SESSION_IMPL *session, const char *uri, const char *cfg[])
+__drop_table(
+ WT_SESSION_IMPL *session, const char *uri, const char *cfg[])
{
WT_COLGROUP *colgroup;
WT_DECL_RET;
@@ -109,13 +106,26 @@ __drop_table(WT_SESSION_IMPL *session, const char *uri, const char *cfg[])
WT_TABLE *table;
const char *name;
u_int i;
+ bool tracked;
+
+ WT_ASSERT(session, F_ISSET(session, WT_SESSION_LOCKED_TABLE_WRITE));
name = uri;
- (void)WT_PREFIX_SKIP(name, "table:");
+ WT_PREFIX_SKIP_REQUIRED(session, name, "table:");
table = NULL;
- WT_ERR(__wt_schema_get_table(
- session, name, strlen(name), true, &table));
+ tracked = false;
+
+ /*
+ * Open the table so we can drop its column groups and indexes.
+ *
+ * Ideally we would keep the table locked exclusive across the drop,
+ * but for now we rely on the global table lock to prevent the table
+ * being reopened while it is being dropped. 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_ERR(__wt_schema_get_table_uri(session, uri, true, 0, &table));
/* Drop the column groups. */
for (i = 0; i < WT_COLGROUPS(table); i++) {
@@ -144,14 +154,23 @@ __drop_table(WT_SESSION_IMPL *session, const char *uri, const char *cfg[])
WT_ERR(__wt_metadata_remove(session, idx->name));
}
- 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;
+ }
/* Remove the metadata entry (ignore missing items). */
WT_ERR(__wt_metadata_remove(session, uri));
-err: if (table != NULL)
- __wt_schema_release_table(session, table);
+err: if (table != NULL && !tracked)
+ WT_TRET(__wt_schema_release_table(session, table));
return (ret);
}
@@ -200,9 +219,6 @@ __wt_schema_drop(WT_SESSION_IMPL *session, const char *uri, const char *cfg[])
if (ret == WT_NOTFOUND || ret == ENOENT)
ret = force ? 0 : ENOENT;
- /* 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));
return (ret);