From e083331679dd2d58cfd3a0b9639a6ecd6220ba31 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 7 Mar 2026 19:30:18 +0800 Subject: refstore: Batch should also be staged --- refstore/batch.go | 36 ++++++++++++++++++++++-------------- refstore/batch_store.go | 2 +- refstore/read_write.go | 7 ------- refstore/read_write_store.go | 2 +- 4 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 refstore/read_write.go (limited to 'refstore') diff --git a/refstore/batch.go b/refstore/batch.go index 05e0f1cb..6352159c 100644 --- a/refstore/batch.go +++ b/refstore/batch.go @@ -2,37 +2,45 @@ package refstore import "codeberg.org/lindenii/furgit/objectid" -// Batch applies reference operations immediately, one operation at a time. +// Batch stages reference operations for one non-atomic apply. // -// Unlike Transaction, Batch does not stage changes for one atomic commit. -// Each method attempts its update immediately and returns that operation's -// error, if any. +// Unlike Transaction, Batch may reject some queued operations while still +// applying others successfully when Apply runs. type Batch interface { // Create creates one detached reference, requiring that the logical // reference does not already exist. - Create(name string, newID objectid.ObjectID) error + Create(name string, newID objectid.ObjectID) // Update updates one detached reference, requiring that the current logical // reference value matches oldID. - Update(name string, newID, oldID objectid.ObjectID) error + Update(name string, newID, oldID objectid.ObjectID) // Delete deletes one detached reference, requiring that the current logical // reference value matches oldID. - Delete(name string, oldID objectid.ObjectID) error + Delete(name string, oldID objectid.ObjectID) // Verify verifies that the current logical reference value matches oldID. - Verify(name string, oldID objectid.ObjectID) error + Verify(name string, oldID objectid.ObjectID) // CreateSymbolic creates one symbolic reference, requiring that the named // reference does not already exist. - CreateSymbolic(name, newTarget string) error + CreateSymbolic(name, newTarget string) // UpdateSymbolic updates one symbolic reference directly, requiring that its // current target matches oldTarget. - UpdateSymbolic(name, newTarget, oldTarget string) error + UpdateSymbolic(name, newTarget, oldTarget string) // DeleteSymbolic deletes one symbolic reference directly, requiring that its // current target matches oldTarget. - DeleteSymbolic(name, oldTarget string) error + DeleteSymbolic(name, oldTarget string) // VerifySymbolic verifies that the named symbolic reference currently points // at oldTarget. - VerifySymbolic(name, oldTarget string) error + VerifySymbolic(name, oldTarget string) - // Close releases any resources associated with the batch. - Close() error + // Apply validates and applies queued operations, returning one result per + // queued operation in order. Fatal backend failures are returned separately. + Apply() ([]BatchResult, error) + // Abort abandons the batch and releases any resources it holds. + Abort() error +} + +// BatchResult reports the outcome for one queued batch operation. +type BatchResult struct { + Name string + Error error } diff --git a/refstore/batch_store.go b/refstore/batch_store.go index 8e821eb6..3ccfdd10 100644 --- a/refstore/batch_store.go +++ b/refstore/batch_store.go @@ -2,6 +2,6 @@ package refstore // BatchStore begins non-atomic reference batches. type BatchStore interface { - // BeginBatch creates one new immediate-apply batch. + // BeginBatch creates one new queued batch. BeginBatch() (Batch, error) } diff --git a/refstore/read_write.go b/refstore/read_write.go deleted file mode 100644 index 8ac592bb..00000000 --- a/refstore/read_write.go +++ /dev/null @@ -1,7 +0,0 @@ -package refstore - -// ReadWriteStore supports both reading and atomic transactional updates. -type ReadWriteStore interface { - ReadingStore - TransactionalStore -} diff --git a/refstore/read_write_store.go b/refstore/read_write_store.go index 506a9aae..7be1af61 100644 --- a/refstore/read_write_store.go +++ b/refstore/read_write_store.go @@ -1,6 +1,6 @@ package refstore -// ReadWriteStore supports reading, atomic transactions, and immediate batches. +// ReadWriteStore supports reading, atomic transactions, and non-atomic batches. type ReadWriteStore interface { ReadingStore TransactionalStore -- cgit v1.3.1-10-gc9f91