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/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
25 #include "third_party/leveldatabase/chromium_logger.h" | 25 #include "third_party/leveldatabase/chromium_logger.h" |
| 26 #include "third_party/leveldatabase/src/include/leveldb/options.h" |
26 #include "third_party/re2/src/re2/re2.h" | 27 #include "third_party/re2/src/re2/re2.h" |
27 | 28 |
28 using base::FilePath; | 29 using base::FilePath; |
29 using leveldb::FileLock; | 30 using leveldb::FileLock; |
30 using leveldb::Slice; | 31 using leveldb::Slice; |
31 using leveldb::Status; | 32 using leveldb::Status; |
32 | 33 |
33 namespace leveldb_env { | 34 namespace leveldb_env { |
34 | 35 |
35 namespace { | 36 namespace { |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 return false; | 485 return false; |
485 leveldb_env::MethodID method; | 486 leveldb_env::MethodID method; |
486 base::File::Error error = base::File::FILE_OK; | 487 base::File::Error error = base::File::FILE_OK; |
487 leveldb_env::ErrorParsingResult result = | 488 leveldb_env::ErrorParsingResult result = |
488 leveldb_env::ParseMethodAndError(status, &method, &error); | 489 leveldb_env::ParseMethodAndError(status, &method, &error); |
489 return (result == leveldb_env::METHOD_AND_BFE && | 490 return (result == leveldb_env::METHOD_AND_BFE && |
490 static_cast<base::File::Error>(error) == | 491 static_cast<base::File::Error>(error) == |
491 base::File::FILE_ERROR_NO_SPACE); | 492 base::File::FILE_ERROR_NO_SPACE); |
492 } | 493 } |
493 | 494 |
| 495 // Given the size of the disk, identified by |disk_size| in bytes, determine the |
| 496 // appropriate write_buffer_size. Ignoring snapshots, if the current set of |
| 497 // tables in a database contains a set of key/value pairs identified by {A}, and |
| 498 // a set of key/value pairs identified by {B} has been written and is in the log |
| 499 // file, then during compaction you will have {A} + {B} + {A, B} = 2A + 2B. |
| 500 // There is no way to know the size of A, so minimizing the size of B will |
| 501 // maximize the likelihood of a successful compaction. |
| 502 size_t WriteBufferSize(int64_t disk_size) { |
| 503 const leveldb::Options default_options; |
| 504 const int64_t kMinBufferSize = 1024 * 1024; |
| 505 const int64_t kMaxBufferSize = default_options.write_buffer_size; |
| 506 const int64_t kDiskMinBuffSize = 10 * 1024 * 1024; |
| 507 const int64_t kDiskMaxBuffSize = 40 * 1024 * 1024; |
| 508 |
| 509 if (disk_size == -1) |
| 510 return default_options.write_buffer_size; |
| 511 |
| 512 if (disk_size <= kDiskMinBuffSize) |
| 513 return kMinBufferSize; |
| 514 |
| 515 if (disk_size >= kDiskMaxBuffSize) |
| 516 return kMaxBufferSize; |
| 517 |
| 518 // A linear equation to intersect (kDiskMinBuffSize, kMinBufferSize) and |
| 519 // (kDiskMaxBuffSize, kMaxBufferSize). |
| 520 return static_cast<size_t>( |
| 521 kMinBufferSize + |
| 522 ((kMaxBufferSize - kMinBufferSize) * (disk_size - kDiskMinBuffSize)) / |
| 523 (kDiskMaxBuffSize - kDiskMinBuffSize)); |
| 524 } |
| 525 |
494 ChromiumEnv::ChromiumEnv() : ChromiumEnv("LevelDBEnv") {} | 526 ChromiumEnv::ChromiumEnv() : ChromiumEnv("LevelDBEnv") {} |
495 | 527 |
496 ChromiumEnv::ChromiumEnv(const std::string& name) | 528 ChromiumEnv::ChromiumEnv(const std::string& name) |
497 : kMaxRetryTimeMillis(1000), | 529 : kMaxRetryTimeMillis(1000), |
498 name_(name), | 530 name_(name), |
499 bgsignal_(&mu_), | 531 bgsignal_(&mu_), |
500 started_bgthread_(false) { | 532 started_bgthread_(false) { |
501 uma_ioerror_base_name_ = name_ + ".IOError.BFE"; | 533 uma_ioerror_base_name_ = name_ + ".IOError.BFE"; |
502 } | 534 } |
503 | 535 |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 | 1053 |
1022 } // namespace leveldb_env | 1054 } // namespace leveldb_env |
1023 | 1055 |
1024 namespace leveldb { | 1056 namespace leveldb { |
1025 | 1057 |
1026 Env* Env::Default() { | 1058 Env* Env::Default() { |
1027 return leveldb_env::default_env.Pointer(); | 1059 return leveldb_env::default_env.Pointer(); |
1028 } | 1060 } |
1029 | 1061 |
1030 } // namespace leveldb | 1062 } // namespace leveldb |
OLD | NEW |