/*修改表名*/ static int __rename_table(WT_SESSION_IMPL *session, const char *uri, const char *newuri, const char *cfg[]) { WT_DECL_RET; WT_TABLE *table; u_int i; const char *oldname; oldname = uri; (void)WT_PREFIX_SKIP(oldname, "table:"); WT_RET(__wt_schema_get_table(session, oldname, strlen(oldname), 0, &table)); /* Rename the column groups. */ for (i = 0; i < WT_COLGROUPS(table); i++) WT_ERR(__rename_tree(session, table, newuri, table->cgroups[i]->name, cfg)); /* Rename the indices. */ WT_ERR(__wt_schema_open_indices(session, table)); for (i = 0; i < table->nindices; i++) WT_ERR(__rename_tree(session, table, newuri, table->indices[i]->name, cfg)); WT_ERR(__wt_schema_remove_table(session, table)); table = NULL; /* Rename the table. */ WT_ERR(__metadata_rename(session, uri, newuri)); }
/* * __rename_table -- * WT_SESSION::rename for a table. */ static int __rename_table(WT_SESSION_IMPL *session, const char *uri, const char *newuri, const char *cfg[]) { WT_DECL_ITEM(buf); WT_DECL_RET; WT_TABLE *table; u_int i; const char *oldname, *value; oldname = uri; (void)WT_PREFIX_SKIP(oldname, "table:"); WT_RET(__wt_schema_get_table( session, oldname, strlen(oldname), 0, &table)); /* Rename the column groups. */ for (i = 0; i < WT_COLGROUPS(table); i++) WT_ERR(__rename_tree(session, table, newuri, table->cgroups[i]->name, cfg)); /* Rename the indices. */ WT_ERR(__wt_schema_open_indices(session, table)); for (i = 0; i < table->nindices; i++) WT_ERR(__rename_tree(session, table, newuri, table->indices[i]->name, cfg)); __wt_schema_remove_table(session, table); table = NULL; /* Rename the table. */ WT_ERR(__wt_scr_alloc(session, 0, &buf)); WT_ERR(__wt_metadata_read(session, uri, &value)); WT_ERR(__wt_metadata_remove(session, uri)); WT_ERR(__wt_metadata_insert(session, newuri, value)); err: __wt_scr_free(&buf); if (table != NULL) __wt_schema_release_table(session, table); return (ret); }
/* * __rename_table -- * WT_SESSION::rename for a table. */ static int __rename_table( WT_SESSION_IMPL *session, const char *oldname, const char *newname) { WT_DECL_RET; WT_ITEM *buf; WT_TABLE *table; int i; const char *value; buf = NULL; WT_RET( __wt_schema_get_table(session, oldname, strlen(oldname), &table)); /* Rename the column groups. */ for (i = 0; i < WT_COLGROUPS(table); i++) WT_RET(__rename_tree(session, table->cg_name[i], newname)); /* Rename the indices. */ WT_RET(__wt_schema_open_index(session, table, NULL, 0)); for (i = 0; i < table->nindices; i++) WT_RET(__rename_tree(session, table->idx_name[i], newname)); WT_RET(__wt_schema_remove_table(session, table)); /* Rename the table. */ WT_ERR(__wt_scr_alloc(session, 0, &buf)); WT_ERR(__wt_buf_fmt(session, buf, "table:%s", oldname)); WT_ERR(__wt_metadata_read(session, buf->data, &value)); WT_ERR(__wt_metadata_remove(session, buf->data)); WT_ERR(__wt_buf_fmt(session, buf, "table:%s", newname)); WT_ERR(__wt_metadata_insert(session, buf->data, value)); err: __wt_scr_free(&buf); return (ret); }