summaryrefslogtreecommitdiff
path: root/src/lsm/lsm_dsrc.c
blob: f04848b3016183cc4c46d0583555434980e0faa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*-
 * Copyright (c) 2008-2012 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "wt_internal.h"

/*
 * __lsm_create --
 *	Implementation of the create operation for LSM trees.
 */
static int
__lsm_create(WT_DATA_SOURCE *dsrc, WT_SESSION *wt_session,
    const char *uri, int exclusive, const char *config)
{
	WT_SESSION_IMPL *session;

	WT_UNUSED(dsrc);

	session = (WT_SESSION_IMPL *)wt_session;
	return (__wt_lsm_tree_create(session, uri, exclusive, config));
}

/*
 * __lsm_drop --
 *	Implementation of the drop operation for LSM trees.
 */
static int
__lsm_drop(WT_DATA_SOURCE *dsrc, WT_SESSION *wt_session,
    const char *uri, const char *cfg[])
{
	WT_SESSION_IMPL *session;

	WT_UNUSED(dsrc);
	session = (WT_SESSION_IMPL *)wt_session;

	return (__wt_lsm_tree_drop(session, uri, cfg));
}

/*
 * __lsm_open_cursor --
 *	Implementation of the open_cursor operation for LSM trees.
 */
static int
__lsm_open_cursor(WT_DATA_SOURCE *dsrc, WT_SESSION *wt_session,
    const char *obj, const char *cfg[], WT_CURSOR **new_cursor)
{
	WT_SESSION_IMPL *session;

	session = (WT_SESSION_IMPL *)wt_session;
	WT_UNUSED(dsrc);

	return (__wt_clsm_open(session, obj, cfg, new_cursor));
}

/*
 * __lsm_rename --
 *	Implementation of the rename operation for LSM trees.
 */
static int
__lsm_rename(WT_DATA_SOURCE *dsrc, WT_SESSION *wt_session,
    const char *oldname, const char *newname, const char *cfg[])
{
	WT_SESSION_IMPL *session;

	WT_UNUSED(dsrc);
	session = (WT_SESSION_IMPL *)wt_session;

	if (!WT_PREFIX_MATCH(newname, "lsm:"))
		WT_RET_MSG(session, EINVAL,
		    "rename target type must match URI: %s to %s",
		    oldname, newname);

	return (__wt_lsm_tree_rename(session, oldname, newname, cfg));
}

/*
 * __lsm_truncate --
 *	Implementation of the truncate operation for LSM trees.
 */
static int
__lsm_truncate(WT_DATA_SOURCE *dsrc, WT_SESSION *session,
    const char *name, const char *cfg[])
{
	WT_UNUSED(dsrc);
	WT_UNUSED(session);
	WT_UNUSED(name);
	WT_UNUSED(cfg);

	return (ENOTSUP);
}

/*
 * __wt_lsm_init --
 *	Initialize LSM structures during wiredtiger_open.
 */
int
__wt_lsm_init(WT_CONNECTION *wt_conn, const char *config)
{
	WT_CONNECTION_IMPL *conn;
	static WT_LSM_DATA_SOURCE *lsm_dsrc;
	WT_SESSION_IMPL *session;
	static WT_DATA_SOURCE iface = {
		__lsm_create,
		__lsm_drop,
		__lsm_open_cursor,
		__lsm_rename,
		__lsm_truncate
	};

	conn = (WT_CONNECTION_IMPL *)wt_conn;
	session = conn->default_session;

	WT_RET(__wt_calloc_def(session, 1, &lsm_dsrc));

	lsm_dsrc->iface = iface;
	WT_RET(
	    __wt_rwlock_alloc(session, "lsm data source", &lsm_dsrc->rwlock));
	TAILQ_INIT(&lsm_dsrc->trees);

	return (wt_conn->add_data_source(wt_conn,
	    "lsm:", &lsm_dsrc->iface, config));
}

/*
 * __wt_lsm_cleanup --
 *	Clean up LSM structures during connection close.
 */
int
__wt_lsm_cleanup(WT_CONNECTION *wt_conn)
{
	WT_CONNECTION_IMPL *conn;
	WT_SESSION_IMPL *session;

	conn = (WT_CONNECTION_IMPL *)wt_conn;
	session = conn->default_session;

	return (__wt_lsm_tree_close_all(session));
}