mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Don't unload blocks if save failed
Improve error handling in saveBlock()
This commit is contained in:
parent
e14c4cdd4c
commit
8b3ed78e53
11 changed files with 108 additions and 67 deletions
|
@ -37,8 +37,8 @@ LevelDB databases
|
|||
#include "log.h"
|
||||
|
||||
#define ENSURE_STATUS_OK(s) \
|
||||
if (!s.ok()) { \
|
||||
throw FileNotGoodException(std::string("LevelDB error: ") + s.ToString()); \
|
||||
if (!(s).ok()) { \
|
||||
throw FileNotGoodException(std::string("LevelDB error: ") + (s).ToString()); \
|
||||
}
|
||||
|
||||
Database_LevelDB::Database_LevelDB(ServerMap *map, std::string savedir)
|
||||
|
@ -58,27 +58,29 @@ int Database_LevelDB::Initialized(void)
|
|||
void Database_LevelDB::beginSave() {}
|
||||
void Database_LevelDB::endSave() {}
|
||||
|
||||
void Database_LevelDB::saveBlock(MapBlock *block)
|
||||
bool Database_LevelDB::saveBlock(MapBlock *block)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
v3s16 p3d = block->getPos();
|
||||
|
||||
/*
|
||||
Dummy blocks are not written
|
||||
*/
|
||||
if(block->isDummy())
|
||||
{
|
||||
return;
|
||||
errorstream << "WARNING: saveBlock: Not writing dummy block "
|
||||
<< PP(p3d) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Format used for writing
|
||||
u8 version = SER_FMT_VER_HIGHEST_WRITE;
|
||||
// Get destination
|
||||
v3s16 p3d = block->getPos();
|
||||
|
||||
/*
|
||||
[0] u8 serialization version
|
||||
[1] data
|
||||
*/
|
||||
|
||||
std::ostringstream o(std::ios_base::binary);
|
||||
o.write((char*)&version, 1);
|
||||
// Write basic data
|
||||
|
@ -86,11 +88,17 @@ void Database_LevelDB::saveBlock(MapBlock *block)
|
|||
// Write block to database
|
||||
std::string tmp = o.str();
|
||||
|
||||
leveldb::Status status = m_database->Put(leveldb::WriteOptions(), i64tos(getBlockAsInteger(p3d)), tmp);
|
||||
ENSURE_STATUS_OK(status);
|
||||
leveldb::Status status = m_database->Put(leveldb::WriteOptions(),
|
||||
i64tos(getBlockAsInteger(p3d)), tmp);
|
||||
if (!status.ok()) {
|
||||
errorstream << "WARNING: saveBlock: LevelDB error saving block "
|
||||
<< PP(p3d) << ": " << status.ToString() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// We just wrote it to the disk so clear modified flag
|
||||
block->resetModified();
|
||||
return true;
|
||||
}
|
||||
|
||||
MapBlock* Database_LevelDB::loadBlock(v3s16 blockpos)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue