Skip to content

Commit 5ac5932

Browse files
committed
Allow specifying database waiting timeout
1 parent effe4a4 commit 5ac5932

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

NETWORKING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ The current server configuration xml looks like this:
153153
<!-- 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 -->
154154
<database-file value="stkservers.db" />
155155

156+
<!-- 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. -->
157+
<database-timeout value="1000" />
158+
156159
<!-- 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. -->
157160
<ip-ban-table value="ip_ban" />
158161

src/network/protocols/server_lobby.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ void ServerLobby::initDatabase()
191191
}
192192
sqlite3_busy_handler(m_db, [](void* data, int retry)
193193
{
194-
// Maximum 1 second total retry time
195-
if (retry < 10)
194+
int retry_count = ServerConfig::m_database_timeout / 100;
195+
if (retry < retry_count)
196196
{
197197
sqlite3_sleep(100);
198198
// Return non-zero to let caller retry again

src/network/server_config.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ namespace ServerConfig
333333
"for each server. You need to create the database yourself first, see "
334334
"NETWORKING.md for details"));
335335

336+
SERVER_CFG_PREFIX IntServerConfigParam m_database_timeout
337+
SERVER_CFG_DEFAULT(IntServerConfigParam(1000,
338+
"database-timeout",
339+
"Specified in millisecond for maximum time waiting in "
340+
"sqlite3_busy_handler. You may need a higher value if your database "
341+
"is shared by many servers or having a slow hard disk."));
342+
336343
SERVER_CFG_PREFIX StringServerConfigParam m_ip_ban_table
337344
SERVER_CFG_DEFAULT(StringServerConfigParam("ip_ban",
338345
"ip-ban-table",

0 commit comments

Comments
 (0)