fix(remote): preserve branches in cache prewarm requests (#5012)

Calling `prewarm_data` or `prewarm_index` on a checked-out remote branch
currently targets main. Both methods omit the branch context, which can
warm the wrong snapshot, miss a branch-only index, or fail when the
branch's minimum read version is ahead of main. This PR carries the
table handle's branch through the existing request helpers. Main
requests retain their existing format, with no public API changes.
This commit is contained in:
Bruno Ramirez
2026-11-13 09:38:50 -08:00
committed by GitHub
parent bab22a3fbd
commit 927b243948
+68 -3
View File
@@ -4548,10 +4548,10 @@ impl<S: HttpSend> BaseTable for RemoteTable<S> {
async fn prewarm_index(&self, index_name: &str) -> Result<()> {
let encoded_name = urlencoding::encode(index_name);
let request = self.client.post(&format!(
let request = self.apply_branch_query(self.client.post(&format!(
"/v1/table/{}/index/{encoded_name}/prewarm/",
self.identifier
));
)));
let (request_id, response) = self.send(request, true).await?;
if response.status() == StatusCode::NOT_FOUND {
return Err(Error::IndexNotFound {
@@ -4567,9 +4567,10 @@ impl<S: HttpSend> BaseTable for RemoteTable<S> {
"/v1/table/{}/page_cache/prewarm/",
self.identifier
));
let body = serde_json::json!({
let mut body = serde_json::json!({
"columns": columns.unwrap_or_default(),
});
self.apply_branch_body(&mut body);
request = request.json(&body);
let (request_id, response) = self.send(request, true).await?;
self.check_table_response(&request_id, response).await?;
@@ -13018,6 +13019,70 @@ mod tests {
.unwrap();
}
#[tokio::test]
async fn test_prewarm_data_sends_the_checked_out_branch() {
use lance::dataset::refs::Ref;
let table =
Table::new_with_handler_version("my_table", semver::Version::new(0, 5, 0), |request| {
match request.url().path() {
"/v1/table/my_table/branches/create/" => {
http::Response::builder().status(200).body("{}").unwrap()
}
"/v1/table/my_table/page_cache/prewarm/" => {
let body = request_body_json(&request);
assert_eq!(body["branch"], "dev");
assert_eq!(body["columns"], json!(["payload"]));
http::Response::builder()
.status(202)
.body(r#"{"job_id":"prewarm-job"}"#)
.unwrap()
}
path => panic!("unexpected request path: {path}"),
}
});
let branch = table
.create_branch("dev", Ref::Version(None, None))
.await
.unwrap();
branch
.prewarm_data(Some(vec!["payload".into()]))
.await
.unwrap();
}
#[tokio::test]
async fn test_prewarm_index_sends_the_checked_out_branch() {
use lance::dataset::refs::Ref;
let table =
Table::new_with_handler_version("my_table", semver::Version::new(0, 5, 0), |request| {
match request.url().path() {
"/v1/table/my_table/branches/create/" => {
http::Response::builder().status(200).body("{}").unwrap()
}
"/v1/table/my_table/index/my_index/prewarm/" => {
let branch = request
.url()
.query_pairs()
.find(|(key, _)| key == "branch")
.map(|(_, value)| value.into_owned());
assert_eq!(branch.as_deref(), Some("feature/dev"));
http::Response::builder()
.status(202)
.body(r#"{"job_id":"prewarm-job"}"#)
.unwrap()
}
path => panic!("unexpected request path: {path}"),
}
});
let branch = table
.create_branch("feature/dev", Ref::Version(None, None))
.await
.unwrap();
branch.prewarm_index("my_index").await.unwrap();
}
#[tokio::test]
async fn test_drop_index() {
let table = Table::new_with_handler("my_table", |request| {