| OLD | NEW |
| 1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. | 1 // Copyright (c) 2011 The LevelDB 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. See the AUTHORS file for names of contributors. | 3 // found in the LICENSE file. See the AUTHORS file for names of contributors. |
| 4 | 4 |
| 5 #include "third_party/leveldatabase/env_chromium.h" | 5 #include "third_party/leveldatabase/env_chromium.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
| 11 #include <dirent.h> | 11 #include <dirent.h> |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "base/files/file_enumerator.h" | 15 #include "base/files/file_enumerator.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/process/process_metrics.h" | 19 #include "base/process/process_metrics.h" |
| 20 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/sys_info.h" |
| 23 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
| 24 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
| 25 #include "third_party/leveldatabase/chromium_logger.h" | 26 #include "third_party/leveldatabase/chromium_logger.h" |
| 27 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
| 26 #include "third_party/re2/src/re2/re2.h" | 28 #include "third_party/re2/src/re2/re2.h" |
| 27 | 29 |
| 28 using base::FilePath; | 30 using base::FilePath; |
| 29 using leveldb::FileLock; | 31 using leveldb::FileLock; |
| 30 using leveldb::Slice; | 32 using leveldb::Slice; |
| 31 using leveldb::Status; | 33 using leveldb::Status; |
| 32 | 34 |
| 33 namespace leveldb_env { | 35 namespace leveldb_env { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return false; | 486 return false; |
| 485 leveldb_env::MethodID method; | 487 leveldb_env::MethodID method; |
| 486 base::File::Error error = base::File::FILE_OK; | 488 base::File::Error error = base::File::FILE_OK; |
| 487 leveldb_env::ErrorParsingResult result = | 489 leveldb_env::ErrorParsingResult result = |
| 488 leveldb_env::ParseMethodAndError(status, &method, &error); | 490 leveldb_env::ParseMethodAndError(status, &method, &error); |
| 489 return (result == leveldb_env::METHOD_AND_BFE && | 491 return (result == leveldb_env::METHOD_AND_BFE && |
| 490 static_cast<base::File::Error>(error) == | 492 static_cast<base::File::Error>(error) == |
| 491 base::File::FILE_ERROR_NO_SPACE); | 493 base::File::FILE_ERROR_NO_SPACE); |
| 492 } | 494 } |
| 493 | 495 |
| 496 // Given the size of the disk, identified by |disk_size| in bytes, determine the |
| 497 // appropriate write_buffer_size. Ignoring snapshots, if the current set of |
| 498 // tables in a database contains a set of key/value pairs identified by {A}, and |
| 499 // a set of key/value pairs identified by {B} has been written and is in the log |
| 500 // file, then during compaction you will have {A} + {B} + {A, B} = 2A + 2B. |
| 501 // There is no way to know the size of A, so minimizing the size of B will |
| 502 // maximize the likelihood of a successful compaction. |
| 503 size_t WriteBufferSize(int64_t disk_size) { |
| 504 const leveldb::Options default_options; |
| 505 const int64_t kMinBufferSize = 1024 * 1024; |
| 506 const int64_t kMaxBufferSize = default_options.write_buffer_size; |
| 507 const int64_t kDiskMinBuffSize = 10 * 1024 * 1024; |
| 508 const int64_t kDiskMaxBuffSize = 40 * 1024 * 1024; |
| 509 |
| 510 if (disk_size == -1) |
| 511 return default_options.write_buffer_size; |
| 512 |
| 513 if (disk_size <= kDiskMinBuffSize) |
| 514 return kMinBufferSize; |
| 515 |
| 516 if (disk_size >= kDiskMaxBuffSize) |
| 517 return kMaxBufferSize; |
| 518 |
| 519 // A linear equation to intersect (kDiskMinBuffSize, kMinBufferSize) and |
| 520 // (kDiskMaxBuffSize, kMaxBufferSize). |
| 521 return static_cast<size_t>( |
| 522 kMinBufferSize + |
| 523 ((kMaxBufferSize - kMinBufferSize) * (disk_size - kDiskMinBuffSize)) / |
| 524 (kDiskMaxBuffSize - kDiskMinBuffSize)); |
| 525 } |
| 526 |
| 527 size_t WriteBufferSize(const base::FilePath& path) { |
| 528 return WriteBufferSize(base::SysInfo::AmountOfTotalDiskSpace(path)); |
| 529 } |
| 530 |
| 494 ChromiumEnv::ChromiumEnv() : ChromiumEnv("LevelDBEnv") {} | 531 ChromiumEnv::ChromiumEnv() : ChromiumEnv("LevelDBEnv") {} |
| 495 | 532 |
| 496 ChromiumEnv::ChromiumEnv(const std::string& name) | 533 ChromiumEnv::ChromiumEnv(const std::string& name) |
| 497 : kMaxRetryTimeMillis(1000), | 534 : kMaxRetryTimeMillis(1000), |
| 498 name_(name), | 535 name_(name), |
| 499 bgsignal_(&mu_), | 536 bgsignal_(&mu_), |
| 500 started_bgthread_(false) { | 537 started_bgthread_(false) { |
| 501 uma_ioerror_base_name_ = name_ + ".IOError.BFE"; | 538 uma_ioerror_base_name_ = name_ + ".IOError.BFE"; |
| 502 } | 539 } |
| 503 | 540 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1058 |
| 1022 } // namespace leveldb_env | 1059 } // namespace leveldb_env |
| 1023 | 1060 |
| 1024 namespace leveldb { | 1061 namespace leveldb { |
| 1025 | 1062 |
| 1026 Env* Env::Default() { | 1063 Env* Env::Default() { |
| 1027 return leveldb_env::default_env.Pointer(); | 1064 return leveldb_env::default_env.Pointer(); |
| 1028 } | 1065 } |
| 1029 | 1066 |
| 1030 } // namespace leveldb | 1067 } // namespace leveldb |
| OLD | NEW |