summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/test/suite/test_join06.py
blob: 9af6f93792f78893f5b64fe1b596dca7806edac8 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
#
# Public Domain 2014-2016 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 os
import wiredtiger, wttest, run
from wtscenario import check_scenarios, multiply_scenarios, number_scenarios

# test_join06.py
#    Join operations
# Joins with a read-uncommitted
class test_join06(wttest.WiredTigerTestCase):
    nentries = 1000

    isoscen = [
        ('isolation_read_uncommitted', dict(uncommitted=True)),
        ('isolation_default', dict(uncommitted=False))
    ]

    bloomscen = [
        ('bloom', dict(bloom=True)),
        ('nobloom', dict(bloom=False))
    ]

    scenarios = number_scenarios(multiply_scenarios('.', isoscen, bloomscen))

    def gen_values(self, i):
        s = str(i)                    # 345 => "345"
        f = s[0:1] + s[0:1] + s[0:1]  # 345 => "333"
        return [s, f]

    def gen_values2(self, i):
        s = str(i)                    # 345 => "345"
        l = s[-1:] + s[-1:] + s[-1:]  # 345 => "555"
        return [s, l]

    def populate(self, s, gen_values):
        c = s.open_cursor('table:join06', None, None)
        for i in range(0, self.nentries):
            c.set_key(i)
            c.set_value(*gen_values(i))
            c.insert()
        c.close()

    # Common function for testing the most basic functionality
    # of joins
    def test_join(self):
        self.session.create('table:join06',
                            'columns=(k,v0,v1),key_format=i,value_format=SS')
        self.session.create('index:join06:index0','columns=(v0)')
        self.session.create('index:join06:index1','columns=(v1)')

        self.populate(self.session, self.gen_values)

        # TODO: needed?
        #self.reopen_conn()

        if self.uncommitted:
            self.session.begin_transaction('isolation=read-uncommitted')

        jc = self.session.open_cursor('join:table:join06', None, None)
        c0 = self.session.open_cursor('index:join06:index0', None, None)
        c0.set_key('520')
        self.assertEquals(0, c0.search())
        self.session.join(jc, c0, 'compare=ge')

        joinconfig = 'compare=eq'
        if self.bloom:
            joinconfig += ',strategy=bloom,count=1000'
        c1 = self.session.open_cursor('index:join06:index1', None, None)
        c1.set_key('555')
        self.assertEquals(0, c1.search())
        self.session.join(jc, c1, joinconfig)

        if self.uncommitted and self.bloom:
            # Make sure that read-uncommitted with Bloom is not allowed.
            # This is detected on the first next() operation.
            msg = '/cannot be used with read-uncommitted/'
            self.assertRaisesWithMessage(wiredtiger.WiredTigerError,
                lambda: jc.next(), msg)
            return

        # Changes made in another session may or may not be visible to us,
        # depending on the isolation level.
        if self.uncommitted:
            # isolation level is read-uncommitted, so we will see
            # additions deletions made in our other session.
            mbr = set(range(525,1000,10)) | set(range(55,100,10)) | set([520])
        else:
            # default isolation level, so we should see a consistent
            # set at the time we begin iteration.
            mbr = set(range(520,600)) | set(range(53,60))

        altered = False

        while jc.next() == 0:
            [k] = jc.get_keys()
            [v0,v1] = jc.get_values()
            #self.tty('GOT: ' + str(k) + ': ' + str(jc.get_values()))
            if altered and self.uncommitted:
                self.assertEquals(self.gen_values2(k), [v0, v1])
            else:
                self.assertEquals(self.gen_values(k), [v0, v1])
            if not k in mbr:
                self.tty('**** ERROR: result ' + str(k) + ' is not in: ' +
                         str(mbr))
            self.assertTrue(k in mbr)
            mbr.remove(k)

            # In another session, we remove entries for keys ending in 6,
            # and add entries for keys ending in 5.  Depending on the
            # isolation level for the transaction, these changes may or
            # may not be visible for the original session.
            if not altered:
                s = self.conn.open_session(None)
                s.begin_transaction(None)
                self.populate(s, self.gen_values2)
                s.commit_transaction()
                s.close()
                altered = True

        if len(mbr) != 0:
            self.tty('**** ERROR: did not see these: ' + str(mbr))
        self.assertEquals(0, len(mbr))

        jc.close()
        c1.close()
        c0.close()
        if self.uncommitted:
            self.session.commit_transaction()
        self.session.drop('table:join06')

if __name__ == '__main__':
    wttest.run()