tustvold commented on code in PR #375:
URL: 
https://github.com/apache/arrow-rs-object-store/pull/375#discussion_r2094184922


##########
src/registry.rs:
##########
@@ -0,0 +1,238 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Map object URLs to [`ObjectStore`]
+
+use crate::path::{InvalidPart, Path, PathPart};
+use crate::{parse_url, parse_url_opts, ObjectStore};
+use parking_lot::RwLock;
+use std::borrow::Borrow;
+use std::collections::btree_map::Entry;
+use std::collections::{BTreeMap, Bound};
+use std::sync::Arc;
+use url::Url;
+
+/// Error type for [`ObjectStoreRegistry`]
+#[derive(Debug, thiserror::Error)]
+#[non_exhaustive]
+enum Error {
+    #[error("ObjectStore not found")]
+    NotFound,
+
+    #[error("Error parsing URL path segment")]
+    InvalidPart(#[from] InvalidPart),
+}
+
+impl From<Error> for crate::Error {
+    fn from(value: Error) -> Self {
+        Self::Generic {
+            store: "ObjectStoreRegistry",
+            source: Box::new(value),
+        }
+    }
+}
+
+/// [`ObjectStoreRegistry`] maps a URL to an [`ObjectStore`] instance
+pub trait ObjectStoreRegistry: Send + Sync + std::fmt::Debug + 'static {
+    /// Register a new store for the provided store URL
+    ///
+    /// If a store with the same URL existed before, it is replaced and 
returned
+    fn register(&self, url: Url, store: Arc<dyn ObjectStore>) -> 
Option<Arc<dyn ObjectStore>>;
+
+    /// Unregister a store for the provided store URL
+    fn unregister(&self, url: &Url) -> Option<Arc<dyn ObjectStore>>;
+
+    /// Resolve an object URL
+    ///
+    /// If [`ObjectStoreRegistry::register`] has been called with a URL with 
the same

Review Comment:
   The original formulation in DF simply uses scheme and host. This works well 
for bucket specific URLs like `s3://bucket/path` but it falls apart for URLs 
like `https://s3.region.amazonaws.com/bucket`.
   
   The challenge is to come up with a mechanism to support keying on more than 
scheme and host, without requiring the registry to actually understand the 
components of that URL. This is the formulation I came up with.
   
   Unlike #356 it avoids the store needing to actually understand the content 
of the URL, making this significantly more flexible.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to