1#!/usr/bin/env python
2#
3# Public Domain 2014-2018 MongoDB, Inc.
4# Public Domain 2008-2014 WiredTiger, Inc.
5#
6# This is free and unencumbered software released into the public domain.
7#
8# Anyone is free to copy, modify, publish, use, compile, sell, or
9# distribute this software, either in source code form or as a compiled
10# binary, for any purpose, commercial or non-commercial, and by any
11# means.
12#
13# In jurisdictions that recognize copyright laws, the author or authors
14# of this software dedicate any and all copyright interest in the
15# software to the public domain. We make this dedication for the benefit
16# of the public at large and to the detriment of our heirs and
17# successors. We intend this dedication to be an overt act of
18# relinquishment in perpetuity of all present and future rights to this
19# software under copyright law.
20#
21# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27# OTHER DEALINGS IN THE SOFTWARE.
28
29import wiredtiger, wttest
30from wtdataset import SimpleDataSet
31from helper import copy_wiredtiger_home
32
33# test_bug014.py
34#    JIRA WT-2115: fast-delete pages can be incorrectly lost due to a crash.
35class test_bug014(wttest.WiredTigerTestCase):
36    def test_bug014(self):
37        # Populate a table with 1000 keys on small pages.
38        uri = 'table:test_bug014'
39        ds = SimpleDataSet(self, uri, 1000,
40                           config='allocation_size=512,leaf_page_max=512')
41        ds.populate()
42
43        # Reopen it so we can fast-delete pages.
44        self.reopen_conn()
45
46        # Truncate a chunk of the key/value pairs inside a transaction.
47        self.session.begin_transaction(None)
48        start = self.session.open_cursor(uri, None)
49        start.set_key(ds.key(250))
50        end = self.session.open_cursor(uri, None)
51        end.set_key(ds.key(500))
52        self.session.truncate(None, start, end, None)
53        start.close()
54        end.close()
55
56        # With the truncation uncommitted, checkpoint the database.
57        ckpt_session = self.conn.open_session()
58        ckpt_session.checkpoint(None)
59        ckpt_session.close()
60
61        # Simulate a crash by copying to a new directory.
62        copy_wiredtiger_home(".", "RESTART")
63
64        # Open the new directory.
65        conn = self.setUpConnectionOpen("RESTART")
66        session = self.setUpSessionOpen(conn)
67        cursor = session.open_cursor(uri)
68
69        # Confirm all of the records are there.
70        for i in range(1, 1001):
71            cursor.set_key(ds.key(i))
72            self.assertEqual(cursor.search(), 0)
73
74        conn.close()
75
76if __name__ == '__main__':
77    wttest.run()
78