Skip to content

Commit 2285647

Browse files
committed
fix
1 parent 979f604 commit 2285647

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/meta/api/src/api_impl/ref_api.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ where
310310
debug!(req :? =(&req); "RefApi: {}", func_name!());
311311

312312
let branch_name = &req.branch_name;
313-
let forks_from_branch = req.from_branch_id.is_some();
314313
let source_table_id = req.from_branch_id.unwrap_or(req.base_table_id);
315314
let key_source_table_id = TableId {
316315
table_id: source_table_id,
@@ -341,7 +340,20 @@ where
341340
)));
342341
}
343342

344-
let base_table_seq = if forks_from_branch {
343+
if self.get_pb(&key_branch).await?.is_some() {
344+
return Err(KVAppError::AppError(AppError::from(
345+
ReferenceAlreadyExists::new(format!("Branch '{}' already exists", branch_name)),
346+
)));
347+
}
348+
349+
let mut conditions = vec![
350+
txn_cond_seq(&key_source_table_id, Eq, seq_source_table_meta.seq),
351+
txn_cond_seq(&key_branch, Eq, 0),
352+
];
353+
354+
if req.from_branch_id.is_some() {
355+
// The source may be a branch table, but the new branch is still created under the
356+
// base table namespace, so the base table must still exist and be active.
345357
let Some(seq_table_meta) = self.get_pb(&key_table_id).await? else {
346358
return Err(KVAppError::AppError(AppError::UnknownTableId(
347359
UnknownTableId::new(req.base_table_id, "create_table_branch: base table"),
@@ -355,15 +367,11 @@ where
355367
),
356368
)));
357369
}
358-
Some(seq_table_meta.seq)
359-
} else {
360-
None
361-
};
370+
conditions.push(txn_cond_seq(&key_table_id, Eq, seq_table_meta.seq));
371+
}
362372

363-
if self.get_pb(&key_branch).await?.is_some() {
364-
return Err(KVAppError::AppError(AppError::from(
365-
ReferenceAlreadyExists::new(format!("Branch '{}' already exists", branch_name)),
366-
)));
373+
if let Some(lvt_check) = req.lvt_check.as_ref() {
374+
conditions.push(build_lvt_condition(self, source_table_id, lvt_check).await?);
367375
}
368376

369377
let branch_id = match maybe_branch_id {
@@ -383,17 +391,6 @@ where
383391
branch_id,
384392
};
385393

386-
let mut conditions = vec![
387-
txn_cond_seq(&key_source_table_id, Eq, seq_source_table_meta.seq),
388-
txn_cond_seq(&key_branch, Eq, 0),
389-
];
390-
if let Some(base_table_seq) = base_table_seq {
391-
conditions.push(txn_cond_seq(&key_table_id, Eq, base_table_seq));
392-
}
393-
if let Some(lvt_check) = req.lvt_check.as_ref() {
394-
conditions.push(build_lvt_condition(self, source_table_id, lvt_check).await?);
395-
}
396-
397394
let mut if_then = vec![
398395
txn_put_pb(&key_branch_table_id, &req.new_table_meta)?,
399396
txn_put_pb(&key_branch, &table_branch)?,

0 commit comments

Comments
 (0)