summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cursor/cur_std.c5
-rw-r--r--src/include/txn.i2
-rw-r--r--src/session/session_api.c20
-rw-r--r--test/suite/test_checkpoint01.py10
-rw-r--r--test/suite/test_cursor06.py5
-rw-r--r--test/suite/test_cursor_random.py24
-rw-r--r--test/suite/test_join01.py9
-rw-r--r--test/suite/test_readonly02.py4
-rw-r--r--test/suite/test_readonly03.py124
9 files changed, 173 insertions, 30 deletions
diff --git a/src/cursor/cur_std.c b/src/cursor/cur_std.c
index 899df8a07cc..ec5a2e88331 100644
--- a/src/cursor/cur_std.c
+++ b/src/cursor/cur_std.c
@@ -15,9 +15,10 @@
int
__wt_cursor_notsup(WT_CURSOR *cursor)
{
- WT_UNUSED(cursor);
+ WT_SESSION_IMPL *session;
- return (ENOTSUP);
+ session = (WT_SESSION_IMPL *)cursor->session;
+ WT_RET_MSG(session, ENOTSUP, "Unsupported cursor operation");
}
/*
diff --git a/src/include/txn.i b/src/include/txn.i
index 46f2ff3e5f1..40e2a6175d6 100644
--- a/src/include/txn.i
+++ b/src/include/txn.i
@@ -266,6 +266,8 @@ __wt_txn_begin(WT_SESSION_IMPL *session, const char *cfg[])
}
F_SET(txn, WT_TXN_RUNNING);
+ if (F_ISSET(S2C(session), WT_CONN_READONLY))
+ F_SET(txn, WT_TXN_READONLY);
return (false);
}
diff --git a/src/session/session_api.c b/src/session/session_api.c
index ea524b12ada..e2723c660fe 100644
--- a/src/session/session_api.c
+++ b/src/session/session_api.c
@@ -20,10 +20,12 @@ int
__wt_session_notsup_cfg(
WT_SESSION *wt_session, const char *config)
{
- WT_UNUSED(wt_session);
+ WT_SESSION_IMPL *session;
+
+ session = (WT_SESSION_IMPL *)wt_session;
WT_UNUSED(config);
- return (ENOTSUP);
+ WT_RET_MSG(session, ENOTSUP, "Unsupported session method");
}
/*
@@ -35,11 +37,13 @@ int
__wt_session_notsup_uri(
WT_SESSION *wt_session, const char *uri, const char *config)
{
- WT_UNUSED(wt_session);
+ WT_SESSION_IMPL *session;
+
+ session = (WT_SESSION_IMPL *)wt_session;
WT_UNUSED(uri);
WT_UNUSED(config);
- return (ENOTSUP);
+ WT_RET_MSG(session, ENOTSUP, "Unsupported session method");
}
/*
@@ -577,7 +581,7 @@ __session_log_printf(WT_SESSION *wt_session, const char *fmt, ...)
SESSION_API_CALL_NOCONF(session, log_printf);
if (F_ISSET(S2C(session), WT_CONN_READONLY))
- WT_ERR(ENOTSUP);
+ WT_ERR_MSG(session, ENOTSUP, "Unsupported session method");
va_start(ap, fmt);
ret = __wt_log_vprintf(session, fmt, ap);
@@ -601,7 +605,7 @@ __session_rebalance(WT_SESSION *wt_session, const char *uri, const char *config)
SESSION_API_CALL(session, rebalance, config, cfg);
if (F_ISSET(S2C(session), WT_CONN_IN_MEMORY | WT_CONN_READONLY))
- WT_ERR(ENOTSUP);
+ WT_ERR_MSG(session, ENOTSUP, "Unsupported session method");
/* Block out checkpoints to avoid spurious EBUSY errors. */
WT_WITH_CHECKPOINT_LOCK(session, ret,
@@ -627,7 +631,7 @@ __session_rename(WT_SESSION *wt_session,
SESSION_API_CALL(session, rename, config, cfg);
if (F_ISSET(S2C(session), WT_CONN_READONLY))
- WT_ERR(ENOTSUP);
+ WT_ERR_MSG(session, ENOTSUP, "Unsupported session method");
/* Disallow objects in the WiredTiger name space. */
WT_ERR(__wt_str_name_check(session, uri));
@@ -990,7 +994,7 @@ __session_truncate(WT_SESSION *wt_session,
WT_STAT_FAST_CONN_INCR(session, cursor_truncate);
if (F_ISSET(S2C(session), WT_CONN_READONLY))
- WT_ERR(ENOTSUP);
+ WT_ERR_MSG(session, ENOTSUP, "Unsupported session method");
/*
* If the URI is specified, we don't need a start/stop, if start/stop
diff --git a/test/suite/test_checkpoint01.py b/test/suite/test_checkpoint01.py
index 7d4503b84b7..36f1ef733a4 100644
--- a/test/suite/test_checkpoint01.py
+++ b/test/suite/test_checkpoint01.py
@@ -265,9 +265,13 @@ class test_checkpoint_cursor_update(wttest.WiredTigerTestCase):
cursor = self.session.open_cursor(self.uri, None, "checkpoint=ckpt")
cursor.set_key(key_populate(cursor, 10))
cursor.set_value("XXX")
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.insert())
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.remove())
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.update())
+ msg = "/not supported/"
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: cursor.insert(), msg)
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: cursor.remove(), msg)
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: cursor.update(), msg)
cursor.close()
diff --git a/test/suite/test_cursor06.py b/test/suite/test_cursor06.py
index ff7c1144344..d702f97c5dd 100644
--- a/test/suite/test_cursor06.py
+++ b/test/suite/test_cursor06.py
@@ -89,10 +89,11 @@ class test_cursor06(wttest.WiredTigerTestCase):
self.session.drop(uri, "force")
self.populate(uri)
cursor = self.session.open_cursor(uri, None, open_config)
+ msg = '/not supported/'
if open_config == "readonly=1":
self.set_kv(cursor)
- self.assertRaises(wiredtiger.WiredTigerError,
- lambda: cursor.update())
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: cursor.update(), msg)
else:
self.set_kv(cursor)
cursor.update()
diff --git a/test/suite/test_cursor_random.py b/test/suite/test_cursor_random.py
index 1fd30d93c11..cd91a925b0c 100644
--- a/test/suite/test_cursor_random.py
+++ b/test/suite/test_cursor_random.py
@@ -51,15 +51,21 @@ class test_cursor_random(wttest.WiredTigerTestCase):
uri = self.type
self.session.create(uri, 'key_format=S,value_format=S')
cursor = self.session.open_cursor(uri, None, self.config)
- self.assertRaises(
- wiredtiger.WiredTigerError, lambda: cursor.compare(cursor))
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.insert())
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.prev())
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.remove())
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.search())
- self.assertRaises(
- wiredtiger.WiredTigerError, lambda: cursor.search_near())
- self.assertRaises(wiredtiger.WiredTigerError, lambda: cursor.update())
+ msg = "/not supported/"
+ self.assertRaisesWithMessage(
+ wiredtiger.WiredTigerError, lambda: cursor.compare(cursor), msg)
+ self.assertRaisesWithMessage(
+ wiredtiger.WiredTigerError, lambda: cursor.insert(), msg)
+ self.assertRaisesWithMessage(
+ wiredtiger.WiredTigerError, lambda: cursor.prev(), msg)
+ self.assertRaisesWithMessage(
+ wiredtiger.WiredTigerError, lambda: cursor.remove(), msg)
+ self.assertRaisesWithMessage(
+ wiredtiger.WiredTigerError, lambda: cursor.search(), msg)
+ self.assertRaisesWithMessage(
+ wiredtiger.WiredTigerError, lambda: cursor.search_near(), msg)
+ self.assertRaisesWithMessage(
+ wiredtiger.WiredTigerError, lambda: cursor.update(), msg)
self.assertTrue(cursor.next(), wiredtiger.WT_NOTFOUND)
self.assertEquals(cursor.reconfigure(), 0)
diff --git a/test/suite/test_join01.py b/test/suite/test_join01.py
index f03c7c6f06c..ee4d6e22870 100644
--- a/test/suite/test_join01.py
+++ b/test/suite/test_join01.py
@@ -342,11 +342,12 @@ class test_join01(wttest.WiredTigerTestCase):
'/index cursor is being used in a join/')
# Only a small number of operations allowed on a join cursor
- self.assertRaises(wiredtiger.WiredTigerError,
- lambda: jc.search())
+ msg = "/not supported/"
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: jc.search(), msg)
- self.assertRaises(wiredtiger.WiredTigerError,
- lambda: jc.prev())
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: jc.prev(), msg)
self.assertEquals(jc.next(), 0)
self.assertEquals(jc.next(), wiredtiger.WT_NOTFOUND)
diff --git a/test/suite/test_readonly02.py b/test/suite/test_readonly02.py
index 63504d35ac2..e94dd85857d 100644
--- a/test/suite/test_readonly02.py
+++ b/test/suite/test_readonly02.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
-# Public Domain 2026-2026 MongoDB, Inc.
-# Public Domain 2008-2026 WiredTiger, Inc.
+# Public Domain 2016-2016 MongoDB, Inc.
+# Public Domain 2008-2016 WiredTiger, Inc.
#
# This is free and unencumbered software released into the public domain.
#
diff --git a/test/suite/test_readonly03.py b/test/suite/test_readonly03.py
new file mode 100644
index 00000000000..e7932839231
--- /dev/null
+++ b/test/suite/test_readonly03.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+#
+# Public Domain 2016-2016 MongoDB, Inc.
+# Public Domain 2008-2016 WiredTiger, Inc.
+#
+# This is free and unencumbered software released into the public domain.
+#
+# Anyone is free to copy, modify, publish, use, compile, sell, or
+# distribute this software, either in source code form or as a compiled
+# binary, for any purpose, commercial or non-commercial, and by any
+# means.
+#
+# In jurisdictions that recognize copyright laws, the author or authors
+# of this software dedicate any and all copyright interest in the
+# software to the public domain. We make this dedication for the benefit
+# of the public at large and to the detriment of our heirs and
+# successors. We intend this dedication to be an overt act of
+# relinquishment in perpetuity of all present and future rights to this
+# software under copyright law.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+#
+# test_readonly03.py
+# Readonly: Test connection readonly mode with modifying methods. Confirm
+# all return ENOTSUP.
+#
+
+from helper import simple_populate
+from suite_subprocess import suite_subprocess
+import os, sys, wiredtiger, wttest
+
+class test_readonly03(wttest.WiredTigerTestCase, suite_subprocess):
+ uri = 'table:test_readonly03'
+ uri2 = 'table:test_readonly03_2'
+ create = True
+
+ conn_params = 'create,log=(enabled),'
+ conn_params_rd = 'readonly=true'
+
+ session_ops = [ 'create', 'compact', 'drop', 'log_flush', 'log_printf',
+ 'rebalance', 'rename', 'salvage', 'truncate', 'upgrade', ]
+ cursor_ops = [ 'insert', 'remove', 'update', ]
+
+ def setUpConnectionOpen(self, dir):
+ self.home = dir
+ if self.create:
+ conn_cfg = self.conn_params
+ else:
+ conn_cfg = self.conn_params_rd
+ conn = self.wiredtiger_open(dir, conn_cfg)
+ self.create = False
+ return conn
+
+
+ def test_readonly(self):
+ create_params = 'key_format=i,value_format=i'
+ entries = 10
+ # Create a database and a table.
+ simple_populate(self, self.uri, create_params, entries)
+
+ #
+ # Now close and reopen. Note that the connection function
+ # above will reopen it readonly.
+ self.reopen_conn()
+ msg = '/not supported/'
+ c = self.session.open_cursor(self.uri, None, None)
+ for op in self.cursor_ops:
+ c.set_key(1)
+ c.set_value(1)
+ if op == 'insert':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: c.insert(), msg)
+ elif op == 'remove':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: c.remove(), msg)
+ elif op == 'update':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: c.update(), msg)
+ else:
+ self.fail('Unknown cursor operation: ' + op)
+ c.close()
+ for op in self.session_ops:
+ if op == 'create':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.create(self.uri2, create_params),
+ msg)
+ elif op == 'compact':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.compact(self.uri, None), msg)
+ elif op == 'drop':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.drop(self.uri, None), msg)
+ elif op == 'log_flush':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.log_flush(None), msg)
+ elif op == 'log_printf':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.log_printf("test"), msg)
+ elif op == 'rebalance':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.rebalance(self.uri, None), msg)
+ elif op == 'rename':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.rename(self.uri, self.uri2, None), msg)
+ elif op == 'salvage':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.salvage(self.uri, None), msg)
+ elif op == 'truncate':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.truncate(self.uri, None, None, None), msg)
+ elif op == 'upgrade':
+ self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
+ lambda: self.session.upgrade(self.uri, None), msg)
+ else:
+ self.fail('Unknown session method: ' + op)
+
+if __name__ == '__main__':
+ wttest.run()