Add PostgreSQL support for rollback backend#16757
Open
johnnyjoy wants to merge 14 commits intoluanti-org:masterfrom
Open
Add PostgreSQL support for rollback backend#16757johnnyjoy wants to merge 14 commits intoluanti-org:masterfrom
johnnyjoy wants to merge 14 commits intoluanti-org:masterfrom
Conversation
sfan5
requested changes
Dec 18, 2025
Member
sfan5
left a comment
There was a problem hiding this comment.
The rollback code is a bit neglected, but surprisingly many people still use it and I guess adding another backend is okay.
sfan5
reviewed
Dec 25, 2025
SmallJoker
reviewed
Dec 28, 2025
SmallJoker
reviewed
Dec 31, 2025
058d001 to
ddcb9a3
Compare
94cb80a to
65adda1
Compare
067d444 to
2c7b830
Compare
8c55343 to
64db4d7
Compare
8977aa3 to
e98362c
Compare
e98362c to
6316eaa
Compare
6316eaa to
b060d38
Compare
767a383 to
ac8bbbc
Compare
SmallJoker
reviewed
Mar 1, 2026
| @@ -0,0 +1,815 @@ | |||
| // Luanti | |||
Member
There was a problem hiding this comment.
Note to reviewers: as of 2026-03-01, this file is identical to the old rollback.cpp but with renamed class name. (This is good. Shared code can be unified later.)
| @@ -0,0 +1,88 @@ | |||
| // Luanti | |||
Member
There was a problem hiding this comment.
Note to reviewers: as of 2026-03-01, this file is identical to the old rollback.h but with renamed class name.
Extract the large cache loading blocks from RollbackManagerPostgreSQL constructor into loadActorCache() and loadNodeCache() helper methods. This reduces the constructor from ~33 lines to 5 lines, addressing sfan5's feedback about large code blocks.
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
Improve error handling in Server::createRollbackManager - Throw exception if world.mt cannot be read, matching openModStorageDatabase pattern - Remove unused backend_source variable and simplify logging - Simplify backend selection using world_mt.getNoEx() instead of if-else block Enhance error messages and help output - Add Server::getRollbackBackends() to dynamically list available backends - Use dynamic backend list in error message for unsupported backends - Add rollback backends to print_help() output in main.cpp - Remove redundant USE_POSTGRESQL=OFF specific error message Improve destructor safety and consistency - Move db != nullptr check from SQLite destructor to flush() method - Move initialized() check from PostgreSQL destructor to flush() method - Ensures consistent safety checks across both backends Restore spacing alignment for readability - Add space padding after sqlite3_bind_* function names - Matches existing pattern in rollback_sqlite3.cpp Rename RollbackManager to RollbackMgr for line length compliance - Use RollbackMgr abbreviation following existing codebase patterns - Rename RollbackManager → RollbackMgr - Rename RollbackManagerSQLite3 → RollbackMgrSQLite3 - Rename RollbackManagerPostgreSQL → RollbackMgrPostgreSQL - Break long function signatures to ensure all lines are under 95 characters
…ng bool The original code would throw std::out_of_range when substr() was called with npos, making the fallback code that bound 0,0,0 unreachable dead code. This change makes parseNodemetaLocation() throw std::invalid_argument on invalid format, matching the original behavior and eliminating the dead code. Changes: Change parseNodemetaLocation() signature from bool to void Throw std::invalid_argument exceptions instead of returning false Remove unreachable fallback blocks in SQLite and PostgreSQL backends Add #include <stdexcept> to rollback.cpp This addresses SmallJoker's feedback.
Address SmallJoker's request for unit tests to verify that parseNodemetaLocation() correctly throws std::invalid_argument on invalid format. Tests cover: Valid format parsing (basic, negative, zero coordinates) Invalid format exceptions (missing prefix, missing commas, empty string)
7bb1370 to
fe6a7e5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds PostgreSQL as an optional backend for the rollback system, complementing the existing SQLite3 implementation. The rollback backend is configurable per-world via
rollback_backendinworld.mt, defaulting tosqlite3when unset.Changes
RollbackMgrPostgreSQL) with feature parity to SQLite3pgsql_rollback_connectionwhen PostgreSQL is selected (no fallback to map backend)RollbackMgr) to eliminate code duplication between backendsServer::init()intoServer::createRollbackManager()doc/world_format.mdandbuiltin/settingtypes.txtupdatedConfiguration
Set in
world.mt:rollback_backend = postgresql(orsqlite3)pgsql_rollback_connection = "host=... dbname=..."(required when using PostgreSQL)Development Process
This PR was developed with assistance from Cursor and LLM tools for code generation and refactoring. All changes have been reviewed against project coding standards, and feedback from maintainers (sfan5, SmallJoker) has been incorporated throughout the development process.