| 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 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include <dirent.h> | 8 #include <dirent.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #endif | 10 #endif |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 const std::string& message, | 405 const std::string& message, |
| 406 MethodID method) { | 406 MethodID method) { |
| 407 char buf[512]; | 407 char buf[512]; |
| 408 snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_str(), | 408 snprintf(buf, sizeof(buf), "%s (ChromeMethodOnly: %d::%s)", message.c_str(), |
| 409 method, MethodIDToString(method)); | 409 method, MethodIDToString(method)); |
| 410 return Status::IOError(filename, buf); | 410 return Status::IOError(filename, buf); |
| 411 } | 411 } |
| 412 | 412 |
| 413 ErrorParsingResult ParseMethodAndError(const leveldb::Status& status, | 413 ErrorParsingResult ParseMethodAndError(const leveldb::Status& status, |
| 414 MethodID* method_param, | 414 MethodID* method_param, |
| 415 int* error) { | 415 base::File::Error* error) { |
| 416 const std::string status_string = status.ToString(); | 416 const std::string status_string = status.ToString(); |
| 417 int method; | 417 int method; |
| 418 if (RE2::PartialMatch(status_string.c_str(), "ChromeMethodOnly: (\\d+)", | 418 if (RE2::PartialMatch(status_string.c_str(), "ChromeMethodOnly: (\\d+)", |
| 419 &method)) { | 419 &method)) { |
| 420 *method_param = static_cast<MethodID>(method); | 420 *method_param = static_cast<MethodID>(method); |
| 421 return METHOD_ONLY; | 421 return METHOD_ONLY; |
| 422 } | 422 } |
| 423 int parsed_error; |
| 423 if (RE2::PartialMatch(status_string.c_str(), | 424 if (RE2::PartialMatch(status_string.c_str(), |
| 424 "ChromeMethodPFE: (\\d+)::.*::(\\d+)", &method, | 425 "ChromeMethodPFE: (\\d+)::.*::(\\d+)", &method, |
| 425 error)) { | 426 &parsed_error)) { |
| 426 *error = -*error; | |
| 427 *method_param = static_cast<MethodID>(method); | 427 *method_param = static_cast<MethodID>(method); |
| 428 *error = static_cast<base::File::Error>(-parsed_error); |
| 429 DCHECK_LT(*error, base::File::FILE_OK); |
| 430 DCHECK_GT(*error, base::File::FILE_ERROR_MAX); |
| 428 return METHOD_AND_PFE; | 431 return METHOD_AND_PFE; |
| 429 } | 432 } |
| 430 if (RE2::PartialMatch(status_string.c_str(), | |
| 431 "ChromeMethodErrno: (\\d+)::.*::(\\d+)", &method, | |
| 432 error)) { | |
| 433 *method_param = static_cast<MethodID>(method); | |
| 434 return METHOD_AND_ERRNO; | |
| 435 } | |
| 436 return NONE; | 433 return NONE; |
| 437 } | 434 } |
| 438 | 435 |
| 439 // Keep in sync with LevelDBCorruptionTypes in histograms.xml. Also, don't | 436 // Keep in sync with LevelDBCorruptionTypes in histograms.xml. Also, don't |
| 440 // change the order because indices into this array have been recorded in uma | 437 // change the order because indices into this array have been recorded in uma |
| 441 // histograms. | 438 // histograms. |
| 442 const char* patterns[] = { | 439 const char* patterns[] = { |
| 443 "missing files", | 440 "missing files", |
| 444 "log record too small", | 441 "log record too small", |
| 445 "corrupted internal key", | 442 "corrupted internal key", |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 int code = GetCorruptionCode(status); | 497 int code = GetCorruptionCode(status); |
| 501 if (code == 0) | 498 if (code == 0) |
| 502 return "Unknown corruption"; | 499 return "Unknown corruption"; |
| 503 return patterns[code - 1]; | 500 return patterns[code - 1]; |
| 504 } | 501 } |
| 505 | 502 |
| 506 bool IndicatesDiskFull(const leveldb::Status& status) { | 503 bool IndicatesDiskFull(const leveldb::Status& status) { |
| 507 if (status.ok()) | 504 if (status.ok()) |
| 508 return false; | 505 return false; |
| 509 leveldb_env::MethodID method; | 506 leveldb_env::MethodID method; |
| 510 int error = -1; | 507 base::File::Error error = base::File::FILE_OK; |
| 511 leveldb_env::ErrorParsingResult result = | 508 leveldb_env::ErrorParsingResult result = |
| 512 leveldb_env::ParseMethodAndError(status, &method, &error); | 509 leveldb_env::ParseMethodAndError(status, &method, &error); |
| 513 return (result == leveldb_env::METHOD_AND_PFE && | 510 return (result == leveldb_env::METHOD_AND_PFE && |
| 514 static_cast<base::File::Error>(error) == | 511 static_cast<base::File::Error>(error) == |
| 515 base::File::FILE_ERROR_NO_SPACE) || | 512 base::File::FILE_ERROR_NO_SPACE); |
| 516 (result == leveldb_env::METHOD_AND_ERRNO && error == ENOSPC); | |
| 517 } | 513 } |
| 518 | 514 |
| 519 bool ChromiumEnv::MakeBackup(const std::string& fname) { | 515 bool ChromiumEnv::MakeBackup(const std::string& fname) { |
| 520 FilePath original_table_name = FilePath::FromUTF8Unsafe(fname); | 516 FilePath original_table_name = FilePath::FromUTF8Unsafe(fname); |
| 521 FilePath backup_table_name = | 517 FilePath backup_table_name = |
| 522 original_table_name.ReplaceExtension(backup_table_extension); | 518 original_table_name.ReplaceExtension(backup_table_extension); |
| 523 return base::CopyFile(original_table_name, backup_table_name); | 519 return base::CopyFile(original_table_name, backup_table_name); |
| 524 } | 520 } |
| 525 | 521 |
| 526 ChromiumEnv::ChromiumEnv() | 522 ChromiumEnv::ChromiumEnv() |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 | 1096 |
| 1101 Env* IDBEnv() { | 1097 Env* IDBEnv() { |
| 1102 return leveldb_env::idb_env.Pointer(); | 1098 return leveldb_env::idb_env.Pointer(); |
| 1103 } | 1099 } |
| 1104 | 1100 |
| 1105 Env* Env::Default() { | 1101 Env* Env::Default() { |
| 1106 return leveldb_env::default_env.Pointer(); | 1102 return leveldb_env::default_env.Pointer(); |
| 1107 } | 1103 } |
| 1108 | 1104 |
| 1109 } // namespace leveldb | 1105 } // namespace leveldb |
| OLD | NEW |