1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Divorce map database locking from env lock (#15151)

This commit is contained in:
sfan5 2024-09-11 19:17:08 +02:00
parent 526a2f7b8c
commit 588a0f83e9
6 changed files with 197 additions and 90 deletions

View file

@ -33,9 +33,22 @@ class IRollbackManager;
class EmergeManager;
class ServerEnvironment;
struct BlockMakeData;
class MetricsBackend;
// TODO: this could wrap all calls to MapDatabase, including locking
struct MapDatabaseAccessor {
/// Lock, to be taken for any operation
std::mutex mutex;
/// Main database
MapDatabase *dbase = nullptr;
/// Fallback database for read operations
MapDatabase *dbase_ro = nullptr;
/// Load a block, taking dbase_ro into account.
/// @note call locked
void loadBlock(v3s16 blockpos, std::string &ret);
};
/*
ServerMap
@ -75,7 +88,7 @@ public:
MapBlock *createBlock(v3s16 p);
/*
Forcefully get a block from somewhere.
Forcefully get a block from somewhere (blocking!).
- Memory
- Load from disk
- Create blank filled with CONTENT_IGNORE
@ -114,9 +127,16 @@ public:
bool saveBlock(MapBlock *block) override;
static bool saveBlock(MapBlock *block, MapDatabase *db, int compression_level = -1);
MapBlock* loadBlock(v3s16 p);
// Database version
void loadBlock(std::string *blob, v3s16 p3d, MapSector *sector, bool save_after_load=false);
// Load block in a synchronous fashion
MapBlock *loadBlock(v3s16 p);
/// Load a block that was already read from disk. Used by EmergeManager.
/// @return non-null block (but can be blank)
MapBlock *loadBlock(const std::string &blob, v3s16 p, bool save_after_load=false);
// Helper for deserializing blocks from disk
// @throws SerializationError
static void deSerializeBlock(MapBlock *block, std::istream &is);
// Blocks are removed from the map but not deleted from memory until
// deleteDetachedBlocks() is called, since pointers to them may still exist
@ -185,8 +205,8 @@ private:
This is reset to false when written on disk.
*/
bool m_map_metadata_changed = true;
MapDatabase *dbase = nullptr;
MapDatabase *dbase_ro = nullptr;
MapDatabaseAccessor m_db;
// Map metrics
MetricGaugePtr m_loaded_blocks_gauge;