16#include "common/lang/filesystem.h"
17#include "common/lang/string_view.h"
18#include "common/log/log.h"
19#include "common/sys/rc.h"
20#include "oblsm/ob_lsm_define.h"
21#include "oblsm/util/ob_file_writer.h"
22#include "oblsm/util/ob_file_reader.h"
63 RC rc = t.from_json(v);
77inline Json::Value JsonConverter::to_json<CompactionType>(
const CompactionType &type)
79 int type_as_int =
static_cast<int>(type);
80 Json::Value res{type_as_int};
94inline RC JsonConverter::from_json<CompactionType>(
const Json::Value &v, CompactionType &type)
98 type_as_int = v.asInt();
100 return RC::INVALID_ARGUMENT;
103 type =
static_cast<CompactionType
>(type_as_int);
172 static string record_type() {
return "ObManifestCompaction"; }
209 static string record_type() {
return "ObManifestSnapshot"; }
244 static string record_type() {
return "ObManifestNewMemtable"; }
295 template <
typename T>
298 static_assert(std::is_same<T, ObManifestCompaction>::value || std::is_same<T, ObManifestSnapshot>::value ||
299 std::is_same<T, ObManifestNewMemtable>::value,
300 "push() only supports ObManifestCompaction ,ObManifestNewMemtable and ObManifestSnapshot types.");
302 string str = json.toStyledString();
303 size_t len = str.size();
304 RC rc =
writer_->write(string_view{
reinterpret_cast<char *
>(&len),
sizeof(len)});
306 LOG_WARN(
"Failed to push record into manifest file %s, rc %s",
writer_->file_name().c_str(), strrc(rc));
311 LOG_WARN(
"Failed to push record into manifest file %s, rc %s",
writer_->file_name().c_str(), strrc(rc));
316 LOG_WARN(
"Failed to flush data of manifest file %s, rc %s",
writer_->file_name().c_str(), strrc(rc));
339 RC
recover(std::unique_ptr<ObManifestSnapshot> &snapshot_record,
340 std::unique_ptr<ObManifestNewMemtable> &memtbale_record, std::vector<ObManifestCompaction> &compactions);
344 friend class ObManifestTester;
356 return filesystem::path(path) / (std::to_string(mf_seq) + MANIFEST_SUFFIX);
A utility class to convert between JSON and user-defined types.
Definition: ob_manifest.h:33
static Json::Value to_json(const T &t)
Converts an object of type T to a JSON value.
Definition: ob_manifest.h:45
static RC from_json(const Json::Value &v, T &t)
Converts a JSON value to an object of type T.
Definition: ob_manifest.h:61
Represents a record in the manifest, used for compaction operations.
Definition: ob_manifest.h:164
uint64_t seq_id
Sequence ID for the record.
Definition: ob_manifest.h:170
Json::Value to_json() const
Converts the ObManifestCompaction to a JSON value.
Definition: ob_manifest.cpp:36
CompactionType compaction_type
The type of compaction (e.g., level)
Definition: ob_manifest.h:166
uint64_t sstable_sequence_id
Sequence ID for SSTables.
Definition: ob_manifest.h:169
std::vector< ObManifestSSTableInfo > added_tables
List of added SSTables.
Definition: ob_manifest.h:168
std::vector< ObManifestSSTableInfo > deleted_tables
List of deleted SSTables.
Definition: ob_manifest.h:167
RC from_json(const Json::Value &v)
Populates the ObManifestCompaction object from a JSON value.
Definition: ob_manifest.cpp:59
Represents a new memtable of ObLsm.
Definition: ob_manifest.h:239
Json::Value to_json() const
Converts the ObManifestNewMemtable to a JSON value.
Definition: ob_manifest.cpp:158
uint64_t memtable_id
The id of memtable and it is used to find the WAL file of memtable.(e.g., memtable=1,...
Definition: ob_manifest.h:241
RC from_json(const Json::Value &v)
Populates the ObManifestNewMemtable object from a JSON value.
Definition: ob_manifest.cpp:166
Represents a snapshot of the manifest.
Definition: ob_manifest.h:202
Json::Value to_json() const
Converts the ObManifestSnapshot to a JSON value.
Definition: ob_manifest.cpp:118
RC from_json(const Json::Value &v)
Populates the ObManifestSnapshot object from a JSON value.
Definition: ob_manifest.cpp:139
uint64_t sstable_id
The ID of the SSTable.
Definition: ob_manifest.h:206
CompactionType compaction_type
The type of compaction.
Definition: ob_manifest.h:207
std::vector< std::vector< uint64_t > > sstables
A list of SSTable IDs grouped by levels.
Definition: ob_manifest.h:204
uint64_t seq
The sequence ID for the snapshot.
Definition: ob_manifest.h:205
A class that manages the manifest file, including reading and writing records and snapshots.
Definition: ob_manifest.h:271
RC push(const T &data)
Pushes a record or snapshot to the writer.
Definition: ob_manifest.h:296
std::unique_ptr< ObFileWriter > writer_
The file writer for manifest data.
Definition: ob_manifest.h:364
RC redirect(const ObManifestSnapshot &snapshot, const ObManifestNewMemtable &memtable)
Redirects to a new manifest file.
Definition: ob_manifest.cpp:303
uint64_t mf_seq_
The sequence ID of the current manifest file.
Definition: ob_manifest.h:362
ObManifest(const std::string &path)
Constructs an ObManifest object with the specified path.
Definition: ob_manifest.h:277
RC open()
Opens the manifest file and initializes the reader and writer.
Definition: ob_manifest.cpp:175
RC recover(std::unique_ptr< ObManifestSnapshot > &snapshot_record, std::unique_ptr< ObManifestNewMemtable > &memtbale_record, std::vector< ObManifestCompaction > &compactions)
Redirects to a new manifest file.
Definition: ob_manifest.cpp:239
filesystem::path path_
The directory path where manifest files are stored.
Definition: ob_manifest.h:360
uint64_t latest_seq
The latest sequence number persisted in the LSM.
Definition: ob_manifest.h:342
std::unique_ptr< ObFileReader > reader_
The file reader for manifest data.
Definition: ob_manifest.h:365
string get_manifest_file_path(string path, uint64_t mf_seq)
Constructs the path to the manifest file.
Definition: ob_manifest.h:354
filesystem::path current_path_
The path to the CURRENT file that tracks the latest manifest file.
Definition: ob_manifest.h:361
Struct representing SSTable information in a manifest.
Definition: ob_manifest.h:113
RC from_json(const Json::Value &v)
Populates the ObManifestSSTableInfo object from a JSON value.
Definition: ob_manifest.cpp:20
int sstable_id
The ID of the SSTable.
Definition: ob_manifest.h:114
Json::Value to_json() const
Converts the ObManifestSSTableInfo object to a JSON value.
Definition: ob_manifest.h:141
ObManifestSSTableInfo()
Definition: ob_manifest.h:126
ObManifestSSTableInfo(int sstable_id_, int level_)
Constructor to initialize with given SSTable ID and level.
Definition: ob_manifest.h:123
bool operator==(const ObManifestSSTableInfo &rhs) const
Equality operator for comparing two ObManifestSSTableInfo objects.
Definition: ob_manifest.h:134
int level
The level of the SSTable.
Definition: ob_manifest.h:115