Skip to content
LeviMC
English
AutoLightDark
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/world/level/storage/DBStoragePerformanceTelemetry.h"
13#include "mc/world/level/storage/LevelStorage.h"
14#include "mc/world/level/storage/LevelStorageWriteBatch.h"
15#include "mc/world/level/storage/StorageVersion.h"
16#include "mc/world/level/storage/db_helpers/Category.h"
17
18// auto generated forward declare list
19// clang-format off
20class ChunkSource;
21class CompoundTag;
22class ContentIdentity;
23class DBChunkStorage;
26class LevelData;
27class LevelDbEnv;
31class TaskGroup;
32class TaskResult;
33struct DBStorageConfig;
36namespace Core { class Path; }
37// clang-format on
38
39class DBStorage : public ::LevelStorage {
40public:
41 // DBStorage inner types declare
42 // clang-format off
43 struct CommitOperation;
44 class DBStorageToken;
45 class Options;
46 struct PendingWriteResult;
47 // clang-format on
48
49 // DBStorage inner types define
51 public:
52 // member variables
53 // NOLINTBEGIN
54 ::ll::TypedStorage<8, 32, ::std::string> mKey;
55 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::std::string>> mValue;
56 ::ll::TypedStorage<4, 4, ::DBHelpers::Category> mCategory;
57 ::ll::TypedStorage<1, 1, bool> mIsDelete;
58 // NOLINTEND
59 };
60
62 public:
63 // member variables
64 // NOLINTBEGIN
65 ::ll::TypedStorage<8, 8, ::std::atomic<int>*> mRefCounter;
66 // NOLINTEND
67 };
68
69 class Options {
70 public:
71 // member variables
72 // NOLINTBEGIN
73 ::ll::TypedStorage<8, 112, ::leveldb::Options> options;
74 ::ll::TypedStorage<8, 24, ::leveldb::ReadOptions> read;
75 ::ll::TypedStorage<1, 1, ::leveldb::WriteOptions> write;
76 // NOLINTEND
77 };
78
80 public:
81 // member variables
82 // NOLINTBEGIN
83 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::std::string const>> mLatestValue;
84 ::ll::TypedStorage<1, 1, bool> mIsDeleted;
85 // NOLINTEND
86 };
87
88public:
89 // member variables
90 // NOLINTBEGIN
91 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::DBStorageEnvironmentChain>> mEnvChain;
92 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::Cache>> mCache;
93 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::FilterPolicy const>> mFilterPolicy;
94 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::DBStorage::Options>> mOptions;
95 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::DecompressAllocator>> mDecompressAllocator;
96 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::leveldb::DB>> mDb;
97 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::TaskGroup>> mIOTaskGroup;
98 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::TaskGroup>> mCompactionTaskGroup;
99 ::ll::TypedStorage<8, 16, ::Bedrock::Threading::Async<void>> mCompactionTask;
100 ::ll::TypedStorage<8, 16, ::Bedrock::Threading::Async<void>> mWriteTask;
101 ::ll::TypedStorage<8, 40, ::Core::LevelStorageResult> mState;
102 ::ll::TypedStorage<8, 8, ::ContentIdentity const*> mContentIdentity;
103 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mFullPath;
104 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDbPath;
105 ::ll::TypedStorage<8, 32, ::std::string> mLevelId;
106 ::ll::TypedStorage<8, 80, ::std::mutex> mCompactionMutex;
107 ::ll::TypedStorage<8, 8, ::std::shared_mutex> mWriteCacheMutex;
108 ::ll::TypedStorage<8, 80, ::std::mutex> mCacheFlushMutex;
109 ::ll::TypedStorage<8, 8, ::std::chrono::steady_clock::time_point> mLastCompactionStartTime;
110 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds> mCompactionInterval;
111 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds> mWriteFlushInterval;
112 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mAllowFlush;
113 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mSavingInProgress;
114 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mSnapshotInProgress;
115 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mShutdownStarted;
116 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mNoMoreWrites;
117 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mShutdownDone;
118 ::ll::TypedStorage<4, 4, ::std::atomic<int>> mOutstandingJobs;
119 ::ll::TypedStorage<8, 24, ::Bedrock::NonOwnerPointer<::SaveTransactionManager>> mSaveTransactionManager;
120 ::ll::TypedStorage<8, 64, ::std::function<void()>> mCriticalSyncSaveCallback;
121 ::ll::TypedStorage<8, 64, ::std::function<void(::CompactionStatus)>> mExternallyRegisteredCompactionCallback;
122 ::ll::TypedStorage<
123 8,
124 24,
126 mChunkStorages;
127 ::ll::TypedStorage<8, 24, ::std::vector<::std::unique_ptr<::LevelStorageObserver>>> mObservers;
128 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mDestructorInProgress;
129 ::ll::TypedStorage<1, 1, bool> mForceCorrupt;
130 ::ll::TypedStorage<1, 1, bool const> mStorageEnabled;
131 ::ll::TypedStorage<1, 1, bool const> mJigsawPersistenceToggle;
132 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mDbSubfolder;
133 ::ll::TypedStorage<8, 128, ::LevelStorageWriteBatch> mSingleKeyWrites;
134 ::ll::TypedStorage<8, 24, ::std::vector<::LevelStorageWriteBatch>> mBatchWrites;
135 ::ll::TypedStorage<8, 8, ::std::unique_ptr<::LevelStorageEventing>> mEventing;
136 ::ll::TypedStorage<8, 24, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv>> mLevelDbEnv;
137 ::ll::TypedStorage<8, 8, ::gsl::not_null<::std::unique_ptr<::DBStorageFolderWatcher>>> mFolderTelemetryWatcher;
138 ::ll::TypedStorage<8, 8, ::std::chrono::steady_clock::time_point> mNextSizeTelemetryCaptureTime;
139 ::ll::TypedStorage<8, 8, ::std::chrono::nanoseconds const> mSizeTelemetryCaptureInterval;
140 ::ll::TypedStorage<8, 192, ::DBStoragePerformanceTelemetry> mDBStoragePerformanceTelemetry;
141 // NOLINTEND
142
143public:
144 // prevent constructor by default
145 DBStorage();
146
147public:
148 // virtual functions
149 // NOLINTBEGIN
150 virtual ~DBStorage() /*override*/ = default;
151
152 virtual void addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer) /*override*/;
153
154 virtual bool loadedSuccessfully() const /*override*/;
155
156 virtual ::Core::LevelStorageResult getState() const /*override*/;
157
158 virtual ::std::unique_ptr<::ChunkSource>
159 createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion) /*override*/;
160
161 virtual ::Core::PathBuffer<::std::string> const& getFullPath() const /*override*/;
162
163 virtual ::std::unique_ptr<::CompoundTag>
164 getCompoundTag(::std::string const& key, ::DBHelpers::Category category) /*override*/;
165
166 virtual bool hasKey(::std::string_view key, ::DBHelpers::Category category) const /*override*/;
167
168 virtual bool loadLevelData(::LevelData& data) /*override*/;
169
170 virtual void saveLevelData(::LevelData const& levelData) /*override*/;
171
172 virtual ::Bedrock::Threading::Async<void>
173 saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category) /*override*/;
174
175 virtual ::Bedrock::Threading::Async<void> saveData(::LevelStorageWriteBatch const& batch) /*override*/;
176
177 virtual ::Bedrock::Threading::Async<void>
178 deleteData(::std::string const& key, ::DBHelpers::Category category) /*override*/;
179
180 virtual bool loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const
181 /*override*/;
182
183 virtual void forEachKeyWithPrefix(
184 ::std::string_view prefix,
185 ::DBHelpers::Category category,
186 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
187 ) const /*override*/;
188
189 virtual ::Core::LevelStorageResult getLevelStorageState() const /*override*/;
190
191 virtual ::ContentIdentity const* getContentIdentity() const /*override*/;
192
193 virtual void startShutdown() /*override*/;
194
195 virtual bool isShuttingDown() const /*override*/;
196
197 virtual bool checkShutdownDone() /*override*/;
198
199 virtual void getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const /*override*/;
200
201 virtual ::std::vector<::SnapshotFilenameAndLength>
202 createSnapshot(::std::string const& filePrefix, bool flushWriteCache) /*override*/;
203
204 virtual void releaseSnapshot() /*override*/;
205
206 virtual ::Bedrock::Threading::Async<void> compactStorage() /*override*/;
207
208 virtual void syncAndSuspendStorage() /*override*/;
209
210 virtual void resumeStorage() /*override*/;
211
212 virtual void setFlushAllowed(bool flushAllowed) /*override*/;
213
214 virtual void flushToPermanentStorage() /*override*/;
215
216 virtual void freeCaches() /*override*/;
217
218 virtual void setCompactionCallback(::std::function<void(::CompactionStatus)> callback) /*override*/;
219
220 virtual void setCriticalSyncSaveCallback(::std::function<void()> callback) /*override*/;
221
222 virtual void
223 setWorldSaveAndExitPackTelemetry(::std::vector<::WorldSaveAndExitPackTelemetryData> packs) /*override*/;
224 // NOLINTEND
225
226public:
227 // member functions
228 // NOLINTBEGIN
229 MCAPI DBStorage(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
230
232
233 MCNAPI ::std::string _getTelemetryMessage(::leveldb::Status const& status) const;
234
235 MCNAPI ::DBStorage::PendingWriteResult
236 _readPendingWrite(::std::string const& key, ::DBHelpers::Category category) const;
237
238 MCNAPI bool tryRepair(::Core::Path const& path) const;
239 // NOLINTEND
240
241public:
242 // constructor thunks
243 // NOLINTBEGIN
244 MCAPI void* $ctor(::DBStorageConfig config, ::Bedrock::NotNullNonOwnerPtr<::LevelDbEnv> levelDbEnv);
245 // NOLINTEND
246
247public:
248 // virtual function thunks
249 // NOLINTBEGIN
250 MCNAPI void $addStorageObserver(::std::unique_ptr<::LevelStorageObserver> observer);
251
252 MCNAPI bool $loadedSuccessfully() const;
253
254 MCNAPI ::Core::LevelStorageResult $getState() const;
255
256 MCNAPI ::std::unique_ptr<::ChunkSource>
257 $createChunkStorage(::std::unique_ptr<::ChunkSource> generator, ::StorageVersion);
258
259 MCNAPI ::Core::PathBuffer<::std::string> const& $getFullPath() const;
260
261 MCNAPI ::std::unique_ptr<::CompoundTag> $getCompoundTag(::std::string const& key, ::DBHelpers::Category category);
262
263 MCNAPI bool $hasKey(::std::string_view key, ::DBHelpers::Category category) const;
264
265 MCNAPI bool $loadLevelData(::LevelData& data);
266
267 MCNAPI void $saveLevelData(::LevelData const& levelData);
268
269 MCNAPI ::Bedrock::Threading::Async<void>
270 $saveData(::std::string const& key, ::std::string&& data, ::DBHelpers::Category category);
271
272 MCNAPI ::Bedrock::Threading::Async<void> $saveData(::LevelStorageWriteBatch const& batch);
273
274 MCNAPI ::Bedrock::Threading::Async<void> $deleteData(::std::string const& key, ::DBHelpers::Category category);
275
276 MCAPI bool $loadData(::std::string_view key, ::std::string& buffer, ::DBHelpers::Category category) const;
277
279 ::std::string_view prefix,
280 ::DBHelpers::Category category,
281 ::std::function<void(::std::string_view, ::std::string_view)> const& callback
282 ) const;
283
284 MCNAPI ::Core::LevelStorageResult $getLevelStorageState() const;
285
286 MCNAPI ::ContentIdentity const* $getContentIdentity() const;
287
288 MCNAPI void $startShutdown();
289
290 MCNAPI bool $isShuttingDown() const;
291
292 MCAPI bool $checkShutdownDone();
293
294 MCNAPI void $getStatistics(::std::string& outStats, ::LevelStorage::StatsType statsType) const;
295
296 MCAPI ::std::vector<::SnapshotFilenameAndLength>
297 $createSnapshot(::std::string const& filePrefix, bool flushWriteCache);
298
299 MCAPI void $releaseSnapshot();
300
301 MCNAPI ::Bedrock::Threading::Async<void> $compactStorage();
302
304
305 MCNAPI void $resumeStorage();
306
307 MCNAPI void $setFlushAllowed(bool flushAllowed);
308
310
311 MCNAPI void $freeCaches();
312
313 MCNAPI void $setCompactionCallback(::std::function<void(::CompactionStatus)> callback);
314
315 MCNAPI void $setCriticalSyncSaveCallback(::std::function<void()> callback);
316
318
319
320 // NOLINTEND
321};
Definition ChunkSource.h:37
Definition CompoundTag.h:18
Definition ContentIdentity.h:8
Definition Path.h:10
Definition DBChunkStorage.h:36
Definition DBStorageEnvironmentChain.h:20
Definition DBStorageFolderWatcher.h:18
Definition DBStorage.h:61
Definition DBStorage.h:69
MCAPI ::Bedrock::Threading::Async< void > $compactStorage()
MCAPI ::std::unique_ptr<::CompoundTag > $getCompoundTag(::std::string const &key, ::DBHelpers::Category category)
MCAPI void $setFlushAllowed(bool flushAllowed)
MCAPI::DBStorage::PendingWriteResult _readPendingWrite(::std::string const &key, ::DBHelpers::Category category) const
MCAPI::Core::LevelStorageResult $getState() const
MCAPI void $setWorldSaveAndExitPackTelemetry(::std::vector<::WorldSaveAndExitPackTelemetryData > packs)
MCAPI void $resumeStorage()
MCAPI void $syncAndSuspendStorage()
MCAPI bool tryRepair(::Core::Path const &path) const
MCAPI bool $loadLevelData(::LevelData &data)
MCAPI void $startShutdown()
MCAPI::Core::LevelStorageResult $getLevelStorageState() const
MCAPI ::Bedrock::Threading::Async< void > $saveData(::std::string const &key, ::std::string &&data, ::DBHelpers::Category category)
MCAPI void $setCriticalSyncSaveCallback(::std::function< void()> callback)
MCAPI ::Bedrock::Threading::Async< void > $deleteData(::std::string const &key, ::DBHelpers::Category category)
MCAPI void $getStatistics(::std::string &outStats, ::LevelStorage::StatsType statsType) const
MCAPI::std::string _getTelemetryMessage(::leveldb::Status const &status) const
MCAPI void $addStorageObserver(::std::unique_ptr<::LevelStorageObserver > observer)
MCAPI bool $loadedSuccessfully() const
MCAPI void $forEachKeyWithPrefix(::std::string_view prefix, ::DBHelpers::Category category, ::std::function< void(::std::string_view, ::std::string_view)> const &callback) const
MCAPI void $freeCaches()
MCAPI bool $isShuttingDown() const
MCAPI void $flushToPermanentStorage()
MCAPI bool $hasKey(::std::string_view key, ::DBHelpers::Category category) const
MCAPI void $setCompactionCallback(::std::function< void(::CompactionStatus)> callback)
MCAPI ::Core::PathBuffer<::std::string > const & $getFullPath() const
MCAPI void $saveLevelData(::LevelData const &levelData)
MCAPI::ContentIdentity const * $getContentIdentity() const
MCAPI ::std::unique_ptr<::ChunkSource > $createChunkStorage(::std::unique_ptr<::ChunkSource > generator, ::StorageVersion)
MCAPI::TaskResult _flushWriteCacheToLevelDB()
Definition LevelData.h:57
Definition LevelDbEnv.h:8
Definition LevelStorageEventing.h:19
Definition LevelStorageObserver.h:5
Definition LevelStorageWriteBatch.h:13
Definition LevelStorage.h:26
Definition Path.h:16
Definition SaveTransactionManager.h:14
Definition TaskGroup.h:85
Definition TaskResult.h:5
Definition flat_set.h:10
STL namespace.
Definition DBStorageConfig.h:21
Definition DBStorage.h:50
Definition DBStorage.h:79
Definition SnapshotFilenameAndLength.h:5
Definition WorldSaveAndExitPackTelemetryData.h:5
Definition buffer.h:5