Modularise RelationalDB - #6224
Conversation
dd1a1a9 to
cf67641
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #6224 +/- ##
=======================================
Coverage 79.9% 79.9%
=======================================
Files 840 840
Lines 65522 65508 -14
Branches 7251 7250 -1
=======================================
- Hits 52355 52353 -2
+ Misses 13167 13155 -12
🚀 New features to boost your workflow:
|
| std::uint32_t minLedger; | ||
| std::uint32_t maxLedger; |
There was a problem hiding this comment.
This is just moved from src/xrpld/app/rdb/RelationalDatabase.h. I think we can have a separate PR for optimisations like this.
There was a problem hiding this comment.
Will be fixed in RIPD-4880.
| using AccountTx = | ||
| std::pair<std::shared_ptr<Transaction>, std::shared_ptr<TxMeta>>; | ||
| using AccountTxs = std::vector<AccountTx>; | ||
| using txnMetaLedgerType = std::tuple<Blob, Blob, std::uint32_t>; |
There was a problem hiding this comment.
Better to avoid pairs and tuples if possible because they decrease readability
There was a problem hiding this comment.
Will be fixed in RIPD-4880.
| closeTransactionDB() = 0; | ||
| }; | ||
|
|
||
| template <class T, class C> |
There was a problem hiding this comment.
Please add concepts on T and C to improve compilation errors on misuse. Probably std::is_arithmetic and that std::is_convertible.
There was a problem hiding this comment.
Will be fixed in RIPD-4880.
c9dbea1 to
8dc9483
Compare
922752a to
17020f9
Compare
572f5b2 to
650dc4f
Compare
eebaec1 to
860e22d
Compare
0dd8b72 to
b3f0361
Compare
860e22d to
39f6e3a
Compare
b3f0361 to
c0bbbb2
Compare
39f6e3a to
e436dff
Compare
godexsoft
left a comment
There was a problem hiding this comment.
Looks fine from refactoring perspective except for the questions i left. I agree with @kuznetsss and there are more obvious things we should fix but i'd leave that for another pr.
| auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase()); | ||
| if (!db) | ||
| Throw<std::runtime_error>("Failed to get relational database"); | ||
| auto& db = app.getRelationalDatabase(); |
There was a problem hiding this comment.
Are we always guaranteed to have a db now? is there no way to start xrpld without a relational db? why was it possible before, do you know?
There was a problem hiding this comment.
We're always guaranteed to have a db even before the change. You can see from the code that we actually used to return a reference instead of a pointer.
The reason why we used to check if db is null is that we had to perform a dyanmic_cast on it, and the reason why we needed to dynamic_cast was the bad design.
We had 3 classes before the change, RelationDatabase, SQLiteDatabase, SQLiteDatabaseImp. The first two are abstract classes, and the last one is a concrete class. RelationDatabase defines some abstract methods, and then SQLiteDatabase inherits from it, adding more abstract methods, and finally, SQLiteDatabaseImp implements all the methods. We should just merge SQLiteDatabase into RelationDatabase because in my opinion, it makes no sense to have a SQLiteDatabase interface that adds some methods but hide that interface under the hood if the business logic needs those methods, and the name creates more confusion when putting it together with SQLiteDatabaseImp as SQLiteDatabase already sounds like the implementation of RelationDatabase.
Another funny thing is that RelationalDatabase::init checks if the rdb backend is sqlite, and it throws an exception if not, which further suggests that there's no chance to have anything other than SQLiteDatabase.
There was a problem hiding this comment.
Ok i see the reasoning. It makes more sense to store and return by interface in the service locator. This will allow us to add another implementation in the future, if we ever need one 👍
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
9dbe6b9 to
6ea2646
Compare
godexsoft
left a comment
There was a problem hiding this comment.
Good for modularization 👍
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
The rdb module was not properly designed, which is fixed in this change. The module had three classes: 1) The abstract class `RelationalDB`. 2) The abstract class `SQLiteDatabase`, which inherited from `RelationalDB` and added some pure virtual methods. 3) The concrete class `SQLiteDatabaseImp`, which inherited from `SQLiteDatabase` and implemented all methods. The updated code simplifies this as follows: * The `SQLiteDatabaseImp` has become `SQLiteDatabase`, and * The former `SQLiteDatabase `has merged with `RelationalDatabase`.
High Level Overview of Change
This PR modularise xrpld/rdb
Context of Change
The rdb module was not properly designed. We have 3 classes:
RelationalDBand adds some more pure virtual methodsSQLiteDatabaseand implements all the methods.The factory function
RelationalDB::initmethod checks the config and only returns an instance of SQLiteDatabaseImp, we can see in the code base that we are doingdynamic_cast<SQLiteDatabase*>(app.getRelationalDb())everywhere.To address this problem and help modularise app/tx, the rdb module needs to be refactored and moved to libxrpl.
This PR is part of the modularisation of the transactors. See all PRs here:
#6222
#6223
#6224
#6225
#6226
#6227
#6228
Type of Change
.gitignore, formatting, dropping support for older tooling)API Impact
libxrplchange (any change that may affectlibxrplor dependents oflibxrpl)