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