lifecycle improvement for none-versionning buckets#9160
Conversation
WalkthroughAdds MDStore.delete_objects_by_query to mark objects deleted via SQL for PostgreSQL, changes MDStore.find_objects to return a Promise, updates object_server to use the new bulk-delete path for non-versioned Postgres buckets, and adds integration tests for the new method; minor test formatting fixes elsewhere. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ObjectServer
participant MDStore
participant PostgreSQL
Client->>ObjectServer: Delete objects by filter request
alt bucket.versioning == DISABLED && DB != mongodb
ObjectServer->>MDStore: delete_objects_by_query(params with return_results=true)
MDStore->>PostgreSQL: Execute CTE + UPDATE to mark matched objects deleted
PostgreSQL-->>MDStore: Return updated rows (if requested)
MDStore-->>ObjectServer: Return deleted object rows
else
ObjectServer->>MDStore: find_objects(params)
MDStore-->>ObjectServer: Return object list
ObjectServer->>ObjectServer: delete_multiple_objects(objects) (per-object)
end
ObjectServer-->>Client: Respond with deletion results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Path-based instructions (1)src/test/**/*.*⚙️ CodeRabbit Configuration File
Files:
🧬 Code Graph Analysis (2)src/test/integration_tests/api/s3/test_lifecycle.js (2)
src/server/object_services/md_store.js (4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (6)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
e064263 to
a2c2eb3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/server/object_services/md_store.js(2 hunks)src/server/object_services/object_server.js(3 hunks)src/test/integration_tests/api/s3/test_lifecycle.js(17 hunks)src/test/integration_tests/db/test_md_store.js(4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/test/**/*.*
⚙️ CodeRabbit Configuration File
src/test/**/*.*: Ensure that the PR includes tests for the changes.
Files:
src/test/integration_tests/api/s3/test_lifecycle.jssrc/test/integration_tests/db/test_md_store.js
🧬 Code Graph Analysis (2)
src/server/object_services/object_server.js (2)
config.js (2)
config(7-7)_(13-13)src/server/object_services/md_store.js (2)
config(28-28)_(7-7)
src/test/integration_tests/db/test_md_store.js (2)
src/test/integration_tests/api/s3/test_lifecycle.js (2)
mocha(10-10)config(20-20)src/server/object_services/md_store.js (1)
config(28-28)
🔇 Additional comments (15)
src/test/integration_tests/api/s3/test_lifecycle.js (4)
290-299: LGTM! Array formatting improved for readability.The reformatting of array literals from multi-line to single-line format improves code compactness and readability without affecting functionality.
Also applies to: 330-339, 494-502, 532-540, 571-582
627-627: Good catch on the typo corrections.The corrections from "lifecyle" to "lifecycle" in test case names improve consistency and correctness.
Also applies to: 639-639, 651-651, 660-660, 669-669, 678-678, 686-686, 695-695, 704-704, 713-713, 721-721, 729-729, 737-737, 744-744
406-406: String formatting improved.The formatting change for the assertion message improves readability while maintaining the same functional behavior.
1-900: Incorrect: delete_objects_by_query test coverage already existsTests for the new
delete_objects_by_querymethod are present insrc/test/integration_tests/db/test_md_store.js(see themocha.it('delete_objects_by_query – …')cases). You can disregard the missing-tests suggestion.Likely an incorrect or invalid review comment.
src/server/object_services/md_store.js (2)
634-634: Correct return type annotation.Good fix! The
find_objectsmethod is async and should returnPromise<nb.ObjectMD[]>rather thannb.ObjectMD[].
698-753: Well-implemented bulk deletion method with proper security measures.The new
delete_objects_by_querymethod effectively addresses the PR objective of improving lifecycle performance for non-versioned buckets. Key strengths:
- Uses CTE pattern for efficient bulk operations
- Properly parameterized query prevents SQL injection for the timestamp
- Comprehensive filtering options (key regex, size, tagging, creation time)
- Restricts to non-versioned objects (
version_enabled IS NULL)- Optional result return for flexibility
The implementation correctly uses PostgreSQL-specific features like jsonb operators and regex matching.
However, there are a few considerations:
#!/bin/bash # Description: Verify the method is only called for PostgreSQL databases # Expected: Find conditional usage based on DB_TYPE echo "Checking for PostgreSQL-specific usage of delete_objects_by_query..." rg -A 5 -B 5 "delete_objects_by_query" src/server/src/server/object_services/object_server.js (4)
975-985: LGTM!Query object construction is well-structured with proper regex escaping for security. The parameter mapping is clear and consistent.
986-1005: Excellent performance optimization with proper fallback logic.The conditional use of
delete_objects_by_queryfor PostgreSQL non-versioned buckets is a well-designed optimization. The fallback to individual deletions ensures compatibility across all scenarios.The TODOs appropriately acknowledge current limitations for versioned buckets and batch processing.
1015-1015: Good defensive programming practice.The safety check prevents potential null/undefined access errors when
delete_resultsis not initialized (which occurs when using the new bulk deletion path).
986-987: LGTM!Variable declarations are appropriate with proper initialization in both conditional branches.
src/test/integration_tests/db/test_md_store.js (5)
53-72: Good test data setup for shared usage across test cases.The shared test objects and timestamp calculations are well-structured and will support consistent testing across the new test cases.
73-90: Comprehensive test for key-based filtering.The test correctly validates regex key filtering functionality with proper database type checking and result verification.
92-116: Excellent test coverage for time-based filtering.The test effectively validates
max_create_timefiltering with different scenarios, ensuring the functionality works correctly across various time thresholds.
118-136: Good test coverage for limit functionality.The test correctly validates that the limit parameter restricts the number of objects deleted as expected.
228-314: Good formatting improvements.The consistent indentation and spacing in the parts array improves code readability and maintainability.
dannyzaken
left a comment
There was a problem hiding this comment.
maybe attach to the PR the EXPLAIN output for the queries for future reference
Signed-off-by: jackyalbo <jacky.albo@gmail.com>
a2c2eb3 to
c013518
Compare
| let delete_results; | ||
| let objects; | ||
| // TODO: Add support to delete_objects_by_query also for versioning or add another function to support versioning. | ||
| if (req.bucket.versioning === 'DISABLED' && config.DB_TYPE !== 'mongodb') /* only for postgres */ { |
There was a problem hiding this comment.
Do we still need config.DB_TYPE !== 'mongodb' ?
Is it possible to have DB_TYPE as mongodb?
Maybe it is used for the tests.
If it is, we should probably remove it.
There was a problem hiding this comment.
Let's wait until we stop supporting MongoDB; then we will delete it, and it will be easy to find that we need to update this place. It is only for testing for now.
Describe the Problem
As most of the times when lifecycle is set, the bucket doesn't have versioning enabled, we would like to add a special case for handling deleting the only key in the bucket that fits the lifecycle rule.
Before the change, we would find 1K keys that fit and then go one by one and delete them from the DB. With this fix, it will be replaced with 1 DB query.
Issues: Fixed #xxx / Gap #xxx
after the fix - this is the explain result:
Testing Instructions:
Summary by CodeRabbit
New Features
Bug Fixes
Tests