convenience.cc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. #ifndef ROCKSDB_LITE
  7. #include "rocksdb/convenience.h"
  8. #include "db/db_impl/db_impl.h"
  9. #include "util/cast_util.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. void CancelAllBackgroundWork(DB* db, bool wait) {
  12. (static_cast_with_check<DBImpl, DB>(db->GetRootDB()))
  13. ->CancelAllBackgroundWork(wait);
  14. }
  15. Status DeleteFilesInRange(DB* db, ColumnFamilyHandle* column_family,
  16. const Slice* begin, const Slice* end,
  17. bool include_end) {
  18. RangePtr range(begin, end);
  19. return DeleteFilesInRanges(db, column_family, &range, 1, include_end);
  20. }
  21. Status DeleteFilesInRanges(DB* db, ColumnFamilyHandle* column_family,
  22. const RangePtr* ranges, size_t n,
  23. bool include_end) {
  24. return (static_cast_with_check<DBImpl, DB>(db->GetRootDB()))
  25. ->DeleteFilesInRanges(column_family, ranges, n, include_end);
  26. }
  27. Status VerifySstFileChecksum(const Options& options,
  28. const EnvOptions& env_options,
  29. const std::string& file_path) {
  30. return VerifySstFileChecksum(options, env_options, ReadOptions(), file_path);
  31. }
  32. Status VerifySstFileChecksum(const Options& options,
  33. const EnvOptions& env_options,
  34. const ReadOptions& read_options,
  35. const std::string& file_path) {
  36. std::unique_ptr<FSRandomAccessFile> file;
  37. uint64_t file_size;
  38. InternalKeyComparator internal_comparator(options.comparator);
  39. ImmutableCFOptions ioptions(options);
  40. Status s = ioptions.fs->NewRandomAccessFile(file_path,
  41. FileOptions(env_options),
  42. &file, nullptr);
  43. if (s.ok()) {
  44. s = ioptions.fs->GetFileSize(file_path, IOOptions(), &file_size, nullptr);
  45. } else {
  46. return s;
  47. }
  48. std::unique_ptr<TableReader> table_reader;
  49. std::unique_ptr<RandomAccessFileReader> file_reader(
  50. new RandomAccessFileReader(std::move(file), file_path));
  51. const bool kImmortal = true;
  52. s = ioptions.table_factory->NewTableReader(
  53. TableReaderOptions(ioptions, options.prefix_extractor.get(), env_options,
  54. internal_comparator, false /* skip_filters */,
  55. !kImmortal, -1 /* level */),
  56. std::move(file_reader), file_size, &table_reader,
  57. false /* prefetch_index_and_filter_in_cache */);
  58. if (!s.ok()) {
  59. return s;
  60. }
  61. s = table_reader->VerifyChecksum(read_options,
  62. TableReaderCaller::kUserVerifyChecksum);
  63. return s;
  64. }
  65. } // namespace ROCKSDB_NAMESPACE
  66. #endif // ROCKSDB_LITE