Skip to content

Commit fa83c63

Browse files
committed
Simplify update endpoint to use same default URI as create
1 parent 18ab970 commit fa83c63

File tree

5 files changed

+23
-41
lines changed

5 files changed

+23
-41
lines changed

docs/reference/rest-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ Updating the doc mapping doesn't reindex existing data. Queries and results are
342342
|---------------------|--------------------|-----------------------------------------------------------------------------------------------------------------------|---------------------------------------|
343343
| `version` | `String` | Config format version, use the same as your Quickwit version. | _required_ |
344344
| `index_id` | `String` | Index ID, must be the same index as in the request URI. | _required_ |
345-
| `index_uri` | `String` | Defines where the index files are stored. Cannot be updated. | `{current_index_uri}` |
345+
| `index_uri` | `String` | Defines where the index files are stored. Cannot be updated. | `{default_index_root_uri}/{index_id}` |
346346
| `doc_mapping` | `DocMapping` | Doc mapping object as specified in the [index config docs](../configuration/index-config.md#doc-mapping). | _required_ |
347347
| `indexing_settings` | `IndexingSettings` | Indexing settings object as specified in the [index config docs](../configuration/index-config.md#indexing-settings). | |
348348
| `search_settings` | `SearchSettings` | Search settings object as specified in the [index config docs](../configuration/index-config.md#search-settings). | |

quickwit/quickwit-common/src/uri.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,23 @@ impl Uri {
169169
}
170170

171171
/// Returns the parent URI.
172-
///
173-
/// When the URI points to an object store, this method makes sure that the
174-
/// result targets to a well defined bucket, e.g `s3://` returns `None`.
175-
///
176172
/// Does not apply to PostgreSQL URIs.
177173
pub fn parent(&self) -> Option<Uri> {
178-
self.parent_unchecked().filter(|parent| {
179-
let path = parent.path();
180-
match self.protocol() {
181-
Protocol::S3 => path.components().count() >= 1,
182-
Protocol::Azure => path.components().count() >= 2,
183-
Protocol::Google => path.components().count() >= 1,
184-
_ => true,
185-
}
186-
})
187-
}
188-
189-
/// Same as [Self::parent()] but without the additional check on object stores.
190-
pub fn parent_unchecked(&self) -> Option<Uri> {
191174
if self.protocol().is_database() {
192175
return None;
193176
}
194177
let path = self.path();
195178
let protocol = self.protocol();
179+
180+
if protocol == Protocol::S3 && path.components().count() < 2 {
181+
return None;
182+
}
183+
if protocol == Protocol::Azure && path.components().count() < 3 {
184+
return None;
185+
}
186+
if protocol == Protocol::Google && path.components().count() < 2 {
187+
return None;
188+
}
196189
let parent_path = path.parent()?;
197190

198191
Some(Self {
@@ -604,23 +597,11 @@ mod tests {
604597
"ram:///foo"
605598
);
606599
assert!(Uri::for_test("s3://bucket").parent().is_none());
607-
assert_eq!(
608-
Uri::for_test("s3://bucket").parent_unchecked().unwrap(),
609-
"s3://"
610-
);
611600
assert!(Uri::for_test("s3://bucket/").parent().is_none());
612-
assert_eq!(
613-
Uri::for_test("s3://bucket/").parent_unchecked().unwrap(),
614-
"s3://"
615-
);
616601
assert_eq!(
617602
Uri::for_test("s3://bucket/foo").parent().unwrap(),
618603
"s3://bucket"
619604
);
620-
assert_eq!(
621-
Uri::for_test("s3://bucket/foo").parent_unchecked().unwrap(),
622-
"s3://bucket"
623-
);
624605
assert_eq!(
625606
Uri::for_test("s3://bucket/foo/").parent().unwrap(),
626607
"s3://bucket"

quickwit/quickwit-config/src/index_config/serialize.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,17 @@ pub fn load_index_config_from_user_config(
6868
///
6969
/// Ensures that the new configuration is valid in itself and compared to the
7070
/// current index config. If the new configuration omits some fields, the
71-
/// default values will be used, not those of the current index config. The only
72-
/// exception is the index_uri because it cannot be updated.
71+
/// default values will be used, not those of the current index config.
7372
pub fn load_index_config_update(
7473
config_format: ConfigFormat,
7574
index_config_bytes: &[u8],
76-
current_index_parent_dir: &Uri,
75+
default_index_root_uri: &Uri,
7776
current_index_config: &IndexConfig,
7877
) -> anyhow::Result<IndexConfig> {
7978
let mut new_index_config = load_index_config_from_user_config(
8079
config_format,
8180
index_config_bytes,
82-
current_index_parent_dir,
81+
default_index_root_uri,
8382
)?;
8483
ensure!(
8584
current_index_config.index_id == new_index_config.index_id,

quickwit/quickwit-serve/src/index_api/index_resource.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,15 @@ pub async fn create_index(
286286

287287
pub fn update_index_handler(
288288
metastore: MetastoreServiceClient,
289+
node_config: Arc<NodeConfig>,
289290
) -> impl Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone {
290291
warp::path!("indexes" / String)
291292
.and(warp::put())
292293
.and(extract_config_format())
293294
.and(warp::body::content_length_limit(1024 * 1024))
294295
.and(warp::filters::body::bytes())
295296
.and(with_arg(metastore))
297+
.and(with_arg(node_config))
296298
.then(update_index)
297299
.map(log_failure("failed to update index"))
298300
.and(extract_format_from_qs())
@@ -325,6 +327,7 @@ pub async fn update_index(
325327
config_format: ConfigFormat,
326328
index_config_bytes: Bytes,
327329
metastore: MetastoreServiceClient,
330+
node_config: Arc<NodeConfig>,
328331
) -> Result<IndexMetadata, IndexServiceError> {
329332
info!(index_id = %target_index_id, "update-index");
330333

@@ -336,14 +339,10 @@ pub async fn update_index(
336339
let index_uid = current_index_metadata.index_uid.clone();
337340
let current_index_config = current_index_metadata.into_index_config();
338341

339-
let current_index_parent_dir = &current_index_config
340-
.index_uri
341-
.parent_unchecked()
342-
.ok_or_else(|| IndexServiceError::Internal("index URI should have a parent".to_string()))?;
343342
let new_index_config = load_index_config_update(
344343
config_format,
345344
&index_config_bytes,
346-
current_index_parent_dir,
345+
&node_config.default_index_root_uri,
347346
&current_index_config,
348347
)
349348
.map_err(IndexServiceError::InvalidConfig)?;

quickwit/quickwit-serve/src/index_api/rest_handler.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ pub fn index_management_handlers(
8989
// Indexes handlers.
9090
get_index_metadata_handler(index_service.metastore())
9191
.or(list_indexes_metadata_handler(index_service.metastore()))
92-
.or(create_index_handler(index_service.clone(), node_config))
93-
.or(update_index_handler(index_service.metastore()))
92+
.or(create_index_handler(
93+
index_service.clone(),
94+
node_config.clone(),
95+
))
96+
.or(update_index_handler(index_service.metastore(), node_config))
9497
.or(clear_index_handler(index_service.clone()))
9598
.or(delete_index_handler(index_service.clone()))
9699
.boxed()

0 commit comments

Comments
 (0)