You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-16 04:01:52 +03:00
feat(FDB): [FDB BlobHandler] Add writeOrUpdateBlob
, update read
and remove
. (#3373)
This patch: 1) Adds a `writeOrUpdateBlob` function. 2) Updates `read` and `remove` to take in account the size of the `keys` and `values` for one FDB transaction.
This commit is contained in:
@ -50,6 +50,8 @@ class Transaction
|
||||
explicit Transaction(FDBTransaction* tnx);
|
||||
~Transaction();
|
||||
|
||||
// Tries to atomically (during one transaction) swap keys.
|
||||
bool swap(const ByteArray &key1, const ByteArray &key2);
|
||||
// Sets a given `key` and given `value`.
|
||||
void set(const ByteArray& key, const ByteArray& value) const;
|
||||
// Gets a `value` by the given `key`.
|
||||
@ -117,6 +119,7 @@ using Keys = std::vector<Key>;
|
||||
using KeyBlockMap = std::unordered_map<Key, Block>;
|
||||
using TreeLevelNumKeysMap = std::unordered_map<uint32_t, uint32_t>;
|
||||
|
||||
// Represents an abstract class for key generators.
|
||||
class KeyGenerator
|
||||
{
|
||||
public:
|
||||
@ -152,12 +155,37 @@ class BlobHandler
|
||||
}
|
||||
|
||||
// Writes the given `blob` with given `key`.
|
||||
// The semantic of this `write` is not atomic, it splits the data into multiple fdb transactions, if one of
|
||||
// this transaction fails, we should call `removeBlob` to clear data which were written partially, and then
|
||||
// try to `writeBlob` again.
|
||||
bool writeBlob(std::shared_ptr<FDBCS::FDBDataBase> database, const ByteArray& key, const ByteArray& blob);
|
||||
|
||||
// This function:
|
||||
// 1) Checks if blob with the same key exists if not, uses `writeBlob` function.
|
||||
// 2) Creates a new tree with a new key.
|
||||
// 3) Atomically (during one fdb transaction) swaps root nodes for the original tree and new tree.
|
||||
// 4) Removes original tree.
|
||||
bool writeOrUpdateBlob(std::shared_ptr<FDBCS::FDBDataBase> database, const ByteArray& key,
|
||||
const ByteArray& blob);
|
||||
|
||||
// Reads `blob` by the given `key`, on error returns false.
|
||||
std::pair<bool, std::string> readBlob(std::shared_ptr<FDBCS::FDBDataBase> database, const ByteArray& key);
|
||||
|
||||
// Read blocks of the data based on the given `keys` starting from `index` position in keys vector
|
||||
// and taking in account the max size of transaction.
|
||||
// If `DataBlock` reached in a tree (leaf nodes), sets `dataBlockReached` flag to true.
|
||||
std::pair<bool, std::vector<Block>> readBlocks(std::shared_ptr<FDBCS::FDBDataBase> database,
|
||||
const std::vector<ByteArray>& keys, uint32_t& index,
|
||||
bool& dataBlockReached);
|
||||
|
||||
// Removes a `blob` by the given `key`, on error returns false.
|
||||
// The semantic of this `remove` is not atomic, it splits keys to remove into multiple fdb transactions, if
|
||||
// one of this transaction fails, we should call `removeBlob` again to remove keys, which were not removed.
|
||||
bool removeBlob(std::shared_ptr<FDBCS::FDBDataBase> database, const ByteArray& key);
|
||||
|
||||
// Checks if key exis.
|
||||
bool keyExists(std::shared_ptr<FDBCS::FDBDataBase> database, const ByteArray& key);
|
||||
|
||||
private:
|
||||
size_t insertData(Block& block, const std::string& blob, const size_t offset);
|
||||
void insertKey(Block& block, const std::string& value);
|
||||
|
Reference in New Issue
Block a user