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 os, time 30import wiredtiger, wttest 31from wtdataset import SimpleDataSet, ComplexDataSet 32from wtscenario import make_scenarios 33 34# test_rebalance.py 35# session level rebalance operation 36class test_rebalance(wttest.WiredTigerTestCase): 37 name = 'test_rebalance' 38 39 # Use small pages so we generate some internal layout 40 # Setup LSM so multiple chunks are present 41 config = 'allocation_size=512,internal_page_max=512' + \ 42 ',leaf_page_max=1k,lsm=(chunk_size=512k,merge_min=10)' 43 44 scenarios = make_scenarios([ 45 ('file', dict(uri='file:')), 46 ('table', dict(uri='table:')), 47 ('lsm', dict(uri='lsm:')) 48 ]) 49 50 # Populate an object, then rebalance it. 51 def rebalance(self, dataset, with_cursor): 52 uri = self.uri + self.name 53 ds = dataset(self, uri, 10000, config=self.config) 54 ds.populate() 55 56 # Force to disk, we don't rebalance in-memory objects. 57 self.reopen_conn() 58 59 # Open cursors should cause failure. 60 if with_cursor: 61 cursor = self.session.open_cursor(uri, None, None) 62 self.assertRaises(wiredtiger.WiredTigerError, 63 lambda: self.session.rebalance(uri, None)) 64 cursor.close() 65 66 self.session.rebalance(uri, None) 67 self.session.drop(uri) 68 69 # Test rebalance of an object. 70 def test_rebalance(self): 71 # Simple file or table object. 72 self.rebalance(SimpleDataSet, False) 73 self.rebalance(SimpleDataSet, True) 74 75 # A complex, multi-file table object. 76 if self.uri == "table:": 77 self.rebalance(ComplexDataSet, False) 78 self.rebalance(ComplexDataSet, True) 79 80if __name__ == '__main__': 81 wttest.run() 82