summaryrefslogtreecommitdiff
path: root/src/database-leveldb.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-07-07 01:20:25 -0400
committerkwolekr <kwolekr@minetest.net>2014-07-07 01:20:25 -0400
commit8b3ed78e53d8ad19d8dee3968430be258559214c (patch)
tree497c583608f3d7e596e899934c9945e4a324db23 /src/database-leveldb.cpp
parente14c4cdd4c3c9b554dc9cb91f8f29078ad337ded (diff)
downloadminetest-8b3ed78e53d8ad19d8dee3968430be258559214c.tar.gz
minetest-8b3ed78e53d8ad19d8dee3968430be258559214c.tar.bz2
minetest-8b3ed78e53d8ad19d8dee3968430be258559214c.zip
Don't unload blocks if save failed
Improve error handling in saveBlock()
Diffstat (limited to 'src/database-leveldb.cpp')
-rw-r--r--src/database-leveldb.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/database-leveldb.cpp b/src/database-leveldb.cpp
index 9fe47b34e..0cf685740 100644
--- a/src/database-leveldb.cpp
+++ b/src/database-leveldb.cpp
@@ -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)