Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace for with Iter on store.GetEmptyTicksForEpochs. #97

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace for with Iter on store.GetEmptyTicksForEpochs.
LINCKODE committed Jan 23, 2025
commit cdcd41fd1ffb9dc2d94e7f8f3f2f3d8df1fe8d17
6 changes: 5 additions & 1 deletion rpc/rpc_server.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import (
"log"
"net"
"net/http"
"slices"
)

var _ protobuff.ArchiveServiceServer = &Server{}
@@ -375,7 +376,10 @@ func (s *Server) GetStatus(ctx context.Context, _ *emptypb.Empty) (*protobuff.Ge
epochs = append(epochs, epoch)
}

emptyTicksForAllEpochs, err := s.store.GetEmptyTicksForEpochs(epochs)
lowestEpoch := slices.Min(epochs)
highestEpoch := slices.Max(epochs)

emptyTicksForAllEpochs, err := s.store.GetEmptyTicksForEpochs(lowestEpoch, highestEpoch)
if err != nil {
return nil, status.Errorf(codes.Internal, "getting empty ticks for all epochs: %v", err)
}
30 changes: 21 additions & 9 deletions store/store.go
Original file line number Diff line number Diff line change
@@ -671,22 +671,34 @@ func (s *PebbleStore) GetEmptyTicksForEpoch(epoch uint32) (uint32, error) {
return emptyTicksCount, nil
}

func (s *PebbleStore) GetEmptyTicksForEpochs(epochs []uint32) (map[uint32]uint32, error) {
func (s *PebbleStore) GetEmptyTicksForEpochs(firstEpoch, lastEpoch uint32) (map[uint32]uint32, error) {

emptyTickMap := make(map[uint32]uint32, len(epochs))
iter, err := s.db.NewIter(&pebble.IterOptions{
LowerBound: emptyTicksPerEpochKey(firstEpoch),
UpperBound: emptyTicksPerEpochKey(lastEpoch + 1), // Increment as upper bound is exclusive
})
if err != nil {
return nil, errors.Wrap(err, "creating iter")
}
defer iter.Close()

emptyTickMap := make(map[uint32]uint32)

for iter.First(); iter.Valid(); iter.Next() {

for _, epoch := range epochs {
emptyTicks, err := s.GetEmptyTicksForEpoch(epoch)
value, err := iter.ValueAndErr()
if err != nil {
if !errors.Is(err, pebble.ErrNotFound) {
return nil, errors.Wrapf(err, "getting empty ticks for epoch %d", epoch)
}
return nil, errors.Wrap(err, "getting value from iter")
}
emptyTickMap[epoch] = emptyTicks

key := iter.Key()
epochNumber := binary.BigEndian.Uint64(key[1:])
emptyTicksCount := binary.LittleEndian.Uint32(value)

emptyTickMap[uint32(epochNumber)] = emptyTicksCount
}

return emptyTickMap, nil

}

func (s *PebbleStore) DeleteEmptyTicksKeyForEpoch(epoch uint32) error {