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> generator, ::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> getCompoundTag(::std::string const&, ::DBHelpers::Category) /*override*/;
207
208 // vIndex: 4
209 virtual bool hasKey(::std::string_view, ::DBHelpers::Category) const /*override*/;
210
211 // vIndex: 6
212 virtual bool loadLevelData(::LevelData& data) /*override*/;
213
214 // vIndex: 8
215 virtual void saveLevelData(::LevelData const& levelData) /*override*/;
216
217 // vIndex: 11
218 virtual ::Bedrock::Threading::Async<void>
219 saveData(::std::string const&, ::std::string&&, ::DBHelpers::Category) /*override*/;
220
221 // vIndex: 10
222 virtual ::Bedrock::Threading::Async<void> saveData(::LevelStorageWriteBatch const& batch) /*override*/;
223
224 // vIndex: 12
225 virtual ::Bedrock::Threading::Async<void> deleteData(::std::string const&, ::DBHelpers::Category) /*override*/;
226
227 // vIndex: 20
228 virtual bool loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const
229 /*override*/;
230
231 // vIndex: 5
232 virtual void forEachKeyWithPrefix(
233 ::std::string_view,
234 ::DBHelpers::Category,
235 ::std::function<void(::std::string_view, ::std::string_view)> const&
236 ) const /*override*/;
237
238 // vIndex: 15
239 virtual ::Core::LevelStorageResult getLevelStorageState() const /*override*/;
240
241 // vIndex: 16
242 virtual ::ContentIdentity const* getContentIdentity() const /*override*/;
243
244 // vIndex: 17
245 virtual void startShutdown() /*override*/;
246
247 // vIndex: 18
248 virtual bool isShuttingDown() const /*override*/;
249
250 // vIndex: 19
251 virtual bool checkShutdownDone() /*override*/;
252
253 // vIndex: 13
254 virtual void getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const /*override*/;
255
256 // vIndex: 22
257 virtual ::std::vector<::SnapshotFilenameAndLength>
258 createSnapshot(::std::string const& filePrefix, bool flushWriteCache) /*override*/;
259
260 // vIndex: 23
261 virtual void releaseSnapshot() /*override*/;
262
263 // vIndex: 24
264 virtual ::Bedrock::Threading::Async<void> compactStorage() /*override*/;
265
266 // vIndex: 25
267 virtual void syncAndSuspendStorage() /*override*/;
268
269 // vIndex: 26
270 virtual void resumeStorage() /*override*/;
271
272 // vIndex: 27
273 virtual void setFlushAllowed(bool flushAllowed) /*override*/;
274
275 // vIndex: 28
276 virtual void flushToPermanentStorage() /*override*/;
277
278 // vIndex: 29
279 virtual void freeCaches() /*override*/;
280
281 // vIndex: 30
282 virtual void setCompactionCallback(::std::function<void(::CompactionStatus)> callback) /*override*/;
283
284 // vIndex: 31
285 virtual void setCriticalSyncSaveCallback(::std::function<void()> callback) /*override*/;
286 // NOLINTEND
287
288public:
289 // member functions
290 // NOLINTBEGIN
291 MCAPI DBStorage(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
292
293 MCAPI ::TaskResult _flushWriteCacheToLevelDB();
294
295 MCAPI ::std::map<::std::string, ::DBStorage::PendingWriteResult> _getAllPendingWrites() const;
296
297 MCAPI ::std::string _getTelemetryMessage(::leveldb::Status const& status) const;
298
299 MCAPI void _handleErrorStatus(::leveldb::Status const& status);
300
301 MCAPI void _markAsCorrupted(::std::string_view message) const;
302
303 MCAPI void _mergeIntoWriteCache(::LevelStorageWriteBatch const& batchToMerge);
304
305 MCAPI void _mergeIntoWriteCache(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category);
306
307 MCAPI void _queueSaveCallback(bool invokeImmediately);
308
309 MCAPI void _read(
310 ::std::string_view prefix,
311 ::DBHelpers::Category category,
312 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
313 ) const;
314
316 _readPendingWrite(::std::string const& key, ::DBHelpers::Category category) const;
317
318 MCAPI void _scheduleNextAutoCompaction();
319
320 MCAPI bool _suspendAndPerformSaveAction(
321 ::brstd::move_only_function<::TaskResult()> action,
322 ::brstd::move_only_function<void()> callback
323 );
324
325 MCAPI bool tryRepair(::Core::Path const& path) const;
326 // NOLINTEND
327
328public:
329 // constructor thunks
330 // NOLINTBEGIN
331 MCAPI void* $ctor(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
332 // NOLINTEND
333
334public:
335 // destructor thunk
336 // NOLINTBEGIN
337 MCAPI void $dtor();
338 // NOLINTEND
339
340public:
341 // virtual function thunks
342 // NOLINTBEGIN
343 MCAPI void $addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer);
344
345 MCFOLD bool $loadedSuccessfully() const;
346
347 MCFOLD ::Core::LevelStorageResult $getState() const;
348
349 MCAPI ::std::unique_ptr<::ChunkSource>
350 $createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion);
351
352 MCAPI ::Core::PathBuffer<::std::string> const& $getFullPath() const;
353
354 MCAPI bool $loadLevelData(::LevelData& data);
355
356 MCAPI void $saveLevelData(::LevelData const& levelData);
357
358 MCAPI ::Bedrock::Threading::Async<void> $saveData(::LevelStorageWriteBatch const& batch);
359
360 MCFOLD ::Core::LevelStorageResult $getLevelStorageState() const;
361
362 MCFOLD ::ContentIdentity const* $getContentIdentity() const;
363
364 MCAPI void $startShutdown();
365
366 MCAPI bool $isShuttingDown() const;
367
368 MCAPI bool $checkShutdownDone();
369
370 MCAPI void $getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const;
371
372 MCAPI ::std::vector<::SnapshotFilenameAndLength>
373 $createSnapshot(::std::string const& filePrefix, bool flushWriteCache);
374
375 MCAPI void $releaseSnapshot();
376
377 MCAPI ::Bedrock::Threading::Async<void> $compactStorage();
378
379 MCAPI void $syncAndSuspendStorage();
380
381 MCFOLD void $resumeStorage();
382
383 MCAPI void $setFlushAllowed(bool flushAllowed);
384
385 MCAPI void $flushToPermanentStorage();
386
387 MCAPI void $freeCaches();
388
389 MCAPI void $setCompactionCallback(::std::function<void(::CompactionStatus)> callback);
390
391 MCAPI void $setCriticalSyncSaveCallback(::std::function<void()> callback);
392 // NOLINTEND
393
394public:
395 // vftables
396 // NOLINTBEGIN
397 MCNAPI static void** $vftable();
398 // NOLINTEND
399};
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:48
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