Allow specifying database waiting timeout

This commit is contained in:
Benau 2019-07-08 00:26:11 +08:00
parent effe4a401c
commit 5ac5932d3a
3 changed files with 12 additions and 2 deletions

View File

@ -153,6 +153,9 @@ The current server configuration xml looks like this:
<!-- Database filename for sqlite to use, it can be shared for all servers created in this machine, and stk will create specific table for each server. You need to create the database yourself first, see NETWORKING.md for details -->
<database-file value="stkservers.db" />
<!-- Specified in millisecond for maximum time waiting in sqlite3_busy_handler. You may need a higher value if your database is shared by many servers or having a slow hard disk. -->
<database-timeout value="1000" />
<!-- Ip ban list table name, you need to create the table first, see NETWORKING.md for details, empty to disable. This table can be shared for all servers if you use the same name. -->
<ip-ban-table value="ip_ban" />

View File

@ -191,8 +191,8 @@ void ServerLobby::initDatabase()
}
sqlite3_busy_handler(m_db, [](void* data, int retry)
{
// Maximum 1 second total retry time
if (retry < 10)
int retry_count = ServerConfig::m_database_timeout / 100;
if (retry < retry_count)
{
sqlite3_sleep(100);
// Return non-zero to let caller retry again

View File

@ -333,6 +333,13 @@ namespace ServerConfig
"for each server. You need to create the database yourself first, see "
"NETWORKING.md for details"));
SERVER_CFG_PREFIX IntServerConfigParam m_database_timeout
SERVER_CFG_DEFAULT(IntServerConfigParam(1000,
"database-timeout",
"Specified in millisecond for maximum time waiting in "
"sqlite3_busy_handler. You may need a higher value if your database "
"is shared by many servers or having a slow hard disk."));
SERVER_CFG_PREFIX StringServerConfigParam m_ip_ban_table
SERVER_CFG_DEFAULT(StringServerConfigParam("ip_ban",
"ip-ban-table",