summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2012-04-10 13:29:19 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2012-04-10 13:29:19 +1000
commit35bfd2fd336cda5298020e97ec00ef9992ce40a1 (patch)
treeec2e6ee70cbfac10577a5669d6e2aad7dad1c14a
parent30fa005a8fd3ec8afcd4d37c45f89916e4e52504 (diff)
downloadmongo-35bfd2fd336cda5298020e97ec00ef9992ce40a1.tar.gz
Create the schema table as part of creating the environment so that application threads don't race trying to create it later.
This is not a complete solution: threads may still race creating other files or schema objects, but this fixes the most common "thundering herd" case. refs #191
-rw-r--r--src/conn/conn_api.c14
-rw-r--r--src/include/extern.h1
-rw-r--r--src/schema/schema_table.c8
3 files changed, 19 insertions, 4 deletions
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index ad3ef8d7e84..e6e9e5eaa31 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -374,6 +374,7 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler,
WT_CONFIG_ITEM cval, skey, sval;
WT_CONNECTION_IMPL *conn;
WT_ITEM *cbuf, expath, exconfig;
+ WT_SESSION *wt_session;
WT_SESSION_IMPL *session;
int ret;
const char *cfg[] =
@@ -512,6 +513,19 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler,
conn = NULL;
WT_ERR(ret);
}
+
+ /*
+ * If this is a new database, create the schema file. This avoids
+ * application threads racing to create it later. We need a real
+ * session handle for this: open one.
+ */
+ if (conn->is_new) {
+ WT_ERR(conn->iface.open_session(&conn->iface,
+ NULL, NULL, &wt_session));
+ WT_TRET(__wt_open_schema_table((WT_SESSION_IMPL *)wt_session));
+ WT_TRET(wt_session->close(wt_session, NULL));
+ WT_ERR(ret);
+ }
STATIC_ASSERT(offsetof(WT_CONNECTION_IMPL, iface) == 0);
*wt_connp = &conn->iface;
diff --git a/src/include/extern.h b/src/include/extern.h
index 652618bcd87..c4dc303a0b2 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -711,6 +711,7 @@ extern int __wt_schema_rename(WT_SESSION_IMPL *session,
const char *uri,
const char *newuri,
const char *cfg[]);
+extern int __wt_open_schema_table(WT_SESSION_IMPL *session);
extern int __wt_schema_table_cursor( WT_SESSION_IMPL *session,
const char *config,
WT_CURSOR **cursorp);
diff --git a/src/schema/schema_table.c b/src/schema/schema_table.c
index d6404e3c9fc..41ba9055f68 100644
--- a/src/schema/schema_table.c
+++ b/src/schema/schema_table.c
@@ -10,11 +10,11 @@
static const char *schematab_config = "key_format=S,value_format=S";
/*
- * __open_schema_table --
+ * __wt_open_schema_table --
* Opens the schema table, sets session->schematab.
*/
-static inline int
-__open_schema_table(WT_SESSION_IMPL *session)
+int
+__wt_open_schema_table(WT_SESSION_IMPL *session)
{
const char *cfg[] = API_CONF_DEFAULTS(file, meta, schematab_config);
const char *schemaconf;
@@ -54,7 +54,7 @@ __wt_schema_table_cursor(
{
const char *cfg[] = API_CONF_DEFAULTS(session, open_cursor, config);
- WT_RET(__open_schema_table(session));
+ WT_RET(__wt_open_schema_table(session));
session->btree = session->schematab;
return (__wt_curfile_create(session, NULL, cfg, cursorp));
}