Skip to content

Commit

Permalink
Change lock manager interfaces (#61)
Browse files Browse the repository at this point in the history
Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby committed Sep 25, 2023
1 parent 0f44a36 commit 0d54a8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions go/storage/lock/lock_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import "github.com/milvus-io/milvus-storage/go/common/constant"

type LockManager interface {
// Acquire the lock, wait until the lock is available, return the version to be modified or use the newest version
Acquire() (version int64, useLatestVersion bool)
Acquire() (version int64, useLatestVersion bool, err error)
// Release the lock, accepts the new allocated manifest version and success state of operations between Acquire and Release as parameters
Release(version int64, success bool)
Release(version int64, success bool) error
}

type EmptyLockManager struct{}

func (h *EmptyLockManager) Acquire() (version int64, useLatestVersion bool) {
return constant.LatestManifestVersion, true
func (h *EmptyLockManager) Acquire() (version int64, useLatestVersion bool, err error) {
return constant.LatestManifestVersion, true, nil
}

func (h *EmptyLockManager) Release(_ int64, _ bool) {}
func (h *EmptyLockManager) Release(_ int64, _ bool) error { return nil }
14 changes: 9 additions & 5 deletions go/storage/manifest/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ func (m *ManifestCommit) AddOp(op ...ManifestCommitOp) {
m.ops = append(m.ops, op...)
}

func (m ManifestCommit) Commit() error {
ver, latest := m.lock.Acquire()
var err error
func (m ManifestCommit) Commit() (err error) {
ver, latest, err := m.lock.Acquire()
if err != nil {
return err
}
var version int64
defer func() {
if err != nil {
m.lock.Release(-1, false)
if err2 := m.lock.Release(-1, false); err2 != nil {
err = err2
}
} else {
m.lock.Release(version, true)
err = m.lock.Release(version, true)
}
}()
var base *Manifest
Expand Down

0 comments on commit 0d54a8c

Please sign in to comment.