Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: sql/connection_unittest.cc

Issue 1533703002: [sql] Consider fresh databases suitable for memory-mapped I/O. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: eyeroll and 0UL Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sql/connection.cc ('k') | sql/meta_table.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/memory_mapped_file.h" 7 #include "base/files/memory_mapped_file.h"
8 #include "base/files/scoped_file.h" 8 #include "base/files/scoped_file.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 EXPECT_FALSE(db().RegisterIntentToUpload()); 1454 EXPECT_FALSE(db().RegisterIntentToUpload());
1455 1455
1456 // Old tag is still prevented. 1456 // Old tag is still prevented.
1457 db().Close(); 1457 db().Close();
1458 db().set_histogram_tag("Test"); 1458 db().set_histogram_tag("Test");
1459 ASSERT_TRUE(db().Open(db_path())); 1459 ASSERT_TRUE(db().Open(db_path()));
1460 EXPECT_FALSE(db().RegisterIntentToUpload()); 1460 EXPECT_FALSE(db().RegisterIntentToUpload());
1461 } 1461 }
1462 #endif // !defined(MOJO_APPTEST_IMPL) 1462 #endif // !defined(MOJO_APPTEST_IMPL)
1463 1463
1464 // Test that a fresh database has mmap enabled by default, if mmap'ed I/O is
1465 // enabled by SQLite.
1466 TEST_F(SQLConnectionTest, MmapInitiallyEnabled) {
1467 {
1468 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size"));
1469
1470 // SQLite doesn't have mmap support (perhaps an early iOS release).
1471 if (!s.Step())
1472 return;
1473
1474 // If mmap I/O is not on, attempt to turn it on. If that succeeds, then
1475 // Open() should have turned it on. If mmap support is disabled, 0 is
1476 // returned. If the VFS does not understand SQLITE_FCNTL_MMAP_SIZE (for
1477 // instance MojoVFS), -1 is returned.
1478 if (s.ColumnInt(0) <= 0) {
1479 ASSERT_TRUE(db().Execute("PRAGMA mmap_size = 1048576"));
1480 s.Reset(true);
1481 ASSERT_TRUE(s.Step());
1482 EXPECT_LE(s.ColumnInt(0), 0);
1483 }
1484 }
1485
1486 // Test that explicit disable prevents mmap'ed I/O.
1487 db().Close();
1488 sql::Connection::Delete(db_path());
1489 db().set_mmap_disabled();
1490 ASSERT_TRUE(db().Open(db_path()));
1491 {
1492 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size"));
1493 ASSERT_TRUE(s.Step());
1494 EXPECT_LE(s.ColumnInt(0), 0);
1495 }
1496 }
1497
1498 // Test specific operation of the GetAppropriateMmapSize() helper.
1499 #if defined(OS_IOS)
1500 TEST_F(SQLConnectionTest, GetAppropriateMmapSize) {
1501 ASSERT_EQ(0UL, db().GetAppropriateMmapSize());
1502 }
1503 #else
1504 TEST_F(SQLConnectionTest, GetAppropriateMmapSize) {
1505 const size_t kMmapAlot = 25 * 1024 * 1024;
1506
1507 // If there is no meta table (as for a fresh database), assume that everything
1508 // should be mapped.
1509 ASSERT_TRUE(!db().DoesTableExist("meta"));
1510 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot);
1511
1512 // Getting the status fails if there is an error. GetAppropriateMmapSize()
1513 // should not call GetMmapStatus() if the table does not exist, but this is an
1514 // easy error to setup for testing.
1515 int64_t mmap_status;
1516 {
1517 sql::ScopedErrorIgnorer ignore_errors;
1518 ignore_errors.IgnoreError(SQLITE_ERROR);
1519 ASSERT_FALSE(MetaTable::GetMmapStatus(&db(), &mmap_status));
1520 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
1521 }
1522
1523 // When the meta table is first created, it sets up to map everything.
1524 MetaTable().Init(&db(), 1, 1);
1525 ASSERT_TRUE(db().DoesTableExist("meta"));
1526 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot);
1527 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status));
1528 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status);
1529
1530 // Failure status maps nothing.
1531 ASSERT_TRUE(db().Execute("REPLACE INTO meta VALUES ('mmap_status', -2)"));
1532 ASSERT_EQ(0UL, db().GetAppropriateMmapSize());
1533
1534 // Re-initializing the meta table does not re-create the key if the table
1535 // already exists.
1536 ASSERT_TRUE(db().Execute("DELETE FROM meta WHERE key = 'mmap_status'"));
1537 MetaTable().Init(&db(), 1, 1);
1538 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status);
1539 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status));
1540 ASSERT_EQ(0, mmap_status);
1541
1542 // With no key, map everything and create the key.
1543 // TODO(shess): This really should be "maps everything after validating it",
1544 // but that is more complicated to structure.
1545 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot);
1546 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status));
1547 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status);
1548 }
1549 #endif
1550
1464 } // namespace sql 1551 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.cc ('k') | sql/meta_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698