-
Notifications
You must be signed in to change notification settings - Fork 0
[Phase 2.1] Implement OSS/S3 backend using object_store #32
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
Conversation
This completes the implementation of the OSS/S3 storage backend using the object_store crate for Alibaba Cloud OSS and other S3-compatible storage services. Key changes: - Implemented OssConfig struct with builder pattern for configuration - Implemented OssStorage with full Storage trait implementation - Added OssWriter for buffered uploads with automatic flush - Support for optional prefix, region, and internal endpoint configuration - Updated StorageFactory to use OssConfig Closes #13
Greptile OverviewGreptile SummaryImplemented OSS/S3 storage backend using Key changes:
Critical issues:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Application
participant Factory as StorageFactory
participant Config as OssConfig
participant OssStorage as OssStorage
participant Runtime as Tokio Runtime
participant ObjectStore as object_store
participant OSS as OSS/S3 Backend
App->>Factory: create("oss://bucket/path")
Factory->>Factory: parse URL
Factory->>Factory: load credentials from env
Factory->>Config: new(bucket, endpoint, key_id, key_secret)
Factory->>Config: with_region(region)
Factory->>OssStorage: with_config(config)
OssStorage->>Runtime: create current_thread runtime
OssStorage->>ObjectStore: AmazonS3Builder::new()
ObjectStore->>ObjectStore: configure credentials & endpoint
ObjectStore-->>OssStorage: Arc<dyn ObjectStore>
OssStorage-->>Factory: OssStorage instance
Factory-->>App: Arc<dyn Storage>
Note over App,OSS: Read Operation
App->>OssStorage: reader(path)
OssStorage->>ObjectStore: get(key)
ObjectStore->>Runtime: block_on(async get)
Runtime->>OSS: HTTP GET request
OSS-->>Runtime: object bytes
Runtime-->>ObjectStore: GetResult
ObjectStore->>Runtime: block_on(bytes())
Runtime-->>OssStorage: Vec<u8>
OssStorage-->>App: Cursor<Vec<u8>>
Note over App,OSS: Write Operation
App->>OssStorage: writer(path)
OssStorage-->>App: OssWriter
App->>OssWriter: write(data)
OssWriter->>OssWriter: buffer.extend(data)
opt buffer > 100MB
OssWriter->>ObjectStore: put(key, payload)
ObjectStore->>Runtime: block_on(async put)
Runtime->>OSS: HTTP PUT request
OSS-->>Runtime: success
end
App->>OssWriter: flush()
OssWriter->>ObjectStore: put(key, payload)
ObjectStore->>Runtime: block_on(async put)
Runtime->>OSS: HTTP PUT request
OSS-->>Runtime: success
Runtime-->>OssWriter: Ok()
|
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.
3 files reviewed, 5 comments
| if self.buffer.len() > self.max_buffer_size { | ||
| self.upload().map_err(|e| std::io::Error::other(format!("Upload failed: {}", e)))?; | ||
| } |
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.
auto-upload clears buffer but continues accepting writes
After auto-uploading at 100MB, buffer is cleared and uploaded=true, but subsequent write() calls will append to buffer without uploading again. This means data after 100MB may be lost.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/storage/oss.rs
Line: 474:476
Comment:
auto-upload clears buffer but continues accepting writes
After auto-uploading at 100MB, buffer is cleared and `uploaded=true`, but subsequent `write()` calls will append to buffer without uploading again. This means data after 100MB may be lost.
How can I resolve this? If you propose a fix, please make it concise.Added additional tests to improve coverage: - test_oss_config_with_internal_endpoint - test_oss_config_full_key_empty_path - test_oss_config_endpoint_url_already_http - test_chrono_to_system_time_conversion - test_convert_metadata (with metadata conversion) - test_convert_metadata_large_file (5GB file handling) Improved coverage from 27.83% to 43.09% regions (+15.26%) and from 22.41% to 34.38% functions (+11.97%)
After auto-uploading when buffer exceeds max size, reset uploaded=false so subsequent writes are uploaded on flush/drop. This fixes data loss when writing more than max_buffer_size bytes.
Summary
Implements full OSS/S3 storage backend using the
object_storecrate for Alibaba Cloud OSS and other S3-compatible storage services.Changes
Storagetrait implementation with reader, writer, exists, size, metadata, list, delete, copyOssConfigfor instantiationTest plan
-D warnings--features cloud-storagecargo fmtEnvironment Variables
OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET, OSS_ENDPOINT (or ALIYUN_* prefixes)
URL Format
oss://bucket/path/to/file.txt?endpoint=oss-cn-hangzhou.aliyuncs.com&internal=true
Closes #13