-
Notifications
You must be signed in to change notification settings - Fork 75
feat: Support Keyspace #2454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support Keyspace #2454
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (1.23%) is below the target coverage (20.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #2454 +/- ##
===========================================
- Coverage 79.95% 79.55% -0.41%
===========================================
Files 384 385 +1
Lines 16037 16118 +81
Branches 8387 8438 +51
===========================================
- Hits 12823 12822 -1
- Misses 1925 2006 +81
- Partials 1289 1290 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
kuznetsss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but let's wait for an approval from @godexsoft
godexsoft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not thoroughly reviewed the code because i don't yet understand why we need so many changes if keyspaces is supposed to be compatible with cassandra?
In general i'm not a fan of adding custom stuff to the cassandra backend.. if we need to have custom behaviour maybe we should create a separate backend and inherit where we can, modify where we need.
|
@godexsoft For some context, Keyspace is compatible with Cassandra but there's a few limitations. Specifically the places where we had: To tackle this, I split the queries that contains the above into 2 queries. ie, 2 queries will be equivalent to the 1 from before. The goal of this PR is to get Clio to run with Keyspace while those running cassandra/scylladb would work the exact same. |
mathbunnyru
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments to mostly make the code more readable and less error-prone
godexsoft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few comments, nothing major, should be easy enough to fix.
For the Schema inheritance idea let's discuss. I think we can still do slightly better than having two copies of the schema with modifications
godexsoft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
| backend = std::make_shared<data::cassandra::CassandraBackend>( | ||
| data::cassandra::SettingsProvider{cfg}, cache, readOnly | ||
| ); | ||
| if (cfg.getValueView("provider").asString() == toString(cassandra::impl::Provider::Keyspace)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to do it vice-versa, have a function to convert string to a enum, and then compare enum values
| * @tparam SettingsProviderType The settings provider type to use | ||
| * @tparam ExecutionStrategyType The execution strategy type to use | ||
| * @tparam FetchLedgerCacheType The ledger header cache type to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove to use in the end, it's not helpful
| // !range_.has_value() means the table 'ledger_range' is not populated; | ||
| // This would be the first write to the table. | ||
| // In this case, insert both min_sequence/max_sequence range into the table. | ||
| if (not(range_.has_value())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, using not this way ( not(x) instead of not x ) is something new, let's not do it 😆
| executor_.writeSync(schema_->insertLedgerRange, false, ledgerSequence_); | ||
| executor_.writeSync(schema_->insertLedgerRange, true, ledgerSequence_); | ||
| } | ||
|
|
||
| if (not this->executeSyncUpdate(schema_->updateLedgerRange.bind(ledgerSequence_, true, ledgerSequence_ - 1))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably add inline comments to a boolean variable like executor_.writeSync(schema_->insertLedgerRange, /* some_opt_name = */ false, ledgerSequence_);
| // Keyspace and ScyllaDB uses the same logic for taxon-filtered queries | ||
| nftIDs = fetchNFTIDsByTaxon(issuer, *taxon, limit, cursorIn, yield); | ||
| } else { | ||
| // --- Amazon Keyspaces Workflow for non-taxon queries --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for --- in the comment, I don't think we do that
| if (auto const res = handle_.connect(); not res) | ||
| throw std::runtime_error("Could not connect to database: " + res.error()); | ||
|
|
||
| if (not readOnly) { | ||
| if (auto const res = handle_.execute(schema_.createKeyspace); not res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
| throw std::runtime_error("Could not create keyspace: " + res.error()); | ||
| } | ||
|
|
||
| if (auto const res = handle_.executeEach(schema_.createSchema); not res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
| if (auto const res = executor_.read(yield, schema_->selectLatestLedger); res) { | ||
| if (auto const& result = res.value(); result) { | ||
| if (auto const maybeValue = result.template get<uint32_t>(); maybeValue) | ||
| return maybeValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
| {"database.cassandra.port", ConfigValue{ConfigType::Integer}.optional()}, | ||
| {"database.cassandra.keyspace", | ||
| ConfigValue{ConfigType::String}.defaultValue(TestGlobals::instance().backendKeyspace)}, | ||
| {"database.cassandra.provider", ConfigValue{ConfigType::String}.defaultValue("cassandra")}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move it to a variable (and in places below as well)
| enum class Provider { Cassandra, Keyspace }; | ||
|
|
||
| inline std::string | ||
| toString(Provider provider) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will have a function providerFromString instead, and this function could be removed
|
Left some comments, mostly about style When you use optional/expected, I suggest using this pattern ( if (my_opt.has_value()) {
use_it(*my_opt);
} |
Support AWS Keyspace queries