Fix various player save issues (performance penalty on sql backends + bugs)
authorLoïc Blot <loic.blot@unix-experience.fr>
Fri, 4 Jan 2019 09:20:04 +0000 (10:20 +0100)
committerLoïc Blot <loic.blot@unix-experience.fr>
Fri, 4 Jan 2019 09:20:04 +0000 (10:20 +0100)
* PostgreSQL & SQLite3 doesn't setModified(false) on RemotePlayer, then player is saved on each server save call. This results in heavy useless writes.
* PostgreSQL & SQLite3 ack engine meta write whereas db commit hasn't been performed. If commit failed write has failed. We mustn't notify engine write is done.
* serializing player meta must not setModified(false) because it didn't ensure write has been done
* add RemotePlayer::on_successfull_save callback to do the flag update on a successful save

src/database/database-files.cpp
src/database/database-postgresql.cpp
src/database/database-sqlite3.cpp
src/remoteplayer.cpp
src/remoteplayer.h

index f425353483dc8f955e8c1ec695ca5656ced14a5c..b1c79c94a93fa4776dcad784dee3b3819df786e5 100644 (file)
@@ -105,7 +105,8 @@ void PlayerDatabaseFiles::savePlayer(RemotePlayer *player)
        if (!fs::safeWriteToFile(path, ss.str())) {
                infostream << "Failed to write " << path << std::endl;
        }
-       player->setModified(false);
+
+       player->on_successful_save();
 }
 
 bool PlayerDatabaseFiles::removePlayer(const std::string &name)
index eec838ef01519d63c294bab8249077c3b9715d9b..f5f8e3adf9b68cc3eb0920e876e3b7f0086f5466 100644 (file)
@@ -527,8 +527,9 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
                };
                execPrepared("save_player_metadata", 3, meta_values);
        }
-       sao->getMeta().setModified(false);
        endSave();
+
+       player->on_successful_save();
 }
 
 bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
index aa156bbbd0b11ca974cd9011fd0c5186da64c08d..7a79fb1875144ecf1aabc19b0a1fc8a2179a02c6 100644 (file)
@@ -528,9 +528,10 @@ void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player)
                sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_add), SQLITE_DONE);
                sqlite3_reset(m_stmt_player_metadata_add);
        }
-       sao->getMeta().setModified(false);
 
        endSave();
+
+       player->on_successful_save();
 }
 
 bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
index d54caf924adc462e056ccbc2ed5c9d0f5418d96a..18749d5ff0d64e83975d47f95e9294a99655eacf 100644 (file)
@@ -79,8 +79,6 @@ void RemotePlayer::serializeExtraAttributes(std::string &output)
        }
 
        output = fastWriteJson(json_root);
-
-       m_sao->getMeta().setModified(false);
 }
 
 
@@ -225,3 +223,10 @@ const RemotePlayerChatResult RemotePlayer::canSendChatMessage()
        m_chat_message_allowance -= 1.0f;
        return RPLAYER_CHATRESULT_OK;
 }
+
+void RemotePlayer::on_successful_save()
+{
+       setModified(false);
+       if (m_sao)
+               m_sao->getMeta().setModified(false);
+}
index ed0f21b424c07432051664fea1533728f32ae8c3..212741df8de16aad5e2b5ae711fbc21a6268a845 100644 (file)
@@ -139,6 +139,8 @@ public:
 
        void setPeerId(session_t peer_id) { m_peer_id = peer_id; }
 
+       void on_successful_save();
+
 private:
        /*
                serialize() writes a bunch of text that can contain