Exemplo n.º 1
0
/*
 * __drop_colgroup --
 *	WT_SESSION::drop for a colgroup.
 */
static int
__drop_colgroup(
    WT_SESSION_IMPL *session, const char *uri, int force, const char *cfg[])
{
	WT_BTREE *btree;
	WT_TABLE *table;
	const char *cgname, *tablename;
	size_t tlen;
	int i, ret;

	tablename = uri;
	if (!WT_PREFIX_SKIP(tablename, "colgroup:"))
		return (EINVAL);
	cgname = strchr(tablename, ':');
	if (cgname != NULL) {
		tlen = (size_t)(cgname - tablename);
		++cgname;
	} else
		tlen = strlen(tablename);

	/*
	 * Try to get the btree handle.  Ideally, we would use an exclusive
	 * lock here to prevent access to the table while we are dropping it,
	 * but conflicts with the exclusive lock taken by
	 * __wt_session_close_any_open_btree.  If two threads race dropping
	 * the same object, it will be caught there.
	 *
	 * If we can't get a tree, try to remove it from the schema table.
	 */
	if ((ret = __wt_schema_get_btree(
	    session, uri, strlen(uri), cfg, WT_BTREE_NO_LOCK)) != 0) {
		(void)__wt_schema_table_remove(session, uri);
		return (ret);
	}
	btree = session->btree;

	/* If we can get the table, detach the colgroup from it. */
	if ((ret = __wt_schema_get_table(
	    session, tablename, tlen, &table)) == 0) {
		for (i = 0; i < WT_COLGROUPS(table); i++) {
			if (table->colgroup[i] == btree) {
				table->colgroup[i] = NULL;
				table->cg_complete = 0;
				break;
			}
		}
	} else if (ret != WT_NOTFOUND)
		WT_TRET(ret);

	WT_TRET(__drop_tree(session, btree, force));

	return (ret);
}
Exemplo n.º 2
0
static int
__find_next_col(WT_SESSION_IMPL *session, WT_TABLE *table,
    WT_CONFIG_ITEM *colname, int *cgnump, int *colnump, char *coltype)
{
	WT_BTREE *cgtree;
	WT_CONFIG conf;
	WT_CONFIG_ITEM cval, k, v;
	WT_DECL_RET;
	int cg, col, foundcg, foundcol, getnext;

	foundcg = foundcol = -1;

	getnext = 1;
	for (cgtree = NULL, cg = 0; cg < WT_COLGROUPS(table); cg++) {
		WT_RET(__wt_schema_get_btree(session,
		    table->cg_name[cg], strlen(table->cg_name[cg]),
		    NULL, 0));
		cgtree = session->btree;

		/*
		 * If there is only one column group, we just scan through all
		 * of the columns.  For tables with multiple column groups, we
		 * look at the key columns once, then go through the value
		 * columns for each group.
		 */
		if (cg == 0) {
			cval = table->colconf;
			col = 0;
		} else {
cgcols:			WT_ERR(__wt_config_getones(session,
			    cgtree->config, "columns", &cval));
			col = table->nkey_columns;
		}
		WT_ERR(__wt_config_subinit(session, &conf, &cval));
		for (; __wt_config_next(&conf, &k, &v) == 0; col++) {
			if (cg == *cgnump && col == *colnump)
				getnext = 1;
			if (getnext && k.len == colname->len &&
			    strncmp(colname->str, k.str, k.len) == 0) {
				foundcg = cg;
				foundcol = col;
				getnext = 0;
			}
			if (cg == 0 && table->ncolgroups > 0 &&
			    col == table->nkey_columns - 1)
				goto cgcols;
		}

		cgtree = NULL;
		WT_ERR(__wt_session_release_btree(session));
	}

err:	if (cgtree != NULL)
		WT_TRET(__wt_session_release_btree(session));
	WT_RET(ret);

	if (foundcg == -1)
		return (WT_NOTFOUND);

	*cgnump = foundcg;
	if (foundcol < table->nkey_columns) {
		*coltype = WT_PROJ_KEY;
		*colnump = foundcol;
	} else {
		*coltype = WT_PROJ_VALUE;
		*colnump = foundcol - table->nkey_columns;
	}
	return (0);
}