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