LeviLamina
Loading...
Searching...
No Matches
DBStorage.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/common/CompactionStatus.h"
7#include "mc/deps/core/file/LevelStorageResult.h"
8#include "mc/deps/core/file/PathBuffer.h"
9#include "mc/deps/core/threading/Async.h"
10#include "mc/deps/core/utility/NonOwnerPointer.h"
11#include "mc/platform/brstd/flat_set.h"
12#include "mc/world/level/storage/DBStoragePerformanceTelemetry.h"
13#include "mc/world/level/storage/LevelStorage.h"
14#include "mc/world/level/storage/LevelStorageWriteBatch.h"
15#include "mc/world/level/storage/StorageVersion.h"
16#include "mc/world/level/storage/db_helpers/Category.h"
17
18// auto generated forward declare list
19// clang-format off
20class ChunkSource;
21class CompoundTag;
22class ContentIdentity;
23class DBChunkStorage;
26class LevelData;
27class LevelDbEnv;
31class TaskGroup;
32class TaskResult;
33struct DBStorageConfig;
35namespace Core { class Path; }
36// clang-format on
37
38class DBStorage : public ::LevelStorage {
39public:
40 // DBStorage inner types declare
41 // clang-format off
42 struct CommitOperation;
43 class DBStorageToken;
44 class Options;
45 struct PendingWriteResult;
46 // clang-format on
47
48 // DBStorage inner types define
50 public:
51 // member variables
52 // NOLINTBEGIN
53 ::ll::TypedStorage<8, 32, ::std::string> mKey;
54 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::std::string>> mValue;
55 ::ll::TypedStorage<4, 4, ::DBHelpers::Category> mCategory;
56 ::ll::TypedStorage<1, 1, bool> mIsDelete;
57 // NOLINTEND
58 };
59
61 public:
62 // member variables
63 // NOLINTBEGIN
64 ::ll::TypedStorage<8, 8, ::std::atomic<int>*> mRefCounter;
65 // NOLINTEND
66 };
67
68 class Options {
69 public:
70 // member variables
71 // NOLINTBEGIN
72 ::ll::TypedStorage<8, 112, ::leveldb::Options> options;
73 ::ll::TypedStorage<8, 24, ::leveldb::ReadOptions> read;
74 ::ll::TypedStorage<1, 1, ::leveldb::WriteOptions> write;
75 // NOLINTEND
76 };
77
79 public:
80 // member variables
81 // NOLINTBEGIN
82 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::std::string const>> mLatestValue;
83 ::ll::TypedStorage<1, 1, bool> mIsDeleted;
84 // NOLINTEND
85 };
86
87public:
88 // member variables
89 // NOLINTBEGIN
90 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::DBStorageEnvironmentChain>> mEnvChain;
91 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::Cache>> mCache;
92 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::FilterPolicy const>> mFilterPolicy;
93 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::DBStorage::Options>> mOptions;
94 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::DecompressAllocator>> mDecompressAllocator;
95 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::DB>> mDb;
96 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::TaskGroup>> mIOTaskGroup;
97 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::TaskGroup>> mCompactionTaskGroup;
98 ::ll::TypedStorage<8, 16, ::Bedrock::Threading::Async<void>> mCompactionTask;
99 ::ll::TypedStorage<8, 16, ::Bedrock::Threading::Async<void>> mWriteTask;
100 ::ll::TypedStorage<8, 40, ::Core::LevelStorageResult> mState;
101 ::ll::TypedStorage<8, 8, ::ContentIdentity const*> mContentIdentity;
102 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mFullPath;
103 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDbPath;
104 ::ll::TypedStorage<8, 32, ::std::string> mLevelId;
105 ::ll::TypedStorage<8, 80, ::std::mutex> mCompactionMutex;
106 ::ll::TypedStorage<8, 8, ::std::shared_mutex> mWriteCacheMutex;
107 ::ll::TypedStorage<8, 80, ::std::mutex> mCacheFlushMutex;
108 ::ll::TypedStorage<8, 8, ::std::chrono::steady_clock::time_point> mLastCompactionStartTime;
109 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds> mCompactionInterval;
110 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds> mWriteFlushInterval;
111 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mAllowFlush;
112 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mSavingInProgress;
113 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mSnapshotInProgress;
114 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mShutdownStarted;
115 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mNoMoreWrites;
116 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mShutdownDone;
117 ::ll::TypedStorage<4, 4, ::std::atomic<int>> mOutstandingJobs;
118 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::SaveTransactionManager>> mSaveTransactionManager;
119 ::ll::TypedStorage<8, 64, ::std::function<void()>> mCriticalSyncSaveCallback;
120 ::ll::TypedStorage<8, 64, ::std::function<void(::CompactionStatus)>> mExternallyRegisteredCompactionCallback;
121 ::ll::TypedStorage<
122 8,
123 24,
125 mChunkStorages;
126 ::ll::TypedStorage<8, 24, ::std::vector<::std::unique_ptr<::LevelStorageObserver>>> mObservers;
127 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mDestructorInProgress;
128 ::ll::TypedStorage<1, 1, bool> mForceCorrupt;
129 ::ll::TypedStorage<1, 1, bool const> mStorageEnabled;
130 ::ll::TypedStorage<1, 1, bool const> mJigsawPersistenceToggle;
131 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDbSubfolder;
132 ::ll::TypedStorage<8, 128, ::LevelStorageWriteBatch> mSingleKeyWrites;
133 ::ll::TypedStorage<8, 24, ::std::vector<::LevelStorageWriteBatch>> mBatchWrites;
134 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::LevelStorageEventing>> mEventing;
135 ::ll::TypedStorage<8, 24, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv>> mLevelDbEnv;
136 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::DBStorageFolderWatcher>>> mFolderTelemetryWatcher;
137 ::ll::TypedStorage<8, 8, ::std::chrono::steady_clock::time_point> mNextSizeTelemetryCaptureTime;
138 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds const> mSizeTelemetryCaptureInterval;
139 ::ll::TypedStorage<8, 192, ::DBStoragePerformanceTelemetry> mDBStoragePerformanceTelemetry;
140 // NOLINTEND
141
142public:
143 // prevent constructor by default
144 DBStorage();
145
146public:
147 // virtual functions
148 // NOLINTBEGIN
149 virtual ~DBStorage() /*override*/ = default;
150
151 virtual void addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer) /*override*/;
152
153 virtual bool loadedSuccessfully() const /*override*/;
154
155 virtual ::Core::LevelStorageResult getState() const /*override*/;
156
157 virtual ::std::unique_ptr<::ChunkSource>
158 createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion) /*override*/;
159
160 virtual ::Core::PathBuffer<::std::string> const& getFullPath() const /*override*/;
161
162 virtual ::std::unique_ptr<::CompoundTag>
163 getCompoundTag(::std::string const& key, ::DBHelpers::Category category) /*override*/;
164
165 virtual bool hasKey(::std::string_view key, ::DBHelpers::Category category) const /*override*/;
166
167 virtual bool loadLevelData(::LevelData& data) /*override*/;
168
169 virtual void saveLevelData(::LevelData const& levelData) /*override*/;
170
171 virtual ::Bedrock::Threading::Async<void>
172 saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category) /*override*/;
173
174 virtual ::Bedrock::Threading::Async<void> saveData(::LevelStorageWriteBatch const& batch) /*override*/;
175
176 virtual ::Bedrock::Threading::Async<void>
177 deleteData(::std::string const& key, ::DBHelpers::Category category) /*override*/;
178
179 virtual bool loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const
180 /*override*/;
181
182 virtual void forEachKeyWithPrefix(
183 ::std::string_view prefix,
184 ::DBHelpers::Category category,
185 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
186 ) const /*override*/;
187
188 virtual ::Core::LevelStorageResult getLevelStorageState() const /*override*/;
189
190 virtual ::ContentIdentity const* getContentIdentity() const /*override*/;
191
192 virtual void startShutdown() /*override*/;
193
194 virtual bool isShuttingDown() const /*override*/;
195
196 virtual bool checkShutdownDone() /*override*/;
197
198 virtual void getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const /*override*/;
199
200 virtual ::std::vector<::SnapshotFilenameAndLength>
201 createSnapshot(::std::string const& filePrefix, bool flushWriteCache) /*override*/;
202
203 virtual void releaseSnapshot() /*override*/;
204
205 virtual ::Bedrock::Threading::Async<void> compactStorage() /*override*/;
206
207 virtual void syncAndSuspendStorage() /*override*/;
208
209 virtual void resumeStorage() /*override*/;
210
211 virtual void setFlushAllowed(bool flushAllowed) /*override*/;
212
213 virtual void flushToPermanentStorage() /*override*/;
214
215 virtual void freeCaches() /*override*/;
216
217 virtual void setCompactionCallback(::std::function<void(::CompactionStatus)> callback) /*override*/;
218
219 virtual void setCriticalSyncSaveCallback(::std::function<void()> callback) /*override*/;
220 // NOLINTEND
221
222public:
223 // member functions
224 // NOLINTBEGIN
225 MCAPI DBStorage(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
226
227 MCAPI ::TaskResult _flushWriteCacheToLevelDB();
228
229 MCAPI ::std::string _getTelemetryMessage(::leveldb::Status const& status) const;
230
231 MCAPI ::DBStorage::PendingWriteResult
232 _readPendingWrite(::std::string const& key, ::DBHelpers::Category category) const;
233
234 MCAPI bool tryRepair(::Core::Path const& path) const;
235 // NOLINTEND
236
237public:
238 // constructor thunks
239 // NOLINTBEGIN
240 MCAPI void* $ctor(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
241 // NOLINTEND
242
243public:
244 // virtual function thunks
245 // NOLINTBEGIN
246 MCAPI void $addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer);
247
248 MCFOLD bool $loadedSuccessfully() const;
249
250 MCAPI ::Core::LevelStorageResult $getState() const;
251
252 MCAPI ::std::unique_ptr<::ChunkSource>
253 $createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion);
254
255 MCAPI ::Core::PathBuffer<::std::string> const& $getFullPath() const;
256
257 MCAPI ::std::unique_ptr<::CompoundTag> $getCompoundTag(::std::string const& key, ::DBHelpers::Category category);
258
259 MCAPI bool $hasKey(::std::string_view key, ::DBHelpers::Category category) const;
260
261 MCAPI bool $loadLevelData(::LevelData& data);
262
263 MCAPI void $saveLevelData(::LevelData const& levelData);
264
265 MCAPI ::Bedrock::Threading::Async<void>
266 $saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category);
267
268 MCAPI ::Bedrock::Threading::Async<void> $saveData(::LevelStorageWriteBatch const& batch);
269
270 MCAPI ::Bedrock::Threading::Async<void> $deleteData(::std::string const& key, ::DBHelpers::Category category);
271
272 MCAPI bool $loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const;
273
274 MCAPI void $forEachKeyWithPrefix(
275 ::std::string_view prefix,
276 ::DBHelpers::Category category,
277 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
278 ) const;
279
280 MCAPI ::Core::LevelStorageResult $getLevelStorageState() const;
281
282 MCFOLD ::ContentIdentity const* $getContentIdentity() const;
283
284 MCAPI void $startShutdown();
285
286 MCAPI bool $isShuttingDown() const;
287
288 MCAPI bool $checkShutdownDone();
289
290 MCAPI void $getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const;
291
292 MCAPI ::std::vector<::SnapshotFilenameAndLength>
293 $createSnapshot(::std::string const& filePrefix, bool flushWriteCache);
294
295 MCAPI void $releaseSnapshot();
296
297 MCAPI ::Bedrock::Threading::Async<void> $compactStorage();
298
299 MCAPI void $syncAndSuspendStorage();
300
301 MCAPI void $resumeStorage();
302
303 MCAPI void $setFlushAllowed(bool flushAllowed);
304
305 MCAPI void $flushToPermanentStorage();
306
307 MCAPI void $freeCaches();
308
309 MCAPI void $setCompactionCallback(::std::function<void(::CompactionStatus)> callback);
310
311 MCAPI void $setCriticalSyncSaveCallback(::std::function<void()> callback);
312
313
314 // NOLINTEND
315};
Definition ChunkSource.h:36
Definition CompoundTag.h:18
Definition ContentIdentity.h:8
Definition Path.h:11
Definition DBChunkStorage.h:34
Definition DBStorageEnvironmentChain.h:20
Definition DBStorageFolderWatcher.h:16
Definition DBStorage.h:60
Definition DBStorage.h:68
Definition LevelData.h:55
Definition LevelDbEnv.h:8
Definition LevelStorageEventing.h:16
Definition LevelStorageObserver.h:5
Definition LevelStorageWriteBatch.h:13
Definition LevelStorage.h:25
Definition Path.h:16
Definition SaveTransactionManager.h:14
Definition TaskGroup.h:86
Definition TaskResult.h:5
Definition flat_set.h:10
STL namespace.
Definition DBStorageConfig.h:21
Definition DBStorage.h:49
Definition DBStorage.h:78
Definition SnapshotFilenameAndLength.h:5
Definition buffer.h:5