Skip to content

Commit

Permalink
Fix various player save issues (performance penalty on sql backends +…
Browse files Browse the repository at this point in the history
… bugs)

* 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
  • Loading branch information
nerzhul committed Jan 4, 2019
1 parent 0717719 commit c1d7dbf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/database/database-files.cpp
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/database/database-postgresql.cpp
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/database/database-sqlite3.cpp
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/remoteplayer.cpp
Expand Up @@ -79,8 +79,6 @@ void RemotePlayer::serializeExtraAttributes(std::string &output)
}

output = fastWriteJson(json_root);

m_sao->getMeta().setModified(false);
}


Expand Down Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions src/remoteplayer.h
Expand Up @@ -139,6 +139,8 @@ class RemotePlayer : public Player

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
Expand Down

0 comments on commit c1d7dbf

Please sign in to comment.