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 #pragma once
7 #ifndef ROCKSDB_LITE
8 #include <string>
9 #include <vector>
10 #include "db/db_impl/db_impl.h"
11 
12 namespace ROCKSDB_NAMESPACE {
13 
14 class CompactedDBImpl : public DBImpl {
15  public:
16   CompactedDBImpl(const DBOptions& options, const std::string& dbname);
17   // No copying allowed
18   CompactedDBImpl(const CompactedDBImpl&) = delete;
19   void operator=(const CompactedDBImpl&) = delete;
20 
21   ~CompactedDBImpl() override;
22 
23   static Status Open(const Options& options, const std::string& dbname,
24                      DB** dbptr);
25 
26   // Implementations of the DB interface
27   using DB::Get;
28   virtual Status Get(const ReadOptions& options,
29                      ColumnFamilyHandle* column_family, const Slice& key,
30                      PinnableSlice* value) override;
31   using DB::MultiGet;
32   virtual std::vector<Status> MultiGet(
33       const ReadOptions& options,
34       const std::vector<ColumnFamilyHandle*>&,
35       const std::vector<Slice>& keys, std::vector<std::string>* values)
36     override;
37 
38   using DBImpl::Put;
Put(const WriteOptions &,ColumnFamilyHandle *,const Slice &,const Slice &)39   virtual Status Put(const WriteOptions& /*options*/,
40                      ColumnFamilyHandle* /*column_family*/,
41                      const Slice& /*key*/, const Slice& /*value*/) override {
42     return Status::NotSupported("Not supported in compacted db mode.");
43   }
44   using DBImpl::Merge;
Merge(const WriteOptions &,ColumnFamilyHandle *,const Slice &,const Slice &)45   virtual Status Merge(const WriteOptions& /*options*/,
46                        ColumnFamilyHandle* /*column_family*/,
47                        const Slice& /*key*/, const Slice& /*value*/) override {
48     return Status::NotSupported("Not supported in compacted db mode.");
49   }
50   using DBImpl::Delete;
Delete(const WriteOptions &,ColumnFamilyHandle *,const Slice &)51   virtual Status Delete(const WriteOptions& /*options*/,
52                         ColumnFamilyHandle* /*column_family*/,
53                         const Slice& /*key*/) override {
54     return Status::NotSupported("Not supported in compacted db mode.");
55   }
Write(const WriteOptions &,WriteBatch *)56   virtual Status Write(const WriteOptions& /*options*/,
57                        WriteBatch* /*updates*/) override {
58     return Status::NotSupported("Not supported in compacted db mode.");
59   }
60   using DBImpl::CompactRange;
CompactRange(const CompactRangeOptions &,ColumnFamilyHandle *,const Slice *,const Slice *)61   virtual Status CompactRange(const CompactRangeOptions& /*options*/,
62                               ColumnFamilyHandle* /*column_family*/,
63                               const Slice* /*begin*/,
64                               const Slice* /*end*/) override {
65     return Status::NotSupported("Not supported in compacted db mode.");
66   }
67 
DisableFileDeletions()68   virtual Status DisableFileDeletions() override {
69     return Status::NotSupported("Not supported in compacted db mode.");
70   }
EnableFileDeletions(bool)71   virtual Status EnableFileDeletions(bool /*force*/) override {
72     return Status::NotSupported("Not supported in compacted db mode.");
73   }
GetLiveFiles(std::vector<std::string> & ret,uint64_t * manifest_file_size,bool)74   virtual 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;
Flush(const FlushOptions &,ColumnFamilyHandle *)81   virtual Status Flush(const FlushOptions& /*options*/,
82                        ColumnFamilyHandle* /*column_family*/) override {
83     return Status::NotSupported("Not supported in compacted db mode.");
84   }
85 
SyncWAL()86   virtual Status SyncWAL() override {
87     return Status::NotSupported("Not supported in compacted db mode.");
88   }
89 
90   using DB::IngestExternalFile;
IngestExternalFile(ColumnFamilyHandle *,const std::vector<std::string> &,const IngestExternalFileOptions &)91   virtual Status IngestExternalFile(
92       ColumnFamilyHandle* /*column_family*/,
93       const std::vector<std::string>& /*external_files*/,
94       const IngestExternalFileOptions& /*ingestion_options*/) override {
95     return Status::NotSupported("Not supported in compacted db mode.");
96   }
97   using DB::CreateColumnFamilyWithImport;
CreateColumnFamilyWithImport(const ColumnFamilyOptions &,const std::string &,const ImportColumnFamilyOptions &,const ExportImportFilesMetaData &,ColumnFamilyHandle **)98   virtual Status CreateColumnFamilyWithImport(
99       const ColumnFamilyOptions& /*options*/,
100       const std::string& /*column_family_name*/,
101       const ImportColumnFamilyOptions& /*import_options*/,
102       const ExportImportFilesMetaData& /*metadata*/,
103       ColumnFamilyHandle** /*handle*/) override {
104     return Status::NotSupported("Not supported in compacted db mode.");
105   }
106 
107  private:
108   friend class DB;
109   inline size_t FindFile(const Slice& key);
110   Status Init(const Options& options);
111 
112   ColumnFamilyData* cfd_;
113   Version* version_;
114   const Comparator* user_comparator_;
115   LevelFilesBrief files_;
116 };
117 }  // namespace ROCKSDB_NAMESPACE
118 #endif  // ROCKSDB_LITE
119