feat(namespace-dir): implement alter_transaction for DirectoryNamespace#6974
Conversation
|
ACTION NEEDED The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification. For details on the error please inspect the "PR Title Check" action. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
6a68586 to
c70209c
Compare
c70209c to
8ffc563
Compare
96425c7 to
949f86a
Compare
Implement the alter_transaction method for DirectoryNamespace, which allows altering a transaction's status and properties. This completes one of the remaining unimplemented methods in the LanceNamespace trait. The implementation supports: - SetStatusAction: change transaction status (Queued/Running/Succeeded/Failed/Canceled) - SetPropertyAction: set transaction properties with Overwrite/Fail/Skip modes - UnsetPropertyAction: remove transaction properties with Skip/Fail modes All actions in a request are applied atomically - either all succeed or the operation fails with an appropriate error. Tests added: - test_alter_transaction_set_status - test_alter_transaction_set_property - test_alter_transaction_set_property_fail_mode - test_alter_transaction_unset_property - test_alter_transaction_invalid_status - test_alter_transaction_not_found - test_alter_transaction_missing_id
949f86a to
363dc69
Compare
| Ok(Self::transaction_response(version, &transaction)) | ||
| } | ||
|
|
||
| async fn alter_transaction( |
There was a problem hiding this comment.
Did you persist or save the changes?
There was a problem hiding this comment.
Did you persist or save the changes?
I updated it.
Previously, alter_transaction only mutated properties in memory and
returned them, so subsequent describe_transaction / alter_transaction
calls could not observe the modifications. Since Lance embeds the
Transaction into the manifest and treats it as immutable, we cannot
rewrite the transaction file in place.
Introduce a namespace-owned sidecar file at
{table}/_alter_transactions/{uuid}.json that records the accumulated
alterations (status, added/overwritten properties, tombstoned
properties). describe_transaction and follow-up alter_transaction
calls now merge the sidecar on top of the immutable transaction so the
altered state survives across calls.
Also treat uuid/version/read_version/operation/tag as reserved keys
that cannot be modified, since they are derived from the immutable
Transaction metadata.
- Remove useless conversion .into() on lance_core::Error - Use RESERVED_KEYS.contains(&key) instead of iter().any()
|
|
||
| [features] | ||
| default = ["dir-aws", "dir-azure", "dir-gcp", "dir-oss", "dir-huggingface"] | ||
| rest = ["dep:reqwest", "dep:serde"] |
There was a problem hiding this comment.
Do we need to change this file?
| create_scalar_table(&namespace, "users").await; | ||
| let transaction_id = create_scalar_index(&namespace, "users", "users_id_idx").await; | ||
|
|
||
| if let Some(txn_id) = transaction_id { |
There was a problem hiding this comment.
This style may cause false positives if it is None. It would be better to use expect(...) or assert!(transaction_id.is_some())
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_alter_transaction_set_property_fail_mode() { |
There was a problem hiding this comment.
Using the reserved field uuid as the key results in zero coverage of the mode='Fail' branch.
- Cargo.toml: revert to original by dropping serde derive; sidecar now serializes/deserializes via serde_json::Value manually, so no changes to Cargo.toml are needed. - Replace 'if let Some(txn_id) = transaction_id' with expect(...) in five alter_transaction tests to avoid silent false-positive passes. - test_alter_transaction_set_property_fail_mode: use a non-reserved 'custom_key' (set once, then set again with mode='Fail') so the test actually exercises the mode='Fail' branch instead of tripping the reserved-key guard first.
Adopt the same pattern used in dir/manifest.rs, which relies on the built-in Serialize/Deserialize impls for Option<String>, HashMap<String, String> and HashSet<String> transitively provided by serde_json. - Replace hand-rolled serde_json::Value match with a single serde_json::from_slice::<Map<String, Value>> plus per-field from_value calls. - Fold the two-step to_json + serde_json::to_vec into a single to_json_bytes helper. - No Cargo.toml changes; still compiles under --no-default-features --features dir-aws where serde is optional. Net effect: -81 lines in dir.rs, all 8 alter_transaction tests still pass, cargo fmt/clippy clean.
Closes #6973
Implement the
alter_transactionmethod forDirectoryNamespace, whichallows altering a transaction's status and properties. This completes one
of the remaining unimplemented methods in the
LanceNamespacetrait.Supported actions
SetStatusAction: change transaction status (Queued / Running / Succeeded / Failed / Canceled)SetPropertyAction: set transaction properties withOverwrite/Fail/SkipmodesUnsetPropertyAction: remove transaction properties withSkip/FailmodesAll actions in a request are applied atomically — either all succeed, or
the operation fails with an appropriate error.
Persistence via sidecar
Since Lance embeds the
Transactioninto the manifest and treats it asimmutable, we cannot rewrite the transaction file in place. Previously,
alter_transactiononly mutated properties in memory and returned them,so subsequent
describe_transaction/alter_transactioncalls couldnot observe the modifications.
To fix this, alterations are now persisted in a namespace-owned sidecar
file at:
This sidecar records the accumulated alterations (status, added /
overwritten properties, tombstoned properties).
describe_transactionand follow-up
alter_transactioncalls merge the sidecar on top of theimmutable transaction, so the altered state survives across calls.
Reserved keys
uuid,version,read_version,operation, andtagare treated asreserved keys that cannot be modified via
alter_transaction, since theyare derived from the immutable
Transactionmetadata. They are stillsurfaced in the response for the caller's convenience.
Tests added
test_alter_transaction_set_statustest_alter_transaction_set_propertytest_alter_transaction_set_property_fail_modetest_alter_transaction_unset_propertytest_alter_transaction_invalid_statustest_alter_transaction_not_foundtest_alter_transaction_missing_id