Skip to content

Commit

Permalink
Allow an optional readonly base database (minetest#7544)
Browse files Browse the repository at this point in the history
* Allow an optional readonly base database

* Added basic documentation
  • Loading branch information
lhofhansl committed Jul 25, 2018
1 parent 9537cfd commit 7454deb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 9 additions & 2 deletions doc/world_format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ See Player File Format below.
world.mt
---------
World metadata.
Example content (added indentation):
gameid = mesetint
Example content (added indentation and - explanations):
gameid = mesetint - name of the game
enable_damage = true - whether damage is enabled or not
creative_mode = false - whether creative mode is enabled or not
backend = sqlite3 - which DB backend to use for blocks (sqlite3, dummy, leveldb, redis, postgresql)
player_backend = sqlite3 - which DB backend to use for player data
readonly_backend = sqlite3 - optionally readonly seed DB (DB file _must_ be located in "readonly" subfolder)
server_announce = false - whether the server is publicly announced or not
load_mod_<mod> = false - whether <mod> is to be loaded in this world

Player File Format
===================
Expand Down
14 changes: 13 additions & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,10 @@ ServerMap::ServerMap(const std::string &savedir, IGameDef *gamedef,
}
std::string backend = conf.get("backend");
dbase = createDatabase(backend, savedir, conf);

if (conf.exists("readonly_backend")) {
std::string readonly_dir = savedir + DIR_DELIM + "readonly";
dbase_ro = createDatabase(conf.get("readonly_backend"), readonly_dir, conf);
}
if (!conf.updateConfigFile(conf_path.c_str()))
errorstream << "ServerMap::ServerMap(): Failed to update world.mt!" << std::endl;

Expand Down Expand Up @@ -1230,6 +1233,8 @@ ServerMap::~ServerMap()
Close database if it was opened
*/
delete dbase;
if (dbase_ro)
delete dbase_ro;

#if 0
/*
Expand Down Expand Up @@ -1869,6 +1874,8 @@ void ServerMap::listAllLoadableBlocks(std::vector<v3s16> &dst)
<< "all blocks that are stored in flat files." << std::endl;
}
dbase->listAllLoadableBlocks(dst);
if (dbase_ro)
dbase_ro->listAllLoadableBlocks(dst);
}

void ServerMap::listAllLoadedBlocks(std::vector<v3s16> &dst)
Expand Down Expand Up @@ -2107,6 +2114,11 @@ MapBlock* ServerMap::loadBlock(v3s16 blockpos)
dbase->loadBlock(blockpos, &ret);
if (!ret.empty()) {
loadBlock(&ret, blockpos, createSector(p2d), false);
} else if (dbase_ro) {
dbase_ro->loadBlock(blockpos, &ret);
if (!ret.empty()) {
loadBlock(&ret, blockpos, createSector(p2d), false);
}
} else {
// Not found in database, try the files

Expand Down
1 change: 1 addition & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ class ServerMap : public Map
*/
bool m_map_metadata_changed = true;
MapDatabase *dbase = nullptr;
MapDatabase *dbase_ro = nullptr;
};


Expand Down

0 comments on commit 7454deb

Please sign in to comment.