summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/test/suite/test_rollback_to_stable24.py
blob: ea690506dc914f5f3e32edaf6cfd636d412504a3 (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
#!/usr/bin/env python
#
# Public Domain 2014-present MongoDB, Inc.
# Public Domain 2008-2014 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.

import wiredtiger, wttest
from wtscenario import make_scenarios

# test_rollback_to_stable24.py
# Exercise a recno-counting bug in column store.
#
# Prior to August 2021 a cell for which there's a pending stable update was counted (in the
# column-store RTS code) as having RLE count 1 regardless of what the actual count was.
#
# In order to exploit this we have to do janky things with timestamps, but I think they're
# allowable.
#
# Construct a cell with RLE count of 3 by writing 3 copies of aaaaaa at timestamp 10.
# Then at the next key write bbbbbb at timestamp 10 and cccccc at timestamp 50.
# Evict the page to reconcile it and produce the RLE cell.
#
# Then post an update to the first key of the RLE cell at timestamp 30 (to dddddd), and roll
# back to 40.
#
# Reading at 40, we should at that point see dddddd and two aaaaaa's followed by bbbbbb, but
# with the bad counting we get a key error on the second key.
#
# This happens because it goes to process key 4 but thinks it's on key 2; it finds that it
# needs to roll back the value it's looking at (the cccccc from timestamp 50) but because it
# thinks it's on key to it asks the history store for key 2 and finds nothing. (The bbbbbb
# from timestamp 10 is in the history store, but under key 4; there's nothing in the history
# store for key 2.) So it issues a tombstone, and issues it for key 2, so key 2 improperly
# disappears.
#
# Run this test on rows as well as columns to help make sure the test itself is valid (and
# stays so over time...)
class test_rollback_to_stable24(wttest.WiredTigerTestCase):
    session_config = 'isolation=snapshot'
    conn_config = 'in_memory=false'

    key_format_values = [
        ('column', dict(key_format='r')),
        ('integer_row', dict(key_format='i')),
    ]

    scenarios = make_scenarios(key_format_values)

    def test_rollback_to_stable24(self):
        # Create a table without logging.
        uri = "table:rollback_to_stable24"
        format = 'key_format={},value_format=S'.format(self.key_format)
        self.session.create(uri, format + ', log=(enabled=false)')

        # Pin oldest timestamp to 10.
        self.conn.set_timestamp('oldest_timestamp=' + self.timestamp_str(10))

        # Start stable timestamp at 10.
        self.conn.set_timestamp('stable_timestamp=' + self.timestamp_str(10))

        value_a = "aaaaa" * 100
        value_b = "bbbbb" * 100
        value_c = "ccccc" * 100
        value_d = "ddddd" * 100

        s = self.conn.open_session()
        cursor = s.open_cursor(uri)

        # Write some keys at time 10.
        s.begin_transaction()
        cursor[1] = value_a
        cursor[2] = value_a
        cursor[3] = value_a
        cursor[4] = value_b
        s.commit_transaction('commit_timestamp=' + self.timestamp_str(10))

        # Update key 4 at time 50.
        s.begin_transaction()
        cursor[4] = value_c
        s.commit_transaction('commit_timestamp=' + self.timestamp_str(50))

        cursor.close()

        # Evict the page to force reconciliation.
        evict_cursor = self.session.open_cursor(uri, None, "debug=(release_evict)")
        s.begin_transaction()
        # Search the key to evict it.
        v = evict_cursor[1]
        self.assertEqual(v, value_a)
        self.assertEqual(evict_cursor.reset(), 0)
        s.rollback_transaction()
        evict_cursor.close()

        # Now update key 1 at time 30.
        cursor = s.open_cursor(uri)
        s.begin_transaction()
        cursor[1] = value_d
        s.commit_transaction('commit_timestamp=' + self.timestamp_str(30))
        cursor.close()

        # Roll back to 40.
        self.conn.set_timestamp('stable_timestamp=' + self.timestamp_str(40))
        self.conn.rollback_to_stable()

        # Now read at 40.
        cursor = s.open_cursor(uri)
        s.begin_transaction('read_timestamp=' + self.timestamp_str(40))
        self.assertEqual(cursor[1], value_d)
        self.assertEqual(cursor[2], value_a)
        self.assertEqual(cursor[3], value_a)
        self.assertEqual(cursor[4], value_b)
        s.rollback_transaction()
        cursor.close()