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 fnmatch, os, time 30import wiredtiger, wttest 31from wtdataset import SimpleDataSet 32 33# test_bug019.py 34# Test that pre-allocating log files only pre-allocates a small number. 35class test_bug019(wttest.WiredTigerTestCase): 36 conn_config = 'log=(enabled,file_max=100K)' 37 uri = "table:bug019" 38 entries = 5000 39 40 # Modify rows so we write log records. We're writing a lot more than a 41 # single log file, so we know the underlying library will churn through 42 # log files. 43 def populate(self, nentries): 44 c = self.session.open_cursor(self.uri, None, None) 45 for i in range(0, nentries): 46 # Make the values about 200 bytes. That's about 1MB of data for 47 # 5000 records, generating 10 log files used plus more for overhead. 48 c[i] = "abcde" * 40 49 c.close() 50 51 # Wait for a log file to be pre-allocated. Avoid timing problems, but 52 # assert a file is created within 30 seconds. 53 def prepfiles(self): 54 for i in range(1,30): 55 f = fnmatch.filter(os.listdir('.'), "*Prep*") 56 if f: 57 return f 58 time.sleep(1) 59 self.assertFalse(not f) 60 61 # There was a bug where pre-allocated log files accumulated on 62 # Windows systems due to an issue with the directory list code. 63 def test_bug019(self): 64 # Create a table just to write something into the log. 65 self.session.create(self.uri, 'key_format=i,value_format=S') 66 self.populate(self.entries) 67 self.session.checkpoint() 68 69 # Loop, making sure pre-allocation is working and the range is moving. 70 older = self.prepfiles() 71 for i in range(1, 10): 72 self.populate(self.entries) 73 newer = self.prepfiles() 74 75 # Files can be returned in any order when reading a directory, older 76 # pre-allocated files can persist longer than newer files when newer 77 # files are returned first. Confirm files are being consumed. 78 self.assertFalse(set(older) < set(newer)) 79 80 older = newer 81 self.session.checkpoint() 82 83if __name__ == '__main__': 84 wttest.run() 85