-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathDbMetadataStorage.hpp
More file actions
83 lines (69 loc) · 3.14 KB
/
DbMetadataStorage.hpp
File metadata and controls
83 lines (69 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Concord
//
// Copyright (c) 2019 VMware, Inc. All Rights Reserved.
//
// This product is licensed to you under the Apache 2.0 license (the
// "License"). You may not use this product except in compliance with the
// Apache 2.0 License.
//
// This product may include a number of subcomponents with separate copyright
// notices and license terms. Your use of these subcomponents is subject to the
// terms and conditions of the subcomponent's license, as noted in the LICENSE
// file.
#pragma once
#include <mutex>
#include <map>
#include <memory>
#include "log/logger.hpp"
#include "bftengine/MetadataStorage.hpp"
#include "storage/db_interface.hpp"
#include "storage/key_manipulator_interface.hpp"
#include "util/sliver.hpp"
namespace concord {
namespace storage {
typedef std::vector<uint32_t> ObjectIdsVector;
typedef std::map<uint32_t, size_t> ObjectIdToSizeMap;
using ObjectId = std::uint32_t;
class DBMetadataStorage : public bftEngine::MetadataStorage {
public:
explicit DBMetadataStorage(IDBClient *dbClient, std::unique_ptr<IMetadataKeyManipulator> metadataKeyManipulator)
: logger_(logging::getLogger("concord.storage.metadata-storage")),
dbClient_(dbClient),
metadataKeyManipulator_(std::move(metadataKeyManipulator)) {
objectIdToSizeMap_[objectsNumParameterId_] = sizeof(objectsNum_);
}
bool initMaxSizeOfObjects(const std::map<uint32_t, ObjectDesc> &metadataObjectsArray,
uint32_t metadataObjectsArrayLength) override;
void read(uint32_t objectId, uint32_t bufferSize, char *outBufferForObject, uint32_t &outActualObjectSize) override;
void atomicWrite(uint32_t objectId, const char *data, uint32_t dataLength) override;
void atomicWriteArbitraryObject(const std::string &key, const char *data, uint32_t dataLength) override;
void beginAtomicWriteOnlyBatch() override;
void writeInBatch(uint32_t objectId, const char *data, uint32_t dataLength) override;
void commitAtomicWriteOnlyBatch(bool sync = false) override;
concordUtils::Status multiDel(const ObjectIdsVector &objectIds);
bool isNewStorage() override;
void eraseData() override;
protected:
void verifyOperation(uint32_t objectId, uint32_t dataLen, const char *buffer, bool writeOperation) const;
void cleanDB();
protected:
const char *WRONG_FLOW = "beginAtomicWriteOnlyBatch should be launched first";
const char *WRONG_PARAMETER = "Wrong parameter value specified";
const uint8_t objectsNumParameterId_ = 1;
logging::Logger logger_;
IDBClient *dbClient_ = nullptr;
SetOfKeyValuePairs *batch_ = nullptr;
std::mutex ioMutex_;
ObjectIdToSizeMap objectIdToSizeMap_;
uint32_t objectsNum_ = 0;
std::unique_ptr<IMetadataKeyManipulator> metadataKeyManipulator_;
};
class DBMetadataStorageUnbounded : public DBMetadataStorage {
public:
explicit DBMetadataStorageUnbounded(IDBClient *dbClient,
std::unique_ptr<IMetadataKeyManipulator> metadataKeyManipulator)
: DBMetadataStorage(dbClient, std::move(metadataKeyManipulator)) {}
void atomicWriteArbitraryObject(const std::string &key, const char *data, uint32_t dataLength) override;
};
} // namespace storage
} // namespace concord