forked from Mirrorlandia_minetest/minetest
Improve error reporting in leveldb backend
This commit is contained in:
parent
9b44bbd0a6
commit
d020e0771d
@ -36,12 +36,17 @@ LevelDB databases
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
#define ENSURE_STATUS_OK(s) \
|
||||||
|
if (!s.ok()) { \
|
||||||
|
throw FileNotGoodException(std::string("LevelDB error: ") + s.ToString()); \
|
||||||
|
}
|
||||||
|
|
||||||
Database_LevelDB::Database_LevelDB(ServerMap *map, std::string savedir)
|
Database_LevelDB::Database_LevelDB(ServerMap *map, std::string savedir)
|
||||||
{
|
{
|
||||||
leveldb::Options options;
|
leveldb::Options options;
|
||||||
options.create_if_missing = true;
|
options.create_if_missing = true;
|
||||||
leveldb::Status status = leveldb::DB::Open(options, savedir + DIR_DELIM + "map.db", &m_database);
|
leveldb::Status status = leveldb::DB::Open(options, savedir + DIR_DELIM + "map.db", &m_database);
|
||||||
assert(status.ok());
|
ENSURE_STATUS_OK(status);
|
||||||
srvmap = map;
|
srvmap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +86,8 @@ void Database_LevelDB::saveBlock(MapBlock *block)
|
|||||||
// Write block to database
|
// Write block to database
|
||||||
std::string tmp = o.str();
|
std::string tmp = o.str();
|
||||||
|
|
||||||
m_database->Put(leveldb::WriteOptions(), i64tos(getBlockAsInteger(p3d)), tmp);
|
leveldb::Status status = m_database->Put(leveldb::WriteOptions(), i64tos(getBlockAsInteger(p3d)), tmp);
|
||||||
|
ENSURE_STATUS_OK(status);
|
||||||
|
|
||||||
// We just wrote it to the disk so clear modified flag
|
// We just wrote it to the disk so clear modified flag
|
||||||
block->resetModified();
|
block->resetModified();
|
||||||
@ -92,9 +98,10 @@ MapBlock* Database_LevelDB::loadBlock(v3s16 blockpos)
|
|||||||
v2s16 p2d(blockpos.X, blockpos.Z);
|
v2s16 p2d(blockpos.X, blockpos.Z);
|
||||||
|
|
||||||
std::string datastr;
|
std::string datastr;
|
||||||
leveldb::Status s = m_database->Get(leveldb::ReadOptions(),
|
leveldb::Status status = m_database->Get(leveldb::ReadOptions(),
|
||||||
i64tos(getBlockAsInteger(blockpos)), &datastr);
|
i64tos(getBlockAsInteger(blockpos)), &datastr);
|
||||||
if (datastr.length() == 0 && s.ok()) {
|
ENSURE_STATUS_OK(status);
|
||||||
|
if (datastr.length() == 0) {
|
||||||
errorstream << "Blank block data in database (datastr.length() == 0) ("
|
errorstream << "Blank block data in database (datastr.length() == 0) ("
|
||||||
<< blockpos.X << "," << blockpos.Y << "," << blockpos.Z << ")" << std::endl;
|
<< blockpos.X << "," << blockpos.Y << "," << blockpos.Z << ")" << std::endl;
|
||||||
|
|
||||||
@ -105,9 +112,7 @@ MapBlock* Database_LevelDB::loadBlock(v3s16 blockpos)
|
|||||||
throw SerializationError("Blank block data in database");
|
throw SerializationError("Blank block data in database");
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (s.ok()) {
|
|
||||||
/*
|
/*
|
||||||
Make sure sector is loaded
|
Make sure sector is loaded
|
||||||
*/
|
*/
|
||||||
@ -176,7 +181,7 @@ void Database_LevelDB::listAllLoadableBlocks(std::list<v3s16> &dst)
|
|||||||
for (it->SeekToFirst(); it->Valid(); it->Next()) {
|
for (it->SeekToFirst(); it->Valid(); it->Next()) {
|
||||||
dst.push_back(getIntegerAsBlock(stoi64(it->key().ToString())));
|
dst.push_back(getIntegerAsBlock(stoi64(it->key().ToString())));
|
||||||
}
|
}
|
||||||
assert(it->status().ok()); // Check for any errors found during the scan
|
ENSURE_STATUS_OK(it->status()); // Check for any errors found during the scan
|
||||||
delete it;
|
delete it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user