Ensure that opening a database that is beyond the maximum size succeeds, even when InitialMmapSize is above the limit (mmaps should not affect file size) https://github.com/etcd-io/bbolt/issues/928
(t *testing.T)
| 1630 | // even when InitialMmapSize is above the limit (mmaps should not affect file size) |
| 1631 | // https://github.com/etcd-io/bbolt/issues/928 |
| 1632 | func TestDB_MaxSizeExceededCanOpenWithHighMmap(t *testing.T) { |
| 1633 | // Open a data file. |
| 1634 | db := createFilledDB(t, nil, 4*1024*1024, 2000) // adjust allocation jumps to 4 MiB, fill with 2000 1KB entries |
| 1635 | path := db.Path() |
| 1636 | |
| 1637 | err := db.Close() |
| 1638 | require.NoError(t, err, "Close should succeed") |
| 1639 | |
| 1640 | // The data file should be 4 MiB now (expanded once from zero). |
| 1641 | minimumSizeForTest := int64(1024 * 1024) |
| 1642 | newSz := fileSize(path) |
| 1643 | require.GreaterOrEqual(t, newSz, minimumSizeForTest, "unexpected new file size: %d. Expected at least %d", newSz, minimumSizeForTest) |
| 1644 | |
| 1645 | // Now try to re-open the database with an extremely small max size |
| 1646 | t.Logf("Reopening bbolt DB at: %s", path) |
| 1647 | db, err = btesting.OpenDBWithOption(t, path, &bolt.Options{ |
| 1648 | MaxSize: 1, |
| 1649 | InitialMmapSize: int(minimumSizeForTest) * 2, |
| 1650 | }) |
| 1651 | assert.NoError(t, err, "Should be able to open database bigger than MaxSize when InitialMmapSize set high") |
| 1652 | |
| 1653 | err = db.Close() |
| 1654 | require.NoError(t, err, "Closing the re-opened database should succeed") |
| 1655 | } |
| 1656 | |
| 1657 | // Ensure that on Windows, mmap never expands the file speculatively via |
| 1658 | // InitialMmapSize, and that the database remains fully usable after such an |
nothing calls this directly
no test coverage detected