OLD | NEW |
---|---|
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 "sql/connection.h" | 5 #include "sql/connection.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 // would keep the zero page around, plus some pre-initialized pages, and SQLite | 505 // would keep the zero page around, plus some pre-initialized pages, and SQLite |
506 // can manage things. The downside is that updates larger than the cache would | 506 // can manage things. The downside is that updates larger than the cache would |
507 // spill to the journal. That could be compensated by setting cache_spill to | 507 // spill to the journal. That could be compensated by setting cache_spill to |
508 // false. The downside then is that it allows open-ended use of memory for | 508 // false. The downside then is that it allows open-ended use of memory for |
509 // large transactions. | 509 // large transactions. |
510 // | 510 // |
511 // TODO(shess): The TrimMemory() trick of bouncing the cache size would also | 511 // TODO(shess): The TrimMemory() trick of bouncing the cache size would also |
512 // work. There could be two prepared statements, one for cache_size=1 one for | 512 // work. There could be two prepared statements, one for cache_size=1 one for |
513 // cache_size=goal. | 513 // cache_size=goal. |
514 void Connection::ReleaseCacheMemoryIfNeeded(bool implicit_change_performed) { | 514 void Connection::ReleaseCacheMemoryIfNeeded(bool implicit_change_performed) { |
515 DCHECK(is_open()); | |
516 | |
515 // If memory-mapping is not enabled, the page cache helps performance. | 517 // If memory-mapping is not enabled, the page cache helps performance. |
516 if (!mmap_enabled_) | 518 if (!mmap_enabled_) |
517 return; | 519 return; |
518 | 520 |
519 // On caller request, force the change comparison to fail. Done before the | 521 // On caller request, force the change comparison to fail. Done before the |
520 // transaction-nesting test so that the signal can carry to transaction | 522 // transaction-nesting test so that the signal can carry to transaction |
521 // commit. | 523 // commit. |
522 if (implicit_change_performed) | 524 if (implicit_change_performed) |
523 --total_changes_at_last_release_; | 525 --total_changes_at_last_release_; |
524 | 526 |
525 // Cached pages may be re-used within the same transaction. | 527 // Cached pages may be re-used within the same transaction. |
526 if (transaction_nesting()) | 528 if (transaction_nesting()) |
527 return; | 529 return; |
528 | 530 |
Scott Hess - ex-Googler
2015/09/30 17:25:04
I didn't put:
if (!is_open())
return;
here b
| |
529 // If no changes have been made, skip flushing. This allows the first page of | 531 // If no changes have been made, skip flushing. This allows the first page of |
530 // the database to remain in cache across multiple reads. | 532 // the database to remain in cache across multiple reads. |
531 const int total_changes = sqlite3_total_changes(db_); | 533 const int total_changes = sqlite3_total_changes(db_); |
532 if (total_changes == total_changes_at_last_release_) | 534 if (total_changes == total_changes_at_last_release_) |
533 return; | 535 return; |
534 | 536 |
535 total_changes_at_last_release_ = total_changes; | 537 total_changes_at_last_release_ = total_changes; |
536 sqlite3_db_release_memory(db_); | 538 sqlite3_db_release_memory(db_); |
537 } | 539 } |
538 | 540 |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 | 1359 |
1358 // Collect the rollback time manually, sql::Statement would register it as | 1360 // Collect the rollback time manually, sql::Statement would register it as |
1359 // query time only. | 1361 // query time only. |
1360 const base::TimeTicks before = Now(); | 1362 const base::TimeTicks before = Now(); |
1361 rollback.RunWithoutTimers(); | 1363 rollback.RunWithoutTimers(); |
1362 const base::TimeDelta delta = Now() - before; | 1364 const base::TimeDelta delta = Now() - before; |
1363 | 1365 |
1364 RecordUpdateTime(delta); | 1366 RecordUpdateTime(delta); |
1365 RecordOneEvent(EVENT_ROLLBACK); | 1367 RecordOneEvent(EVENT_ROLLBACK); |
1366 | 1368 |
1367 // The cache may have been accumulating dirty pages for commit. | 1369 // The cache may have been accumulating dirty pages for commit. Note that in |
1368 ReleaseCacheMemoryIfNeeded(false); | 1370 // some cases sql::Transaction can fire rollback after a database is closed. |
1371 if (is_open()) | |
1372 ReleaseCacheMemoryIfNeeded(false); | |
1369 | 1373 |
1370 needs_rollback_ = false; | 1374 needs_rollback_ = false; |
1371 } | 1375 } |
1372 | 1376 |
1373 void Connection::StatementRefCreated(StatementRef* ref) { | 1377 void Connection::StatementRefCreated(StatementRef* ref) { |
1374 DCHECK(open_statements_.find(ref) == open_statements_.end()); | 1378 DCHECK(open_statements_.find(ref) == open_statements_.end()); |
1375 open_statements_.insert(ref); | 1379 open_statements_.insert(ref); |
1376 } | 1380 } |
1377 | 1381 |
1378 void Connection::StatementRefDeleted(StatementRef* ref) { | 1382 void Connection::StatementRefDeleted(StatementRef* ref) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1479 ignore_result(Execute(kNoWritableSchema)); | 1483 ignore_result(Execute(kNoWritableSchema)); |
1480 | 1484 |
1481 return ret; | 1485 return ret; |
1482 } | 1486 } |
1483 | 1487 |
1484 base::TimeTicks TimeSource::Now() { | 1488 base::TimeTicks TimeSource::Now() { |
1485 return base::TimeTicks::Now(); | 1489 return base::TimeTicks::Now(); |
1486 } | 1490 } |
1487 | 1491 |
1488 } // namespace sql | 1492 } // namespace sql |
OLD | NEW |