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
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 // member functions
63 // NOLINTBEGIN
65 // NOLINTEND
66
67 public:
68 // destructor thunk
69 // NOLINTBEGIN
70 MCNAPI void $dtor();
71 // NOLINTEND
72 };
73
75 public:
76 // member variables
77 // NOLINTBEGIN
78 ::ll::TypedStorage<8, 8, ::std::atomic<int>*> mRefCounter;
79 // NOLINTEND
80
81 public:
82 // member functions
83 // NOLINTBEGIN
85 // NOLINTEND
86
87 public:
88 // destructor thunk
89 // NOLINTBEGIN
90 MCNAPI void $dtor();
91 // NOLINTEND
92 };
93
94 class Options {
95 public:
96 // member variables
97 // NOLINTBEGIN
98 ::ll::TypedStorage<8, 112, ::leveldb::Options> options;
99 ::ll::TypedStorage<8, 24, ::leveldb::ReadOptions> read;
100 ::ll::TypedStorage<1, 1, ::leveldb::WriteOptions> write;
101 // NOLINTEND
102 };
103
105 public:
106 // member variables
107 // NOLINTBEGIN
108 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::std::string const>> mLatestValue;
109 ::ll::TypedStorage<1, 1, bool> mIsDeleted;
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 virtual ~DBStorage() /*override*/;
187
188 virtual void addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer) /*override*/;
189
190 virtual bool loadedSuccessfully() const /*override*/;
191
192 virtual ::Core::LevelStorageResult getState() const /*override*/;
193
194 virtual ::std::unique_ptr<::ChunkSource>
195 createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion) /*override*/;
196
197 virtual ::Core::PathBuffer<::std::string> const& getFullPath() const /*override*/;
198
199 virtual ::std::unique_ptr<::CompoundTag>
200 getCompoundTag(::std::string const& key, ::DBHelpers::Category category) /*override*/;
201
202 virtual bool hasKey(::std::string_view key, ::DBHelpers::Category category) const /*override*/;
203
204 virtual bool loadLevelData(::LevelData& data) /*override*/;
205
206 virtual void saveLevelData(::LevelData const& levelData) /*override*/;
207
208 virtual ::Bedrock::Threading::Async<void>
209 saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category) /*override*/;
210
211 virtual ::Bedrock::Threading::Async<void> saveData(::LevelStorageWriteBatch const& batch) /*override*/;
212
213 virtual ::Bedrock::Threading::Async<void>
214 deleteData(::std::string const& key, ::DBHelpers::Category category) /*override*/;
215
216 virtual bool loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const
217 /*override*/;
218
219 virtual void forEachKeyWithPrefix(
220 ::std::string_view prefix,
221 ::DBHelpers::Category category,
222 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
223 ) const /*override*/;
224
225 virtual ::Core::LevelStorageResult getLevelStorageState() const /*override*/;
226
227 virtual ::ContentIdentity const* getContentIdentity() const /*override*/;
228
229 virtual void startShutdown() /*override*/;
230
231 virtual bool isShuttingDown() const /*override*/;
232
233 virtual bool checkShutdownDone() /*override*/;
234
235 virtual void getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const /*override*/;
236
237 virtual ::std::vector<::SnapshotFilenameAndLength>
238 createSnapshot(::std::string const& filePrefix, bool flushWriteCache) /*override*/;
239
240 virtual void releaseSnapshot() /*override*/;
241
242 virtual ::Bedrock::Threading::Async<void> compactStorage() /*override*/;
243
244 virtual void syncAndSuspendStorage() /*override*/;
245
246 virtual void resumeStorage() /*override*/;
247
248 virtual void setFlushAllowed(bool flushAllowed) /*override*/;
249
250 virtual void flushToPermanentStorage() /*override*/;
251
252 virtual void freeCaches() /*override*/;
253
254 virtual void setCompactionCallback(::std::function<void(::CompactionStatus)> callback) /*override*/;
255
256 virtual void setCriticalSyncSaveCallback(::std::function<void()> callback) /*override*/;
257 // NOLINTEND
258
259public:
260 // member functions
261 // NOLINTBEGIN
262 MCAPI DBStorage(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
263
264 MCAPI ::TaskResult _flushWriteCacheToLevelDB();
265
266 MCAPI ::std::map<::std::string, ::DBStorage::PendingWriteResult> _getAllPendingWrites() const;
267
268 MCAPI ::std::string _getTelemetryMessage(::leveldb::Status const& status) const;
269
270 MCAPI void _handleErrorStatus(::leveldb::Status const& status);
271
272 MCAPI void _markAsCorrupted(::std::string_view message) const;
273
274 MCAPI void _mergeIntoWriteCache(::LevelStorageWriteBatch const& batchToMerge);
275
276 MCAPI void _mergeIntoWriteCache(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category);
277
278 MCAPI void _queueSaveCallback(bool invokeImmediately);
279
280 MCAPI void _read(
281 ::std::string_view prefix,
282 ::DBHelpers::Category category,
283 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
284 ) const;
285
286 MCAPI ::DBStorage::PendingWriteResult
287 _readPendingWrite(::std::string const& key, ::DBHelpers::Category category) const;
288
289 MCAPI void _scheduleNextAutoCompaction();
290
291 MCAPI bool _suspendAndPerformSaveAction(
292 ::brstd::move_only_function<::TaskResult()> action,
293 ::brstd::move_only_function<void()> callback
294 );
295
296 MCAPI bool tryRepair(::Core::Path const& path) const;
297 // NOLINTEND
298
299public:
300 // constructor thunks
301 // NOLINTBEGIN
302 MCAPI void* $ctor(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
303 // NOLINTEND
304
305public:
306 // destructor thunk
307 // NOLINTBEGIN
308 MCAPI void $dtor();
309 // NOLINTEND
310
311public:
312 // virtual function thunks
313 // NOLINTBEGIN
314 MCAPI void $addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer);
315
316 MCFOLD bool $loadedSuccessfully() const;
317
318 MCFOLD ::Core::LevelStorageResult $getState() const;
319
320 MCAPI ::std::unique_ptr<::ChunkSource>
321 $createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion);
322
323 MCAPI ::Core::PathBuffer<::std::string> const& $getFullPath() const;
324
325 MCAPI ::std::unique_ptr<::CompoundTag> $getCompoundTag(::std::string const& key, ::DBHelpers::Category category);
326
327 MCAPI bool $hasKey(::std::string_view key, ::DBHelpers::Category category) const;
328
329 MCAPI bool $loadLevelData(::LevelData& data);
330
331 MCAPI void $saveLevelData(::LevelData const& levelData);
332
333 MCAPI ::Bedrock::Threading::Async<void>
334 $saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category);
335
336 MCAPI ::Bedrock::Threading::Async<void> $saveData(::LevelStorageWriteBatch const& batch);
337
338 MCAPI ::Bedrock::Threading::Async<void> $deleteData(::std::string const& key, ::DBHelpers::Category category);
339
340 MCAPI bool $loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const;
341
342 MCAPI void $forEachKeyWithPrefix(
343 ::std::string_view prefix,
344 ::DBHelpers::Category category,
345 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
346 ) const;
347
348 MCFOLD ::Core::LevelStorageResult $getLevelStorageState() const;
349
350 MCFOLD ::ContentIdentity const* $getContentIdentity() const;
351
352 MCAPI void $startShutdown();
353
354 MCAPI bool $isShuttingDown() const;
355
356 MCAPI bool $checkShutdownDone();
357
358 MCAPI void $getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const;
359
360 MCAPI ::std::vector<::SnapshotFilenameAndLength>
361 $createSnapshot(::std::string const& filePrefix, bool flushWriteCache);
362
363 MCAPI void $releaseSnapshot();
364
365 MCAPI ::Bedrock::Threading::Async<void> $compactStorage();
366
367 MCAPI void $syncAndSuspendStorage();
368
369 MCAPI void $resumeStorage();
370
371 MCAPI void $setFlushAllowed(bool flushAllowed);
372
373 MCAPI void $flushToPermanentStorage();
374
375 MCAPI void $freeCaches();
376
377 MCAPI void $setCompactionCallback(::std::function<void(::CompactionStatus)> callback);
378
379 MCAPI void $setCriticalSyncSaveCallback(::std::function<void()> callback);
380
381
382 // NOLINTEND
383
384public:
385 // vftables
386 // NOLINTBEGIN
387 MCNAPI static void** $vftable();
388 // NOLINTEND
389};
Definition ChunkSource.h:37
Definition CompoundTag.h:23
Definition ContentIdentity.h:8
Definition Path.h:10
Definition DBChunkStorage.h:34
Definition DBStorageEnvironmentChain.h:19
Definition DBStorageFolderWatcher.h:14
Definition DBStorage.h:74
Definition DBStorage.h:94
static MCAPI void ** $vftable()
Definition LevelData.h:50
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:51
Definition DBStorage.h:104
Definition SnapshotFilenameAndLength.h:5
Definition buffer.h:5