compacted_db_impl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #pragma once
  6. #include <string>
  7. #include <vector>
  8. #include "db/db_impl/db_impl.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. // TODO: Share common structure with DBImplSecondary and DBImplReadOnly
  11. class CompactedDBImpl : public DBImpl {
  12. public:
  13. CompactedDBImpl(const DBOptions& options, const std::string& dbname);
  14. // No copying allowed
  15. CompactedDBImpl(const CompactedDBImpl&) = delete;
  16. void operator=(const CompactedDBImpl&) = delete;
  17. ~CompactedDBImpl() override;
  18. static Status Open(const Options& options, const std::string& dbname,
  19. std::unique_ptr<DB>* dbptr);
  20. // Implementations of the DB interface
  21. using DB::Get;
  22. Status Get(const ReadOptions& options, ColumnFamilyHandle* column_family,
  23. const Slice& key, PinnableSlice* value,
  24. std::string* timestamp) override;
  25. using DB::MultiGet;
  26. // Note that CompactedDBImpl::MultiGet is not the optimized version of
  27. // MultiGet to use.
  28. // TODO: optimize CompactedDBImpl::MultiGet, see DBImpl::MultiGet for details.
  29. void MultiGet(const ReadOptions& options, size_t num_keys,
  30. ColumnFamilyHandle** column_families, const Slice* keys,
  31. PinnableSlice* values, std::string* timestamps,
  32. Status* statuses, const bool sorted_input) override;
  33. using DBImpl::Put;
  34. Status Put(const WriteOptions& /*options*/,
  35. ColumnFamilyHandle* /*column_family*/, const Slice& /*key*/,
  36. const Slice& /*value*/) override {
  37. return Status::NotSupported("Not supported in compacted db mode.");
  38. }
  39. using DBImpl::PutEntity;
  40. Status PutEntity(const WriteOptions& /* options */,
  41. ColumnFamilyHandle* /* column_family */,
  42. const Slice& /* key */,
  43. const WideColumns& /* columns */) override {
  44. return Status::NotSupported("Not supported in compacted db mode.");
  45. }
  46. using DBImpl::Merge;
  47. Status Merge(const WriteOptions& /*options*/,
  48. ColumnFamilyHandle* /*column_family*/, const Slice& /*key*/,
  49. const Slice& /*value*/) override {
  50. return Status::NotSupported("Not supported in compacted db mode.");
  51. }
  52. using DBImpl::Delete;
  53. Status Delete(const WriteOptions& /*options*/,
  54. ColumnFamilyHandle* /*column_family*/,
  55. const Slice& /*key*/) override {
  56. return Status::NotSupported("Not supported in compacted db mode.");
  57. }
  58. Status Write(const WriteOptions& /*options*/,
  59. WriteBatch* /*updates*/) override {
  60. return Status::NotSupported("Not supported in compacted db mode.");
  61. }
  62. using DBImpl::CompactRange;
  63. Status CompactRange(const CompactRangeOptions& /*options*/,
  64. ColumnFamilyHandle* /*column_family*/,
  65. const Slice* /*begin*/, const Slice* /*end*/) override {
  66. return Status::NotSupported("Not supported in compacted db mode.");
  67. }
  68. Status DisableFileDeletions() override {
  69. return Status::NotSupported("Not supported in compacted db mode.");
  70. }
  71. Status EnableFileDeletions() override {
  72. return Status::NotSupported("Not supported in compacted db mode.");
  73. }
  74. Status GetLiveFiles(std::vector<std::string>& ret,
  75. uint64_t* manifest_file_size,
  76. bool /*flush_memtable*/) override {
  77. return DBImpl::GetLiveFiles(ret, manifest_file_size,
  78. false /* flush_memtable */);
  79. }
  80. using DBImpl::Flush;
  81. Status Flush(const FlushOptions& /*options*/,
  82. ColumnFamilyHandle* /*column_family*/) override {
  83. return Status::NotSupported("Not supported in compacted db mode.");
  84. }
  85. Status SyncWAL() override {
  86. return Status::NotSupported("Not supported in compacted db mode.");
  87. }
  88. using DB::IngestExternalFile;
  89. Status IngestExternalFile(
  90. ColumnFamilyHandle* /*column_family*/,
  91. const std::vector<std::string>& /*external_files*/,
  92. const IngestExternalFileOptions& /*ingestion_options*/) override {
  93. return Status::NotSupported("Not supported in compacted db mode.");
  94. }
  95. using DB::CreateColumnFamilyWithImport;
  96. Status CreateColumnFamilyWithImport(
  97. const ColumnFamilyOptions& /*options*/,
  98. const std::string& /*column_family_name*/,
  99. const ImportColumnFamilyOptions& /*import_options*/,
  100. const std::vector<const ExportImportFilesMetaData*>& /*metadatas*/,
  101. ColumnFamilyHandle** /*handle*/) override {
  102. return Status::NotSupported("Not supported in compacted db mode.");
  103. }
  104. using DB::ClipColumnFamily;
  105. Status ClipColumnFamily(ColumnFamilyHandle* /*column_family*/,
  106. const Slice& /*begin*/,
  107. const Slice& /*end*/) override {
  108. return Status::NotSupported("Not supported in compacted db mode.");
  109. }
  110. // FIXME: some missing overrides for more "write" functions
  111. // Share with DBImplReadOnly?
  112. protected:
  113. Status FlushForGetLiveFiles() override {
  114. // No-op for read-only DB
  115. return Status::OK();
  116. }
  117. private:
  118. friend class DB;
  119. inline size_t FindFile(const Slice& key);
  120. Status Init(const Options& options);
  121. ColumnFamilyData* cfd_;
  122. Version* version_;
  123. const Comparator* user_comparator_;
  124. LevelFilesBrief files_;
  125. };
  126. } // namespace ROCKSDB_NAMESPACE