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/platform/brstd/move_only_function.h"
13#include "mc/platform/threading/Mutex.h"
14#include "mc/world/level/storage/DBStoragePerformanceTelemetry.h"
15#include "mc/world/level/storage/LevelStorage.h"
16#include "mc/world/level/storage/LevelStorageWriteBatch.h"
17#include "mc/world/level/storage/StorageVersion.h"
18#include "mc/world/level/storage/db_helpers/Category.h"
19
20// auto generated forward declare list
21// clang-format off
22class ChunkSource;
23class CompoundTag;
24class ContentIdentity;
25class DBChunkStorage;
28class LevelData;
29class LevelDbEnv;
33class TaskGroup;
34class TaskResult;
35struct DBStorageConfig;
37namespace Core { class Path; }
38// clang-format on
39
40class DBStorage : public ::LevelStorage {
41public:
42 // DBStorage inner types declare
43 // clang-format off
44 struct CommitOperation;
45 class DBStorageToken;
46 class Options;
47 struct PendingWriteResult;
48 // clang-format on
49
50 // DBStorage inner types define
51 struct CommitOperation {
52 public:
53 // member variables
54 // NOLINTBEGIN
55 ::ll::TypedStorage<8, 32, ::std::string> mKey;
56 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::std::string>> mValue;
57 ::ll::TypedStorage<4, 4, ::DBHelpers::Category> mCategory;
58 ::ll::TypedStorage<1, 1, bool> mIsDelete;
59 // NOLINTEND
60
61 public:
62 // prevent constructor by default
63 CommitOperation();
64
65 public:
66 // member functions
67 // NOLINTBEGIN
69 ::std::string const& key,
70 ::std::shared_ptr<::std::string> value,
71 bool isDelete,
72 ::DBHelpers::Category category
73 );
74
76 // NOLINTEND
77
78 public:
79 // constructor thunks
80 // NOLINTBEGIN
81 MCNAPI void* $ctor(
82 ::std::string const& key,
83 ::std::shared_ptr<::std::string> value,
84 bool isDelete,
85 ::DBHelpers::Category category
86 );
87 // NOLINTEND
88
89 public:
90 // destructor thunk
91 // NOLINTBEGIN
92 MCNAPI void $dtor();
93 // NOLINTEND
94 };
95
97 public:
98 // member variables
99 // NOLINTBEGIN
100 ::ll::TypedStorage<8, 8, ::std::atomic<int>*> mRefCounter;
101 // NOLINTEND
102 };
103
104 class Options {
105 public:
106 // member variables
107 // NOLINTBEGIN
108 ::ll::TypedStorage<8, 112, ::leveldb::Options> options;
109 ::ll::TypedStorage<8, 24, ::leveldb::ReadOptions> read;
110 ::ll::TypedStorage<1, 1, ::leveldb::WriteOptions> write;
111 // NOLINTEND
112 };
113
115 public:
116 // member variables
117 // NOLINTBEGIN
118 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::std::string const>> mLatestValue;
119 ::ll::TypedStorage<1, 1, bool> mIsDeleted;
120 // NOLINTEND
121
122 public:
123 // member functions
124 // NOLINTBEGIN
126 // NOLINTEND
127
128 public:
129 // destructor thunk
130 // NOLINTBEGIN
131 MCNAPI void $dtor();
132 // NOLINTEND
133 };
134
135public:
136 // member variables
137 // NOLINTBEGIN
138 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::DBStorageEnvironmentChain>> mEnvChain;
139 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::Cache>> mCache;
140 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::FilterPolicy const>> mFilterPolicy;
141 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::DBStorage::Options>> mOptions;
142 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::DecompressAllocator>> mDecompressAllocator;
143 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::DB>> mDb;
144 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::TaskGroup>> mIOTaskGroup;
145 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::TaskGroup>> mCompactionTaskGroup;
146 ::ll::TypedStorage<8, 16, ::Bedrock::Threading::Async<void>> mCompactionTask;
147 ::ll::TypedStorage<8, 16, ::Bedrock::Threading::Async<void>> mWriteTask;
148 ::ll::TypedStorage<8, 40, ::Core::LevelStorageResult> mState;
149 ::ll::TypedStorage<8, 8, ::ContentIdentity const*> mContentIdentity;
150 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mFullPath;
151 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDbPath;
152 ::ll::TypedStorage<8, 32, ::std::string> mLevelId;
153 ::ll::TypedStorage<8, 80, ::Bedrock::Threading::Mutex> mCompactionMutex;
154 ::ll::TypedStorage<8, 8, ::std::shared_mutex> mWriteCacheMutex;
155 ::ll::TypedStorage<8, 80, ::Bedrock::Threading::Mutex> mCacheFlushMutex;
156 ::ll::TypedStorage<8, 8, ::std::chrono::steady_clock::time_point> mLastCompactionStartTime;
157 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds> mCompactionInterval;
158 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds> mWriteFlushInterval;
159 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mAllowFlush;
160 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mSavingInProgress;
161 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mSnapshotInProgress;
162 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mShutdownStarted;
163 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mNoMoreWrites;
164 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mShutdownDone;
165 ::ll::TypedStorage<4, 4, ::std::atomic<int>> mOutstandingJobs;
166 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::SaveTransactionManager>> mSaveTransactionManager;
167 ::ll::TypedStorage<8, 64, ::std::function<void()>> mCriticalSyncSaveCallback;
168 ::ll::TypedStorage<8, 64, ::std::function<void(::CompactionStatus)>> mExternallyRegisteredCompactionCallback;
169 ::ll::TypedStorage<
170 8,
171 24,
173 mChunkStorages;
174 ::ll::TypedStorage<8, 24, ::std::vector<::std::unique_ptr<::LevelStorageObserver>>> mObservers;
175 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mDestructorInProgress;
176 ::ll::TypedStorage<1, 1, bool> mForceCorrupt;
177 ::ll::TypedStorage<1, 1, bool const> mStorageEnabled;
178 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDbSubfolder;
179 ::ll::TypedStorage<8, 128, ::LevelStorageWriteBatch> mSingleKeyWrites;
180 ::ll::TypedStorage<8, 24, ::std::vector<::LevelStorageWriteBatch>> mBatchWrites;
181 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::LevelStorageEventing>> mEventing;
182 ::ll::TypedStorage<8, 24, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv>> mLevelDbEnv;
183 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::DBStorageFolderWatcher>>> mFolderTelemetryWatcher;
184 ::ll::TypedStorage<8, 8, ::std::chrono::steady_clock::time_point> mNextSizeTelemetryCaptureTime;
185 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds const> mSizeTelemetryCaptureInterval;
186 ::ll::TypedStorage<8, 192, ::DBStoragePerformanceTelemetry> mDBStoragePerformanceTelemetry;
187 // NOLINTEND
188
189public:
190 // prevent constructor by default
191 DBStorage();
192
193public:
194 // virtual functions
195 // NOLINTBEGIN
196 virtual ~DBStorage() /*override*/;
197
198 virtual void addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer) /*override*/;
199
200 virtual bool loadedSuccessfully() const /*override*/;
201
202 virtual ::Core::LevelStorageResult getState() const /*override*/;
203
204 virtual ::std::unique_ptr<::ChunkSource>
205 createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion) /*override*/;
206
207 virtual ::Core::PathBuffer<::std::string> const& getFullPath() const /*override*/;
208
209 virtual ::std::unique_ptr<::CompoundTag>
210 getCompoundTag(::std::string const& key, ::DBHelpers::Category category) /*override*/;
211
212 virtual bool hasKey(::std::string_view key, ::DBHelpers::Category) const /*override*/;
213
214 virtual bool loadLevelData(::LevelData& data) /*override*/;
215
216 virtual void saveLevelData(::LevelData const& levelData) /*override*/;
217
218 virtual ::Bedrock::Threading::Async<void>
219 saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category) /*override*/;
220
221 virtual ::Bedrock::Threading::Async<void> saveData(::LevelStorageWriteBatch const& batch) /*override*/;
222
223 virtual ::Bedrock::Threading::Async<void>
224 deleteData(::std::string const& key, ::DBHelpers::Category category) /*override*/;
225
226 virtual bool loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const
227 /*override*/;
228
229 virtual void forEachKeyWithPrefix(
230 ::std::string_view prefix,
231 ::DBHelpers::Category category,
232 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
233 ) const /*override*/;
234
235 virtual ::Core::LevelStorageResult getLevelStorageState() const /*override*/;
236
237 virtual ::ContentIdentity const* getContentIdentity() const /*override*/;
238
239 virtual void startShutdown() /*override*/;
240
241 virtual bool isShuttingDown() const /*override*/;
242
243 virtual bool checkShutdownDone() /*override*/;
244
245 virtual void getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const /*override*/;
246
247 virtual ::std::vector<::SnapshotFilenameAndLength>
248 createSnapshot(::std::string const& filePrefix, bool flushWriteCache) /*override*/;
249
250 virtual void releaseSnapshot() /*override*/;
251
252 virtual ::Bedrock::Threading::Async<void> compactStorage() /*override*/;
253
254 virtual void syncAndSuspendStorage() /*override*/;
255
256 virtual void resumeStorage() /*override*/;
257
258 virtual void setFlushAllowed(bool flushAllowed) /*override*/;
259
260 virtual void flushToPermanentStorage() /*override*/;
261
262 virtual void freeCaches() /*override*/;
263
264 virtual void setCompactionCallback(::std::function<void(::CompactionStatus)> callback) /*override*/;
265
266 virtual void setCriticalSyncSaveCallback(::std::function<void()> callback) /*override*/;
267 // NOLINTEND
268
269public:
270 // member functions
271 // NOLINTBEGIN
272 MCAPI DBStorage(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
273
274 MCAPI ::TaskResult _flushWriteCacheToLevelDB();
275
276 MCAPI ::std::map<::std::string, ::DBStorage::PendingWriteResult> _getAllPendingWrites() const;
277
278 MCAPI ::std::string _getTelemetryMessage(::leveldb::Status const& status) const;
279
280 MCAPI void _handleErrorStatus(::leveldb::Status const& status);
281
282 MCAPI bool _isMarkedAsCorrupted() const;
283
284 MCAPI void _markAsCorrupted(::std::string_view message) const;
285
286 MCAPI void _mergeIntoDeleteCache(::std::string const& key, ::DBHelpers::Category category);
287
288 MCAPI void _mergeIntoWriteCache(::LevelStorageWriteBatch const& batchToMerge);
289
290 MCAPI void _mergeIntoWriteCache(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category);
291
292 MCAPI void _queueSaveCallback(bool invokeImmediately);
293
294 MCAPI void _read(
295 ::std::string_view prefix,
296 ::DBHelpers::Category category,
297 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
298 ) const;
299
300 MCAPI ::DBStorage::PendingWriteResult _readPendingWrite(::std::string const& key, ::DBHelpers::Category) const;
301
302 MCAPI void _removeCorruptedMark() const;
303
304 MCAPI void _scheduleNextAutoCompaction();
305
306 MCAPI bool _suspendAndPerformSaveAction(
307 ::brstd::move_only_function<::TaskResult()> action,
308 ::brstd::move_only_function<void()> callback
309 );
310
311 MCAPI void _write(::leveldb::WriteBatch& batch, uint batchSizeInBytes, uint writesInBatch);
312
313#ifdef LL_PLAT_C
314 MCFOLD ::TaskGroup& getTaskGroup();
315#endif
316
317 MCAPI bool tryRepair(::Core::Path const& path) const;
318 // NOLINTEND
319
320public:
321 // constructor thunks
322 // NOLINTBEGIN
323 MCAPI void* $ctor(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
324 // NOLINTEND
325
326public:
327 // destructor thunk
328 // NOLINTBEGIN
329 MCAPI void $dtor();
330 // NOLINTEND
331
332public:
333 // virtual function thunks
334 // NOLINTBEGIN
335 MCAPI void $addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer);
336
337 MCFOLD bool $loadedSuccessfully() const;
338
339 MCFOLD ::Core::LevelStorageResult $getState() const;
340
341 MCAPI ::std::unique_ptr<::ChunkSource>
342 $createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion);
343
344 MCFOLD ::Core::PathBuffer<::std::string> const& $getFullPath() const;
345
346 MCAPI ::std::unique_ptr<::CompoundTag> $getCompoundTag(::std::string const& key, ::DBHelpers::Category category);
347
348 MCAPI bool $hasKey(::std::string_view key, ::DBHelpers::Category) const;
349
350 MCAPI bool $loadLevelData(::LevelData& data);
351
352 MCAPI void $saveLevelData(::LevelData const& levelData);
353
354 MCAPI ::Bedrock::Threading::Async<void>
355 $saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category);
356
357 MCAPI ::Bedrock::Threading::Async<void> $saveData(::LevelStorageWriteBatch const& batch);
358
359 MCAPI ::Bedrock::Threading::Async<void> $deleteData(::std::string const& key, ::DBHelpers::Category category);
360
361 MCAPI bool $loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const;
362
363 MCAPI void $forEachKeyWithPrefix(
364 ::std::string_view prefix,
365 ::DBHelpers::Category category,
366 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
367 ) const;
368
369 MCFOLD ::Core::LevelStorageResult $getLevelStorageState() const;
370
371 MCFOLD ::ContentIdentity const* $getContentIdentity() const;
372
373 MCAPI void $startShutdown();
374
375 MCAPI bool $isShuttingDown() const;
376
377 MCAPI bool $checkShutdownDone();
378
379 MCAPI void $getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const;
380
381 MCAPI ::std::vector<::SnapshotFilenameAndLength>
382 $createSnapshot(::std::string const& filePrefix, bool flushWriteCache);
383
384 MCAPI void $releaseSnapshot();
385
386 MCAPI ::Bedrock::Threading::Async<void> $compactStorage();
387
388 MCAPI void $syncAndSuspendStorage();
389
390 MCAPI void $resumeStorage();
391
392 MCAPI void $setFlushAllowed(bool flushAllowed);
393
394 MCAPI void $flushToPermanentStorage();
395
396 MCAPI void $freeCaches();
397
398 MCAPI void $setCompactionCallback(::std::function<void(::CompactionStatus)> callback);
399
400 MCAPI void $setCriticalSyncSaveCallback(::std::function<void()> callback);
401
402
403 // NOLINTEND
404
405public:
406 // vftables
407 // NOLINTBEGIN
408 MCNAPI static void** $vftable();
409 // NOLINTEND
410};
Definition ChunkSource.h:37
Definition CompoundTag.h:23
Definition ContentIdentity.h:8
Definition Path.h:12
Definition DBChunkStorage.h:37
Definition DBStorageEnvironmentChain.h:19
Definition DBStorageFolderWatcher.h:15
Definition DBStorage.h:96
Definition DBStorage.h:104
static MCAPI void ** $vftable()
Definition LevelData.h:55
Definition LevelDbEnv.h:8
Definition LevelStorageEventing.h:17
Definition LevelStorageObserver.h:5
Definition LevelStorageWriteBatch.h:14
Definition LevelStorage.h:26
Definition SaveTransactionManager.h:14
Definition TaskGroup.h:55
Definition TaskResult.h:5
Definition flat_set.h:10
STL namespace.
Definition DBStorageConfig.h:21
Definition DBStorage.h:51
MCAPI void * $ctor(::std::string const &key, ::std::shared_ptr<::std::string > value, bool isDelete, ::DBHelpers::Category category)
MCAPI CommitOperation(::std::string const &key, ::std::shared_ptr<::std::string > value, bool isDelete, ::DBHelpers::Category category)
Definition DBStorage.h:114
Definition SnapshotFilenameAndLength.h:5
Definition buffer.h:5