Skip to content

Commit

Permalink
fix: more
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Jan 30, 2024
1 parent cdeafe7 commit 0420935
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions pkg/storer/internal/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ func (s *store) NewTransaction(ctx context.Context) (Transaction, func()) {
}
}

type readOnly struct {
indexStore *indexTrx
chunkStore *chunkStoreTrx
}

func (s *store) ReadOnly() ReadOnlyStore {
indexStore := &indexTrx{s.bstore, nil}
sharyTrx := &sharkyTrx{s.sharky, s.metrics, nil, nil}
Expand Down Expand Up @@ -139,6 +134,11 @@ func (s *store) Close() error {
return errors.Join(s.bstore.Close(), s.sharky.Close())
}

type readOnly struct {
indexStore *indexTrx
chunkStore *chunkStoreTrx
}

func (t *readOnly) IndexStore() storage.Reader {
return t.indexStore
}
Expand All @@ -147,35 +147,6 @@ func (t *readOnly) ChunkStore() storage.ReadOnlyChunkStore {
return t.chunkStore
}

type indexTrx struct {
store storage.Reader
batch storage.Batch
}

func (s *indexTrx) Get(i storage.Item) error { return s.store.Get(i) }
func (s *indexTrx) Has(k storage.Key) (bool, error) { return s.store.Has(k) }
func (s *indexTrx) GetSize(k storage.Key) (int, error) { return s.store.GetSize(k) }
func (s *indexTrx) Iterate(q storage.Query, f storage.IterateFn) error {
return s.store.Iterate(q, f)
}
func (s *indexTrx) Count(k storage.Key) (int, error) { return s.store.Count(k) }
func (s *indexTrx) Put(i storage.Item) error { return s.batch.Put(i) }
func (s *indexTrx) Delete(i storage.Item) error { return s.batch.Delete(i) }

// IndexStore gives acces to the index store of the transaction.
// Note that no writes are persisted to the disk until the commit is called.
// Reads return data from the disk and not what has been written to the transaction before the commit call.
func (t *transaction) IndexStore() storage.IndexStore {
return t.indexstore
}

// ChunkStore gives acces to the chunkstore of the transaction.
// Note that no writes are persisted to the disk until the commit is called.
// Reads return data from the disk and not what has been written to the transaction before the commit call.
func (t *transaction) ChunkStore() storage.ChunkStore {
return t.chunkStore
}

func (t *transaction) Commit() (err error) {

defer handleMetric("commit", t.metrics)(err)
Expand Down Expand Up @@ -211,6 +182,20 @@ func (t *transaction) Commit() (err error) {
return err
}

// IndexStore gives acces to the index store of the transaction.
// Note that no writes are persisted to the disk until the commit is called.
// Reads return data from the disk and not what has been written to the transaction before the commit call.
func (t *transaction) IndexStore() storage.IndexStore {
return t.indexstore
}

// ChunkStore gives acces to the chunkstore of the transaction.
// Note that no writes are persisted to the disk until the commit is called.
// Reads return data from the disk and not what has been written to the transaction before the commit call.
func (t *transaction) ChunkStore() storage.ChunkStore {
return t.chunkStore
}

type chunkStoreTrx struct {
indexStore *indexTrx
sharkyTrx *sharkyTrx
Expand Down Expand Up @@ -266,6 +251,21 @@ func (c *chunkStoreTrx) lock(addr swarm.Address) func() {
return func() {} // unlocking the chunk will be done in the Commit()
}

type indexTrx struct {
store storage.Reader
batch storage.Batch
}

func (s *indexTrx) Get(i storage.Item) error { return s.store.Get(i) }
func (s *indexTrx) Has(k storage.Key) (bool, error) { return s.store.Has(k) }
func (s *indexTrx) GetSize(k storage.Key) (int, error) { return s.store.GetSize(k) }
func (s *indexTrx) Iterate(q storage.Query, f storage.IterateFn) error {
return s.store.Iterate(q, f)
}
func (s *indexTrx) Count(k storage.Key) (int, error) { return s.store.Count(k) }
func (s *indexTrx) Put(i storage.Item) error { return s.batch.Put(i) }
func (s *indexTrx) Delete(i storage.Item) error { return s.batch.Delete(i) }

type sharkyTrx struct {
sharky *sharky.Store
metrics metrics
Expand Down

0 comments on commit 0420935

Please sign in to comment.