Example #1
0
/*
 * __wt_schema_get_table_uri --
 *	Get the table handle for the named table.
 */
int
__wt_schema_get_table_uri(WT_SESSION_IMPL *session,
    const char *uri, bool ok_incomplete, uint32_t flags,
    WT_TABLE **tablep)
{
	WT_DATA_HANDLE *saved_dhandle;
	WT_DECL_RET;
	WT_TABLE *table;

	saved_dhandle = session->dhandle;

	*tablep = NULL;

	WT_ERR(__wt_session_get_dhandle(session, uri, NULL, NULL, flags));
	table = (WT_TABLE *)session->dhandle;
	if (!ok_incomplete && !table->cg_complete) {
		ret = EINVAL;
		WT_TRET(__wt_session_release_dhandle(session));
		WT_ERR_MSG(session, ret, "'%s' cannot be used "
		    "until all column groups are created",
		    table->iface.name);
	}
	*tablep = table;

err:	session->dhandle = saved_dhandle;
	return (ret);
}
Example #2
0
/*
 * __meta_btree_apply --
 *	Apply a function to all files listed in the metadata, apart from the
 *	metadata file.
 */
static inline int
__meta_btree_apply(WT_SESSION_IMPL *session, WT_CURSOR *cursor,
    int (*file_func)(WT_SESSION_IMPL *, const char *[]),
    int (*name_func)(WT_SESSION_IMPL *, const char *, bool *),
    const char *cfg[])
{
	WT_DECL_RET;
	int t_ret;
	const char *uri;
	bool skip;

	/*
	 * Accumulate errors but continue through to the end of the metadata.
	 */
	while ((t_ret = cursor->next(cursor)) == 0) {
		if ((t_ret = cursor->get_key(cursor, &uri)) != 0 ||
		    strcmp(uri, WT_METAFILE_URI) == 0) {
			WT_TRET(t_ret);
			continue;
		}

		skip = false;
		if (name_func != NULL &&
		    (t_ret = name_func(session, uri, &skip)) != 0) {
			WT_TRET(t_ret);
			continue;
		}

		if (file_func == NULL || skip || !WT_PREFIX_MATCH(uri, "file:"))
			continue;

		/*
		 * We need to pull the handle into the session handle cache
		 * and make sure it's referenced to stop other internal code
		 * dropping the handle (e.g in LSM when cleaning up obsolete
		 * chunks).  Holding the schema lock isn't enough.
		 *
		 * Handles that are busy are skipped without the whole
		 * operation failing.  This deals among other cases with
		 * checkpoint encountering handles that are locked (e.g., for
		 * bulk loads or verify operations).
		 */
		if ((t_ret = __wt_session_get_dhandle(
		    session, uri, NULL, NULL, 0)) != 0) {
			WT_TRET_BUSY_OK(t_ret);
			continue;
		}

		WT_SAVE_DHANDLE(session, WT_TRET(file_func(session, cfg)));
		WT_TRET(__wt_session_release_dhandle(session));
	}
	WT_TRET_NOTFOUND_OK(t_ret);

	return (ret);
}
Example #3
0
/*
 * __compact_handle_append --
 *	Gather a file handle to be compacted.
 *	Called via the schema_worker function.
 */
static int
__compact_handle_append(WT_SESSION_IMPL *session, const char *cfg[])
{
	WT_DECL_RET;

	WT_UNUSED(cfg);

	WT_RET(__wt_session_get_dhandle(
	    session, session->dhandle->name, NULL, NULL, 0));

	/* Set compact active on the handle. */
	if ((ret = __compact_start(session)) != 0) {
		WT_TRET(__wt_session_release_dhandle(session));
		return (ret);
	}

	/* Make sure there is space for the next entry. */
	WT_RET(__wt_realloc_def(session, &session->op_handle_allocated,
	    session->op_handle_next + 1, &session->op_handle));

	session->op_handle[session->op_handle_next++] = session->dhandle;
	return (0);
}