Limit max navmeshdb file size

Use "pragma max_page_count" to define max allowed file size in combination with
"pragma page_size" based on a new setting "max navmeshdb file size".

* Stop navmeshtool on the first db error.
* Disable writes to db in the engine on first "database or disk is full"
  SQLite3 error. There is no special error code for this error.
* Change default "write to navmeshdb" to true.
* Use time intervals for transaction duration instead of number of changes.
This commit is contained in:
elsid 2022-03-10 18:34:35 +01:00
parent 2325b16f8f
commit 5b9dd10cbe
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
19 changed files with 242 additions and 68 deletions

View file

@ -10,7 +10,7 @@ namespace Sqlite3
{
void CloseSqlite3::operator()(sqlite3* handle) const noexcept
{
sqlite3_close(handle);
sqlite3_close_v2(handle);
}
Db makeDb(std::string_view path, const char* schema)

View file

@ -9,25 +9,43 @@
namespace Sqlite3
{
namespace
{
const char* getBeginStatement(TransactionMode mode)
{
switch (mode)
{
case TransactionMode::Default: return "BEGIN";
case TransactionMode::Deferred: return "BEGIN DEFERRED";
case TransactionMode::Immediate: return "BEGIN IMMEDIATE";
case TransactionMode::Exclusive: return "BEGIN EXCLUSIVE";
}
throw std::logic_error("Invalid transaction mode: " + std::to_string(static_cast<std::underlying_type_t<TransactionMode>>(mode)));
}
}
void Rollback::operator()(sqlite3* db) const
{
if (db == nullptr)
return;
if (const int ec = sqlite3_exec(db, "ROLLBACK", nullptr, nullptr, nullptr); ec != SQLITE_OK)
Log(Debug::Warning) << "Failed to rollback SQLite3 transaction: " << std::string(sqlite3_errmsg(db));
Log(Debug::Debug) << "Failed to rollback SQLite3 transaction: " << sqlite3_errmsg(db) << " (" << ec << ")";
}
Transaction::Transaction(sqlite3& db)
Transaction::Transaction(sqlite3& db, TransactionMode mode)
: mDb(&db)
{
if (const int ec = sqlite3_exec(mDb.get(), "BEGIN", nullptr, nullptr, nullptr); ec != SQLITE_OK)
throw std::runtime_error("Failed to start transaction: " + std::string(sqlite3_errmsg(mDb.get())));
if (const int ec = sqlite3_exec(&db, getBeginStatement(mode), nullptr, nullptr, nullptr); ec != SQLITE_OK)
{
(void) mDb.release();
throw std::runtime_error("Failed to start transaction: " + std::string(sqlite3_errmsg(&db)) + " (" + std::to_string(ec) + ")");
}
}
void Transaction::commit()
{
if (const int ec = sqlite3_exec(mDb.get(), "COMMIT", nullptr, nullptr, nullptr); ec != SQLITE_OK)
throw std::runtime_error("Failed to commit transaction: " + std::string(sqlite3_errmsg(mDb.get())));
throw std::runtime_error("Failed to commit transaction: " + std::string(sqlite3_errmsg(mDb.get())) + " (" + std::to_string(ec) + ")");
(void) mDb.release();
}
}

View file

@ -12,10 +12,18 @@ namespace Sqlite3
void operator()(sqlite3* handle) const;
};
enum class TransactionMode
{
Default,
Deferred,
Immediate,
Exclusive,
};
class Transaction
{
public:
Transaction(sqlite3& db);
explicit Transaction(sqlite3& db, TransactionMode mode = TransactionMode::Default);
void commit();