-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(tiering): Decoders #5883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dranikpg
wants to merge
1
commit into
dragonflydb:main
Choose a base branch
from
dranikpg:tiering-decoders
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+201
−75
Open
feat(tiering): Decoders #5883
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2025, DragonflyDB authors. All rights reserved. | ||
// See LICENSE for licensing terms. | ||
// | ||
|
||
#include "server/tiering/decoders.h" | ||
|
||
namespace dfly::tiering { | ||
|
||
std::unique_ptr<Decoder> BareDecoder::Clone() const { | ||
return std::make_unique<BareDecoder>(); | ||
} | ||
|
||
void BareDecoder::Initialize(std::string_view slice) { | ||
this->slice = slice; | ||
} | ||
|
||
void BareDecoder::Upload(CompactObj* obj) { | ||
ABSL_UNREACHABLE(); | ||
} | ||
|
||
StringDecoder::StringDecoder(const CompactObj& obj) : StringDecoder{obj.GetStrEncoding()} { | ||
} | ||
|
||
StringDecoder::StringDecoder(CompactObj::StrEncoding encoding) : encoding_{encoding} { | ||
} | ||
|
||
std::unique_ptr<Decoder> StringDecoder::Clone() const { | ||
return std::unique_ptr<StringDecoder>{new StringDecoder(encoding_)}; | ||
} | ||
|
||
void StringDecoder::Initialize(std::string_view slice) { | ||
slice_ = slice; | ||
value_ = encoding_.Decode(slice); | ||
estimated_mem_usage = slice.length(); // will be encoded back | ||
} | ||
|
||
void StringDecoder::Upload(CompactObj* obj) { | ||
if (modified) | ||
obj->Materialize(value_.view(), false); | ||
else | ||
obj->Materialize(slice_, true); | ||
} | ||
|
||
std::string_view StringDecoder::Read() const { | ||
return value_.view(); | ||
} | ||
|
||
std::string* StringDecoder::Write() { | ||
modified = true; | ||
return value_.BorrowMut(); | ||
} | ||
|
||
} // namespace dfly::tiering |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2025, DragonflyDB authors. All rights reserved. | ||
// See LICENSE for licensing terms. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include "core/compact_object.h" | ||
#include "core/string_or_view.h" | ||
|
||
namespace dfly::tiering { | ||
|
||
// Decodes serialized value and provides it to callbacks. | ||
// Acts as generic interface to callback driver (OpManager) | ||
struct Decoder { | ||
virtual ~Decoder() = default; | ||
|
||
// Poor man's type-erasure copy | ||
virtual std::unique_ptr<Decoder> Clone() const = 0; | ||
|
||
// Initialize decoder from slice | ||
virtual void Initialize(std::string_view slice) = 0; | ||
|
||
// Store value in compact object | ||
virtual void Upload(CompactObj* obj) = 0; | ||
|
||
bool modified = false; // Must be set if modified (not equal to original slice) | ||
size_t estimated_mem_usage = 0; // Estimated usage if uploaded | ||
}; | ||
|
||
struct BareDecoder : public Decoder { | ||
std::unique_ptr<Decoder> Clone() const override; | ||
void Initialize(std::string_view slice) override; | ||
void Upload(CompactObj* obj) override; | ||
|
||
std::string_view slice; | ||
}; | ||
|
||
struct StringDecoder : public Decoder { | ||
explicit StringDecoder(const CompactObj& obj); | ||
|
||
std::unique_ptr<Decoder> Clone() const override; | ||
void Initialize(std::string_view slice) override; | ||
void Upload(CompactObj* obj) override; | ||
|
||
std::string_view Read() const; | ||
std::string* Write(); | ||
|
||
private: | ||
explicit StringDecoder(CompactObj::StrEncoding encoding); | ||
|
||
std::string_view slice_; | ||
CompactObj::StrEncoding encoding_; | ||
dfly::StringOrView value_; | ||
}; | ||
|
||
} // namespace dfly::tiering |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.