Skip to content

Commit

Permalink
[Go]: set manifest after txn (#103)
Browse files Browse the repository at this point in the history
Signed-off-by: sunby <[email protected]>
  • Loading branch information
sunby committed Dec 27, 2023
1 parent 5751940 commit ebd0b8e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
20 changes: 10 additions & 10 deletions go/storage/manifest/commit.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2023 Zilliz
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -29,10 +29,10 @@ func (m *ManifestCommit) AddOp(op ...ManifestCommitOp) {
m.ops = append(m.ops, op...)
}

func (m ManifestCommit) Commit() (err error) {
func (m ManifestCommit) Commit() (manifest *Manifest, err error) {
ver, latest, err := m.lock.Acquire()
if err != nil {
return err
return nil, err
}
var version int64
defer func() {
Expand All @@ -48,17 +48,17 @@ func (m ManifestCommit) Commit() (err error) {
if latest {
base, err = m.rw.Read(constant.LatestManifestVersion)
if err != nil {
return err
return nil, err
}
base.version++
} else {
base, err = m.rw.Read(ver)
if err != nil {
return err
return nil, err
}
maxVersion, err := m.rw.MaxVersion()
if err != nil {
return err
return nil, err
}
base.version = maxVersion + 1
}
Expand All @@ -70,9 +70,9 @@ func (m ManifestCommit) Commit() (err error) {

err = m.rw.Write(base)
if err != nil {
return err
return nil, err
}
return nil
return base, nil
}

func NewManifestCommit(lock lock.LockManager, rw ManifestReaderWriter) ManifestCommit {
Expand Down
4 changes: 2 additions & 2 deletions go/storage/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestManifestCommitOp(t *testing.T) {
mc.AddOp(AddScalarFragmentOp{ScalarFragment: fragment.NewFragment()})
mc.AddOp(AddVectorFragmentOp{VectorFragment: fragment.NewFragment()})
mc.AddOp(AddDeleteFragmentOp{DeleteFragment: fragment.NewFragment()})
err = mc.Commit()
_, err = mc.Commit()
assert.NoError(t, err)
}

Expand Down Expand Up @@ -254,7 +254,7 @@ func TestManifestCommit_concurrency(t *testing.T) {
mc.AddOp(AddScalarFragmentOp{ScalarFragment: fragment.NewFragment()})
mc.AddOp(AddVectorFragmentOp{VectorFragment: fragment.NewFragment()})
mc.AddOp(AddDeleteFragmentOp{DeleteFragment: fragment.NewFragment()})
err = mc.Commit()
_, err = mc.Commit()
wg.Done()
}()
}
Expand Down
12 changes: 8 additions & 4 deletions go/storage/space.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2023 Zilliz
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -119,7 +119,7 @@ func Open(uri string, opt options.Options) (*Space, error) {
return nil, err
}
m = manifest.NewManifest(opt.Schema)
m.SetVersion(0) //TODO: check if this is necessary
m.SetVersion(0) // TODO: check if this is necessary
if err = rw.Write(m); err != nil {
return nil, err
}
Expand Down Expand Up @@ -203,6 +203,10 @@ func (s *Space) Manifest() *manifest.Manifest {
return s.manifest
}

func (s *Space) SetManifest(manifest *manifest.Manifest) {
s.manifest = manifest
}

func (s *Space) LockManager() lock.LockManager {
return s.lockManager
}
Expand Down
8 changes: 7 additions & 1 deletion go/storage/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type SpaceMeta interface {
Fs() fs.Fs
Manifest() *manifest.Manifest
LockManager() lock.LockManager
SetManifest(manifest *manifest.Manifest)
}

type Transaction interface {
Expand Down Expand Up @@ -90,7 +91,12 @@ func (t *ConcurrentWriteTransaction) Commit() error {
for _, op := range t.operations {
op.Execute()
}
return t.commit.Commit()
nxtManifest, err := t.commit.Commit()
if err != nil {
return err
}
t.space.SetManifest(nxtManifest)
return nil
}

func NewConcurrentWriteTransaction(space SpaceMeta) *ConcurrentWriteTransaction {
Expand Down

0 comments on commit ebd0b8e

Please sign in to comment.