Skip to content

Commit

Permalink
feat: s3 conditional puts for r2, minio, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ion-elgreco committed Aug 22, 2024
1 parent 57acc06 commit 480e8b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion crates/aws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{
};
use tracing::debug;

use deltalake_core::logstore::{logstores, LogStore, LogStoreFactory};
use deltalake_core::logstore::{default_logstore, logstores, LogStore, LogStoreFactory};
use deltalake_core::storage::{factories, url_prefix_handler, ObjectStoreRef, StorageOptions};
use deltalake_core::{DeltaResult, Path};
use url::Url;
Expand All @@ -49,6 +49,15 @@ impl LogStoreFactory for S3LogStoreFactory {
) -> DeltaResult<Arc<dyn LogStore>> {
let store = url_prefix_handler(store, Path::parse(location.path())?);

// With conditional put in S3-like API we can use the deltalake default logstore which use PutIfAbsent
if options
.0
.contains_key(AmazonS3ConfigKey::ConditionalPut.as_ref())
{
debug!("S3LogStoreFactory has been asked to create a default LogStore where the underlying store has Conditonal Put enabled - no locking provider required");
return Ok(default_logstore(store, location, options));
}

if options
.0
.contains_key(AmazonS3ConfigKey::CopyIfNotExists.as_ref())
Expand Down
5 changes: 4 additions & 1 deletion crates/aws/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ fn aws_storage_handler(
store: ObjectStoreRef,
options: &StorageOptions,
) -> DeltaResult<ObjectStoreRef> {
// If the copy-if-not-exists env var is set, we don't need to instantiate a locking client or check for allow-unsafe-rename.
// If the copy-if-not-exists env var is set or ConditionalPut is set, we don't need to instantiate a locking client or check for allow-unsafe-rename.
if options
.0
.contains_key(AmazonS3ConfigKey::CopyIfNotExists.as_ref())
|| options
.0
.contains_key(AmazonS3ConfigKey::ConditionalPut.as_ref())
{
Ok(store)
} else {
Expand Down

0 comments on commit 480e8b6

Please sign in to comment.